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::net::auth::GuardianAuthToken;
12use fedimint_core::session_outcome::SessionStatusV2;
13use fedimint_core::util::SafeUrl;
14use fedimint_core::{Feerate, PeerId};
15use serde::{Deserialize, Serialize};
16
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 Mixed,
31}
32
33#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
35pub struct P2PConnectionStatus {
36 pub conn_type: Option<ConnectionType>,
38 pub rtt: Option<Duration>,
40}
41
42#[async_trait]
44pub trait IDashboardApi {
45 async fn auth(&self) -> ApiAuth;
47
48 async fn guardian_id(&self) -> PeerId;
50
51 async fn guardian_names(&self) -> BTreeMap<PeerId, String>;
53
54 async fn federation_name(&self) -> String;
56
57 async fn session_count(&self) -> u64;
59
60 async fn get_session_status(&self, session_idx: u64) -> SessionStatusV2;
62
63 async fn consensus_ord_latency(&self) -> Option<Duration>;
65
66 async fn p2p_connection_status(&self) -> BTreeMap<PeerId, Option<P2PConnectionStatus>>;
68
69 async fn federation_invite_code(&self) -> String;
71
72 async fn federation_audit(&self) -> AuditSummary;
74
75 async fn bitcoin_rpc_url(&self) -> SafeUrl;
77
78 async fn bitcoin_rpc_status(&self) -> Option<ServerBitcoinRpcStatus>;
80
81 async fn download_guardian_config_backup(
83 &self,
84 password: &str,
85 guardian_auth: &GuardianAuthToken,
86 ) -> GuardianConfigBackup;
87
88 fn get_module_by_kind(&self, kind: ModuleKind) -> Option<&DynServerModule>;
90
91 async fn fedimintd_version(&self) -> String;
93
94 async fn change_password(
96 &self,
97 new_password: &str,
98 current_password: &str,
99 guardian_auth: &GuardianAuthToken,
100 ) -> Result<(), String>;
101
102 fn into_dyn(self) -> DynDashboardApi
104 where
105 Self: Sized + Send + Sync + 'static,
106 {
107 Arc::new(self)
108 }
109}
110
111pub trait DashboardApiModuleExt {
113 fn get_module<M: ServerModule + 'static>(&self) -> Option<&M>;
115}
116
117impl DashboardApiModuleExt for DynDashboardApi {
118 fn get_module<M: ServerModule + 'static>(&self) -> Option<&M> {
119 self.get_module_by_kind(M::module_kind())?
120 .as_any()
121 .downcast_ref::<M>()
122 }
123}
124
125#[derive(Debug, Clone)]
126pub struct ServerBitcoinRpcStatus {
127 pub network: Network,
128 pub block_count: u64,
129 pub fee_rate: Feerate,
130 pub sync_progress: Option<f64>,
131}