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

fix(rpc): return error instead of wrong operation type in otterscan API #10896

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions crates/rpc/rpc/src/otterscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ where

/// Handler for `ots_getInternalOperations`
async fn get_internal_operations(&self, tx_hash: TxHash) -> RpcResult<Vec<InternalOperation>> {
let internal_operations = self
let Some(transfer_operations) = self
.eth
.spawn_trace_transaction_in_block_with_inspector(
tx_hash,
Expand All @@ -108,25 +108,29 @@ where
)
.await
.map_err(Into::into)?
.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 | TransferKind::EofCreate => {
OperationType::OpCreate
}
TransferKind::Create2 => OperationType::OpCreate2,
TransferKind::SelfDestruct => OperationType::OpSelfDestruct,
},
})
.collect::<Vec<_>>()
else {
return Ok(Vec::new())
};

let mut internal_operations = Vec::with_capacity(transfer_operations.len());

for op in transfer_operations {
internal_operations.push(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,
TransferKind::EofCreate => {
return Err(internal_rpc_err("EOFCREATE unsupported"))
}
},
})
.unwrap_or_default();
}

Ok(internal_operations)
}

Expand Down
Loading