feat: convert EthApiError to RpcError directly (#1241)

Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
This commit is contained in:
Aurélien
2023-02-11 22:40:45 +01:00
committed by GitHub
parent d40d9e4d15
commit 7aedee601a
2 changed files with 15 additions and 4 deletions

View File

@@ -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> {

View File

@@ -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)]