mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 01:47:55 +00:00
feat: add super trait for block number (#2334)
And also related to a subxt PR https://github.com/paritytech/subxt/pull/1265
This commit is contained in:
@@ -21,16 +21,11 @@ use crate::{
|
||||
codec::{Codec, Decode, Encode},
|
||||
generic::Digest,
|
||||
scale_info::TypeInfo,
|
||||
traits::{
|
||||
self, AtLeast32BitUnsigned, Hash as HashT, MaybeDisplay, MaybeFromStr,
|
||||
MaybeSerializeDeserialize, Member,
|
||||
},
|
||||
traits::{self, AtLeast32BitUnsigned, BlockNumber, Hash as HashT, MaybeDisplay, Member},
|
||||
};
|
||||
use codec::{FullCodec, MaxEncodedLen};
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sp_core::U256;
|
||||
use sp_std::fmt::Debug;
|
||||
|
||||
/// Abstraction over a block header for a substrate chain.
|
||||
#[derive(Encode, Decode, PartialEq, Eq, Clone, sp_core::RuntimeDebug, TypeInfo)]
|
||||
@@ -79,20 +74,7 @@ where
|
||||
|
||||
impl<Number, Hash> traits::Header for Header<Number, Hash>
|
||||
where
|
||||
Number: Member
|
||||
+ MaybeSerializeDeserialize
|
||||
+ MaybeFromStr
|
||||
+ Debug
|
||||
+ Default
|
||||
+ sp_std::hash::Hash
|
||||
+ MaybeDisplay
|
||||
+ AtLeast32BitUnsigned
|
||||
+ FullCodec
|
||||
+ Copy
|
||||
+ MaxEncodedLen
|
||||
+ Into<U256>
|
||||
+ TryFrom<U256>
|
||||
+ TypeInfo,
|
||||
Number: BlockNumber,
|
||||
Hash: HashT,
|
||||
{
|
||||
type Number = Number;
|
||||
|
||||
@@ -38,7 +38,7 @@ pub use sp_arithmetic::traits::{
|
||||
EnsureOp, EnsureOpAssign, EnsureSub, EnsureSubAssign, IntegerSquareRoot, One,
|
||||
SaturatedConversion, Saturating, UniqueSaturatedFrom, UniqueSaturatedInto, Zero,
|
||||
};
|
||||
use sp_core::{self, storage::StateVersion, Hasher, RuntimeDebug, TypeId};
|
||||
use sp_core::{self, storage::StateVersion, Hasher, RuntimeDebug, TypeId, U256};
|
||||
#[doc(hidden)]
|
||||
pub use sp_core::{
|
||||
parameter_types, ConstBool, ConstI128, ConstI16, ConstI32, ConstI64, ConstI8, ConstU128,
|
||||
@@ -1149,6 +1149,44 @@ pub trait IsMember<MemberId> {
|
||||
fn is_member(member_id: &MemberId) -> bool;
|
||||
}
|
||||
|
||||
/// Super trait with all the attributes for a block number.
|
||||
pub trait BlockNumber:
|
||||
Member
|
||||
+ MaybeSerializeDeserialize
|
||||
+ MaybeFromStr
|
||||
+ Debug
|
||||
+ sp_std::hash::Hash
|
||||
+ Copy
|
||||
+ MaybeDisplay
|
||||
+ AtLeast32BitUnsigned
|
||||
+ Into<U256>
|
||||
+ TryFrom<U256>
|
||||
+ Default
|
||||
+ TypeInfo
|
||||
+ MaxEncodedLen
|
||||
+ FullCodec
|
||||
{
|
||||
}
|
||||
|
||||
impl<
|
||||
T: Member
|
||||
+ MaybeSerializeDeserialize
|
||||
+ MaybeFromStr
|
||||
+ Debug
|
||||
+ sp_std::hash::Hash
|
||||
+ Copy
|
||||
+ MaybeDisplay
|
||||
+ AtLeast32BitUnsigned
|
||||
+ Into<U256>
|
||||
+ TryFrom<U256>
|
||||
+ Default
|
||||
+ TypeInfo
|
||||
+ MaxEncodedLen
|
||||
+ FullCodec,
|
||||
> BlockNumber for T
|
||||
{
|
||||
}
|
||||
|
||||
/// Something which fulfills the abstract idea of a Substrate header. It has types for a `Number`,
|
||||
/// a `Hash` and a `Hashing`. It provides access to an `extrinsics_root`, `state_root` and
|
||||
/// `parent_hash`, as well as a `digest` and a block `number`.
|
||||
@@ -1158,18 +1196,7 @@ pub trait Header:
|
||||
Clone + Send + Sync + Codec + Eq + MaybeSerialize + Debug + TypeInfo + 'static
|
||||
{
|
||||
/// Header number.
|
||||
type Number: Member
|
||||
+ MaybeSerializeDeserialize
|
||||
+ MaybeFromStr
|
||||
+ Debug
|
||||
+ sp_std::hash::Hash
|
||||
+ Copy
|
||||
+ MaybeDisplay
|
||||
+ AtLeast32BitUnsigned
|
||||
+ Default
|
||||
+ TypeInfo
|
||||
+ MaxEncodedLen
|
||||
+ FullCodec;
|
||||
type Number: BlockNumber;
|
||||
/// Header hash type
|
||||
type Hash: HashOutput;
|
||||
/// Hashing algorithm
|
||||
|
||||
Reference in New Issue
Block a user