Skip to content

Commit 6520d9e

Browse files
committed
feat: add callframe utils
1 parent a108862 commit 6520d9e

File tree

1 file changed

+33
-1
lines changed
  • crates/rpc-types-trace/src/geth

1 file changed

+33
-1
lines changed

crates/rpc-types-trace/src/geth/call.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Geth call tracer types.
22
33
use crate::parity::LocalizedTransactionTrace;
4-
use alloy_primitives::{Address, Bytes, B256, U256};
4+
use alloy_primitives::{Address, Bytes, Selector, B256, U256};
55
use serde::{Deserialize, Serialize};
66

77
/// The response object for `debug_traceTransaction` with `"tracer": "callTracer"`.
@@ -45,6 +45,21 @@ pub struct CallFrame {
4545
pub typ: String,
4646
}
4747

48+
impl CallFrame {
49+
/// Error selector is the first 4 bytes of calldata
50+
pub fn selector(&self) -> Option<Selector> {
51+
if self.input.len() < 4 {
52+
return None;
53+
}
54+
Some(Selector::from_slice(&self.input[..4]))
55+
}
56+
57+
/// Returns true if this call reverted.
58+
pub const fn is_revert(&self) -> bool {
59+
self.revert_reason.is_some()
60+
}
61+
}
62+
4863
/// Represents a recorded log that is emitted during a trace call.
4964
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
5065
pub struct CallLogFrame {
@@ -62,6 +77,23 @@ pub struct CallLogFrame {
6277
pub position: Option<u64>,
6378
}
6479

80+
impl CallLogFrame {
81+
/// Converts this log frame into a primitives log object
82+
pub fn into_log(self) -> alloy_primitives::Log {
83+
alloy_primitives::Log::new_unchecked(
84+
self.address.unwrap_or_default(),
85+
self.topics.unwrap_or_default(),
86+
self.data.unwrap_or_default(),
87+
)
88+
}
89+
}
90+
91+
impl From<CallLogFrame> for alloy_primitives::Log {
92+
fn from(value: CallLogFrame) -> Self {
93+
value.into_log()
94+
}
95+
}
96+
6597
/// The configuration for the call tracer.
6698
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
6799
#[serde(rename_all = "camelCase")]

0 commit comments

Comments
 (0)