cli_config.rs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //use crate::serial::{deserialize, serialize, Decodable, Encodable};
  2. //use toml::{map::Map, Value};
  3. use crate::util::join_config_path;
  4. //use crate::Result;
  5. use serde::{Deserialize, Serialize};
  6. //use log::*;
  7. use std::{fs::OpenOptions, io::prelude::*, path::PathBuf};
  8. //pub trait ClientConfig: Default + Deserialize {
  9. // fn load(path: PathBuf) -> Result<Self> {
  10. // let path = join_config_path(&path)?;
  11. // let mut file = OpenOptions::new()
  12. // .read(true)
  13. // .write(true)
  14. // .create(true)
  15. // .open(path)?;
  16. //
  17. // //let mut toml_map = Map::new();
  18. // let mut buffer = String::new();
  19. // file.read_to_string(&mut buffer)?;
  20. // //let buffer: &'static str = buffer;
  21. //
  22. // //let tomlstring = toml::to_string(&file).expect("Could not encode TTOML value");
  23. // if !buffer.is_empty() {
  24. // let config: Self = toml::from_str(&buffer)?;
  25. // //let config = toml::to_string(&buffer).unwrap();
  26. // //let config: Self = deserialize(&buffer)?;
  27. // //Ok(config)
  28. // Ok(config)
  29. // } else {
  30. // Ok(Self::default())
  31. // }
  32. // }
  33. // fn save(&self, path: PathBuf) -> Result<()> {
  34. // //let path = join_config_path(&path)?;
  35. // //let mut file = OpenOptions::new().write(true).create(true).open(&path)?;
  36. // //let serialized = serialize(self);
  37. // //file.write_all(&serialized)?;
  38. // Ok(())
  39. // }
  40. //}
  41. //
  42. //impl ClientConfig for DrkConfig {}
  43. //impl ClientConfig for DarkfidConfig {}
  44. #[derive(Serialize, Default, Deserialize, Debug)]
  45. pub struct DrkConfig {
  46. #[serde(rename = "rpc_url")]
  47. pub rpc_url: String,
  48. #[serde(rename = "log_path")]
  49. pub log_path: String,
  50. }
  51. #[derive(Serialize, Default, Deserialize, Debug)]
  52. pub struct DarkfidConfig {
  53. #[serde(rename = "connect_url")]
  54. pub connect_url: String,
  55. #[serde(rename = "subscriber_url")]
  56. pub subscriber_url: String,
  57. #[serde(rename = "rpc_url")]
  58. pub rpc_url: String,
  59. #[serde(rename = "database_path")]
  60. pub database_path: String,
  61. #[serde(rename = "log_path")]
  62. pub log_path: String,
  63. #[serde(rename = "password")]
  64. pub password: String,
  65. }
  66. #[derive(Serialize, Default, Deserialize, Debug)]
  67. pub struct GatewaydConfig {
  68. #[serde(rename = "connect_url")]
  69. pub accept_url: String,
  70. #[serde(rename = "subscriber_url")]
  71. pub publisher_url: String,
  72. #[serde(rename = "database_path")]
  73. pub database_path: String,
  74. #[serde(rename = "log_path")]
  75. pub log_path: String,
  76. }
  77. #[derive(Serialize, Default, Deserialize, Debug)]
  78. pub struct CashierdConfig {
  79. #[serde(rename = "connect_url")]
  80. pub accept_url: String,
  81. #[serde(rename = "database_path")]
  82. pub database_path: String,
  83. #[serde(rename = "log_path")]
  84. pub log_path: String,
  85. }
  86. //impl Default for DrkCliConfig {
  87. // // default toml file
  88. // fn default() -> Self {
  89. // let rpc_url = String::from("http://127.0.0.1:8000");
  90. // let log_path = String::from("/tmp/drk_cli.log");
  91. // Self {
  92. // rpc_url,
  93. // log_path,
  94. // }
  95. // }
  96. //}
  97. //impl Default for DarkfidCliConfig {
  98. // // create default config file
  99. // fn default() -> Self {
  100. // //toml::toml! {
  101. // // connect-url = "127.0.0.1:3333"
  102. // //};
  103. // let connect_url = String::from("127.0.0.1:3333");
  104. // let subscriber_url = String::from("127.0.0.1:4444");
  105. // let rpc_url = String::from("127.0.0.1:8000");
  106. //
  107. // let database_path = String::from("database_client.db");
  108. // let database_path = join_config_path(&PathBuf::from(database_path))
  109. // .expect("error during join database_path to config path");
  110. // let database_path = String::from(
  111. // database_path
  112. // .to_str()
  113. // .expect("error convert Path to String"),
  114. // );
  115. // let log_path = String::from("/tmp/darkfid_service_daemon.log");
  116. //
  117. // let password = String::new();
  118. // Self {
  119. // connect_url,
  120. // subscriber_url,
  121. // rpc_url,
  122. // database_path,
  123. // log_path,
  124. // password,
  125. // }
  126. // }
  127. //}