diff --git a/sube/examples/send_tx.rs b/sube/examples/send_tx.rs index a35c911..3578fc3 100644 --- a/sube/examples/send_tx.rs +++ b/sube/examples/send_tx.rs @@ -34,7 +34,7 @@ async fn main() -> Result<(), Box> { let public_hex = public.as_ref(); println!("hex: {}", hex::encode(public_hex)); - let response = sube!("wss://kreivo.io/balances/transfer_keep_alive" => { + let response = sube!("ws://127.0.0.1:8000/balances/transfer_keep_alive" => { signer: async |message: &[u8]| Ok(wallet.sign(message).await.expect("hello").as_bytes()) , sender: public.as_ref(), body: json!({ diff --git a/sube/src/http.rs b/sube/src/http.rs index 17366de..c0fe66c 100644 --- a/sube/src/http.rs +++ b/sube/src/http.rs @@ -26,7 +26,8 @@ impl Backend { impl Rpc for Backend { /// HTTP based JSONRpc request expecting an hex encoded result async fn rpc(&self, method: &str, params: &[&str]) -> RpcResult { - log::info!("RPC `{}` to {}", method, &self.0); + log::info!("RPC `{}`({:?}) to {}", method, params, &self.0); + let req = surf::post(&self.0).content_type("application/json").body( to_string(&rpc::Request { id: 1.into(), diff --git a/sube/src/lib.rs b/sube/src/lib.rs index 3f6296e..d052a2a 100644 --- a/sube/src/lib.rs +++ b/sube/src/lib.rs @@ -163,15 +163,15 @@ async fn query<'m>(chain: &impl Backend, meta: &'m Metadata, path: &str) -> Resu } if let Ok(key_res) = StorageKey::new(pallet, &item_or_call, &keys) { + log::info!("key_res {:?}", &key_res); let res = chain.query_storage(&key_res).await?; Ok(Response::Value(Value::new(res, key_res.ty, &meta.types))) } else { + log::info!("hello here the chain is not available {:?}", &keys); Err(Error::ChainUnavailable) } } - - #[derive(Deserialize, Debug)] pub struct AccountInfo { nonce: u64, @@ -189,7 +189,6 @@ pub struct Data { flags: u128, } - async fn submit<'m, V>( chain: impl Backend, meta: &'m Metadata, @@ -209,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]; @@ -240,12 +239,12 @@ where ) .await?; - - match response { - Response::Value(value) => { + match response { + Response::Value(value) => { log::info!("{:?}", serde_json::to_string(&value)); let str = serde_json::to_string(&value).expect("wrong account info"); - let value: AccountInfo = serde_json::from_str(&str).expect("it must serialize"); + let value: AccountInfo = + serde_json::from_str(&str).expect("it must serialize"); // let account_info: AccountInfo = serde_json::).unwrap(); log::info!("{}", &value.nonce); Ok(value.nonce) @@ -263,28 +262,37 @@ where log::info!("tip_hex: {}", hex::encode(Compact(tip.clone()).encode())); - let extra_params_hex = - hex::encode([Compact(era).encode(), Compact(nonce).encode(), Compact(tip).encode(), vec![0x00u8]].concat()); + let extra_params_hex = hex::encode( + [ + Compact(era).encode(), + Compact(nonce).encode(), + Compact(tip).encode(), + vec![0x00u8], + ] + .concat(), + ); log::info!("extra_params_hex: {}", extra_params_hex); let extensions = (); - // vec![0x00u8] sign extensions - // TODO: implement signed 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(), vec![0x00u8] - ].concat() + vec![era], + Compact(nonce).encode(), + Compact(tip).encode(), + vec![0x00u8], + ] + .concat() }; - log::info!("Hex {:?}", hex::encode(&extra_params)); let additional_params = { @@ -324,11 +332,24 @@ where "System_Version.transaction_version is not a number".into(), ))? as u32; + let genesis_info = chain.block_info(Some(0u32)).await?; + log::info!("genesis_info {:?}", &genesis_info.number); let genesis_block: Vec = chain.block_info(Some(0u32)).await?.into(); log::info!("spec {:?}", &spec_version); log::info!("transaction_version {:?}", &transaction_version); - log::info!("genesis_block {:?}", &genesis_block); + log::info!("genesis_block {:?}", hex::encode(&genesis_block)); + log::info!("genesis_block_hash {:?}", hex::encode(&genesis_info.hash)); + + // let response = query(&chain, meta, "system/BlockHash/0").await?; + // TODO: check why this params were not converted to 0x + // match response { + // Response::Value(value) => { + // let str = serde_json::to_string(&value).expect("helo"); + // log::info!("storage blockhash {:?}", str); + // } + // _ => return Err(Error::BadInput), + // }; [ spec_version.to_le_bytes().to_vec(), @@ -537,16 +558,26 @@ pub struct StorageKey { impl StorageKey { pub fn new>(meta: &PalletMeta, item: &str, map_keys: &[T]) -> Result { + log::info!("item {:?}", item); + let entry = meta .storage() - .map(|s| s.entries().find(|e| e.name() == item)) + .map(|s| s.entries().find(|e| { + log::info!("e.name {:?}", e.name()); + e.name() == item + })) .flatten() .ok_or(Error::StorageKeyNotFound)?; + log::info!("entry {:?}", &entry); + log::info!("meta.name {:?}", &meta.name()); + let key = entry .key(meta.name(), map_keys) .ok_or(Error::StorageKeyNotFound)?; + log::info!("key {:?}", key); + Ok(StorageKey { key, ty: entry.ty_id(), diff --git a/sube/src/rpc.rs b/sube/src/rpc.rs index 741cd4d..3cff250 100644 --- a/sube/src/rpc.rs +++ b/sube/src/rpc.rs @@ -16,9 +16,18 @@ pub trait Rpc: Backend + Send + Sync { async fn rpc(&self, method: &str, params: &[&str]) -> RpcResult; fn convert_params(params: &[&str]) -> Vec> { + + let params_debug = params + .iter() + .map(|p| format!("{}", p)) + .map(RawValue::from_string) + .map(Result::unwrap) + .collect::>(); + + log::info!("rpc_debug {:?}", ¶ms_debug); params .iter() - .map(|p| format!("\"{}\"", p)) + .map(|p| format!("{}", p)) .map(RawValue::from_string) .map(Result::unwrap) .collect::>() @@ -30,7 +39,7 @@ impl Backend for R { async fn query_storage(&self, key: &StorageKey) -> crate::Result> { let key = key.to_string(); log::debug!("StorageKey encoded: {}", key); - self.rpc("state_getStorage", &[&key]).await.map_err(|e| { + self.rpc("state_getStorage", &[&format!("\"{}\"", &key)]).await.map_err(|e| { log::debug!("RPC failure: {}", e); // NOTE it could fail for more reasons crate::Error::StorageKeyNotFound @@ -45,7 +54,7 @@ impl Backend for R { log::debug!("Extrinsic: {}", extrinsic); let res = self - .rpc("author_submitExtrinsic", &[&extrinsic]) + .rpc("author_submitExtrinsic", &[&format!("\"{}\"", &extrinsic)]) .await .map_err(|e| crate::Error::Node(e.to_string()))?; log::debug!("Extrinsic {:x?}", res); @@ -75,6 +84,7 @@ impl Backend for R { let block_hash = if let Some(block_number) = at { let block_number = block_number.to_string(); + block_info(self, &[&block_number]).await? } else { block_info(self, &[]).await? diff --git a/sube/src/ws.rs b/sube/src/ws.rs index 1483456..c30ccd9 100644 --- a/sube/src/ws.rs +++ b/sube/src/ws.rs @@ -52,7 +52,7 @@ unsafe impl Sync for Backend {} impl Rpc for Backend { async fn rpc(&self, method: &str, params: &[&str]) -> RpcResult { let id = self.next_id().await; - info!("RPC `{}` (ID={})", method, id); + info!("RPC `{}`({:?}) (ID={})", method, params, id); // Store a sender that will notify our receiver when a matching message arrives let (sender, recv) = oneshot::channel::(); @@ -68,7 +68,7 @@ impl Rpc for Backend { }) .expect("Request is serializable"); - log::debug!("RPC Request {} ...", &msg[..50]); + log::debug!("RPC Request {} ...", &msg); self.tx .lock()