From 26d3123d753d32c0ba50562594050fc82c3ec699 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 7 Feb 2023 19:20:42 +0200 Subject: [PATCH] XXX: Codegen export decoding type for the result call Signed-off-by: Alexandru Vasile --- codegen/src/api/runtime_api.rs | 5 +++++ examples/examples/runtime_calls.rs | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/codegen/src/api/runtime_api.rs b/codegen/src/api/runtime_api.rs index 2f4e6caa78..8c14ebb3be 100644 --- a/codegen/src/api/runtime_api.rs +++ b/codegen/src/api/runtime_api.rs @@ -48,6 +48,9 @@ fn generate_trait_api( let params = inputs.iter().map(|(param, _)| param); let encoded = inputs.iter().map(|(_, encoded)| encoded); + let method_target = format_ident!("{}_target", &method.name); + let output = type_gen.resolve_type_path(method.output.id()); + quote!( #( #[doc = #docs ] )* pub fn #method_name( #( #params, )* ) -> #crate_path::runtime_api::RuntimeAPIPayload { @@ -60,6 +63,8 @@ fn generate_trait_api( [0; 32], ) } + + pub type #method_target = #output; ) }).collect(); diff --git a/examples/examples/runtime_calls.rs b/examples/examples/runtime_calls.rs index 557d88ac53..3477f45361 100644 --- a/examples/examples/runtime_calls.rs +++ b/examples/examples/runtime_calls.rs @@ -24,7 +24,7 @@ use subxt::{ OnlineClient, }; -use codec::Encode; +use codec::Decode; #[subxt::subxt(runtime_metadata_url = "http://localhost:9933")] pub mod polkadot {} @@ -40,6 +40,10 @@ async fn main() -> Result<(), Box> { let bytes = api.runtime_api().at(None).await?.call(api_tx).await?; println!("Result: {:?}", bytes); + let result: polkadot::runtime_api::Core::version_target = + Decode::decode(&mut &bytes[..])?; + + println!("Result is: {:?}", result); Ok(()) }