Skip to content

Instantly share code, notes, and snippets.

@brenzi
Created April 25, 2019 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brenzi/59b510e5a03dd0dc9053770b918c6e88 to your computer and use it in GitHub Desktop.
Save brenzi/59b510e5a03dd0dc9053770b918c6e88 to your computer and use it in GitHub Desktop.
listening to and decoding substrate events
println!("Got message: {}", msg);
let retstr = msg.as_text().unwrap();
let value: serde_json::Value = serde_json::from_str(retstr).unwrap();
match value["id"].as_str() {
Some(idstr) => { },
_ => {
// subscriptions
println!("no id field found in response. must be subscription");
println!("method: {:?}", value["method"].as_str());
match value["method"].as_str() {
Some("state_storage") => {
let _changes = &value["params"]["result"]["changes"];
println!("state_storage changes: {:?}", _changes);
let _unhex = hexstr_to_vec(_changes[0][0].as_str().unwrap().to_string());
let mut _er_enc = _unhex.as_slice();
let _er = EventRecord::decode(&mut _er_enc);
println!("decoded: {:?}", _er)
//self.result.send(res.to_string()).unwrap();
}
_ => println!("unsupported method"),
}
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment