use result for TransactionCompact::fill. (#12170)

Co-authored-by: Emilia Hane <elsaemiliaevahane@gmail.com>
Co-authored-by: dkathiriya <lakshya-sky@users.noreply.github.com>
This commit is contained in:
Darshan Kathiriya
2024-11-12 05:31:32 -05:00
committed by GitHub
parent c261532a27
commit bad7a4f0c9
20 changed files with 124 additions and 62 deletions

View File

@ -501,7 +501,8 @@ where
trace!(target: "rpc::eth", ?hash, "Serving eth_getTransactionByHash");
Ok(EthTransactions::transaction_by_hash(self, hash)
.await?
.map(|tx| tx.into_transaction(self.tx_resp_builder())))
.map(|tx| tx.into_transaction(self.tx_resp_builder()))
.transpose()?)
}
/// Handler for: `eth_getRawTransactionByBlockHashAndIndex`

View File

@ -64,8 +64,7 @@ pub trait EthBlocks: LoadBlock {
full.into(),
Some(block_hash),
self.tx_resp_builder(),
)
.map_err(Self::Error::from_eth_err)?;
)?;
Ok(Some(block))
}
}

View File

@ -1,98 +0,0 @@
//! Helper traits to wrap generic l1 errors, in network specific error type configured in
//! [`EthApiTypes`](crate::EthApiTypes).
use reth_rpc_eth_types::EthApiError;
use revm_primitives::EVMError;
/// Helper trait to wrap core [`EthApiError`].
pub trait FromEthApiError: From<EthApiError> {
/// Converts from error via [`EthApiError`].
fn from_eth_err<E>(err: E) -> Self
where
EthApiError: From<E>;
}
impl<T> FromEthApiError for T
where
T: From<EthApiError>,
{
fn from_eth_err<E>(err: E) -> Self
where
EthApiError: From<E>,
{
T::from(EthApiError::from(err))
}
}
/// Helper trait to wrap core [`EthApiError`].
pub trait IntoEthApiError: Into<EthApiError> {
/// Converts into error via [`EthApiError`].
fn into_eth_err<E>(self) -> E
where
E: FromEthApiError;
}
impl<T> IntoEthApiError for T
where
EthApiError: From<T>,
{
fn into_eth_err<E>(self) -> E
where
E: FromEthApiError,
{
E::from_eth_err(self)
}
}
/// Helper trait to access wrapped core error.
pub trait AsEthApiError {
/// Returns reference to [`EthApiError`], if this an error variant inherited from core
/// functionality.
fn as_err(&self) -> Option<&EthApiError>;
/// Returns `true` if error is
/// [`RpcInvalidTransactionError::GasTooHigh`](reth_rpc_eth_types::RpcInvalidTransactionError::GasTooHigh).
fn is_gas_too_high(&self) -> bool {
if let Some(err) = self.as_err() {
return err.is_gas_too_high()
}
false
}
/// Returns `true` if error is
/// [`RpcInvalidTransactionError::GasTooLow`](reth_rpc_eth_types::RpcInvalidTransactionError::GasTooLow).
fn is_gas_too_low(&self) -> bool {
if let Some(err) = self.as_err() {
return err.is_gas_too_low()
}
false
}
}
impl AsEthApiError for EthApiError {
fn as_err(&self) -> Option<&EthApiError> {
Some(self)
}
}
/// Helper trait to convert from revm errors.
pub trait FromEvmError: From<EthApiError> {
/// Converts from a revm error.
fn from_evm_err<E>(err: EVMError<E>) -> Self
where
EthApiError: From<E>;
}
impl<T> FromEvmError for T
where
T: From<EthApiError>,
{
fn from_evm_err<E>(err: EVMError<E>) -> Self
where
EthApiError: From<E>,
{
err.into_eth_err()
}
}

View File

@ -17,7 +17,6 @@
pub mod block;
pub mod blocking_task;
pub mod call;
pub mod error;
pub mod fee;
pub mod pending_block;
pub mod receipt;

View File

@ -208,7 +208,7 @@ pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {
tx.clone().with_signer(*signer),
tx_info,
self.tx_resp_builder(),
)))
)?))
}
}
@ -233,7 +233,7 @@ pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {
RpcNodeCore::pool(self).get_transaction_by_sender_and_nonce(sender, nonce)
{
let transaction = tx.transaction.clone().into_consensus();
return Ok(Some(from_recovered(transaction.into(), self.tx_resp_builder())));
return Ok(Some(from_recovered(transaction.into(), self.tx_resp_builder())?));
}
}
@ -291,7 +291,7 @@ pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {
)
})
})
.ok_or(EthApiError::HeaderNotFound(block_id).into())
.ok_or(EthApiError::HeaderNotFound(block_id))?
.map(Some)
}
}

View File

@ -20,12 +20,14 @@ pub mod node;
pub mod pubsub;
pub mod types;
pub use reth_rpc_eth_types::error::{
AsEthApiError, FromEthApiError, FromEvmError, IntoEthApiError,
};
pub use reth_rpc_types_compat::TransactionCompat;
pub use bundle::{EthBundleApiServer, EthCallBundleApiServer};
pub use core::{EthApiServer, FullEthApiServer};
pub use filter::EthFilterApiServer;
pub use helpers::error::{AsEthApiError, FromEthApiError, FromEvmError, IntoEthApiError};
pub use node::{RpcNodeCore, RpcNodeCoreExt};
pub use pubsub::EthPubSubApiServer;
pub use types::{EthApiTypes, FullEthApiTypes, RpcBlock, RpcReceipt, RpcTransaction};

View File

@ -39,15 +39,26 @@ pub type RpcBlock<T> = Block<RpcTransaction<T>, <T as Network>::HeaderResponse>;
/// Adapter for network specific receipt type.
pub type RpcReceipt<T> = <T as Network>::ReceiptResponse;
/// Adapter for network specific error type.
pub type RpcError<T> = <T as EthApiTypes>::Error;
/// Helper trait holds necessary trait bounds on [`EthApiTypes`] to implement `eth` API.
pub trait FullEthApiTypes:
EthApiTypes<TransactionCompat: TransactionCompat<Transaction = RpcTransaction<Self::NetworkTypes>>>
EthApiTypes<
TransactionCompat: TransactionCompat<
Transaction = RpcTransaction<Self::NetworkTypes>,
Error = RpcError<Self>,
>,
>
{
}
impl<T> FullEthApiTypes for T where
T: EthApiTypes<
TransactionCompat: TransactionCompat<Transaction = RpcTransaction<T::NetworkTypes>>,
TransactionCompat: TransactionCompat<
Transaction = RpcTransaction<T::NetworkTypes>,
Error = RpcError<T>,
>,
>
{
}