mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 03:01:07 +00:00
Update to 2024 edition (#2001)
* Update to 2024 edition * Update to 2024 edition; fmt, use<> and remove refs * async functions
This commit is contained in:
@@ -2,12 +2,12 @@
|
||||
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
|
||||
// see LICENSE for license details.
|
||||
|
||||
use crate::config::TransactionExtension;
|
||||
use crate::config::transaction_extensions::{
|
||||
ChargeAssetTxPayment, ChargeTransactionPayment, CheckNonce,
|
||||
};
|
||||
use crate::config::TransactionExtension;
|
||||
use crate::dynamic::Value;
|
||||
use crate::{config::Config, error::Error, Metadata};
|
||||
use crate::{Metadata, config::Config, error::Error};
|
||||
use frame_decode::extrinsics::ExtrinsicExtensions;
|
||||
use scale_decode::DecodeAsType;
|
||||
|
||||
@@ -35,7 +35,7 @@ impl<'a, T: Config> ExtrinsicTransactionExtensions<'a, T> {
|
||||
}
|
||||
|
||||
/// Returns an iterator over each of the signed extension details of the extrinsic.
|
||||
pub fn iter(&self) -> impl Iterator<Item = ExtrinsicTransactionExtension<T>> {
|
||||
pub fn iter(&self) -> impl Iterator<Item = ExtrinsicTransactionExtension<'a, T>> + use<'a, T> {
|
||||
self.decoded_info
|
||||
.iter()
|
||||
.map(|s| ExtrinsicTransactionExtension {
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
use super::BlockError;
|
||||
use crate::blocks::extrinsic_transaction_extensions::ExtrinsicTransactionExtensions;
|
||||
use crate::{
|
||||
Metadata,
|
||||
config::{Config, HashFor, Hasher},
|
||||
error::{Error, MetadataError},
|
||||
Metadata,
|
||||
};
|
||||
use alloc::sync::Arc;
|
||||
use alloc::vec::Vec;
|
||||
@@ -106,7 +106,7 @@ impl<T: Config> Extrinsics<T> {
|
||||
/// If an error occurs, all subsequent iterations return `None`.
|
||||
pub fn find<E: StaticExtrinsic>(
|
||||
&self,
|
||||
) -> impl Iterator<Item = Result<FoundExtrinsic<T, E>, Error>> + '_ {
|
||||
) -> impl Iterator<Item = Result<FoundExtrinsic<T, E>, Error>> {
|
||||
self.iter().filter_map(|details| {
|
||||
match details.as_extrinsic::<E>() {
|
||||
// Failed to decode extrinsic:
|
||||
@@ -367,10 +367,10 @@ mod tests {
|
||||
use codec::{Decode, Encode};
|
||||
use frame_metadata::v15::{CustomMetadata, OuterEnums};
|
||||
use frame_metadata::{
|
||||
v15::{ExtrinsicMetadata, PalletCallMetadata, PalletMetadata, RuntimeMetadataV15},
|
||||
RuntimeMetadataPrefixed,
|
||||
v15::{ExtrinsicMetadata, PalletCallMetadata, PalletMetadata, RuntimeMetadataV15},
|
||||
};
|
||||
use scale_info::{meta_type, TypeInfo};
|
||||
use scale_info::{TypeInfo, meta_type};
|
||||
use scale_value::Value;
|
||||
|
||||
// Extrinsic needs to contain at least the generic type parameter "Call"
|
||||
|
||||
@@ -68,9 +68,9 @@ mod extrinsic_transaction_extensions;
|
||||
mod extrinsics;
|
||||
mod static_extrinsic;
|
||||
|
||||
use crate::Metadata;
|
||||
use crate::config::Config;
|
||||
use crate::error::Error;
|
||||
use crate::Metadata;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
pub use crate::error::BlockError;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// see LICENSE for license details.
|
||||
|
||||
use super::Config;
|
||||
use super::{transaction_extensions, ExtrinsicParams};
|
||||
use super::{ExtrinsicParams, transaction_extensions};
|
||||
|
||||
/// The default [`super::ExtrinsicParams`] implementation understands common signed extensions
|
||||
/// and how to apply them to a given chain.
|
||||
|
||||
@@ -19,7 +19,7 @@ use codec::{Decode, Encode};
|
||||
use core::fmt::Debug;
|
||||
use scale_decode::DecodeAsType;
|
||||
use scale_encode::EncodeAsType;
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
use serde::{Serialize, de::DeserializeOwned};
|
||||
use subxt_metadata::Metadata;
|
||||
|
||||
pub use default_extrinsic_params::{DefaultExtrinsicParams, DefaultExtrinsicParamsBuilder};
|
||||
|
||||
@@ -43,7 +43,7 @@ pub mod address;
|
||||
use address::Address;
|
||||
use alloc::borrow::ToOwned;
|
||||
|
||||
use crate::{error::MetadataError, metadata::DecodeWithMetadata, Error, Metadata};
|
||||
use crate::{Error, Metadata, error::MetadataError, metadata::DecodeWithMetadata};
|
||||
|
||||
/// When the provided `address` is statically generated via the `#[subxt]` macro, this validates
|
||||
/// that the shape of the constant value is the same as the shape expected by the static address.
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
pub mod address;
|
||||
|
||||
use crate::utils::Yes;
|
||||
use crate::{error::MetadataError, metadata::DecodeWithMetadata, Error, Metadata};
|
||||
use crate::{Error, Metadata, error::MetadataError, metadata::DecodeWithMetadata};
|
||||
use address::Address;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
@@ -96,8 +96,8 @@ mod tests {
|
||||
use alloc::collections::BTreeMap;
|
||||
use codec::Encode;
|
||||
use scale_decode::DecodeAsType;
|
||||
use scale_info::form::PortableForm;
|
||||
use scale_info::TypeInfo;
|
||||
use scale_info::form::PortableForm;
|
||||
|
||||
use alloc::borrow::ToOwned;
|
||||
use alloc::string::String;
|
||||
|
||||
+9
-3
@@ -53,7 +53,9 @@ impl From<codec::Error> for Error {
|
||||
#[derive(Debug, DeriveError)]
|
||||
pub enum BlockError {
|
||||
/// Leftover bytes found after decoding the extrinsic.
|
||||
#[error("After decoding the extrinsic at index {extrinsic_index}, {num_leftover_bytes} bytes were left, suggesting that decoding may have failed")]
|
||||
#[error(
|
||||
"After decoding the extrinsic at index {extrinsic_index}, {num_leftover_bytes} bytes were left, suggesting that decoding may have failed"
|
||||
)]
|
||||
LeftoverBytes {
|
||||
/// Index of the extrinsic that failed to decode.
|
||||
extrinsic_index: usize,
|
||||
@@ -153,10 +155,14 @@ pub enum StorageAddressError {
|
||||
#[error("We have leftover bytes after decoding the storage address")]
|
||||
TooManyBytes,
|
||||
/// The bytes of a storage address are not the expected address for decoding the storage keys of the address.
|
||||
#[error("Storage address bytes are not the expected format. Addresses need to be at least 16 bytes (pallet ++ entry) and follow a structure given by the hashers defined in the metadata")]
|
||||
#[error(
|
||||
"Storage address bytes are not the expected format. Addresses need to be at least 16 bytes (pallet ++ entry) and follow a structure given by the hashers defined in the metadata"
|
||||
)]
|
||||
UnexpectedAddressBytes,
|
||||
/// An invalid hasher was used to reconstruct a value from a chunk of bytes that is part of a storage address. Hashers where the hash does not contain the original value are invalid for this purpose.
|
||||
#[error("An invalid hasher was used to reconstruct a value with type ID {ty_id} from a hash formed by a {hasher:?} hasher. This is only possible for concat-style hashers or the identity hasher")]
|
||||
#[error(
|
||||
"An invalid hasher was used to reconstruct a value with type ID {ty_id} from a hash formed by a {hasher:?} hasher. This is only possible for concat-style hashers or the identity hasher"
|
||||
)]
|
||||
HasherCannotReconstructKey {
|
||||
/// Type id of the key's type.
|
||||
ty_id: u32,
|
||||
|
||||
+5
-5
@@ -46,9 +46,9 @@ use scale_decode::{DecodeAsFields, DecodeAsType};
|
||||
use subxt_metadata::PalletMetadata;
|
||||
|
||||
use crate::{
|
||||
Error, Metadata,
|
||||
config::{Config, HashFor},
|
||||
error::MetadataError,
|
||||
Error, Metadata,
|
||||
};
|
||||
|
||||
/// Create a new [`Events`] instance from the given bytes.
|
||||
@@ -184,7 +184,7 @@ impl<T: Config> Events<T> {
|
||||
/// Iterate through the events using metadata to dynamically decode and skip
|
||||
/// them, and return only those which should decode to the provided `Ev` type.
|
||||
/// If an error occurs, all subsequent iterations return `None`.
|
||||
pub fn find<Ev: StaticEvent>(&self) -> impl Iterator<Item = Result<Ev, Error>> + '_ {
|
||||
pub fn find<Ev: StaticEvent>(&self) -> impl Iterator<Item = Result<Ev, Error>> {
|
||||
self.iter()
|
||||
.filter_map(|ev| ev.and_then(|ev| ev.as_event::<Ev>()).transpose())
|
||||
}
|
||||
@@ -437,13 +437,13 @@ pub(crate) mod test_utils {
|
||||
use crate::config::{HashFor, SubstrateConfig};
|
||||
use codec::Encode;
|
||||
use frame_metadata::{
|
||||
RuntimeMetadataPrefixed,
|
||||
v15::{
|
||||
CustomMetadata, ExtrinsicMetadata, OuterEnums, PalletEventMetadata, PalletMetadata,
|
||||
RuntimeMetadataV15,
|
||||
},
|
||||
RuntimeMetadataPrefixed,
|
||||
};
|
||||
use scale_info::{meta_type, TypeInfo};
|
||||
use scale_info::{TypeInfo, meta_type};
|
||||
|
||||
/// An "outer" events enum containing exactly one event.
|
||||
#[derive(
|
||||
@@ -587,7 +587,7 @@ pub(crate) mod test_utils {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
test_utils::{event_record, events, events_raw, AllEvents, EventRecord},
|
||||
test_utils::{AllEvents, EventRecord, event_record, events, events_raw},
|
||||
*,
|
||||
};
|
||||
use crate::config::SubstrateConfig;
|
||||
|
||||
@@ -14,9 +14,9 @@ use derive_where::derive_where;
|
||||
use scale_encode::EncodeAsFields;
|
||||
use scale_value::Composite;
|
||||
|
||||
use crate::Error;
|
||||
use crate::dynamic::DecodedValueThunk;
|
||||
use crate::error::MetadataError;
|
||||
use crate::Error;
|
||||
|
||||
use crate::metadata::{DecodeWithMetadata, Metadata};
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ mod utils;
|
||||
|
||||
pub mod address;
|
||||
|
||||
use crate::{error::MetadataError, metadata::DecodeWithMetadata, Error, Metadata};
|
||||
use crate::{Error, Metadata, error::MetadataError, metadata::DecodeWithMetadata};
|
||||
use address::Address;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ impl<K: codec::Decode> StaticStorageKey<K> {
|
||||
impl<K: ?Sized> StaticStorageKey<K> {
|
||||
/// Returns the scale-encoded bytes that make up this key
|
||||
pub fn bytes(&self) -> &[u8] {
|
||||
&self.bytes.0 .0
|
||||
&self.bytes.0.0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,7 +361,7 @@ const _: () = {
|
||||
mod tests {
|
||||
|
||||
use codec::Encode;
|
||||
use scale_info::{meta_type, PortableRegistry, Registry, TypeInfo};
|
||||
use scale_info::{PortableRegistry, Registry, TypeInfo, meta_type};
|
||||
use subxt_metadata::StorageHasher;
|
||||
|
||||
use crate::utils::Era;
|
||||
@@ -463,15 +463,15 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(keys_a.1.decoded().unwrap(), 13);
|
||||
assert_eq!(keys_b.1 .0.decoded().unwrap(), 13);
|
||||
assert_eq!(keys_c.0 .1.decoded().unwrap(), 13);
|
||||
assert_eq!(keys_b.1.0.decoded().unwrap(), 13);
|
||||
assert_eq!(keys_c.0.1.decoded().unwrap(), 13);
|
||||
|
||||
assert_eq!(keys_a.2.decoded().unwrap(), "Hello");
|
||||
assert_eq!(keys_b.1 .1.decoded().unwrap(), "Hello");
|
||||
assert_eq!(keys_c.1 .0.decoded().unwrap(), "Hello");
|
||||
assert_eq!(keys_b.1.1.decoded().unwrap(), "Hello");
|
||||
assert_eq!(keys_c.1.0.decoded().unwrap(), "Hello");
|
||||
assert_eq!(keys_a.3.decoded().unwrap(), era);
|
||||
assert_eq!(keys_b.2.decoded().unwrap(), era);
|
||||
assert_eq!(keys_c.1 .1.decoded().unwrap(), era);
|
||||
assert_eq!(keys_c.1.1.decoded().unwrap(), era);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
//! This module contains the trait and types used to represent
|
||||
//! transactions that can be submitted.
|
||||
|
||||
use crate::Error;
|
||||
use crate::error::MetadataError;
|
||||
use crate::metadata::Metadata;
|
||||
use crate::Error;
|
||||
use alloc::borrow::{Cow, ToOwned};
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::String;
|
||||
|
||||
@@ -9,8 +9,8 @@ use alloc::vec::Vec;
|
||||
use codec::{Compact, Input};
|
||||
use core::marker::PhantomData;
|
||||
use scale_bits::{
|
||||
scale::format::{Format, OrderFormat, StoreFormat},
|
||||
Bits,
|
||||
scale::format::{Format, OrderFormat, StoreFormat},
|
||||
};
|
||||
use scale_decode::{IntoVisitor, TypeResolver};
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// see LICENSE for license details.
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use scale_decode::{visitor::DecodeAsTypeResult, IntoVisitor, TypeResolver, Visitor};
|
||||
use scale_decode::{IntoVisitor, TypeResolver, Visitor, visitor::DecodeAsTypeResult};
|
||||
use scale_encode::EncodeAsType;
|
||||
|
||||
use alloc::vec::Vec;
|
||||
@@ -44,7 +44,7 @@ impl<T: Decode, R: TypeResolver> Visitor for StaticDecodeAsTypeVisitor<T, R> {
|
||||
_type_id: R::TypeId,
|
||||
_types: &'info R,
|
||||
) -> DecodeAsTypeResult<Self, Result<Self::Value<'scale, 'info>, Self::Error>> {
|
||||
use scale_decode::{visitor::DecodeError, Error};
|
||||
use scale_decode::{Error, visitor::DecodeError};
|
||||
let decoded = T::decode(input)
|
||||
.map(Static)
|
||||
.map_err(|e| Error::new(DecodeError::CodecError(e).into()));
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use scale_decode::{visitor::DecodeAsTypeResult, DecodeAsType, IntoVisitor, TypeResolver, Visitor};
|
||||
use scale_decode::{DecodeAsType, IntoVisitor, TypeResolver, Visitor, visitor::DecodeAsTypeResult};
|
||||
|
||||
use super::{Encoded, Static};
|
||||
use alloc::vec::Vec;
|
||||
@@ -32,7 +32,7 @@ impl<Address, Call, Signature, Extra> UncheckedExtrinsic<Address, Call, Signatur
|
||||
|
||||
/// Get the bytes of the encoded extrinsic.
|
||||
pub fn bytes(&self) -> &[u8] {
|
||||
self.0 .0 .0.as_slice()
|
||||
self.0.0.0.as_slice()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ impl<Address, Call, Signature, Extra> From<UncheckedExtrinsic<Address, Call, Sig
|
||||
for Vec<u8>
|
||||
{
|
||||
fn from(bytes: UncheckedExtrinsic<Address, Call, Signature, Extra>) -> Self {
|
||||
bytes.0 .0 .0
|
||||
bytes.0.0.0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,8 +106,8 @@ impl<Address, Call, Signature, Extra> IntoVisitor
|
||||
type AnyVisitor<R: TypeResolver> =
|
||||
UncheckedExtrinsicDecodeAsTypeVisitor<Address, Call, Signature, Extra, R>;
|
||||
|
||||
fn into_visitor<R: TypeResolver>(
|
||||
) -> UncheckedExtrinsicDecodeAsTypeVisitor<Address, Call, Signature, Extra, R> {
|
||||
fn into_visitor<R: TypeResolver>()
|
||||
-> UncheckedExtrinsicDecodeAsTypeVisitor<Address, Call, Signature, Extra, R> {
|
||||
UncheckedExtrinsicDecodeAsTypeVisitor(PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
use super::PhantomDataSendSync;
|
||||
use codec::{Compact, Decode, DecodeAll, Encode};
|
||||
use derive_where::derive_where;
|
||||
use scale_decode::{ext::scale_type_resolver::visitor, IntoVisitor, TypeResolver, Visitor};
|
||||
use scale_decode::{IntoVisitor, TypeResolver, Visitor, ext::scale_type_resolver::visitor};
|
||||
use scale_encode::EncodeAsType;
|
||||
|
||||
use alloc::format;
|
||||
@@ -135,7 +135,9 @@ impl<T, R: TypeResolver> Visitor for WrapperKeepOpaqueVisitor<T, R> {
|
||||
|
||||
// Sanity check that the compact length we decoded lines up with the number of bytes encoded in the next field.
|
||||
if field.bytes().len() != len as usize {
|
||||
return Err(Error::custom_str("WrapperTypeKeepOpaque compact encoded length doesn't line up with encoded byte len"));
|
||||
return Err(Error::custom_str(
|
||||
"WrapperTypeKeepOpaque compact encoded length doesn't line up with encoded byte len",
|
||||
));
|
||||
}
|
||||
|
||||
Ok(WrapperKeepOpaque {
|
||||
@@ -166,7 +168,7 @@ mod test {
|
||||
impl<T: scale_info::TypeInfo + 'static> scale_info::TypeInfo for WrapperKeepOpaque<T> {
|
||||
type Identity = Self;
|
||||
fn type_info() -> scale_info::Type {
|
||||
use scale_info::{build::Fields, meta_type, Path, Type, TypeParameter};
|
||||
use scale_info::{Path, Type, TypeParameter, build::Fields, meta_type};
|
||||
|
||||
Type::builder()
|
||||
.path(Path::new("WrapperKeepOpaque", module_path!()))
|
||||
|
||||
@@ -11,9 +11,9 @@ use derive_where::derive_where;
|
||||
use scale_encode::EncodeAsFields;
|
||||
use scale_value::Composite;
|
||||
|
||||
use crate::Error;
|
||||
use crate::dynamic::DecodedValueThunk;
|
||||
use crate::error::MetadataError;
|
||||
use crate::Error;
|
||||
|
||||
use crate::metadata::{DecodeWithMetadata, Metadata};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user