From a069a3b8419a8a57463139dd73e68af34dd5e578 Mon Sep 17 00:00:00 2001 From: Louis Thiery Date: Thu, 5 Mar 2020 11:34:53 -0800 Subject: [PATCH] Fix Payment Units (#7) * bump version * requires units on user input --- companion-app/Cargo.lock | 2 +- companion-app/Cargo.toml | 2 +- companion-app/src/main.rs | 34 ++++++++++++++++++++++++++-------- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/companion-app/Cargo.lock b/companion-app/Cargo.lock index 30b2901..67b657b 100644 --- a/companion-app/Cargo.lock +++ b/companion-app/Cargo.lock @@ -546,7 +546,7 @@ dependencies = [ [[package]] name = "helium-ledger-app" -version = "1.0.0" +version = "1.0.1" dependencies = [ "bs58", "byteorder", diff --git a/companion-app/Cargo.toml b/companion-app/Cargo.toml index bd77a08..ed69c35 100644 --- a/companion-app/Cargo.toml +++ b/companion-app/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "helium-ledger-app" -version = "1.0.0" +version = "1.0.1" authors = ["Louis Thiery "] edition = "2018" diff --git a/companion-app/src/main.rs b/companion-app/src/main.rs index e9a2cae..724ef88 100644 --- a/companion-app/src/main.rs +++ b/companion-app/src/main.rs @@ -14,6 +14,18 @@ use std::process; use structopt::StructOpt; pub type Result = std::result::Result>; +#[derive(StructOpt, Debug)] +enum Units { + /// Pay using Bones as units (must be integer) + Bones { + bones: u64 + }, + /// Pay using HNT as units (up to 8 decimals are tolerated) + Hnt { + hnt: Hnt + } +} + /// Interact with Ledger Nano S for hardware wallet management #[derive(Debug, StructOpt)] enum Cli { @@ -23,16 +35,16 @@ enum Cli { #[structopt(long = "qr")] qr_code: bool, }, - /// Pay a number of bones to a given address. Note that amount - /// is parsed as HNT (1 HNT = 100_000_000 Bones) + /// Pay a given address. + /// Use subcommand hnt or bones. + /// Note that 1 HNT = 100,000,000 Bones = 100M Bones. Pay { /// Address of the payee address: String, - - /// Amount of HNT to transfer to payee - #[structopt(name = "amount")] - amount: Hnt, - }, + /// Select HNT or Bones + #[structopt(subcommand)] + units: Units, + } } fn main() { @@ -57,7 +69,13 @@ fn run(cli: Cli) -> Result { } Ok(()) } - Cli::Pay { address, amount } => { + Cli::Pay { address, units } => { + + let amount = match units { + Units::Hnt { hnt } => hnt, + Units::Bones { bones } => Hnt::from_bones(bones), + }; + println!("Creating transaction for:"); println!(" {:0.*} HNT", 8, amount.get_decimal()); println!(" =");