Created
April 25, 2019 16:07
-
-
Save brenzi/59b510e5a03dd0dc9053770b918c6e88 to your computer and use it in GitHub Desktop.
listening to and decoding substrate events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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