Skip to content

Commit f0fd87c

Browse files
authored
Add Proxy module (paritytech#478)
* Add Proxy module * Cargo fmt * Bump spec version
1 parent 8094dc7 commit f0fd87c

File tree

8 files changed

+367
-9
lines changed

8 files changed

+367
-9
lines changed

Cargo.lock

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pallet-indices = { git = "https://github.com/paritytech/substrate", rev = "11ace
8585
pallet-membership = { git = "https://github.com/paritytech/substrate", rev = "11ace4ef8b2ad176293ad6db2b3dd795befd2c79" }
8686
pallet-multisig = { git = "https://github.com/paritytech/substrate", rev = "11ace4ef8b2ad176293ad6db2b3dd795befd2c79" }
8787
pallet-offences = { git = "https://github.com/paritytech/substrate", rev = "11ace4ef8b2ad176293ad6db2b3dd795befd2c79" }
88+
pallet-proxy = { git = "https://github.com/paritytech/substrate", rev = "11ace4ef8b2ad176293ad6db2b3dd795befd2c79" }
8889
pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", rev = "11ace4ef8b2ad176293ad6db2b3dd795befd2c79" }
8990
pallet-scheduler = { git = "https://github.com/paritytech/substrate", rev = "11ace4ef8b2ad176293ad6db2b3dd795befd2c79" }
9091
pallet-session = { git = "https://github.com/paritytech/substrate", rev = "11ace4ef8b2ad176293ad6db2b3dd795befd2c79" }

runtime/chainx/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pallet-indices = { version = "2.0.0", default-features = false }
4848
pallet-membership = { version = "2.0.0", default-features = false }
4949
pallet-multisig = { version = "2.0.0", default-features = false }
5050
pallet-offences = { version = "2.0.0", default-features = false }
51+
pallet-proxy = { version = "2.0.0", default-features = false }
5152
pallet-randomness-collective-flip = { version = "2.0.0", default-features = false }
5253
pallet-scheduler = { version = "2.0.0", default-features = false }
5354
pallet-session = { version = "2.0.0", default-features = false, features = ["historical"] }
@@ -135,6 +136,7 @@ std = [
135136
"pallet-membership/std",
136137
"pallet-multisig/std",
137138
"pallet-offences/std",
139+
"pallet-proxy/std",
138140
"pallet-randomness-collective-flip/std",
139141
"pallet-scheduler/std",
140142
"pallet-session/std",

runtime/chainx/src/lib.rs

Lines changed: 114 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#[cfg(feature = "std")]
1111
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
1212

13-
use codec::Encode;
13+
use codec::{Decode, Encode};
1414
use static_assertions::const_assert;
1515

1616
use sp_api::impl_runtime_apis;
@@ -31,7 +31,7 @@ use sp_runtime::{
3131
InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity,
3232
TransactionValidityError, ValidTransaction,
3333
},
34-
ApplyExtrinsicResult, DispatchError, ModuleId, Perbill, Percent, Permill,
34+
ApplyExtrinsicResult, DispatchError, ModuleId, Perbill, Percent, Permill, RuntimeDebug,
3535
};
3636
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
3737
#[cfg(feature = "std")]
@@ -104,7 +104,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
104104
spec_name: create_runtime_str!("chainx"),
105105
impl_name: create_runtime_str!("chainx-net"),
106106
authoring_version: 1,
107-
spec_version: 9,
107+
spec_version: 10,
108108
impl_version: 1,
109109
apis: RUNTIME_API_VERSIONS,
110110
transaction_version: 1,
@@ -758,6 +758,115 @@ impl pallet_identity::Trait for Runtime {
758758
type WeightInfo = pallet_identity::weights::SubstrateWeight<Runtime>;
759759
}
760760

761+
parameter_types! {
762+
// One storage item; key size 32, value size 8; .
763+
pub const ProxyDepositBase: Balance = deposit(1, 8);
764+
// Additional storage item size of 33 bytes.
765+
pub const ProxyDepositFactor: Balance = deposit(0, 33);
766+
pub const MaxProxies: u16 = 32;
767+
pub const AnnouncementDepositBase: Balance = deposit(1, 8);
768+
pub const AnnouncementDepositFactor: Balance = deposit(0, 66);
769+
pub const MaxPending: u16 = 32;
770+
}
771+
772+
/// The type used to represent the kinds of proxying allowed.
773+
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug)]
774+
pub enum ProxyType {
775+
Any = 0,
776+
NonTransfer = 1,
777+
Governance = 2,
778+
Staking = 3,
779+
IdentityJudgement = 4,
780+
CancelProxy = 5,
781+
}
782+
783+
impl Default for ProxyType {
784+
fn default() -> Self {
785+
Self::Any
786+
}
787+
}
788+
789+
impl InstanceFilter<Call> for ProxyType {
790+
fn filter(&self, c: &Call) -> bool {
791+
match self {
792+
ProxyType::Any => true,
793+
ProxyType::NonTransfer => matches!(
794+
c,
795+
Call::System(..)
796+
| Call::Scheduler(..)
797+
| Call::Babe(..)
798+
| Call::Timestamp(..)
799+
| Call::Indices(pallet_indices::Call::claim(..))
800+
| Call::Indices(pallet_indices::Call::free(..))
801+
| Call::Indices(pallet_indices::Call::freeze(..))
802+
// Specifically omitting Indices `transfer`, `force_transfer`
803+
// Specifically omitting the entire Balances pallet
804+
| Call::Authorship(..)
805+
| Call::XStaking(..)
806+
| Call::Offences(..)
807+
| Call::Session(..)
808+
| Call::Grandpa(..)
809+
| Call::ImOnline(..)
810+
| Call::AuthorityDiscovery(..)
811+
| Call::Democracy(..)
812+
| Call::Council(..)
813+
| Call::TechnicalCommittee(..)
814+
| Call::Elections(..)
815+
| Call::TechnicalMembership(..)
816+
| Call::Treasury(..)
817+
| Call::Utility(..)
818+
| Call::Identity(..)
819+
| Call::Proxy(..)
820+
| Call::Multisig(..)
821+
),
822+
ProxyType::Governance => matches!(
823+
c,
824+
Call::Democracy(..)
825+
| Call::Council(..)
826+
| Call::TechnicalCommittee(..)
827+
| Call::Elections(..)
828+
| Call::Treasury(..)
829+
| Call::Utility(..)
830+
),
831+
ProxyType::Staking => matches!(
832+
c,
833+
Call::XStaking(..) | Call::Session(..) | Call::Utility(..)
834+
),
835+
ProxyType::IdentityJudgement => matches!(
836+
c,
837+
Call::Identity(pallet_identity::Call::provide_judgement(..)) | Call::Utility(..)
838+
),
839+
ProxyType::CancelProxy => {
840+
matches!(c, Call::Proxy(pallet_proxy::Call::reject_announcement(..)))
841+
}
842+
}
843+
}
844+
fn is_superset(&self, o: &Self) -> bool {
845+
match (self, o) {
846+
(x, y) if x == y => true,
847+
(ProxyType::Any, _) => true,
848+
(_, ProxyType::Any) => false,
849+
(ProxyType::NonTransfer, _) => true,
850+
_ => false,
851+
}
852+
}
853+
}
854+
855+
impl pallet_proxy::Trait for Runtime {
856+
type Event = Event;
857+
type Call = Call;
858+
type Currency = Balances;
859+
type ProxyType = ProxyType;
860+
type ProxyDepositBase = ProxyDepositBase;
861+
type ProxyDepositFactor = ProxyDepositFactor;
862+
type MaxProxies = MaxProxies;
863+
type WeightInfo = pallet_proxy::weights::SubstrateWeight<Runtime>;
864+
type MaxPending = MaxPending;
865+
type CallHasher = BlakeTwo256;
866+
type AnnouncementDepositBase = AnnouncementDepositBase;
867+
type AnnouncementDepositFactor = AnnouncementDepositFactor;
868+
}
869+
761870
///////////////////////////////////////////
762871
// orml
763872
///////////////////////////////////////////
@@ -956,6 +1065,8 @@ construct_runtime!(
9561065
// It might be possible to merge this module into pallet_transaction_payment in future, thus
9571066
// we put it at the end for keeping the extrinsic ordering.
9581067
XTransactionFee: xpallet_transaction_fee::{Module, Event<T>} = 35,
1068+
1069+
Proxy: pallet_proxy::{Module, Call, Storage, Event<T>} = 37,
9591070
}
9601071
);
9611072

