mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 20:57:59 +00:00
This PR reverts #2280 which introduced `TransactionExtension` to replace `SignedExtension`. As a result of the discussion [here](https://github.com/paritytech/polkadot-sdk/pull/3623#issuecomment-1986789700), the changes will be reverted for now with plans to reintroduce the concept in the future. --------- Signed-off-by: georgepisaltu <george.pisaltu@parity.io>
This commit is contained in:
@@ -18,115 +18,81 @@
|
||||
//! Generic implementation of an extrinsic that has passed the verification
|
||||
//! stage.
|
||||
|
||||
use codec::Encode;
|
||||
|
||||
use crate::{
|
||||
traits::{
|
||||
self, transaction_extension::TransactionExtension, DispatchInfoOf, DispatchTransaction,
|
||||
Dispatchable, MaybeDisplay, Member, PostDispatchInfoOf, ValidateUnsigned,
|
||||
self, DispatchInfoOf, Dispatchable, MaybeDisplay, Member, PostDispatchInfoOf,
|
||||
SignedExtension, ValidateUnsigned,
|
||||
},
|
||||
transaction_validity::{TransactionSource, TransactionValidity},
|
||||
};
|
||||
|
||||
/// The kind of extrinsic this is, including any fields required of that kind. This is basically
|
||||
/// the full extrinsic except the `Call`.
|
||||
#[derive(PartialEq, Eq, Clone, sp_core::RuntimeDebug)]
|
||||
pub enum ExtrinsicFormat<AccountId, Extension> {
|
||||
/// Extrinsic is bare; it must pass either the bare forms of `TransactionExtension` or
|
||||
/// `ValidateUnsigned`, both deprecated, or alternatively a `ProvideInherent`.
|
||||
Bare,
|
||||
/// Extrinsic has a default `Origin` of `Signed(AccountId)` and must pass all
|
||||
/// `TransactionExtension`s regular checks and includes all extension data.
|
||||
Signed(AccountId, Extension),
|
||||
/// Extrinsic has a default `Origin` of `None` and must pass all `TransactionExtension`s.
|
||||
/// regular checks and includes all extension data.
|
||||
General(Extension),
|
||||
}
|
||||
|
||||
// TODO: Rename ValidateUnsigned to ValidateInherent
|
||||
// TODO: Consider changing ValidateInherent API to avoid need for duplicating validate
|
||||
// code into pre_dispatch (rename that to `prepare`).
|
||||
// TODO: New extrinsic type corresponding to `ExtrinsicFormat::General`, which is
|
||||
// unsigned but includes extension data.
|
||||
// TODO: Move usage of `signed` to `format`:
|
||||
// - Inherent instead of None.
|
||||
// - Signed(id, extension) instead of Some((id, extra)).
|
||||
// - Introduce General(extension) for one without a signature.
|
||||
|
||||
/// Definition of something that the external world might want to say; its existence implies that it
|
||||
/// has been checked and is good, particularly with regards to the signature.
|
||||
///
|
||||
/// This is typically passed into [`traits::Applyable::apply`], which should execute
|
||||
/// [`CheckedExtrinsic::function`], alongside all other bits and bobs.
|
||||
#[derive(PartialEq, Eq, Clone, sp_core::RuntimeDebug)]
|
||||
pub struct CheckedExtrinsic<AccountId, Call, Extension> {
|
||||
pub struct CheckedExtrinsic<AccountId, Call, Extra> {
|
||||
/// Who this purports to be from and the number of extrinsics have come before
|
||||
/// from the same signer, if anyone (note this is not a signature).
|
||||
pub format: ExtrinsicFormat<AccountId, Extension>,
|
||||
pub signed: Option<(AccountId, Extra)>,
|
||||
|
||||
/// The function that should be called.
|
||||
pub function: Call,
|
||||
}
|
||||
|
||||
impl<AccountId, Call, Extension, RuntimeOrigin> traits::Applyable
|
||||
for CheckedExtrinsic<AccountId, Call, Extension>
|
||||
impl<AccountId, Call, Extra, RuntimeOrigin> traits::Applyable
|
||||
for CheckedExtrinsic<AccountId, Call, Extra>
|
||||
where
|
||||
AccountId: Member + MaybeDisplay,
|
||||
Call: Member + Dispatchable<RuntimeOrigin = RuntimeOrigin> + Encode,
|
||||
Extension: TransactionExtension<Call, ()>,
|
||||
Call: Member + Dispatchable<RuntimeOrigin = RuntimeOrigin>,
|
||||
Extra: SignedExtension<AccountId = AccountId, Call = Call>,
|
||||
RuntimeOrigin: From<Option<AccountId>>,
|
||||
{
|
||||
type Call = Call;
|
||||
|
||||
fn validate<I: ValidateUnsigned<Call = Self::Call>>(
|
||||
fn validate<U: ValidateUnsigned<Call = Self::Call>>(
|
||||
&self,
|
||||
// TODO [#5006;ToDr] should source be passed to `SignedExtension`s?
|
||||
// Perhaps a change for 2.0 to avoid breaking too much APIs?
|
||||
source: TransactionSource,
|
||||
info: &DispatchInfoOf<Self::Call>,
|
||||
len: usize,
|
||||
) -> TransactionValidity {
|
||||
match self.format {
|
||||
ExtrinsicFormat::Bare => {
|
||||
let inherent_validation = I::validate_unsigned(source, &self.function)?;
|
||||
#[allow(deprecated)]
|
||||
let legacy_validation = Extension::validate_bare_compat(&self.function, info, len)?;
|
||||
Ok(legacy_validation.combine_with(inherent_validation))
|
||||
},
|
||||
ExtrinsicFormat::Signed(ref signer, ref extension) => {
|
||||
let origin = Some(signer.clone()).into();
|
||||
extension.validate_only(origin, &self.function, info, len).map(|x| x.0)
|
||||
},
|
||||
ExtrinsicFormat::General(ref extension) =>
|
||||
extension.validate_only(None.into(), &self.function, info, len).map(|x| x.0),
|
||||
if let Some((ref id, ref extra)) = self.signed {
|
||||
Extra::validate(extra, id, &self.function, info, len)
|
||||
} else {
|
||||
let valid = Extra::validate_unsigned(&self.function, info, len)?;
|
||||
let unsigned_validation = U::validate_unsigned(source, &self.function)?;
|
||||
Ok(valid.combine_with(unsigned_validation))
|
||||
}
|
||||
}
|
||||
|
||||
fn apply<I: ValidateUnsigned<Call = Self::Call>>(
|
||||
fn apply<U: ValidateUnsigned<Call = Self::Call>>(
|
||||
self,
|
||||
info: &DispatchInfoOf<Self::Call>,
|
||||
len: usize,
|
||||
) -> crate::ApplyExtrinsicResultWithInfo<PostDispatchInfoOf<Self::Call>> {
|
||||
match self.format {
|
||||
ExtrinsicFormat::Bare => {
|
||||
I::pre_dispatch(&self.function)?;
|
||||
// TODO: Remove below once `pre_dispatch_unsigned` is removed from `LegacyExtension`
|
||||
// or `LegacyExtension` is removed.
|
||||
#[allow(deprecated)]
|
||||
Extension::validate_bare_compat(&self.function, info, len)?;
|
||||
#[allow(deprecated)]
|
||||
Extension::pre_dispatch_bare_compat(&self.function, info, len)?;
|
||||
let res = self.function.dispatch(None.into());
|
||||
let post_info = res.unwrap_or_else(|err| err.post_info);
|
||||
let pd_res = res.map(|_| ()).map_err(|e| e.error);
|
||||
// TODO: Remove below once `pre_dispatch_unsigned` is removed from `LegacyExtension`
|
||||
// or `LegacyExtension` is removed.
|
||||
#[allow(deprecated)]
|
||||
Extension::post_dispatch_bare_compat(info, &post_info, len, &pd_res)?;
|
||||
Ok(res)
|
||||
},
|
||||
ExtrinsicFormat::Signed(signer, extension) =>
|
||||
extension.dispatch_transaction(Some(signer).into(), self.function, info, len),
|
||||
ExtrinsicFormat::General(extension) =>
|
||||
extension.dispatch_transaction(None.into(), self.function, info, len),
|
||||
}
|
||||
let (maybe_who, maybe_pre) = if let Some((id, extra)) = self.signed {
|
||||
let pre = Extra::pre_dispatch(extra, &id, &self.function, info, len)?;
|
||||
(Some(id), Some(pre))
|
||||
} else {
|
||||
Extra::pre_dispatch_unsigned(&self.function, info, len)?;
|
||||
U::pre_dispatch(&self.function)?;
|
||||
(None, None)
|
||||
};
|
||||
let res = self.function.dispatch(RuntimeOrigin::from(maybe_who));
|
||||
let post_info = match res {
|
||||
Ok(info) => info,
|
||||
Err(err) => err.post_info,
|
||||
};
|
||||
Extra::post_dispatch(
|
||||
maybe_pre,
|
||||
info,
|
||||
&post_info,
|
||||
len,
|
||||
&res.map(|_| ()).map_err(|e| e.error),
|
||||
)?;
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +29,9 @@ mod unchecked_extrinsic;
|
||||
|
||||
pub use self::{
|
||||
block::{Block, BlockId, SignedBlock},
|
||||
checked_extrinsic::{CheckedExtrinsic, ExtrinsicFormat},
|
||||
checked_extrinsic::CheckedExtrinsic,
|
||||
digest::{Digest, DigestItem, DigestItemRef, OpaqueDigestItemId},
|
||||
era::{Era, Phase},
|
||||
header::Header,
|
||||
unchecked_extrinsic::{Preamble, SignedPayload, UncheckedExtrinsic},
|
||||
unchecked_extrinsic::{SignedPayload, UncheckedExtrinsic},
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user