Skip to content

Instantly share code, notes, and snippets.

@brenzi
Last active April 6, 2019 21:40
Show Gist options
  • Save brenzi/9e38ae3f5b3e33da8066b237b579fb95 to your computer and use it in GitHub Desktop.
Save brenzi/9e38ae3f5b3e33da8066b237b579fb95 to your computer and use it in GitHub Desktop.
getStorage
fn state_getStorage(&mut self, module: &str, storage_key_name: &str, param: Vec<u8>) {
let mut key = module.as_bytes().to_vec();
key.append(&mut vec!(' ' as u8));
key.append(&mut storage_key_name.as_bytes().to_vec());
key.append(&mut param.clone());
println!("will query storage for: {:?}", key);
let mut keyhash = hex::encode(twox_128(&key));
keyhash.insert_str(0, "0x");
println!("with storage key: {}", keyhash);
let jsonreq = json!({
"method": "state_getStorage",
"params": [keyhash],
"jsonrpc": "2.0",
"id": REQUEST_GET_STORAGE.to_string(),
});
println!("sending extrinsic: {}", jsonreq.to_string());
self.out.send(jsonreq.to_string()).unwrap();
}
....
let accountid = AccountId::from(AccountKeyring::Alice);
self.state_getStorage("System", "AccountNonce", accountid.encode())
@brenzi
Copy link
Author

brenzi commented Apr 6, 2019

result:

Got message: {"jsonrpc":"2.0","result":"0x28e518b5d14790d77c1fcf1c2eaab717105ba6f853f99077dc3ab15ccd8886c3","id":"1"}
genesis_hash is 0x28e518b5d14790d77c1fcf1c2eaab717105ba6f853f99077dc3ab15ccd8886c3
will query storage for: [83, 121, 115, 116, 101, 109, 32, 65, 99, 99, 111, 117, 110, 116, 78, 111, 110, 99, 101, 212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165, 109, 162, 125]
with storage key: 0x57215254d60f17a7ca3f0f11fef371c5
sending extrinsic: {"id":"4","jsonrpc":"2.0","method":"state_getStorage","params":["0x57215254d60f17a7ca3f0f11fef371c5"]}
Got message: {"jsonrpc":"2.0","result":null,"id":"4"}

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