From 7333a4d045e5c8c48529e4bb319200aebcf4a2dd Mon Sep 17 00:00:00 2001 From: bear <2630582710@qq.com> Date: Tue, 5 Jan 2021 16:31:45 +0800 Subject: [PATCH] Expand Executed Event (#429) --- frame/dvm/src/lib.rs | 70 ++++++++++++++++++++---------------------- frame/dvm/src/tests.rs | 4 +-- 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/frame/dvm/src/lib.rs b/frame/dvm/src/lib.rs index a432383f01..e14cfc1251 100644 --- a/frame/dvm/src/lib.rs +++ b/frame/dvm/src/lib.rs @@ -106,8 +106,8 @@ decl_storage! { decl_event!( /// Ethereum pallet events. pub enum Event { - /// An ethereum transaction was successfully executed. [from, transaction_hash] - Executed(H160, H256, ExitReason), + /// An ethereum transaction was successfully executed. [from, to/contract_address, transaction_hash, exit_reason] + Executed(H160, H160, H256, ExitReason), } ); @@ -138,7 +138,7 @@ decl_module! { ); let transaction_index = Pending::get().len() as u32; - let (to, info) = Self::execute( + let (to, contract_address, info) = Self::execute( source, transaction.input.clone(), transaction.value, @@ -202,7 +202,7 @@ decl_module! { Pending::append((transaction, status, receipt)); - Self::deposit_event(Event::Executed(source, transaction_hash,reason)); + Self::deposit_event(Event::Executed(source, contract_address.unwrap_or_default(), transaction_hash, reason)); Ok(Some(T::GasToWeight::gas_to_weight(used_gas.low_u32())).into()) } @@ -422,39 +422,37 @@ impl Module { nonce: Option, action: TransactionAction, config: Option, - ) -> Result<(Option, CallOrCreateInfo), DispatchError> { + ) -> Result<(Option, Option, CallOrCreateInfo), DispatchError> { match action { - ethereum::TransactionAction::Call(target) => Ok(( - Some(target), - CallOrCreateInfo::Call( - T::Runner::call( - from, - target, - input.clone(), - value, - gas_limit.low_u32(), - gas_price, - nonce, - config.as_ref().unwrap_or(T::config()), - ) - .map_err(Into::into)?, - ), - )), - ethereum::TransactionAction::Create => Ok(( - None, - CallOrCreateInfo::Create( - T::Runner::create( - from, - input.clone(), - value, - gas_limit.low_u32(), - gas_price, - nonce, - config.as_ref().unwrap_or(T::config()), - ) - .map_err(Into::into)?, - ), - )), + ethereum::TransactionAction::Call(target) => { + let res = T::Runner::call( + from, + target, + input.clone(), + value, + gas_limit.low_u32(), + gas_price, + nonce, + config.as_ref().unwrap_or(T::config()), + ) + .map_err(Into::into)?; + + Ok((Some(target), None, CallOrCreateInfo::Call(res))) + } + ethereum::TransactionAction::Create => { + let res = T::Runner::create( + from, + input.clone(), + value, + gas_limit.low_u32(), + gas_price, + nonce, + config.as_ref().unwrap_or(T::config()), + ) + .map_err(Into::into)?; + + Ok((None, Some(res.value), CallOrCreateInfo::Create(res))) + } } } } diff --git a/frame/dvm/src/tests.rs b/frame/dvm/src/tests.rs index 35ebb43be0..0a39198996 100644 --- a/frame/dvm/src/tests.rs +++ b/frame/dvm/src/tests.rs @@ -232,7 +232,7 @@ fn transaction_should_generate_correct_gas_used() { ext.execute_with(|| { let t = default_erc20_creation_transaction(alice); - let (_, info) = Ethereum::execute( + let (_, _, info) = Ethereum::execute( alice.address, t.input, t.value, @@ -296,7 +296,7 @@ fn call_should_handle_errors() { let bar: Vec = FromHex::from_hex("febb0f7e").unwrap(); // calling foo will succeed - let (_, info) = Ethereum::execute( + let (_, _, info) = Ethereum::execute( alice.address, foo, U256::zero(),