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(rpc): remove redundant trait bounds #8414

Merged
merged 2 commits into from
May 27, 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
6 changes: 4 additions & 2 deletions crates/net/eth-wire-types/src/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ mod tests {
);
}

#[test]
// Test vector from: https://eips.ethereum.org/EIPS/eip-2481
#[test]
#[allow(clippy::needless_update)]
fn encode_receipts() {
let expected = hex!("f90172820457f9016cf90169f901668001b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f85ff85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff");
let mut data = vec![];
Expand Down Expand Up @@ -120,8 +121,9 @@ mod tests {
assert_eq!(data, expected);
}

#[test]
// Test vector from: https://eips.ethereum.org/EIPS/eip-2481
#[test]
#[allow(clippy::needless_update)]
fn decode_receipts() {
let data = hex!("f90172820457f9016cf90169f901668001b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f85ff85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff");
let request = RequestPair::<Receipts>::decode(&mut &data[..]).unwrap();
Expand Down
136 changes: 61 additions & 75 deletions crates/rpc/rpc/src/eth/api/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1367,11 +1367,7 @@ where

impl<Provider, Pool, Network, EvmConfig> EthApi<Provider, Pool, Network, EvmConfig>
where
Pool: TransactionPool + Clone + 'static,
Provider:
BlockReaderIdExt + ChainSpecProvider + StateProviderFactory + EvmEnvProvider + 'static,
Network: NetworkInfo + Send + Sync + 'static,
EvmConfig: ConfigureEvm + 'static,
Self: Send + Sync + 'static,
{
/// Spawns the given closure on a new blocking tracing task
async fn spawn_tracing_task_with<F, T>(&self, f: F) -> EthResult<T>
Expand All @@ -1390,11 +1386,11 @@ where

impl<Provider, Pool, Network, EvmConfig> EthApi<Provider, Pool, Network, EvmConfig>
where
Pool: TransactionPool + Clone + 'static,
Pool: TransactionPool + 'static,
Provider:
BlockReaderIdExt + ChainSpecProvider + StateProviderFactory + EvmEnvProvider + 'static,
Network: NetworkInfo + Send + Sync + 'static,
EvmConfig: ConfigureEvm + 'static,
Network: NetworkInfo + 'static,
EvmConfig: ConfigureEvm,
{
/// Returns the gas price if it is set, otherwise fetches a suggested gas price for legacy
/// transactions.
Expand Down Expand Up @@ -1449,13 +1445,67 @@ where
None => self.blob_base_fee().await,
}
}

pub(crate) fn sign_request(
&self,
from: &Address,
request: TypedTransactionRequest,
) -> EthResult<TransactionSigned> {
for signer in self.inner.signers.read().iter() {
if signer.is_signer_for(from) {
return match signer.sign_transaction(request, from) {
Ok(tx) => Ok(tx),
Err(e) => Err(e.into()),
}
}
}
Err(EthApiError::InvalidTransactionSignature)
}

/// Get Transaction by [BlockId] and the index of the transaction within that Block.
///
/// Returns `Ok(None)` if the block does not exist, or the block as fewer transactions
pub(crate) async fn transaction_by_block_and_tx_index(
&self,
block_id: impl Into<BlockId>,
index: Index,
) -> EthResult<Option<Transaction>> {
if let Some(block) = self.block_with_senders(block_id.into()).await? {
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()) {
return Ok(Some(from_recovered_with_block_context(
tx,
block_hash,
block_number,
base_fee_per_gas,
index.into(),
)))
}
}

Ok(None)
}

pub(crate) async fn raw_transaction_by_block_and_tx_index(
&self,
block_id: impl Into<BlockId>,
index: Index,
) -> EthResult<Option<Bytes>> {
if let Some(block) = self.block_with_senders(block_id.into()).await? {
if let Some(tx) = block.transactions().nth(index.into()) {
return Ok(Some(tx.envelope_encoded()))
}
}

Ok(None)
}
}

impl<Provider, Pool, Network, EvmConfig> EthApi<Provider, Pool, Network, EvmConfig>
where
Provider:
BlockReaderIdExt + ChainSpecProvider + StateProviderFactory + EvmEnvProvider + 'static,
Network: NetworkInfo + 'static,
Provider: BlockReaderIdExt + ChainSpecProvider,
{
/// Helper function for `eth_getTransactionReceipt`
///
Expand Down Expand Up @@ -1545,70 +1595,6 @@ where
}
}

impl<Provider, Pool, Network, EvmConfig> EthApi<Provider, Pool, Network, EvmConfig>
where
Pool: TransactionPool + 'static,
Provider:
BlockReaderIdExt + ChainSpecProvider + StateProviderFactory + EvmEnvProvider + 'static,
Network: NetworkInfo + Send + Sync + 'static,
EvmConfig: ConfigureEvm + 'static,
{
pub(crate) fn sign_request(
&self,
from: &Address,
request: TypedTransactionRequest,
) -> EthResult<TransactionSigned> {
for signer in self.inner.signers.read().iter() {
if signer.is_signer_for(from) {
return match signer.sign_transaction(request, from) {
Ok(tx) => Ok(tx),
Err(e) => Err(e.into()),
}
}
}
Err(EthApiError::InvalidTransactionSignature)
}

/// Get Transaction by [BlockId] and the index of the transaction within that Block.
///
/// Returns `Ok(None)` if the block does not exist, or the block as fewer transactions
pub(crate) async fn transaction_by_block_and_tx_index(
&self,
block_id: impl Into<BlockId>,
index: Index,
) -> EthResult<Option<Transaction>> {
if let Some(block) = self.block_with_senders(block_id.into()).await? {
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()) {
return Ok(Some(from_recovered_with_block_context(
tx,
block_hash,
block_number,
base_fee_per_gas,
index.into(),
)))
}
}

Ok(None)
}

pub(crate) async fn raw_transaction_by_block_and_tx_index(
&self,
block_id: impl Into<BlockId>,
index: Index,
) -> EthResult<Option<Bytes>> {
if let Some(block) = self.block_with_senders(block_id.into()).await? {
if let Some(tx) = block.transactions().nth(index.into()) {
return Ok(Some(tx.envelope_encoded()))
}
}

Ok(None)
}
}
/// Represents from where a transaction was fetched.
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum TransactionSource {
Expand Down
Loading