Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Introduce DispatchInfoOf type alias
  • Loading branch information
athei committed Apr 7, 2020
commit 211334abe642fa2f05d2a33e7961db875ef5b83d
7 changes: 5 additions & 2 deletions frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ use sp_std::{prelude::*, marker::PhantomData, fmt::Debug};
use codec::{Codec, Encode, Decode};
use sp_io::hashing::blake2_256;
use sp_runtime::{
traits::{Hash, StaticLookup, Zero, MaybeSerializeDeserialize, Member, SignedExtension},
traits::{
Hash, StaticLookup, Zero, MaybeSerializeDeserialize, Member, SignedExtension,
DispatchInfoOf,
},
transaction_validity::{
ValidTransaction, InvalidTransaction, TransactionValidity, TransactionValidityError,
},
Expand Down Expand Up @@ -1098,7 +1101,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckBlockGasLimit<T> {
&self,
_: &Self::AccountId,
call: &Self::Call,
_: &<Self::Call as Dispatchable>::Info,
_: &DispatchInfoOf<Self::Call>,
_: usize,
) -> TransactionValidity {
let call = match call.is_sub_type() {
Expand Down
6 changes: 4 additions & 2 deletions frame/example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ use sp_std::prelude::*;
use frame_system::{self as system, ensure_signed, ensure_root};
use codec::{Encode, Decode};
use sp_runtime::{
traits::{SignedExtension, Bounded, SaturatedConversion, Dispatchable},
traits::{
SignedExtension, Bounded, SaturatedConversion, DispatchInfoOf,
},
transaction_validity::{
ValidTransaction, TransactionValidityError, InvalidTransaction, TransactionValidity,
},
Expand Down Expand Up @@ -626,7 +628,7 @@ impl<T: Trait + Send + Sync> SignedExtension for WatchDummy<T> {
&self,
_who: &Self::AccountId,
call: &Self::Call,
_info: &<Self::Call as Dispatchable>::Info,
_info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> TransactionValidity {
// if the transaction is too big, just drop it.
Expand Down
4 changes: 2 additions & 2 deletions frame/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ use sp_runtime::{
curve::PiecewiseLinear,
traits::{
Convert, Zero, StaticLookup, CheckedSub, Saturating, SaturatedConversion, AtLeast32Bit,
SignedExtension, Dispatchable
SignedExtension, Dispatchable, DispatchInfoOf,
},
transaction_validity::{
TransactionValidityError, TransactionValidity, ValidTransaction, InvalidTransaction,
Expand Down Expand Up @@ -3133,7 +3133,7 @@ impl<T: Trait + Send + Sync> SignedExtension for LockStakingStatus<T> {
&self,
_who: &Self::AccountId,
call: &Self::Call,
_info: &<Self::Call as Dispatchable>::Info,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> TransactionValidity {
if let Some(inner_call) = call.is_sub_type() {
Expand Down
30 changes: 15 additions & 15 deletions frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ use sp_runtime::{
self, CheckEqual, AtLeast32Bit, Zero, SignedExtension, Lookup, LookupError,
SimpleBitOps, Hash, Member, MaybeDisplay, BadOrigin, SaturatedConversion,
MaybeSerialize, MaybeSerializeDeserialize, MaybeMallocSizeOf, StaticLookup, One, Bounded,
Dispatchable,
Dispatchable, DispatchInfoOf, PostDispatchInfoOf,
},
};

Expand Down Expand Up @@ -1183,7 +1183,7 @@ impl<T: Trait + Send + Sync> CheckWeight<T> where
///
/// Upon successes, it returns the new block weight as a `Result`.
fn check_weight(
info: &<T::Call as Dispatchable>::Info,
info: &DispatchInfoOf<T::Call>,
) -> Result<Weight, TransactionValidityError> {
let current_weight = Module::<T>::all_extrinsics_weight();
let maximum_weight = T::MaximumBlockWeight::get();
Expand All @@ -1201,7 +1201,7 @@ impl<T: Trait + Send + Sync> CheckWeight<T> where
///
/// Upon successes, it returns the new block length as a `Result`.
fn check_block_length(
info: &<T::Call as Dispatchable>::Info,
info: &DispatchInfoOf<T::Call>,
len: usize,
) -> Result<u32, TransactionValidityError> {
let current_len = Module::<T>::all_extrinsics_len();
Expand All @@ -1217,7 +1217,7 @@ impl<T: Trait + Send + Sync> CheckWeight<T> where
}

/// get the priority of an extrinsic denoted by `info`.
fn get_priority(info: &<T::Call as Dispatchable>::Info) -> TransactionPriority {
fn get_priority(info: &DispatchInfoOf<T::Call>) -> TransactionPriority {
match info.class {
DispatchClass::Normal => info.weight.into(),
DispatchClass::Operational => Bounded::max_value(),
Expand All @@ -1235,7 +1235,7 @@ impl<T: Trait + Send + Sync> CheckWeight<T> where
///
/// It checks and notes the new weight and length.
fn do_pre_dispatch(
info: &<T::Call as Dispatchable>::Info,
info: &DispatchInfoOf<T::Call>,
len: usize,
) -> Result<(), TransactionValidityError> {
let next_len = Self::check_block_length(info, len)?;
Expand All @@ -1249,7 +1249,7 @@ impl<T: Trait + Send + Sync> CheckWeight<T> where
///
/// It only checks that the block weight and length limit will not exceed.
fn do_validate(
info: &<T::Call as Dispatchable>::Info,
info: &DispatchInfoOf<T::Call>,
len: usize,
) -> TransactionValidity {
// ignore the next weight and length. If they return `Ok`, then it is below the limit.
Expand All @@ -1275,7 +1275,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckWeight<T> where
self,
_who: &Self::AccountId,
_call: &Self::Call,
info: &<Self::Call as Dispatchable>::Info,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> Result<(), TransactionValidityError> {
if info.class == DispatchClass::Mandatory {
Expand All @@ -1288,7 +1288,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckWeight<T> where
&self,
_who: &Self::AccountId,
_call: &Self::Call,
info: &<Self::Call as Dispatchable>::Info,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> TransactionValidity {
if info.class == DispatchClass::Mandatory {
Expand All @@ -1299,24 +1299,24 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckWeight<T> where

fn pre_dispatch_unsigned(
_call: &Self::Call,
info: &<Self::Call as Dispatchable>::Info,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> Result<(), TransactionValidityError> {
Self::do_pre_dispatch(info, len)
}

fn validate_unsigned(
_call: &Self::Call,
info: &<Self::Call as Dispatchable>::Info,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> TransactionValidity {
Self::do_validate(info, len)
}

fn post_dispatch(
_pre: Self::Pre,
info: &<Self::Call as Dispatchable>::Info,
_post_info: &<Self::Call as Dispatchable>::PostInfo,
info: &DispatchInfoOf<Self::Call>,
_post_info: &PostDispatchInfoOf<Self::Call>,
_len: usize,
result: &DispatchResult,
) -> Result<(), TransactionValidityError> {
Expand Down Expand Up @@ -1380,7 +1380,7 @@ impl<T: Trait> SignedExtension for CheckNonce<T> where
self,
who: &Self::AccountId,
_call: &Self::Call,
_info: &<Self::Call as Dispatchable>::Info,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> Result<(), TransactionValidityError> {
let mut account = Account::<T>::get(who);
Expand All @@ -1402,7 +1402,7 @@ impl<T: Trait> SignedExtension for CheckNonce<T> where
&self,
who: &Self::AccountId,
_call: &Self::Call,
info: &<Self::Call as Dispatchable>::Info,
info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> TransactionValidity {
// check index
Expand Down Expand Up @@ -1468,7 +1468,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckEra<T> {
&self,
_who: &Self::AccountId,
_call: &Self::Call,
_info: &<Self::Call as Dispatchable>::Info,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> TransactionValidity {
let current_u64 = <Module<T>>::block_number().saturated_into::<u64>();
Expand Down
9 changes: 6 additions & 3 deletions frame/transaction-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ use sp_runtime::{
TransactionPriority, ValidTransaction, InvalidTransaction, TransactionValidityError,
TransactionValidity,
},
traits::{Zero, Saturating, SignedExtension, SaturatedConversion, Convert, Dispatchable},
traits::{
Zero, Saturating, SignedExtension, SaturatedConversion, Convert, Dispatchable,
DispatchInfoOf,
},
};
use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;

Expand Down Expand Up @@ -160,7 +163,7 @@ impl<T: Trait + Send + Sync> ChargeTransactionPayment<T> where
/// final_fee = base_fee + targeted_fee_adjustment(len_fee + weight_fee) + tip;
pub fn compute_fee(
len: u32,
info: &<T::Call as Dispatchable>::Info,
info: &DispatchInfoOf<T::Call>,
tip: BalanceOf<T>,
) -> BalanceOf<T>
where
Expand Down Expand Up @@ -219,7 +222,7 @@ impl<T: Trait + Send + Sync> SignedExtension for ChargeTransactionPayment<T> whe
&self,
who: &Self::AccountId,
_call: &Self::Call,
info: &<Self::Call as Dispatchable>::Info,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> TransactionValidity {
// pay any fees.
Expand Down
7 changes: 3 additions & 4 deletions primitives/runtime/src/generic/checked_extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
//! stage.

use crate::traits::{
self, Member, MaybeDisplay, SignedExtension, Dispatchable,
self, Member, MaybeDisplay, SignedExtension, Dispatchable, DispatchInfoOf, ValidateUnsigned,
};
use crate::traits::ValidateUnsigned;
use crate::transaction_validity::{TransactionValidity, TransactionSource};

/// Definition of something that the external world might want to say; its
Expand Down Expand Up @@ -51,7 +50,7 @@ where
// 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: &<Self::Call as Dispatchable>::Info,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> TransactionValidity {
if let Some((ref id, ref extra)) = self.signed {
Expand All @@ -65,7 +64,7 @@ where

fn apply<U: ValidateUnsigned<Call=Self::Call>>(
self,
info: &<Self::Call as Dispatchable>::Info,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> crate::ApplyExtrinsicResult {
let (maybe_who, pre) = if let Some((id, extra)) = self.signed {
Expand Down
6 changes: 3 additions & 3 deletions primitives/runtime/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::{fmt::Debug, ops::Deref, fmt, cell::RefCell};
use crate::codec::{Codec, Encode, Decode};
use crate::traits::{
self, Checkable, Applyable, BlakeTwo256, OpaqueKeys,
SignedExtension, Dispatchable,
SignedExtension, Dispatchable, DispatchInfoOf,
};
use crate::traits::ValidateUnsigned;
use crate::{generic, KeyTypeId, ApplyExtrinsicResult};
Expand Down Expand Up @@ -356,7 +356,7 @@ impl<Origin, Call, Extra> Applyable for TestXt<Call, Extra> where
fn validate<U: ValidateUnsigned<Call=Self::Call>>(
&self,
_source: TransactionSource,
_info: &<Self::Call as Dispatchable>::Info,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> TransactionValidity {
Ok(Default::default())
Expand All @@ -366,7 +366,7 @@ impl<Origin, Call, Extra> Applyable for TestXt<Call, Extra> where
/// index and sender.
fn apply<U: ValidateUnsigned<Call=Self::Call>>(
self,
info: &<Self::Call as Dispatchable>::Info,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> ApplyExtrinsicResult {
let maybe_who = if let Some((who, extra)) = self.signature {
Expand Down
33 changes: 19 additions & 14 deletions primitives/runtime/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,11 @@ pub trait Dispatchable {
fn dispatch(self, origin: Self::Origin) -> crate::DispatchResultWithInfo<Self::PostInfo>;
}

/// Shortcut to reference the `Info` type of a `Dispatchable`.
pub type DispatchInfoOf<T> = <T as Dispatchable>::Info;
/// Shortcut to reference the `PostInfo` type of a `Dispatchable`.
pub type PostDispatchInfoOf<T> = <T as Dispatchable>::PostInfo;

impl Dispatchable for () {
type Origin = ();
type Trait = ();
Expand Down Expand Up @@ -685,7 +690,7 @@ pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq
&self,
_who: &Self::AccountId,
_call: &Self::Call,
_info: &<Self::Call as Dispatchable>::Info,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> TransactionValidity {
Ok(ValidTransaction::default())
Expand All @@ -703,7 +708,7 @@ pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq
self,
who: &Self::AccountId,
call: &Self::Call,
info: &<Self::Call as Dispatchable>::Info,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
self.validate(who, call, info.clone(), len)
Expand All @@ -721,7 +726,7 @@ pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq
/// Make sure to perform the same checks in `pre_dispatch_unsigned` function.
fn validate_unsigned(
_call: &Self::Call,
_info: &<Self::Call as Dispatchable>::Info,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> TransactionValidity {
Ok(ValidTransaction::default())
Expand All @@ -737,7 +742,7 @@ pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq
/// perform the same validation as in `validate_unsigned`.
fn pre_dispatch_unsigned(
call: &Self::Call,
info: &<Self::Call as Dispatchable>::Info,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
Self::validate_unsigned(call, info.clone(), len)
Expand All @@ -760,8 +765,8 @@ pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq
/// will come from either an offchain-worker or via `InherentData`.
fn post_dispatch(
_pre: Self::Pre,
_info: &<Self::Call as Dispatchable>::Info,
_post_info: &<Self::Call as Dispatchable>::PostInfo,
_info: &DispatchInfoOf<Self::Call>,
_post_info: &PostDispatchInfoOf<Self::Call>,
_len: usize,
_result: &DispatchResult,
) -> Result<(), TransactionValidityError> {
Expand Down Expand Up @@ -797,23 +802,23 @@ impl<AccountId, Call: Dispatchable> SignedExtension for Tuple {
&self,
who: &Self::AccountId,
call: &Self::Call,
info: &<Self::Call as Dispatchable>::Info,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> TransactionValidity {
let valid = ValidTransaction::default();
for_tuples!( #( let valid = valid.combine_with(Tuple.validate(who, call, info, len)?); )* );
Ok(valid)
}

fn pre_dispatch(self, who: &Self::AccountId, call: &Self::Call, info: &<Self::Call as Dispatchable>::Info, len: usize)
fn pre_dispatch(self, who: &Self::AccountId, call: &Self::Call, info: &DispatchInfoOf<Self::Call>, len: usize)
-> Result<Self::Pre, TransactionValidityError>
{
Ok(for_tuples!( ( #( Tuple.pre_dispatch(who, call, info, len)? ),* ) ))
}

fn validate_unsigned(
call: &Self::Call,
info: &<Self::Call as Dispatchable>::Info,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> TransactionValidity {
let valid = ValidTransaction::default();
Expand All @@ -823,16 +828,16 @@ impl<AccountId, Call: Dispatchable> SignedExtension for Tuple {

fn pre_dispatch_unsigned(
call: &Self::Call,
info: &<Self::Call as Dispatchable>::Info,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
Ok(for_tuples!( ( #( Tuple::pre_dispatch_unsigned(call, info, len)? ),* ) ))
}

fn post_dispatch(
pre: Self::Pre,
info: &<Self::Call as Dispatchable>::Info,
post_info: &<Self::Call as Dispatchable>::PostInfo,
info: &DispatchInfoOf<Self::Call>,
post_info: &PostDispatchInfoOf<Self::Call>,
len: usize,
result: &DispatchResult,
) -> Result<(), TransactionValidityError> {
Expand Down Expand Up @@ -872,15 +877,15 @@ pub trait Applyable: Sized + Send + Sync {
fn validate<V: ValidateUnsigned<Call=Self::Call>>(
&self,
source: TransactionSource,
info: &<Self::Call as Dispatchable>::Info,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> TransactionValidity;

/// Executes all necessary logic needed prior to dispatch and deconstructs into function call,
/// index and sender.
fn apply<V: ValidateUnsigned<Call=Self::Call>>(
self,
info: &<Self::Call as Dispatchable>::Info,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> crate::ApplyExtrinsicResult;
}
Expand Down