Skip to content

Commit

Permalink
feat(trace/parity): add trace creation method (#237)
Browse files Browse the repository at this point in the history
waiting for alloy-rs/alloy#1621

---------

Signed-off-by: jsvisa <delweng@gmail.com>
  • Loading branch information
jsvisa authored Nov 6, 2024
1 parent c4e6bb1 commit ebf965e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/tracing/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use alloy_rpc_types_trace::{
geth::{CallFrame, CallLogFrame, GethDefaultTracingOptions, StructLog},
parity::{
Action, ActionType, CallAction, CallOutput, CallType, CreateAction, CreateOutput,
SelfdestructAction, TraceOutput, TransactionTrace,
CreationMethod, SelfdestructAction, TraceOutput, TransactionTrace,
},
};
use revm::interpreter::{opcode, CallScheme, CreateScheme, InstructionResult, OpCode};
Expand Down Expand Up @@ -397,6 +397,7 @@ impl CallTraceNode {
value: self.trace.value,
gas: self.trace.gas_limit,
init: self.trace.data.clone(),
creation_method: self.kind().into(),
})
}
}
Expand Down Expand Up @@ -522,6 +523,17 @@ impl CallKind {
}
}

impl From<CallKind> for CreationMethod {
fn from(kind: CallKind) -> CreationMethod {
match kind {
CallKind::Create => CreationMethod::Create,
CallKind::Create2 => CreationMethod::Create2,
CallKind::EOFCreate => CreationMethod::EofCreate,
_ => CreationMethod::None,
}
}
}

impl std::fmt::Display for CallKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.to_str())
Expand Down
5 changes: 4 additions & 1 deletion tests/it/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
use crate::utils::{inspect, print_traces, TestEvm};
use alloy_primitives::{address, hex, map::HashSet, Address, U256};
use alloy_rpc_types_eth::TransactionInfo;
use alloy_rpc_types_trace::parity::{Action, CallAction, CallType, SelfdestructAction, TraceType};
use alloy_rpc_types_trace::parity::{
Action, CallAction, CallType, CreationMethod, SelfdestructAction, TraceType,
};
use revm::{
db::{CacheDB, EmptyDB},
primitives::{
Expand Down Expand Up @@ -132,6 +134,7 @@ fn test_parity_constructor_selfdestruct() {

assert_eq!(traces.len(), 3);
assert!(traces[1].trace.action.is_create());
assert_eq!(traces[1].trace.action.as_create().unwrap().creation_method, CreationMethod::Create);
assert_eq!(traces[1].trace.trace_address, vec![0]);
assert_eq!(traces[1].trace.subtraces, 1);
assert!(traces[2].trace.action.is_selfdestruct());
Expand Down

0 comments on commit ebf965e

Please sign in to comment.