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    /// Restore this guardian from a config backup archive
53    async fn restore_from_backup(&self, password: String, backup: Vec<u8>) -> Result<()>;
54
55    /// Returns the expected federation size if any setup code (ours or a
56    /// peer's) has set it
57    async fn federation_size(&self) -> Option<u32>;
58
59    /// Returns the federation name if set by any setup code
60    async fn cfg_federation_name(&self) -> Option<String>;
61
62    /// Returns whether base fees are disabled, if set by any setup code
63    async fn cfg_base_fees_disabled(&self) -> Option<bool>;
64
65    /// Returns the enabled modules, if set by any setup code
66    async fn cfg_enabled_modules(&self) -> Option<BTreeSet<ModuleKind>>;
67
68    /// Get the fedimintd version
69    async fn fedimintd_version(&self) -> String;
70
71    /// Get the git hash of the fedimintd binary, or `None` if it is not
72    /// available (e.g. it was built outside a git checkout).
73    async fn fedimintd_version_hash(&self) -> Option<String>;
74
75    /// Create a trait object
76    fn into_dyn(self) -> DynSetupApi
77    where
78        Self: Sized + Send + Sync + 'static,
79    {
80        Arc::new(self)
81    }
82}