runtime/dev/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pallet-indices = { version = "2.0.0", default-features = false }
4848
pallet-membership = { version = "2.0.0", default-features = false }
4949
pallet-multisig = { version = "2.0.0", default-features = false }
5050
pallet-offences = { version = "2.0.0", default-features = false }
51+
pallet-proxy = { version = "2.0.0", default-features = false }
5152
pallet-randomness-collective-flip = { version = "2.0.0", default-features = false }
5253
pallet-scheduler = { version = "2.0.0", default-features = false }
5354
pallet-session = { version = "2.0.0", default-features = false, features = ["historical"] }
@@ -136,6 +137,7 @@ std = [
136137
"pallet-membership/std",
137138
"pallet-multisig/std",
138139
"pallet-offences/std",
140+
"pallet-proxy/std",
139141
"pallet-randomness-collective-flip/std",
140142
"pallet-scheduler/std",
141143
"pallet-session/std",

runtime/dev/src/lib.rs

Lines changed: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#[cfg(feature = "std")]
1111
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
1212

13-
use codec::Encode;
13+
use codec::{Decode, Encode};
1414
use static_assertions::const_assert;
1515

1616
use sp_api::impl_runtime_apis;
@@ -31,7 +31,7 @@ use sp_runtime::{
3131
InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity,
3232
TransactionValidityError, ValidTransaction,
3333
},
34-
ApplyExtrinsicResult, DispatchError, ModuleId, Perbill, Percent, Permill,
34+
ApplyExtrinsicResult, DispatchError, ModuleId, Perbill, Percent, Permill, RuntimeDebug,
3535
};
3636
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
3737
#[cfg(feature = "std")]
@@ -761,6 +761,115 @@ impl pallet_identity::Trait for Runtime {
761761
type WeightInfo = pallet_identity::weights::SubstrateWeight<Runtime>;
762762
}
763763

