Skip to content

Commit 6d6713f

Browse files
committed
Change to XCM Origin
1 parent dcc01ce commit 6d6713f

2 files changed

Lines changed: 33 additions & 12 deletions

File tree

frame/ethereum/src/lib.rs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub use fp_xcm::{EthereumXcmTransaction, XcmToEthereum};
6969
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
7070
pub enum RawOrigin {
7171
EthereumTransaction(H160),
72+
XcmEthereumTransaction(H160),
7273
}
7374

7475
pub fn ensure_ethereum_transaction<OuterOrigin>(o: OuterOrigin) -> Result<H160, &'static str>
@@ -81,6 +82,16 @@ where
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)]
8596
struct 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+
136166
impl<T> Call<T>
137167
where
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);

primitives/xcm/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ pub struct EthereumXcmTransactionV1 {
8080
pub input: Vec<u8>,
8181
/// Map of addresses to be pre-paid to warm storage.
8282
pub access_list: Option<Vec<(H160, Vec<H256>)>>,
83-
/// account calling the dispatchable
84-
pub from: H160,
8583
}
8684

8785
pub trait XcmToEthereum {
@@ -197,7 +195,6 @@ mod tests {
197195
value: U256::from(0),
198196
input: vec![1u8],
199197
access_list: None,
200-
from: H160::default(),
201198
};
202199
let nonce = U256::from(0);
203200
let base_fee = U256::from(1);
@@ -231,7 +228,6 @@ mod tests {
231228
value: U256::from(0),
232229
input: vec![1u8],
233230
access_list: None,
234-
from: H160::default(),
235231
};
236232
let nonce = U256::from(0);
237233
let base_fee = U256::from(1);
@@ -265,7 +261,6 @@ mod tests {
265261
value: U256::from(0),
266262
input: vec![1u8],
267263
access_list: None,
268-
from: H160::default(),
269264
};
270265
let nonce = U256::from(0);
271266
let base_fee = U256::from(1);

0 commit comments

Comments
 (0)