波卡一起学

system::Trait

2019-10-26  本文已影响0人  空乱木

/substrate-pow-template/substrate/srml/system/src

type 类型别名
参考链接:https://www.jianshu.com/p/42b0a1446983
fn main() {
type NanoSecond = u64;
type Point = (u8, u8);

let x : NanoSecond = 19999;
let y : Point = (1,2);

println!("x = {:?}", x);
println!("y = {:?}", y);
}

pub trait Trait: 'static + Eq + Clone {
/// The aggregated Origin type used by dispatchable calls.
type Origin: Into<Result<RawOrigin<Self::AccountId>, Self::Origin>> + From<RawOrigin<Self::AccountId>>;

/// The aggregated `Call` type.
type Call;

/// Account index (aka nonce) type. This stores the number of previous transactions associated with a sender
/// account.
type Index:
    Parameter + Member + MaybeSerializeDebugButNotDeserialize + Default + MaybeDisplay + SimpleArithmetic + Copy;

/// The block number type used by the runtime.
type BlockNumber:
    Parameter + Member + MaybeSerializeDebug + MaybeDisplay + SimpleArithmetic + Default + Bounded + Copy
    + rstd::hash::Hash;

/// The output of the `Hashing` function.
type Hash:
    Parameter + Member + MaybeSerializeDebug + MaybeDisplay + SimpleBitOps + Default + Copy + CheckEqual
    + rstd::hash::Hash + AsRef<[u8]> + AsMut<[u8]>;

/// The hashing system (algorithm) being used in the runtime (e.g. Blake2).
type Hashing: Hash<Output = Self::Hash>;

/// The user account identifier type for the runtime.
type AccountId: Parameter + Member + MaybeSerializeDebug + MaybeDisplay + Ord + Default;

/// Converting trait to take a source type and convert to `AccountId`.
///
/// Used to define the type and conversion mechanism for referencing accounts in transactions. It's perfectly
/// reasonable for this to be an identity conversion (with the source type being `AccountId`), but other modules
/// (e.g. Indices module) may provide more functional/efficient alternatives.
type Lookup: StaticLookup<Target = Self::AccountId>;

/// Handler for updating the weight multiplier at the end of each block.
///
/// It receives the current block's weight as input and returns the next weight multiplier for next
/// block.
///
/// Note that passing `()` will keep the value constant.
type WeightMultiplierUpdate: Convert<(Weight, WeightMultiplier), WeightMultiplier>;

/// The block header.
type Header: Parameter + traits::Header<
    Number = Self::BlockNumber,
    Hash = Self::Hash,
>;

/// The aggregated event type of the runtime.
type Event: Parameter + Member + From<Event>;

/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
type BlockHashCount: Get<Self::BlockNumber>;

/// The maximum weight of a block.
type MaximumBlockWeight: Get<Weight>;

/// The maximum length of a block (in bytes).
type MaximumBlockLength: Get<u32>;

/// The portion of the block that is available to normal transaction. The rest can only be used
/// by operational transactions. This can be applied to any resource limit managed by the system
/// module, including weight and length.
type AvailableBlockRatio: Get<Perbill>;

/// Get the chain's current version.
type Version: Get<RuntimeVersion>;

type类型的定义找到原来的类型test方法中;
type AccountId = u64;
impl Trait for Test {
type Origin = Origin;
type Call = ();
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type WeightMultiplierUpdate = ();
type Event = u16;
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
}

<T as system::Trait>::AccountId,
<T as Trait>::Balance,
<T as Trait>::AssetId

上一篇 下一篇

猜你喜欢

热点阅读