Merge pull request #777 from ethcore/call

added output to execution result
This commit is contained in:
Marek Kotewicz 2016-03-20 10:28:28 +01:00
commit 6feb503c67

View File

@ -41,21 +41,21 @@ pub fn contract_address(address: &Address, nonce: &U256) -> Address {
pub struct Executed { pub struct Executed {
/// Gas paid up front for execution of transaction. /// Gas paid up front for execution of transaction.
pub gas: U256, pub gas: U256,
/// Gas used during execution of transaction. /// Gas used during execution of transaction.
pub gas_used: U256, pub gas_used: U256,
/// Gas refunded after the execution of transaction. /// Gas refunded after the execution of transaction.
/// To get gas that was required up front, add `refunded` and `gas_used`. /// To get gas that was required up front, add `refunded` and `gas_used`.
pub refunded: U256, pub refunded: U256,
/// Cumulative gas used in current block so far. /// Cumulative gas used in current block so far.
/// ///
/// `cumulative_gas_used = gas_used(t0) + gas_used(t1) + ... gas_used(tn)` /// `cumulative_gas_used = gas_used(t0) + gas_used(t1) + ... gas_used(tn)`
/// ///
/// where `tn` is current transaction. /// where `tn` is current transaction.
pub cumulative_gas_used: U256, pub cumulative_gas_used: U256,
/// Vector of logs generated by transaction. /// Vector of logs generated by transaction.
pub logs: Vec<LogEntry>, pub logs: Vec<LogEntry>,
@ -66,7 +66,8 @@ pub struct Executed {
/// ///
/// B creation ends first, and it will be the first element of the vector. /// B creation ends first, and it will be the first element of the vector.
pub contracts_created: Vec<Address>, pub contracts_created: Vec<Address>,
/// Transaction output.
pub output: Bytes,
/// The trace of this transaction. /// The trace of this transaction.
pub trace: Option<Trace>, pub trace: Option<Trace>,
} }
@ -152,7 +153,7 @@ impl<'a> Executive<'a> {
let mut substate = Substate::new(tracing); let mut substate = Substate::new(tracing);
let res = match t.action { let (gas_left, output) = match t.action {
Action::Create => { Action::Create => {
let new_address = contract_address(&sender, &nonce); let new_address = contract_address(&sender, &nonce);
let params = ActionParams { let params = ActionParams {
@ -166,7 +167,7 @@ impl<'a> Executive<'a> {
code: Some(t.data.clone()), code: Some(t.data.clone()),
data: None, data: None,
}; };
self.create(params, &mut substate) (self.create(params, &mut substate), vec![])
}, },
Action::Call(ref address) => { Action::Call(ref address) => {
let params = ActionParams { let params = ActionParams {
@ -182,12 +183,12 @@ impl<'a> Executive<'a> {
}; };
// TODO: move output upstream // TODO: move output upstream
let mut out = vec![]; let mut out = vec![];
self.call(params, &mut substate, BytesRef::Flexible(&mut out)) (self.call(params, &mut substate, BytesRef::Flexible(&mut out)), out)
} }
}; };
// finalize here! // finalize here!
Ok(try!(self.finalize(t, substate, res))) Ok(try!(self.finalize(t, substate, gas_left, output)))
} }
fn exec_vm(&mut self, params: ActionParams, unconfirmed_substate: &mut Substate, output_policy: OutputPolicy) -> evm::Result { fn exec_vm(&mut self, params: ActionParams, unconfirmed_substate: &mut Substate, output_policy: OutputPolicy) -> evm::Result {
@ -258,9 +259,9 @@ impl<'a> Executive<'a> {
self.exec_vm(params, &mut unconfirmed_substate, OutputPolicy::Return(output, trace_output.as_mut())) self.exec_vm(params, &mut unconfirmed_substate, OutputPolicy::Return(output, trace_output.as_mut()))
}; };
// if there's tracing, make up trace_info's result with trace_output and some arithmetic. // if there's tracing, make up trace_info's result with trace_output and some arithmetic.
if let Some((TraceAction::Call(ref mut c), _)) = trace_info { if let Some((TraceAction::Call(ref mut c), _)) = trace_info {
if let Some(output) = trace_output { if let Some(output) = trace_output {
c.result = res.as_ref().ok().map(|gas_left| (c.gas - *gas_left, output)); c.result = res.as_ref().ok().map(|gas_left| (c.gas - *gas_left, output));
} }
} }
@ -306,7 +307,7 @@ impl<'a> Executive<'a> {
}; };
if let Some((TraceAction::Create(ref mut c), _)) = trace_info { if let Some((TraceAction::Create(ref mut c), _)) = trace_info {
if let Some(output) = trace_output { if let Some(output) = trace_output {
c.result = res.as_ref().ok().map(|gas_left| (c.gas - *gas_left, created, output)); c.result = res.as_ref().ok().map(|gas_left| (c.gas - *gas_left, created, output));
} }
} }
@ -316,7 +317,7 @@ impl<'a> Executive<'a> {
} }
/// Finalizes the transaction (does refunds and suicides). /// Finalizes the transaction (does refunds and suicides).
fn finalize(&mut self, t: &SignedTransaction, substate: Substate, result: evm::Result) -> ExecutionResult { fn finalize(&mut self, t: &SignedTransaction, substate: Substate, result: evm::Result, output: Bytes) -> ExecutionResult {
let schedule = self.engine.schedule(self.info); let schedule = self.engine.schedule(self.info);
// refunds from SSTORE nonzero -> zero // refunds from SSTORE nonzero -> zero
@ -357,6 +358,7 @@ impl<'a> Executive<'a> {
cumulative_gas_used: self.info.gas_used + t.gas, cumulative_gas_used: self.info.gas_used + t.gas,
logs: vec![], logs: vec![],
contracts_created: vec![], contracts_created: vec![],
output: output,
trace: None, trace: None,
}) })
}, },
@ -368,6 +370,7 @@ impl<'a> Executive<'a> {
cumulative_gas_used: self.info.gas_used + gas_used, cumulative_gas_used: self.info.gas_used + gas_used,
logs: substate.logs, logs: substate.logs,
contracts_created: substate.contracts_created, contracts_created: substate.contracts_created,
output: output,
trace: substate.subtraces.and_then(|mut v| v.pop()), trace: substate.subtraces.and_then(|mut v| v.pop()),
}) })
}, },