diff --git a/ethcore/engine/src/engine.rs b/ethcore/engine/src/engine.rs index a25ab4a27..8ec7bba31 100644 --- a/ethcore/engine/src/engine.rs +++ b/ethcore/engine/src/engine.rs @@ -42,7 +42,7 @@ use machine::{ Machine, executed_block::ExecutedBlock, }; -use vm::{EnvInfo, Schedule, CallType, ActionValue}; +use vm::{EnvInfo, Schedule, ActionType, ActionValue}; use crate::signer::EngineSigner; @@ -82,7 +82,7 @@ pub fn default_system_or_code_call<'a>(machine: &'a Machine, block: &'a mut Exec Some(ActionValue::Apparent(U256::zero())), U256::max_value(), Some(data), - Some(CallType::StaticCall), + Some(ActionType::StaticCall), ) }, }; diff --git a/ethcore/evm/src/interpreter/mod.rs b/ethcore/evm/src/interpreter/mod.rs index 67cd39ce7..19d763fc6 100644 --- a/ethcore/evm/src/interpreter/mod.rs +++ b/ethcore/evm/src/interpreter/mod.rs @@ -33,7 +33,7 @@ use ethereum_types::{U256, U512, H256, Address, BigEndianHash}; use vm::{ - self, ActionParams, ParamsType, ActionValue, CallType, MessageCallResult, + self, ActionParams, ParamsType, ActionValue, ActionType, MessageCallResult, ContractCreateResult, CreateContractAddress, ReturnData, GasLeft, Schedule, TrapKind, TrapError }; @@ -133,8 +133,8 @@ struct InterpreterParams { pub value: ActionValue, /// Input data. pub data: Option, - /// Type of call - pub call_type: CallType, + /// Type of action + pub action_type: ActionType, /// Param types encoding pub params_type: ParamsType, } @@ -152,7 +152,7 @@ impl From for InterpreterParams { gas_price: params.gas_price, value: params.value, data: params.data, - call_type: params.call_type, + action_type: params.action_type, params_type: params.params_type, } } @@ -532,7 +532,9 @@ impl Interpreter { let init_size = self.stack.pop_back(); let address_scheme = match instruction { instructions::CREATE => CreateContractAddress::FromSenderAndNonce, - instructions::CREATE2 => CreateContractAddress::FromSenderSaltAndCodeHash(BigEndianHash::from_uint(&self.stack.pop_back())), + instructions::CREATE2 => CreateContractAddress::FromSenderSaltAndCodeHash( + BigEndianHash::from_uint(&self.stack.pop_back()) + ), _ => unreachable!("instruction can only be CREATE/CREATE2 checked above; qed"), }; @@ -553,7 +555,14 @@ impl Interpreter { let contract_code = self.mem.read_slice(init_off, init_size); - let create_result = ext.create(&create_gas.as_u256(), &endowment, contract_code, &self.params.code_version, address_scheme, true); + let create_result = ext.create( + &create_gas.as_u256(), + &endowment, + contract_code, + &self.params.code_version, + address_scheme, + true, + ); return match create_result { Ok(ContractCreateResult::Created(address, gas_left)) => { self.stack.push(address_to_u256(address)); @@ -607,14 +616,14 @@ impl Interpreter { return Err(vm::Error::MutableCallInStaticContext); } let has_balance = ext.balance(&self.params.address)? >= value.expect("value set for all but delegate call; qed"); - (&self.params.address, &code_address, has_balance, CallType::Call) + (&self.params.address, &code_address, has_balance, ActionType::Call) }, instructions::CALLCODE => { let has_balance = ext.balance(&self.params.address)? >= value.expect("value set for all but delegate call; qed"); - (&self.params.address, &self.params.address, has_balance, CallType::CallCode) + (&self.params.address, &self.params.address, has_balance, ActionType::CallCode) }, - instructions::DELEGATECALL => (&self.params.sender, &self.params.address, true, CallType::DelegateCall), - instructions::STATICCALL => (&self.params.address, &code_address, true, CallType::StaticCall), + instructions::DELEGATECALL => (&self.params.sender, &self.params.address, true, ActionType::DelegateCall), + instructions::STATICCALL => (&self.params.address, &code_address, true, ActionType::StaticCall), _ => panic!(format!("Unexpected instruction {:?} in CALL branch.", instruction)) }; diff --git a/ethcore/evm/src/lib.rs b/ethcore/evm/src/lib.rs index 463473d47..2907a7ae1 100644 --- a/ethcore/evm/src/lib.rs +++ b/ethcore/evm/src/lib.rs @@ -47,7 +47,7 @@ mod instructions; mod tests; pub use vm::{ - Schedule, CleanDustMode, EnvInfo, CallType, ActionParams, Ext, + Schedule, CleanDustMode, EnvInfo, ActionType, ActionParams, Ext, ContractCreateResult, MessageCallResult, CreateContractAddress, GasLeft, ReturnData }; diff --git a/ethcore/executive-state/src/lib.rs b/ethcore/executive-state/src/lib.rs index b9468a7a7..be4315144 100644 --- a/ethcore/executive-state/src/lib.rs +++ b/ethcore/executive-state/src/lib.rs @@ -276,7 +276,6 @@ mod tests { test_helpers::{get_temp_state, get_temp_state_db} }; use ethtrie; - use evm::CallType; use machine::Machine; use pod::{self, PodAccount, PodState}; use rustc_hex::FromHex; @@ -324,6 +323,7 @@ mod tests { value: 100.into(), gas: 77412.into(), init: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85], + creation_method: Some(trace::CreationMethod::Create), }), result: trace::Res::Create(trace::CreateResult { gas_used: U256::from(3224), @@ -381,6 +381,7 @@ mod tests { value: 100.into(), gas: 78792.into(), init: vec![91, 96, 0, 86], + creation_method: Some(trace::CreationMethod::Create), }), result: trace::Res::FailedCreate(TraceError::OutOfGas), subtraces: 0 @@ -419,7 +420,7 @@ mod tests { value: 100.into(), gas: 79000.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::Call(trace::CallResult { gas_used: U256::from(3), @@ -460,7 +461,7 @@ mod tests { value: 100.into(), gas: 79000.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::Call(trace::CallResult { gas_used: U256::from(0), @@ -501,7 +502,7 @@ mod tests { value: 0.into(), gas: 79_000.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::Call(trace::CallResult { gas_used: U256::from(3000), @@ -543,7 +544,7 @@ mod tests { value: 0.into(), gas: 79000.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::Call(trace::CallResult { gas_used: U256::from(3_721), // in post-eip150 @@ -587,7 +588,7 @@ mod tests { value: 0.into(), gas: 79000.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::Call(trace::CallResult { gas_used: 724.into(), // in post-eip150 @@ -602,7 +603,7 @@ mod tests { value: 0.into(), gas: 4096.into(), input: vec![], - call_type: CallType::CallCode, + call_type: Some(trace::CallType::CallCode), }), result: trace::Res::Call(trace::CallResult { gas_used: 3.into(), @@ -646,7 +647,7 @@ mod tests { value: 0.into(), gas: 79000.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::Call(trace::CallResult { gas_used: U256::from(736), // in post-eip150 @@ -661,7 +662,7 @@ mod tests { value: 0.into(), gas: 32768.into(), input: vec![], - call_type: CallType::DelegateCall, + call_type: Some(trace::CallType::DelegateCall), }), result: trace::Res::Call(trace::CallResult { gas_used: 18.into(), @@ -702,7 +703,7 @@ mod tests { value: 100.into(), gas: 79000.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::FailedCall(TraceError::OutOfGas), subtraces: 0, @@ -744,7 +745,7 @@ mod tests { value: 100.into(), gas: 79000.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::Call(trace::CallResult { gas_used: U256::from(69), @@ -759,7 +760,7 @@ mod tests { value: 0.into(), gas: 78934.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::Call(trace::CallResult { gas_used: U256::from(3), @@ -801,7 +802,7 @@ mod tests { value: 100.into(), gas: 79000.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::Call(trace::CallResult { gas_used: U256::from(31761), @@ -816,7 +817,7 @@ mod tests { value: 69.into(), gas: 2300.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::Call(trace::CallResult::default()), }]; @@ -855,7 +856,7 @@ mod tests { value: 100.into(), gas: 79000.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::Call(trace::CallResult { gas_used: U256::from(31761), @@ -898,7 +899,7 @@ mod tests { value: 100.into(), gas: 79000.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::Call(trace::CallResult { gas_used: U256::from(79_000), @@ -913,7 +914,7 @@ mod tests { value: 0.into(), gas: 78934.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::FailedCall(TraceError::OutOfGas), }]; @@ -954,7 +955,7 @@ mod tests { value: 100.into(), gas: 79000.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::Call(trace::CallResult { gas_used: U256::from(135), @@ -969,7 +970,7 @@ mod tests { value: 0.into(), gas: 78934.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::Call(trace::CallResult { gas_used: U256::from(69), @@ -984,7 +985,7 @@ mod tests { value: 0.into(), gas: 78868.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::Call(trace::CallResult { gas_used: U256::from(3), @@ -1029,7 +1030,7 @@ mod tests { value: 100.into(), gas: 79000.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::Call(trace::CallResult { gas_used: U256::from(79_000), @@ -1044,7 +1045,7 @@ mod tests { value: 0.into(), gas: 78934.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::FailedCall(TraceError::OutOfGas), }, FlatTrace { @@ -1055,7 +1056,7 @@ mod tests { to: Address::from_low_u64_be(0xc), value: 0.into(), gas: 78868.into(), - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), input: vec![], }), result: trace::Res::Call(trace::CallResult { @@ -1099,7 +1100,7 @@ mod tests { value: 100.into(), gas: 79000.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::Call(trace::CallResult { gas_used: 3.into(), diff --git a/ethcore/machine/src/executive.rs b/ethcore/machine/src/executive.rs index 18852d4f6..652bda819 100644 --- a/ethcore/machine/src/executive.rs +++ b/ethcore/machine/src/executive.rs @@ -26,7 +26,7 @@ use rlp::RlpStream; use log::trace; use account_state::{Backend as StateBackend, State, CleanupMode}; -use evm::{CallType, Finalize, FinalizationResult}; +use evm::{ActionType, Finalize, FinalizationResult}; use vm::{ self, EnvInfo, CreateContractAddress, ReturnData, CleanDustMode, ActionParams, ActionValue, Schedule, TrapError, ResumeCall, ResumeCreate @@ -241,7 +241,7 @@ impl<'a> CallCreateExecutive<'a> { trace!("Executive::call(params={:?}) self.env_info={:?}, parent_static={}", params, info, parent_static_flag); let gas = params.gas; - let static_flag = parent_static_flag || params.call_type == CallType::StaticCall; + let static_flag = parent_static_flag || params.action_type == ActionType::StaticCall; // if destination is builtin, try to execute it let kind = if let Some(builtin) = machine.builtin(¶ms.code_address, info.number) { @@ -298,7 +298,7 @@ impl<'a> CallCreateExecutive<'a> { } } else { if (static_flag && - (params.call_type == CallType::StaticCall || params.call_type == CallType::Call)) && + (params.action_type == ActionType::StaticCall || params.action_type == ActionType::Call)) && params.value.value() > U256::zero() { return Err(vm::Error::MutableCallInStaticContext); @@ -909,7 +909,7 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> { code: Some(Arc::new(t.data.clone())), code_version: schedule.latest_version, data: None, - call_type: CallType::None, + action_type: ActionType::Create, params_type: vm::ParamsType::Embedded, }; let res = self.create(params, &mut substate, &mut tracer, &mut vm_tracer); @@ -932,7 +932,7 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> { code_hash: self.state.code_hash(address)?, code_version: self.state.code_version(address)?, data: Some(t.data.clone()), - call_type: CallType::Call, + action_type: ActionType::Call, params_type: vm::ParamsType::Separate, }; let res = self.call(params, &mut substate, &mut tracer, &mut vm_tracer); @@ -1236,7 +1236,7 @@ mod tests { use parity_crypto::publickey::{Generator, Random}; use evm::{Factory, evm_test, evm_test_ignore}; use macros::vec_into; - use vm::{ActionParams, ActionValue, CallType, EnvInfo, CreateContractAddress}; + use vm::{ActionParams, ActionValue, EnvInfo, CreateContractAddress}; use ::trace::{ trace, FlatTrace, Tracer, NoopTracer, ExecutiveTracer, @@ -1414,7 +1414,7 @@ mod tests { params.gas = U256::from(100_000); params.code = Some(Arc::new(code)); params.value = ActionValue::Transfer(U256::from(100)); - params.call_type = CallType::Call; + params.action_type = ActionType::Call; let mut state = get_temp_state(); state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty).unwrap(); let info = EnvInfo::default(); @@ -1434,7 +1434,7 @@ mod tests { value: 100.into(), gas: 100_000.into(), input: vec![], - call_type: CallType::Call + call_type: Some(trace::CallType::Call) }), result: trace::Res::Call(trace::CallResult { gas_used: 33021.into(), @@ -1449,7 +1449,7 @@ mod tests { value: 1.into(), gas: 66560.into(), input: vec![], - call_type: CallType::Call + call_type: Some(trace::CallType::Call) }), result: trace::Res::Call(trace::CallResult { gas_used: 600.into(), output: vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 156, 17, 133, 165, 197, 233, 252, 84, 97, 40, 8, 151, 126, 232, 245, 72, 178, 37, 141, 49] @@ -1498,7 +1498,7 @@ mod tests { params.gas = U256::from(100_000); params.code = Some(Arc::new(code)); params.value = ActionValue::Transfer(U256::from(100)); - params.call_type = CallType::Call; + params.action_type = ActionType::Call; let mut state = get_temp_state(); state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty).unwrap(); let info = EnvInfo::default(); @@ -1524,7 +1524,7 @@ mod tests { value: 100.into(), gas: 100000.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::Call(trace::CallResult { gas_used: U256::from(55_248), @@ -1537,7 +1537,8 @@ mod tests { from: Address::from_str("b010143a42d5980c7e5ef0e4a4416dc098a4fed3").unwrap(), value: 23.into(), gas: 67979.into(), - init: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85] + init: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85], + creation_method: Some(trace::CreationMethod::Create), }), result: trace::Res::Create(trace::CreateResult { gas_used: U256::from(3224), @@ -1614,7 +1615,7 @@ mod tests { params.gas = U256::from(100_000); params.code = Some(Arc::new(code)); params.value = ActionValue::Transfer(U256::from(100)); - params.call_type = CallType::Call; + params.action_type = ActionType::Call; let mut state = get_temp_state(); state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty).unwrap(); let info = EnvInfo::default(); @@ -1640,7 +1641,7 @@ mod tests { value: 100.into(), gas: 100_000.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(trace::CallType::Call), }), result: trace::Res::Call(trace::CallResult { gas_used: U256::from(37_033), @@ -1653,7 +1654,8 @@ mod tests { from: Address::from_str("b010143a42d5980c7e5ef0e4a4416dc098a4fed3").unwrap(), value: 23.into(), gas: 66_917.into(), - init: vec![0x60, 0x01, 0x60, 0x00, 0xfd] + init: vec![0x60, 0x01, 0x60, 0x00, 0xfd], + creation_method: Some(trace::CreationMethod::Create), }), result: trace::Res::FailedCreate(vm::Error::Reverted.into()), }]; @@ -1711,6 +1713,7 @@ mod tests { value: 100.into(), gas: params.gas, init: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85], + creation_method: Some(trace::CreationMethod::Create), }), result: trace::Res::Create(trace::CreateResult { gas_used: U256::from(3224), diff --git a/ethcore/machine/src/externalities.rs b/ethcore/machine/src/externalities.rs index adab87b00..e380ed8bd 100644 --- a/ethcore/machine/src/externalities.rs +++ b/ethcore/machine/src/externalities.rs @@ -29,7 +29,7 @@ use common_types::{ }; use trace::{Tracer, VMTracer}; use vm::{ - self, ActionParams, ActionValue, EnvInfo, CallType, Schedule, + self, ActionParams, ActionValue, EnvInfo, ActionType, Schedule, Ext, ContractCreateResult, MessageCallResult, CreateContractAddress, ReturnData, TrapKind }; @@ -193,7 +193,7 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B> code_hash, code_version, data: Some(data.as_bytes().to_vec()), - call_type: CallType::Call, + action_type: ActionType::Call, params_type: vm::ParamsType::Separate, }; @@ -241,6 +241,12 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B> } }; + let create_type = match address_scheme { + CreateContractAddress::FromSenderAndNonce => ActionType::Create, + CreateContractAddress::FromSenderSaltAndCodeHash(_) => ActionType::Create2, + CreateContractAddress::FromSenderAndCodeHash => ActionType::Create2, + }; + // prepare the params let params = ActionParams { code_address: address.clone(), @@ -254,7 +260,7 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B> code_hash, code_version: *parent_version, data: None, - call_type: CallType::None, + action_type: create_type, params_type: vm::ParamsType::Embedded, }; @@ -285,7 +291,7 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B> value: Option, data: &[u8], code_address: &Address, - call_type: CallType, + call_type: ActionType, trap: bool, ) -> ::std::result::Result { trace!(target: "externalities", "call"); @@ -311,7 +317,7 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B> code_hash, code_version, data: Some(data.to_vec()), - call_type, + action_type: call_type, params_type: vm::ParamsType::Separate, }; @@ -457,7 +463,7 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B> mod tests { use std::str::FromStr; use ethereum_types::{U256, Address}; - use evm::{EnvInfo, Ext, CallType}; + use evm::{EnvInfo, Ext, ActionType}; use account_state::State; use ethcore::test_helpers::get_temp_state; use trace::{NoopTracer, NoopVMTracer}; @@ -591,7 +597,7 @@ mod tests { Some("0000000000000000000000000000000000000000000000000000000000150000".parse::().unwrap()), &[], &Address::zero(), - CallType::Call, + ActionType::Call, false, ).ok().unwrap(); } diff --git a/ethcore/machine/src/machine.rs b/ethcore/machine/src/machine.rs index fcf710b1d..b3fa13478 100644 --- a/ethcore/machine/src/machine.rs +++ b/ethcore/machine/src/machine.rs @@ -34,7 +34,7 @@ use common_types::{ errors::{EngineError, EthcoreError as Error}, transaction::{self, SYSTEM_ADDRESS, UNSIGNED_SENDER, UnverifiedTransaction, SignedTransaction}, }; -use vm::{CallType, ActionParams, ActionValue, ParamsType}; +use vm::{ActionType, ActionParams, ActionValue, ParamsType}; use vm::{EnvInfo, Schedule}; use account_state::CleanupMode; @@ -141,7 +141,7 @@ impl Machine { value: Option, gas: U256, data: Option>, - call_type: Option, + action_type: Option, ) -> Result, Error> { let env_info = { let mut env_info = block.env_info(); @@ -163,7 +163,7 @@ impl Machine { code_hash, code_version: 0.into(), data, - call_type: call_type.unwrap_or(CallType::Call), + action_type: action_type.unwrap_or(ActionType::Call), params_type: ParamsType::Separate, }; let schedule = self.schedule(env_info.number); diff --git a/ethcore/spec/src/spec.rs b/ethcore/spec/src/spec.rs index 332734697..c11ab4ae0 100644 --- a/ethcore/spec/src/spec.rs +++ b/ethcore/spec/src/spec.rs @@ -52,7 +52,7 @@ use pod::PodState; use rlp::{Rlp, RlpStream}; use trace::{NoopTracer, NoopVMTracer}; use trie_vm_factories::Factories; -use vm::{EnvInfo, CallType, ActionValue, ActionParams, ParamsType}; +use vm::{EnvInfo, ActionType, ActionValue, ActionParams, ParamsType}; use crate::{ Genesis, @@ -163,7 +163,7 @@ fn run_constructors( value: ActionValue::Transfer(Default::default()), code: Some(Arc::new(constructor.clone())), data: None, - call_type: CallType::None, + action_type: ActionType::Create, params_type: ParamsType::Embedded, }; diff --git a/ethcore/src/json_tests/executive.rs b/ethcore/src/json_tests/executive.rs index c68b92ba5..0057e8f7d 100644 --- a/ethcore/src/json_tests/executive.rs +++ b/ethcore/src/json_tests/executive.rs @@ -20,7 +20,7 @@ use super::test_common::*; use account_state::{Backend as StateBackend, State}; use evm::Finalize; use vm::{ - self, ActionParams, CallType, Schedule, Ext, + self, ActionParams, ActionType, Schedule, Ext, ContractCreateResult, EnvInfo, MessageCallResult, CreateContractAddress, ReturnData, }; @@ -172,7 +172,7 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for TestExt<'a, T, V, B> value: Option, data: &[u8], _code_address: &Address, - _call_type: CallType, + _call_type: ActionType, _trap: bool ) -> Result { self.callcreates.push(CallCreate { diff --git a/ethcore/src/tests/evm.rs b/ethcore/src/tests/evm.rs index 78ff7ff11..514b17de9 100644 --- a/ethcore/src/tests/evm.rs +++ b/ethcore/src/tests/evm.rs @@ -18,7 +18,7 @@ use std::sync::Arc; use hash::keccak; -use vm::{EnvInfo, ActionParams, ActionValue, CallType, ParamsType}; +use vm::{EnvInfo, ActionParams, ActionValue, ActionType, ParamsType}; use evm::Factory; use machine::{ executive::Executive, @@ -62,7 +62,7 @@ fn test_blockhash_eip210(factory: Factory) { code_hash: Some(blockhash_contract_code_hash), code_version: 0.into(), data: Some(H256::from_low_u64_be(i - 1).as_bytes().to_vec()), - call_type: CallType::Call, + action_type: ActionType::Call, params_type: ParamsType::Separate, }; let schedule = machine.schedule(env_info.number); @@ -86,7 +86,7 @@ fn test_blockhash_eip210(factory: Factory) { code_hash: Some(get_prev_hash_code_hash), code_version: 0.into(), data: None, - call_type: CallType::Call, + action_type: ActionType::Call, params_type: ParamsType::Separate, }; let schedule = machine.schedule(env_info.number); diff --git a/ethcore/trace/src/db.rs b/ethcore/trace/src/db.rs index 8426e2e3a..076fbf238 100644 --- a/ethcore/trace/src/db.rs +++ b/ethcore/trace/src/db.rs @@ -374,13 +374,12 @@ mod tests { use ethcore::test_helpers::new_db; use ethereum_types::{H256, U256, Address}; - use evm::CallType; use kvdb::DBTransaction; use crate::{ BlockNumber, Config, TraceDB, Database as TraceDatabase, ImportRequest, DatabaseExtras, Filter, LocalizedTrace, AddressesFilter, TraceError, - trace::{Call, Action, Res}, + trace::{Call, CallType, Action, Res}, flat::{FlatTrace, FlatBlockTraces, FlatTransactionTraces} }; @@ -465,7 +464,7 @@ mod tests { value: 3.into(), gas: 4.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(CallType::Call), }), result: Res::FailedCall(TraceError::OutOfGas), }])]), @@ -487,7 +486,7 @@ mod tests { value: 3.into(), gas: 4.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(CallType::Call), }), result: Res::FailedCall(TraceError::OutOfGas), }])]), @@ -506,7 +505,7 @@ mod tests { value: U256::from(3), gas: U256::from(4), input: vec![], - call_type: CallType::Call, + call_type: Some(CallType::Call), }), result: Res::FailedCall(TraceError::OutOfGas), trace_address: vec![], diff --git a/ethcore/trace/src/types/filter.rs b/ethcore/trace/src/types/filter.rs index 936de0c40..b88c485e7 100644 --- a/ethcore/trace/src/types/filter.rs +++ b/ethcore/trace/src/types/filter.rs @@ -125,10 +125,9 @@ impl Filter { #[cfg(test)] mod tests { use ethereum_types::{Address, Bloom, BloomInput}; - use evm::CallType; use crate::{ Filter, AddressesFilter, TraceError, RewardType, - trace::{Action, Call, Res, Create, CreateResult, Suicide, Reward}, + trace::{Action, Call, CallType, Res, Create, CreationMethod, CreateResult, Suicide, Reward}, flat::FlatTrace, }; @@ -273,7 +272,7 @@ mod tests { value: 3.into(), gas: 4.into(), input: vec![0x5], - call_type: CallType::Call, + call_type: Some(CallType::Call), }), result: Res::FailedCall(TraceError::OutOfGas), trace_address: vec![0].into_iter().collect(), @@ -294,6 +293,7 @@ mod tests { value: 3.into(), gas: 4.into(), init: vec![0x5], + creation_method: Some(CreationMethod::Create), }), result: Res::Create(CreateResult { gas_used: 10.into(), @@ -413,6 +413,7 @@ mod tests { gas: 4.into(), init: vec![0x5], value: 3.into(), + creation_method: Some(CreationMethod::Create), }), result: Res::FailedCall(TraceError::BadInstruction), trace_address: vec![].into_iter().collect(), diff --git a/ethcore/trace/src/types/flat.rs b/ethcore/trace/src/types/flat.rs index 203eb7f5d..b937e85e7 100644 --- a/ethcore/trace/src/types/flat.rs +++ b/ethcore/trace/src/types/flat.rs @@ -123,9 +123,8 @@ mod tests { use rlp::*; use crate::{ FlatBlockTraces, FlatTransactionTraces, FlatTrace, - trace::{Action, Res, CallResult, Call, Suicide, Reward, RewardType} + trace::{Action, Res, CallResult, Call, CallType, Suicide, Reward, RewardType} }; - use evm::CallType; #[test] fn encode_flat_transaction_traces() { @@ -162,7 +161,7 @@ mod tests { value: "3627e8f712373c0000".parse().unwrap(), gas: 0x03e8.into(), input: vec![], - call_type: CallType::Call, + call_type: Some(CallType::Call), }), result: Res::Call(CallResult { gas_used: 0.into(), @@ -179,7 +178,7 @@ mod tests { value: 0.into(), gas: 0x010c78.into(), input: vec![0x41, 0xc0, 0xe1, 0xb5], - call_type: CallType::Call, + call_type: Some(CallType::Call), }), result: Res::Call(CallResult { gas_used: 0x0127.into(), diff --git a/ethcore/trace/src/types/trace.rs b/ethcore/trace/src/types/trace.rs index a0a920031..43a35ed94 100644 --- a/ethcore/trace/src/types/trace.rs +++ b/ethcore/trace/src/types/trace.rs @@ -16,12 +16,13 @@ //! Tracing data types. +use std::convert::TryFrom; use ethereum_types::{U256, Address, Bloom, BloomInput}; use parity_bytes::Bytes; use rlp::{Rlp, RlpStream, Encodable, DecoderError, Decodable}; use rlp_derive::{RlpEncodable, RlpDecodable}; use vm::ActionParams; -use evm::CallType; +use evm::ActionType; use super::error::Error; /// `Call` result. @@ -33,6 +34,57 @@ pub struct CallResult { pub output: Bytes, } +/// `Call` type. Distinguish between different types of contract interactions. +#[derive(Debug, Clone, PartialEq)] +pub enum CallType { + /// Call + Call, + /// Call code + CallCode, + /// Delegate call + DelegateCall, + /// Static call + StaticCall, +} + +impl TryFrom for CallType { + type Error = &'static str; + fn try_from(action_type: ActionType) -> Result { + match action_type { + ActionType::Call => Ok(CallType::Call), + ActionType::CallCode => Ok(CallType::CallCode), + ActionType::DelegateCall => Ok(CallType::DelegateCall), + ActionType::StaticCall => Ok(CallType::StaticCall), + ActionType::Create => Err("Create cannot be converted to CallType"), + ActionType::Create2 => Err("Create2 cannot be converted to CallType"), + } + } +} + +impl Encodable for CallType { + fn rlp_append(&self, s: &mut RlpStream) { + let v = match *self { + CallType::Call => 0u32, + CallType::CallCode => 1, + CallType::DelegateCall => 2, + CallType::StaticCall => 3, + }; + Encodable::rlp_append(&v, s); + } +} + +impl Decodable for CallType { + fn decode(rlp: &Rlp) -> Result { + rlp.as_val().and_then(|v| Ok(match v { + 0u32 => CallType::Call, + 1 => CallType::CallCode, + 2 => CallType::DelegateCall, + 3 => CallType::StaticCall, + _ => return Err(DecoderError::Custom("Invalid value of RewardType item")), + })) + } +} + /// `Create` result. #[derive(Debug, Clone, PartialEq, RlpEncodable, RlpDecodable)] pub struct CreateResult { @@ -51,6 +103,49 @@ impl CreateResult { } } +/// `Create` method. Distinguish between use of `CREATE` and `CREATE2` opcodes in an action. +#[derive(Debug, Clone, PartialEq)] +pub enum CreationMethod { + /// Create + Create, + /// Create2 + Create2, +} + +impl TryFrom for CreationMethod { + type Error = &'static str; + fn try_from(action_type: ActionType) -> Result { + match action_type { + ActionType::Call => Err("Call cannot be converted to CreationMethod"), + ActionType::CallCode => Err("CallCode cannot be converted to CreationMethod"), + ActionType::DelegateCall => Err("DelegateCall cannot be converted to CreationMethod"), + ActionType::StaticCall => Err("StaticCall cannot be converted to CreationMethod"), + ActionType::Create => Ok(CreationMethod::Create), + ActionType::Create2 => Ok(CreationMethod::Create2), + } + } +} + +impl Encodable for CreationMethod { + fn rlp_append(&self, s: &mut RlpStream) { + let v = match *self { + CreationMethod::Create => 0u32, + CreationMethod::Create2 => 1, + }; + Encodable::rlp_append(&v, s); + } +} + +impl Decodable for CreationMethod { + fn decode(rlp: &Rlp) -> Result { + rlp.as_val().and_then(|v| Ok(match v { + 0u32 => CreationMethod::Create, + 1 => CreationMethod::Create2, + _ => return Err(DecoderError::Custom("Invalid value of RewardType item")), + })) + } +} + /// Description of a _call_ action, either a `CALL` operation or a message transaction. #[derive(Debug, Clone, PartialEq, RlpEncodable, RlpDecodable)] pub struct Call { @@ -65,19 +160,19 @@ pub struct Call { /// The input data provided to the call. pub input: Bytes, /// The type of the call. - pub call_type: CallType, + pub call_type: Option, } impl From for Call { fn from(p: ActionParams) -> Self { - match p.call_type { - CallType::DelegateCall | CallType::CallCode => Call { + match p.action_type { + ActionType::DelegateCall | ActionType::CallCode => Call { from: p.address, to: p.code_address, value: p.value.value(), gas: p.gas, input: p.data.unwrap_or_else(Vec::new), - call_type: p.call_type, + call_type: CallType::try_from(p.action_type).ok(), }, _ => Call { from: p.sender, @@ -85,7 +180,7 @@ impl From for Call { value: p.value.value(), gas: p.gas, input: p.data.unwrap_or_else(Vec::new), - call_type: p.call_type, + call_type: CallType::try_from(p.action_type).ok(), }, } } @@ -113,6 +208,8 @@ pub struct Create { pub gas: U256, /// The init code. pub init: Bytes, + /// Creation method (CREATE vs CREATE2). + pub creation_method: Option, } impl From for Create { @@ -122,6 +219,7 @@ impl From for Create { value: p.value.value(), gas: p.gas, init: p.code.map_or_else(Vec::new, |c| (*c).clone()), + creation_method: CreationMethod::try_from(p.action_type).ok(), } } } diff --git a/ethcore/vm/src/action_params.rs b/ethcore/vm/src/action_params.rs index 6d0ca2a0f..11ab18572 100644 --- a/ethcore/vm/src/action_params.rs +++ b/ethcore/vm/src/action_params.rs @@ -20,7 +20,7 @@ use bytes::Bytes; use hash::{keccak, KECCAK_EMPTY}; use ethjson; -use call_type::CallType; +use action_type::ActionType; use std::sync::Arc; @@ -88,8 +88,8 @@ pub struct ActionParams { pub code_version: U256, /// Input data. pub data: Option, - /// Type of call - pub call_type: CallType, + /// Type of action (e.g. CALL, DELEGATECALL, CREATE, etc.) + pub action_type: ActionType, /// Param types encoding pub params_type: ParamsType, } @@ -109,7 +109,7 @@ impl Default for ActionParams { code: None, code_version: U256::zero(), data: None, - call_type: CallType::None, + action_type: ActionType::Create, params_type: ParamsType::Separate, } } @@ -130,7 +130,7 @@ impl From for ActionParams { gas: t.gas.into(), gas_price: t.gas_price.into(), value: ActionValue::Transfer(t.value.into()), - call_type: match address.is_zero() { true => CallType::None, false => CallType::Call }, // TODO @debris is this correct? + action_type: ActionType::Call, params_type: ParamsType::Separate, } } diff --git a/ethcore/vm/src/call_type.rs b/ethcore/vm/src/action_type.rs similarity index 66% rename from ethcore/vm/src/call_type.rs rename to ethcore/vm/src/action_type.rs index e5245c8c1..c436c8310 100644 --- a/ethcore/vm/src/call_type.rs +++ b/ethcore/vm/src/action_type.rs @@ -14,47 +14,51 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -//! EVM call types. +//! EVM action types. use rlp::{Encodable, Decodable, DecoderError, RlpStream, Rlp}; -/// The type of the call-like instruction. +/// The type of the instruction. #[derive(Debug, PartialEq, Clone)] -pub enum CallType { - /// Not a CALL. - None, +pub enum ActionType { + /// CREATE. + Create, /// CALL. Call, /// CALLCODE. CallCode, /// DELEGATECALL. DelegateCall, - /// STATICCALL + /// STATICCALL. StaticCall, + /// CREATE2. + Create2 } -impl Encodable for CallType { +impl Encodable for ActionType { fn rlp_append(&self, s: &mut RlpStream) { let v = match *self { - CallType::None => 0u32, - CallType::Call => 1, - CallType::CallCode => 2, - CallType::DelegateCall => 3, - CallType::StaticCall => 4, + ActionType::Create => 0u32, + ActionType::Call => 1, + ActionType::CallCode => 2, + ActionType::DelegateCall => 3, + ActionType::StaticCall => 4, + ActionType::Create2 => 5, }; Encodable::rlp_append(&v, s); } } -impl Decodable for CallType { +impl Decodable for ActionType { fn decode(rlp: &Rlp) -> Result { rlp.as_val().and_then(|v| Ok(match v { - 0u32 => CallType::None, - 1 => CallType::Call, - 2 => CallType::CallCode, - 3 => CallType::DelegateCall, - 4 => CallType::StaticCall, - _ => return Err(DecoderError::Custom("Invalid value of CallType item")), + 0u32 => ActionType::Create, + 1 => ActionType::Call, + 2 => ActionType::CallCode, + 3 => ActionType::DelegateCall, + 4 => ActionType::StaticCall, + 5 => ActionType::Create2, + _ => return Err(DecoderError::Custom("Invalid value of ActionType item")), })) } } @@ -62,11 +66,11 @@ impl Decodable for CallType { #[cfg(test)] mod tests { use rlp::*; - use super::CallType; + use super::ActionType; #[test] fn encode_call_type() { - let ct = CallType::Call; + let ct = ActionType::Call; let mut s = RlpStream::new_list(2); s.append(&ct); @@ -78,9 +82,9 @@ mod tests { #[test] fn should_encode_and_decode_call_type() { - let original = CallType::Call; + let original = ActionType::Call; let encoded = encode(&original); - let decoded = decode(&encoded).expect("failure decoding CallType"); + let decoded = decode(&encoded).expect("failure decoding ActionType"); assert_eq!(original, decoded); } } diff --git a/ethcore/vm/src/ext.rs b/ethcore/vm/src/ext.rs index bb153acff..828051968 100644 --- a/ethcore/vm/src/ext.rs +++ b/ethcore/vm/src/ext.rs @@ -19,7 +19,7 @@ use std::sync::Arc; use ethereum_types::{U256, H256, Address}; use bytes::Bytes; -use call_type::CallType; +use action_type::ActionType; use env_info::EnvInfo; use schedule::Schedule; use return_data::ReturnData; @@ -115,7 +115,7 @@ pub trait Ext { value: Option, data: &[u8], code_address: &Address, - call_type: CallType, + call_type: ActionType, trap: bool ) -> ::std::result::Result; diff --git a/ethcore/vm/src/lib.rs b/ethcore/vm/src/lib.rs index d2e436704..07cd5cd82 100644 --- a/ethcore/vm/src/lib.rs +++ b/ethcore/vm/src/lib.rs @@ -24,7 +24,7 @@ extern crate keccak_hash as hash; extern crate patricia_trie_ethereum as ethtrie; mod action_params; -mod call_type; +mod action_type; mod env_info; mod schedule; mod ext; @@ -34,7 +34,7 @@ mod error; pub mod tests; pub use action_params::{ActionParams, ActionValue, ParamsType}; -pub use call_type::CallType; +pub use action_type::ActionType; pub use env_info::{EnvInfo, LastHashes}; pub use schedule::{Schedule, VersionedSchedule, CleanDustMode, WasmCosts}; pub use ext::{Ext, MessageCallResult, ContractCreateResult, CreateContractAddress}; diff --git a/ethcore/vm/src/tests.rs b/ethcore/vm/src/tests.rs index 40ae0dac4..623cea396 100644 --- a/ethcore/vm/src/tests.rs +++ b/ethcore/vm/src/tests.rs @@ -20,7 +20,7 @@ use std::collections::{HashMap, HashSet}; use ethereum_types::{U256, H256, Address}; use bytes::Bytes; use { - CallType, Schedule, EnvInfo, + ActionType, Schedule, EnvInfo, ReturnData, Ext, ContractCreateResult, MessageCallResult, CreateContractAddress, Result, GasLeft, }; @@ -185,7 +185,7 @@ impl Ext for FakeExt { value: Option, data: &[u8], code_address: &Address, - _call_type: CallType, + _call_type: ActionType, _trap: bool, ) -> ::std::result::Result { self.calls.insert(FakeCall { diff --git a/ethcore/wasm/src/runtime.rs b/ethcore/wasm/src/runtime.rs index 34030d308..ef85dee62 100644 --- a/ethcore/wasm/src/runtime.rs +++ b/ethcore/wasm/src/runtime.rs @@ -16,7 +16,7 @@ use std::cmp; use ethereum_types::{BigEndianHash, U256, H256, Address}; -use vm::{self, CallType}; +use vm::{self, ActionType}; use wasmi::{self, MemoryRef, RuntimeArgs, RuntimeValue, Error as InterpreterError, Trap, TrapKind}; use super::panic_payload; @@ -384,7 +384,7 @@ impl<'a> Runtime<'a> { fn do_call( &mut self, use_val: bool, - call_type: CallType, + call_type: ActionType, args: RuntimeArgs, ) -> Result @@ -445,8 +445,8 @@ impl<'a> Runtime<'a> { let call_result = self.ext.call( &gas.into(), - match call_type { CallType::DelegateCall => &self.context.sender, _ => &self.context.address }, - match call_type { CallType::Call | CallType::StaticCall => &address, _ => &self.context.address }, + match call_type { ActionType::DelegateCall => &self.context.sender, _ => &self.context.address }, + match call_type { ActionType::Call | ActionType::StaticCall => &address, _ => &self.context.address }, val, &payload, &address, @@ -487,17 +487,17 @@ impl<'a> Runtime<'a> { /// Message call fn ccall(&mut self, args: RuntimeArgs) -> Result { - self.do_call(true, CallType::Call, args) + self.do_call(true, ActionType::Call, args) } /// Delegate call fn dcall(&mut self, args: RuntimeArgs) -> Result { - self.do_call(false, CallType::DelegateCall, args) + self.do_call(false, ActionType::DelegateCall, args) } /// Static call fn scall(&mut self, args: RuntimeArgs) -> Result { - self.do_call(false, CallType::StaticCall, args) + self.do_call(false, ActionType::StaticCall, args) } fn return_address_ptr(&mut self, ptr: u32, val: Address) -> Result<()> diff --git a/evmbin/src/main.rs b/evmbin/src/main.rs index 3f1591124..6df86d206 100644 --- a/evmbin/src/main.rs +++ b/evmbin/src/main.rs @@ -45,7 +45,7 @@ use ethereum_types::{U256, Address}; use ethcore::{json_tests, test_helpers::TrieSpec}; use spec; use serde::Deserialize; -use vm::{ActionParams, CallType}; +use vm::{ActionParams, ActionType}; mod info; mod display; @@ -314,7 +314,7 @@ fn run_call(args: Args, informant: T) { } let mut params = ActionParams::default(); - params.call_type = if code.is_none() { CallType::Call } else { CallType::None }; + params.action_type = if code.is_none() { ActionType::Call } else { ActionType::Create }; params.code = code.map(Arc::new); params.code_address = to; params.address = to; diff --git a/rpc/src/v1/tests/mocked/traces.rs b/rpc/src/v1/tests/mocked/traces.rs index 7dffdd8fb..89c565795 100644 --- a/rpc/src/v1/tests/mocked/traces.rs +++ b/rpc/src/v1/tests/mocked/traces.rs @@ -23,7 +23,7 @@ use ethcore::test_helpers::TestBlockChainClient; use ethereum_types::{Address, H256}; use types::transaction::CallError; -use vm::CallType; +use trace::trace::CallType; use jsonrpc_core::IoHandler; use v1::tests::helpers::{TestMinerService}; @@ -44,7 +44,7 @@ fn io() -> Tester { value: 0x1.into(), gas: 0x100.into(), input: vec![1, 2, 3], - call_type: CallType::Call, + call_type: Some(CallType::Call), }), result: Res::None, subtraces: 0, diff --git a/rpc/src/v1/types/trace.rs b/rpc/src/v1/types/trace.rs index 519e85714..c7ae92ad4 100644 --- a/rpc/src/v1/types/trace.rs +++ b/rpc/src/v1/types/trace.rs @@ -24,7 +24,6 @@ use serde::ser::SerializeStruct; use serde::{Serialize, Serializer}; use types::account_diff; use types::state_diff; -use vm; use v1::types::Bytes; @@ -214,6 +213,7 @@ impl From for StateDiff { /// Create response #[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] pub struct Create { /// Sender from: H160, @@ -223,6 +223,9 @@ pub struct Create { gas: U256, /// Initialization code init: Bytes, + // Create Type + #[serde(skip_serializing_if="Option::is_none")] + creation_method: Option, } impl From for Create { @@ -232,6 +235,7 @@ impl From for Create { value: c.value, gas: c.gas, init: Bytes::new(c.init), + creation_method: c.creation_method.map(|c| c.into()), } } } @@ -240,8 +244,6 @@ impl From for Create { #[derive(Debug, Serialize)] #[serde(rename_all = "lowercase")] pub enum CallType { - /// None - None, /// Call Call, /// Call code @@ -252,14 +254,32 @@ pub enum CallType { StaticCall, } -impl From for CallType { - fn from(c: vm::CallType) -> Self { +impl From for CallType { + fn from(c: trace::CallType) -> Self { match c { - vm::CallType::None => CallType::None, - vm::CallType::Call => CallType::Call, - vm::CallType::CallCode => CallType::CallCode, - vm::CallType::DelegateCall => CallType::DelegateCall, - vm::CallType::StaticCall => CallType::StaticCall, + trace::CallType::Call => CallType::Call, + trace::CallType::CallCode => CallType::CallCode, + trace::CallType::DelegateCall => CallType::DelegateCall, + trace::CallType::StaticCall => CallType::StaticCall, + } + } +} + +/// Create type. +#[derive(Debug, Serialize)] +#[serde(rename_all = "lowercase")] +pub enum CreationMethod { + /// Create + Create, + /// Create2 + Create2, +} + +impl From for CreationMethod { + fn from(c: trace::CreationMethod) -> Self { + match c { + trace::CreationMethod::Create => CreationMethod::Create, + trace::CreationMethod::Create2 => CreationMethod::Create2, } } } @@ -279,7 +299,7 @@ pub struct Call { /// Input data input: Bytes, /// The type of the call. - call_type: CallType, + call_type: Option, } impl From for Call { @@ -290,7 +310,7 @@ impl From for Call { value: c.value, gas: c.gas, input: c.input.into(), - call_type: c.call_type.into(), + call_type: c.call_type.map(|c| c.into()), } } } @@ -681,7 +701,7 @@ mod tests { value: 6.into(), gas: 7.into(), input: Bytes::new(vec![0x12, 0x34]), - call_type: CallType::Call, + call_type: Some(CallType::Call), }), result: Res::Call(CallResult { gas_used: 8.into(), @@ -707,7 +727,7 @@ mod tests { value: 6.into(), gas: 7.into(), input: Bytes::new(vec![0x12, 0x34]), - call_type: CallType::Call, + call_type: Some(CallType::Call), }), result: Res::FailedCall(TraceError::OutOfGas), trace_address: vec![10], @@ -729,6 +749,7 @@ mod tests { value: 6.into(), gas: 7.into(), init: Bytes::new(vec![0x12, 0x34]), + creation_method: Some(CreationMethod::Create), }), result: Res::Create(CreateResult { gas_used: 8.into(), @@ -743,7 +764,7 @@ mod tests { block_hash: H256::from_low_u64_be(14), }; let serialized = serde_json::to_string(&t).unwrap(); - assert_eq!(serialized, r#"{"type":"create","action":{"from":"0x0000000000000000000000000000000000000004","value":"0x6","gas":"0x7","init":"0x1234"},"result":{"gasUsed":"0x8","code":"0x5678","address":"0x00000000000000000000000000000000000000ff"},"traceAddress":[10],"subtraces":1,"transactionPosition":11,"transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#); + assert_eq!(serialized, r#"{"type":"create","action":{"from":"0x0000000000000000000000000000000000000004","value":"0x6","gas":"0x7","init":"0x1234","creationMethod":"create"},"result":{"gasUsed":"0x8","code":"0x5678","address":"0x00000000000000000000000000000000000000ff"},"traceAddress":[10],"subtraces":1,"transactionPosition":11,"transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#); } #[test] @@ -754,6 +775,7 @@ mod tests { value: 6.into(), gas: 7.into(), init: Bytes::new(vec![0x12, 0x34]), + creation_method: Some(CreationMethod::Create), }), result: Res::FailedCreate(TraceError::OutOfGas), trace_address: vec![10], @@ -764,7 +786,7 @@ mod tests { block_hash: H256::from_low_u64_be(14), }; let serialized = serde_json::to_string(&t).unwrap(); - assert_eq!(serialized, r#"{"type":"create","action":{"from":"0x0000000000000000000000000000000000000004","value":"0x6","gas":"0x7","init":"0x1234"},"error":"Out of gas","traceAddress":[10],"subtraces":1,"transactionPosition":11,"transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#); + assert_eq!(serialized, r#"{"type":"create","action":{"from":"0x0000000000000000000000000000000000000004","value":"0x6","gas":"0x7","init":"0x1234","creationMethod":"create"},"error":"Out of gas","traceAddress":[10],"subtraces":1,"transactionPosition":11,"transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#); } #[test]