Skip to content

Commit

Permalink
Edited to make changes to RPC types only
Browse files Browse the repository at this point in the history
To make a transactions hash trace with "trace_replayBlockTransactions" add "transactionHash" to parameters
  • Loading branch information
shamardy committed Jun 13, 2018
1 parent 9d082be commit 291b4a0
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 5 deletions.
13 changes: 9 additions & 4 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,7 @@ impl Client {
env_info: &EnvInfo,
machine: &::machine::EthereumMachine,
state_diff: bool,
hash_trace: bool,
transaction: &SignedTransaction,
options: TransactOptions<T, V>,
) -> Result<Executed<T::Output, V::Output>, CallError> where
Expand All @@ -1240,6 +1241,8 @@ impl Client {

let mut ret = Executive::new(state, env_info, machine).transact_virtual(transaction, options)?;

ret.transaction_hash = if hash_trace { Some(transaction.hash()) } else { None };

let transaction_hash = transaction.transaction_hash();

if let Some(original) = original_state {
Expand All @@ -1250,11 +1253,13 @@ impl Client {

let state_diff = analytics.state_diffing;

let hash_trace = analytics.hash_tracing;

match (analytics.transaction_tracing, analytics.vm_tracing) {
(true, true) => call(state, env_info, machine, state_diff, t, TransactOptions::with_tracing_and_vm_tracing()),
(true, false) => call(state, env_info, machine, state_diff, t, TransactOptions::with_tracing()),
(false, true) => call(state, env_info, machine, state_diff, t, TransactOptions::with_vm_tracing()),
(false, false) => call(state, env_info, machine, state_diff, t, TransactOptions::with_no_tracing()),
(true, true) => call(state, env_info, machine, state_diff, hash_trace, t, TransactOptions::with_tracing_and_vm_tracing()),
(true, false) => call(state, env_info, machine, state_diff, hash_trace, t, TransactOptions::with_tracing()),
(false, true) => call(state, env_info, machine, state_diff, hash_trace, t, TransactOptions::with_vm_tracing()),
(false, false) => call(state, env_info, machine, state_diff, hash_trace, t, TransactOptions::with_no_tracing()),
}
}

Expand Down
4 changes: 3 additions & 1 deletion ethcore/src/executed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! Transaction execution format module.
use ethereum_types::{U256, U512, Address};
use ethereum_types::{U256, U512, Address, H256};
use bytes::Bytes;
use trie;
use vm;
Expand Down Expand Up @@ -67,6 +67,8 @@ pub struct Executed<T = FlatTrace, V = VMTrace> {
pub vm_trace: Option<V>,
/// The state diff, if we traced it.
pub state_diff: Option<StateDiff>,
/// The transaction hash, if we traced it.
pub transaction_hash: Option<H256>,
}

/// Result of executing the transaction.
Expand Down
2 changes: 2 additions & 0 deletions ethcore/src/executive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> {
trace: trace,
vm_trace: vm_trace,
state_diff: None,
transaction_hash: None,
})
},
Ok(r) => {
Expand All @@ -673,6 +674,7 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> {
trace: trace,
vm_trace: vm_trace,
state_diff: None,
transaction_hash: None,
})
},
}
Expand Down
5 changes: 5 additions & 0 deletions ethcore/transaction/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,11 @@ impl SignedTransaction {
self.transaction.is_unsigned()
}

/// Returns Transaction Hash
pub fn hash(&self) -> H256 {
self.transaction.hash()
}

/// Deconstructs this transaction back into `UnverifiedTransaction`
pub fn deconstruct(self) -> (UnverifiedTransaction, Address, Option<Public>) {
(self.transaction, self.sender, self.public)
Expand Down
2 changes: 2 additions & 0 deletions ethcore/types/src/call_analytics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ pub struct CallAnalytics {
pub vm_tracing: bool,
/// Make a diff.
pub state_diffing: bool,
/// Make a transaction hash trace.
pub hash_tracing: bool,
}
1 change: 1 addition & 0 deletions rpc/src/v1/impls/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn to_call_analytics(flags: TraceOptions) -> CallAnalytics {
transaction_tracing: flags.contains(&("trace".to_owned())),
vm_tracing: flags.contains(&("vmTrace".to_owned())),
state_diffing: flags.contains(&("stateDiff".to_owned())),
hash_tracing: flags.contains(&("transactionHash".to_owned())),
}
}

Expand Down
4 changes: 4 additions & 0 deletions rpc/src/v1/types/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,9 @@ pub struct TraceResults {
/// The transaction trace.
#[serde(rename="stateDiff")]
pub state_diff: Option<StateDiff>,
/// The transaction trace.
#[serde(rename="transactionHash")]
pub transaction_hash: Option<H256>,
}

impl From<Executed> for TraceResults {
Expand All @@ -626,6 +629,7 @@ impl From<Executed> for TraceResults {
trace: t.trace.into_iter().map(Into::into).collect(),
vm_trace: t.vm_trace.map(Into::into),
state_diff: t.state_diff.map(Into::into),
transaction_hash: t.transaction_hash.map(Into::into),
}
}
}
Expand Down

0 comments on commit 291b4a0

Please sign in to comment.