diff --git a/Cargo.lock b/Cargo.lock index 210f6bc942..05bac73e17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5837,6 +5837,7 @@ dependencies = [ name = "pallet-ethereum" version = "4.0.0-dev" dependencies = [ + "environmental", "ethereum", "ethereum-types", "evm", diff --git a/frame/ethereum/Cargo.toml b/frame/ethereum/Cargo.toml index 77f2d78d4e..484bf27338 100644 --- a/frame/ethereum/Cargo.toml +++ b/frame/ethereum/Cargo.toml @@ -11,6 +11,7 @@ repository = { workspace = true } targets = ["x86_64-unknown-linux-gnu"] [dependencies] +environmental = { workspace = true } ethereum = { workspace = true, features = ["with-codec"] } ethereum-types = { workspace = true } evm = { workspace = true, features = ["with-codec"] } @@ -44,6 +45,7 @@ fp-self-contained = { workspace = true, features = ["default"] } [features] default = ["std"] std = [ + "environmental/std", "ethereum/std", "evm/std", "ethereum-types/std", diff --git a/frame/ethereum/src/catch_exec_info.rs b/frame/ethereum/src/catch_exec_info.rs new file mode 100644 index 0000000000..64fb933e15 --- /dev/null +++ b/frame/ethereum/src/catch_exec_info.rs @@ -0,0 +1,32 @@ +// This file is part of Frontier. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use fp_evm::CallOrCreateInfo; + +environmental::environmental!(GLOBAL: Option); + +// Allow to catch informations of an ethereum execution inside the provided closure. +pub fn catch_exec_info R>( + execution_info: &mut Option, + f: F, +) -> R { + GLOBAL::using(execution_info, f) +} + +pub(super) fn fill_exec_info(execution_info: &CallOrCreateInfo) { + GLOBAL::with(|exec_info| exec_info.replace(execution_info.clone())); +} diff --git a/frame/ethereum/src/lib.rs b/frame/ethereum/src/lib.rs index a211f2478e..867ab4a7c1 100644 --- a/frame/ethereum/src/lib.rs +++ b/frame/ethereum/src/lib.rs @@ -27,17 +27,20 @@ extern crate alloc; +mod catch_exec_info; #[cfg(all(feature = "std", test))] mod mock; #[cfg(all(feature = "std", test))] mod tests; use alloc::{vec, vec::Vec}; +pub use catch_exec_info::catch_exec_info; use core::marker::PhantomData; pub use ethereum::{ AccessListItem, BlockV2 as Block, LegacyTransactionMessage, Log, ReceiptV3 as Receipt, TransactionAction, TransactionV2 as Transaction, }; + use ethereum_types::{Bloom, BloomInput, H160, H256, H64, U256}; use evm::ExitReason; use scale_codec::{Decode, Encode, MaxEncodedLen}; @@ -597,6 +600,8 @@ impl Pallet { ) -> Result<(PostDispatchInfo, CallOrCreateInfo), DispatchErrorWithPostInfo> { let (to, _, info) = Self::execute(source, &transaction, None)?; + catch_exec_info::fill_exec_info(&info); + let pending = Pending::::get(); let transaction_hash = transaction.hash(); let transaction_index = pending.len() as u32;