From 25e0052ef289bab62052f3e66cb151f44b5c1665 Mon Sep 17 00:00:00 2001 From: ytqaljn <2716693942@qq.com> Date: Sun, 12 Nov 2023 18:54:14 -0800 Subject: [PATCH] feat: add mutisig pallet --- Cargo.lock | 33 +++++++++++++++++ runtime/Cargo.toml | 8 +++-- runtime/src/lib.rs | 90 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 128 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b686868b..1a378743 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1019,9 +1019,11 @@ dependencies = [ "pallet-insecure-randomness-collective-flip", "pallet-membership", "pallet-mmr", + "pallet-multisig", "pallet-offences", "pallet-oss", "pallet-preimage", + "pallet-proxy", "pallet-rrsc", "pallet-scheduler", "pallet-scheduler-credit", @@ -6386,6 +6388,22 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-multisig" +version = "4.0.0-dev" +source = "git+https://github.com/CESSProject/substrate?branch=cess-polkadot-v0.9.42#48fb01c12d4cdb22c6a71f3b9b387b01e30f0ff9" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-offences" version = "4.0.0-dev" @@ -6438,6 +6456,21 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-proxy" +version = "4.0.0-dev" +source = "git+https://github.com/CESSProject/substrate?branch=cess-polkadot-v0.9.42#48fb01c12d4cdb22c6a71f3b9b387b01e30f0ff9" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-rrsc" version = "4.0.0-dev" diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index edbb9977..b2025dbb 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -76,14 +76,14 @@ pallet-indices = { version = "4.0.0-dev", default-features = false, git = "http pallet-membership = { version = "4.0.0-dev", default-features = false, git = "https://github.com/CESSProject/substrate", branch = "cess-polkadot-v0.9.42" } # pallet-message-queue pallet-mmr = { version = "4.0.0-dev", default-features = false, git = "https://github.com/CESSProject/substrate", branch = "cess-polkadot-v0.9.42" } -# pallet-multisig +pallet-multisig = { version = "4.0.0-dev", default-features = false, git = "https://github.com/CESSProject/substrate", branch = "cess-polkadot-v0.9.42" } # pallet-nomination-pools # pallet-nomination-pools-benchmarking # pallet-nomination-pools-runtime-api pallet-offences = { version = "4.0.0-dev", default-features = false, git = "https://github.com/CESSProject/substrate", branch = "cess-polkadot-v0.9.42" } # pallet-offences-benchmarking pallet-preimage = { version = "4.0.0-dev", default-features = false, git = "https://github.com/CESSProject/substrate", branch = "cess-polkadot-v0.9.42" } -# pallet-proxy +pallet-proxy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/CESSProject/substrate", branch = "cess-polkadot-v0.9.42" } pallet-insecure-randomness-collective-flip = { version = "4.0.0-dev", default-features = false, git = "https://github.com/CESSProject/substrate", branch = "cess-polkadot-v0.9.42" } # pallet-ranked-collective # pallet-recovery @@ -156,6 +156,7 @@ std = [ "frame-system-benchmarking?/std", "pallet-im-online/std", "pallet-membership/std", + "pallet-multisig/std", "pallet-offences/std", "pallet-scheduler/std", "pallet-session/std", @@ -169,6 +170,7 @@ std = [ "pallet-cacher/std", "pallet-cess-treasury/std", "pallet-preimage/std", + "pallet-proxy/std", "pallet-assets/std", "pallet-child-bounties/std", "pallet-mmr/std", @@ -269,8 +271,10 @@ try-runtime = [ "pallet-indices/try-runtime", "pallet-membership/try-runtime", "pallet-mmr/try-runtime", + "pallet-multisig/try-runtime", "pallet-offences/try-runtime", "pallet-preimage/try-runtime", + "pallet-proxy/try-runtime", "pallet-insecure-randomness-collective-flip/try-runtime", "pallet-scheduler/try-runtime", "pallet-session/try-runtime", diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 0fda2c85..bf133af5 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -71,7 +71,7 @@ pub use frame_support::{ }, ConstantMultiplier, IdentityFee, Weight, }, - PalletId, StorageValue, + PalletId, StorageValue, RuntimeDebug, }; use frame_system::{ @@ -933,6 +933,92 @@ impl pallet_sudo::Config for Runtime { impl pallet_evm_chain_id::Config for Runtime {} +parameter_types! { + // One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes. + pub const DepositBase: Balance = deposit(1, 88); + // Additional storage item size of 32 bytes. + pub const DepositFactor: Balance = deposit(0, 32); +} + +impl pallet_multisig::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = Balances; + type DepositBase = DepositBase; + type DepositFactor = DepositFactor; + type MaxSignatories = ConstU32<100>; + type WeightInfo = pallet_multisig::weights::SubstrateWeight; +} + +/// The type used to represent the kinds of proxying allowed. +#[derive( + Copy, + Clone, + Eq, + PartialEq, + Ord, + PartialOrd, + Encode, + Decode, + RuntimeDebug, + MaxEncodedLen, + scale_info::TypeInfo, +)] +pub enum ProxyType { + Any, + NonTransfer, + Governance, + Staking, +} +impl Default for ProxyType { + fn default() -> Self { + Self::Any + } +} +impl InstanceFilter for ProxyType { + fn filter(&self, c: &RuntimeCall) -> bool { + match self { + ProxyType::Any => true, + ProxyType::NonTransfer => !matches!( + c, + RuntimeCall::Balances(..) | + RuntimeCall::Assets(..) | + RuntimeCall::Indices(pallet_indices::Call::transfer { .. }) + ), + ProxyType::Governance => matches!( + c, + RuntimeCall::Council(..) | + RuntimeCall::TechnicalCommittee(..) | + RuntimeCall::Treasury(..) + ), + ProxyType::Staking => matches!(c, RuntimeCall::Staking(..)), + } + } + fn is_superset(&self, o: &Self) -> bool { + match (self, o) { + (x, y) if x == y => true, + (ProxyType::Any, _) => true, + (_, ProxyType::Any) => false, + (ProxyType::NonTransfer, _) => true, + _ => false, + } + } +} +impl pallet_proxy::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = Balances; + type ProxyType = ProxyType; + type ProxyDepositBase = ProxyDepositBase; + type ProxyDepositFactor = ProxyDepositFactor; + type MaxProxies = ConstU32<32>; + type WeightInfo = pallet_proxy::weights::SubstrateWeight; + type MaxPending = ConstU32<32>; + type CallHasher = BlakeTwo256; + type AnnouncementDepositBase = AnnouncementDepositBase; + type AnnouncementDepositFactor = AnnouncementDepositFactor; +} + /*** * Add This Block */ @@ -1520,6 +1606,7 @@ construct_runtime!( // Account lookup Indices: pallet_indices = 7, + Proxy: pallet_proxy = 8, // Tokens & Fees Balances: pallet_balances = 10, @@ -1547,6 +1634,7 @@ construct_runtime!( Treasury: pallet_treasury = 43, Bounties: pallet_bounties = 44, ChildBounties: pallet_child_bounties = 45, + Multisig: pallet_multisig = 46, // Smart contracts Contracts: pallet_contracts = 50,