Skip to main content

fedimint_server_core/
setup_ui.rs

1use std::collections::BTreeSet;
2use std::sync::Arc;
3
4use anyhow::Result;
5use async_trait::async_trait;
6use fedimint_core::core::ModuleKind;
7use fedimint_core::module::ApiAuth;
8
9pub type DynSetupApi = Arc<dyn ISetupApi + Send + Sync + 'static>;
10
11/// Interface for the web UI to interact with the config generation process
12#[async_trait]
13pub trait ISetupApi {
14    /// Get our connection info encoded as base32 string
15    async fn setup_code(&self) -> Option<String>;
16
17    /// Get our guardian name
18    async fn guardian_name(&self) -> Option<String>;
19
20    /// Get the auth token for API calls
21    async fn auth(&self) -> Option<ApiAuth>;
22
23    /// Get list of names of connected peers
24    async fn connected_peers(&self) -> Vec<String>;
25
26    /// Get the available modules that can be enabled during setup
27    fn available_modules(&self) -> BTreeSet<ModuleKind>;
28
29    /// Get the modules that should be enabled by default in the setup UI
30    fn default_modules(&self) -> BTreeSet<ModuleKind>;
31
32    /// Reset the set of other guardians
33    async fn reset_setup_codes(&self);
34
35    /// Set local guardian parameters
36    async fn set_local_parameters(
37        &self,
38        auth: ApiAuth,
39        name: String,
40        federation_name: Option<String>,
41        disable_base_fees: Option<bool>,
42        enabled_modules: Option<BTreeSet<ModuleKind>>,
43        federation_size: Option<u32>,
44    ) -> Result<String>;
45
46    /// Add peer connection info
47    async fn add_peer_setup_code(&self, info: String) -> Result<String>;
48
49    /// Start the distributed key generation process
50    async fn start_dkg(&self) -> Result<()>;
51
52    /// Returns the expected federation size if any setup code (ours or a
53    /// peer's) has set it
54    async fn federation_size(&self) -> Option<u32>;
55
56    /// Returns the federation name if set by any setup code
57    async fn cfg_federation_name(&self) -> Option<String>;
58
59    /// Returns whether base fees are disabled, if set by any setup code
60    async fn cfg_base_fees_disabled(&self) -> Option<bool>;
61
62    /// Returns the enabled modules, if set by any setup code
63    async fn cfg_enabled_modules(&self) -> Option<BTreeSet<ModuleKind>>;
64
65    /// Create a trait object
66    fn into_dyn(self) -> DynSetupApi
67    where
68        Self: Sized + Send + Sync + 'static,
69    {
70        Arc::new(self)
71    }
72}