Skip to content

Commit

Permalink
Fix Payment Units (#7)
Browse files Browse the repository at this point in the history
* bump version
* requires units on user input
  • Loading branch information
lthiery authored Mar 5, 2020
1 parent 72faac8 commit a069a3b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion companion-app/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion companion-app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "helium-ledger-app"
version = "1.0.0"
version = "1.0.1"
authors = ["Louis Thiery <louis@helium.com>"]
edition = "2018"

Expand Down
34 changes: 26 additions & 8 deletions companion-app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ use std::process;
use structopt::StructOpt;
pub type Result<T = ()> = std::result::Result<T, Box<dyn std::error::Error>>;

#[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 {
Expand All @@ -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() {
Expand All @@ -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!(" =");
Expand Down

0 comments on commit a069a3b

Please sign in to comment.