From abf3793addb76b559ddd83a2e17bc972640e6d6f Mon Sep 17 00:00:00 2001 From: Tumas Date: Thu, 16 May 2024 14:42:38 +0300 Subject: [PATCH] Fix peer count serialization in beacon API --- http_api/src/standard.rs | 34 ++++++++++++++++++++++++++++++++-- p2p/src/network_api.rs | 8 ++++---- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/http_api/src/standard.rs b/http_api/src/standard.rs index a3133838..9850078d 100644 --- a/http_api/src/standard.rs +++ b/http_api/src/standard.rs @@ -337,6 +337,36 @@ pub struct MetaPeersResponse { count: usize, } +#[derive(Serialize)] +pub struct NodePeerCountResponse { + #[serde(with = "serde_utils::string_or_native")] + connected: u64, + #[serde(with = "serde_utils::string_or_native")] + connecting: u64, + #[serde(with = "serde_utils::string_or_native")] + disconnected: u64, + #[serde(with = "serde_utils::string_or_native")] + disconnecting: u64, +} + +impl From for NodePeerCountResponse { + fn from(node_peer_count: NodePeerCount) -> Self { + let NodePeerCount { + connected, + connecting, + disconnected, + disconnecting, + } = node_peer_count; + + Self { + connected, + connecting, + disconnected, + disconnecting, + } + } +} + #[derive(Serialize)] struct NodeVersionResponse<'version> { version: Option<&'version str>, @@ -1598,14 +1628,14 @@ pub async fn node_peer( /// `GET /eth/v1/node/peer_count` pub async fn node_peer_count( State(api_to_p2p_tx): State>>, -) -> Result, Error> { +) -> Result, Error> { let (sender, receiver) = futures::channel::oneshot::channel(); ApiToP2p::RequestPeerCount(sender).send(&api_to_p2p_tx); let data = receiver.await?; - Ok(EthResponse::json(data)) + Ok(EthResponse::json(data.into())) } /// `GET /eth/v1/node/version` diff --git a/p2p/src/network_api.rs b/p2p/src/network_api.rs index 79ecc435..1200bf75 100644 --- a/p2p/src/network_api.rs +++ b/p2p/src/network_api.rs @@ -55,10 +55,10 @@ impl NodePeer { #[derive(Serialize)] pub struct NodePeerCount { - connected: u64, - connecting: u64, - disconnected: u64, - disconnecting: u64, + pub connected: u64, + pub connecting: u64, + pub disconnected: u64, + pub disconnecting: u64, } #[derive(Serialize)]