764+
parameter_types! {
765+
// One storage item; key size 32, value size 8; .
766+
pub const ProxyDepositBase: Balance = deposit(1, 8);
767+
// Additional storage item size of 33 bytes.
768+
pub const ProxyDepositFactor: Balance = deposit(0, 33);
769+
pub const MaxProxies: u16 = 32;
770+
pub const AnnouncementDepositBase: Balance = deposit(1, 8);
771+
pub const AnnouncementDepositFactor: Balance = deposit(0, 66);
772+
pub const MaxPending: u16 = 32;
773+
}
774+
775+
/// The type used to represent the kinds of proxying allowed.
776+
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug)]
777+
pub enum ProxyType {
778+
Any = 0,
779+
NonTransfer = 1,
780+
Governance = 2,
781+
Staking = 3,
782+
IdentityJudgement = 4,
783+
CancelProxy = 5,
784+
}
785+
786+
impl Default for ProxyType {
787+
fn default() -> Self {
788+
Self::Any
789+
}
790+
}
791+
792+
impl InstanceFilter<Call> for ProxyType {
793+
fn filter(&self, c: &Call) -> bool {
794+
match self {
795+
ProxyType::Any => true,
796+
ProxyType::NonTransfer => matches!(
797+
c,
798+
Call::System(..)
799+
| Call::Scheduler(..)
800+
| Call::Babe(..)
801+
| Call::Timestamp(..)
802+
| Call::Indices(pallet_indices::Call::claim(..))
803+
| Call::Indices(pallet_indices::Call::free(..))
804+
| Call::Indices(pallet_indices::Call::freeze(..))
805+
// Specifically omitting Indices `transfer`, `force_transfer`
806+
// Specifically omitting the entire Balances pallet
807+
| Call::Authorship(..)
808+
| Call::XStaking(..)
809+
| Call::Offences(..)
810+
| Call::Session(..)
811+
| Call::Grandpa(..)
812+
| Call::ImOnline(..)
813+
| Call::AuthorityDiscovery(..)
814+
| Call::Democracy(..)
815+
| Call::Council(..)
816+
| Call::TechnicalCommittee(..)
817+
| Call::Elections(..)
818+
| Call::TechnicalMembership(..)
819+
| Call::Treasury(..)
820+
| Call::Utility(..)
821+
| Call::Identity(..)
822+
| Call::Proxy(..)
823+
| Call::Multisig(..)
824+
),
825+
ProxyType::Governance => matches!(
826+
c,
827+
Call::Democracy(..)
828+
| Call::Council(..)
829+
| Call::TechnicalCommittee(..)
830+
| Call::Elections(..)
831+
| Call::Treasury(..)
832+
| Call::Utility(..)
833+
),
834+
ProxyType::Staking => matches!(
835+
c,
836+
Call::XStaking(..) | Call::Session(..) | Call::Utility(..)
837+
),
838+
ProxyType::IdentityJudgement => matches!(
839+
c,
840+
Call::Identity(pallet_identity::Call::provide_judgement(..)) | Call::Utility(..)
841+
),
842+
ProxyType::CancelProxy => {
843+
matches!(c, Call::Proxy(pallet_proxy::Call::reject_announcement(..)))
844+
}
845+
}
846+
}
847+
fn is_superset(&self, o: &Self) -> bool {
848+
match (self, o) {
849+
(x, y) if x == y => true,
850+
(ProxyType::Any, _) => true,
851+
(_, ProxyType::Any) => false,
852+
(ProxyType::NonTransfer, _) => true,
853+
_ => false,
854+
}
855+
}
856+
}
857+
858+
impl pallet_proxy::Trait for Runtime {
859+
type Event = Event;
860+
type Call = Call;
861+
type Currency = Balances;
862+
type ProxyType = ProxyType;
863+
type ProxyDepositBase = ProxyDepositBase;
864+
type ProxyDepositFactor = ProxyDepositFactor;
865+
type MaxProxies = MaxProxies;
866+
type WeightInfo = pallet_proxy::weights::SubstrateWeight<Runtime>;
867+
type MaxPending = MaxPending;
868+
type CallHasher = BlakeTwo256;
869+
type AnnouncementDepositBase = AnnouncementDepositBase;
870+
type AnnouncementDepositFactor = AnnouncementDepositFactor;
871+
}
872+
764873
///////////////////////////////////////////
765874
// orml
766875
///////////////////////////////////////////
@@ -961,6 +1070,8 @@ construct_runtime!(
9611070

9621071
// Put Sudo last so that the extrinsic ordering stays the same once it's removed.
9631072
Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},
1073+
1074+
Proxy: pallet_proxy::{Module, Call, Storage, Event<T>},
9641075
}
9651076
);
9661077

runtime/malan/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pallet-indices = { version = "2.0.0", default-features = false }
4848
pallet-membership = { version = "2.0.0", default-features = false }
4949
pallet-multisig = { version = "2.0.0", default-features = false }
5050
pallet-offences = { version = "2.0.0", default-features = false }
51+
pallet-proxy = { version = "2.0.0", default-features = false }
5152
pallet-randomness-collective-flip = { version = "2.0.0", default-features = false }
5253
pallet-scheduler = { version = "2.0.0", default-features = false }
5354
pallet-session = { version = "2.0.0", default-features = false, features = ["historical"] }
@@ -136,6 +137,7 @@ std = [
136137
"pallet-membership/std",
137138
"pallet-multisig/std",
138139
"pallet-offences/std",
140+
"pallet-proxy/std",
139141
"pallet-randomness-collective-flip/std",
140142
"pallet-scheduler/std",
141143
"pallet-session/std",

0 commit comments

Comments
 (0)