mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-23 22:31:06 +00:00
add post_dispatch (#3229)
* add post_dispatch * Update traits.rs * Update checked_extrinsic.rs * Update traits.rs * Update traits.rs * fix build issue * update runtime version * fix test build issue
This commit is contained in:
@@ -77,14 +77,16 @@ where
|
|||||||
info: DispatchInfo,
|
info: DispatchInfo,
|
||||||
len: usize,
|
len: usize,
|
||||||
) -> Result<DispatchResult, DispatchError> {
|
) -> Result<DispatchResult, DispatchError> {
|
||||||
let maybe_who = if let Some((id, extra)) = self.signed {
|
let (maybe_who, pre) = if let Some((id, extra)) = self.signed {
|
||||||
Extra::pre_dispatch(extra, &id, &self.function, info, len)?;
|
let pre = Extra::pre_dispatch(extra, &id, &self.function, info, len)?;
|
||||||
Some(id)
|
(Some(id), pre)
|
||||||
} else {
|
} else {
|
||||||
Extra::pre_dispatch_unsigned(&self.function, info, len)?;
|
let pre = Extra::pre_dispatch_unsigned(&self.function, info, len)?;
|
||||||
None
|
(None, pre)
|
||||||
};
|
};
|
||||||
Ok(self.function.dispatch(Origin::from(maybe_who)))
|
let res = self.function.dispatch(Origin::from(maybe_who));
|
||||||
|
Extra::post_dispatch(pre, info, len);
|
||||||
|
Ok(res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -236,6 +236,8 @@ mod tests {
|
|||||||
type AccountId = u64;
|
type AccountId = u64;
|
||||||
type Call = ();
|
type Call = ();
|
||||||
type AdditionalSigned = ();
|
type AdditionalSigned = ();
|
||||||
|
type Pre = ();
|
||||||
|
|
||||||
fn additional_signed(&self) -> rstd::result::Result<(), &'static str> { Ok(()) }
|
fn additional_signed(&self) -> rstd::result::Result<(), &'static str> { Ok(()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -808,6 +808,9 @@ pub trait SignedExtension:
|
|||||||
/// from the transaction using the `additional_signed` function.
|
/// from the transaction using the `additional_signed` function.
|
||||||
type AdditionalSigned: Encode;
|
type AdditionalSigned: Encode;
|
||||||
|
|
||||||
|
/// The type that encodes information that can be passed from pre_dispatch to post-dispatch.
|
||||||
|
type Pre: Default;
|
||||||
|
|
||||||
/// Construct any additional data that should be in the signed payload of the transaction. Can
|
/// Construct any additional data that should be in the signed payload of the transaction. Can
|
||||||
/// also perform any pre-signature-verification checks and return an error if needed.
|
/// also perform any pre-signature-verification checks and return an error if needed.
|
||||||
fn additional_signed(&self) -> Result<Self::AdditionalSigned, &'static str>;
|
fn additional_signed(&self) -> Result<Self::AdditionalSigned, &'static str>;
|
||||||
@@ -830,8 +833,8 @@ pub trait SignedExtension:
|
|||||||
call: &Self::Call,
|
call: &Self::Call,
|
||||||
info: DispatchInfo,
|
info: DispatchInfo,
|
||||||
len: usize,
|
len: usize,
|
||||||
) -> Result<(), DispatchError> {
|
) -> Result<Self::Pre, DispatchError> {
|
||||||
self.validate(who, call, info, len).map(|_| ())
|
self.validate(who, call, info, len).map(|_| Self::Pre::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Validate an unsigned transaction for the transaction queue. Normally the default
|
/// Validate an unsigned transaction for the transaction queue. Normally the default
|
||||||
@@ -848,9 +851,16 @@ pub trait SignedExtension:
|
|||||||
call: &Self::Call,
|
call: &Self::Call,
|
||||||
info: DispatchInfo,
|
info: DispatchInfo,
|
||||||
len: usize,
|
len: usize,
|
||||||
) -> Result<(), DispatchError> {
|
) -> Result<Self::Pre, DispatchError> {
|
||||||
Self::validate_unsigned(call, info, len).map(|_| ())
|
Self::validate_unsigned(call, info, len).map(|_| Self::Pre::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Do any post-flight stuff for a transaction.
|
||||||
|
fn post_dispatch(
|
||||||
|
_pre: Self::Pre,
|
||||||
|
_info: DispatchInfo,
|
||||||
|
_len: usize,
|
||||||
|
) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! tuple_impl_indexed {
|
macro_rules! tuple_impl_indexed {
|
||||||
@@ -866,6 +876,7 @@ macro_rules! tuple_impl_indexed {
|
|||||||
type AccountId = AccountId;
|
type AccountId = AccountId;
|
||||||
type Call = Call;
|
type Call = Call;
|
||||||
type AdditionalSigned = ($($direct::AdditionalSigned,)+);
|
type AdditionalSigned = ($($direct::AdditionalSigned,)+);
|
||||||
|
type Pre = ($($direct::Pre,)+);
|
||||||
fn additional_signed(&self) -> Result<Self::AdditionalSigned, &'static str> {
|
fn additional_signed(&self) -> Result<Self::AdditionalSigned, &'static str> {
|
||||||
Ok(( $(self.$index.additional_signed()?,)+ ))
|
Ok(( $(self.$index.additional_signed()?,)+ ))
|
||||||
}
|
}
|
||||||
@@ -885,9 +896,8 @@ macro_rules! tuple_impl_indexed {
|
|||||||
call: &Self::Call,
|
call: &Self::Call,
|
||||||
info: DispatchInfo,
|
info: DispatchInfo,
|
||||||
len: usize,
|
len: usize,
|
||||||
) -> Result<(), DispatchError> {
|
) -> Result<Self::Pre, DispatchError> {
|
||||||
$(self.$index.pre_dispatch(who, call, info, len)?;)+
|
Ok(($(self.$index.pre_dispatch(who, call, info, len)?,)+))
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
fn validate_unsigned(
|
fn validate_unsigned(
|
||||||
call: &Self::Call,
|
call: &Self::Call,
|
||||||
@@ -901,9 +911,15 @@ macro_rules! tuple_impl_indexed {
|
|||||||
call: &Self::Call,
|
call: &Self::Call,
|
||||||
info: DispatchInfo,
|
info: DispatchInfo,
|
||||||
len: usize,
|
len: usize,
|
||||||
) -> Result<(), DispatchError> {
|
) -> Result<Self::Pre, DispatchError> {
|
||||||
$($direct::pre_dispatch_unsigned(call, info, len)?;)+
|
Ok(($($direct::pre_dispatch_unsigned(call, info, len)?,)+))
|
||||||
Ok(())
|
}
|
||||||
|
fn post_dispatch(
|
||||||
|
pre: Self::Pre,
|
||||||
|
info: DispatchInfo,
|
||||||
|
len: usize,
|
||||||
|
) {
|
||||||
|
$($direct::post_dispatch(pre.$index, info, len);)+
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -931,6 +947,7 @@ impl SignedExtension for () {
|
|||||||
type AccountId = u64;
|
type AccountId = u64;
|
||||||
type AdditionalSigned = ();
|
type AdditionalSigned = ();
|
||||||
type Call = ();
|
type Call = ();
|
||||||
|
type Pre = ();
|
||||||
fn additional_signed(&self) -> rstd::result::Result<(), &'static str> { Ok(()) }
|
fn additional_signed(&self) -> rstd::result::Result<(), &'static str> { Ok(()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,8 +80,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
|||||||
// and set impl_version to equal spec_version. If only runtime
|
// and set impl_version to equal spec_version. If only runtime
|
||||||
// implementation changes and behavior does not, then leave spec_version as
|
// implementation changes and behavior does not, then leave spec_version as
|
||||||
// is and increment impl_version.
|
// is and increment impl_version.
|
||||||
spec_version: 134,
|
spec_version: 135,
|
||||||
impl_version: 134,
|
impl_version: 135,
|
||||||
apis: RUNTIME_API_VERSIONS,
|
apis: RUNTIME_API_VERSIONS,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1216,6 +1216,7 @@ impl<T: Trait<I>, I: Instance + Clone + Eq> SignedExtension for TakeFees<T, I> {
|
|||||||
type AccountId = T::AccountId;
|
type AccountId = T::AccountId;
|
||||||
type Call = T::Call;
|
type Call = T::Call;
|
||||||
type AdditionalSigned = ();
|
type AdditionalSigned = ();
|
||||||
|
type Pre = ();
|
||||||
fn additional_signed(&self) -> rstd::result::Result<(), &'static str> { Ok(()) }
|
fn additional_signed(&self) -> rstd::result::Result<(), &'static str> { Ok(()) }
|
||||||
|
|
||||||
fn validate(
|
fn validate(
|
||||||
|
|||||||
@@ -881,6 +881,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckWeight<T> {
|
|||||||
type AccountId = T::AccountId;
|
type AccountId = T::AccountId;
|
||||||
type Call = T::Call;
|
type Call = T::Call;
|
||||||
type AdditionalSigned = ();
|
type AdditionalSigned = ();
|
||||||
|
type Pre = ();
|
||||||
|
|
||||||
fn additional_signed(&self) -> rstd::result::Result<(), &'static str> { Ok(()) }
|
fn additional_signed(&self) -> rstd::result::Result<(), &'static str> { Ok(()) }
|
||||||
|
|
||||||
@@ -944,6 +945,7 @@ impl<T: Trait> SignedExtension for CheckNonce<T> {
|
|||||||
type AccountId = T::AccountId;
|
type AccountId = T::AccountId;
|
||||||
type Call = T::Call;
|
type Call = T::Call;
|
||||||
type AdditionalSigned = ();
|
type AdditionalSigned = ();
|
||||||
|
type Pre = ();
|
||||||
|
|
||||||
fn additional_signed(&self) -> rstd::result::Result<(), &'static str> { Ok(()) }
|
fn additional_signed(&self) -> rstd::result::Result<(), &'static str> { Ok(()) }
|
||||||
|
|
||||||
@@ -1017,6 +1019,8 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckEra<T> {
|
|||||||
type AccountId = T::AccountId;
|
type AccountId = T::AccountId;
|
||||||
type Call = T::Call;
|
type Call = T::Call;
|
||||||
type AdditionalSigned = T::Hash;
|
type AdditionalSigned = T::Hash;
|
||||||
|
type Pre = ();
|
||||||
|
|
||||||
fn additional_signed(&self) -> Result<Self::AdditionalSigned, &'static str> {
|
fn additional_signed(&self) -> Result<Self::AdditionalSigned, &'static str> {
|
||||||
let current_u64 = <Module<T>>::block_number().saturated_into::<u64>();
|
let current_u64 = <Module<T>>::block_number().saturated_into::<u64>();
|
||||||
let n = (self.0).0.birth(current_u64).saturated_into::<T::BlockNumber>();
|
let n = (self.0).0.birth(current_u64).saturated_into::<T::BlockNumber>();
|
||||||
@@ -1047,6 +1051,8 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckGenesis<T> {
|
|||||||
type AccountId = T::AccountId;
|
type AccountId = T::AccountId;
|
||||||
type Call = <T as Trait>::Call;
|
type Call = <T as Trait>::Call;
|
||||||
type AdditionalSigned = T::Hash;
|
type AdditionalSigned = T::Hash;
|
||||||
|
type Pre = ();
|
||||||
|
|
||||||
fn additional_signed(&self) -> Result<Self::AdditionalSigned, &'static str> {
|
fn additional_signed(&self) -> Result<Self::AdditionalSigned, &'static str> {
|
||||||
Ok(<Module<T>>::block_hash(T::BlockNumber::zero()))
|
Ok(<Module<T>>::block_hash(T::BlockNumber::zero()))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user