mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 01:41:09 +00:00
cargo fmt with stable defaults (#876)
This commit is contained in:
@@ -12,10 +12,7 @@ pub mod utils;
|
||||
|
||||
pub use storage_client::StorageClient;
|
||||
|
||||
pub use storage_type::{
|
||||
KeyIter,
|
||||
Storage,
|
||||
};
|
||||
pub use storage_type::{KeyIter, Storage};
|
||||
|
||||
// Re-export as this is used in the public API in this module:
|
||||
pub use crate::rpc::types::StorageKey;
|
||||
@@ -24,22 +21,10 @@ pub use crate::rpc::types::StorageKey;
|
||||
/// entry lives and how to properly decode it.
|
||||
pub mod address {
|
||||
pub use super::storage_address::{
|
||||
dynamic,
|
||||
dynamic_root,
|
||||
Address,
|
||||
DynamicAddress,
|
||||
StaticStorageMapKey,
|
||||
StorageAddress,
|
||||
Yes,
|
||||
dynamic, dynamic_root, Address, DynamicAddress, StaticStorageMapKey, StorageAddress, Yes,
|
||||
};
|
||||
}
|
||||
|
||||
// For consistency with other modules, also expose
|
||||
// the basic address stuff at the root of the module.
|
||||
pub use storage_address::{
|
||||
dynamic,
|
||||
dynamic_root,
|
||||
Address,
|
||||
DynamicAddress,
|
||||
StorageAddress,
|
||||
};
|
||||
pub use storage_address::{dynamic, dynamic_root, Address, DynamicAddress, StorageAddress};
|
||||
|
||||
@@ -3,24 +3,11 @@
|
||||
// see LICENSE for license details.
|
||||
|
||||
use crate::{
|
||||
dynamic::{
|
||||
DecodedValueThunk,
|
||||
Value,
|
||||
},
|
||||
error::{
|
||||
Error,
|
||||
StorageAddressError,
|
||||
},
|
||||
metadata::{
|
||||
DecodeWithMetadata,
|
||||
EncodeWithMetadata,
|
||||
Metadata,
|
||||
},
|
||||
};
|
||||
use frame_metadata::{
|
||||
StorageEntryType,
|
||||
StorageHasher,
|
||||
dynamic::{DecodedValueThunk, Value},
|
||||
error::{Error, StorageAddressError},
|
||||
metadata::{DecodeWithMetadata, EncodeWithMetadata, Metadata},
|
||||
};
|
||||
use frame_metadata::{StorageEntryType, StorageHasher};
|
||||
use scale_info::TypeDef;
|
||||
use std::borrow::Cow;
|
||||
|
||||
@@ -47,11 +34,7 @@ pub trait StorageAddress {
|
||||
|
||||
/// Output the non-prefix bytes; that is, any additional bytes that need
|
||||
/// to be appended to the key to dig into maps.
|
||||
fn append_entry_bytes(
|
||||
&self,
|
||||
metadata: &Metadata,
|
||||
bytes: &mut Vec<u8>,
|
||||
) -> Result<(), Error>;
|
||||
fn append_entry_bytes(&self, metadata: &Metadata, bytes: &mut Vec<u8>) -> Result<(), Error>;
|
||||
|
||||
/// An optional hash which, if present, will be checked against
|
||||
/// the node metadata to confirm that the return type matches what
|
||||
@@ -77,8 +60,7 @@ pub struct Address<StorageKey, ReturnTy, Fetchable, Defaultable, Iterable> {
|
||||
|
||||
/// A typical storage address constructed at runtime rather than via the `subxt` macro; this
|
||||
/// has no restriction on what it can be used for (since we don't statically know).
|
||||
pub type DynamicAddress<StorageKey> =
|
||||
Address<StorageKey, DecodedValueThunk, Yes, Yes, Yes>;
|
||||
pub type DynamicAddress<StorageKey> = Address<StorageKey, DecodedValueThunk, Yes, Yes, Yes>;
|
||||
|
||||
impl<StorageKey, ReturnTy, Fetchable, Defaultable, Iterable>
|
||||
Address<StorageKey, ReturnTy, Fetchable, Defaultable, Iterable>
|
||||
@@ -154,11 +136,7 @@ where
|
||||
&self.entry_name
|
||||
}
|
||||
|
||||
fn append_entry_bytes(
|
||||
&self,
|
||||
metadata: &Metadata,
|
||||
bytes: &mut Vec<u8>,
|
||||
) -> Result<(), Error> {
|
||||
fn append_entry_bytes(&self, metadata: &Metadata, bytes: &mut Vec<u8>) -> Result<(), Error> {
|
||||
let pallet = metadata.pallet(&self.pallet_name)?;
|
||||
let storage = pallet.storage(&self.entry_name)?;
|
||||
|
||||
@@ -193,7 +171,7 @@ where
|
||||
expected: type_ids.len(),
|
||||
actual: self.storage_entry_keys.len(),
|
||||
}
|
||||
.into())
|
||||
.into());
|
||||
}
|
||||
|
||||
if hashers.len() == 1 {
|
||||
|
||||
@@ -3,27 +3,17 @@
|
||||
// see LICENSE for license details.
|
||||
|
||||
use super::{
|
||||
storage_type::{
|
||||
validate_storage_address,
|
||||
Storage,
|
||||
},
|
||||
utils,
|
||||
StorageAddress,
|
||||
storage_type::{validate_storage_address, Storage},
|
||||
utils, StorageAddress,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
client::{
|
||||
OfflineClientT,
|
||||
OnlineClientT,
|
||||
},
|
||||
client::{OfflineClientT, OnlineClientT},
|
||||
error::Error,
|
||||
Config,
|
||||
};
|
||||
use derivative::Derivative;
|
||||
use std::{
|
||||
future::Future,
|
||||
marker::PhantomData,
|
||||
};
|
||||
use std::{future::Future, marker::PhantomData};
|
||||
|
||||
/// Query the runtime storage.
|
||||
#[derive(Derivative)]
|
||||
@@ -52,19 +42,13 @@ where
|
||||
/// if the address is valid (or if it's not possible to check since the address has no validation hash).
|
||||
/// Return an error if the address was not valid or something went wrong trying to validate it (ie
|
||||
/// the pallet or storage entry in question do not exist at all).
|
||||
pub fn validate<Address: StorageAddress>(
|
||||
&self,
|
||||
address: &Address,
|
||||
) -> Result<(), Error> {
|
||||
pub fn validate<Address: StorageAddress>(&self, address: &Address) -> Result<(), Error> {
|
||||
validate_storage_address(address, &self.client.metadata())
|
||||
}
|
||||
|
||||
/// Convert some storage address into the raw bytes that would be submitted to the node in order
|
||||
/// to retrieve the entries at the root of the associated address.
|
||||
pub fn address_root_bytes<Address: StorageAddress>(
|
||||
&self,
|
||||
address: &Address,
|
||||
) -> Vec<u8> {
|
||||
pub fn address_root_bytes<Address: StorageAddress>(&self, address: &Address) -> Vec<u8> {
|
||||
utils::storage_address_root_bytes(address)
|
||||
}
|
||||
|
||||
@@ -99,13 +83,11 @@ where
|
||||
// for the latest block and use that.
|
||||
let block_hash = match block_hash {
|
||||
Some(hash) => hash,
|
||||
None => {
|
||||
client
|
||||
.rpc()
|
||||
.block_hash(None)
|
||||
.await?
|
||||
.expect("didn't pass a block number; qed")
|
||||
}
|
||||
None => client
|
||||
.rpc()
|
||||
.block_hash(None)
|
||||
.await?
|
||||
.expect("didn't pass a block number; qed"),
|
||||
};
|
||||
|
||||
Ok(Storage::new(client, block_hash))
|
||||
|
||||
@@ -2,30 +2,18 @@
|
||||
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
|
||||
// see LICENSE for license details.
|
||||
|
||||
use super::storage_address::{
|
||||
StorageAddress,
|
||||
Yes,
|
||||
};
|
||||
use super::storage_address::{StorageAddress, Yes};
|
||||
use crate::{
|
||||
client::OnlineClientT,
|
||||
error::Error,
|
||||
metadata::{
|
||||
DecodeWithMetadata,
|
||||
Metadata,
|
||||
},
|
||||
rpc::types::{
|
||||
StorageData,
|
||||
StorageKey,
|
||||
},
|
||||
metadata::{DecodeWithMetadata, Metadata},
|
||||
rpc::types::{StorageData, StorageKey},
|
||||
Config,
|
||||
};
|
||||
use derivative::Derivative;
|
||||
use frame_metadata::StorageEntryType;
|
||||
use scale_info::form::PortableForm;
|
||||
use std::{
|
||||
future::Future,
|
||||
marker::PhantomData,
|
||||
};
|
||||
use std::{future::Future, marker::PhantomData};
|
||||
|
||||
/// Query the runtime storage.
|
||||
#[derive(Derivative)]
|
||||
@@ -150,15 +138,10 @@ where
|
||||
// We have to dig into metadata already, so no point using the optimised `decode_storage_with_metadata` call.
|
||||
let pallet_metadata = metadata.pallet(pallet_name)?;
|
||||
let storage_metadata = pallet_metadata.storage(storage_name)?;
|
||||
let return_ty_id =
|
||||
return_type_from_storage_entry_type(&storage_metadata.ty);
|
||||
let return_ty_id = return_type_from_storage_entry_type(&storage_metadata.ty);
|
||||
let bytes = &mut &storage_metadata.default[..];
|
||||
|
||||
let val = Address::Target::decode_with_metadata(
|
||||
bytes,
|
||||
return_ty_id,
|
||||
&metadata,
|
||||
)?;
|
||||
let val = Address::Target::decode_with_metadata(bytes, return_ty_id, &metadata)?;
|
||||
Ok(val)
|
||||
}
|
||||
}
|
||||
@@ -237,11 +220,8 @@ where
|
||||
// Look up the return type for flexible decoding. Do this once here to avoid
|
||||
// potentially doing it every iteration if we used `decode_storage_with_metadata`
|
||||
// in the iterator.
|
||||
let return_type_id = lookup_storage_return_type(
|
||||
&metadata,
|
||||
address.pallet_name(),
|
||||
address.entry_name(),
|
||||
)?;
|
||||
let return_type_id =
|
||||
lookup_storage_return_type(&metadata, address.pallet_name(), address.entry_name())?;
|
||||
|
||||
// The root pallet/entry bytes for this storage entry:
|
||||
let address_root_bytes = super::utils::storage_address_root_bytes(&address);
|
||||
@@ -289,7 +269,7 @@ where
|
||||
self.return_type_id,
|
||||
&self.metadata,
|
||||
)?;
|
||||
return Ok(Some((k, val)))
|
||||
return Ok(Some((k, val)));
|
||||
} else {
|
||||
let start_key = self.start_key.take();
|
||||
let keys = self
|
||||
@@ -302,7 +282,7 @@ where
|
||||
.await?;
|
||||
|
||||
if keys.is_empty() {
|
||||
return Ok(None)
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
self.start_key = keys.last().cloned();
|
||||
@@ -350,13 +330,11 @@ fn validate_storage(
|
||||
};
|
||||
match expected_hash == hash {
|
||||
true => Ok(()),
|
||||
false => {
|
||||
Err(crate::error::MetadataError::IncompatibleStorageMetadata(
|
||||
pallet_name.into(),
|
||||
storage_name.into(),
|
||||
)
|
||||
.into())
|
||||
}
|
||||
false => Err(crate::error::MetadataError::IncompatibleStorageMetadata(
|
||||
pallet_name.into(),
|
||||
storage_name.into(),
|
||||
)
|
||||
.into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,7 @@
|
||||
//! the trait itself.
|
||||
|
||||
use super::StorageAddress;
|
||||
use crate::{
|
||||
error::Error,
|
||||
metadata::Metadata,
|
||||
};
|
||||
use crate::{error::Error, metadata::Metadata};
|
||||
|
||||
/// Return the root of a given [`StorageAddress`]: hash the pallet name and entry name
|
||||
/// and append those bytes to the output.
|
||||
@@ -35,9 +32,7 @@ pub(crate) fn storage_address_bytes<Address: StorageAddress>(
|
||||
}
|
||||
|
||||
/// Outputs a vector containing the bytes written by [`write_storage_address_root_bytes`].
|
||||
pub(crate) fn storage_address_root_bytes<Address: StorageAddress>(
|
||||
addr: &Address,
|
||||
) -> Vec<u8> {
|
||||
pub(crate) fn storage_address_root_bytes<Address: StorageAddress>(addr: &Address) -> Vec<u8> {
|
||||
let mut bytes = Vec::new();
|
||||
write_storage_address_root_bytes(addr, &mut bytes);
|
||||
bytes
|
||||
|
||||
Reference in New Issue
Block a user