extern crate alloc;
use alloc::string::String;
use alloy_primitives::Address;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use url::Url;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TangleSettings {
pub blueprint_id: u64,
pub service_id: Option<u64>,
pub tangle_contract: Address,
pub restaking_contract: Address,
pub status_registry_contract: Address,
}
impl Default for TangleSettings {
fn default() -> Self {
Self {
blueprint_id: 0,
service_id: None,
tangle_contract: Address::ZERO,
restaking_contract: Address::ZERO,
status_registry_contract: Address::ZERO,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TangleClientConfig {
pub http_rpc_endpoint: Url,
pub ws_rpc_endpoint: Url,
pub keystore_uri: String,
pub data_dir: PathBuf,
pub settings: TangleSettings,
pub test_mode: bool,
#[serde(default)]
pub dry_run: bool,
}
impl TangleClientConfig {
pub fn new(
http_rpc_endpoint: impl Into<Url>,
ws_rpc_endpoint: impl Into<Url>,
keystore_uri: impl Into<String>,
settings: TangleSettings,
) -> Self {
Self {
http_rpc_endpoint: http_rpc_endpoint.into(),
ws_rpc_endpoint: ws_rpc_endpoint.into(),
keystore_uri: keystore_uri.into(),
data_dir: PathBuf::default(),
settings,
test_mode: false,
dry_run: false,
}
}
pub fn data_dir(mut self, path: impl Into<PathBuf>) -> Self {
self.data_dir = path.into();
self
}
pub fn test_mode(mut self, test_mode: bool) -> Self {
self.test_mode = test_mode;
self
}
pub fn dry_run(mut self, dry_run: bool) -> Self {
self.dry_run = dry_run;
self
}
pub fn keystore_config(&self) -> blueprint_keystore::KeystoreConfig {
blueprint_keystore::KeystoreConfig::new().fs_root(self.keystore_uri.replace("file://", ""))
}
}