| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- 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(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(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 = "log_path")]
- pub log_path: String,
- #[serde(rename = "password")]
- pub password: String,
- #[serde(rename = "client_password")]
- pub client_password: String,
- }
|