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 2 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
3 changes: 2 additions & 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.err().unwrap();

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

Expand Down
1 change: 1 addition & 0 deletions crates/rpc/rpc-types/Cargo.toml
Expand Up @@ -21,6 +21,7 @@ alloy-rpc-engine-types = { workspace = true, features = ["jsonrpsee-types"] }
ethereum_ssz_derive = { version = "0.5", optional = true }
ethereum_ssz = { version = "0.5", optional = true }
alloy-genesis.workspace = true
revm-inspectors.workspace = true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want the dep here we can convert this in the request impl, because we only really need it there
and eventually we will move the otterscan types to alloy and then can do the conversion natively in revm-inspectors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


# misc
thiserror.workspace = true
Expand Down
18 changes: 18 additions & 0 deletions crates/rpc/rpc-types/src/otterscan.rs
Expand Up @@ -4,6 +4,7 @@ use crate::{
serde_helpers::u64_hex, Block, BlockTransactions, Rich, Transaction, TransactionReceipt,
};
use alloy_primitives::{Address, Bytes, U256};
use revm_inspectors::transfer::{TransferKind, TransferOperation};
use serde::{Deserialize, Serialize};

/// Operation type enum for `InternalOperation` struct
Expand Down Expand Up @@ -122,3 +123,20 @@ impl From<Rich<Block>> for BlockDetails {
}
}
}

impl From<TransferKind> for OperationType {
fn from(kind: TransferKind) -> Self {
match kind {
TransferKind::Call => Self::OpTransfer,
TransferKind::Create => Self::OpCreate,
TransferKind::Create2 => Self::OpCreate2,
TransferKind::SelfDestruct => Self::OpSelfDestruct,
}
}
}

impl From<TransferOperation> for InternalOperation {
fn from(op: TransferOperation) -> Self {
Self { r#type: op.kind.into(), from: op.from, to: op.to, value: op.value }
}
}
13 changes: 11 additions & 2 deletions crates/rpc/rpc/src/otterscan.rs
Expand Up @@ -2,6 +2,7 @@ use alloy_primitives::Bytes;
use async_trait::async_trait;
use jsonrpsee::core::RpcResult;
use revm::inspectors::NoOpInspector;
use revm_inspectors::transfer::TransferInspector;
use revm_primitives::ExecutionResult;

use reth_primitives::{Address, BlockId, BlockNumberOrTag, TxHash, B256};
Expand Down Expand Up @@ -44,8 +45,16 @@ 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>> {
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.into_iter().map(Into::into).collect())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's move the conversion in here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

.ok_or_else(|| internal_rpc_err("failed to inspect transaction"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not required, can use ? here I believe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't use ? on Option<Vec<InternalOperation> to get Result<Vec<InternalOperation>, Err>, so I use unwrap_or_default to the inside content and return with Ok

}

/// Handler for `ots_getTransactionError`
Expand Down