Skip to content

Commit

Permalink
apply suggestion from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
AbnerZheng committed Mar 24, 2024
1 parent 149d123 commit c1633be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
4 changes: 2 additions & 2 deletions crates/rpc/rpc-api/src/otterscan.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
use reth_primitives::{Address, BlockId, BlockNumberOrTag, TxHash, B256};
use reth_primitives::{Address, BlockId, BlockNumberOrTag, Bytes, TxHash, B256};
use reth_rpc_types::{
BlockDetails, ContractCreator, InternalOperation, OtsBlockTransactions, TraceEntry,
Transaction, TransactionsWithReceipts,
Expand All @@ -25,7 +25,7 @@ pub trait Otterscan {

/// Given a transaction hash, returns its raw revert reason.
#[method(name = "getTransactionError")]
async fn get_transaction_error(&self, tx_hash: TxHash) -> RpcResult<String>;
async fn get_transaction_error(&self, tx_hash: TxHash) -> RpcResult<Option<Bytes>>;

/// Extract all variations of calls, contract creation and self-destructs and returns a call
/// tree.
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-builder/tests/it/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ where
OtterscanClient::get_internal_operations(client, tx_hash).await.err().unwrap()
));

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

assert!(is_unimplemented(
OtterscanClient::trace_transaction(client, tx_hash).await.err().unwrap()
Expand Down
18 changes: 7 additions & 11 deletions crates/rpc/rpc/src/otterscan.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{eth::EthTransactions, result::internal_rpc_err};
use alloy_primitives::Bytes;
use async_trait::async_trait;
use jsonrpsee::core::RpcResult;
use reth_primitives::{Address, BlockId, BlockNumberOrTag, TxHash, B256};
Expand Down Expand Up @@ -46,23 +47,18 @@ where
}

/// Handler for `ots_getTransactionError`
async fn get_transaction_error(&self, _tx_hash: TxHash) -> RpcResult<String> {
async fn get_transaction_error(&self, tx_hash: TxHash) -> RpcResult<Option<Bytes>> {
self.eth
.spawn_trace_transaction_in_block_with_inspector(
_tx_hash,
tx_hash,
NoOpInspector,
|_tx_info, _inspector, res, _| match res.result {
// hexadecimal-formatted error blob
ExecutionResult::Revert { output, .. } => Ok(format!("b{output}")),

// Returns "0x"
// 1. if the transaction was successfully executed.
// 2. if it failed with no revert reason or out of gas
_ => Ok("0x".to_string()),
ExecutionResult::Revert { output, .. } => Ok(output),
_ => Ok(Bytes::new()),
},
)
.await?
.ok_or_else(|| internal_rpc_err("transaction not found"))
.await
.map_err(|e| internal_rpc_err(e.to_string()))
}

/// Handler for `ots_traceTransaction`
Expand Down

0 comments on commit c1633be

Please sign in to comment.