|
@@ -1,6 +1,6 @@
|
|
|
use std::{path::PathBuf, str::FromStr};
|
|
use std::{path::PathBuf, str::FromStr};
|
|
|
|
|
|
|
|
-use clap::{IntoApp, Parser};
|
|
|
|
|
|
|
+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_json::{json, Value};
|
|
use serde_json::{json, Value};
|
|
@@ -9,13 +9,114 @@ use simplelog::{ColorChoice, TermLogger, TerminalMode};
|
|
|
use darkfi::{
|
|
use darkfi::{
|
|
|
cli::{
|
|
cli::{
|
|
|
cli_config::{log_config, spawn_config},
|
|
cli_config::{log_config, spawn_config},
|
|
|
- CliDrk, CliDrkSubCommands, Config, DrkConfig,
|
|
|
|
|
|
|
+ Config, DrkConfig,
|
|
|
},
|
|
},
|
|
|
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,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+#[derive(Subcommand)]
|
|
|
|
|
+pub enum CliDrkSubCommands {
|
|
|
|
|
+ /// Say hello to the RPC
|
|
|
|
|
+ Hello {},
|
|
|
|
|
+ /// Show what features the cashier supports
|
|
|
|
|
+ Features {},
|
|
|
|
|
+ /// Wallet operations
|
|
|
|
|
+ Wallet {
|
|
|
|
|
+ /// Initialize a new wallet
|
|
|
|
|
+ #[clap(long)]
|
|
|
|
|
+ create: bool,
|
|
|
|
|
+ /// Generate wallet keypair
|
|
|
|
|
+ #[clap(long)]
|
|
|
|
|
+ keygen: bool,
|
|
|
|
|
+ /// Get default wallet address
|
|
|
|
|
+ #[clap(long)]
|
|
|
|
|
+ address: bool,
|
|
|
|
|
+ /// Get wallet addresses
|
|
|
|
|
+ #[clap(long)]
|
|
|
|
|
+ addresses: bool,
|
|
|
|
|
+ /// Set default address
|
|
|
|
|
+ #[clap(long, value_name = "ADDRESS")]
|
|
|
|
|
+ set_default_address: Option<String>,
|
|
|
|
|
+ /// Export default address
|
|
|
|
|
+ #[clap(long, value_name = "PATH")]
|
|
|
|
|
+ export_keypair: Option<String>,
|
|
|
|
|
+ /// Import address
|
|
|
|
|
+ #[clap(long, value_name = "PATH")]
|
|
|
|
|
+ import_keypair: Option<String>,
|
|
|
|
|
+ /// Get wallet balances
|
|
|
|
|
+ #[clap(long)]
|
|
|
|
|
+ balances: bool,
|
|
|
|
|
+ },
|
|
|
|
|
+ /// Get hexidecimal ID for token symbol
|
|
|
|
|
+ Id {
|
|
|
|
|
+ /// Which network to use (bitcoin/solana/...)
|
|
|
|
|
+ #[clap(long)]
|
|
|
|
|
+ network: String,
|
|
|
|
|
+ /// Which token to query (btc/sol/usdc/...)
|
|
|
|
|
+ #[clap(parse(try_from_str))]
|
|
|
|
|
+ token: String,
|
|
|
|
|
+ },
|
|
|
|
|
+ /// Withdraw Dark tokens for clear tokens
|
|
|
|
|
+ Withdraw {
|
|
|
|
|
+ /// Which network to use (bitcoin/solana/...)
|
|
|
|
|
+ #[clap(long)]
|
|
|
|
|
+ network: String,
|
|
|
|
|
+ /// Which token to receive (btc/sol/usdc/...)
|
|
|
|
|
+ #[clap(parse(try_from_str))]
|
|
|
|
|
+ token_sym: String,
|
|
|
|
|
+ /// Recipient address
|
|
|
|
|
+ #[clap(parse(try_from_str))]
|
|
|
|
|
+ address: String,
|
|
|
|
|
+ /// Amount to withdraw
|
|
|
|
|
+ #[clap(parse(try_from_str))]
|
|
|
|
|
+ amount: u64,
|
|
|
|
|
+ },
|
|
|
|
|
+ /// Transfer Dark tokens to address
|
|
|
|
|
+ Transfer {
|
|
|
|
|
+ /// Which network to use (bitcoin/solana/...)
|
|
|
|
|
+ #[clap(long)]
|
|
|
|
|
+ network: String,
|
|
|
|
|
+ /// Which token to transfer (btc/sol/usdc/...)
|
|
|
|
|
+ #[clap(parse(try_from_str))]
|
|
|
|
|
+ token_sym: String,
|
|
|
|
|
+ /// Recipient address
|
|
|
|
|
+ #[clap(parse(try_from_str))]
|
|
|
|
|
+ address: String,
|
|
|
|
|
+ /// Amount to transfer
|
|
|
|
|
+ #[clap(parse(try_from_str))]
|
|
|
|
|
+ amount: f64,
|
|
|
|
|
+ },
|
|
|
|
|
+ /// Deposit clear tokens for Dark tokens
|
|
|
|
|
+ Deposit {
|
|
|
|
|
+ /// Which network to use (bitcoin/solana/...)
|
|
|
|
|
+ #[clap(long)]
|
|
|
|
|
+ network: String,
|
|
|
|
|
+ /// Which token to deposit (btc/sol/usdc/...)
|
|
|
|
|
+ #[clap(parse(try_from_str))]
|
|
|
|
|
+ token_sym: String,
|
|
|
|
|
+ },
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// Drk cli
|
|
|
|
|
+#[derive(Parser)]
|
|
|
|
|
+#[clap(name = "drk")]
|
|
|
|
|
+#[clap(author, version, about)]
|
|
|
|
|
+#[clap(global_setting(AppSettings::PropagateVersion))]
|
|
|
|
|
+#[clap(global_setting(AppSettings::UseLongFormatForHelpSubcommand))]
|
|
|
|
|
+#[clap(setting(AppSettings::SubcommandRequiredElseHelp))]
|
|
|
|
|
+pub struct CliDrk {
|
|
|
|
|
+ /// Sets a custom config file
|
|
|
|
|
+ #[clap(short, long)]
|
|
|
|
|
+ pub config: Option<String>,
|
|
|
|
|
+ /// Increase verbosity
|
|
|
|
|
+ #[clap(short, parse(from_occurrences))]
|
|
|
|
|
+ pub verbose: u8,
|
|
|
|
|
+ #[clap(subcommand)]
|
|
|
|
|
+ pub command: Option<CliDrkSubCommands>,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
const CONFIG_FILE_CONTENTS: &[u8] = include_bytes!("../drk_config.toml");
|
|
const CONFIG_FILE_CONTENTS: &[u8] = include_bytes!("../drk_config.toml");
|
|
|
|
|
|
|
|
struct Drk {
|
|
struct Drk {
|