mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-01 10:07:24 +00:00
Rename traits to remove T suffix (#1535)
* Rename traits to renmove T suffix * Fix doc links * Fix straggler doc links
This commit is contained in:
@@ -21,7 +21,7 @@ pub use super::storage_key::{StaticStorageKey, StorageHashers, StorageHashersIte
|
||||
|
||||
/// This represents a storage address. Anything implementing this trait
|
||||
/// can be used to fetch and iterate over storage entries.
|
||||
pub trait AddressT {
|
||||
pub trait Address {
|
||||
/// The target type of the value that lives at this address.
|
||||
type Target: DecodeWithMetadata;
|
||||
/// The keys type used to construct this address.
|
||||
@@ -57,7 +57,7 @@ pub trait AddressT {
|
||||
/// A concrete storage address. This can be created from static values (ie those generated
|
||||
/// via the `subxt` macro) or dynamic values via [`dynamic`].
|
||||
#[derive_where(Clone, Debug, Eq, Ord, PartialEq, PartialOrd; Keys)]
|
||||
pub struct Address<Keys: StorageKey, ReturnTy, Fetchable, Defaultable, Iterable> {
|
||||
pub struct DefaultAddress<Keys: StorageKey, ReturnTy, Fetchable, Defaultable, Iterable> {
|
||||
pallet_name: Cow<'static, str>,
|
||||
entry_name: Cow<'static, str>,
|
||||
keys: Keys,
|
||||
@@ -65,9 +65,12 @@ pub struct Address<Keys: StorageKey, ReturnTy, Fetchable, Defaultable, Iterable>
|
||||
_marker: core::marker::PhantomData<(ReturnTy, Fetchable, Defaultable, Iterable)>,
|
||||
}
|
||||
|
||||
/// A storage address constructed by the static codegen.
|
||||
pub type StaticAddress<Keys, ReturnTy, Fetchable, Defaultable, Iterable> =
|
||||
DefaultAddress<Keys, 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<Keys> = Address<Keys, DecodedValueThunk, Yes, Yes, Yes>;
|
||||
pub type DynamicAddress<Keys> = DefaultAddress<Keys, DecodedValueThunk, Yes, Yes, Yes>;
|
||||
|
||||
impl<Keys: StorageKey> DynamicAddress<Keys> {
|
||||
/// Creates a new dynamic address. As `Keys` you can use a `Vec<scale_value::Value>`
|
||||
@@ -83,7 +86,7 @@ impl<Keys: StorageKey> DynamicAddress<Keys> {
|
||||
}
|
||||
|
||||
impl<Keys, ReturnTy, Fetchable, Defaultable, Iterable>
|
||||
Address<Keys, ReturnTy, Fetchable, Defaultable, Iterable>
|
||||
DefaultAddress<Keys, ReturnTy, Fetchable, Defaultable, Iterable>
|
||||
where
|
||||
Keys: StorageKey,
|
||||
ReturnTy: DecodeWithMetadata,
|
||||
@@ -108,7 +111,7 @@ where
|
||||
}
|
||||
|
||||
impl<Keys, ReturnTy, Fetchable, Defaultable, Iterable>
|
||||
Address<Keys, ReturnTy, Fetchable, Defaultable, Iterable>
|
||||
DefaultAddress<Keys, ReturnTy, Fetchable, Defaultable, Iterable>
|
||||
where
|
||||
Keys: StorageKey,
|
||||
ReturnTy: DecodeWithMetadata,
|
||||
@@ -127,8 +130,8 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<Keys, ReturnTy, Fetchable, Defaultable, Iterable> AddressT
|
||||
for Address<Keys, ReturnTy, Fetchable, Defaultable, Iterable>
|
||||
impl<Keys, ReturnTy, Fetchable, Defaultable, Iterable> Address
|
||||
for DefaultAddress<Keys, ReturnTy, Fetchable, Defaultable, Iterable>
|
||||
where
|
||||
Keys: StorageKey,
|
||||
ReturnTy: DecodeWithMetadata,
|
||||
|
||||
+13
-13
@@ -47,7 +47,7 @@ mod utils;
|
||||
pub mod address;
|
||||
|
||||
use crate::{error::MetadataError, metadata::DecodeWithMetadata, Error, Metadata};
|
||||
use address::AddressT;
|
||||
use address::Address;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
// This isn't a part of the public API, but expose here because it's useful in Subxt.
|
||||
@@ -59,7 +59,7 @@ pub use utils::lookup_storage_entry_details;
|
||||
///
|
||||
/// When the provided `address` is dynamic (and thus does not come with any expectation of the
|
||||
/// shape of the constant value), this just returns `Ok(())`
|
||||
pub fn validate<Address: AddressT>(address: &Address, metadata: &Metadata) -> Result<(), Error> {
|
||||
pub fn validate<Addr: Address>(address: &Addr, metadata: &Metadata) -> Result<(), Error> {
|
||||
let Some(hash) = address.validation_hash() else {
|
||||
return Ok(());
|
||||
};
|
||||
@@ -80,8 +80,8 @@ pub fn validate<Address: AddressT>(address: &Address, metadata: &Metadata) -> Re
|
||||
|
||||
/// Given a storage address and some metadata, this encodes the address into bytes which can be
|
||||
/// handed to a node to retrieve the corresponding value.
|
||||
pub fn get_address_bytes<Address: AddressT>(
|
||||
address: &Address,
|
||||
pub fn get_address_bytes<Addr: Address>(
|
||||
address: &Addr,
|
||||
metadata: &Metadata,
|
||||
) -> Result<Vec<u8>, Error> {
|
||||
let mut bytes = Vec::new();
|
||||
@@ -93,7 +93,7 @@ pub fn get_address_bytes<Address: AddressT>(
|
||||
/// Given a storage address and some metadata, this encodes the root of the address (ie the pallet
|
||||
/// and storage entry part) into bytes. If the entry being addressed is inside a map, this returns
|
||||
/// the bytes needed to iterate over all of the entries within it.
|
||||
pub fn get_address_root_bytes<Address: AddressT>(address: &Address) -> Vec<u8> {
|
||||
pub fn get_address_root_bytes<Addr: Address>(address: &Addr) -> Vec<u8> {
|
||||
let mut bytes = Vec::new();
|
||||
utils::write_storage_address_root_bytes(address, &mut bytes);
|
||||
bytes
|
||||
@@ -102,11 +102,11 @@ pub fn get_address_root_bytes<Address: AddressT>(address: &Address) -> Vec<u8> {
|
||||
/// Given some storage value that we've retrieved from a node, the address used to retrieve it, and
|
||||
/// metadata from the node, this function attempts to decode the bytes into the target value specified
|
||||
/// by the address.
|
||||
pub fn decode_value<Address: AddressT>(
|
||||
pub fn decode_value<Addr: Address>(
|
||||
bytes: &mut &[u8],
|
||||
address: &Address,
|
||||
address: &Addr,
|
||||
metadata: &Metadata,
|
||||
) -> Result<Address::Target, Error> {
|
||||
) -> Result<Addr::Target, Error> {
|
||||
let pallet_name = address.pallet_name();
|
||||
let entry_name = address.entry_name();
|
||||
|
||||
@@ -117,15 +117,15 @@ pub fn decode_value<Address: AddressT>(
|
||||
subxt_metadata::StorageEntryType::Map { value_ty, .. } => *value_ty,
|
||||
};
|
||||
|
||||
let val = Address::Target::decode_with_metadata(bytes, value_ty_id, metadata)?;
|
||||
let val = Addr::Target::decode_with_metadata(bytes, value_ty_id, metadata)?;
|
||||
Ok(val)
|
||||
}
|
||||
|
||||
/// Return the default value at a given storage address if one is available, or an error otherwise.
|
||||
pub fn default_value<Address: AddressT>(
|
||||
address: &Address,
|
||||
pub fn default_value<Addr: Address>(
|
||||
address: &Addr,
|
||||
metadata: &Metadata,
|
||||
) -> Result<Address::Target, Error> {
|
||||
) -> Result<Addr::Target, Error> {
|
||||
let pallet_name = address.pallet_name();
|
||||
let entry_name = address.entry_name();
|
||||
|
||||
@@ -137,6 +137,6 @@ pub fn default_value<Address: AddressT>(
|
||||
};
|
||||
|
||||
let default_bytes = entry_metadata.default_bytes();
|
||||
let val = Address::Target::decode_with_metadata(&mut &*default_bytes, value_ty_id, metadata)?;
|
||||
let val = Addr::Target::decode_with_metadata(&mut &*default_bytes, value_ty_id, metadata)?;
|
||||
Ok(val)
|
||||
}
|
||||
|
||||
@@ -2,20 +2,20 @@
|
||||
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
|
||||
// see LICENSE for license details.
|
||||
|
||||
//! these utility methods complement the [`AddressT`] trait, but
|
||||
//! these utility methods complement the [`Address`] trait, but
|
||||
//! aren't things that should ever be overridden, and so don't exist on
|
||||
//! the trait itself.
|
||||
|
||||
use super::address::AddressT;
|
||||
use super::address::Address;
|
||||
use crate::error::{Error, MetadataError};
|
||||
use crate::metadata::Metadata;
|
||||
use alloc::borrow::ToOwned;
|
||||
use alloc::vec::Vec;
|
||||
use subxt_metadata::{PalletMetadata, StorageEntryMetadata, StorageHasher};
|
||||
|
||||
/// Return the root of a given [`AddressT`]: hash the pallet name and entry name
|
||||
/// Return the root of a given [`Address`]: hash the pallet name and entry name
|
||||
/// and append those bytes to the output.
|
||||
pub fn write_storage_address_root_bytes<Address: AddressT>(addr: &Address, out: &mut Vec<u8>) {
|
||||
pub fn write_storage_address_root_bytes<Addr: Address>(addr: &Addr, out: &mut Vec<u8>) {
|
||||
out.extend(sp_crypto_hashing::twox_128(addr.pallet_name().as_bytes()));
|
||||
out.extend(sp_crypto_hashing::twox_128(addr.entry_name().as_bytes()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user