subsoil/runtime/traits/transaction_extension/
as_transaction_extension.rs1#![allow(deprecated)]
11
12use crate::runtime::Debug;
13use scale_info::TypeInfo;
14
15use crate::runtime::{
16 traits::{AsSystemOriginSigner, SignedExtension, ValidateResult},
17 transaction_validity::{InvalidTransaction, TransactionSource},
18};
19
20use super::*;
21
22#[derive(TypeInfo, Encode, Decode, DecodeWithMemTracking, Clone, PartialEq, Eq, Debug)]
24#[deprecated = "Convert your SignedExtension to a TransactionExtension."]
25pub struct AsTransactionExtension<SE: SignedExtension>(pub SE);
26
27impl<SE: SignedExtension + Default> Default for AsTransactionExtension<SE> {
28 fn default() -> Self {
29 Self(SE::default())
30 }
31}
32
33impl<SE: SignedExtension> From<SE> for AsTransactionExtension<SE> {
34 fn from(value: SE) -> Self {
35 Self(value)
36 }
37}
38
39impl<SE: SignedExtension> TransactionExtension<SE::Call> for AsTransactionExtension<SE>
40where
41 <SE::Call as Dispatchable>::RuntimeOrigin: AsSystemOriginSigner<SE::AccountId> + Clone,
42{
43 const IDENTIFIER: &'static str = SE::IDENTIFIER;
44 type Implicit = SE::AdditionalSigned;
45
46 fn implicit(&self) -> Result<Self::Implicit, TransactionValidityError> {
47 self.0.additional_signed()
48 }
49 fn metadata() -> Vec<TransactionExtensionMetadata> {
50 SE::metadata()
51 }
52 fn weight(&self, _call: &SE::Call) -> Weight {
53 Weight::zero()
54 }
55 type Val = ();
56 type Pre = SE::Pre;
57
58 fn validate(
59 &self,
60 origin: <SE::Call as Dispatchable>::RuntimeOrigin,
61 call: &SE::Call,
62 info: &DispatchInfoOf<SE::Call>,
63 len: usize,
64 _self_implicit: Self::Implicit,
65 _inherited_implication: &impl Encode,
66 _source: TransactionSource,
67 ) -> ValidateResult<Self::Val, SE::Call> {
68 let who = origin.as_system_origin_signer().ok_or(InvalidTransaction::BadSigner)?;
69 let r = self.0.validate(who, call, info, len)?;
70 Ok((r, (), origin))
71 }
72
73 fn prepare(
74 self,
75 _: (),
76 origin: &<SE::Call as Dispatchable>::RuntimeOrigin,
77 call: &SE::Call,
78 info: &DispatchInfoOf<SE::Call>,
79 len: usize,
80 ) -> Result<Self::Pre, TransactionValidityError> {
81 let who = origin.as_system_origin_signer().ok_or(InvalidTransaction::BadSigner)?;
82 self.0.pre_dispatch(who, call, info, len)
83 }
84
85 fn post_dispatch_details(
86 pre: Self::Pre,
87 info: &DispatchInfoOf<SE::Call>,
88 post_info: &PostDispatchInfoOf<SE::Call>,
89 len: usize,
90 result: &DispatchResult,
91 ) -> Result<Weight, TransactionValidityError> {
92 SE::post_dispatch(Some(pre), info, post_info, len, result)?;
93 Ok(Weight::zero())
94 }
95
96 fn bare_validate(
97 call: &SE::Call,
98 info: &DispatchInfoOf<SE::Call>,
99 len: usize,
100 ) -> TransactionValidity {
101 SE::validate_unsigned(call, info, len)
102 }
103
104 fn bare_validate_and_prepare(
105 call: &SE::Call,
106 info: &DispatchInfoOf<SE::Call>,
107 len: usize,
108 ) -> Result<(), TransactionValidityError> {
109 SE::pre_dispatch_unsigned(call, info, len)
110 }
111
112 fn bare_post_dispatch(
113 info: &DispatchInfoOf<SE::Call>,
114 post_info: &mut PostDispatchInfoOf<SE::Call>,
115 len: usize,
116 result: &DispatchResult,
117 ) -> Result<(), TransactionValidityError> {
118 SE::post_dispatch(None, info, post_info, len, result)
119 }
120}