| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- use crate::{Error, Result};
- use serde::de::DeserializeOwned;
- use serde::{Deserialize, Serialize};
- use std::marker::PhantomData;
- use std::{
- fs,
- path::{Path, PathBuf},
- str,
- };
- #[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.clone())?;
- Ok(config)
- } else {
- println!("No config files were found in .config/darkfi. Please follow the instructions in the README and add default configs.");
- Err(Error::ConfigNotFound)
- }
- }
- }
- #[derive(Serialize, Deserialize, Debug)]
- pub struct DrkConfig {
- pub rpc_url: String,
- pub log_path: String,
- }
- #[derive(Clone, Serialize, Deserialize, Debug)]
- pub struct DarkfidConfig {
- #[serde(rename = "connect_url")]
- pub connect_url: String,
- #[serde(rename = "subscriber_url")]
- pub subscriber_url: String,
- #[serde(rename = "cashier_url")]
- pub cashier_url: String,
- #[serde(rename = "rpc_url")]
- pub rpc_url: String,
- #[serde(rename = "database_path")]
- pub database_path: String,
- #[serde(rename = "walletdb_path")]
- pub walletdb_path: String,
- #[serde(rename = "log_path")]
- pub log_path: String,
- #[serde(rename = "password")]
- pub password: String,
- }
- #[derive(Serialize, Deserialize, Debug)]
- pub struct GatewaydConfig {
- #[serde(rename = "connect_url")]
- pub accept_url: String,
- #[serde(rename = "publisher_url")]
- pub publisher_url: String,
- #[serde(rename = "log_path")]
- pub log_path: String,
- }
- #[derive(Clone, Serialize, Deserialize, Debug)]
- pub struct CashierdConfig {
- #[serde(rename = "accept_url")]
- pub accept_url: String,
- #[serde(rename = "rpc_url")]
- pub rpc_url: String,
- #[serde(rename = "gateway_url")]
- pub gateway_url: String,
- #[serde(rename = "gateway_subscriber_url")]
- pub gateway_subscriber_url: String,
- #[serde(rename = "log_path")]
- pub log_path: String,
- #[serde(rename = "database_path")]
- pub database_path: String,
- #[serde(rename = "cashierdb_path")]
- pub cashierdb_path: String,
- #[serde(rename = "password")]
- pub password: String,
- #[serde(rename = "client_password")]
- pub client_password: String,
- }
|