Trait sp_runtime::traits::SignedExtension
source · pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq + StaticTypeInfo {
type AccountId;
type Call: Dispatchable;
type AdditionalSigned: Encode + TypeInfo;
type Pre;
const IDENTIFIER: &'static str;
// Required methods
fn additional_signed(
&self
) -> Result<Self::AdditionalSigned, TransactionValidityError>;
fn pre_dispatch(
self,
who: &Self::AccountId,
call: &Self::Call,
info: &DispatchInfoOf<Self::Call>,
len: usize
) -> Result<Self::Pre, TransactionValidityError>;
// Provided methods
fn validate(
&self,
_who: &Self::AccountId,
_call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize
) -> TransactionValidity { ... }
fn validate_unsigned(
_call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize
) -> TransactionValidity { ... }
fn pre_dispatch_unsigned(
call: &Self::Call,
info: &DispatchInfoOf<Self::Call>,
len: usize
) -> Result<(), TransactionValidityError> { ... }
fn post_dispatch(
_pre: Option<Self::Pre>,
_info: &DispatchInfoOf<Self::Call>,
_post_info: &PostDispatchInfoOf<Self::Call>,
_len: usize,
_result: &DispatchResult
) -> Result<(), TransactionValidityError> { ... }
fn metadata() -> Vec<SignedExtensionMetadata> { ... }
}
Expand description
Means by which a transaction may be extended. This type embodies both the data and the logic that should be additionally associated with the transaction. It should be plain old data.
Required Associated Types§
sourcetype Call: Dispatchable
type Call: Dispatchable
The type which encodes the call to be dispatched.
sourcetype AdditionalSigned: Encode + TypeInfo
type AdditionalSigned: Encode + TypeInfo
Any additional data that will go into the signed payload. This may be created dynamically
from the transaction using the additional_signed
function.
Required Associated Constants§
sourceconst IDENTIFIER: &'static str
const IDENTIFIER: &'static str
Unique identifier of this signed extension.
This will be exposed in the metadata to identify the signed extension used in an extrinsic.
Required Methods§
sourcefn additional_signed(
&self
) -> Result<Self::AdditionalSigned, TransactionValidityError>
fn additional_signed( &self ) -> Result<Self::AdditionalSigned, TransactionValidityError>
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.
sourcefn pre_dispatch(
self,
who: &Self::AccountId,
call: &Self::Call,
info: &DispatchInfoOf<Self::Call>,
len: usize
) -> Result<Self::Pre, TransactionValidityError>
fn pre_dispatch( self, who: &Self::AccountId, call: &Self::Call, info: &DispatchInfoOf<Self::Call>, len: usize ) -> Result<Self::Pre, TransactionValidityError>
Do any pre-flight stuff for a signed transaction.
Make sure to perform the same checks as in Self::validate
.
Provided Methods§
sourcefn validate(
&self,
_who: &Self::AccountId,
_call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize
) -> TransactionValidity
fn validate( &self, _who: &Self::AccountId, _call: &Self::Call, _info: &DispatchInfoOf<Self::Call>, _len: usize ) -> TransactionValidity
Validate a signed transaction for the transaction queue.
This function can be called frequently by the transaction queue, to obtain transaction validity against current state. It should perform all checks that determine a valid transaction, that can pay for its execution and quickly eliminate ones that are stale or incorrect.
Make sure to perform the same checks in pre_dispatch
function.
sourcefn validate_unsigned(
_call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize
) -> TransactionValidity
fn validate_unsigned( _call: &Self::Call, _info: &DispatchInfoOf<Self::Call>, _len: usize ) -> TransactionValidity
Validate an unsigned transaction for the transaction queue.
This function can be called frequently by the transaction queue to obtain transaction validity against current state. It should perform all checks that determine a valid unsigned transaction, and quickly eliminate ones that are stale or incorrect.
Make sure to perform the same checks in pre_dispatch_unsigned
function.
sourcefn pre_dispatch_unsigned(
call: &Self::Call,
info: &DispatchInfoOf<Self::Call>,
len: usize
) -> Result<(), TransactionValidityError>
fn pre_dispatch_unsigned( call: &Self::Call, info: &DispatchInfoOf<Self::Call>, len: usize ) -> Result<(), TransactionValidityError>
Do any pre-flight stuff for a unsigned transaction.
Note this function by default delegates to validate_unsigned
, so that
all checks performed for the transaction queue are also performed during
the dispatch phase (applying the extrinsic).
If you ever override this function, you need to make sure to always
perform the same validation as in validate_unsigned
.
sourcefn post_dispatch(
_pre: Option<Self::Pre>,
_info: &DispatchInfoOf<Self::Call>,
_post_info: &PostDispatchInfoOf<Self::Call>,
_len: usize,
_result: &DispatchResult
) -> Result<(), TransactionValidityError>
fn post_dispatch( _pre: Option<Self::Pre>, _info: &DispatchInfoOf<Self::Call>, _post_info: &PostDispatchInfoOf<Self::Call>, _len: usize, _result: &DispatchResult ) -> Result<(), TransactionValidityError>
Do any post-flight stuff for an extrinsic.
If the transaction is signed, then _pre
will contain the output of pre_dispatch
,
and None
otherwise.
This gets given the DispatchResult
_result
from the extrinsic and can, if desired,
introduce a TransactionValidityError
, causing the block to become invalid for including
it.
WARNING: It is dangerous to return an error here. To do so will fundamentally invalidate the transaction and any block that it is included in, causing the block author to not be compensated for their work in validating the transaction or producing the block so far.
It can only be used safely when you know that the extrinsic is one that can only be
introduced by the current block author; generally this implies that it is an inherent and
will come from either an offchain-worker or via InherentData
.
sourcefn metadata() -> Vec<SignedExtensionMetadata>
fn metadata() -> Vec<SignedExtensionMetadata>
Returns the metadata for this signed extension.
As a SignedExtension
can be a tuple of SignedExtension
s we need to return a Vec
that holds the metadata of each one. Each individual SignedExtension
must return
exactly one SignedExtensionMetadata
.
This method provides a default implementation that returns a vec containing a single
SignedExtensionMetadata
.
Implementations on Foreign Types§
source§impl<AccountId, Call: Dispatchable, TupleElement0, TupleElement1, TupleElement2> SignedExtension for (TupleElement0, TupleElement1, TupleElement2)where
TupleElement0: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
TupleElement1: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
TupleElement2: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
impl<AccountId, Call: Dispatchable, TupleElement0, TupleElement1, TupleElement2> SignedExtension for (TupleElement0, TupleElement1, TupleElement2)where TupleElement0: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension, TupleElement1: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension, TupleElement2: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
type AccountId = AccountId
type Call = Call
const IDENTIFIER: &'static str = "You should call `identifier()`!"
type AdditionalSigned = (<TupleElement0 as SignedExtension>::AdditionalSigned, <TupleElement1 as SignedExtension>::AdditionalSigned, <TupleElement2 as SignedExtension>::AdditionalSigned)
type Pre = (<TupleElement0 as SignedExtension>::Pre, <TupleElement1 as SignedExtension>::Pre, <TupleElement2 as SignedExtension>::Pre)
fn additional_signed( &self ) -> Result<Self::AdditionalSigned, TransactionValidityError>
fn validate( &self, who: &Self::AccountId, call: &Self::Call, info: &DispatchInfoOf<Self::Call>, len: usize ) -> TransactionValidity
fn pre_dispatch( self, who: &Self::AccountId, call: &Self::Call, info: &DispatchInfoOf<Self::Call>, len: usize ) -> Result<Self::Pre, TransactionValidityError>
fn validate_unsigned( call: &Self::Call, info: &DispatchInfoOf<Self::Call>, len: usize ) -> TransactionValidity
fn pre_dispatch_unsigned( call: &Self::Call, info: &DispatchInfoOf<Self::Call>, len: usize ) -> Result<(), TransactionValidityError>
fn post_dispatch( pre: Option<Self::Pre>, info: &DispatchInfoOf<Self::Call>, post_info: &PostDispatchInfoOf<Self::Call>, len: usize, result: &DispatchResult ) -> Result<(), TransactionValidityError>
fn metadata() -> Vec<SignedExtensionMetadata>
source§impl<AccountId, Call: Dispatchable, TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5> SignedExtension for (TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5)where
TupleElement0: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
TupleElement1: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
TupleElement2: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
TupleElement3: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
TupleElement4: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
TupleElement5: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
impl<AccountId, Call: Dispatchable, TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5> SignedExtension for (TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5)where TupleElement0: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension, TupleElement1: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension, TupleElement2: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension, TupleElement3: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension, TupleElement4: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension, TupleElement5: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
type AccountId = AccountId
type Call = Call
const IDENTIFIER: &'static str = "You should call `identifier()`!"
type AdditionalSigned = (<TupleElement0 as SignedExtension>::AdditionalSigned, <TupleElement1 as SignedExtension>::AdditionalSigned, <TupleElement2 as SignedExtension>::AdditionalSigned, <TupleElement3 as SignedExtension>::AdditionalSigned, <TupleElement4 as SignedExtension>::AdditionalSigned, <TupleElement5 as SignedExtension>::AdditionalSigned)
type Pre = (<TupleElement0 as SignedExtension>::Pre, <TupleElement1 as SignedExtension>::Pre, <TupleElement2 as SignedExtension>::Pre, <TupleElement3 as SignedExtension>::Pre, <TupleElement4 as SignedExtension>::Pre, <TupleElement5 as SignedExtension>::Pre)
fn additional_signed( &self ) -> Result<Self::AdditionalSigned, TransactionValidityError>
fn validate( &self, who: &Self::AccountId, call: &Self::Call, info: &DispatchInfoOf<Self::Call>, len: usize ) -> TransactionValidity
fn pre_dispatch( self, who: &Self::AccountId, call: &Self::Call, info: &DispatchInfoOf<Self::Call>, len: usize ) -> Result<Self::Pre, TransactionValidityError>
fn validate_unsigned( call: &Self::Call, info: &DispatchInfoOf<Self::Call>, len: usize ) -> TransactionValidity
fn pre_dispatch_unsigned( call: &Self::Call, info: &DispatchInfoOf<Self::Call>, len: usize ) -> Result<(), TransactionValidityError>
fn post_dispatch( pre: Option<Self::Pre>, info: &DispatchInfoOf<Self::Call>, post_info: &PostDispatchInfoOf<Self::Call>, len: usize, result: &DispatchResult ) -> Result<(), TransactionValidityError>
fn metadata() -> Vec<SignedExtensionMetadata>
source§impl<AccountId, Call: Dispatchable, TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6, TupleElement7, TupleElement8, TupleElement9, TupleElement10, TupleElement11> SignedExtension for (TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6, TupleElement7, TupleElement8, TupleElement9, TupleElement10, TupleElement11)where
TupleElement0: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
TupleElement1: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
TupleElement2: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
TupleElement3: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
TupleElement4: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
TupleElement5: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
TupleElement6: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
TupleElement7: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
TupleElement8: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
TupleElement9: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
TupleElement10: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
TupleElement11: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
impl<AccountId, Call: Dispatchable, TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6, TupleElement7, TupleElement8, TupleElement9, TupleElement10, TupleElement11> SignedExtension for (TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6, TupleElement7, TupleElement8, TupleElement9, TupleElement10, TupleElement11)where TupleElement0: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension, TupleElement1: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension, TupleElement2: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension, TupleElement3: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension, TupleElement4: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension, TupleElement5: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension, TupleElement6: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension, TupleElement7: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension, TupleElement8: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension, TupleElement9: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension, TupleElement10: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension, TupleElement11: SignedExtension<AccountId = AccountId, Call = Call> + SignedExtension,
type AccountId = AccountId
type Call = Call
const IDENTIFIER: &'static str = "You should call `identifier()`!"
type AdditionalSigned = (<TupleElement0 as SignedExtension>::AdditionalSigned, <TupleElement1 as SignedExtension>::AdditionalSigned, <TupleElement2 as SignedExtension>::AdditionalSigned, <TupleElement3 as SignedExtension>::AdditionalSigned, <TupleElement4 as SignedExtension>::AdditionalSigned, <TupleElement5 as SignedExtension>::AdditionalSigned, <TupleElement6 as SignedExtension>::AdditionalSigned, <TupleElement7 as SignedExtension>::AdditionalSigned, <TupleElement8 as SignedExtension>::AdditionalSigned, <TupleElement9 as SignedExtension>::AdditionalSigned, <TupleElement10 as SignedExtension>::AdditionalSigned, <TupleElement11 as SignedExtension>::AdditionalSigned)
type Pre = (<TupleElement0 as SignedExtension>::Pre, <TupleElement1 as SignedExtension>::Pre, <TupleElement2 as SignedExtension>::Pre, <TupleElement3 as SignedExtension>::Pre, <TupleElement4 as SignedExtension>::Pre, <TupleElement5 as SignedExtension>::Pre, <TupleElement6 as SignedExtension>::Pre, <TupleElement7 as SignedExtension>::Pre, <TupleElement8 as SignedExtension>::Pre, <TupleElement9 as SignedExtension>::Pre, <TupleElement10 as SignedExtension>::Pre, <TupleElement11 as SignedExtension>::Pre)
fn additional_signed( &self ) -> Result<Self::AdditionalSigned, TransactionValidityError>
fn validate( &self, who: &Self::AccountId, call: &Self::Call, info: &DispatchInfoOf<Self::Call>, len: usize ) -> TransactionValidity
fn pre_dispatch( self, who: &Self::AccountId, call: &Self::Call, info: &DispatchInfoOf<Self::Call>, len: usize ) -> Result<Self::Pre, TransactionValidityError>
fn validate_unsigned( call: &Self::Call, info: &DispatchInfoOf<Self::Call>, len: usize ) -> TransactionValidity
fn pre_dispatch_unsigned( call: &Self::Call, info: &DispatchInfoOf<Self::Call>, len: usize ) -> Result<(), TransactionValidityError>
fn post_dispatch( pre: Option<Self::Pre>, info: &DispatchInfoOf<Self::Call>, post_info: &PostDispatchInfoOf<Self::Call>, len: usize, result: &DispatchResult ) -> Result<(), TransactionValidityError>
fn metadata() -> Vec<SignedExtensionMetadata>
source§impl SignedExtension for ()
impl SignedExtension for ()
Only for bare bone testing when you don’t care about signed extensions at all.