diff --git a/Cargo.lock b/Cargo.lock index 418ddf85cd8d4b02bd8bfcbd928347d6d97c8fad..c0fc162f7e1d280fa007d29cdd279a7b2acaf9e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1915,6 +1915,7 @@ dependencies = [ "pallet-membership", "pallet-multisig", "pallet-offences", + "pallet-proxy", "pallet-scheduler", "pallet-session", "pallet-sudo", @@ -1971,6 +1972,7 @@ dependencies = [ "pallet-membership", "pallet-multisig", "pallet-offences", + "pallet-proxy", "pallet-scheduler", "pallet-session", "pallet-sudo", @@ -2164,6 +2166,7 @@ dependencies = [ "pallet-membership", "pallet-multisig", "pallet-offences", + "pallet-proxy", "pallet-scheduler", "pallet-session", "pallet-sudo", @@ -4461,6 +4464,20 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-proxy" +version = "4.0.0-dev" +source = "git+https://github.com/librelois/substrate.git?branch=duniter-monthly-2022-01#277da611dd03bc181b094682acf83138e2ea85aa" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-scheduler" version = "4.0.0-dev" diff --git a/runtime/common/src/constants.rs b/runtime/common/src/constants.rs index d7f1c058cbec221ea1d4d96fdf66a267abc0040e..4c618dfb1993612500a6c2acde13aece4d543eaf 100644 --- a/runtime/common/src/constants.rs +++ b/runtime/common/src/constants.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU Affero General Public License // along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>. -use crate::BlockNumber; +use crate::{Balance, BlockNumber}; use sp_runtime::Perbill; /// This determines the average expected block time that we are targeting. @@ -56,3 +56,8 @@ pub const BABE_GENESIS_EPOCH_CONFIG: sp_consensus_babe::BabeEpochConfiguration = c: PRIMARY_PROBABILITY, allowed_slots: sp_consensus_babe::AllowedSlots::PrimaryAndSecondaryVRFSlots, }; + +// 1 unit per item + 1 cent per byte +pub const fn deposit(items: u32, bytes: u32) -> Balance { + items as Balance * 100 + (bytes as Balance) +} diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs index f8c9f43eaa15267cbe257d7654daca2ee834736a..08f5968cefe620f74bf2ddd581053f2018ad6c9b 100644 --- a/runtime/common/src/pallets_config.rs +++ b/runtime/common/src/pallets_config.rs @@ -249,6 +249,29 @@ macro_rules! pallets_config { // UTILITIES // + 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 AnnouncementDepositBase: Balance = deposit(1, 8); + pub const AnnouncementDepositFactor: Balance = deposit(0, 66); + } + 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 = frame_support::traits::ConstU32<32>; + type MaxPending = frame_support::traits::ConstU32<32>; + type CallHasher = BlakeTwo256; + type AnnouncementDepositBase = AnnouncementDepositBase; + type AnnouncementDepositFactor = AnnouncementDepositFactor; + type WeightInfo = pallet_proxy::weights::SubstrateWeight<Self>; + } + impl pallet_utility::Config for Runtime { type Event = Event; type Call = Call; diff --git a/runtime/g1/Cargo.toml b/runtime/g1/Cargo.toml index 8d4aaa9ec1d32527c374457f864a4f1e5abc5027..4b4701332d1e7d29897f8e78e3b285812fceee7c 100644 --- a/runtime/g1/Cargo.toml +++ b/runtime/g1/Cargo.toml @@ -42,6 +42,7 @@ std = [ 'pallet-identity/std', 'pallet-im-online/std', 'pallet-membership/std', + 'pallet-proxy/std', 'pallet-multisig/std', 'pallet-session/std', 'pallet-sudo/std', @@ -158,6 +159,11 @@ default-features = false git = 'https://github.com/librelois/substrate.git' branch = 'duniter-monthly-2022-01' +[dependencies.pallet-proxy] +default-features = false +git = 'https://github.com/librelois/substrate.git' +branch = 'duniter-monthly-2022-01' + [dependencies.pallet-multisig] default-features = false git = 'https://github.com/librelois/substrate.git' diff --git a/runtime/g1/src/lib.rs b/runtime/g1/src/lib.rs index db327efb3efd4e4f2c3e3c7f07f8125dd0883bb4..6df027d4c8ad1d989af3319bec9ae27a00d177ca 100644 --- a/runtime/g1/src/lib.rs +++ b/runtime/g1/src/lib.rs @@ -137,6 +137,48 @@ impl frame_support::traits::Contains<Call> for BaseCallFilter { } } +/// The type used to represent the kinds of proxying allowed. +#[derive( + Copy, + Clone, + Eq, + PartialEq, + Ord, + PartialOrd, + codec::Encode, + codec::Decode, + frame_support::RuntimeDebug, + codec::MaxEncodedLen, + scale_info::TypeInfo, +)] +#[allow(clippy::unnecessary_cast)] +pub enum ProxyType { + Any = 0, + TransferOnly = 1, + CancelProxy = 2, +} +impl Default for ProxyType { + fn default() -> Self { + Self::Any + } +} +impl frame_support::traits::InstanceFilter<Call> for ProxyType { + fn filter(&self, c: &Call) -> bool { + match self { + ProxyType::Any => true, + ProxyType::TransferOnly => { + matches!(c, Call::Balances(..) | Call::UniversalDividend(..)) + } + ProxyType::CancelProxy => { + matches!( + c, + Call::Proxy(pallet_proxy::Call::reject_announcement { .. }) + ) + } + } + } +} + common_runtime::pallets_config! { impl pallet_sudo::Config for Runtime { type Event = Event; @@ -178,7 +220,8 @@ construct_runtime!( Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>} = 20, // Cunning utilities. - Utility: pallet_utility::{Pallet, Call, Event} = 30, + Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 30, + Utility: pallet_utility::{Pallet, Call, Event} = 31, // Universal dividend. UdAccountsStorage: pallet_ud_accounts_storage::{Pallet, Config<T>, Storage} = 40, diff --git a/runtime/gdev/Cargo.toml b/runtime/gdev/Cargo.toml index 8d88706dce4833d78581d8fd11cfdb5645476dd7..ba759bb8d1e2db9969b9a74a182ad0c206345040 100644 --- a/runtime/gdev/Cargo.toml +++ b/runtime/gdev/Cargo.toml @@ -45,6 +45,7 @@ std = [ 'pallet-membership/std', 'pallet-im-online/std', 'pallet-multisig/std', + 'pallet-proxy/std', 'pallet-session/std', 'pallet-sudo/std', 'pallet-universal-dividend/std', @@ -166,6 +167,11 @@ default-features = false git = 'https://github.com/librelois/substrate.git' branch = 'duniter-monthly-2022-01' +[dependencies.pallet-proxy] +default-features = false +git = 'https://github.com/librelois/substrate.git' +branch = 'duniter-monthly-2022-01' + [dependencies.pallet-scheduler] default-features = false git = 'https://github.com/librelois/substrate.git' diff --git a/runtime/gdev/src/lib.rs b/runtime/gdev/src/lib.rs index 94c3c976a8c46413428f51c613002ac7753f52f7..8b0e56323c78fda1639dbee18faefe06726f6437 100644 --- a/runtime/gdev/src/lib.rs +++ b/runtime/gdev/src/lib.rs @@ -138,6 +138,48 @@ impl frame_support::traits::Contains<Call> for BaseCallFilter { } } +/// The type used to represent the kinds of proxying allowed. +#[derive( + Copy, + Clone, + Eq, + PartialEq, + Ord, + PartialOrd, + codec::Encode, + codec::Decode, + frame_support::RuntimeDebug, + codec::MaxEncodedLen, + scale_info::TypeInfo, +)] +#[allow(clippy::unnecessary_cast)] +pub enum ProxyType { + Any = 0, + TransferOnly = 1, + CancelProxy = 2, +} +impl Default for ProxyType { + fn default() -> Self { + Self::Any + } +} +impl frame_support::traits::InstanceFilter<Call> for ProxyType { + fn filter(&self, c: &Call) -> bool { + match self { + ProxyType::Any => true, + ProxyType::TransferOnly => { + matches!(c, Call::Balances(..) | Call::UniversalDividend(..)) + } + ProxyType::CancelProxy => { + matches!( + c, + Call::Proxy(pallet_proxy::Call::reject_announcement { .. }) + ) + } + } + } +} + // Configure FRAME pallets to include in runtime. common_runtime::pallets_config! { // Dynamic parameters @@ -224,8 +266,9 @@ construct_runtime!( // Governance stuff Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>} = 20, - // Cunning utilities - Utility: pallet_utility::{Pallet, Call, Event} = 30, + // Utilities + Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 30, + Utility: pallet_utility::{Pallet, Call, Event} = 31, // Universal dividend UdAccountsStorage: pallet_ud_accounts_storage::{Pallet, Config<T>, Storage} = 40, diff --git a/runtime/gtest/Cargo.toml b/runtime/gtest/Cargo.toml index 64cb9051d806055a0968b0588a6aebe8a03a5a6d..248bc42fee7fa6c1e50709f5480cccd821e5770d 100644 --- a/runtime/gtest/Cargo.toml +++ b/runtime/gtest/Cargo.toml @@ -42,6 +42,7 @@ std = [ 'pallet-identity/std', 'pallet-membership/std', 'pallet-im-online/std', + 'pallet-proxy/std', 'pallet-multisig/std', 'pallet-session/std', 'pallet-sudo/std', @@ -158,6 +159,11 @@ default-features = false git = 'https://github.com/librelois/substrate.git' branch = 'duniter-monthly-2022-01' +[dependencies.pallet-proxy] +default-features = false +git = 'https://github.com/librelois/substrate.git' +branch = 'duniter-monthly-2022-01' + [dependencies.pallet-multisig] default-features = false git = 'https://github.com/librelois/substrate.git' diff --git a/runtime/gtest/src/lib.rs b/runtime/gtest/src/lib.rs index 06f29b133345d626b4b0197434270f7982cfd979..9edf36e92005c6d653423ea7a4de93f15287cfce 100644 --- a/runtime/gtest/src/lib.rs +++ b/runtime/gtest/src/lib.rs @@ -138,6 +138,48 @@ impl frame_support::traits::Contains<Call> for BaseCallFilter { } } +/// The type used to represent the kinds of proxying allowed. +#[derive( + Copy, + Clone, + Eq, + PartialEq, + Ord, + PartialOrd, + codec::Encode, + codec::Decode, + frame_support::RuntimeDebug, + codec::MaxEncodedLen, + scale_info::TypeInfo, +)] +#[allow(clippy::unnecessary_cast)] +pub enum ProxyType { + Any = 0, + TransferOnly = 1, + CancelProxy = 2, +} +impl Default for ProxyType { + fn default() -> Self { + Self::Any + } +} +impl frame_support::traits::InstanceFilter<Call> for ProxyType { + fn filter(&self, c: &Call) -> bool { + match self { + ProxyType::Any => true, + ProxyType::TransferOnly => { + matches!(c, Call::Balances(..) | Call::UniversalDividend(..)) + } + ProxyType::CancelProxy => { + matches!( + c, + Call::Proxy(pallet_proxy::Call::reject_announcement { .. }) + ) + } + } + } +} + common_runtime::pallets_config! { impl pallet_sudo::Config for Runtime { type Event = Event; @@ -178,7 +220,8 @@ construct_runtime!( Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>} = 20, // Cunning utilities. - Utility: pallet_utility::{Pallet, Call, Event} = 30, + Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 30, + Utility: pallet_utility::{Pallet, Call, Event} = 31, // Universal dividend. UdAccountsStorage: pallet_ud_accounts_storage::{Pallet, Config<T>, Storage} = 40,