mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 17:01:09 +00:00
Remove unneeded Config bounds and BlockNumber associated type (#804)
* remove unneeded Config bounds and BlockNumber associated type * clippy and fmt
This commit is contained in:
@@ -57,7 +57,7 @@ where
|
||||
}
|
||||
|
||||
/// Return the block number.
|
||||
pub fn number(&self) -> T::BlockNumber {
|
||||
pub fn number(&self) -> <T::Header as crate::config::Header>::Number {
|
||||
self.header().number()
|
||||
}
|
||||
|
||||
|
||||
+20
-46
@@ -13,12 +13,14 @@ pub mod polkadot;
|
||||
pub mod substrate;
|
||||
|
||||
use codec::{
|
||||
Codec,
|
||||
Decode,
|
||||
Encode,
|
||||
EncodeLike,
|
||||
};
|
||||
use core::fmt::Debug;
|
||||
use serde::Serialize;
|
||||
use serde::{
|
||||
de::DeserializeOwned,
|
||||
Serialize,
|
||||
};
|
||||
|
||||
pub use extrinsic_params::ExtrinsicParams;
|
||||
pub use polkadot::PolkadotConfig;
|
||||
@@ -31,66 +33,39 @@ pub use substrate::SubstrateConfig;
|
||||
pub trait Config: 'static {
|
||||
/// Account index (aka nonce) type. This stores the number of previous
|
||||
/// transactions associated with a sender account.
|
||||
type Index: Parameter
|
||||
+ Member
|
||||
+ serde::de::DeserializeOwned
|
||||
+ Default
|
||||
+ Copy
|
||||
+ scale_info::TypeInfo
|
||||
+ Into<u64>;
|
||||
|
||||
/// The block number type used by the runtime.
|
||||
type BlockNumber: Parameter
|
||||
+ Member
|
||||
+ Default
|
||||
+ Copy
|
||||
+ std::hash::Hash
|
||||
+ std::str::FromStr
|
||||
+ Into<u64>;
|
||||
type Index: Debug + Copy + DeserializeOwned + Into<u64>;
|
||||
|
||||
/// The output of the `Hashing` function.
|
||||
type Hash: Parameter
|
||||
+ Member
|
||||
+ serde::Serialize
|
||||
+ serde::de::DeserializeOwned
|
||||
+ Ord
|
||||
+ Default
|
||||
type Hash: Debug
|
||||
+ Copy
|
||||
+ std::hash::Hash
|
||||
+ Send
|
||||
+ Sync
|
||||
+ Decode
|
||||
+ AsRef<[u8]>
|
||||
+ AsMut<[u8]>
|
||||
+ scale_info::TypeInfo;
|
||||
+ Serialize
|
||||
+ DeserializeOwned
|
||||
+ Encode
|
||||
+ PartialEq;
|
||||
|
||||
/// The account ID type.
|
||||
type AccountId: Clone + Serialize;
|
||||
type AccountId: Debug + Clone + Serialize;
|
||||
|
||||
/// The address type.
|
||||
type Address: Encode + From<Self::AccountId>;
|
||||
type Address: Debug + Encode + From<Self::AccountId>;
|
||||
|
||||
/// The signature type.
|
||||
type Signature: Encode;
|
||||
type Signature: Debug + Encode;
|
||||
|
||||
/// The hashing system (algorithm) being used in the runtime (e.g. Blake2).
|
||||
type Hasher: Hasher<Output = Self::Hash>;
|
||||
type Hasher: Debug + Hasher<Output = Self::Hash>;
|
||||
|
||||
/// The block header.
|
||||
type Header: Parameter
|
||||
+ Header<Number = Self::BlockNumber, Hasher = Self::Hasher>
|
||||
+ Member
|
||||
+ serde::de::DeserializeOwned;
|
||||
type Header: Debug + Header<Hasher = Self::Hasher> + Send + DeserializeOwned;
|
||||
|
||||
/// This type defines the extrinsic extra and additional parameters.
|
||||
type ExtrinsicParams: extrinsic_params::ExtrinsicParams<Self::Index, Self::Hash>;
|
||||
}
|
||||
|
||||
/// Parameter trait copied from `substrate::frame_support`.
|
||||
pub trait Parameter: Codec + EncodeLike + Clone + Eq + Debug {}
|
||||
impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + Debug {}
|
||||
|
||||
/// A type that can be used in runtime structures. Copied from `sp_runtime::traits`.
|
||||
pub trait Member: Send + Sync + Sized + Debug + Eq + PartialEq + Clone + 'static {}
|
||||
impl<T: Send + Sync + Sized + Debug + Eq + PartialEq + Clone + 'static> Member for T {}
|
||||
|
||||
/// This represents the hasher used by a node to hash things like block headers
|
||||
/// and extrinsics.
|
||||
pub trait Hasher {
|
||||
@@ -110,7 +85,7 @@ pub trait Hasher {
|
||||
/// This represents the block header type used by a node.
|
||||
pub trait Header: Sized + Encode {
|
||||
/// The block number type for this header.
|
||||
type Number;
|
||||
type Number: Into<u64>;
|
||||
/// The hasher used to hash this header.
|
||||
type Hasher: Hasher;
|
||||
|
||||
@@ -146,7 +121,6 @@ impl<T: Config, E: extrinsic_params::ExtrinsicParams<T::Index, T::Hash>> Config
|
||||
for WithExtrinsicParams<T, E>
|
||||
{
|
||||
type Index = T::Index;
|
||||
type BlockNumber = T::BlockNumber;
|
||||
type Hash = T::Hash;
|
||||
type AccountId = T::AccountId;
|
||||
type Address = T::Address;
|
||||
|
||||
@@ -39,13 +39,12 @@ pub enum SubstrateConfig {}
|
||||
|
||||
impl Config for SubstrateConfig {
|
||||
type Index = u32;
|
||||
type BlockNumber = u32;
|
||||
type Hash = H256;
|
||||
type AccountId = AccountId32;
|
||||
type Address = MultiAddress<Self::AccountId, u32>;
|
||||
type Signature = MultiSignature;
|
||||
type Hasher = BlakeTwo256;
|
||||
type Header = SubstrateHeader<Self::BlockNumber, BlakeTwo256>;
|
||||
type Header = SubstrateHeader<u32, BlakeTwo256>;
|
||||
type ExtrinsicParams = SubstrateExtrinsicParams<Self>;
|
||||
}
|
||||
|
||||
@@ -124,10 +123,9 @@ pub struct SubstrateHeader<N: Copy + Into<U256> + TryFrom<U256>, H: Hasher> {
|
||||
pub digest: Digest,
|
||||
}
|
||||
|
||||
impl<N: Copy + Into<U256> + TryFrom<U256> + Encode, H: Hasher + Encode> Header
|
||||
for SubstrateHeader<N, H>
|
||||
impl<N, H> Header for SubstrateHeader<N, H>
|
||||
where
|
||||
N: Copy + Into<U256> + TryFrom<U256> + Encode,
|
||||
N: Copy + Into<u64> + Into<U256> + TryFrom<U256> + Encode,
|
||||
H: Hasher + Encode,
|
||||
SubstrateHeader<N, H>: Encode,
|
||||
{
|
||||
@@ -268,14 +266,11 @@ impl<'a> serde::Deserialize<'a> for DigestItem {
|
||||
{
|
||||
let r = impl_serde::serialize::deserialize(de)?;
|
||||
Decode::decode(&mut &r[..])
|
||||
.map_err(|e| serde::de::Error::custom(format!("Decode error: {}", e)))
|
||||
.map_err(|e| serde::de::Error::custom(format!("Decode error: {e}")))
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_number<S, T: Copy + Into<U256> + TryFrom<U256>>(
|
||||
val: &T,
|
||||
s: S,
|
||||
) -> Result<S::Ok, S::Error>
|
||||
fn serialize_number<S, T: Copy + Into<U256>>(val: &T, s: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
@@ -283,9 +278,7 @@ where
|
||||
serde::Serialize::serialize(&u256, s)
|
||||
}
|
||||
|
||||
fn deserialize_number<'a, D, T: Copy + Into<U256> + TryFrom<U256>>(
|
||||
d: D,
|
||||
) -> Result<T, D::Error>
|
||||
fn deserialize_number<'a, D, T: TryFrom<U256>>(d: D) -> Result<T, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'a>,
|
||||
{
|
||||
|
||||
@@ -124,7 +124,7 @@ impl<'a> ::serde::Deserialize<'a> for ChainBlockExtrinsic {
|
||||
{
|
||||
let r = impl_serde::serialize::deserialize(de)?;
|
||||
let bytes = Decode::decode(&mut &r[..])
|
||||
.map_err(|e| ::serde::de::Error::custom(format!("Decode error: {}", e)))?;
|
||||
.map_err(|e| ::serde::de::Error::custom(format!("Decode error: {e}")))?;
|
||||
Ok(ChainBlockExtrinsic(bytes))
|
||||
}
|
||||
}
|
||||
@@ -778,7 +778,7 @@ mod as_string {
|
||||
) -> Result<usize, D::Error> {
|
||||
String::deserialize(deserializer)?
|
||||
.parse()
|
||||
.map_err(|e| serde::de::Error::custom(format!("Parsing failed: {}", e)))
|
||||
.map_err(|e| serde::de::Error::custom(format!("Parsing failed: {e}")))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ impl<'de> Deserialize<'de> for AccountId32 {
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
AccountId32::from_ss58check(&String::deserialize(deserializer)?)
|
||||
.map_err(|e| serde::de::Error::custom(format!("{:?}", e)))
|
||||
.map_err(|e| serde::de::Error::custom(format!("{e:?}")))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user