Skip to content

Instantly share code, notes, and snippets.

@brenzi
Created May 16, 2019 14:02
Show Gist options
  • Save brenzi/936ceab317e350507ae4cb7d6ec4434f to your computer and use it in GitHub Desktop.
Save brenzi/936ceab317e350507ae4cb7d6ec4434f to your computer and use it in GitHub Desktop.
raw Externalities HashMap write
pub type SgxExternalities = HashMap<Vec<u8>, Vec<u8>>;
...
let mut ext = SgxExternalities::new();
...
//custom struct
let key = runtime_io::twox_128("Contract Schedule".to_vec());
let value = Schedule::<Gas>::default().encode()
ext.insert(key.to_vec(), value)
...
// primitive Type
let key = runtime_io::twox_128("Contract BlockGasLimit".to_vec());
let value = 10_000_000u64.encode()
ext.insert(key.to_vec(), value)
@brenzi
Copy link
Author

brenzi commented May 16, 2019

// key "Contract BlockGasLimit" is
twox_128 of [43, 6f, 6e, 74, 72, 61, 63, 74, 20, 42, 6c, 6f, 63, 6b, 47, 61, 73, 4c, 69, 6d, 69, 74]
// writing 0u64.encode() to that key results in raw:
[0, 0, 0, 0, 0, 0, 0, 0]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment