From 5369888edc2e8faf0dc49a1a1c557dd385ce6fc9 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 23 Jan 2023 10:15:36 +0000 Subject: [PATCH] examples: Use substrate as polkadot.scale and print codegen Signed-off-by: Alexandru Vasile --- artifacts/polkadot_metadata.scale | Bin 464268 -> 464354 bytes codegen/src/api/mod.rs | 9 +++++-- examples/examples/runtime_calls.rs | 37 +++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 examples/examples/runtime_calls.rs diff --git a/artifacts/polkadot_metadata.scale b/artifacts/polkadot_metadata.scale index f1eb9975581ebab5b119caf3bc7ba1fd9baf0c7a..63b7b85a2bc7e2ddf17fd37ab52cb314fa917f22 100644 GIT binary patch delta 129 zcmeBKE%Ru#3|nq$Nh1HwMz&Tq##T0_RyO8VHkPeytjkVYujOW7VBy%vy_K6`Baq3Y z%f_&kn?t6!AU-+2DAmHhAhEDC)fcEeC9xzCsFcBgQ6?-k*{0OOu6@;M*6piKvpw{b RVo`uAVNn2C238F+8vw;{Ce8o= delta 44 zcmaE~TBc{U3|nq$Nh1H+Mz&Tq##T0_RyO8VHkPeytjkWfzdX&l{pD%4`<{#p0A&gg AE&u=k diff --git a/codegen/src/api/mod.rs b/codegen/src/api/mod.rs index fdddcdb7c4..e54a361a80 100644 --- a/codegen/src/api/mod.rs +++ b/codegen/src/api/mod.rs @@ -155,9 +155,14 @@ fn generate_runtime_call_api( ) -> TokenStream2 { let mut result = quote!(); + println!("inside runtime: {:?}", runtime); + for trait_ in runtime { for method in &trait_.methods { - let fn_name = format!("{}{}", trait_.name, method.name); + let trait_name = trait_.name.clone(); + let method_name = method.name.clone(); + + let fn_name = format_ident!("{}_{}", trait_.name, method.name); let mut params = Vec::new(); for input in &method.inputs { @@ -172,7 +177,7 @@ fn generate_runtime_call_api( let output = type_gen.resolve_type_path(output.id()); let fn_ = quote!( - pub fn #fn_name( &self, #( #params, )* ) -> #output { + pub fn #fn_name( #( #params, )* ) -> #output { // call into RPC. } ); diff --git a/examples/examples/runtime_calls.rs b/examples/examples/runtime_calls.rs new file mode 100644 index 0000000000..0a150b2433 --- /dev/null +++ b/examples/examples/runtime_calls.rs @@ -0,0 +1,37 @@ +// Copyright 2019-2022 Parity Technologies (UK) Ltd. +// This file is dual-licensed as Apache-2.0 or GPL-3.0. +// see LICENSE for license details. + +//! To run this example, a local polkadot node should be running. Example verified against polkadot v0.9.28-9ffe6e9e3da. +//! +//! E.g. +//! ```bash +//! curl "https://github.com/paritytech/polkadot/releases/download/v0.9.28/polkadot" --output /usr/local/bin/polkadot --location +//! polkadot --dev --tmp +//! ``` + +use sp_keyring::AccountKeyring; +use subxt::{ + config::{ + polkadot::{ + Era, + PlainTip, + PolkadotExtrinsicParamsBuilder as Params, + }, + PolkadotConfig, + }, + tx::PairSigner, + OnlineClient, +}; + +#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")] +pub mod polkadot {} + +#[tokio::main] +async fn main() -> Result<(), Box> { + tracing_subscriber::fmt::init(); + + polkadot::runtime_api::Metadata_metadata(); + + Ok(()) +}