fedimint_server_core/
dashboard_ui.rs

1use 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/// Interface for guardian dashboard API in a running federation
21#[async_trait]
22pub trait IDashboardApi {
23    /// Get the guardian's authentication details
24    async fn auth(&self) -> ApiAuth;
25
26    /// Get the guardian ID
27    async fn guardian_id(&self) -> PeerId;
28
29    /// Get a map of peer IDs to guardian names
30    async fn guardian_names(&self) -> BTreeMap<PeerId, String>;
31
32    /// Get the federation name
33    async fn federation_name(&self) -> String;
34
35    /// Get the current active session count
36    async fn session_count(&self) -> u64;
37
38    /// Get items in a given session
39    async fn get_session_status(&self, session_idx: u64) -> SessionStatusV2;
40
41    /// The time it took to order our last proposal in the current session
42    async fn consensus_ord_latency(&self) -> Option<Duration>;
43
44    /// Returns a map of peer ID to estimated round trip time
45    async fn p2p_connection_status(&self) -> BTreeMap<PeerId, Option<Duration>>;
46
47    /// Get the federation invite code to share with users
48    async fn federation_invite_code(&self) -> String;
49
50    /// Get the federation audit summary
51    async fn federation_audit(&self) -> AuditSummary;
52
53    /// Get the url of the bitcoin rpc
54    async fn bitcoin_rpc_url(&self) -> SafeUrl;
55
56    /// Get the status of the bitcoin backend
57    async fn bitcoin_rpc_status(&self) -> Option<ServerBitcoinRpcStatus>;
58
59    /// Download a backup of the guardian's configuration
60    async fn download_guardian_config_backup(
61        &self,
62        password: &str,
63        guardian_auth: &GuardianAuthToken,
64    ) -> GuardianConfigBackup;
65
66    /// Get reference to a server module instance by module kind
67    fn get_module_by_kind(&self, kind: ModuleKind) -> Option<&DynServerModule>;
68
69    /// Create a trait object
70    fn into_dyn(self) -> DynDashboardApi
71    where
72        Self: Sized + Send + Sync + 'static,
73    {
74        Arc::new(self)
75    }
76}
77
78/// Extension trait for IDashboardApi providing type-safe module access
79pub trait DashboardApiModuleExt {
80    /// Get a typed reference to a server module instance by kind
81    fn get_module<M: ServerModule + 'static>(&self) -> Option<&M>;
82}
83
84impl DashboardApiModuleExt for DynDashboardApi {
85    fn get_module<M: ServerModule + 'static>(&self) -> Option<&M> {
86        self.get_module_by_kind(M::module_kind())?
87            .as_any()
88            .downcast_ref::<M>()
89    }
90}
91
92#[derive(Debug, Clone)]
93pub struct ServerBitcoinRpcStatus {
94    pub network: Network,
95    pub block_count: u64,
96    pub fee_rate: Feerate,
97    pub sync_progress: Option<f64>,
98}