| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- use crate::util::join_config_path;
- use crate::Result;
- use serde::{Deserialize, Serialize};
- use std::str;
- use std::{
- fs,
- fs::{create_dir_all, File},
- io::Write,
- };
- use std::path::PathBuf;
- #[derive(Serialize, Deserialize, Debug)]
- pub struct DrkConfig {
- #[serde(default)]
- pub rpc_url: String,
- #[serde(default)]
- pub log_path: String,
- }
- impl DrkConfig {
- pub fn load(path: PathBuf) -> Result<Self> {
- let toml = fs::read(&path)?;
- let str_buff = str::from_utf8(&toml)?;
- let config: Self = toml::from_str(str_buff)?;
- Ok(config)
- }
- pub fn load_default(path: PathBuf) -> Result<Self> {
- let toml = Self::default();
- let config_file = toml::to_string(&toml)?;
- if let Some(outdir) = path.parent() {
- create_dir_all(outdir)?;
- }
- let mut file = File::create(path.clone())?;
- file.write_all(&config_file.into_bytes())?;
- let config = Self::load(path)?;
- Ok(config)
- }
- }
- impl Default for DrkConfig {
- fn default() -> Self {
- let rpc_url = String::from("http://127.0.0.1:8000");
- let log_path = String::from("/tmp/drk_cli.log");
- Self { rpc_url, log_path }
- }
- }
- #[derive(Serialize, Deserialize, Debug)]
- pub struct DarkfidConfig {
- #[serde(default)]
- #[serde(rename = "connect_url")]
- pub connect_url: String,
- #[serde(default)]
- #[serde(rename = "subscriber_url")]
- pub subscriber_url: String,
- #[serde(default)]
- #[serde(rename = "rpc_url")]
- pub rpc_url: String,
- #[serde(default)]
- #[serde(rename = "database_path")]
- pub database_path: String,
- #[serde(default)]
- #[serde(rename = "log_path")]
- pub log_path: String,
- #[serde(default)]
- #[serde(rename = "password")]
- pub password: String,
- }
- impl DarkfidConfig {
- pub fn load(path: PathBuf) -> Result<Self> {
- let toml = fs::read(&path)?;
- let str_buff = str::from_utf8(&toml)?;
- let config: Self = toml::from_str(str_buff)?;
- Ok(config)
- }
- pub fn load_default(path: PathBuf) -> Result<Self> {
- let toml = Self::default();
- let config_file = toml::to_string(&toml)?;
- if let Some(outdir) = path.parent() {
- create_dir_all(outdir)?;
- }
- let mut file = File::create(path.clone())?;
- file.write_all(&config_file.into_bytes())?;
- let config = Self::load(path)?;
- Ok(config)
- }
- }
- impl Default for DarkfidConfig {
- fn default() -> Self {
- let connect_url = String::from("127.0.0.1:3333");
- let subscriber_url = String::from("127.0.0.1:4444");
- let rpc_url = String::from("127.0.0.1:8000");
- let database_path = String::from("database_client.db");
- let database_path = join_config_path(&PathBuf::from(database_path))
- .expect("error during join database_path to config path");
- let database_path = String::from(
- database_path
- .to_str()
- .expect("error convert Path to String"),
- );
- let log_path = String::from("/tmp/darkfid_service_daemon.log");
- let password = String::new();
- Self {
- connect_url,
- subscriber_url,
- rpc_url,
- database_path,
- log_path,
- password,
- }
- }
- }
- #[derive(Serialize, Deserialize, Debug)]
- pub struct GatewaydConfig {
- #[serde(default)]
- #[serde(rename = "connect_url")]
- pub accept_url: String,
- #[serde(default)]
- #[serde(rename = "publisher_url")]
- pub publisher_url: String,
- #[serde(default)]
- #[serde(rename = "database_path")]
- pub database_path: String,
- #[serde(default)]
- #[serde(rename = "log_path")]
- pub log_path: String,
- }
- impl GatewaydConfig {
- pub fn load(path: PathBuf) -> Result<Self> {
- let toml = fs::read(&path)?;
- let str_buff = str::from_utf8(&toml)?;
- let config: Self = toml::from_str(str_buff)?;
- Ok(config)
- }
- pub fn load_default(path: PathBuf) -> Result<Self> {
- let toml = Self::default();
- let config_file = toml::to_string(&toml)?;
- if let Some(outdir) = path.parent() {
- create_dir_all(outdir)?;
- }
- let mut file = File::create(path.clone())?;
- file.write_all(&config_file.into_bytes())?;
- let config = Self::load(path)?;
- Ok(config)
- }
- }
- impl Default for GatewaydConfig {
- fn default() -> Self {
- let accept_url = String::from("127.0.0.1:3333");
- let publisher_url = String::from("127.0.0.1:4444");
- let database_path = String::from("gatewayd.db");
- let log_path = String::from("/tmp/gatewayd.log");
- Self {
- accept_url,
- publisher_url,
- database_path,
- log_path,
- }
- }
- }
- #[derive(Serialize, Deserialize, Debug)]
- pub struct CashierdConfig {
- #[serde(default)]
- #[serde(rename = "connect_url")]
- pub accept_url: String,
- #[serde(default)]
- #[serde(rename = "database_path")]
- pub database_path: String,
- #[serde(default)]
- #[serde(rename = "log_path")]
- pub log_path: String,
- #[serde(default)]
- #[serde(rename = "password")]
- pub password: String,
- }
- impl CashierdConfig {
- pub fn load(path: PathBuf) -> Result<Self> {
- let toml = fs::read(&path)?;
- let str_buff = str::from_utf8(&toml)?;
- let config: Self = toml::from_str(str_buff)?;
- Ok(config)
- }
- pub fn load_default(path: PathBuf) -> Result<Self> {
- let toml = Self::default();
- let config_file = toml::to_string(&toml)?;
- if let Some(outdir) = path.parent() {
- create_dir_all(outdir)?;
- }
- let mut file = File::create(path.clone())?;
- file.write_all(&config_file.into_bytes())?;
- let config = Self::load(path)?;
- Ok(config)
- }
- }
- impl Default for CashierdConfig {
- fn default() -> Self {
- let accept_url = String::from("127.0.0.1:7777");
- let database_path = String::from("cashierd.db");
- let log_path = String::from("/tmp/cashierd.log");
- let password = String::new();
- Self {
- accept_url,
- database_path,
- log_path,
- password,
- }
- }
- }
|