diff --git a/node/Cargo.toml b/node/Cargo.toml index c8af5784..f48333c1 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -17,6 +17,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] clap = { features = ["derive"], workspace = true } codec.workspace = true +async-trait.workspace = true frame-benchmarking-cli = { workspace = true, default-features = true, optional = true } frame-metadata-hash-extension.default-features = true frame-metadata-hash-extension.workspace = true diff --git a/node/src/rpc.rs b/node/src/rpc.rs index e0c319f0..0cffaa19 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -7,6 +7,7 @@ use std::sync::Arc; +use async_trait::async_trait; use jsonrpsee::{core::RpcResult, proc_macros::rpc, RpcModule}; use quantus_runtime::{opaque::Block, AccountId, Balance, Nonce}; use sc_network::service::traits::NetworkService; @@ -36,7 +37,7 @@ pub struct PeerInfo { pub trait PeerApi { /// Get basic peer information #[method(name = "peer_getBasicInfo")] - fn get_basic_info(&self) -> RpcResult; + async fn get_basic_info(&self) -> RpcResult; } /// Peer RPC implementation @@ -52,17 +53,17 @@ impl Peer { } } +#[async_trait] impl PeerApiServer for Peer { - fn get_basic_info(&self) -> RpcResult { + async fn get_basic_info(&self) -> RpcResult { if let Some(network) = &self.network { - let network_state = - futures::executor::block_on(network.network_state()).map_err(|_| { - jsonrpsee::types::error::ErrorObject::owned( - 5001, - "Failed to get network state", - None::<()>, - ) - })?; + let network_state = network.network_state().await.map_err(|_| { + jsonrpsee::types::error::ErrorObject::owned( + 5001, + "Failed to get network state", + None::<()>, + ) + })?; let connected_peers: Vec = network_state.connected_peers.keys().cloned().collect();