Skip to main content

acta_maker_sdk/ws/vault/
config.rs

1use std::sync::Arc;
2use std::time::Duration;
3
4use crate::orders::SignerLike;
5use crate::ws::managed::{ChallengeSigning, ManagedWsConfig};
6use crate::ws::types::HelloData;
7
8#[derive(Clone)]
9pub struct VaultOperatorConfig {
10    pub managed: ManagedWsConfig,
11    pub request_timeout: Duration,
12    pub(super) vault_pda: crate::Address32,
13    pub(super) operator: Arc<dyn SignerLike + Send + Sync>,
14}
15
16impl VaultOperatorConfig {
17    #[must_use]
18    pub fn new(
19        products: crate::ProductSet,
20        url: impl Into<String>,
21        hello: HelloData,
22        vault_pda: impl Into<crate::Address32>,
23        operator: Arc<dyn SignerLike + Send + Sync>,
24    ) -> Self {
25        let vault_pda = vault_pda.into();
26        let managed = ManagedWsConfig::new_with_signing(
27            url,
28            hello,
29            crate::Address32::new(operator.pubkey_bytes()),
30            ChallengeSigning::Local(Arc::clone(&operator)),
31        )
32        .with_vault_auth(vault_pda, products);
33        Self {
34            managed,
35            request_timeout: Duration::from_secs(5),
36            vault_pda,
37            operator,
38        }
39    }
40
41    #[must_use]
42    pub fn with_managed(mut self, adjust: impl FnOnce(ManagedWsConfig) -> ManagedWsConfig) -> Self {
43        self.managed = adjust(self.managed);
44        self
45    }
46
47    #[must_use]
48    pub const fn with_request_timeout(mut self, timeout: Duration) -> Self {
49        self.request_timeout = timeout;
50        self
51    }
52
53    #[must_use]
54    pub fn vault_pda(&self) -> &crate::Address32 {
55        &self.vault_pda
56    }
57
58    #[must_use]
59    pub fn operator_pubkey(&self) -> crate::Address32 {
60        crate::Address32::new(self.operator.pubkey_bytes())
61    }
62}