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

chore: use usize in internal functions #9337

Merged
merged 1 commit into from
Jul 6, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions crates/rpc/rpc-eth-api/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@ where
index: Index,
) -> RpcResult<Option<Bytes>> {
trace!(target: "rpc::eth", ?hash, ?index, "Serving eth_getRawTransactionByBlockHashAndIndex");
Ok(EthTransactions::raw_transaction_by_block_and_tx_index(self, hash.into(), index).await?)
Ok(EthTransactions::raw_transaction_by_block_and_tx_index(self, hash.into(), index.into())
.await?)
}

/// Handler for: `eth_getTransactionByBlockHashAndIndex`
Expand All @@ -473,7 +474,8 @@ where
index: Index,
) -> RpcResult<Option<reth_rpc_types::Transaction>> {
trace!(target: "rpc::eth", ?hash, ?index, "Serving eth_getTransactionByBlockHashAndIndex");
Ok(EthTransactions::transaction_by_block_and_tx_index(self, hash.into(), index).await?)
Ok(EthTransactions::transaction_by_block_and_tx_index(self, hash.into(), index.into())
.await?)
}

/// Handler for: `eth_getRawTransactionByBlockNumberAndIndex`
Expand All @@ -483,8 +485,12 @@ where
index: Index,
) -> RpcResult<Option<Bytes>> {
trace!(target: "rpc::eth", ?number, ?index, "Serving eth_getRawTransactionByBlockNumberAndIndex");
Ok(EthTransactions::raw_transaction_by_block_and_tx_index(self, number.into(), index)
.await?)
Ok(EthTransactions::raw_transaction_by_block_and_tx_index(
self,
number.into(),
index.into(),
)
.await?)
}

/// Handler for: `eth_getTransactionByBlockNumberAndIndex`
Expand All @@ -494,7 +500,8 @@ where
index: Index,
) -> RpcResult<Option<reth_rpc_types::Transaction>> {
trace!(target: "rpc::eth", ?number, ?index, "Serving eth_getTransactionByBlockNumberAndIndex");
Ok(EthTransactions::transaction_by_block_and_tx_index(self, number.into(), index).await?)
Ok(EthTransactions::transaction_by_block_and_tx_index(self, number.into(), index.into())
.await?)
}

/// Handler for: `eth_getTransactionReceipt`
Expand Down
12 changes: 6 additions & 6 deletions crates/rpc/rpc-eth-api/src/helpers/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use reth_rpc_types::{
EIP1559TransactionRequest, EIP2930TransactionRequest, EIP4844TransactionRequest,
LegacyTransactionRequest,
},
AnyTransactionReceipt, Index, Transaction, TransactionRequest, TypedTransactionRequest,
AnyTransactionReceipt, Transaction, TransactionRequest, TypedTransactionRequest,
};
use reth_rpc_types_compat::transaction::from_recovered_with_block_context;
use reth_transaction_pool::{TransactionOrigin, TransactionPool};
Expand Down Expand Up @@ -184,7 +184,7 @@ pub trait EthTransactions: LoadTransaction {
fn transaction_by_block_and_tx_index(
&self,
block_id: BlockId,
index: Index,
index: usize,
) -> impl Future<Output = EthResult<Option<Transaction>>> + Send
where
Self: LoadBlock,
Expand All @@ -194,13 +194,13 @@ pub trait EthTransactions: LoadTransaction {
let block_hash = block.hash();
let block_number = block.number;
let base_fee_per_gas = block.base_fee_per_gas;
if let Some(tx) = block.into_transactions_ecrecovered().nth(index.into()) {
if let Some(tx) = block.into_transactions_ecrecovered().nth(index) {
return Ok(Some(from_recovered_with_block_context(
tx,
block_hash,
block_number,
base_fee_per_gas,
index.into(),
index,
)))
}
}
Expand All @@ -215,14 +215,14 @@ pub trait EthTransactions: LoadTransaction {
fn raw_transaction_by_block_and_tx_index(
&self,
block_id: BlockId,
index: Index,
index: usize,
) -> impl Future<Output = EthResult<Option<Bytes>>> + Send
where
Self: LoadBlock,
{
async move {
if let Some(block) = self.block_with_senders(block_id).await? {
if let Some(tx) = block.transactions().nth(index.into()) {
if let Some(tx) = block.transactions().nth(index) {
return Ok(Some(tx.envelope_encoded()))
}
}
Expand Down
Loading