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::PeerId;
7use fedimint_core::core::ModuleKind;
8use fedimint_core::module::ApiAuth;
9use fedimint_core::module::audit::AuditSummary;
10
11use crate::{DynServerModule, ServerModule};
12
13pub type DynDashboardApi = Arc<dyn IDashboardApi + Send + Sync + 'static>;
14
15/// Interface for guardian dashboard API in a running federation
16#[async_trait]
17pub trait IDashboardApi {
18    /// Get the guardian's authentication details
19    async fn auth(&self) -> ApiAuth;
20
21    /// Get the guardian ID
22    async fn guardian_id(&self) -> PeerId;
23
24    /// Get a map of peer IDs to guardian names
25    async fn guardian_names(&self) -> BTreeMap<PeerId, String>;
26
27    /// Get the federation name
28    async fn federation_name(&self) -> String;
29
30    /// Get the current active session count
31    async fn session_count(&self) -> usize;
32
33    /// The time it took to order our last proposal in the current session
34    async fn consensus_ord_latency(&self) -> Option<Duration>;
35
36    /// Returns a map of peer ID to estimated round trip time
37    async fn p2p_connection_status(&self) -> BTreeMap<PeerId, Option<Duration>>;
38
39    /// Get the federation invite code to share with users
40    async fn federation_invite_code(&self) -> String;
41
42    /// Get the federation audit summary
43    async fn federation_audit(&self) -> AuditSummary;
44
45    /// Get reference to a server module instance by module kind
46    fn get_module_by_kind(&self, kind: ModuleKind) -> Option<&DynServerModule>;
47
48    /// Create a trait object
49    fn into_dyn(self) -> DynDashboardApi
50    where
51        Self: Sized + Send + Sync + 'static,
52    {
53        Arc::new(self)
54    }
55}
56
57/// Extension trait for IDashboardApi providing type-safe module access
58pub trait DashboardApiModuleExt {
59    /// Get a typed reference to a server module instance by kind
60    fn get_module<M: ServerModule + 'static>(&self) -> Option<&M>;
61}
62
63impl DashboardApiModuleExt for DynDashboardApi {
64    fn get_module<M: ServerModule + 'static>(&self) -> Option<&M> {
65        self.get_module_by_kind(M::module_kind())?
66            .as_any()
67            .downcast_ref::<M>()
68    }
69}