From 214cc867b0ae2e6c31ffad4c56fc28da2da4473f Mon Sep 17 00:00:00 2001 From: librelois <c@elo.tf> Date: Sun, 25 Jul 2021 22:32:16 +0200 Subject: [PATCH] ref(runtime): move UdAccountsProvider in common part --- runtime/common/src/lib.rs | 1 + runtime/common/src/pallets_config.rs | 4 ++-- runtime/common/src/providers.rs | 33 ++++++++++++++++++++++++++++ runtime/g1/src/lib.rs | 13 ----------- runtime/gdev/src/lib.rs | 13 ----------- runtime/gtest/src/lib.rs | 13 ----------- 6 files changed, 36 insertions(+), 41 deletions(-) create mode 100644 runtime/common/src/providers.rs diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index c48bc4458..d1bde64f5 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -23,6 +23,7 @@ pub mod entities; pub mod fees; pub mod handlers; mod pallets_config; +pub mod providers; pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs index 3600fdbc7..07010a1f7 100644 --- a/runtime/common/src/pallets_config.rs +++ b/runtime/common/src/pallets_config.rs @@ -146,8 +146,8 @@ macro_rules! pallets_config { impl pallet_universal_dividend::Config for Runtime { type Currency = pallet_balances::Pallet<Runtime>; type Event = Event; - type MembersCount = UdAccountsProvider; - type MembersIds = UdAccountsProvider; + type MembersCount = common_runtime::providers::UdAccountsProvider<Runtime>; + type MembersIds = common_runtime::providers::UdAccountsProvider<Runtime>; type SquareMoneyGrowthRate = SquareMoneyGrowthRate; type UdCreationPeriod = UdCreationPeriod; type UdReevalPeriod = UdReevalPeriod; diff --git a/runtime/common/src/providers.rs b/runtime/common/src/providers.rs new file mode 100644 index 000000000..1f49810e9 --- /dev/null +++ b/runtime/common/src/providers.rs @@ -0,0 +1,33 @@ +// Copyright 2021 Axiom-Team +// +// This file is part of Substrate-Libre-Currency. +// +// Substrate-Libre-Currency is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Substrate-Libre-Currency is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// 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::AccountId; +use frame_support::traits::Get; +use sp_std::vec::Vec; + +pub struct UdAccountsProvider<Runtime>(core::marker::PhantomData<Runtime>); +impl<Runtime: pallet_ud_accounts_storage::Config> Get<u64> for UdAccountsProvider<Runtime> { + fn get() -> u64 { + <pallet_ud_accounts_storage::Pallet<Runtime>>::ud_accounts_count() + } +} +impl<Runtime: frame_system::Config<AccountId = AccountId> + pallet_ud_accounts_storage::Config> + Get<Vec<AccountId>> for UdAccountsProvider<Runtime> +{ + fn get() -> Vec<AccountId> { + <pallet_ud_accounts_storage::Pallet<Runtime>>::account_list() + } +} diff --git a/runtime/g1/src/lib.rs b/runtime/g1/src/lib.rs index a4699e1a1..2b756140a 100644 --- a/runtime/g1/src/lib.rs +++ b/runtime/g1/src/lib.rs @@ -46,7 +46,6 @@ use common_runtime::{ OnRightKeyChangeHandler, }, }; -use frame_support::traits::Get; use frame_system::EnsureRoot; use pallet_grandpa::fg_primitives; use pallet_grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList}; @@ -146,18 +145,6 @@ common_runtime::pallets_config! { } } -pub struct UdAccountsProvider; -impl Get<u64> for UdAccountsProvider { - fn get() -> u64 { - UdAccountsStorage::ud_accounts_count() - } -} -impl Get<Vec<AccountId>> for UdAccountsProvider { - fn get() -> Vec<AccountId> { - UdAccountsStorage::account_list() - } -} - // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where diff --git a/runtime/gdev/src/lib.rs b/runtime/gdev/src/lib.rs index 0e9c3c9d6..cbe02cce4 100644 --- a/runtime/gdev/src/lib.rs +++ b/runtime/gdev/src/lib.rs @@ -45,7 +45,6 @@ use common_runtime::{ OnRightKeyChangeHandler, }, }; -use frame_support::traits::Get; use frame_system::EnsureRoot; use pallet_grandpa::fg_primitives; use pallet_grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList}; @@ -135,18 +134,6 @@ common_runtime::pallets_config! { } } -pub struct UdAccountsProvider; -impl Get<u64> for UdAccountsProvider { - fn get() -> u64 { - UdAccountsStorage::ud_accounts_count() - } -} -impl Get<Vec<AccountId>> for UdAccountsProvider { - fn get() -> Vec<AccountId> { - UdAccountsStorage::account_list() - } -} - // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where diff --git a/runtime/gtest/src/lib.rs b/runtime/gtest/src/lib.rs index 2c3296940..226c258f7 100644 --- a/runtime/gtest/src/lib.rs +++ b/runtime/gtest/src/lib.rs @@ -46,7 +46,6 @@ use common_runtime::{ OnRightKeyChangeHandler, }, }; -use frame_support::traits::Get; use frame_system::EnsureRoot; use pallet_grandpa::fg_primitives; use pallet_grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList}; @@ -146,18 +145,6 @@ common_runtime::pallets_config! { } } -pub struct UdAccountsProvider; -impl Get<u64> for UdAccountsProvider { - fn get() -> u64 { - UdAccountsStorage::ud_accounts_count() - } -} -impl Get<Vec<AccountId>> for UdAccountsProvider { - fn get() -> Vec<AccountId> { - UdAccountsStorage::account_list() - } -} - // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where -- GitLab