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: Implement ots_getTransactionError endpoints #7316

Merged
merged 5 commits into from Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
21 changes: 17 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,18 @@ 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>> {
self.eth
.spawn_trace_transaction_in_block_with_inspector(
tx_hash,
NoOpInspector,
|_tx_info, _inspector, res, _| match res.result {
ExecutionResult::Revert { output, .. } => Ok(output),
_ => Ok(Bytes::new()),
},
)
.await
.map_err(|e| internal_rpc_err(e.to_string()))
}

/// Handler for `ots_traceTransaction`
Expand Down