Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 211334a

Browse files
committed
Introduce DispatchInfoOf type alias
1 parent 839b223 commit 211334a

File tree

8 files changed

+57
-45
lines changed

8 files changed

+57
-45
lines changed

frame/contracts/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ use sp_std::{prelude::*, marker::PhantomData, fmt::Debug};
113113
use codec::{Codec, Encode, Decode};
114114
use sp_io::hashing::blake2_256;
115115
use sp_runtime::{
116-
traits::{Hash, StaticLookup, Zero, MaybeSerializeDeserialize, Member, SignedExtension},
116+
traits::{
117+
Hash, StaticLookup, Zero, MaybeSerializeDeserialize, Member, SignedExtension,
118+
DispatchInfoOf,
119+
},
117120
transaction_validity::{
118121
ValidTransaction, InvalidTransaction, TransactionValidity, TransactionValidityError,
119122
},
@@ -1098,7 +1101,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckBlockGasLimit<T> {
10981101
&self,
10991102
_: &Self::AccountId,
11001103
call: &Self::Call,
1101-
_: &<Self::Call as Dispatchable>::Info,
1104+
_: &DispatchInfoOf<Self::Call>,
11021105
_: usize,
11031106
) -> TransactionValidity {
11041107
let call = match call.is_sub_type() {

frame/example/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,9 @@ use sp_std::prelude::*;
264264
use frame_system::{self as system, ensure_signed, ensure_root};
265265
use codec::{Encode, Decode};
266266
use sp_runtime::{
267-
traits::{SignedExtension, Bounded, SaturatedConversion, Dispatchable},
267+
traits::{
268+
SignedExtension, Bounded, SaturatedConversion, DispatchInfoOf,
269+
},
268270
transaction_validity::{
269271
ValidTransaction, TransactionValidityError, InvalidTransaction, TransactionValidity,
270272
},
@@ -626,7 +628,7 @@ impl<T: Trait + Send + Sync> SignedExtension for WatchDummy<T> {
626628
&self,
627629
_who: &Self::AccountId,
628630
call: &Self::Call,
629-
_info: &<Self::Call as Dispatchable>::Info,
631+
_info: &DispatchInfoOf<Self::Call>,
630632
len: usize,
631633
) -> TransactionValidity {
632634
// if the transaction is too big, just drop it.

frame/staking/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ use sp_runtime::{
288288
curve::PiecewiseLinear,
289289
traits::{
290290
Convert, Zero, StaticLookup, CheckedSub, Saturating, SaturatedConversion, AtLeast32Bit,
291-
SignedExtension, Dispatchable
291+
SignedExtension, Dispatchable, DispatchInfoOf,
292292
},
293293
transaction_validity::{
294294
TransactionValidityError, TransactionValidity, ValidTransaction, InvalidTransaction,
@@ -3133,7 +3133,7 @@ impl<T: Trait + Send + Sync> SignedExtension for LockStakingStatus<T> {
31333133
&self,
31343134
_who: &Self::AccountId,
31353135
call: &Self::Call,
3136-
_info: &<Self::Call as Dispatchable>::Info,
3136+
_info: &DispatchInfoOf<Self::Call>,
31373137
_len: usize,
31383138
) -> TransactionValidity {
31393139
if let Some(inner_call) = call.is_sub_type() {

frame/system/src/lib.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ use sp_runtime::{
109109
self, CheckEqual, AtLeast32Bit, Zero, SignedExtension, Lookup, LookupError,
110110
SimpleBitOps, Hash, Member, MaybeDisplay, BadOrigin, SaturatedConversion,
111111
MaybeSerialize, MaybeSerializeDeserialize, MaybeMallocSizeOf, StaticLookup, One, Bounded,
112-
Dispatchable,
112+
Dispatchable, DispatchInfoOf, PostDispatchInfoOf,
113113
},
114114
};
115115

@@ -1183,7 +1183,7 @@ impl<T: Trait + Send + Sync> CheckWeight<T> where
11831183
///
11841184
/// Upon successes, it returns the new block weight as a `Result`.
11851185
fn check_weight(
1186-
info: &<T::Call as Dispatchable>::Info,
1186+
info: &DispatchInfoOf<T::Call>,
11871187
) -> Result<Weight, TransactionValidityError> {
11881188
let current_weight = Module::<T>::all_extrinsics_weight();
11891189
let maximum_weight = T::MaximumBlockWeight::get();
@@ -1201,7 +1201,7 @@ impl<T: Trait + Send + Sync> CheckWeight<T> where
12011201
///
12021202
/// Upon successes, it returns the new block length as a `Result`.
12031203
fn check_block_length(
1204-
info: &<T::Call as Dispatchable>::Info,
1204+
info: &DispatchInfoOf<T::Call>,
12051205
len: usize,
12061206
) -> Result<u32, TransactionValidityError> {
12071207
let current_len = Module::<T>::all_extrinsics_len();
@@ -1217,7 +1217,7 @@ impl<T: Trait + Send + Sync> CheckWeight<T> where
12171217
}
12181218

12191219
/// get the priority of an extrinsic denoted by `info`.
1220-
fn get_priority(info: &<T::Call as Dispatchable>::Info) -> TransactionPriority {
1220+
fn get_priority(info: &DispatchInfoOf<T::Call>) -> TransactionPriority {
12211221
match info.class {
12221222
DispatchClass::Normal => info.weight.into(),
12231223
DispatchClass::Operational => Bounded::max_value(),
@@ -1235,7 +1235,7 @@ impl<T: Trait + Send + Sync> CheckWeight<T> where
12351235
///
12361236
/// It checks and notes the new weight and length.
12371237
fn do_pre_dispatch(
1238-
info: &<T::Call as Dispatchable>::Info,
1238+
info: &DispatchInfoOf<T::Call>,
12391239
len: usize,
12401240
) -> Result<(), TransactionValidityError> {
12411241
let next_len = Self::check_block_length(info, len)?;
@@ -1249,7 +1249,7 @@ impl<T: Trait + Send + Sync> CheckWeight<T> where
12491249
///
12501250
/// It only checks that the block weight and length limit will not exceed.
12511251
fn do_validate(
1252-
info: &<T::Call as Dispatchable>::Info,
1252+
info: &DispatchInfoOf<T::Call>,
12531253
len: usize,
12541254
) -> TransactionValidity {
12551255
// ignore the next weight and length. If they return `Ok`, then it is below the limit.
@@ -1275,7 +1275,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckWeight<T> where
12751275
self,
12761276
_who: &Self::AccountId,
12771277
_call: &Self::Call,
1278-
info: &<Self::Call as Dispatchable>::Info,
1278+
info: &DispatchInfoOf<Self::Call>,
12791279
len: usize,
12801280
) -> Result<(), TransactionValidityError> {
12811281
if info.class == DispatchClass::Mandatory {
@@ -1288,7 +1288,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckWeight<T> where
12881288
&self,
12891289
_who: &Self::AccountId,
12901290
_call: &Self::Call,
1291-
info: &<Self::Call as Dispatchable>::Info,
1291+
info: &DispatchInfoOf<Self::Call>,
12921292
len: usize,
12931293
) -> TransactionValidity {
12941294
if info.class == DispatchClass::Mandatory {
@@ -1299,24 +1299,24 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckWeight<T> where
12991299

13001300
fn pre_dispatch_unsigned(
13011301
_call: &Self::Call,
1302-
info: &<Self::Call as Dispatchable>::Info,
1302+
info: &DispatchInfoOf<Self::Call>,
13031303
len: usize,
13041304
) -> Result<(), TransactionValidityError> {
13051305
Self::do_pre_dispatch(info, len)
13061306
}
13071307

13081308
fn validate_unsigned(
13091309
_call: &Self::Call,
1310-
info: &<Self::Call as Dispatchable>::Info,
1310+
info: &DispatchInfoOf<Self::Call>,
13111311
len: usize,
13121312
) -> TransactionValidity {
13131313
Self::do_validate(info, len)
13141314
}
13151315

13161316
fn post_dispatch(
13171317
_pre: Self::Pre,
1318-
info: &<Self::Call as Dispatchable>::Info,
1319-
_post_info: &<Self::Call as Dispatchable>::PostInfo,
1318+
info: &DispatchInfoOf<Self::Call>,
1319+
_post_info: &PostDispatchInfoOf<Self::Call>,
13201320
_len: usize,
13211321
result: &DispatchResult,
13221322
) -> Result<(), TransactionValidityError> {
@@ -1380,7 +1380,7 @@ impl<T: Trait> SignedExtension for CheckNonce<T> where
13801380
self,
13811381
who: &Self::AccountId,
13821382
_call: &Self::Call,
1383-
_info: &<Self::Call as Dispatchable>::Info,
1383+
_info: &DispatchInfoOf<Self::Call>,
13841384
_len: usize,
13851385
) -> Result<(), TransactionValidityError> {
13861386
let mut account = Account::<T>::get(who);
@@ -1402,7 +1402,7 @@ impl<T: Trait> SignedExtension for CheckNonce<T> where
14021402
&self,
14031403
who: &Self::AccountId,
14041404
_call: &Self::Call,
1405-
info: &<Self::Call as Dispatchable>::Info,
1405+
info: &DispatchInfoOf<Self::Call>,
14061406
_len: usize,
14071407
) -> TransactionValidity {
14081408
// check index
@@ -1468,7 +1468,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckEra<T> {
14681468
&self,
14691469
_who: &Self::AccountId,
14701470
_call: &Self::Call,
1471-
_info: &<Self::Call as Dispatchable>::Info,
1471+
_info: &DispatchInfoOf<Self::Call>,
14721472
_len: usize,
14731473
) -> TransactionValidity {
14741474
let current_u64 = <Module<T>>::block_number().saturated_into::<u64>();

frame/transaction-payment/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ use sp_runtime::{
4444
TransactionPriority, ValidTransaction, InvalidTransaction, TransactionValidityError,
4545
TransactionValidity,
4646
},
47-
traits::{Zero, Saturating, SignedExtension, SaturatedConversion, Convert, Dispatchable},
47+
traits::{
48+
Zero, Saturating, SignedExtension, SaturatedConversion, Convert, Dispatchable,
49+
DispatchInfoOf,
50+
},
4851
};
4952
use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
5053

@@ -160,7 +163,7 @@ impl<T: Trait + Send + Sync> ChargeTransactionPayment<T> where
160163
/// final_fee = base_fee + targeted_fee_adjustment(len_fee + weight_fee) + tip;
161164
pub fn compute_fee(
162165
len: u32,
163-
info: &<T::Call as Dispatchable>::Info,
166+
info: &DispatchInfoOf<T::Call>,
164167
tip: BalanceOf<T>,
165168
) -> BalanceOf<T>
166169
where
@@ -219,7 +222,7 @@ impl<T: Trait + Send + Sync> SignedExtension for ChargeTransactionPayment<T> whe
219222
&self,
220223
who: &Self::AccountId,
221224
_call: &Self::Call,
222-
info: &<Self::Call as Dispatchable>::Info,
225+
info: &DispatchInfoOf<Self::Call>,
223226
len: usize,
224227
) -> TransactionValidity {
225228
// pay any fees.

primitives/runtime/src/generic/checked_extrinsic.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
//! stage.
1919
2020
use crate::traits::{
21-
self, Member, MaybeDisplay, SignedExtension, Dispatchable,
21+
self, Member, MaybeDisplay, SignedExtension, Dispatchable, DispatchInfoOf, ValidateUnsigned,
2222
};
23-
use crate::traits::ValidateUnsigned;
2423
use crate::transaction_validity::{TransactionValidity, TransactionSource};
2524

2625
/// Definition of something that the external world might want to say; its
@@ -51,7 +50,7 @@ where
5150
// TODO [#5006;ToDr] should source be passed to `SignedExtension`s?
5251
// Perhaps a change for 2.0 to avoid breaking too much APIs?
5352
source: TransactionSource,
54-
info: &<Self::Call as Dispatchable>::Info,
53+
info: &DispatchInfoOf<Self::Call>,
5554
len: usize,
5655
) -> TransactionValidity {
5756
if let Some((ref id, ref extra)) = self.signed {
@@ -65,7 +64,7 @@ where
6564

6665
fn apply<U: ValidateUnsigned<Call=Self::Call>>(
6766
self,
68-
info: &<Self::Call as Dispatchable>::Info,
67+
info: &DispatchInfoOf<Self::Call>,
6968
len: usize,
7069
) -> crate::ApplyExtrinsicResult {
7170
let (maybe_who, pre) = if let Some((id, extra)) = self.signed {

primitives/runtime/src/testing.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::{fmt::Debug, ops::Deref, fmt, cell::RefCell};
2121
use crate::codec::{Codec, Encode, Decode};
2222
use crate::traits::{
2323
self, Checkable, Applyable, BlakeTwo256, OpaqueKeys,
24-
SignedExtension, Dispatchable,
24+
SignedExtension, Dispatchable, DispatchInfoOf,
2525
};
2626
use crate::traits::ValidateUnsigned;
2727
use crate::{generic, KeyTypeId, ApplyExtrinsicResult};
@@ -356,7 +356,7 @@ impl<Origin, Call, Extra> Applyable for TestXt<Call, Extra> where
356356
fn validate<U: ValidateUnsigned<Call=Self::Call>>(
357357
&self,
358358
_source: TransactionSource,
359-
_info: &<Self::Call as Dispatchable>::Info,
359+
_info: &DispatchInfoOf<Self::Call>,
360360
_len: usize,
361361
) -> TransactionValidity {
362362
Ok(Default::default())
@@ -366,7 +366,7 @@ impl<Origin, Call, Extra> Applyable for TestXt<Call, Extra> where
366366
/// index and sender.
367367
fn apply<U: ValidateUnsigned<Call=Self::Call>>(
368368
self,
369-
info: &<Self::Call as Dispatchable>::Info,
369+
info: &DispatchInfoOf<Self::Call>,
370370
len: usize,
371371
) -> ApplyExtrinsicResult {
372372
let maybe_who = if let Some((who, extra)) = self.signature {

primitives/runtime/src/traits.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,11 @@ pub trait Dispatchable {
636636
fn dispatch(self, origin: Self::Origin) -> crate::DispatchResultWithInfo<Self::PostInfo>;
637637
}
638638

639+
/// Shortcut to reference the `Info` type of a `Dispatchable`.
640+
pub type DispatchInfoOf<T> = <T as Dispatchable>::Info;
641+
/// Shortcut to reference the `PostInfo` type of a `Dispatchable`.
642+
pub type PostDispatchInfoOf<T> = <T as Dispatchable>::PostInfo;
643+
639644
impl Dispatchable for () {
640645
type Origin = ();
641646
type Trait = ();
@@ -685,7 +690,7 @@ pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq
685690
&self,
686691
_who: &Self::AccountId,
687692
_call: &Self::Call,
688-
_info: &<Self::Call as Dispatchable>::Info,
693+
_info: &DispatchInfoOf<Self::Call>,
689694
_len: usize,
690695
) -> TransactionValidity {
691696
Ok(ValidTransaction::default())
@@ -703,7 +708,7 @@ pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq
703708
self,
704709
who: &Self::AccountId,
705710
call: &Self::Call,
706-
info: &<Self::Call as Dispatchable>::Info,
711+
info: &DispatchInfoOf<Self::Call>,
707712
len: usize,
708713
) -> Result<Self::Pre, TransactionValidityError> {
709714
self.validate(who, call, info.clone(), len)
@@ -721,7 +726,7 @@ pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq
721726
/// Make sure to perform the same checks in `pre_dispatch_unsigned` function.
722727
fn validate_unsigned(
723728
_call: &Self::Call,
724-
_info: &<Self::Call as Dispatchable>::Info,
729+
_info: &DispatchInfoOf<Self::Call>,
725730
_len: usize,
726731
) -> TransactionValidity {
727732
Ok(ValidTransaction::default())
@@ -737,7 +742,7 @@ pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq
737742
/// perform the same validation as in `validate_unsigned`.
738743
fn pre_dispatch_unsigned(
739744
call: &Self::Call,
740-
info: &<Self::Call as Dispatchable>::Info,
745+
info: &DispatchInfoOf<Self::Call>,
741746
len: usize,
742747
) -> Result<Self::Pre, TransactionValidityError> {
743748
Self::validate_unsigned(call, info.clone(), len)
@@ -760,8 +765,8 @@ pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq
760765
/// will come from either an offchain-worker or via `InherentData`.
761766
fn post_dispatch(
762767
_pre: Self::Pre,
763-
_info: &<Self::Call as Dispatchable>::Info,
764-
_post_info: &<Self::Call as Dispatchable>::PostInfo,
768+
_info: &DispatchInfoOf<Self::Call>,
769+
_post_info: &PostDispatchInfoOf<Self::Call>,
765770
_len: usize,
766771
_result: &DispatchResult,
767772
) -> Result<(), TransactionValidityError> {
@@ -797,23 +802,23 @@ impl<AccountId, Call: Dispatchable> SignedExtension for Tuple {
797802
&self,
798803
who: &Self::AccountId,
799804
call: &Self::Call,
800-
info: &<Self::Call as Dispatchable>::Info,
805+
info: &DispatchInfoOf<Self::Call>,
801806
len: usize,
802807
) -> TransactionValidity {
803808
let valid = ValidTransaction::default();
804809
for_tuples!( #( let valid = valid.combine_with(Tuple.validate(who, call, info, len)?); )* );
805810
Ok(valid)
806811
}
807812

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

814819
fn validate_unsigned(
815820
call: &Self::Call,
816-
info: &<Self::Call as Dispatchable>::Info,
821+
info: &DispatchInfoOf<Self::Call>,
817822
len: usize,
818823
) -> TransactionValidity {
819824
let valid = ValidTransaction::default();
@@ -823,16 +828,16 @@ impl<AccountId, Call: Dispatchable> SignedExtension for Tuple {
823828

824829
fn pre_dispatch_unsigned(
825830
call: &Self::Call,
826-
info: &<Self::Call as Dispatchable>::Info,
831+
info: &DispatchInfoOf<Self::Call>,
827832
len: usize,
828833
) -> Result<Self::Pre, TransactionValidityError> {
829834
Ok(for_tuples!( ( #( Tuple::pre_dispatch_unsigned(call, info, len)? ),* ) ))
830835
}
831836

832837
fn post_dispatch(
833838
pre: Self::Pre,
834-
info: &<Self::Call as Dispatchable>::Info,
835-
post_info: &<Self::Call as Dispatchable>::PostInfo,
839+
info: &DispatchInfoOf<Self::Call>,
840+
post_info: &PostDispatchInfoOf<Self::Call>,
836841
len: usize,
837842
result: &DispatchResult,
838843
) -> Result<(), TransactionValidityError> {
@@ -872,15 +877,15 @@ pub trait Applyable: Sized + Send + Sync {
872877
fn validate<V: ValidateUnsigned<Call=Self::Call>>(
873878
&self,
874879
source: TransactionSource,
875-
info: &<Self::Call as Dispatchable>::Info,
880+
info: &DispatchInfoOf<Self::Call>,
876881
len: usize,
877882
) -> TransactionValidity;
878883

879884
/// Executes all necessary logic needed prior to dispatch and deconstructs into function call,
880885
/// index and sender.
881886
fn apply<V: ValidateUnsigned<Call=Self::Call>>(
882887
self,
883-
info: &<Self::Call as Dispatchable>::Info,
888+
info: &DispatchInfoOf<Self::Call>,
884889
len: usize,
885890
) -> crate::ApplyExtrinsicResult;
886891
}

0 commit comments

Comments
 (0)