Add tipping into treasury (#4480)

* First draft

* Initial work on tests

* Add tests.

* Ensure old members can't tip.

* Fix complexity

* Update node runtime

* Build fix.

* build fix

* Fix tests

* Fix tests

* Refactor Contains impl for tests

* Introduce new way to avoid impl Contains conflicts

* Fixes

* Docs.

* Docs.

* Typo

* Whitespace

* Docs

* Typo

* Formatting

* Update frame/treasury/src/lib.rs

Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com>

* Update frame/treasury/src/lib.rs

Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com>

* Update frame/treasury/src/lib.rs

Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com>

* Apply suggestions from code review

Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com>

* Add provisional weights.

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Gavin Wood
2020-01-09 14:39:12 +01:00
committed by Shawn Tabrizi
parent 586685fca0
commit 67202b7ec3
12 changed files with 666 additions and 100 deletions
+25
View File
@@ -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};
+7 -7
View File
@@ -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 {
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.