fedimint_server_core/
dashboard_ui.rs1use std::collections::BTreeMap;
2use std::sync::Arc;
3use std::time::Duration;
4
5use async_trait::async_trait;
6use fedimint_core::bitcoin::Network;
7use fedimint_core::core::ModuleKind;
8use fedimint_core::module::ApiAuth;
9use fedimint_core::module::audit::AuditSummary;
10use fedimint_core::session_outcome::SessionStatusV2;
11use fedimint_core::util::SafeUrl;
12use fedimint_core::{Feerate, PeerId};
13
14use crate::{DynServerModule, ServerModule};
15
16pub type DynDashboardApi = Arc<dyn IDashboardApi + Send + Sync + 'static>;
17
18#[async_trait]
20pub trait IDashboardApi {
21 async fn auth(&self) -> ApiAuth;
23
24 async fn guardian_id(&self) -> PeerId;
26
27 async fn guardian_names(&self) -> BTreeMap<PeerId, String>;
29
30 async fn federation_name(&self) -> String;
32
33 async fn session_count(&self) -> u64;
35
36 async fn get_session_status(&self, session_idx: u64) -> SessionStatusV2;
38
39 async fn consensus_ord_latency(&self) -> Option<Duration>;
41
42 async fn p2p_connection_status(&self) -> BTreeMap<PeerId, Option<Duration>>;
44
45 async fn federation_invite_code(&self) -> String;
47
48 async fn federation_audit(&self) -> AuditSummary;
50
51 async fn bitcoin_rpc_url(&self) -> SafeUrl;
53
54 async fn bitcoin_rpc_status(&self) -> Option<ServerBitcoinRpcStatus>;
56
57 fn get_module_by_kind(&self, kind: ModuleKind) -> Option<&DynServerModule>;
59
60 fn into_dyn(self) -> DynDashboardApi
62 where
63 Self: Sized + Send + Sync + 'static,
64 {
65 Arc::new(self)
66 }
67}
68
69pub trait DashboardApiModuleExt {
71 fn get_module<M: ServerModule + 'static>(&self) -> Option<&M>;
73}
74
75impl DashboardApiModuleExt for DynDashboardApi {
76 fn get_module<M: ServerModule + 'static>(&self) -> Option<&M> {
77 self.get_module_by_kind(M::module_kind())?
78 .as_any()
79 .downcast_ref::<M>()
80 }
81}
82
83#[derive(Debug, Clone)]
84pub struct ServerBitcoinRpcStatus {
85 pub network: Network,
86 pub block_count: u64,
87 pub fee_rate: Feerate,
88 pub sync_percentage: Option<f64>,
89}