-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Grand Central Dispatch #5130
Grand Central Dispatch #5130
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,7 @@ | |
| use sp_std::{prelude::*, result}; | ||
| use sp_core::u32_trait::Value as U32; | ||
| use sp_runtime::RuntimeDebug; | ||
| use sp_runtime::traits::{Hash, EnsureOrigin}; | ||
| use sp_runtime::traits::{Hash, EnsureOrigin, Dispatcher}; | ||
| use frame_support::weights::SimpleDispatchInfo; | ||
| use frame_support::{ | ||
| dispatch::{Dispatchable, Parameter}, codec::{Encode, Decode}, | ||
|
|
@@ -69,6 +69,9 @@ pub trait Trait<I=DefaultInstance>: frame_system::Trait { | |
|
|
||
| /// The time-out for council motions. | ||
| type MotionDuration: Get<Self::BlockNumber>; | ||
|
|
||
| /// The means of dispatching the calls to the runtime. | ||
| type Dispatcher: Dispatcher<<Self as Trait<I>>::Proposal, <Self as Trait<I>>::Origin>; | ||
| } | ||
|
|
||
| /// Origin for the collective module. | ||
|
|
@@ -203,7 +206,7 @@ decl_module! { | |
| ensure!(Self::is_member(&who), Error::<T, I>::NotMember); | ||
|
|
||
| let proposal_hash = T::Hashing::hash_of(&proposal); | ||
| let ok = proposal.dispatch(RawOrigin::Member(who).into()).is_ok(); | ||
| let ok = T::Dispatcher::dispatch(*proposal, RawOrigin::Member(who).into()).is_ok(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we can ever come up with an abstraction here to actually prevent one from calling
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could require the trait to accept a parameter of a type for which an instance can only be created from the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rewrite applies gav's suggestion in order to accomplish this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have a |
||
| Self::deposit_event(RawEvent::MemberExecuted(proposal_hash, ok)); | ||
| } | ||
|
|
||
|
|
@@ -222,7 +225,7 @@ decl_module! { | |
|
|
||
| if threshold < 2 { | ||
| let seats = Self::members().len() as MemberCount; | ||
| let ok = proposal.dispatch(RawOrigin::Members(1, seats).into()).is_ok(); | ||
| let ok = T::Dispatcher::dispatch(*proposal, RawOrigin::Members(1, seats).into()).is_ok(); | ||
| Self::deposit_event(RawEvent::Executed(proposal_hash, ok)); | ||
| } else { | ||
| let index = Self::proposal_count(); | ||
|
|
@@ -360,7 +363,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> { | |
| // execute motion, assuming it exists. | ||
| if let Some(p) = ProposalOf::<T, I>::take(&proposal) { | ||
| let origin = RawOrigin::Members(voting.threshold, seats).into(); | ||
| let ok = p.dispatch(origin).is_ok(); | ||
| let ok = T::Dispatcher::dispatch(p, origin).is_ok(); | ||
| Self::deposit_event(RawEvent::Executed(proposal, ok)); | ||
| } | ||
| } else { | ||
|
|
@@ -537,18 +540,21 @@ mod tests { | |
| type AccountData = (); | ||
| type OnNewAccount = (); | ||
| type OnKilledAccount = (); | ||
| type RootDispatcher = (); | ||
| } | ||
| impl Trait<Instance1> for Test { | ||
| type Origin = Origin; | ||
| type Proposal = Call; | ||
| type Event = Event; | ||
| type MotionDuration = MotionDuration; | ||
| type Dispatcher = sp_runtime::SimpleDispatcher; | ||
| } | ||
| impl Trait for Test { | ||
| type Origin = Origin; | ||
| type Proposal = Call; | ||
| type Event = Event; | ||
| type MotionDuration = MotionDuration; | ||
| type Dispatcher = sp_runtime::SimpleDispatcher; | ||
| } | ||
|
|
||
| pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -165,7 +165,10 @@ | |||||||
|
|
||||||||
| use sp_std::prelude::*; | ||||||||
| use sp_runtime::{ | ||||||||
| DispatchResult, DispatchError, traits::{Zero, EnsureOrigin, Hash, Dispatchable, Saturating}, | ||||||||
| DispatchResult, DispatchError, traits::{ | ||||||||
| Zero, EnsureOrigin, Hash, Dispatchable, Dispatcher, Saturating | ||||||||
| }, | ||||||||
|
|
||||||||
| }; | ||||||||
| use codec::{Ref, Decode}; | ||||||||
| use frame_support::{ | ||||||||
|
|
@@ -270,6 +273,9 @@ pub trait Trait: frame_system::Trait + Sized { | |||||||
|
|
||||||||
| /// Handler for the unbalanced reduction when slashing a preimage deposit. | ||||||||
| type Slash: OnUnbalanced<NegativeImbalanceOf<Self>>; | ||||||||
|
|
||||||||
| /// The means of dispatching the proposals. | ||||||||
| type Dispatcher: Dispatcher<Self::Proposal, Self::Origin>; | ||||||||
| } | ||||||||
|
|
||||||||
| decl_storage! { | ||||||||
|
|
@@ -1539,7 +1545,11 @@ impl<T: Trait> Module<T> { | |||||||
| let _ = T::Currency::unreserve(&who, amount); | ||||||||
| Self::deposit_event(RawEvent::PreimageUsed(proposal_hash, who, amount)); | ||||||||
|
|
||||||||
| let ok = proposal.dispatch(frame_system::RawOrigin::Root.into()).is_ok(); | ||||||||
| let ok = T::Dispatcher::dispatch( | ||||||||
| proposal, | ||||||||
| frame_system::RawOrigin::Root.into() | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| ) | ||||||||
| .is_ok(); | ||||||||
| Self::deposit_event(RawEvent::Executed(index, ok)); | ||||||||
|
|
||||||||
| Ok(()) | ||||||||
|
|
@@ -1663,4 +1673,4 @@ impl<T: Trait> Module<T> { | |||||||
| } | ||||||||
| Ok(()) | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.