diff --git a/Cargo.lock b/Cargo.lock index 3c1533cb14..f51f3ec07c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4285,6 +4285,7 @@ dependencies = [ "frame-support", "frame-system", "hex", + "impl-trait-for-tuples", "log", "pallet-balances", "pallet-evm-precompile-simple", diff --git a/frame/ethereum/src/mock.rs b/frame/ethereum/src/mock.rs index a14d482988..4928dca369 100644 --- a/frame/ethereum/src/mock.rs +++ b/frame/ethereum/src/mock.rs @@ -168,6 +168,7 @@ impl pallet_evm::Config for Test { type BlockGasLimit = BlockGasLimit; type Runner = pallet_evm::runner::stack::Runner; type OnChargeTransaction = (); + type OnCreate = (); type FindAuthor = FindAuthorTruncated; } diff --git a/frame/evm/Cargo.toml b/frame/evm/Cargo.toml index ce6203cc83..15676a46fd 100644 --- a/frame/evm/Cargo.toml +++ b/frame/evm/Cargo.toml @@ -15,6 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"] environmental = { workspace = true, optional = true } evm = { workspace = true, features = ["with-codec"] } hex = { version = "0.4.3", default-features = false, features = ["alloc"] } +impl-trait-for-tuples = "0.2.2" log = { version = "0.4.17", default-features = false } rlp = { workspace = true } scale-codec = { package = "parity-scale-codec", workspace = true } diff --git a/frame/evm/precompile/dispatch/src/mock.rs b/frame/evm/precompile/dispatch/src/mock.rs index b9ad6bd216..173091f4f6 100644 --- a/frame/evm/precompile/dispatch/src/mock.rs +++ b/frame/evm/precompile/dispatch/src/mock.rs @@ -157,6 +157,7 @@ impl pallet_evm::Config for Test { type BlockGasLimit = BlockGasLimit; type Runner = pallet_evm::runner::stack::Runner; type OnChargeTransaction = (); + type OnCreate = (); type FindAuthor = FindAuthorTruncated; } diff --git a/frame/evm/src/lib.rs b/frame/evm/src/lib.rs index fa38d6bd5a..a6b1406e2d 100644 --- a/frame/evm/src/lib.rs +++ b/frame/evm/src/lib.rs @@ -73,6 +73,7 @@ use frame_support::{ weights::Weight, }; use frame_system::RawOrigin; +use impl_trait_for_tuples::impl_for_tuples; use sp_core::{Hasher, H160, H256, U256}; use sp_runtime::{ traits::{BadOrigin, Saturating, UniqueSaturatedInto, Zero}, @@ -148,6 +149,9 @@ pub mod pallet { /// Similar to `OnChargeTransaction` of `pallet_transaction_payment` type OnChargeTransaction: OnChargeEVMTransaction; + /// Called on create calls, used to record owner + type OnCreate: OnCreate; + /// Find author for the current block. type FindAuthor: FindAuthor; @@ -892,3 +896,20 @@ U256: UniqueSaturatedInto>, ::Currency, ()> as OnChargeEVMTransaction>::pay_priority_fee(tip); } } + +pub trait OnCreate { + fn on_create(owner: H160, contract: H160); +} + +impl OnCreate for () { + fn on_create(_owner: H160, _contract: H160) {} +} + +#[impl_for_tuples(1, 12)] +impl OnCreate for Tuple { + fn on_create(owner: H160, contract: H160) { + for_tuples!(#( + Tuple::on_create(owner, contract); + )*) + } +} diff --git a/frame/evm/src/mock.rs b/frame/evm/src/mock.rs index 1e9018e61b..a82721fe5e 100644 --- a/frame/evm/src/mock.rs +++ b/frame/evm/src/mock.rs @@ -150,6 +150,7 @@ impl crate::Config for Test { type BlockGasLimit = BlockGasLimit; type Runner = crate::runner::stack::Runner; type OnChargeTransaction = (); + type OnCreate = (); type FindAuthor = FindAuthorTruncated; } diff --git a/frame/evm/src/runner/stack.rs b/frame/evm/src/runner/stack.rs index 82926bf2c4..be39912a48 100644 --- a/frame/evm/src/runner/stack.rs +++ b/frame/evm/src/runner/stack.rs @@ -19,8 +19,8 @@ use crate::{ runner::Runner as RunnerT, AccountCodes, AccountStorages, AddressMapping, BalanceOf, - BlockHashMapping, Config, Error, Event, FeeCalculator, OnChargeEVMTransaction, Pallet, - RunnerError, + BlockHashMapping, Config, Error, Event, FeeCalculator, OnChargeEVMTransaction, OnCreate, + Pallet, RunnerError, }; use evm::{ backend::Backend as BackendT, @@ -417,6 +417,7 @@ where is_transactional, |executor| { let address = executor.create_address(evm::CreateScheme::Legacy { caller: source }); + T::OnCreate::on_create(source, address); let (reason, _) = executor.transact_create(source, value, init, gas_limit, access_list); (reason, address) @@ -470,6 +471,7 @@ where code_hash, salt, }); + T::OnCreate::on_create(source, address); let (reason, _) = executor.transact_create2(source, value, init, salt, gas_limit, access_list); (reason, address) diff --git a/template/runtime/src/lib.rs b/template/runtime/src/lib.rs index f2ed3f3d6d..e7b9c9bb69 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -335,6 +335,7 @@ impl pallet_evm::Config for Runtime { type BlockGasLimit = BlockGasLimit; type Runner = pallet_evm::runner::stack::Runner; type OnChargeTransaction = (); + type OnCreate = (); type FindAuthor = FindAuthorTruncated; }