Skip to main content

blueprint_client_tangle/
config.rs

1//! Tangle Client Configuration
2//!
3//! This module provides configuration types for the Tangle client that don't
4//! create cyclic dependencies with the runner crate.
5
6extern crate alloc;
7
8use alloc::string::String;
9use alloy_primitives::Address;
10use serde::{Deserialize, Serialize};
11use std::path::PathBuf;
12use url::Url;
13
14/// Protocol settings for Tangle
15///
16/// This contains the EVM-specific configuration for connecting to Tangle contracts.
17#[derive(Debug, Clone, Serialize, Deserialize)]
18pub struct TangleSettings {
19    /// The blueprint ID registered in the Tangle contract
20    pub blueprint_id: u64,
21    /// The service ID for the Tangle blueprint instance
22    ///
23    /// Note: This will be `None` if running in Registration Mode.
24    pub service_id: Option<u64>,
25    /// The Tangle core contract address
26    pub tangle_contract: Address,
27    /// The MultiAssetDelegation (restaking) contract address
28    pub restaking_contract: Address,
29    /// Operator status registry contract used for heartbeats
30    pub status_registry_contract: Address,
31}
32
33impl Default for TangleSettings {
34    fn default() -> Self {
35        Self {
36            blueprint_id: 0,
37            service_id: None,
38            // Default to zero address - must be configured
39            tangle_contract: Address::ZERO,
40            restaking_contract: Address::ZERO,
41            status_registry_contract: Address::ZERO,
42        }
43    }
44}
45
46/// Client configuration for connecting to Tangle contracts
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct TangleClientConfig {
49    /// HTTP RPC endpoint for the EVM network
50    pub http_rpc_endpoint: Url,
51    /// WebSocket RPC endpoint for the EVM network
52    pub ws_rpc_endpoint: Url,
53    /// Path to the keystore directory
54    pub keystore_uri: String,
55    /// Data directory for the client
56    pub data_dir: PathBuf,
57    /// Protocol-specific settings
58    pub settings: TangleSettings,
59    /// Whether the client is in test mode
60    pub test_mode: bool,
61    /// When true, avoid on-chain submissions from this client.
62    #[serde(default)]
63    pub dry_run: bool,
64}
65
66impl TangleClientConfig {
67    /// Create a new client config with required parameters
68    pub fn new(
69        http_rpc_endpoint: impl Into<Url>,
70        ws_rpc_endpoint: impl Into<Url>,
71        keystore_uri: impl Into<String>,
72        settings: TangleSettings,
73    ) -> Self {
74        Self {
75            http_rpc_endpoint: http_rpc_endpoint.into(),
76            ws_rpc_endpoint: ws_rpc_endpoint.into(),
77            keystore_uri: keystore_uri.into(),
78            data_dir: PathBuf::default(),
79            settings,
80            test_mode: false,
81            dry_run: false,
82        }
83    }
84
85    /// Set the data directory
86    pub fn data_dir(mut self, path: impl Into<PathBuf>) -> Self {
87        self.data_dir = path.into();
88        self
89    }
90
91    /// Set test mode
92    pub fn test_mode(mut self, test_mode: bool) -> Self {
93        self.test_mode = test_mode;
94        self
95    }
96
97    /// Set dry-run mode
98    pub fn dry_run(mut self, dry_run: bool) -> Self {
99        self.dry_run = dry_run;
100        self
101    }
102
103    /// Get keystore configuration
104    pub fn keystore_config(&self) -> blueprint_keystore::KeystoreConfig {
105        blueprint_keystore::KeystoreConfig::new().fs_root(self.keystore_uri.replace("file://", ""))
106    }
107}