From 948b404f8c0bc3cb42f10c760b36019684750acb Mon Sep 17 00:00:00 2001 From: tgmichel Date: Mon, 21 Sep 2020 17:43:49 +0200 Subject: [PATCH] evm: Add executor logs to execute_evm response (#7048) * evm: Add executor logs to execute_evm response * Return logs on estimate gas * Cleanup --- substrate/frame/evm/src/lib.rs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/substrate/frame/evm/src/lib.rs b/substrate/frame/evm/src/lib.rs index a94ffe9535..dddb71fc02 100644 --- a/substrate/frame/evm/src/lib.rs +++ b/substrate/frame/evm/src/lib.rs @@ -337,10 +337,10 @@ decl_module! { nonce, true, )? { - (ExitReason::Succeed(_), _, _) => { + (ExitReason::Succeed(_), _, _, _) => { Module::::deposit_event(Event::::Executed(target)); }, - (_, _, _) => { + (_, _, _, _) => { Module::::deposit_event(Event::::ExecutedFailed(target)); }, } @@ -371,10 +371,10 @@ decl_module! { nonce, true, )? { - (ExitReason::Succeed(_), create_address, _) => { + (ExitReason::Succeed(_), create_address, _, _) => { Module::::deposit_event(Event::::Created(create_address)); }, - (_, create_address, _) => { + (_, create_address, _, _) => { Module::::deposit_event(Event::::CreatedFailed(create_address)); }, } @@ -406,10 +406,10 @@ decl_module! { nonce, true, )? { - (ExitReason::Succeed(_), create_address, _) => { + (ExitReason::Succeed(_), create_address, _, _) => { Module::::deposit_event(Event::::Created(create_address)); }, - (_, create_address, _) => { + (_, create_address, _, _) => { Module::::deposit_event(Event::::CreatedFailed(create_address)); }, } @@ -485,7 +485,7 @@ impl Module { gas_price: U256, nonce: Option, apply_state: bool, - ) -> Result<(ExitReason, H160, U256), Error> { + ) -> Result<(ExitReason, H160, U256, Vec), Error> { Self::execute_evm( source, value, @@ -517,7 +517,7 @@ impl Module { gas_price: U256, nonce: Option, apply_state: bool, - ) -> Result<(ExitReason, H160, U256), Error> { + ) -> Result<(ExitReason, H160, U256, Vec), Error> { let code_hash = H256::from_slice(Keccak256::digest(&init).as_slice()); Self::execute_evm( source, @@ -551,7 +551,7 @@ impl Module { gas_price: U256, nonce: Option, apply_state: bool, - ) -> Result<(ExitReason, Vec, U256), Error> { + ) -> Result<(ExitReason, Vec, U256, Vec), Error> { Self::execute_evm( source, value, @@ -578,7 +578,7 @@ impl Module { nonce: Option, apply_state: bool, f: F, - ) -> Result<(ExitReason, R, U256), Error> where + ) -> Result<(ExitReason, R, U256, Vec), Error> where F: FnOnce(&mut StackExecutor>) -> (ExitReason, R), { @@ -627,11 +627,19 @@ impl Module { ); executor.deposit(source, total_fee.saturating_sub(actual_fee)); + let (values, logs) = executor.deconstruct(); + let logs_data = logs.into_iter().map(|x| x ).collect::>(); + let logs_result = logs_data.clone().into_iter().map(|it| { + Log { + address: it.address, + topics: it.topics, + data: it.data + } + }).collect(); if apply_state { - let (values, logs) = executor.deconstruct(); - backend.apply(values, logs, true); + backend.apply(values, logs_data, true); } - Ok((retv, reason, used_gas)) + Ok((retv, reason, used_gas, logs_result)) } }