mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 17:28:00 +00:00
Allow modules to validate transaction, second attempt (#2463)
* first impl * rename origin::inherent to none * fix * fix * Apply suggestions from code review Co-Authored-By: thiolliere <gui.thiolliere@gmail.com> * comment * better error * doc * (add unsigned module 🤦) * doc * fix * implement for node-template as well * add validated unsigned to executor * fix * fix * bump version * testing xt * remove extraneous logic * licence * impl test
This commit is contained in:
@@ -233,15 +233,17 @@ pub enum RawOrigin<AccountId> {
|
||||
Root,
|
||||
/// It is signed by some public key and we provide the `AccountId`.
|
||||
Signed(AccountId),
|
||||
/// It is signed by nobody but included and agreed upon by the validators anyway: it's "inherently" true.
|
||||
Inherent,
|
||||
/// It is signed by nobody, can be either:
|
||||
/// * included and agreed upon by the validators anyway,
|
||||
/// * or unsigned transaction validated by a module.
|
||||
None,
|
||||
}
|
||||
|
||||
impl<AccountId> From<Option<AccountId>> for RawOrigin<AccountId> {
|
||||
fn from(s: Option<AccountId>) -> RawOrigin<AccountId> {
|
||||
match s {
|
||||
Some(who) => RawOrigin::Signed(who),
|
||||
None => RawOrigin::Inherent,
|
||||
None => RawOrigin::None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -363,12 +365,12 @@ pub fn ensure_root<OuterOrigin, AccountId>(o: OuterOrigin) -> Result<(), &'stati
|
||||
}
|
||||
|
||||
/// Ensure that the origin `o` represents an unsigned extrinsic. Returns `Ok` or an `Err` otherwise.
|
||||
pub fn ensure_inherent<OuterOrigin, AccountId>(o: OuterOrigin) -> Result<(), &'static str>
|
||||
pub fn ensure_none<OuterOrigin, AccountId>(o: OuterOrigin) -> Result<(), &'static str>
|
||||
where OuterOrigin: Into<Option<RawOrigin<AccountId>>>
|
||||
{
|
||||
match o.into() {
|
||||
Some(RawOrigin::Inherent) => Ok(()),
|
||||
_ => Err("bad origin: expected to be an inherent origin"),
|
||||
Some(RawOrigin::None) => Ok(()),
|
||||
_ => Err("bad origin: expected to be no origin"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user