Mise à jour de GitLab prévue ce samedi 23 octobre 2021 à partir de 9h00 CET

Commit 26c5ce89 authored by Éloïs's avatar Éloïs
Browse files

ref(runtime): move common pallets config in a macro

parent a7b30b1b
......@@ -15,7 +15,7 @@
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
#[macro_export]
macro_rules! impl_runtime_apis_plus_common {
macro_rules! runtime_apis {
{$($custom:tt)*} => {
impl_runtime_apis! {
$($custom)*
......
......@@ -22,6 +22,7 @@ pub mod constants;
pub mod entities;
pub mod fees;
pub mod handlers;
mod pallets_config;
pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
......
// 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/>.
#[macro_export]
macro_rules! pallets_config {
{$($custom:tt)*} => {
$($custom)*
impl frame_system::Config for Runtime {
/// The basic call filter to use in dispatchable.
type BaseCallFilter = ();
/// Block & extrinsics weights: base values and limits.
type BlockWeights = BlockWeights;
/// The maximum length of a block (in bytes).
type BlockLength = BlockLength;
/// The identifier used to distinguish between accounts.
type AccountId = AccountId;
/// The aggregated dispatch type that is available for extrinsics.
type Call = Call;
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
type Lookup = AccountIdLookup<AccountId, ()>;
/// The index type for storing how many extrinsics an account has signed.
type Index = Index;
/// The index type for blocks.
type BlockNumber = BlockNumber;
/// The type for hashing blocks and tries.
type Hash = Hash;
/// The hashing algorithm used.
type Hashing = BlakeTwo256;
/// The header type.
type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// The ubiquitous event type.
type Event = Event;
/// The ubiquitous origin type.
type Origin = Origin;
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
type BlockHashCount = BlockHashCount;
/// The weight of database operations that the runtime can invoke.
type DbWeight = RocksDbWeight;
/// Version of the runtime.
type Version = Version;
/// Converts a module to the index of the module in `construct_runtime!`.
///
/// This type is being generated by `construct_runtime!`.
type PalletInfo = PalletInfo;
/// What to do if a new account is created.
type OnNewAccount = ();
/// What to do if an account is fully reaped from the system.
type OnKilledAccount = ();
/// The data to be stored in an account.
type AccountData = pallet_balances::AccountData<Balance>;
/// Weight information for the extrinsics of this pallet.
type SystemWeightInfo = ();
/// This is used as an identifier of the chain. 42 is the generic substrate prefix.
type SS58Prefix = SS58Prefix;
/// The set code logic, just the default since we're not a parachain.
type OnSetCode = ();
}
impl pallet_grandpa::Config for Runtime {
type Event = Event;
type Call = Call;
type KeyOwnerProofSystem = ();
type KeyOwnerProof =
<Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;
type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
GrandpaId,
)>>::IdentificationTuple;
type HandleEquivocation = ();
type WeightInfo = ();
}
impl pallet_balances::Config for Runtime {
type MaxLocks = MaxLocks;
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
/// The type for recording an account's balance.
type Balance = Balance;
/// The ubiquitous event type.
type Event = Event;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
}
impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction = CurrencyAdapter<Balances, ()>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = common_runtime::fees::WeightToFeeImpl<Balance>;
type FeeMultiplierUpdate = ();
}
impl pallet_identity::Config for Runtime {
type ConfirmPeriod = ConfirmPeriod;
type Event = Event;
type AddRightOrigin = EnsureRoot<Self::AccountId>;
type DelRightOrigin = EnsureRoot<Self::AccountId>;
type EnsureIdtyCallAllowed = EnsureIdtyCallAllowedImpl<Runtime, IDTY_CREATE_PERIOD>;
type IdtyData = IdtyData;
type IdtyDid = IdtyDid;
type IdtyIndex = IdtyIndex;
type IdtyValidationOrigin = EnsureRoot<Self::AccountId>;
type IdtyRight = IdtyRight;
type OnIdtyChange = OnIdtyChangeHandler<Runtime>;
type OnRightKeyChange = OnRightKeyChangeHandler<Runtime>;
type MaxInactivityPeriod = MaxInactivityPeriod;
type MaxNoRightPeriod = MaxNoRightPeriod;
type RenewablePeriod = IdtyRenewablePeriod;
type ValidationPeriod = ValidationPeriod;
}
impl pallet_certification::Config for Runtime {
type AddCertOrigin = AddStrongCertOrigin<Runtime>;
type CertPeriod = CertPeriod;
type DelCertOrigin = DelStrongCertOrigin<Runtime>;
type Event = Event;
type IdtyIndex = IdtyIndex;
type MaxByIssuer = MaxByIssuer;
type OnNewcert =
OnNewStrongCertHandler<Runtime, MIN_STRONG_CERT_FOR_UD, MIN_STRONG_CERT_FOR_STRONG_CERT>;
type OnRemovedCert = OnRemovedStrongCertHandler<Runtime, MIN_STRONG_CERT_FOR_UD>;
type RenewablePeriod = StrongCertRenewablePeriod;
type ValidityPeriod = ValidityPeriod;
}
impl pallet_universal_dividend::Config for Runtime {
type Currency = pallet_balances::Pallet<Runtime>;
type Event = Event;
type MembersCount = UdAccountsProvider;
type MembersIds = UdAccountsProvider;
type SquareMoneyGrowthRate = SquareMoneyGrowthRate;
type UdCreationPeriod = UdCreationPeriod;
type UdReevalPeriod = UdReevalPeriod;
type UdReevalPeriodInBlocks = UdReevalPeriodInBlocks;
}
impl pallet_ud_accounts_storage::Config for Runtime {}
};
}
......@@ -124,161 +124,28 @@ parameter_types! {
::with_sensible_defaults(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub const SS58Prefix: u8 = 42;
pub const SS58Prefix: u16 = 42;
}
// Configure FRAME pallets to include in runtime.
impl frame_system::Config for Runtime {
/// The basic call filter to use in dispatchable.
type BaseCallFilter = ();
/// Block & extrinsics weights: base values and limits.
type BlockWeights = BlockWeights;
/// The maximum length of a block (in bytes).
type BlockLength = BlockLength;
/// The identifier used to distinguish between accounts.
type AccountId = AccountId;
/// The aggregated dispatch type that is available for extrinsics.
type Call = Call;
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
type Lookup = AccountIdLookup<AccountId, ()>;
/// The index type for storing how many extrinsics an account has signed.
type Index = Index;
/// The index type for blocks.
type BlockNumber = BlockNumber;
/// The type for hashing blocks and tries.
type Hash = Hash;
/// The hashing algorithm used.
type Hashing = BlakeTwo256;
/// The header type.
type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// The ubiquitous event type.
type Event = Event;
/// The ubiquitous origin type.
type Origin = Origin;
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
type BlockHashCount = BlockHashCount;
/// The weight of database operations that the runtime can invoke.
type DbWeight = RocksDbWeight;
/// Version of the runtime.
type Version = Version;
/// Converts a module to the index of the module in `construct_runtime!`.
///
/// This type is being generated by `construct_runtime!`.
type PalletInfo = PalletInfo;
/// What to do if a new account is created.
type OnNewAccount = ();
/// What to do if an account is fully reaped from the system.
type OnKilledAccount = ();
/// The data to be stored in an account.
type AccountData = pallet_balances::AccountData<Balance>;
/// Weight information for the extrinsics of this pallet.
type SystemWeightInfo = ();
/// This is used as an identifier of the chain. 42 is the generic substrate prefix.
type SS58Prefix = SS58Prefix;
/// The set code logic, just the default since we're not a parachain.
type OnSetCode = ();
}
impl pallet_randomness_collective_flip::Config for Runtime {}
impl pallet_aura::Config for Runtime {
type AuthorityId = sp_consensus_aura::sr25519::AuthorityId;
}
impl pallet_grandpa::Config for Runtime {
type Event = Event;
type Call = Call;
type KeyOwnerProofSystem = ();
type KeyOwnerProof =
<Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;
type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
GrandpaId,
)>>::IdentificationTuple;
type HandleEquivocation = ();
type WeightInfo = ();
}
impl pallet_timestamp::Config for Runtime {
/// A timestamp: milliseconds since the unix epoch.
type Moment = u64;
type OnTimestampSet = Aura;
type MinimumPeriod = MinimumPeriod;
type WeightInfo = ();
}
impl pallet_balances::Config for Runtime {
type MaxLocks = MaxLocks;
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
/// The type for recording an account's balance.
type Balance = Balance;
type Event = Event;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
}
impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction = CurrencyAdapter<Balances, ()>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = common_runtime::fees::WeightToFeeImpl<Balance>;
type FeeMultiplierUpdate = ();
}
impl pallet_sudo::Config for Runtime {
type Event = Event;
type Call = Call;
}
// PALLET IDENTITY
/// Configure the pallet identity
impl pallet_identity::Config for Runtime {
type ConfirmPeriod = ConfirmPeriod;
type Event = Event;
type AddRightOrigin = EnsureRoot<Self::AccountId>;
type DelRightOrigin = EnsureRoot<Self::AccountId>;
type EnsureIdtyCallAllowed = EnsureIdtyCallAllowedImpl<Runtime, IDTY_CREATE_PERIOD>;
type IdtyData = IdtyData;
type IdtyDid = IdtyDid;
type IdtyIndex = IdtyIndex;
type IdtyValidationOrigin = EnsureRoot<Self::AccountId>;
type IdtyRight = IdtyRight;
type OnIdtyChange = OnIdtyChangeHandler<Runtime>;
type OnRightKeyChange = OnRightKeyChangeHandler<Runtime>;
type MaxInactivityPeriod = MaxInactivityPeriod;
type MaxNoRightPeriod = MaxNoRightPeriod;
type RenewablePeriod = IdtyRenewablePeriod;
type ValidationPeriod = ValidationPeriod;
}
// PALLET CERTIFICATION
/// Configure the pallet certification
impl pallet_certification::Config for Runtime {
type AddCertOrigin = AddStrongCertOrigin<Runtime>;
type CertPeriod = CertPeriod;
type DelCertOrigin = DelStrongCertOrigin<Runtime>;
type Event = Event;
type IdtyIndex = IdtyIndex;
type MaxByIssuer = MaxByIssuer;
type OnNewcert =
OnNewStrongCertHandler<Runtime, MIN_STRONG_CERT_FOR_UD, MIN_STRONG_CERT_FOR_STRONG_CERT>;
type OnRemovedCert = OnRemovedStrongCertHandler<Runtime, MIN_STRONG_CERT_FOR_UD>;
type RenewablePeriod = StrongCertRenewablePeriod;
type ValidityPeriod = ValidityPeriod;
common_runtime::pallets_config! {
impl pallet_randomness_collective_flip::Config for Runtime {}
impl pallet_aura::Config for Runtime {
type AuthorityId = sp_consensus_aura::sr25519::AuthorityId;
}
impl pallet_timestamp::Config for Runtime {
/// A timestamp: milliseconds since the unix epoch.
type Moment = u64;
type OnTimestampSet = Aura;
type MinimumPeriod = MinimumPeriod;
type WeightInfo = ();
}
impl pallet_sudo::Config for Runtime {
type Event = Event;
type Call = Call;
}
}
// PALLET UNIVERSAL DIVIDEND
pub struct UdAccountsProvider;
impl Get<u64> for UdAccountsProvider {
fn get() -> u64 {
......@@ -291,21 +158,6 @@ impl Get<Vec<AccountId>> for UdAccountsProvider {
}
}
/// Configure the pallet universal-dividend in pallets/universal-dividend.
impl pallet_universal_dividend::Config for Runtime {
type Currency = pallet_balances::Pallet<Runtime>;
type Event = Event;
type MembersCount = UdAccountsProvider;
type MembersIds = UdAccountsProvider;
type SquareMoneyGrowthRate = SquareMoneyGrowthRate;
type UdCreationPeriod = UdCreationPeriod;
type UdReevalPeriod = UdReevalPeriod;
type UdReevalPeriodInBlocks = UdReevalPeriodInBlocks;
}
/// Configure the pallet ud-accounts-storage
impl pallet_ud_accounts_storage::Config for Runtime {}
// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime where
......@@ -358,10 +210,10 @@ pub type Executive = frame_executive::Executive<
// impl_runtime_apis! {
// // All impl blocks shared between all runtimes.
//
// // Specific impls provided to the `impl_runtime_apis_plus_common!` macro.
// // Specific impls provided to the `runtime_apis!` macro.
// }
// ```
common_runtime::impl_runtime_apis_plus_common! {
common_runtime::runtime_apis! {
impl sp_consensus_aura::AuraApi<Block, sp_consensus_aura::sr25519::AuthorityId> for Runtime {
fn slot_duration() -> sp_consensus_aura::SlotDuration {
sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())
......
......@@ -122,150 +122,19 @@ parameter_types! {
::with_sensible_defaults(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub const SS58Prefix: u8 = 42;
pub const SS58Prefix: u16 = 42;
}
// Configure FRAME pallets to include in runtime.
common_runtime::pallets_config! {
impl pallet_randomness_collective_flip::Config for Runtime {}
impl frame_system::Config for Runtime {
/// The basic call filter to use in dispatchable.
type BaseCallFilter = ();
/// Block & extrinsics weights: base values and limits.
type BlockWeights = BlockWeights;
/// The maximum length of a block (in bytes).
type BlockLength = BlockLength;
/// The identifier used to distinguish between accounts.
type AccountId = AccountId;
/// The aggregated dispatch type that is available for extrinsics.
type Call = Call;
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
type Lookup = AccountIdLookup<AccountId, ()>;
/// The index type for storing how many extrinsics an account has signed.
type Index = Index;
/// The index type for blocks.
type BlockNumber = BlockNumber;
/// The type for hashing blocks and tries.
type Hash = Hash;
/// The hashing algorithm used.
type Hashing = BlakeTwo256;
/// The header type.
type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// The ubiquitous event type.
type Event = Event;
/// The ubiquitous origin type.
type Origin = Origin;
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
type BlockHashCount = BlockHashCount;
/// The weight of database operations that the runtime can invoke.
type DbWeight = RocksDbWeight;
/// Version of the runtime.
type Version = Version;
/// Converts a module to the index of the module in `construct_runtime!`.
///
/// This type is being generated by `construct_runtime!`.
type PalletInfo = PalletInfo;
/// What to do if a new account is created.
type OnNewAccount = ();
/// What to do if an account is fully reaped from the system.
type OnKilledAccount = ();
/// The data to be stored in an account.
type AccountData = pallet_balances::AccountData<Balance>;
/// Weight information for the extrinsics of this pallet.
type SystemWeightInfo = ();
/// This is used as an identifier of the chain. 42 is the generic substrate prefix.
type SS58Prefix = SS58Prefix;
/// The set code logic, just the default since we're not a parachain.
type OnSetCode = ();
}
impl pallet_randomness_collective_flip::Config for Runtime {}
impl pallet_grandpa::Config for Runtime {
type Event = Event;
type Call = Call;
type KeyOwnerProofSystem = ();
type KeyOwnerProof =
<Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;
type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
GrandpaId,
)>>::IdentificationTuple;
type HandleEquivocation = ();
type WeightInfo = ();
}
impl pallet_balances::Config for Runtime {
type MaxLocks = MaxLocks;
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
/// The type for recording an account's balance.
type Balance = Balance;
/// The ubiquitous event type.
type Event = Event;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
}
impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction = CurrencyAdapter<Balances, ()>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = common_runtime::fees::WeightToFeeImpl<Balance>;
type FeeMultiplierUpdate = ();
}
impl pallet_sudo::Config for Runtime {
type Event = Event;
type Call = Call;
}
// PALLET IDENTITY
/// Configure the pallet identity
impl pallet_identity::Config for Runtime {
type ConfirmPeriod = ConfirmPeriod;
type Event = Event;
type AddRightOrigin = EnsureRoot<Self::AccountId>;
type DelRightOrigin = EnsureRoot<Self::AccountId>;
type EnsureIdtyCallAllowed = EnsureIdtyCallAllowedImpl<Runtime, IDTY_CREATE_PERIOD>;
type IdtyData = IdtyData;
type IdtyDid = IdtyDid;
type IdtyIndex = IdtyIndex;
type IdtyValidationOrigin = EnsureRoot<Self::AccountId>;
type IdtyRight = IdtyRight;
type OnIdtyChange = OnIdtyChangeHandler<Runtime>;
type OnRightKeyChange = OnRightKeyChangeHandler<Runtime>;
type MaxInactivityPeriod = MaxInactivityPeriod;
type MaxNoRightPeriod = MaxNoRightPeriod;
type RenewablePeriod = IdtyRenewablePeriod;
type ValidationPeriod = ValidationPeriod;
}
// PALLET CERTIFICATION
/// Configure the pallet certification
impl pallet_certification::Config for Runtime {
type AddCertOrigin = AddStrongCertOrigin<Runtime>;
type CertPeriod = CertPeriod;
type DelCertOrigin = DelStrongCertOrigin<Runtime>;
type Event = Event;
type IdtyIndex = IdtyIndex;
type MaxByIssuer = MaxByIssuer;
type OnNewcert =
OnNewStrongCertHandler<Runtime, MIN_STRONG_CERT_FOR_UD, MIN_STRONG_CERT_FOR_STRONG_CERT>;
type OnRemovedCert = OnRemovedStrongCertHandler<Runtime, MIN_STRONG_CERT_FOR_UD>;
type RenewablePeriod = StrongCertRenewablePeriod;
type ValidityPeriod = ValidityPeriod;
impl pallet_sudo::Config for Runtime {
type Event = Event;
type Call = Call;
}
}
// PALLET UNIVERSAL DIVIDEND
pub struct UdAccountsProvider;
impl Get<u64> for UdAccountsProvider {
fn get() -> u64 {
......@@ -278,21 +147,6 @@ impl Get<Vec<AccountId>> for UdAccountsProvider {
}
}
/// Configure the pallet universal-dividend in pallets/universal-dividend.
impl pallet_universal_dividend::Config for Runtime {
type Currency = pallet_balances::Pallet<Runtime>;
type Event = Event;
type MembersCount = UdAccountsProvider;
type MembersIds = UdAccountsProvider;
type SquareMoneyGrowthRate = SquareMoneyGrowthRate;
type UdCreationPeriod = UdCreationPeriod;
type UdReevalPeriod = UdReevalPeriod;
type UdReevalPeriodInBlocks = UdReevalPeriodInBlocks;
}
/// Configure the pallet ud-accounts-storage
impl pallet_ud_accounts_storage::Config for Runtime {}
// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime where
......@@ -343,10 +197,10 @@ pub type Executive = frame_executive::Executive<
// impl_runtime_apis! {
// // All impl blocks shared between all runtimes.
//
// // Specific impls provided to the `impl_runtime_apis_plus_common!` macro.
// // Specific impls provided to the `runtime_apis!` macro.
// }
// ```
common_runtime::impl_runtime_apis_plus_common! {
common_runtime::runtime_apis! {
impl sp_consensus_aura::AuraApi<Block, sp_consensus_aura::sr25519::AuthorityId> for Runtime {
fn slot_duration() -> sp_consensus_aura::SlotDuration {
sp_consensus_aura::SlotDuration::from_millis(0)
......
......@@ -124,161 +124,28 @@ parameter_types! {
::with_sensible_defaults(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub const SS58Prefix: u8 = 42;
pub const SS58Prefix: u16 = 42;
}
// Configure FRAME pallets to include in runtime.
impl frame_system::Config for Runtime {
/// The basic call filter to use in dispatchable.
type BaseCallFilter = ();
/// Block & extrinsics weights: base values and limits.
type BlockWeights = BlockWeights;
/// The maximum length of a block (in bytes).
type BlockLength = BlockLength;
/// The identifier used to distinguish between accounts.
type AccountId = AccountId;
/// The aggregated dispatch type that is available for extrinsics.
type Call = Call;
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
type Lookup = AccountIdLookup<AccountId, ()>;
/// The index type for storing how many extrinsics an account has signed.
type Index = Index;
/// The index type for blocks.
type BlockNumber = BlockNumber;