mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(rpc): add default to_rpc_result function (#993)
This commit is contained in:
@ -55,7 +55,7 @@ impl AdminApiServer for AdminApi {
|
||||
|
||||
async fn node_info(&self) -> RpcResult<NodeInfo> {
|
||||
let enr = self.network.local_node_record();
|
||||
let status = self.network.network_status().await.map_internal_err(|e| e.to_string())?;
|
||||
let status = self.network.network_status().await.to_rpc_result()?;
|
||||
|
||||
Ok(NodeInfo::new(enr, status))
|
||||
}
|
||||
|
||||
@ -1,9 +1,19 @@
|
||||
//! Additional helpers for converting errors.
|
||||
|
||||
use jsonrpsee::core::{Error as RpcError, RpcResult};
|
||||
use std::fmt::Display;
|
||||
|
||||
/// Helper trait to easily convert various `Result` types into [`RpcResult`]
|
||||
pub(crate) trait ToRpcResult<Ok, Err> {
|
||||
/// Converts the error of the [Result] to an [RpcResult] via the `Err` [Display] impl.
|
||||
fn to_rpc_result(self) -> RpcResult<Ok>
|
||||
where
|
||||
Err: Display,
|
||||
Self: Sized,
|
||||
{
|
||||
self.map_internal_err(|err| err.to_string())
|
||||
}
|
||||
|
||||
/// Converts this type into an [`RpcResult`]
|
||||
fn map_rpc_err<'a, F, M>(self, op: F) -> RpcResult<Ok>
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user