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};
14use serde::{Deserialize, Serialize};
15
16use crate::net::GuardianAuthToken;
17use crate::{DynServerModule, ServerModule};
18
19pub type DynDashboardApi = Arc<dyn IDashboardApi + Send + Sync + 'static>;
20
21#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
23#[serde(rename_all = "snake_case")]
24pub enum ConnectionType {
25 Direct,
27 Relay,
29 Unknown,
31}
32
33#[async_trait]
35pub trait IDashboardApi {
36 async fn auth(&self) -> ApiAuth;
38
39 async fn guardian_id(&self) -> PeerId;
41
42 async fn guardian_names(&self) -> BTreeMap<PeerId, String>;
44
45 async fn federation_name(&self) -> String;
47
48 async fn session_count(&self) -> u64;
50
51 async fn get_session_status(&self, session_idx: u64) -> SessionStatusV2;
53
54 async fn consensus_ord_latency(&self) -> Option<Duration>;
56
57 async fn p2p_connection_status(&self) -> BTreeMap<PeerId, Option<Duration>>;
59
60 async fn p2p_connection_type_status(&self) -> BTreeMap<PeerId, ConnectionType>;
62
63 async fn federation_invite_code(&self) -> String;
65
66 async fn federation_audit(&self) -> AuditSummary;
68
69 async fn bitcoin_rpc_url(&self) -> SafeUrl;
71
72 async fn bitcoin_rpc_status(&self) -> Option<ServerBitcoinRpcStatus>;
74
75 async fn download_guardian_config_backup(
77 &self,
78 password: &str,
79 guardian_auth: &GuardianAuthToken,
80 ) -> GuardianConfigBackup;
81
82 fn get_module_by_kind(&self, kind: ModuleKind) -> Option<&DynServerModule>;
84
85 async fn fedimintd_version(&self) -> String;
87
88 fn into_dyn(self) -> DynDashboardApi
90 where
91 Self: Sized + Send + Sync + 'static,
92 {
93 Arc::new(self)
94 }
95}
96
97pub trait DashboardApiModuleExt {
99 fn get_module<M: ServerModule + 'static>(&self) -> Option<&M>;
101}
102
103impl DashboardApiModuleExt for DynDashboardApi {
104 fn get_module<M: ServerModule + 'static>(&self) -> Option<&M> {
105 self.get_module_by_kind(M::module_kind())?
106 .as_any()
107 .downcast_ref::<M>()
108 }
109}
110
111#[derive(Debug, Clone)]
112pub struct ServerBitcoinRpcStatus {
113 pub network: Network,
114 pub block_count: u64,
115 pub fee_rate: Feerate,
116 pub sync_progress: Option<f64>,
117}