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

Implement ots_getInternalOperations #7332

Merged
merged 4 commits into from Mar 26, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Expand Up @@ -198,7 +198,7 @@ reth-trie-parallel = { path = "crates/trie-parallel" }
# 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
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
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