mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-28 00:28:20 -05:00
feat: convert EthApiError to RpcError directly (#1241)
Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
This commit is contained in:
@@ -151,7 +151,7 @@ where
|
||||
}
|
||||
|
||||
async fn get_code(&self, address: Address, block_number: Option<BlockId>) -> Result<Bytes> {
|
||||
EthApi::get_code(self, address, block_number).to_rpc_result()
|
||||
Ok(EthApi::get_code(self, address, block_number)?)
|
||||
}
|
||||
|
||||
async fn call(&self, _request: CallRequest, _block_number: Option<BlockId>) -> Result<Bytes> {
|
||||
@@ -216,7 +216,7 @@ where
|
||||
}
|
||||
|
||||
async fn send_raw_transaction(&self, tx: Bytes) -> Result<H256> {
|
||||
EthApi::send_raw_transaction(self, tx).await.to_rpc_result()
|
||||
Ok(EthApi::send_raw_transaction(self, tx).await?)
|
||||
}
|
||||
|
||||
async fn sign(&self, _address: Address, _message: Bytes) -> Result<Bytes> {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
//! Error variants for the `eth_` namespace.
|
||||
|
||||
use crate::{impl_to_rpc_result, result::ToRpcResult};
|
||||
use jsonrpsee::{core::Error as RpcError, types::error::INVALID_PARAMS_CODE};
|
||||
use reth_transaction_pool::error::PoolError;
|
||||
|
||||
use crate::result::{internal_rpc_err, rpc_err};
|
||||
|
||||
/// Result alias
|
||||
pub(crate) type EthResult<T> = Result<T, EthApiError>;
|
||||
|
||||
@@ -27,7 +29,16 @@ pub(crate) enum EthApiError {
|
||||
Internal(#[from] reth_interfaces::Error),
|
||||
}
|
||||
|
||||
impl_to_rpc_result!(EthApiError);
|
||||
impl From<EthApiError> for RpcError {
|
||||
fn from(value: EthApiError) -> Self {
|
||||
match value {
|
||||
EthApiError::UnknownBlockNumber => {
|
||||
rpc_err(INVALID_PARAMS_CODE, value.to_string(), None)
|
||||
}
|
||||
err => internal_rpc_err(err.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A helper error type that mirrors `geth` Txpool's error messages
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
||||
Reference in New Issue
Block a user