Skip to content

Commit

Permalink
Implement ots_getInternalOperations (paradigmxyz#7332)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbnerZheng authored and Ruteri committed Apr 17, 2024
1 parent 9e03724 commit 2e032b0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ reth-trie = { path = "crates/trie" }
# revm
revm = { version = "7.2.0", features = ["std", "secp256k1"], default-features = false }
revm-primitives = { version = "3.1.0", features = ["std"], default-features = false }
revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors", rev = "2b48b65" }
revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors", rev = "b3082f3" }

# eth
alloy-chains = { version = "0.1", feature = ["serde", "rlp", "arbitrary"] }
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 @@ -297,9 +297,7 @@ where

OtterscanClient::get_api_level(client).await.unwrap();

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

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

Expand Down
34 changes: 30 additions & 4 deletions crates/rpc/rpc/src/otterscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use alloy_primitives::Bytes;
use async_trait::async_trait;
use jsonrpsee::core::RpcResult;
use revm::inspectors::NoOpInspector;
use revm_inspectors::transfer::{TransferInspector, TransferKind};
use revm_primitives::ExecutionResult;

use reth_primitives::{Address, BlockId, BlockNumberOrTag, TxHash, B256};
use reth_rpc_api::{EthApiServer, OtterscanServer};
use reth_rpc_types::{
BlockDetails, BlockTransactions, ContractCreator, InternalOperation, OtsBlockTransactions,
OtsTransactionReceipt, TraceEntry, Transaction, TransactionsWithReceipts,
BlockDetails, BlockTransactions, ContractCreator, InternalOperation, OperationType,
OtsBlockTransactions, OtsTransactionReceipt, TraceEntry, Transaction, TransactionsWithReceipts,
};

use crate::{eth::EthTransactions, result::internal_rpc_err};
Expand Down Expand Up @@ -44,8 +45,33 @@ where
}

/// Handler for `ots_getInternalOperations`
async fn get_internal_operations(&self, _tx_hash: TxHash) -> RpcResult<Vec<InternalOperation>> {
Err(internal_rpc_err("unimplemented"))
async fn get_internal_operations(&self, tx_hash: TxHash) -> RpcResult<Vec<InternalOperation>> {
let internal_operations = self
.eth
.spawn_trace_transaction_in_block_with_inspector(
tx_hash,
TransferInspector::new(false),
|_tx_info, inspector, _, _| Ok(inspector.into_transfers()),
)
.await?
.map(|transfer_operations| {
transfer_operations
.iter()
.map(|op| InternalOperation {
from: op.from,
to: op.to,
value: op.value,
r#type: match op.kind {
TransferKind::Call => OperationType::OpTransfer,
TransferKind::Create => OperationType::OpCreate,
TransferKind::Create2 => OperationType::OpCreate2,
TransferKind::SelfDestruct => OperationType::OpSelfDestruct,
},
})
.collect::<Vec<_>>()
})
.unwrap_or_default();
Ok(internal_operations)
}

/// Handler for `ots_getTransactionError`
Expand Down

0 comments on commit 2e032b0

Please sign in to comment.