| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- use serde::de::DeserializeOwned;
- use serde::{Deserialize, Serialize};
- use std::{
- fs,
- marker::PhantomData,
- net::SocketAddr,
- path::{Path, PathBuf},
- str,
- };
- use crate::{Error, Result};
- #[derive(Clone, Default)]
- pub struct Config<T> {
- config: PhantomData<T>,
- }
- impl<T: Serialize + DeserializeOwned> Config<T> {
- pub fn load(path: PathBuf) -> Result<T> {
- if Path::new(&path).exists() {
- let toml = fs::read(&path)?;
- let str_buff = str::from_utf8(&toml)?;
- let config: T = toml::from_str(str_buff)?;
- Ok(config)
- } else {
- println!("Could not parse configuration");
- println!("Please follow the instructions in the README");
- Err(Error::ConfigNotFound)
- }
- }
- }
- /// The configuration for drk
- #[derive(Clone, Serialize, Deserialize, Debug)]
- pub struct DrkConfig {
- /// The URL where darkfid RPC is listening on
- pub darkfid_rpc_url: String,
- }
- /// The configuration for darkfid
- #[derive(Clone, Serialize, Deserialize, Debug)]
- pub struct DarkfidConfig {
- /// The address where darkfid should bind its RPC socket
- pub rpc_listen_address: SocketAddr,
- /// Whether to listen with TLS or plain TCP
- pub serve_tls: bool,
- /// Path to DER-formatted PKCS#12 archive. (Unused if serve_tls=false)
- pub tls_identity_path: String,
- /// Password for the TLS identity. (Unused if serve_tls=false)
- pub tls_identity_password: String,
- /// The RPC endpoint for a selected cashier
- pub cashier_rpc_url: String,
- /// Path to the client database
- pub database_path: String,
- /// Path to the wallet database
- pub wallet_path: String,
- /// The wallet password
- pub wallet_password: String,
- }
- /// The configuration for gatewayd
- #[derive(Serialize, Deserialize, Debug)]
- pub struct GatewaydConfig {
- /// The address where gatewayd should bind its protocol socket
- pub protocol_listen_address: SocketAddr,
- /// The address where gatewayd should bind its publisher socket
- pub publisher_listen_address: SocketAddr,
- /// Whether to listen with TLS or plain TCP
- pub serve_tls: bool,
- /// Path to DER-formatted PKCS#12 archive. (Unused if serve_tls=false)
- pub tls_identity_path: String,
- /// Password for the TLS identity. (Unused if serve_tls=false)
- pub tls_identity_password: String,
- /// Path to the database
- pub database_path: String,
- }
- #[derive(Clone, Debug, Serialize, Deserialize)]
- pub struct FeatureNetwork {
- /// Network name
- pub name: String,
- /// Blockchain (mainnet/testnet/etc.)
- pub blockchain: String,
- }
- #[derive(Clone, Serialize, Deserialize, Debug)]
- pub struct CashierdConfig {
- /// The endpoint where cashierd will bind its RPC socket
- pub rpc_listen_address: SocketAddr,
- /// Whether to listen with TLS or plain TCP
- pub serve_tls: bool,
- /// Path to DER-formatted PKCS#12 archive. (Unused if serve_tls=false)
- pub tls_identity_path: String,
- /// Password for the TLS identity. (Unused if serve_tls=false)
- pub tls_identity_password: String,
- /// The endpoint to a gatewayd protocol API
- pub gateway_protocol_url: String,
- /// The endpoint to a gatewayd publisher API
- pub gateway_publisher_url: String,
- /// Path to mint.params
- pub mint_params_path: String,
- /// Path to spend.params
- pub spend_params_path: String,
- /// Path to cashierd wallet
- pub cashier_wallet_path: String,
- /// Password for cashierd wallet
- pub cashier_wallet_password: String,
- /// Path to client wallet
- pub client_wallet_path: String,
- /// Password for client wallet
- pub client_wallet_password: String,
- /// Path to database
- pub database_path: String,
- /// The configured networks to use
- pub networks: Vec<FeatureNetwork>,
- }
|