diff --git a/Cargo.lock b/Cargo.lock index 2315746..4f17062 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2332,6 +2332,7 @@ dependencies = [ "pallet-balances", "pallet-grandpa", "pallet-multisig", + "pallet-proxy", "pallet-randomness-collective-flip", "pallet-sudo", "pallet-teerex", @@ -3866,6 +3867,19 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-proxy" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate.git?branch=master#b391b82954ad95a927a921035e3017c4a0aad516" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-randomness-collective-flip" version = "4.0.0-dev" diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 17e4b55..3318beb 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -29,6 +29,7 @@ pallet-timestamp = { version = "4.0.0-dev", default-features = false, git = "htt pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" } pallet-treasury = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" } pallet-multisig = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" } +pallet-proxy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" } sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" } sp-block-builder = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" } @@ -90,6 +91,7 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "pallet-teerex/std", + "pallet-proxy/std", ] runtime-benchmarks = [ "frame-benchmarking", diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 8e422b1..9f649d2 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -35,7 +35,7 @@ use sp_std::prelude::*; #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; - +use codec::{Decode, Encode, MaxEncodedLen}; // A few exports that help ease life for downstream crates. pub use frame_support::{ construct_runtime, parameter_types, @@ -44,7 +44,7 @@ pub use frame_support::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, IdentityFee, Weight, }, - PalletId, StorageValue, + PalletId, StorageValue, RuntimeDebug, }; pub use pallet_balances::Call as BalancesCall; pub use pallet_timestamp::Call as TimestampCall; @@ -53,10 +53,9 @@ use pallet_transaction_payment::CurrencyAdapter; pub use sp_runtime::BuildStorage; pub use sp_runtime::{Perbill, Permill}; use frame_system::EnsureRoot; - /// added by Integritee pub use pallet_teerex; -use frame_support::traits::{OnUnbalanced, Imbalance}; +use frame_support::traits::{OnUnbalanced, Imbalance, InstanceFilter}; /// An index to a block. @@ -402,6 +401,90 @@ impl pallet_multisig::Config for Runtime { type WeightInfo = (); } +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; +} + +/// The type used to represent the kinds of proxying allowed. +#[derive( +Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, MaxEncodedLen, +)] +pub enum ProxyType { + Any, //any transactions + NonTransfer, //any type of transaction except balance transfers (including vested transfers) + Governance, + //Staking = 3, + //IdentityJudgement = 4, + CancelProxy, + //Auction, +} +impl Default for ProxyType { + fn default() -> Self { + Self::Any + } +} +impl InstanceFilter for ProxyType { + fn filter(&self, c: &Call) -> bool { + match self { + ProxyType::Any => true, + ProxyType::NonTransfer => matches!( + c, + Call::System(..) | + Call::Timestamp(..) | + // Specifically omitting Indices `transfer`, `force_transfer` + // Specifically omitting the entire Balances pallet + Call::Grandpa(..) | + Call::Treasury(..) | +// Call::Vesting(pallet_vesting::Call::vest(..)) | +// Call::Vesting(pallet_vesting::Call::vest_other(..)) | + // Specifically omitting Vesting `vested_transfer`, and `force_vested_transfer` + Call::Proxy(..) | + Call::Multisig(..) + ), + ProxyType::Governance => { + matches!( + c, + Call::Treasury(..) + ) + }, + ProxyType::CancelProxy => { + matches!(c, Call::Proxy(pallet_proxy::Call::reject_announcement(..))) + }, + } + } + 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 Event = Event; + type Call = Call; + type Currency = Balances; + type ProxyType = ProxyType; + type ProxyDepositBase = ProxyDepositBase; + type ProxyDepositFactor = ProxyDepositFactor; + type MaxProxies = MaxProxies; + type WeightInfo = (); + type MaxPending = MaxPending; + type CallHasher = BlakeTwo256; + type AnnouncementDepositBase = AnnouncementDepositBase; + type AnnouncementDepositFactor = AnnouncementDepositFactor; +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where @@ -421,6 +504,7 @@ construct_runtime!( Teerex: pallet_teerex::{Pallet, Call, Storage, Event}, Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event}, Multisig: pallet_multisig::{Pallet, Call, Storage, Event}, + Proxy: pallet_proxy::{Pallet, Call, Storage, Event}, } );