如何将标准Substrate extrinsic format解码为Transaction
对象,使之能够获得Sender
,最好是字符串形式?
我有以下代码,其中在extrinsic_hex
变量中硬编码了一个样本外部数据以进行测试:
use parity_codec::Decode;
use primitives::generic::UncheckedMortalExtrinsic;
fn main() {
let extrinsic_hex: &'static str="81ffd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d3c6b8941e2976034e67bdd1a999c3eff4403c8ceaf717f18d9760ab18573ab2ce870e9b751c2f14dd9883e54746e1eb6639978ceab49968c25176cc0d2507205040003000ca10f";
let result = hex::decode(extrinsic_hex);
match result {
Ok(v1) => {
let extr_option = UncheckedMortalExtrinsic::decode(&mut v1.as_slice());
()
}
_ => {
println!("Error decoding");
()
}
}
}
Cargo.toml
[package]
name = "decaddr"
version = "0.1.0"
authors = ["niko"]
edition = "2018"
[dependencies]
parity-codec = { version = "3.4.0", default-features = false, features = ["derive"] }
primitives = { package = "sr-primitives", path = "../sr-primitives"}
hex = { version = "0.3"}
我得到的错误是:
Compiling decaddr v0.1.0 (/home/niko/sub/substrate/core/decaddr)
error[E0282]: type annotations needed
--> core/decaddr/src/main.rs:11:20
|
11 | let extr_option=UncheckedMortalExtrinsic::decode(&mut v1.as_slice());
| ----------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for `Address`
| |
| consider giving `extr_option` a type
我不清楚如何解决此问题。