This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Dispatch Macro Enhancements #681
Copy link
Copy link
Closed
Labels
J0-enhancementAn additional feature request.An additional feature request.
Milestone
Description
- 1. Introduce ability to not have
originparameter at all (dispatch pre-executessystem::ensure_root(origin)?) - 2. Introduce logic for arbitrary origin matching in the macro
Notes
fndefinitions indecl_modulethat do not include anoriginterm should be assumed to be privileged and automaticallyensure!thatorigin == Root.
Before:
pub struct Module<T: Trait>;
pub enum Call where aux: T::PublicAux {
fn propose_spend(aux, value: T::Balance, beneficiary: T::AccountId) -> Result = 0;
}
pub enum PrivCall {
fn set_pot(new_pot: T::Balance) -> Result = 0;
}
After:
pub struct Module<T: Trait> where origin: T::Origin {
fn propose_spend(origin, value: T::Balance, beneficiary: T::AccountId) -> Result = 0;
fn set_pot(new_pot: T::Balance) -> Result = 1;
}
- This can be done by ensuring that the
impl_dispatchplaces theensure!in thematchdispatcher before dispatching in the cases where no origin is provided. A more sophisticated macro would allow origin to be required to match a particular value:
Before:
use {T::Origin::council as CouncilOrigin, council::Origin::Members};
use {T::Origin::system as SystemOrigin, system::Origin::Signed};
pub struct Module<T: Trait> where origin: T::Origin {
fn propose(origin, value: T::Balance, beneficiary: T::AccountId) -> Result = 0;
fn accept(origin, index: ProposalIndex) -> Result = 1;
}
impl<T: Trait> Module<T> {
fn propose(origin: T::Origin, index: ProposalIndex) -> Result {
match origin {
SystemOrigin(Signed(&who)) => {
ensure!(Self::check_account(who), "not a good account");
Self::do_some_stuff(who)
}
_ => return Err("invalid origin"),
}
}
fn accept(origin: T::Origin, index: ProposalIndex) -> Result {
match origin {
CouncilOrigin(Members(n)) if n >= 2 => {
// ...
}
_ => return Err("invalid origin"),
}
}
}
After:
use {T::Origin::council as CouncilOrigin, council::Origin::Members};
pub struct Module<T: Trait> where origin: T::Origin {
fn propose(SystemOrigin(Signed(who)), value: T::Balance, beneficiary: T::AccountId) -> Result = 0;
fn accept(CouncilOrigin(Members(n)) if n >= 2, index: ProposalIndex) -> Result = 1;
}
impl<T: Trait> Module<T> {
fn propose(who: &T::AccountId, index: ProposalIndex) -> Result {
ensure!(Self::check_account(who), "not a good account");
Self::do_some_stuff(who)
}
fn accept(index: ProposalIndex) -> Result {
// ...
}
}
Metadata
Metadata
Assignees
Labels
J0-enhancementAn additional feature request.An additional feature request.