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 fedimintd_version_hash(&self) -> Option<String>;
97
98 async fn change_password(
100 &self,
101 new_password: &str,
102 current_password: &str,
103 guardian_auth: &GuardianAuthToken,
104 ) -> Result<(), String>;
105
106 fn into_dyn(self) -> DynDashboardApi
108 where
109 Self: Sized + Send + Sync + 'static,
110 {
111 Arc::new(self)
112 }
113}
114
115pub trait DashboardApiModuleExt {
117 fn get_module<M: ServerModule + 'static>(&self) -> Option<&M>;
119}
120
121impl DashboardApiModuleExt for DynDashboardApi {
122 fn get_module<M: ServerModule + 'static>(&self) -> Option<&M> {
123 self.get_module_by_kind(M::module_kind())?
124 .as_any()
125 .downcast_ref::<M>()
126 }
127}
128
129#[derive(Debug, Clone)]
130pub struct ServerBitcoinRpcStatus {
131 pub network: Network,
132 pub block_count: u64,
133 pub fee_rate: Feerate,
134 pub sync_progress: Option<f64>,
135}