Skip to main content

glsdk/
config.rs

1// SDK configuration for Greenlight node operations.
2// Holds network selection and optional developer certificate.
3
4use std::sync::Arc;
5use crate::credentials::DeveloperCert;
6use crate::Network;
7
8#[derive(uniffi::Object, Clone)]
9pub struct Config {
10    pub(crate) network: gl_client::bitcoin::Network,
11    pub(crate) developer_cert: Option<gl_client::credentials::Nobody>,
12}
13
14impl Config {
15    /// Resolve the credentials to use for unauthenticated scheduler
16    /// calls (register, recover). Uses the developer certificate if
17    /// one was provided, otherwise falls back to the compiled-in default.
18    pub(crate) fn nobody(&self) -> gl_client::credentials::Nobody {
19        self.developer_cert
20            .clone()
21            .unwrap_or_else(gl_client::credentials::Nobody::new)
22    }
23}
24
25#[uniffi::export]
26impl Config {
27    /// Create a Config with default settings: BITCOIN network, no developer certificate.
28    #[uniffi::constructor()]
29    pub fn new() -> Self {
30        Self {
31            network: gl_client::bitcoin::Network::Bitcoin,
32            developer_cert: None,
33        }
34    }
35
36    /// Return a new Config with the given developer certificate.
37    /// Nodes registered through this config will be associated with the developer's account.
38    pub fn with_developer_cert(&self, cert: &DeveloperCert) -> Arc<Config> {
39        Arc::new(Config {
40            developer_cert: Some(cert.inner.clone()),
41            ..self.clone()
42        })
43    }
44
45    /// Return a new Config with the given network.
46    pub fn with_network(&self, network: Network) -> Arc<Config> {
47        Arc::new(Config {
48            network: network.into(),
49            ..self.clone()
50        })
51    }
52}