@@ -69,6 +69,7 @@ pub use fp_xcm::{EthereumXcmTransaction, XcmToEthereum};
6969#[ derive( PartialEq , Eq , Clone , Encode , Decode , RuntimeDebug , TypeInfo ) ]
7070pub enum RawOrigin {
7171 EthereumTransaction ( H160 ) ,
72+ XcmEthereumTransaction ( H160 ) ,
7273}
7374
7475pub fn ensure_ethereum_transaction < OuterOrigin > ( o : OuterOrigin ) -> Result < H160 , & ' static str >
8182 }
8283}
8384
85+ pub fn ensure_xcm_ethereum_transaction < OuterOrigin > ( o : OuterOrigin ) -> Result < H160 , & ' static str >
86+ where
87+ OuterOrigin : Into < Result < RawOrigin , OuterOrigin > > ,
88+ {
89+ match o. into ( ) {
90+ Ok ( RawOrigin :: XcmEthereumTransaction ( n) ) => Ok ( n) ,
91+ _ => Err ( "bad origin: expected to be a xcm Ethereum transaction" ) ,
92+ }
93+ }
94+
8495#[ derive( Clone , Debug , Encode , Decode , PartialEq , Eq ) ]
8596struct TransactionData {
8697 action : TransactionAction ,
@@ -122,8 +133,9 @@ impl<O: Into<Result<RawOrigin, O>> + From<RawOrigin>> EnsureOrigin<O>
122133{
123134 type Success = H160 ;
124135 fn try_origin ( o : O ) -> Result < Self :: Success , O > {
125- o. into ( ) . map ( |o| match o {
126- RawOrigin :: EthereumTransaction ( id) => id,
136+ o. into ( ) . and_then ( |o| match o {
137+ RawOrigin :: EthereumTransaction ( id) => Ok ( id) ,
138+ _ => Err ( o. into ( ) ) ,
127139 } )
128140 }
129141
@@ -133,6 +145,24 @@ impl<O: Into<Result<RawOrigin, O>> + From<RawOrigin>> EnsureOrigin<O>
133145 }
134146}
135147
148+ pub struct EnsureXcmEthereumTransaction ;
149+ impl < O : Into < Result < RawOrigin , O > > + From < RawOrigin > > EnsureOrigin < O >
150+ for EnsureXcmEthereumTransaction
151+ {
152+ type Success = H160 ;
153+ fn try_origin ( o : O ) -> Result < Self :: Success , O > {
154+ o. into ( ) . and_then ( |o| match o {
155+ RawOrigin :: XcmEthereumTransaction ( id) => Ok ( id) ,
156+ _ => Err ( o. into ( ) ) ,
157+ } )
158+ }
159+
160+ #[ cfg( feature = "runtime-benchmarks" ) ]
161+ fn successful_origin ( ) -> O {
162+ O :: from ( RawOrigin :: XcmEthereumTransaction ( Default :: default ( ) ) )
163+ }
164+ }
165+
136166impl < T > Call < T >
137167where
138168 OriginFor < T > : Into < Result < RawOrigin , OriginFor < T > > > ,
@@ -316,11 +346,7 @@ pub mod pallet {
316346 origin : OriginFor < T > ,
317347 xcm_transaction : EthereumXcmTransaction ,
318348 ) -> DispatchResultWithPostInfo {
319- let source = match & xcm_transaction {
320- EthereumXcmTransaction :: V1 ( v1_tx) => v1_tx. from ,
321- } ;
322-
323- T :: XcmTransactOrigin :: ensure_address_origin ( & source, origin) ?;
349+ let source = ensure_xcm_ethereum_transaction ( origin) ?;
324350
325351 let ( base_fee, base_fee_weight) = T :: FeeCalculator :: min_gas_price ( ) ;
326352 let ( who, account_weight) = pallet_evm:: Pallet :: < T > :: account_basic ( & source) ;
0 commit comments