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