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::admin_client::GuardianConfigBackup;
7use fedimint_core::bitcoin::Network;
8use fedimint_core::core::ModuleKind;
9use fedimint_core::module::ApiAuth;
10use fedimint_core::module::audit::AuditSummary;
11use fedimint_core::session_outcome::SessionStatusV2;
12use fedimint_core::util::SafeUrl;
13use fedimint_core::{Feerate, PeerId};
14
15use crate::net::GuardianAuthToken;
16use crate::{DynServerModule, ServerModule};
17
18pub type DynDashboardApi = Arc<dyn IDashboardApi + Send + Sync + 'static>;
19
20#[async_trait]
22pub trait IDashboardApi {
23 async fn auth(&self) -> ApiAuth;
25
26 async fn guardian_id(&self) -> PeerId;
28
29 async fn guardian_names(&self) -> BTreeMap<PeerId, String>;
31
32 async fn federation_name(&self) -> String;
34
35 async fn session_count(&self) -> u64;
37
38 async fn get_session_status(&self, session_idx: u64) -> SessionStatusV2;
40
41 async fn consensus_ord_latency(&self) -> Option<Duration>;
43
44 async fn p2p_connection_status(&self) -> BTreeMap<PeerId, Option<Duration>>;
46
47 async fn federation_invite_code(&self) -> String;
49
50 async fn federation_audit(&self) -> AuditSummary;
52
53 async fn bitcoin_rpc_url(&self) -> SafeUrl;
55
56 async fn bitcoin_rpc_status(&self) -> Option<ServerBitcoinRpcStatus>;
58
59 async fn download_guardian_config_backup(
61 &self,
62 password: &str,
63 guardian_auth: &GuardianAuthToken,
64 ) -> GuardianConfigBackup;
65
66 fn get_module_by_kind(&self, kind: ModuleKind) -> Option<&DynServerModule>;
68
69 async fn fedimintd_version(&self) -> String;
71
72 fn into_dyn(self) -> DynDashboardApi
74 where
75 Self: Sized + Send + Sync + 'static,
76 {
77 Arc::new(self)
78 }
79}
80
81pub trait DashboardApiModuleExt {
83 fn get_module<M: ServerModule + 'static>(&self) -> Option<&M>;
85}
86
87impl DashboardApiModuleExt for DynDashboardApi {
88 fn get_module<M: ServerModule + 'static>(&self) -> Option<&M> {
89 self.get_module_by_kind(M::module_kind())?
90 .as_any()
91 .downcast_ref::<M>()
92 }
93}
94
95#[derive(Debug, Clone)]
96pub struct ServerBitcoinRpcStatus {
97 pub network: Network,
98 pub block_count: u64,
99 pub fee_rate: Feerate,
100 pub sync_progress: Option<f64>,
101}