Skip to content

Commit

Permalink
chore: fix clipply errors
Browse files Browse the repository at this point in the history
  • Loading branch information
S0c5 committed Aug 18, 2024
1 parent 4531532 commit c87bf6b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 25 deletions.
2 changes: 1 addition & 1 deletion sube/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
meta::BlockInfo, Backend, Error, ExtrinsicBody, Metadata, Response, Result as SubeResult,
Signer, StorageKey,
};
use crate::{prelude::*, Offline, StorageChangeSet};
use crate::{prelude::*, Offline};

use core::future::{Future, IntoFuture};
use url::Url;
Expand Down
27 changes: 5 additions & 22 deletions sube/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ async fn query<'m>(
let block = match block {
Some(block) if block.starts_with("0x") => Some(block),
Some(block) => {
let block_number =
u32::from_str_radix(&block, 10).expect("blockhash to be a number or either a hash");
let block_number = block
.parse::<u32>()
.expect("blockhash to be a number or either a hash");
let info = chain.block_info(Some(block_number)).await?;
Some(format!("0x{}", hex::encode(info.hash)))
}
Expand All @@ -124,32 +125,15 @@ async fn query<'m>(
let value = result
.into_iter()
.map(|(key, data)| {
log::info!("- key: {}", hex::encode(&key));
log::info!("- data: {}", hex::encode(&data));

log::info!("[+] pallet: {}", hex::encode(&key_res.pallet));
log::info!("[+] call: {}", hex::encode(&key_res.call));

log::info!("[+] pallet_size: {}", key_res.pallet.len());
log::info!("[+] call_size: {}", key_res.call.len());

let key = &key[(key_res.pallet.len() + key_res.call.len())..];

log::info!("- result: {}", hex::encode(&key));

let mut offset = 16; // TODO it depends on the hasher used to encode the key, then the size could change
let keys = key_res
.args
.iter()
.map(|arg| match arg {
KeyValue::Empty(type_id) | KeyValue::Value((type_id, _, _, _)) => {
let hashed = &key[offset..];
log::info!("hashed: {}", hex::encode(&hashed));
log::info!(" {:?}", &arg);

let value = Value::new(hashed.to_vec(), *type_id, &meta.types);

log::info!("value done!");
offset += value.size() + 16;
value
}
Expand Down Expand Up @@ -435,11 +419,10 @@ pub trait Backend {

async fn get_storage_item(&self, key: String, block: Option<String>) -> crate::Result<Vec<u8>> {
let res = self.get_storage_items(vec![key], block).await?;
Ok(res
.into_iter()
res.into_iter()
.next()
.map(|(_, v)| v)
.ok_or(Error::StorageKeyNotFound)?)
.ok_or(Error::StorageKeyNotFound)
}

async fn get_keys_paged(
Expand Down
4 changes: 2 additions & 2 deletions sube/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ impl<R: Rpc> Backend for RpcClient<R> {
)
});

return Ok(keys_response);
Ok(keys_response)
} else {
return Err(crate::Error::StorageKeyNotFound);
Err(crate::Error::StorageKeyNotFound)
}
}

Expand Down

0 comments on commit c87bf6b

Please sign in to comment.