Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ sp-transaction-pool = { version = "2.0.0", default-features = false, path = "../
sp-version = { version = "2.0.0", default-features = false, path = "../../../primitives/version" }

# frame dependencies
frame-executive = { version = "2.0.0", default-features = false, path = "../../../frame/executive" }
frame-support = { version = "2.0.0", default-features = false, path = "../../../frame/support" }
frame-system = { version = "2.0.0", default-features = false, path = "../../../frame/system" }
frame-system-rpc-runtime-api = { version = "2.0.0", default-features = false, path = "../../../frame/system/rpc/runtime-api/" }
pallet-authority-discovery = { version = "2.0.0", default-features = false, path = "../../../frame/authority-discovery" }
pallet-authorship = { version = "2.0.0", default-features = false, path = "../../../frame/authorship" }
pallet-babe = { version = "2.0.0", default-features = false, path = "../../../frame/babe" }
Expand All @@ -40,7 +44,6 @@ pallet-contracts = { version = "2.0.0", default-features = false, path = "../../
pallet-contracts-rpc-runtime-api = { version = "2.0.0", default-features = false, path = "../../../frame/contracts/rpc/runtime-api/" }
pallet-democracy = { version = "2.0.0", default-features = false, path = "../../../frame/democracy" }
pallet-elections-phragmen = { version = "2.0.0", default-features = false, path = "../../../frame/elections-phragmen" }
frame-executive = { version = "2.0.0", default-features = false, path = "../../../frame/executive" }
pallet-finality-tracker = { version = "2.0.0", default-features = false, path = "../../../frame/finality-tracker" }
pallet-grandpa = { version = "2.0.0", default-features = false, path = "../../../frame/grandpa" }
pallet-im-online = { version = "2.0.0", default-features = false, path = "../../../frame/im-online" }
Expand All @@ -53,9 +56,6 @@ pallet-session = { version = "2.0.0", features = ["historical"], path = "../../.
pallet-staking = { version = "2.0.0", features = ["migrate"], path = "../../../frame/staking", default-features = false }
pallet-staking-reward-curve = { version = "2.0.0", path = "../../../frame/staking/reward-curve" }
pallet-sudo = { version = "2.0.0", default-features = false, path = "../../../frame/sudo" }
frame-support = { version = "2.0.0", default-features = false, path = "../../../frame/support" }
frame-system = { version = "2.0.0", default-features = false, path = "../../../frame/system" }
frame-system-rpc-runtime-api = { version = "2.0.0", default-features = false, path = "../../../frame/system/rpc/runtime-api/" }
pallet-timestamp = { version = "2.0.0", default-features = false, path = "../../../frame/timestamp" }
pallet-treasury = { version = "2.0.0", default-features = false, path = "../../../frame/treasury" }
pallet-utility = { version = "2.0.0", default-features = false, path = "../../../frame/utility" }
Expand Down
13 changes: 12 additions & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ use frame_support::{
use sp_core::u32_trait::{_1, _2, _3, _4};
use node_primitives::{AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, Moment, Signature};
use sp_api::impl_runtime_apis;
use sp_runtime::{Permill, Perbill, ApplyExtrinsicResult, impl_opaque_keys, generic, create_runtime_str};
use sp_runtime::{
Permill, Perbill, Percent, ApplyExtrinsicResult, impl_opaque_keys, generic, create_runtime_str
};
use sp_runtime::curve::PiecewiseLinear;
use sp_runtime::transaction_validity::TransactionValidity;
use sp_runtime::traits::{
Expand Down Expand Up @@ -376,6 +378,10 @@ parameter_types! {
pub const ProposalBondMinimum: Balance = 1 * DOLLARS;
pub const SpendPeriod: BlockNumber = 1 * DAYS;
pub const Burn: Permill = Permill::from_percent(50);
pub const TipCountdown: BlockNumber = 1 * DAYS;
pub const TipFindersFee: Percent = Percent::from_percent(20);
pub const TipReportDepositBase: Balance = 1 * DOLLARS;
pub const TipReportDepositPerByte: Balance = 1 * CENTS;
}

impl pallet_treasury::Trait for Runtime {
Expand All @@ -388,6 +394,11 @@ impl pallet_treasury::Trait for Runtime {
type ProposalBondMinimum = ProposalBondMinimum;
type SpendPeriod = SpendPeriod;
type Burn = Burn;
type Tippers = Elections;
type TipCountdown = TipCountdown;
type TipFindersFee = TipFindersFee;
type TipReportDepositBase = TipReportDepositBase;
type TipReportDepositPerByte = TipReportDepositPerByte;
}

parameter_types! {
Expand Down
9 changes: 5 additions & 4 deletions frame/democracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,8 +1144,7 @@ mod tests {
use std::cell::RefCell;
use frame_support::{
impl_outer_origin, impl_outer_dispatch, assert_noop, assert_ok, parameter_types,
traits::Contains,
weights::Weight,
ord_parameter_types, traits::Contains, weights::Weight,
};
use sp_core::H256;
use sp_runtime::{
Expand Down Expand Up @@ -1221,6 +1220,8 @@ mod tests {
pub const MinimumDeposit: u64 = 1;
pub const EnactmentPeriod: u64 = 2;
pub const CooloffPeriod: u64 = 2;
}
ord_parameter_types! {
pub const One: u64 = 1;
pub const Two: u64 = 2;
pub const Three: u64 = 3;
Expand All @@ -1229,8 +1230,8 @@ mod tests {
}
pub struct OneToFive;
impl Contains<u64> for OneToFive {
fn contains(n: &u64) -> bool {
*n >= 1 && *n <= 5
fn sorted_members() -> Vec<u64> {
vec![1, 2, 3, 4, 5]
}
}
thread_local! {
Expand Down
9 changes: 8 additions & 1 deletion frame/elections-phragmen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ use frame_support::{
decl_storage, decl_event, ensure, decl_module, decl_error, weights::SimpleDispatchInfo,
traits::{
Currency, Get, LockableCurrency, LockIdentifier, ReservableCurrency, WithdrawReasons,
ChangeMembers, OnUnbalanced, WithdrawReason
ChangeMembers, OnUnbalanced, WithdrawReason, Contains
}
};
use sp_phragmen::ExtendedBalance;
Expand Down Expand Up @@ -767,6 +767,13 @@ impl<T: Trait> Module<T> {
}
}

impl<T: Trait> Contains<T::AccountId> for Module<T> {
fn contains(who: &T::AccountId) -> bool {
Self::is_member(who)
}
fn sorted_members() -> Vec<T::AccountId> { Self::members_ids() }
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
7 changes: 6 additions & 1 deletion frame/identity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,10 @@ mod tests {
use super::*;

use sp_runtime::traits::BadOrigin;
use frame_support::{assert_ok, assert_noop, impl_outer_origin, parameter_types, weights::Weight};
use frame_support::{
assert_ok, assert_noop, impl_outer_origin, parameter_types, weights::Weight,
ord_parameter_types
};
use sp_core::H256;
use frame_system::EnsureSignedBy;
// The testing primitives are very useful for avoiding having to work with signatures
Expand Down Expand Up @@ -929,6 +932,8 @@ mod tests {
pub const FieldDeposit: u64 = 10;
pub const SubAccountDeposit: u64 = 10;
pub const MaximumSubAccounts: u32 = 2;
}
ord_parameter_types! {
pub const One: u64 = 1;
pub const Two: u64 = 2;
}
Expand Down
10 changes: 7 additions & 3 deletions frame/membership/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,15 @@ mod tests {
use super::*;

use std::cell::RefCell;
use frame_support::{assert_ok, assert_noop, impl_outer_origin, parameter_types, weights::Weight};
use frame_support::{
assert_ok, assert_noop, impl_outer_origin, parameter_types, weights::Weight,
ord_parameter_types
};
use frame_support::traits::Contains;
use sp_core::H256;
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are requried.
use sp_runtime::{Perbill, traits::{BlakeTwo256, IdentityLookup}, testing::Header, traits::BadOrigin};
use sp_runtime::{Perbill, traits::{BlakeTwo256, IdentityLookup, BadOrigin}, testing::Header};
use frame_system::EnsureSignedBy;

impl_outer_origin! {
Expand Down Expand Up @@ -267,7 +271,7 @@ mod tests {
type Version = ();
type ModuleToIndex = ();
}
parameter_types! {
ord_parameter_types! {
pub const One: u64 = 1;
pub const Two: u64 = 2;
pub const Three: u64 = 3;
Expand Down
7 changes: 6 additions & 1 deletion frame/nicks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ decl_module! {
mod tests {
use super::*;

use frame_support::{assert_ok, assert_noop, impl_outer_origin, parameter_types, weights::Weight};
use frame_support::{
assert_ok, assert_noop, impl_outer_origin, parameter_types, weights::Weight,
ord_parameter_types
};
use sp_core::H256;
use frame_system::EnsureSignedBy;
// The testing primitives are very useful for avoiding having to work with signatures
Expand Down Expand Up @@ -303,6 +306,8 @@ mod tests {
pub const ReservationFee: u64 = 2;
pub const MinLength: usize = 3;
pub const MaxLength: usize = 16;
}
ord_parameter_types! {
pub const One: u64 = 1;
}
impl Trait for Test {
Expand Down
9 changes: 5 additions & 4 deletions frame/scored-pool/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use super::*;

use std::cell::RefCell;
use frame_support::{impl_outer_origin, parameter_types, weights::Weight};
use frame_support::{impl_outer_origin, parameter_types, weights::Weight, ord_parameter_types};
use sp_core::H256;
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are requried.
Expand All @@ -41,9 +41,6 @@ parameter_types! {
pub const CandidateDeposit: u64 = 25;
pub const Period: u64 = 4;

pub const KickOrigin: u64 = 2;
pub const ScoreOrigin: u64 = 3;

pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
Expand All @@ -53,6 +50,10 @@ parameter_types! {
pub const TransferFee: u64 = 0;
pub const CreationFee: u64 = 0;
}
ord_parameter_types! {
pub const KickOrigin: u64 = 2;
pub const ScoreOrigin: u64 = 3;
}

impl frame_system::Trait for Test {
type Origin = Origin;
Expand Down
25 changes: 25 additions & 0 deletions frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,31 @@ macro_rules! parameter_types {
}
}

/// Macro for easily creating a new implementation of both the `Get` and `Contains` traits. Use
/// exactly as with `parameter_types`, only the type must be `Ord`.
#[macro_export]
macro_rules! ord_parameter_types {
(
$( #[ $attr:meta ] )*
$vis:vis const $name:ident: $type:ty = $value:expr;
$( $rest:tt )*
) => (
$( #[ $attr ] )*
$vis struct $name;
$crate::parameter_types!{IMPL $name , $type , $value}
$crate::ord_parameter_types!{IMPL $name , $type , $value}
$crate::ord_parameter_types!{ $( $rest )* }
);
() => ();
(IMPL $name:ident , $type:ty , $value:expr) => {
impl $crate::traits::Contains<$type> for $name {
fn contains(t: &$type) -> bool { &$value == t }
fn sorted_members() -> $crate::sp_std::prelude::Vec<$type> { vec![$value] }
fn count() -> usize { 1 }
}
}
}

#[doc(inline)]
pub use frame_support_procedural::{decl_storage, construct_runtime};

Expand Down
14 changes: 7 additions & 7 deletions frame/support/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ impl<T: Default> Get<T> for () {
/// A trait for querying whether a type can be said to statically "contain" a value. Similar
/// in nature to `Get`, except it is designed to be lazy rather than active (you can't ask it to
/// enumerate all values that it contains) and work for multiple values rather than just one.
pub trait Contains<T> {
pub trait Contains<T: Ord> {
/// Return `true` if this "contains" the given value `t`.
fn contains(t: &T) -> bool;
}
fn contains(t: &T) -> bool { Self::sorted_members().binary_search(t).is_ok() }

impl<V: PartialEq, T: Get<V>> Contains<V> for T {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this won't work if we also have specialisation for a module as we do now with the treasury module, hence the need for these changes and ord_parameter_types.

fn contains(t: &V) -> bool {
&Self::get() == t
}
/// Get a vector of all members in the set, ordered.
fn sorted_members() -> Vec<T>;

/// Get the number of items in the set.
fn count() -> usize { Self::sorted_members().len() }
}

/// The account with the given id was killed.
Expand Down
2 changes: 1 addition & 1 deletion frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ pub struct EnsureSignedBy<Who, AccountId>(sp_std::marker::PhantomData<(Who, Acco
impl<
O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>,
Who: Contains<AccountId>,
AccountId: PartialEq + Clone,
AccountId: PartialEq + Clone + Ord,
> EnsureOrigin<O> for EnsureSignedBy<Who, AccountId> {
type Success = AccountId;
fn try_origin(o: O) -> Result<Self::Success, O> {
Expand Down
Loading