这里值的重新回头看 https://substrate.dev/docs/zh-CN/knowledgebase/runtime/frame
以后再重新去研读FRAME代码
1. 添加 authorship
Authorship 模块用于追踪当前区块的创建者,以及邻近的 “叔块”。
添加到runtime的Cargo.toml
pallet-authorship = { version = "3.0.0", default-features = false }
添加到lib.rs
parameter_types! {
pub const UncleGenerations: BlockNumber = 5;
}
impl pallet_authorship::Config for Runtime {
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>;
type UncleGenerations = UncleGenerations; // 5
type FilterUncle = ();
type EventHandler = (Staking, ()); // ImOnline
}
// construct_runtime
Authorship: pallet_authorship::{Module, Call, Storage, Inherent},
2. 添加indices
Indices 模块可为新创建的帐户分配索引。 索引是地址的缩写形式。
添加到Cargo.toml
pallet-indices = { version = "3.0.0", default-features = false }
添加lib.rs
parameter_types! {
pub const IndexDeposit: Balance = DOLLARS;
}
impl pallet_indices::Config for Runtime {
type Event = Event;
type Currency = Balances;
type Deposit = IndexDeposit;
type AccountIndex = AccountIndex;
type WeightInfo = ();
}
// construct_runtime
Indices: pallet_indices::{Module, Call, Storage, Config<T>, Event<T>},
3. 添加Multisig
Multisig 模块是一个用于调用多重签名函数的模块。
添加到Cargo.toml
pallet-multisig = { version = "3.0.0", default-features = false }
添加lib.rs
parameter_types! {
pub const MultisigDepositBase: Balance = 500 * MILLICENTS;
pub const MultisigDepositFactor: Balance = 100 * MILLICENTS;
pub const MaxSignatories: u16 = 100;
}
impl pallet_multisig::Config for Runtime {
type Event = Event;
type Call = Call;
type Currency = Balances;
type DepositBase = MultisigDepositBase;
type DepositFactor = MultisigDepositFactor;
type MaxSignatories = MaxSignatories;
type WeightInfo = ();
}
// construct_runtime
Multisig: pallet_multisig::{Module, Call, Storage, Event<T>},
4. 添加Scheduler
此模块提供了预约功能,可以提前设定可调用函数于指定区块数或指定时间段发出。 这些提前设定的可调用函数,可以包含调用者名称或匿名,也可跟着被取消。
添加到Cargo.toml
pallet-multisig = { version = "3.0.0", default-features = false }
添加lib.rs
parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(10) * BlockWeights::get().max_block;
pub const MaxScheduledPerBlock: u32 = 50;
}
impl pallet_scheduler::Config for Runtime {
type Call = Call;
type Event = Event;
type Origin = Origin;
type PalletsOrigin = OriginCaller;
type MaximumWeight = MaximumSchedulerWeight;
type ScheduleOrigin = EnsureRoot<AccountId>;
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type WeightInfo = ();
}
// construct_runtime
Scheduler: pallet_scheduler::{Module, Call, Storage, Event<T>},
5. 添加Proxy
Proxy 模块允许一个帐户授权其他帐户以其名义调用不同函数的模块。
添加到Cargo.toml
pallet-proxy = { version = "3.0.0", default-features = false }
添加lib.rs
parameter_types! {
// One storage item; key size 32, value size 8; .
pub const ProxyDepositBase: Balance = deposit(1, 8);
// Additional storage item size of 33 bytes.
pub const ProxyDepositFactor: Balance = deposit(0, 33);
pub const MaxProxies: u16 = 32;
pub const AnnouncementDepositBase: Balance = deposit(1, 8);
pub const AnnouncementDepositFactor: Balance = deposit(0, 66);
pub const MaxPending: u16 = 32;
}
impl pallet_proxy::Config for Runtime {
type Event = Event;
type Call = Call;
type Currency = Balances;
type ProxyType = ();
type ProxyDepositBase = ProxyDepositBase;
type ProxyDepositFactor = ProxyDepositFactor;
type MaxProxies = MaxProxies;
type WeightInfo = ();
type MaxPending = MaxPending;
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
}
// construct_runtime
Proxy: pallet_proxy::{Module, Call, Storage, Event<T>},
6. 添加Recover
Recovery 模块是一种依靠 M-of-N 的社交来恢复用户帐户的工具。如果用户帐户的私钥或其他身份验证机制丢失,用户可使用这模块重新获取账户访问权限。 通过这个模块,用户可以另一个帐户代替其原本帐户对外发出请求调用。 账户的恢复过程受到了原始帐户主所选的受信 “朋友” 的保护。 需要得到 N 个朋友当中的最低门鉴数 (M) 个人的同意,才能把原有账户的访问权限授予给另一个账户。
添加到Cargo.toml
pallet-recovery = { version = "3.0.0", default-features = false }
添加lib.rs
parameter_types! {
pub const ConfigDepositBase: Balance = 10 * CENTS;
pub const FriendDepositFactor: Balance = CENTS;
pub const MaxFriends: u16 = 9;
pub const RecoveryDeposit: Balance = 10 * CENTS;
}
impl pallet_recovery::Config for Runtime {
type Event = Event;
type Call = Call;
type Currency = Balances;
type ConfigDepositBase = ConfigDepositBase;
type FriendDepositFactor = FriendDepositFactor;
type MaxFriends = MaxFriends;
type RecoveryDeposit = RecoveryDeposit;
}
// construct_runtime
Recovery: pallet_recovery::{Module, Call, Storage, Event<T>},
7. 添加Utility
一个用于管理函数调用的无状态 (存储) 的模块,并有着一系列的支援函数。
添加到Cargo.toml
pallet-utility = { version = "3.0.0", default-features = false }
添加lib.rs
impl pallet_utility::Config for Runtime {
type Event = Event;
type Call = Call;
type WeightInfo = ();
}
// construct_runtime
Utility: pallet_utility::{Module, Call, Event},
由于时间紧,所以没用深入分析源码,还有很多优秀模块可下次博客继续添加,文中很多参数参考了波卡官方polkadot和Acala两个优秀项目,下一篇添加治理