From 7bdd90376f18962ecf5bbd5fdd89a01f61ae9446 Mon Sep 17 00:00:00 2001 From: hhstore Date: Sun, 5 Jun 2022 08:02:18 +0800 Subject: [PATCH] update: rust crypto wallet cli tool --- crates/rs-scripts/Cargo.toml | 4 + crates/rs-scripts/Taskfile.yml | 6 ++ crates/rs-scripts/src/bin/commands/keytool.rs | 88 +++++++++++++++++++ crates/rs-scripts/src/bin/commands/mod.rs | 1 + crates/rs-scripts/src/bin/keytool.rs | 38 ++++++++ crates/rs-scripts/src/bin/modules/keytool.rs | 5 ++ crates/rs-scripts/src/bin/modules/mod.rs | 1 + 7 files changed, 143 insertions(+) create mode 100644 crates/rs-scripts/src/bin/commands/keytool.rs create mode 100644 crates/rs-scripts/src/bin/keytool.rs create mode 100644 crates/rs-scripts/src/bin/modules/keytool.rs diff --git a/crates/rs-scripts/Cargo.toml b/crates/rs-scripts/Cargo.toml index ead37c9..dd7d7c9 100644 --- a/crates/rs-scripts/Cargo.toml +++ b/crates/rs-scripts/Cargo.toml @@ -30,6 +30,10 @@ path = "src/bin/discord_bot.rs" name = "rs-binance" path = "src/bin/binance.rs" +[[bin]] +name = "rs-keytool" +path = "src/bin/keytool.rs" + [[bin]] name = "rs-tui" path = "src/bin/tui.rs" diff --git a/crates/rs-scripts/Taskfile.yml b/crates/rs-scripts/Taskfile.yml index a197398..5982740 100644 --- a/crates/rs-scripts/Taskfile.yml +++ b/crates/rs-scripts/Taskfile.yml @@ -27,6 +27,12 @@ tasks: - echo "run:binance api tool" - cargo run --bin rs-binance -- market empty + run:keytool: + cmds: + - echo "run:keytool" +# - cargo run --bin rs-keytool -- query -h + - cargo run --bin rs-keytool -- -h + run:tui: cmds: - cargo run --bin rs-tui -- market empty diff --git a/crates/rs-scripts/src/bin/commands/keytool.rs b/crates/rs-scripts/src/bin/commands/keytool.rs new file mode 100644 index 0000000..fca74fc --- /dev/null +++ b/crates/rs-scripts/src/bin/commands/keytool.rs @@ -0,0 +1,88 @@ +use clap::{Parser, Subcommand}; + +/// A fictional versioning CLI +#[derive(Parser)] +#[clap( + name = "keytool", + about = "A Cli Crypto Wallet Tool", + version = "0.1.0", + long_about = None, +)] +pub struct KeyToolCli { + #[clap(subcommand)] + pub command: KeyToolCommand, +} + +#[derive(Subcommand)] +pub enum KeyToolCommand { + /* + todo x: + 1. 生成 HD 钱包, 助记词/私钥/地址 + 2. 多链支持: BTC/ETH/DOT + 3. 命令行查询 + - 钱包余额 + - 钱包交易记录 + - 单笔交易状态 + 4. 命令行转账: + - 发起交易 + - 交易状态查询 + */ + /// Generate a new crypto wallet account: mnemonic/private key/address + #[clap(arg_required_else_help = true)] + Generate { + /// allow emtpy + empty: String, + }, + + /// Query blockchain info + #[clap(arg_required_else_help = true)] + #[clap(subcommand)] + Query(QueryCommand), + + /// Send a transaction + #[clap(arg_required_else_help = true)] + Send { + /// chain name + chain_type: String, + + /// from address + from: String, + + /// to address + to: String, + + /// amount + amount: String, + + /// miner fee + fee: String, + }, +} + +#[derive(Subcommand)] +pub enum QueryCommand { + /// Query balance + #[clap(arg_required_else_help = true)] + Balance { + /// blockchain type + chain_type: String, + + /// blockchain id: + chain_id: String, + + /// address + address: String, + }, + + /// Query transaction + Transaction { + /// blockchain type + chain_type: String, + + /// blockchain id: + chain_id: String, + + /// transaction id + tx_id: String, + }, +} diff --git a/crates/rs-scripts/src/bin/commands/mod.rs b/crates/rs-scripts/src/bin/commands/mod.rs index 096e1c2..955432f 100644 --- a/crates/rs-scripts/src/bin/commands/mod.rs +++ b/crates/rs-scripts/src/bin/commands/mod.rs @@ -1,2 +1,3 @@ pub mod binance; pub mod eth; +pub mod keytool; diff --git a/crates/rs-scripts/src/bin/keytool.rs b/crates/rs-scripts/src/bin/keytool.rs new file mode 100644 index 0000000..e90a614 --- /dev/null +++ b/crates/rs-scripts/src/bin/keytool.rs @@ -0,0 +1,38 @@ +use clap::Parser; +use log::info; +use pretty_env_logger; + +use crate::commands::keytool::{KeyToolCli, KeyToolCommand, QueryCommand}; + +mod commands; +mod modules; + +fn main() { + pretty_env_logger::init(); + + let args = KeyToolCli::parse(); + + match &args.command { + KeyToolCommand::Generate { empty: _ } => { + info!("GenerateAccount command"); + }, + + // subcommands: + KeyToolCommand::Query(x) => { + info!("GenerateAccount command"); + match x { + QueryCommand::Balance { chain_type, chain_id, address } => { + info!("Balance command: {}, {}, {}", chain_type, chain_id, address); + }, + QueryCommand::Transaction { chain_type, chain_id, tx_id } => { + info!("Balance command: {}, {}, {}", chain_type, chain_id, tx_id); + }, + } + }, + KeyToolCommand::Send { chain_type, from, to, amount, fee } => { + info!("GenerateAccount command: {}, {}, {}, {}, {}", chain_type, from, to, amount, fee); + }, + } + + info!("cli finished"); +} diff --git a/crates/rs-scripts/src/bin/modules/keytool.rs b/crates/rs-scripts/src/bin/modules/keytool.rs new file mode 100644 index 0000000..3e3b729 --- /dev/null +++ b/crates/rs-scripts/src/bin/modules/keytool.rs @@ -0,0 +1,5 @@ +use log::info; + +fn generate_wallet() { + info!("Generating wallet"); +} diff --git a/crates/rs-scripts/src/bin/modules/mod.rs b/crates/rs-scripts/src/bin/modules/mod.rs index 096e1c2..955432f 100644 --- a/crates/rs-scripts/src/bin/modules/mod.rs +++ b/crates/rs-scripts/src/bin/modules/mod.rs @@ -1,2 +1,3 @@ pub mod binance; pub mod eth; +pub mod keytool;