Skip to content

Commit 0e0080f

Browse files
committed
feat(node/web): expose block producer stats rpc
1 parent 4f62245 commit 0e0080f

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

node/common/src/service/rpc/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
mod sender;
22
pub use sender::RpcSender;
33

4+
pub mod stats;
5+
46
use node::rpc::{
57
RpcBlockProducerStatsGetResponse, RpcDiscoveryBoostrapStatsResponse,
68
RpcDiscoveryRoutingTableResponse, RpcHealthCheckResponse, RpcLedgerAccountsResponse,

node/common/src/service/rpc/sender.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use node::core::channels::{mpsc, oneshot};
88
use node::p2p::connection::outgoing::P2pConnectionOutgoingInitOpts;
99
use node::rpc::*;
1010

11+
use super::stats::Stats;
1112
use super::NodeRpcRequest;
1213

1314
#[derive(Clone)]
@@ -65,6 +66,13 @@ impl RpcSender {
6566
}
6667
}
6768

69+
#[cfg_attr(target_family = "wasm", wasm_bindgen)]
70+
impl RpcSender {
71+
pub fn stats(&self) -> Stats {
72+
Stats::new(self.clone())
73+
}
74+
}
75+
6876
#[cfg(target_family = "wasm")]
6977
#[cfg_attr(target_family = "wasm", wasm_bindgen)]
7078
impl RpcSender {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#[cfg(target_family = "wasm")]
2+
use gloo_utils::format::JsValueSerdeExt;
3+
#[cfg(target_family = "wasm")]
4+
use node::rpc::{RpcBlockProducerStatsGetResponse, RpcRequest};
5+
#[cfg(target_family = "wasm")]
6+
use wasm_bindgen::prelude::*;
7+
8+
use super::RpcSender;
9+
10+
#[derive(Clone)]
11+
#[cfg_attr(target_family = "wasm", wasm_bindgen)]
12+
pub struct Stats {
13+
#[allow(unused)]
14+
sender: RpcSender,
15+
}
16+
17+
impl Stats {
18+
pub fn new(sender: RpcSender) -> Self {
19+
Self { sender }
20+
}
21+
}
22+
23+
#[cfg(target_family = "wasm")]
24+
#[cfg_attr(target_family = "wasm", wasm_bindgen)]
25+
impl Stats {
26+
pub async fn block_producer(&self) -> JsValue {
27+
let res = self
28+
.sender
29+
.oneshot_request::<RpcBlockProducerStatsGetResponse>(RpcRequest::BlockProducerStatsGet)
30+
.await
31+
.flatten();
32+
JsValue::from_serde(&res).unwrap_or_default()
33+
}
34+
}

0 commit comments

Comments
 (0)