Skip to content

Commit

Permalink
fix(anvil): Return transaction hash in ots_getTransactionBySenderAndN…
Browse files Browse the repository at this point in the history
…once (#7741)

Return transaction hash in ots_getTransactionBySenderAndNonce
  • Loading branch information
sealer3 authored Apr 22, 2024
1 parent 9f06a4a commit e971af1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions crates/anvil/src/eth/otterscan/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use crate::eth::{
EthApi,
};
use alloy_primitives::{Address, Bytes, B256, U256};
use alloy_rpc_types::{
Block, BlockId, BlockNumberOrTag as BlockNumber, Transaction, WithOtherFields,
};
use alloy_rpc_types::{Block, BlockId, BlockNumberOrTag as BlockNumber};
use alloy_rpc_types_trace::parity::{
Action, CallAction, CreateAction, CreateOutput, RewardAction, TraceOutput,
};
Expand Down Expand Up @@ -240,7 +238,7 @@ impl EthApi {
&self,
address: Address,
nonce: U256,
) -> Result<Option<WithOtherFields<Transaction>>> {
) -> Result<Option<B256>> {
node_info!("ots_getTransactionBySenderAndNonce");

let from = self.get_fork().map(|f| f.block_number() + 1).unwrap_or_default();
Expand All @@ -250,7 +248,7 @@ impl EthApi {
if let Some(txs) = self.backend.mined_transactions_by_block_number(n.into()).await {
for tx in txs {
if U256::from(tx.nonce) == nonce && tx.from == address {
return Ok(Some(tx))
return Ok(Some(tx.hash))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/anvil/tests/it/otterscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,8 @@ async fn can_call_ots_get_transaction_by_sender_and_nonce() {
.await
.unwrap();

assert_eq!(result1.unwrap().hash, receipt1.transaction_hash.to_alloy());
assert_eq!(result2.unwrap().hash, receipt2.transaction_hash.to_alloy());
assert_eq!(result1.unwrap(), receipt1.transaction_hash.to_alloy());
assert_eq!(result2.unwrap(), receipt2.transaction_hash.to_alloy());
}

#[tokio::test(flavor = "multi_thread")]
Expand Down

0 comments on commit e971af1

Please sign in to comment.