From 061f8a18ad9679c39ef3db2710473f10a9b1f3df Mon Sep 17 00:00:00 2001 From: david barinas Date: Wed, 1 May 2024 14:37:34 -0500 Subject: [PATCH] refactor: Add logging and improve readability in sending transaction and extrinsic building functions --- sube/examples/send_tx.rs | 9 ++++++--- sube/src/lib.rs | 22 +++++++++++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/sube/examples/send_tx.rs b/sube/examples/send_tx.rs index c56d3f0..a35c911 100644 --- a/sube/examples/send_tx.rs +++ b/sube/examples/send_tx.rs @@ -13,6 +13,7 @@ use anyhow::{anyhow, Result}; #[async_std::main] async fn main() -> Result<(), Box> { + env_logger::init(); let phrase = env::args().skip(1).collect::>().join(" "); let (vault, phrase) = if phrase.is_empty() { @@ -30,15 +31,17 @@ async fn main() -> Result<(), Box> { let account = wallet.default_account(); let public = account.unwrap().public(); + let public_hex = public.as_ref(); + println!("hex: {}", hex::encode(public_hex)); - let response = sube!("wss://rococo-rpc.polkadot.io/balances/transfer" => { + let response = sube!("wss://kreivo.io/balances/transfer_keep_alive" => { signer: async |message: &[u8]| Ok(wallet.sign(message).await.expect("hello").as_bytes()) , sender: public.as_ref(), body: json!({ "dest": { - "Id": public.as_ref() + "Id": hex::decode("e25b1e3758a5fbedb956b36113252f9e866d3ece688364cc9d34eb01f4b2125d").unwrap() }, - "value": 100000 + "value": 1000000000 }), }) .await diff --git a/sube/src/lib.rs b/sube/src/lib.rs index 0a1a56c..7d8bf79 100644 --- a/sube/src/lib.rs +++ b/sube/src/lib.rs @@ -100,7 +100,7 @@ use serde_json::json; #[cfg(feature = "builder")] pub use paste::paste; -use crate::util::to_camel; +use crate::{meta::Registry, util::to_camel}; mod prelude { pub use alloc::boxed::Box; @@ -208,7 +208,7 @@ where .ok_or_else(|| Error::PalletNotFound(pallet))?; let reg = &meta.types; - + let ty = pallet.calls().expect("pallet does not have calls").ty.id; let mut encoded_call = vec![pallet.index]; @@ -266,10 +266,26 @@ where hex::encode([Compact(era).encode(), Compact(nonce).encode(), Compact(tip).encode()].concat()); log::info!("extra_params_hex: {}", extra_params_hex); + let extensions = (); + + + // vec![0x00u8] sign extensions + // TODO: implement signed extensions + // meta.extrinsic.signed_extensions.iter().for_each(|ext| { + // log::info!("signed extension: {:?}", ext); + // let type_resolved = meta.types.resolve(ext.ty.id); + // log::info!("type_resolved: {:?}", type_resolved); + // log::info!("========================"); + // }); - [vec![era], Compact(nonce).encode(), Compact(tip).encode()].concat() + [ + vec![era], Compact(nonce).encode(), Compact(tip).encode(), vec![0x00u8] + ].concat() }; + + log::info!("Hex {:?}", hex::encode(&extra_params)); + let additional_params = { let metadata = meta;