Implement ots_getInternalOperations (#7332)

This commit is contained in:
Abner Zheng
2024-03-26 19:40:53 +08:00
committed by GitHub
parent d611f11a07
commit 903fc2dcd0
4 changed files with 33 additions and 9 deletions

2
Cargo.lock generated
View File

@@ -6786,7 +6786,7 @@ dependencies = [
[[package]]
name = "revm-inspectors"
version = "0.1.0"
source = "git+https://github.com/paradigmxyz/evm-inspectors?rev=2b48b65#2b48b65f3880803f51883948c319012da09ecba7"
source = "git+https://github.com/paradigmxyz/evm-inspectors?rev=b3082f3#b3082f3deca76e721ac72cee4a6857b4ff88e684"
dependencies = [
"alloy-primitives",
"alloy-rpc-trace-types",

View File

@@ -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"] }

View File

@@ -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();

View File

@@ -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};
@@ -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`