Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc/ots): implement ots_traceTransaction RPC #9246

Merged
merged 7 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading