Procházet zdrojové kódy

tidied /cli directory

lunar-mining před 5 roky
rodič
revize
53344b7a81

+ 4 - 0
Cargo.toml

@@ -81,6 +81,10 @@ dirs = "3.0.2"
 version = "0.25.1"
 features = ["bundled", "sqlcipher"]
 
+[[bin]]
+name = "example"
+path = "src/bin/example.rs"
+
 [[bin]]
 name = "lisp"
 path = "lisp/lisp.rs"

+ 2 - 2
src/bin/gatewayd.rs

@@ -7,7 +7,7 @@ use std::io::Read;
 use std::{fs, path::PathBuf};
 use toml;
 use drk::blockchain::{rocks::columns, Rocks, RocksColumn};
-use drk::cli::{ServiceCli, GatewaydConfig};
+use drk::cli::{GatewaydCli, GatewaydConfig};
 use drk::service::GatewayService;
 use drk::util::join_config_path;
 use drk::Result;
@@ -74,7 +74,7 @@ fn main() -> Result<()> {
     let config: GatewaydConfig = toml::from_str(str_buff)?;
     let config_pointer = Arc::new(&config);
 
-    let options = ServiceCli::load()?;
+    let options = GatewaydCli::load()?;
 
     let logger_config = ConfigBuilder::new().set_time_format_str("%T%.6f").build();
 

+ 0 - 137
src/cli/client_cli/cli_config.rs

@@ -1,137 +0,0 @@
-//use crate::serial::{deserialize, serialize, Decodable, Encodable};
-//use toml::{map::Map, Value};
-use crate::util::join_config_path;
-//use crate::Result;
-
-use serde::{Deserialize, Serialize};
-//use log::*;
-
-use std::{fs::OpenOptions, io::prelude::*, path::PathBuf};
-
-//pub trait ClientConfig: Default + Deserialize {
-//    fn load(path: PathBuf) -> Result<Self> {
-//        let path = join_config_path(&path)?;
-//        let mut file = OpenOptions::new()
-//            .read(true)
-//            .write(true)
-//            .create(true)
-//            .open(path)?;
-//
-//        //let mut toml_map = Map::new();
-//        let mut buffer = String::new();
-//        file.read_to_string(&mut buffer)?;
-//        //let buffer: &'static str = buffer;
-//
-//        //let tomlstring = toml::to_string(&file).expect("Could not encode TTOML value");
-//        if !buffer.is_empty() {
-//            let config: Self = toml::from_str(&buffer)?;
-//            //let config = toml::to_string(&buffer).unwrap();
-//            //let config: Self = deserialize(&buffer)?;
-//            //Ok(config)
-//            Ok(config)
-//        } else {
-//            Ok(Self::default())
-//        }
-//    }
-//    fn save(&self, path: PathBuf) -> Result<()> {
-//        //let path = join_config_path(&path)?;
-//        //let mut file = OpenOptions::new().write(true).create(true).open(&path)?;
-//        //let serialized = serialize(self);
-//        //file.write_all(&serialized)?;
-//        Ok(())
-//    }
-//}
-//
-//impl ClientConfig for DrkConfig {}
-//impl ClientConfig for DarkfidConfig {}
-
-#[derive(Serialize, Default, Deserialize, Debug)]
-pub struct DrkConfig {
-    #[serde(rename = "rpc_url")]
-    pub rpc_url: String,
-
-    #[serde(rename = "log_path")]
-    pub log_path: String,
-}
-
-#[derive(Serialize, Default, Deserialize, Debug)]
-pub struct DarkfidConfig {
-    #[serde(rename = "connect_url")]
-    pub connect_url: String,
-
-    #[serde(rename = "subscriber_url")]
-    pub subscriber_url: String,
-
-    #[serde(rename = "rpc_url")]
-    pub rpc_url: String,
-
-    #[serde(rename = "database_path")]
-    pub database_path: String,
-
-    #[serde(rename = "log_path")]
-    pub log_path: String,
-
-    #[serde(rename = "password")]
-    pub password: String,
-}
-
-
-#[derive(Serialize, Default, Deserialize, Debug)]
-pub struct GatewaydConfig {
-    #[serde(rename = "connect_url")]
-    pub accept_url: String,
-
-    #[serde(rename = "subscriber_url")]
-    pub publisher_url: String,
-
-    #[serde(rename = "database_path")]
-    pub database_path: String,
-
-    #[serde(rename = "log_path")]
-    pub log_path: String,
-}
-
-//impl Default for DrkCliConfig {
-//    // default toml file
-//    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,
-//        }
-//    }
-//}
-
-//impl Default for DarkfidCliConfig {
-//    // create default config file
-//    fn default() -> Self {
-//        //toml::toml! {
-//        //    connect-url = "127.0.0.1:3333"
-//        //};
-//        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,
-//        }
-//    }
-//}
-

+ 0 - 121
src/cli/client_cli/darkfid_cli.rs

@@ -1,121 +0,0 @@
-//use super::cli_config::DarkfidCliConfig;
-use crate::Result;
-
-use clap::{App, Arg};
-
-pub struct DarkfidCli {
-    //pub change_config: bool,
-    pub verbose: bool,
-}
-
-impl DarkfidCli {
-    pub fn load() -> Result<Self> {
-        let app = App::new("Darkfi Daemon CLI")
-            .version("0.1.0")
-            .author("Amir Taaki <amir@dyne.org>")
-            .about("Run Darkfi Daemon")
-            .arg(
-                Arg::new("verbose")
-                    .short('v')
-                    .help_heading(Some("Increase verbosity"))
-                    .long("verbose")
-                    .takes_value(false),
-            )
-            //.subcommand(
-            //    App::new("config")
-            //        .about("Configuration settings")
-            //        .aliases(&["get", "set"])
-            //        .setting(AppSettings::SubcommandRequiredElseHelp)
-            //        .subcommand(App::new("get").about("Get configuration settings"))
-            //        .subcommand(
-            //            App::new("set")
-            //                .about("Set configuration settings")
-            //                .args(&[
-            //                    Arg::new("connect_url")
-            //                        .about("Set Connect Url")
-            //                        .long("connect-url")
-            //                        .takes_value(true),
-            //                    Arg::new("subscriber_url")
-            //                        .about("Set Subscriber Url")
-            //                        .long("subscriber-url")
-            //                        .takes_value(true),
-            //                    Arg::new("rpc_url")
-            //                        .about("Set RPC Url")
-            //                        .long("rpc-url")
-            //                        .takes_value(true),
-            //                    Arg::new("database_path")
-            //                        .about("Set Database Path")
-            //                        .long("database-path")
-            //                        .takes_value(true),
-            //                    Arg::new("log_path")
-            //                        .about("Set Log Path")
-            //                        .long("log-path")
-            //                        .takes_value(true),
-            //                    Arg::new("password")
-            //                        .about("Set password")
-            //                        .long("password")
-            //                        .takes_value(true),
-            //                ])
-            //                .setting(AppSettings::ArgRequiredElseHelp),
-            //        ),
-            //)
-            .get_matches();
-
-        //let mut change_config = false;
-
-        let verbose = app.is_present("verbose");
-
-        //match app.subcommand_matches("config") {
-        //    Some(config_sub) => match config_sub.subcommand() {
-        //        Some(c) => match c {
-        //            ("get", _) => {
-        //                change_config = true;
-        //                println!("Connect Url: {}", config.connect_url);
-        //                println!("Subscriber Url: {}", config.subscriber_url);
-        //                println!("RPC Url: {}", config.rpc_url);
-        //                println!("Database path: {}", config.database_path);
-        //                println!("Log Path: {}", config.log_path);
-        //                if config.password.trim().is_empty() {
-        //                    println!("Password is empty. Please set a password.")
-        //                };
-        //            }
-        //            ("set", c) => {
-        //                change_config = true;
-        //                if let Some(v) = c.value_of("connect_url") {
-        //                    config.connect_url = v.to_string();
-        //                    println!("Change Connect Url To {}", config.connect_url);
-        //                }
-        //                if let Some(v) = c.value_of("subscriber_url") {
-        //                    config.subscriber_url = v.to_string();
-        //                    println!("Change Subscriber Url To {}", config.subscriber_url);
-        //                }
-        //                if let Some(v) = c.value_of("rpc_url") {
-        //                    config.rpc_url = v.to_string();
-        //                    println!("Change RPC Url To {}", config.rpc_url);
-        //                }
-        //                if let Some(v) = c.value_of("database_path") {
-        //                    config.database_path = v.to_string();
-        //                    println!("Change Database Path To {}", config.database_path);
-        //                }
-        //                if let Some(v) = c.value_of("log_path") {
-        //                    config.log_path = v.to_string();
-        //                    println!("Change Log Path To {}", config.log_path);
-        //                }
-        //                if let Some(v) = c.value_of("password") {
-        //                    config.password = v.to_string();
-        //                    println!("Updated password. New password: {}", config.password);
-        //                }
-        //            }
-        //            _ => {}
-        //        },
-        //        None => {}
-        //    },
-        //    None => {}
-        //}
-
-        Ok(Self {
-            //change_config,
-            verbose,
-        })
-    }
-}

+ 0 - 206
src/cli/client_cli/drk_cli.rs

@@ -1,206 +0,0 @@
-//use super::cli_config::DrkCliConfig;
-use crate::Result;
-
-use clap::{App, Arg};
-
-pub struct Transfer {
-    pub pub_key: String,
-    pub amount: String,
-}
-
-impl Transfer {
-    pub fn new() -> Self {
-        Self {
-            pub_key: String::new(),
-            amount: String::new(),
-        }
-    }
-
-    pub fn verfiy_amount(amount: &str) -> Result<()> {
-        if amount.parse::<u64>().is_ok() || amount.parse::<f64>().is_ok() {
-            Ok(())
-        } else {
-            let err = format!(
-                "Unable to parse input amount as integer or float: {}",
-                amount
-            );
-            Err(crate::Error::ParseFailed(Box::leak(err.into_boxed_str())))
-        }
-    }
-}
-
-pub struct DrkCli {
-    //pub change_config: bool,
-    pub verbose: bool,
-    pub cashier: bool,
-    pub wallet: bool,
-    pub key: bool,
-    pub info: bool,
-    pub hello: bool,
-    pub stop: bool,
-    pub transfer: Option<Transfer>,
-}
-
-impl DrkCli {
-    pub fn load() -> Result<Self> {
-        let app = App::new("Drk CLI")
-            .version("0.1.0")
-            .author("Amir Taaki <amir@dyne.org>")
-            .about("Run Drk Client")
-            .arg(
-                Arg::new("verbose")
-                    .short('v')
-                    .help_heading(Some("Increase verbosity"))
-                    .long("verbose")
-                    .takes_value(false),
-            )
-            .arg(
-                Arg::new("hello")
-                    .long("hello")
-                    .help_heading(Some("Test Hello"))
-                    .takes_value(false),
-            )
-            .arg(
-                Arg::new("cashier")
-                    .short('c')
-                    .long("cashier")
-                    .help_heading(Some("Create a cashier wallet"))
-                    .takes_value(false),
-            )
-            .arg(
-                Arg::new("key")
-                    .short('k')
-                    .long("key")
-                    .help_heading(Some("Test key"))
-                    .takes_value(false),
-            )
-            .arg(
-                Arg::new("wallet")
-                    .short('w')
-                    .long("wallet")
-                    .help_heading(Some("Create a new wallet"))
-                    .takes_value(false),
-            )
-            .arg(
-                Arg::new("info")
-                    .short('i')
-                    .long("info")
-                    .help_heading(Some("Request info from daemon"))
-                    .takes_value(false),
-            )
-            .arg(
-                Arg::new("stop")
-                    .short('s')
-                    .long("stop")
-                    .help_heading(Some("Send a stop signal to the daemon"))
-                    .takes_value(false),
-            )
-            .subcommand(
-                App::new("transfer")
-                    .about("Transfer DBTC between users")
-                    .arg(
-                        Arg::new("address")
-                            .value_name("RECIPIENT_ADDRESS")
-                            .takes_value(true)
-                            .index(1)
-                            .help_heading(Some("Address of recipient"))
-                            .required(true),
-                    )
-                    .arg(
-                        Arg::new("amount")
-                            .value_name("AMOUNT")
-                            .takes_value(true)
-                            .index(2)
-                            .help_heading(Some("Amount to send, in DBTC"))
-                            .required(true),
-                    ),
-            )
-            //.subcommand(
-            //    App::new("config")
-            //        .about("Configuration settings")
-            //        .aliases(&["get", "set"])
-            //        .setting(AppSettings::SubcommandRequiredElseHelp)
-            //        .subcommand(App::new("get").about("Get configuration settings"))
-            //        .subcommand(
-            //            App::new("set")
-            //                .about("Set configuration settings")
-            //                .args(&[
-            //                    Arg::new("rpc_url")
-            //                        .about("Set RPC Url")
-            //                        .long("rpc-url")
-            //                        .takes_value(true),
-            //                    Arg::new("log_path")
-            //                        .about("Set Log Path")
-            //                        .long("log-path")
-            //                        .takes_value(true),
-            //                ])
-            //                .setting(AppSettings::ArgRequiredElseHelp),
-            //        ),
-            //)
-            .get_matches();
-
-        //let mut change_config = false;
-
-        let verbose = app.is_present("verbose");
-        let cashier = app.is_present("cashier");
-        let wallet = app.is_present("wallet");
-        let key = app.is_present("key");
-        let info = app.is_present("info");
-        let hello = app.is_present("hello");
-        let stop = app.is_present("stop");
-
-        let mut transfer = None;
-        match app.subcommand_matches("transfer") {
-            Some(transfer_sub) => {
-                let mut trn = Transfer::new();
-                if let Some(address) = transfer_sub.value_of("address") {
-                    trn.pub_key = address.to_string();
-                }
-                if let Some(amount) = transfer_sub.value_of("amount") {
-                    Transfer::verfiy_amount(amount)?;
-                    trn.amount = amount.to_string();
-                }
-                transfer = Some(trn);
-            }
-            None => {}
-        }
-
-        //match app.subcommand_matches("config") {
-        //    Some(config_sub) => match config_sub.subcommand() {
-        //        Some(c) => match c {
-        //            ("get", _) => {
-        //                change_config = true;
-        //                println!("RPC Url: {}", config.rpc_url);
-        //                println!("Log Path: {}", config.log_path);
-        //            }
-        //            ("set", c) => {
-        //                change_config = true;
-        //                if let Some(v) = c.value_of("rpc_url") {
-        //                    config.rpc_url = v.to_string();
-        //                    println!("Change RPC Url To {}", config.rpc_url);
-        //                }
-        //                if let Some(v) = c.value_of("log_path") {
-        //                    config.log_path = v.to_string();
-        //                    println!("Change Log Path To {}", config.log_path);
-        //                }
-        //            }
-        //            _ => {}
-        //        },
-        //        None => {}
-        //    },
-        //    None => {}
-        //}
-
-        Ok(Self {
-            //change_config,
-            verbose,
-            cashier,
-            wallet,
-            key,
-            info,
-            hello,
-            stop,
-            transfer,
-        })
-    }
-}

+ 0 - 3
src/cli/client_cli/mod.rs

@@ -1,3 +0,0 @@
-pub mod cli_config;
-pub mod darkfid_cli;
-pub mod drk_cli;

+ 9 - 5
src/cli/mod.rs

@@ -1,6 +1,10 @@
-pub mod client_cli;
-pub mod service_cli;
+pub mod cli_config;
+pub mod darkfid_cli;
+pub mod drk_cli;
+pub mod gatewayd_cli;
 
-pub use client_cli::cli_config::{DarkfidConfig, GatewaydConfig, DrkConfig};
-pub use client_cli::{darkfid_cli::DarkfidCli, drk_cli::DrkCli, drk_cli::Transfer};
-pub use service_cli::ServiceCli;
+pub use cli_config::{DarkfidConfig, GatewaydConfig, DrkConfig};
+pub use darkfid_cli::DarkfidCli;
+pub use drk_cli::DrkCli;
+pub use drk_cli::Transfer;
+pub use gatewayd_cli::GatewaydCli;

+ 0 - 66
src/cli/service_cli.rs

@@ -1,66 +0,0 @@
-use crate::Result;
-use std::net::SocketAddr;
-
-pub struct ServiceCli {
-    //pub accept_addr: Option<SocketAddr>,
-    //pub pub_addr: Option<SocketAddr>,
-    pub verbose: bool,
-    //pub database_path: Box<std::path::PathBuf>,
-    //pub log_path: Box<std::path::PathBuf>,
-}
-
-impl ServiceCli {
-    pub fn load() -> Result<Self> {
-        let app = clap_app!(dfi =>
-            (version: "0.1.0")
-            (author: "Amir Taaki <amir@dyne.org>")
-            (about: "run service daemon")
-            //(@arg ACCEPT: -a --accept +takes_value "Accept add//ress")
-            //(@arg PUB_ADDR: -p --pubaddr +takes_value "Publisher addr")
-            (@arg VERBOSE: -v --verbose "Increase verbosity")
-            //(@arg DATABASE_PATH: --database +takes_value "database path")
-            //(@arg LOG_PATH: --log +takes_value "Logfile path")
-        )
-        .get_matches();
-
-        //let accept_addr = if let Some(accept_addr) = app.value_of("ACCEPT") {
-        //    Some(accept_addr.parse()?)
-        //} else {
-        //    None
-        //};
-
-        //let pub_addr = if let Some(pub_addr) = app.value_of("PUB_ADDR") {
-        //    Some(pub_addr.parse()?)
-        //} else {
-        //    None
-        //};
-
-        let verbose = app.is_present("VERBOSE");
-
-        //let database_path = Box::new(
-        //    if let Some(database_path) = app.value_of("DATABASE_PATH") {
-        //        std::path::Path::new(database_path)
-        //    } else {
-        //        std::path::Path::new("database.db")
-        //    }
-        //    .to_path_buf(),
-        //);
-
-        //let log_path = Box::new(
-        //    if let Some(log_path) = app.value_of("LOG_PATH") {
-        //        std::path::Path::new(log_path)
-        //    } else {
-        //        std::path::Path::new("/tmp/darkfid_service_daemon.log")
-        //    }
-        //    .to_path_buf(),
-        //);
-
-        Ok(Self {
-            //accept_addr,
-            //pub_addr,
-            verbose,
-            //database_path,
-            //log_path,
-        })
-    }
-}