diff --git a/sube/examples/pallet_communities.rs b/sube/examples/pallet_communities.rs index 2630016..4874e8c 100644 --- a/sube/examples/pallet_communities.rs +++ b/sube/examples/pallet_communities.rs @@ -1,11 +1,23 @@ use env_logger; +use futures_util::future::join_all; use serde_json; use sube::{sube, ExtrinsicBody, Response, Result, SubeBuilder}; + #[async_std::main] async fn main() -> Result<()> { env_logger::init(); + let response = sube!("wss://kreivo.io/communityMemberships/account/0xe25b1e3758a5fbedb956b36113252f9e866d3ece688364cc9d34eb01f4b2125d/2").await.expect("to work"); + + if let Response::ValueSet(value) = response { + let data = serde_json::to_value(&value).expect("to be serializable"); + println!( + "Collection Array {}", + serde_json::to_string_pretty(&data).expect("it must return an str") + ); + } + let response = sube!("ws://127.0.0.1:12281/communityMemberships/collection").await?; if let Response::ValueSet(value) = response { diff --git a/sube/src/lib.rs b/sube/src/lib.rs index b4a0b67..3b69f8c 100644 --- a/sube/src/lib.rs +++ b/sube/src/lib.rs @@ -388,7 +388,7 @@ pub trait Backend { async fn get_storage_item(&self, key: RawKey, block: Option) -> crate::Result { let res = self.get_storage_items(vec![key], block).await?; - + log::info!("before it died"); res.into_iter() .next() .map(|(_, v)| v) diff --git a/sube/src/rpc.rs b/sube/src/rpc.rs index a84facc..0e87874 100644 --- a/sube/src/rpc.rs +++ b/sube/src/rpc.rs @@ -6,7 +6,7 @@ use serde::Deserialize; use crate::meta::{self, Metadata}; use crate::Backend; use crate::Error; -use crate::{prelude::*, RawKey, StorageChangeSet}; +use crate::{prelude::*, RawKey as RawStorageKey, StorageChangeSet}; use meta::from_bytes; pub type RpcResult = Result; @@ -32,7 +32,7 @@ pub struct RpcClient(pub R); impl Backend for RpcClient { async fn get_storage_items( &self, - keys: Vec, + keys: Vec, block: Option, ) -> crate::Result, Vec)>> { let keys = serde_json::to_string( @@ -54,7 +54,6 @@ impl Backend for RpcClient { vec![keys] }; - let result = self .0 .rpc::>( @@ -71,28 +70,31 @@ impl Backend for RpcClient { crate::Error::StorageKeyNotFound })?; - if let Some(change_set) = result.into_iter().next() { - let keys_response = change_set.changes.into_iter().map(|[k, v]| { - log::info!("key: {} value: {}", k, v); - - ( - hex::decode(&k[2..]).expect("to be an hex"), - hex::decode(&v[2..]).expect("to be an hex"), - ) - }); + let result = match result.into_iter().next() { + None => vec![], + Some(change_set) => change_set + .changes + .into_iter() + .map(|[k, v]| { + log::info!("key: {} value: {}", k, v); + + ( + hex::decode(&k[2..]).expect("to be an hex"), + hex::decode(&v[2..]).expect("to be an hex"), + ) + }) + .collect(), + }; - Ok(keys_response) - } else { - Err(crate::Error::StorageKeyNotFound) - } + Ok(result.into_iter()) } async fn get_keys_paged( &self, - from: RawKey, + from: RawStorageKey, size: u16, - to: Option, - ) -> crate::Result> { + to: Option, + ) -> crate::Result> { let result: Vec = self .0 .rpc(