Skip to content

Commit

Permalink
feat: Implement ots_getTransactionError endpoints (#7316)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
AbnerZheng and mattsse committed Mar 25, 2024
1 parent 61801b9 commit eed60d9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions crates/rpc/rpc-api/src/otterscan.rs
@@ -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
6 changes: 3 additions & 3 deletions crates/rpc/rpc-builder/tests/it/http.rs
Expand Up @@ -300,9 +300,9 @@ where
assert!(is_unimplemented(
OtterscanClient::get_internal_operations(client, tx_hash).await.err().unwrap()
));
assert!(is_unimplemented(
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
23 changes: 19 additions & 4 deletions crates/rpc/rpc/src/otterscan.rs
@@ -1,4 +1,5 @@
use crate::result::internal_rpc_err;
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 All @@ -7,6 +8,8 @@ use reth_rpc_types::{
BlockDetails, ContractCreator, InternalOperation, OtsBlockTransactions, TraceEntry,
Transaction, TransactionsWithReceipts,
};
use revm::inspectors::NoOpInspector;
use revm_primitives::ExecutionResult;

const API_LEVEL: u64 = 8;

Expand All @@ -26,7 +29,7 @@ impl<Eth> OtterscanApi<Eth> {
#[async_trait]
impl<Eth> OtterscanServer for OtterscanApi<Eth>
where
Eth: EthApiServer,
Eth: EthApiServer + EthTransactions,
{
/// Handler for `ots_hasCode`
async fn has_code(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<bool> {
Expand All @@ -44,8 +47,20 @@ where
}

/// Handler for `ots_getTransactionError`
async fn get_transaction_error(&self, _tx_hash: TxHash) -> RpcResult<String> {
Err(internal_rpc_err("unimplemented"))
async fn get_transaction_error(&self, tx_hash: TxHash) -> RpcResult<Option<Bytes>> {
let maybe_revert = self
.eth
.spawn_trace_transaction_in_block_with_inspector(
tx_hash,
NoOpInspector,
|_tx_info, _inspector, res, _| match res.result {
ExecutionResult::Revert { output, .. } => Ok(Some(output)),
_ => Ok(None),
},
)
.await
.map(Option::flatten)?;
Ok(maybe_revert)
}

/// Handler for `ots_traceTransaction`
Expand Down

0 comments on commit eed60d9

Please sign in to comment.