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    /// Password protecting the setup UI login form. `None` means the UI is
21    /// served without a login form.
22    fn auth_ui(&self) -> Option<ApiAuth>;
23
24    /// Get list of names of connected peers
25    async fn connected_peers(&self) -> Vec<String>;
26
27    /// Get the available modules that can be enabled during setup
28    fn available_modules(&self) -> BTreeSet<ModuleKind>;
29
30    /// Get the modules that should be enabled by default in the setup UI
31    fn default_modules(&self) -> BTreeSet<ModuleKind>;
32
33    /// Reset the set of other guardians
34    async fn reset_setup_codes(&self);
35
36    /// Set local guardian parameters
37    async fn set_local_parameters(
38        &self,
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    /// Restore this guardian from a config backup archive. The password is
53    /// only required for legacy encrypted backups; current plaintext backups
54    /// restore without one.
55    async fn restore_from_backup(&self, password: Option<String>, backup: Vec<u8>) -> Result<()>;
56
57    /// Returns the expected federation size if any setup code (ours or a
58    /// peer's) has set it
59    async fn federation_size(&self) -> Option<u32>;
60
61    /// Returns the federation name if set by any setup code
62    async fn cfg_federation_name(&self) -> Option<String>;
63
64    /// Returns whether base fees are disabled, if set by any setup code
65    async fn cfg_base_fees_disabled(&self) -> Option<bool>;
66
67    /// Returns the enabled modules, if set by any setup code
68    async fn cfg_enabled_modules(&self) -> Option<BTreeSet<ModuleKind>>;
69
70    /// Get the fedimintd version
71    async fn fedimintd_version(&self) -> String;
72
73    /// Get the git hash of the fedimintd binary, or `None` if it is not
74    /// available (e.g. it was built outside a git checkout).
75    async fn fedimintd_version_hash(&self) -> Option<String>;
76
77    /// Create a trait object
78    fn into_dyn(self) -> DynSetupApi
79    where
80        Self: Sized + Send + Sync + 'static,
81    {
82        Arc::new(self)
83    }
84}