Skip to content

Commit

Permalink
Backing/GetBacking: Abstraction over pluralistic origins for XCM. (pa…
Browse files Browse the repository at this point in the history
…ritytech#8579)

* Backing/GetBacking: Abstraction over pluralistic origins for XCM.

* Update frame/support/src/traits/misc.rs

Co-authored-by: Kian Paimani <[email protected]>

* Update frame/support/src/traits/misc.rs

Co-authored-by: Kian Paimani <[email protected]>

Co-authored-by: Kian Paimani <[email protected]>
  • Loading branch information
gavofyork and kianenigma authored Apr 9, 2021
1 parent 35b74db commit 787ea59
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
11 changes: 10 additions & 1 deletion frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use frame_support::{
PostDispatchInfo,
},
ensure,
traits::{ChangeMembers, EnsureOrigin, Get, InitializeMembers},
traits::{ChangeMembers, EnsureOrigin, Get, InitializeMembers, GetBacking, Backing},
weights::{DispatchClass, GetDispatchInfo, Weight, Pays},
};
use frame_system::{self as system, ensure_signed, ensure_root};
Expand Down Expand Up @@ -165,6 +165,15 @@ pub enum RawOrigin<AccountId, I> {
_Phantom(sp_std::marker::PhantomData<I>),
}

impl<AccountId, I> GetBacking for RawOrigin<AccountId, I> {
fn get_backing(&self) -> Option<Backing> {
match self {
RawOrigin::Members(n, d) => Some(Backing { approvals: *n, eligible: *d }),
_ => None,
}
}
}

/// Origin for the collective module.
pub type Origin<T, I=DefaultInstance> = RawOrigin<<T as frame_system::Config>::AccountId, I>;

Expand Down
2 changes: 1 addition & 1 deletion frame/support/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub use filter::{
mod misc;
pub use misc::{
Len, Get, GetDefault, HandleLifetime, TryDrop, Time, UnixTime, IsType, IsSubType, ExecuteBlock,
SameOrOther, OnNewAccount, OnKilledAccount, OffchainWorker,
SameOrOther, OnNewAccount, OnKilledAccount, OffchainWorker, GetBacking, Backing,
};

mod stored_map;
Expand Down
15 changes: 15 additions & 0 deletions frame/support/src/traits/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,18 @@ pub trait OffchainWorker<BlockNumber> {
fn offchain_worker(_n: BlockNumber) {}
}

/// Some amount of backing from a group. The precise defintion of what it means to "back" something
/// is left flexible.
pub struct Backing {
/// The number of members of the group that back some motion.
pub approvals: u32,
/// The total count of group members.
pub eligible: u32,
}

/// Retrieve the backing from an object's ref.
pub trait GetBacking {
/// Returns `Some` `Backing` if `self` represents a fractional/groupwise backing of some
/// implicit motion. `None` if it does not.
fn get_backing(&self) -> Option<Backing>;
}

0 comments on commit 787ea59

Please sign in to comment.