Skip to content

Commit

Permalink
update: rust crypto wallet cli tool
Browse files Browse the repository at this point in the history
  • Loading branch information
hhstore committed Jun 5, 2022
1 parent a311ffd commit 7bdd903
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/rs-scripts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions crates/rs-scripts/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
88 changes: 88 additions & 0 deletions crates/rs-scripts/src/bin/commands/keytool.rs
Original file line number Diff line number Diff line change
@@ -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,
},
}
1 change: 1 addition & 0 deletions crates/rs-scripts/src/bin/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod binance;
pub mod eth;
pub mod keytool;
38 changes: 38 additions & 0 deletions crates/rs-scripts/src/bin/keytool.rs
Original file line number Diff line number Diff line change
@@ -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");
}
5 changes: 5 additions & 0 deletions crates/rs-scripts/src/bin/modules/keytool.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use log::info;

fn generate_wallet() {
info!("Generating wallet");
}
1 change: 1 addition & 0 deletions crates/rs-scripts/src/bin/modules/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod binance;
pub mod eth;
pub mod keytool;

0 comments on commit 7bdd903

Please sign in to comment.