cli_config.rs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 ClientCliConfig<'a>: Default + Deserialize<'a> {
  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. //impl ClientCliConfig<'_> for DrkCliConfig {}
  42. //impl ClientCliConfig<'_> for DarkfidCliConfig {}
  43. //#[derive(Serialize, Default, Deserialize, Debug)]
  44. //pub struct Configs {
  45. // pub drk: DrkCliConfig,
  46. // pub darkfid: DarkfidCliConfig,
  47. //}
  48. #[derive(Serialize, Default, Deserialize, Debug)]
  49. pub struct DrkConfig {
  50. #[serde(rename = "RPC URL")]
  51. pub rpc_url: String,
  52. #[serde(rename = "Log path")]
  53. pub log_path: String,
  54. }
  55. #[derive(Serialize, Default, Deserialize, Debug)]
  56. pub struct DarkfidConfig {
  57. #[serde(rename = "Connect URL")]
  58. pub connect_url: String,
  59. #[serde(rename = "Subscriber URL")]
  60. pub subscriber_url: String,
  61. #[serde(rename = "RPC URL")]
  62. pub rpc_url: String,
  63. #[serde(rename = "Database path")]
  64. pub database_path: String,
  65. #[serde(rename = "Log path")]
  66. pub log_path: String,
  67. #[serde(rename = "Password")]
  68. pub password: String,
  69. }
  70. //impl Default for DrkCliConfig {
  71. // // default toml file
  72. // fn default() -> Self {
  73. // let rpc_url = String::from("http://127.0.0.1:8000");
  74. // let log_path = String::from("/tmp/drk_cli.log");
  75. // Self {
  76. // rpc_url,
  77. // log_path,
  78. // }
  79. // }
  80. //}
  81. //impl Default for DarkfidCliConfig {
  82. // // create default config file
  83. // fn default() -> Self {
  84. // //toml::toml! {
  85. // // connect-url = "127.0.0.1:3333"
  86. // //};
  87. // let connect_url = String::from("127.0.0.1:3333");
  88. // let subscriber_url = String::from("127.0.0.1:4444");
  89. // let rpc_url = String::from("127.0.0.1:8000");
  90. //
  91. // let database_path = String::from("database_client.db");
  92. // let database_path = join_config_path(&PathBuf::from(database_path))
  93. // .expect("error during join database_path to config path");
  94. // let database_path = String::from(
  95. // database_path
  96. // .to_str()
  97. // .expect("error convert Path to String"),
  98. // );
  99. // let log_path = String::from("/tmp/darkfid_service_daemon.log");
  100. //
  101. // let password = String::new();
  102. // Self {
  103. // connect_url,
  104. // subscriber_url,
  105. // rpc_url,
  106. // database_path,
  107. // log_path,
  108. // password,
  109. // }
  110. // }
  111. //}