浏览代码

splitting config struct in src/cli between aps in bin/

Dastan-glitch 4 年之前
父节点
当前提交
a14355263c

+ 4 - 0
Cargo.lock

@@ -1442,6 +1442,7 @@ dependencies = [
  "log",
  "log",
  "num-bigint",
  "num-bigint",
  "num_cpus",
  "num_cpus",
+ "serde",
  "serde_json",
  "serde_json",
  "simplelog",
  "simplelog",
  "smol",
  "smol",
@@ -1681,6 +1682,7 @@ dependencies = [
  "darkfi",
  "darkfi",
  "log",
  "log",
  "prettytable-rs",
  "prettytable-rs",
+ "serde",
  "serde_json",
  "serde_json",
  "simplelog",
  "simplelog",
  "url",
  "url",
@@ -2175,6 +2177,7 @@ dependencies = [
  "easy-parallel",
  "easy-parallel",
  "log",
  "log",
  "num_cpus",
  "num_cpus",
+ "serde",
  "simplelog",
  "simplelog",
  "smol",
  "smol",
 ]
 ]
@@ -2845,6 +2848,7 @@ dependencies = [
  "log",
  "log",
  "num_cpus",
  "num_cpus",
  "rand 0.6.5",
  "rand 0.6.5",
+ "serde",
  "serde_json",
  "serde_json",
  "simplelog",
  "simplelog",
  "smol",
  "smol",

+ 1 - 3
bin/cashierd/Cargo.toml

@@ -29,7 +29,7 @@ thiserror = "1.0.30"
 url = "2.2.2"
 url = "2.2.2"
 
 
 # Encoding and parsing
 # Encoding and parsing
-serde = {version = "1.0.133", features = ["derive"], optional = true}
+serde = {version = "1.0.133", features = ["derive"]}
 serde_json = "1.0.74"
 serde_json = "1.0.74"
 
 
 # Bitcoin bridge dependencies
 # Bitcoin bridge dependencies
@@ -63,7 +63,6 @@ btc = [
 ]
 ]
 
 
 eth = [
 eth = [
-    "serde",
     "num-bigint",
     "num-bigint",
     "keccak-hasher",
     "keccak-hasher",
     "hash-db",
     "hash-db",
@@ -74,7 +73,6 @@ eth = [
 sol = [
 sol = [
     "async-native-tls",
     "async-native-tls",
     "native-tls",
     "native-tls",
-    "serde",
     "solana-client",
     "solana-client",
     "solana-sdk",
     "solana-sdk",
     "spl-associated-token-account",
     "spl-associated-token-account",

+ 47 - 2
bin/cashierd/src/main.rs

@@ -1,4 +1,4 @@
-use std::{path::PathBuf, str::FromStr};
+use std::{net::SocketAddr, path::PathBuf, str::FromStr};
 
 
 use async_executor::Executor;
 use async_executor::Executor;
 use async_std::sync::{Arc, Mutex};
 use async_std::sync::{Arc, Mutex};
@@ -7,6 +7,7 @@ use clap::{IntoApp, Parser};
 use easy_parallel::Parallel;
 use easy_parallel::Parallel;
 use log::{debug, info};
 use log::{debug, info};
 use rand::rngs::OsRng;
 use rand::rngs::OsRng;
+use serde::{Deserialize, Serialize};
 use serde_json::{json, Value};
 use serde_json::{json, Value};
 use simplelog::{ColorChoice, TermLogger, TerminalMode};
 use simplelog::{ColorChoice, TermLogger, TerminalMode};
 
 
@@ -14,7 +15,7 @@ use darkfi::{
     blockchain::{rocks::columns, Rocks, RocksColumn},
     blockchain::{rocks::columns, Rocks, RocksColumn},
     cli::{
     cli::{
         cli_config::{log_config, spawn_config},
         cli_config::{log_config, spawn_config},
-        CashierdConfig, Config,
+        Config,
     },
     },
     crypto::{
     crypto::{
         address::Address,
         address::Address,
@@ -39,6 +40,50 @@ use darkfi::{
 
 
 use cashierd::service::{bridge, bridge::Bridge};
 use cashierd::service::{bridge, bridge::Bridge};
 
 
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct FeatureNetwork {
+    /// Network name
+    pub name: String,
+    /// Blockchain (mainnet/testnet/etc.)
+    pub blockchain: String,
+    /// Keypair
+    pub keypair: String,
+}
+
+#[derive(Clone, Serialize, Deserialize, Debug)]
+pub struct CashierdConfig {
+    /// The DNS name of the cashier (can also be an IP, or a .onion address)
+    pub dns_addr: String,
+    /// The endpoint where cashierd will bind its RPC socket
+    pub rpc_listen_address: SocketAddr,
+    /// Whether to listen with TLS or plain TCP
+    pub serve_tls: bool,
+    /// Path to DER-formatted PKCS#12 archive. (Unused if serve_tls=false)
+    pub tls_identity_path: String,
+    /// Password for the TLS identity. (Unused if serve_tls=false)
+    pub tls_identity_password: String,
+    /// The endpoint to a gatewayd protocol API
+    pub gateway_protocol_url: String,
+    /// The endpoint to a gatewayd publisher API
+    pub gateway_publisher_url: String,
+    /// Path to cashierd wallet
+    pub cashier_wallet_path: String,
+    /// Password for cashierd wallet
+    pub cashier_wallet_password: String,
+    /// Path to client wallet
+    pub client_wallet_path: String,
+    /// Password for client wallet
+    pub client_wallet_password: String,
+    /// Path to database
+    pub database_path: String,
+    /// Geth IPC endpoint
+    pub geth_socket: String,
+    /// Geth passphrase
+    pub geth_passphrase: String,
+    /// The configured networks to use
+    pub networks: Vec<FeatureNetwork>,
+}
+
 /// Cashierd cli
 /// Cashierd cli
 #[derive(Parser)]
 #[derive(Parser)]
 #[clap(name = "cashierd")]
 #[clap(name = "cashierd")]

+ 1 - 0
bin/darkfid/Cargo.toml

@@ -25,4 +25,5 @@ simplelog = "0.11.2"
 
 
 # Encoding and parsing
 # Encoding and parsing
 serde_json = "1.0.74"
 serde_json = "1.0.74"
+serde = {version = "1.0.133", features = ["derive"]}
 num-bigint = {version = "0.4.3", features = ["serde"]}
 num-bigint = {version = "0.4.3", features = ["serde"]}

+ 38 - 2
bin/darkfid/src/main.rs

@@ -1,4 +1,4 @@
-use std::{collections::HashMap, path::PathBuf, str::FromStr};
+use std::{collections::HashMap, net::SocketAddr, path::PathBuf, str::FromStr};
 
 
 use async_executor::Executor;
 use async_executor::Executor;
 use async_std::sync::{Arc, Mutex};
 use async_std::sync::{Arc, Mutex};
@@ -7,6 +7,7 @@ use clap::{IntoApp, Parser};
 use easy_parallel::Parallel;
 use easy_parallel::Parallel;
 use log::{debug, info};
 use log::{debug, info};
 use num_bigint::BigUint;
 use num_bigint::BigUint;
+use serde::{Deserialize, Serialize};
 use serde_json::{json, Value};
 use serde_json::{json, Value};
 use simplelog::{ColorChoice, TermLogger, TerminalMode};
 use simplelog::{ColorChoice, TermLogger, TerminalMode};
 use url::Url;
 use url::Url;
@@ -15,7 +16,7 @@ use darkfi::{
     blockchain::{rocks::columns, Rocks, RocksColumn},
     blockchain::{rocks::columns, Rocks, RocksColumn},
     cli::{
     cli::{
         cli_config::{log_config, spawn_config},
         cli_config::{log_config, spawn_config},
-        Config, DarkfidConfig,
+        Config,
     },
     },
     crypto::{
     crypto::{
         address::Address,
         address::Address,
@@ -41,6 +42,41 @@ use darkfi::{
     Error, Result,
     Error, Result,
 };
 };
 
 
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct CashierC {
+    /// Cashier name
+    pub name: String,
+    /// The RPC endpoint for a selected cashier
+    pub rpc_url: String,
+    /// The selected cashier public key
+    pub public_key: String,
+}
+
+/// The configuration for darkfid
+#[derive(Clone, Serialize, Deserialize, Debug)]
+pub struct DarkfidConfig {
+    /// The address where darkfid should bind its RPC socket
+    pub rpc_listen_address: SocketAddr,
+    /// Whether to listen with TLS or plain TCP
+    pub serve_tls: bool,
+    /// Path to DER-formatted PKCS#12 archive. (Unused if serve_tls=false)
+    pub tls_identity_path: String,
+    /// Password for the TLS identity. (Unused if serve_tls=false)
+    pub tls_identity_password: String,
+    /// The endpoint to a gatewayd protocol API
+    pub gateway_protocol_url: String,
+    /// The endpoint to a gatewayd publisher API
+    pub gateway_publisher_url: String,
+    /// Path to the client database
+    pub database_path: String,
+    /// Path to the wallet database
+    pub wallet_path: String,
+    /// The wallet password
+    pub wallet_password: String,
+    /// The configured cashiers to use
+    pub cashiers: Vec<CashierC>,
+}
+
 /// Darkfid cli
 /// Darkfid cli
 #[derive(Parser)]
 #[derive(Parser)]
 #[clap(name = "darkfid")]
 #[clap(name = "darkfid")]

+ 1 - 0
bin/drk/Cargo.toml

@@ -20,3 +20,4 @@ url = "2.2.2"
 
 
 # Encoding and parsing
 # Encoding and parsing
 serde_json = "1.0.74"
 serde_json = "1.0.74"
+serde = {version = "1.0.133", features = ["derive"]}

+ 9 - 1
bin/drk/src/main.rs

@@ -3,6 +3,7 @@ use std::{path::PathBuf, str::FromStr};
 use clap::{AppSettings, IntoApp, Parser, Subcommand};
 use clap::{AppSettings, IntoApp, Parser, Subcommand};
 use log::{debug, error};
 use log::{debug, error};
 use prettytable::{cell, format, row, Table};
 use prettytable::{cell, format, row, Table};
+use serde::{Deserialize, Serialize};
 use serde_json::{json, Value};
 use serde_json::{json, Value};
 use simplelog::{ColorChoice, TermLogger, TerminalMode};
 use simplelog::{ColorChoice, TermLogger, TerminalMode};
 use url::Url;
 use url::Url;
@@ -10,13 +11,20 @@ use url::Url;
 use darkfi::{
 use darkfi::{
     cli::{
     cli::{
         cli_config::{log_config, spawn_config},
         cli_config::{log_config, spawn_config},
-        Config, DrkConfig,
+        Config,
     },
     },
     rpc::{jsonrpc, jsonrpc::JsonResult},
     rpc::{jsonrpc, jsonrpc::JsonResult},
     util::{join_config_path, path::expand_path, NetworkName},
     util::{join_config_path, path::expand_path, NetworkName},
     Error, Result,
     Error, Result,
 };
 };
 
 
+/// The configuration for drk
+#[derive(Clone, Serialize, Deserialize, Debug)]
+pub struct DrkConfig {
+    /// The URL where darkfid RPC is listening on
+    pub darkfid_rpc_url: String,
+}
+
 #[derive(Subcommand)]
 #[derive(Subcommand)]
 pub enum CliDrkSubCommands {
 pub enum CliDrkSubCommands {
     /// Say hello to the RPC
     /// Say hello to the RPC

+ 3 - 0
bin/gatewayd/Cargo.toml

@@ -20,3 +20,6 @@ clap = {version = "3.0.7", features = ["derive"]}
 log = "0.4.14"
 log = "0.4.14"
 num_cpus = "1.13.1"
 num_cpus = "1.13.1"
 simplelog = "0.11.2"
 simplelog = "0.11.2"
+
+# Encoding and parsing
+serde = {version = "1.0.133", features = ["derive"]}

+ 20 - 2
bin/gatewayd/src/main.rs

@@ -1,22 +1,40 @@
-use std::{path::PathBuf, sync::Arc};
+use std::{net::SocketAddr, path::PathBuf, sync::Arc};
 
 
 use async_executor::Executor;
 use async_executor::Executor;
 use clap::{IntoApp, Parser};
 use clap::{IntoApp, Parser};
 use easy_parallel::Parallel;
 use easy_parallel::Parallel;
 use log::debug;
 use log::debug;
+use serde::{Deserialize, Serialize};
 use simplelog::{ColorChoice, TermLogger, TerminalMode};
 use simplelog::{ColorChoice, TermLogger, TerminalMode};
 
 
 use darkfi::{
 use darkfi::{
     blockchain::{rocks::columns, Rocks, RocksColumn},
     blockchain::{rocks::columns, Rocks, RocksColumn},
     cli::{
     cli::{
         cli_config::{log_config, spawn_config},
         cli_config::{log_config, spawn_config},
-        Config, GatewaydConfig,
+        Config,
     },
     },
     node::service::gateway::GatewayService,
     node::service::gateway::GatewayService,
     util::{expand_path, join_config_path},
     util::{expand_path, join_config_path},
     Result,
     Result,
 };
 };
 
 
+/// The configuration for gatewayd
+#[derive(Serialize, Deserialize, Debug)]
+pub struct GatewaydConfig {
+    /// The address where gatewayd should bind its protocol socket
+    pub protocol_listen_address: SocketAddr,
+    /// The address where gatewayd should bind its publisher socket
+    pub publisher_listen_address: SocketAddr,
+    /// Whether to listen with TLS or plain TCP
+    pub serve_tls: bool,
+    /// Path to DER-formatted PKCS#12 archive. (Unused if serve_tls=false)
+    pub tls_identity_path: String,
+    /// Password for the TLS identity. (Unused if serve_tls=false)
+    pub tls_identity_password: String,
+    /// Path to the database
+    pub database_path: String,
+}
+
 /// Gatewayd cli
 /// Gatewayd cli
 #[derive(Parser)]
 #[derive(Parser)]
 #[clap(name = "gatewayd")]
 #[clap(name = "gatewayd")]

+ 1 - 0
bin/map/Cargo.toml

@@ -28,3 +28,4 @@ url = "2.2.2"
 
 
 # Encoding and parsing
 # Encoding and parsing
 serde_json = "1.0.74"
 serde_json = "1.0.74"
+serde = {version = "1.0.133", features = ["derive"]}

+ 13 - 1
bin/map/src/main.rs

@@ -1,7 +1,7 @@
 use darkfi::{
 use darkfi::{
     cli::{
     cli::{
         cli_config::{log_config, spawn_config},
         cli_config::{log_config, spawn_config},
-        Config, MapConfig,
+        Config,
     },
     },
     error::{Error, Result},
     error::{Error, Result},
     rpc::{jsonrpc, jsonrpc::JsonResult},
     rpc::{jsonrpc, jsonrpc::JsonResult},
@@ -11,6 +11,7 @@ use darkfi::{
 use async_std::sync::Arc;
 use async_std::sync::Arc;
 use easy_parallel::Parallel;
 use easy_parallel::Parallel;
 use log::{debug, info};
 use log::{debug, info};
+use serde::{Deserialize, Serialize};
 use serde_json::{json, Value};
 use serde_json::{json, Value};
 use simplelog::*;
 use simplelog::*;
 use smol::Executor;
 use smol::Executor;
@@ -38,6 +39,17 @@ use map::{
 
 
 const CONFIG_FILE_CONTENTS: &[u8] = include_bytes!("../map_config.toml");
 const CONFIG_FILE_CONTENTS: &[u8] = include_bytes!("../map_config.toml");
 
 
+#[derive(Clone, Serialize, Deserialize, Debug)]
+pub struct MapConfig {
+    pub nodes: Vec<IrcNode>,
+}
+
+#[derive(Clone, Serialize, Deserialize, Debug)]
+pub struct IrcNode {
+    pub node_id: String,
+    //pub rpc_url: String,
+}
+
 struct Map {
 struct Map {
     url: Url,
     url: Url,
 }
 }

+ 1 - 116
src/cli/cli_config.rs

@@ -2,12 +2,11 @@ use std::{
     env, fs,
     env, fs,
     io::Write,
     io::Write,
     marker::PhantomData,
     marker::PhantomData,
-    net::SocketAddr,
     path::{Path, PathBuf},
     path::{Path, PathBuf},
     str,
     str,
 };
 };
 
 
-use serde::{de::DeserializeOwned, Deserialize, Serialize};
+use serde::{de::DeserializeOwned, Serialize};
 
 
 use clap::ArgMatches;
 use clap::ArgMatches;
 use simplelog::ConfigBuilder;
 use simplelog::ConfigBuilder;
@@ -39,120 +38,6 @@ impl<T: Serialize + DeserializeOwned> Config<T> {
     }
     }
 }
 }
 
 
-/// The configuration for drk
-#[derive(Clone, Serialize, Deserialize, Debug)]
-pub struct DrkConfig {
-    /// The URL where darkfid RPC is listening on
-    pub darkfid_rpc_url: String,
-}
-
-#[derive(Clone, Debug, Serialize, Deserialize)]
-pub struct Cashier {
-    /// Cashier name
-    pub name: String,
-    /// The RPC endpoint for a selected cashier
-    pub rpc_url: String,
-    /// The selected cashier public key
-    pub public_key: String,
-}
-
-/// The configuration for darkfid
-#[derive(Clone, Serialize, Deserialize, Debug)]
-pub struct DarkfidConfig {
-    /// The address where darkfid should bind its RPC socket
-    pub rpc_listen_address: SocketAddr,
-    /// Whether to listen with TLS or plain TCP
-    pub serve_tls: bool,
-    /// Path to DER-formatted PKCS#12 archive. (Unused if serve_tls=false)
-    pub tls_identity_path: String,
-    /// Password for the TLS identity. (Unused if serve_tls=false)
-    pub tls_identity_password: String,
-    /// The endpoint to a gatewayd protocol API
-    pub gateway_protocol_url: String,
-    /// The endpoint to a gatewayd publisher API
-    pub gateway_publisher_url: String,
-    /// Path to the client database
-    pub database_path: String,
-    /// Path to the wallet database
-    pub wallet_path: String,
-    /// The wallet password
-    pub wallet_password: String,
-    /// The configured cashiers to use
-    pub cashiers: Vec<Cashier>,
-}
-
-/// The configuration for gatewayd
-#[derive(Serialize, Deserialize, Debug)]
-pub struct GatewaydConfig {
-    /// The address where gatewayd should bind its protocol socket
-    pub protocol_listen_address: SocketAddr,
-    /// The address where gatewayd should bind its publisher socket
-    pub publisher_listen_address: SocketAddr,
-    /// Whether to listen with TLS or plain TCP
-    pub serve_tls: bool,
-    /// Path to DER-formatted PKCS#12 archive. (Unused if serve_tls=false)
-    pub tls_identity_path: String,
-    /// Password for the TLS identity. (Unused if serve_tls=false)
-    pub tls_identity_password: String,
-    /// Path to the database
-    pub database_path: String,
-}
-
-#[derive(Clone, Debug, Serialize, Deserialize)]
-pub struct FeatureNetwork {
-    /// Network name
-    pub name: String,
-    /// Blockchain (mainnet/testnet/etc.)
-    pub blockchain: String,
-    /// Keypair
-    pub keypair: String,
-}
-
-#[derive(Clone, Serialize, Deserialize, Debug)]
-pub struct CashierdConfig {
-    /// The DNS name of the cashier (can also be an IP, or a .onion address)
-    pub dns_addr: String,
-    /// The endpoint where cashierd will bind its RPC socket
-    pub rpc_listen_address: SocketAddr,
-    /// Whether to listen with TLS or plain TCP
-    pub serve_tls: bool,
-    /// Path to DER-formatted PKCS#12 archive. (Unused if serve_tls=false)
-    pub tls_identity_path: String,
-    /// Password for the TLS identity. (Unused if serve_tls=false)
-    pub tls_identity_password: String,
-    /// The endpoint to a gatewayd protocol API
-    pub gateway_protocol_url: String,
-    /// The endpoint to a gatewayd publisher API
-    pub gateway_publisher_url: String,
-    /// Path to cashierd wallet
-    pub cashier_wallet_path: String,
-    /// Password for cashierd wallet
-    pub cashier_wallet_password: String,
-    /// Path to client wallet
-    pub client_wallet_path: String,
-    /// Password for client wallet
-    pub client_wallet_password: String,
-    /// Path to database
-    pub database_path: String,
-    /// Geth IPC endpoint
-    pub geth_socket: String,
-    /// Geth passphrase
-    pub geth_passphrase: String,
-    /// The configured networks to use
-    pub networks: Vec<FeatureNetwork>,
-}
-
-#[derive(Clone, Serialize, Deserialize, Debug)]
-pub struct MapConfig {
-    pub nodes: Vec<IrcNode>,
-}
-
-#[derive(Clone, Serialize, Deserialize, Debug)]
-pub struct IrcNode {
-    pub node_id: String,
-    //pub rpc_url: String,
-}
-
 pub fn spawn_config(path: &Path, contents: &[u8]) -> Result<()> {
 pub fn spawn_config(path: &Path, contents: &[u8]) -> Result<()> {
     if !path.exists() {
     if !path.exists() {
         if let Some(parent) = path.parent() {
         if let Some(parent) = path.parent() {

+ 1 - 1
src/cli/mod.rs

@@ -1,3 +1,3 @@
 pub mod cli_config;
 pub mod cli_config;
 
 
-pub use cli_config::{CashierdConfig, Config, DarkfidConfig, DrkConfig, GatewaydConfig, MapConfig};
+pub use cli_config::Config;