2016-03-19 12:54:34 +01:00
|
|
|
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
//! Tracing datatypes.
|
|
|
|
use common::*;
|
|
|
|
|
2016-04-06 21:23:52 +02:00
|
|
|
/// TraceCall result.
|
|
|
|
#[derive(Debug, Clone, PartialEq, Default)]
|
|
|
|
pub struct TraceCallResult {
|
|
|
|
/// Gas used by call.
|
|
|
|
pub gas_used: U256,
|
|
|
|
/// Call Output.
|
|
|
|
pub output: Bytes,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// TraceCreate result.
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
|
|
pub struct TraceCreateResult {
|
|
|
|
/// Gas used by create.
|
|
|
|
pub gas_used: U256,
|
|
|
|
/// Code of the newly created contract.
|
|
|
|
pub code: Bytes,
|
|
|
|
/// Address of the newly created contract.
|
|
|
|
pub address: Address,
|
|
|
|
}
|
|
|
|
|
2016-03-19 12:54:34 +01:00
|
|
|
/// Description of a _call_ action, either a `CALL` operation or a message transction.
|
2016-03-19 21:02:44 +01:00
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
2016-03-19 12:54:34 +01:00
|
|
|
pub struct TraceCall {
|
|
|
|
/// The sending account.
|
|
|
|
pub from: Address,
|
|
|
|
/// The destination account.
|
|
|
|
pub to: Address,
|
|
|
|
/// The value transferred to the destination account.
|
|
|
|
pub value: U256,
|
|
|
|
/// The gas available for executing the call.
|
|
|
|
pub gas: U256,
|
|
|
|
/// The input data provided to the call.
|
|
|
|
pub input: Bytes,
|
|
|
|
/// The result of the operation; the gas used and the output data of the call.
|
2016-04-06 21:23:52 +02:00
|
|
|
pub result: Option<TraceCallResult>,
|
2016-03-19 12:54:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Description of a _create_ action, either a `CREATE` operation or a create transction.
|
2016-03-19 21:02:44 +01:00
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
2016-03-19 12:54:34 +01:00
|
|
|
pub struct TraceCreate {
|
|
|
|
/// The address of the creator.
|
|
|
|
pub from: Address,
|
|
|
|
/// The value with which the new account is endowed.
|
|
|
|
pub value: U256,
|
|
|
|
/// The gas available for the creation init code.
|
|
|
|
pub gas: U256,
|
|
|
|
/// The init code.
|
|
|
|
pub init: Bytes,
|
|
|
|
/// The result of the operation; tuple of the gas used, the address of the newly created account and its code.
|
|
|
|
/// NOTE: Presently failed operations are not reported so this will always be `Some`.
|
2016-04-06 21:23:52 +02:00
|
|
|
pub result: Option<TraceCreateResult>,
|
2016-03-19 12:54:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Description of an action that we trace; will be either a call or a create.
|
2016-03-19 21:02:44 +01:00
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
2016-03-19 12:54:34 +01:00
|
|
|
pub enum TraceAction {
|
|
|
|
/// It's a call action.
|
|
|
|
Call(TraceCall),
|
|
|
|
/// It's a create action.
|
|
|
|
Create(TraceCreate),
|
|
|
|
}
|
|
|
|
|
2016-03-19 21:02:44 +01:00
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
2016-03-19 12:54:34 +01:00
|
|
|
/// A trace; includes a description of the action being traced and sub traces of each interior action.
|
|
|
|
pub struct Trace {
|
2016-03-19 14:35:09 +01:00
|
|
|
/// The number of EVM execution environments active when this action happened; 0 if it's
|
|
|
|
/// the outer action of the transaction.
|
|
|
|
pub depth: usize,
|
2016-03-19 12:54:34 +01:00
|
|
|
/// The action being performed.
|
|
|
|
pub action: TraceAction,
|
|
|
|
/// The sub traces for each interior action performed as part of this call.
|
|
|
|
pub subs: Vec<Trace>,
|
|
|
|
}
|
|
|
|
|
2016-03-19 22:37:11 +01:00
|
|
|
impl TraceAction {
|
|
|
|
/// Compose a `TraceAction` from an `ActionParams`, knowing that the action is a call.
|
|
|
|
pub fn from_call(p: &ActionParams) -> TraceAction {
|
|
|
|
TraceAction::Call(TraceCall {
|
|
|
|
from: p.sender.clone(),
|
|
|
|
to: p.address.clone(),
|
2016-04-01 03:08:42 +02:00
|
|
|
value: p.value.value(),
|
|
|
|
gas: p.gas,
|
|
|
|
input: p.data.clone().unwrap_or_else(Vec::new),
|
2016-03-19 22:37:11 +01:00
|
|
|
result: None,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Compose a `TraceAction` from an `ActionParams`, knowing that the action is a create.
|
|
|
|
pub fn from_create(p: &ActionParams) -> TraceAction {
|
|
|
|
TraceAction::Create(TraceCreate {
|
|
|
|
from: p.sender.clone(),
|
2016-04-01 03:08:42 +02:00
|
|
|
value: p.value.value(),
|
|
|
|
gas: p.gas,
|
|
|
|
init: p.code.clone().unwrap_or_else(Vec::new),
|
2016-03-19 22:37:11 +01:00
|
|
|
result: None,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|