Skip to content

Commit

Permalink
feat(rpc/ots): implement ots_traceTransaction RPC (#9246)
Browse files Browse the repository at this point in the history
Signed-off-by: jsvisa <[email protected]>
  • Loading branch information
jsvisa authored Jul 9, 2024
1 parent 38f4c61 commit 67478b7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion crates/rpc/rpc-api/src/otterscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub trait Otterscan {
/// Extract all variations of calls, contract creation and self-destructs and returns a call
/// tree.
#[method(name = "traceTransaction")]
async fn trace_transaction(&self, tx_hash: TxHash) -> RpcResult<TraceEntry>;
async fn trace_transaction(&self, tx_hash: TxHash) -> RpcResult<Option<Vec<TraceEntry>>>;

/// Tailor-made and expanded version of eth_getBlockByNumber for block details page in
/// Otterscan.
Expand Down
4 changes: 1 addition & 3 deletions crates/rpc/rpc-builder/tests/it/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,7 @@ where

OtterscanClient::get_transaction_error(client, tx_hash).await.unwrap();

assert!(is_unimplemented(
OtterscanClient::trace_transaction(client, tx_hash).await.err().unwrap()
));
OtterscanClient::trace_transaction(client, tx_hash).await.unwrap();

OtterscanClient::get_block_details(client, block_number).await.unwrap();

Expand Down
32 changes: 29 additions & 3 deletions crates/rpc/rpc/src/otterscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use reth_rpc_types::{
BlockTransactions, Header, Transaction,
};
use revm_inspectors::{
tracing::TracingInspectorConfig,
tracing::{types::CallTraceNode, TracingInspectorConfig},
transfer::{TransferInspector, TransferKind},
};
use revm_primitives::ExecutionResult;
Expand Down Expand Up @@ -101,8 +101,34 @@ where
}

/// Handler for `ots_traceTransaction`
async fn trace_transaction(&self, _tx_hash: TxHash) -> RpcResult<TraceEntry> {
Err(internal_rpc_err("unimplemented"))
async fn trace_transaction(&self, tx_hash: TxHash) -> RpcResult<Option<Vec<TraceEntry>>> {
let traces = self
.eth
.spawn_trace_transaction_in_block(
tx_hash,
TracingInspectorConfig::default_parity(),
move |_tx_info, inspector, _, _| Ok(inspector.into_traces().into_nodes()),
)
.await?
.map(|traces| {
traces
.into_iter()
.map(|CallTraceNode { trace, .. }| TraceEntry {
r#type: if trace.is_selfdestruct() {
"SELFDESTRUCT".to_string()
} else {
trace.kind.to_string()
},
depth: trace.depth as u32,
from: trace.caller,
to: trace.address,
value: trace.value,
input: trace.data,
output: trace.output,
})
.collect::<Vec<_>>()
});
Ok(traces)
}

/// Handler for `ots_getBlockDetails`
Expand Down

0 comments on commit 67478b7

Please sign in to comment.