impl: decode authority set also
@@ -29,23 +29,24 @@ fn main() {
&payload.trim()
};
let scale_encoded = hex::decode(hex).expect("Hex decoding error");
- match args[1].as_str() {
- "blocknumber" => println!("{:?}", block_number(scale_encoded)),
- "authority_set" => println!("{:?}", authority_set(scale_encoded)),
- _ => println!("Unknown subcommand"),
- }
-}
-
-fn block_number(scale_encoded: Vec<u8>) -> u32 {
let justification =
GrandpaJustification::<Header>::decode(&mut &*scale_encoded).expect("SCALE decoding error");
- justification.commit.target_number
+ match args[1].as_str() {
+ "block_number" | "blockNumber" => println!("{:?}", justification.commit.target_number),
+ "authority_set" | "authoritySet" => println!("{:?}", authority_set(&justification)),
+ _ => println!(
+ "{:?}",
+ serde_json::json!({
+ "blockNumber": justification.commit.target_number,
+ "authoritySet": authority_set(&justification),
+ })
+ .to_string()
+ ),
+ }
}
-fn authority_set(scale_encoded: Vec<u8>) -> String {
- let justification =
- GrandpaJustification::<Header>::decode(&mut &*scale_encoded).expect("SCALE decoding error");
- let mut authorities = vec![];
+fn authority_set(justification: &GrandpaJustification<Header>) -> String {
+ let mut authorities = Vec::with_capacity(justification.commit.precommits.len());
for signed in &justification.commit.precommits {
authorities.push(signed.id.encode());
}
