Skip to content

Commit

Permalink
Implement pre_dispatch for SignedExtensions (paritytech#370)
Browse files Browse the repository at this point in the history
* Explicitly specify master branch for sp-keyring dev dependency

* Implement pre_dispatch for `SignedExtension`s

* Update macro/Cargo.toml

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
  • Loading branch information
2 people authored and 0623forbidden committed Feb 15, 2022
1 parent 9ee5e23 commit b5fdee5
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
2 changes: 1 addition & 1 deletion macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ pretty_assertions = "0.6.1"
subxt = { path = ".." }
trybuild = "1.0.38"

sp-keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate/" }
sp-keyring = { git = "https://github.com/paritytech/substrate/", branch = "master" }
77 changes: 76 additions & 1 deletion src/extrinsic/extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ use core::{
use scale_info::TypeInfo;
use sp_runtime::{
generic::Era,
traits::SignedExtension,
traits::{
DispatchInfoOf,
SignedExtension,
},
transaction_validity::TransactionValidityError,
};

Expand Down Expand Up @@ -68,6 +71,15 @@ where
) -> Result<Self::AdditionalSigned, TransactionValidityError> {
Ok(self.1)
}
fn pre_dispatch(
self,
_who: &Self::AccountId,
_call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
Ok(())
}
}

/// Ensure the transaction version registered in the transaction is the same as at present.
Expand Down Expand Up @@ -99,6 +111,15 @@ where
) -> Result<Self::AdditionalSigned, TransactionValidityError> {
Ok(self.1)
}
fn pre_dispatch(
self,
_who: &Self::AccountId,
_call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
Ok(())
}
}

/// Check genesis hash
Expand Down Expand Up @@ -130,6 +151,15 @@ where
) -> Result<Self::AdditionalSigned, TransactionValidityError> {
Ok(self.1)
}
fn pre_dispatch(
self,
_who: &Self::AccountId,
_call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
Ok(())
}
}

/// Check for transaction mortality.
Expand Down Expand Up @@ -163,6 +193,15 @@ where
) -> Result<Self::AdditionalSigned, TransactionValidityError> {
Ok(self.1)
}
fn pre_dispatch(
self,
_who: &Self::AccountId,
_call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
Ok(())
}
}

/// Nonce check and increment to give replay protection for transactions.
Expand All @@ -184,6 +223,15 @@ where
) -> Result<Self::AdditionalSigned, TransactionValidityError> {
Ok(())
}
fn pre_dispatch(
self,
_who: &Self::AccountId,
_call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
Ok(())
}
}

/// Resource limit check.
Expand All @@ -205,6 +253,15 @@ where
) -> Result<Self::AdditionalSigned, TransactionValidityError> {
Ok(())
}
fn pre_dispatch(
self,
_who: &Self::AccountId,
_call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
Ok(())
}
}

/// Require the transactor pay for themselves and maybe include a tip to gain additional priority
Expand All @@ -230,6 +287,15 @@ impl SignedExtension for ChargeAssetTxPayment {
) -> Result<Self::AdditionalSigned, TransactionValidityError> {
Ok(())
}
fn pre_dispatch(
self,
_who: &Self::AccountId,
_call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
Ok(())
}
}

/// Trait for implementing transaction extras for a runtime.
Expand Down Expand Up @@ -318,4 +384,13 @@ impl<T: Config + Clone + Debug + Eq + Send + Sync> SignedExtension for DefaultEx
) -> Result<Self::AdditionalSigned, TransactionValidityError> {
self.extra().additional_signed()
}
fn pre_dispatch(
self,
_who: &Self::AccountId,
_call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
Ok(())
}
}

0 comments on commit b5fdee5

Please sign in to comment.