Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit a069a3b

Browse files
authored
Fix Payment Units (#7)
* bump version * requires units on user input
1 parent 72faac8 commit a069a3b

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

companion-app/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

companion-app/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "helium-ledger-app"
3-
version = "1.0.0"
3+
version = "1.0.1"
44
authors = ["Louis Thiery <louis@helium.com>"]
55
edition = "2018"
66

companion-app/src/main.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ use std::process;
1414
use structopt::StructOpt;
1515
pub type Result<T = ()> = std::result::Result<T, Box<dyn std::error::Error>>;
1616

17+
#[derive(StructOpt, Debug)]
18+
enum Units {
19+
/// Pay using Bones as units (must be integer)
20+
Bones {
21+
bones: u64
22+
},
23+
/// Pay using HNT as units (up to 8 decimals are tolerated)
24+
Hnt {
25+
hnt: Hnt
26+
}
27+
}
28+
1729
/// Interact with Ledger Nano S for hardware wallet management
1830
#[derive(Debug, StructOpt)]
1931
enum Cli {
@@ -23,16 +35,16 @@ enum Cli {
2335
#[structopt(long = "qr")]
2436
qr_code: bool,
2537
},
26-
/// Pay a number of bones to a given address. Note that amount
27-
/// is parsed as HNT (1 HNT = 100_000_000 Bones)
38+
/// Pay a given address.
39+
/// Use subcommand hnt or bones.
40+
/// Note that 1 HNT = 100,000,000 Bones = 100M Bones.
2841
Pay {
2942
/// Address of the payee
3043
address: String,
31-
32-
/// Amount of HNT to transfer to payee
33-
#[structopt(name = "amount")]
34-
amount: Hnt,
35-
},
44+
/// Select HNT or Bones
45+
#[structopt(subcommand)]
46+
units: Units,
47+
}
3648
}
3749

3850
fn main() {
@@ -57,7 +69,13 @@ fn run(cli: Cli) -> Result {
5769
}
5870
Ok(())
5971
}
60-
Cli::Pay { address, amount } => {
72+
Cli::Pay { address, units } => {
73+
74+
let amount = match units {
75+
Units::Hnt { hnt } => hnt,
76+
Units::Bones { bones } => Hnt::from_bones(bones),
77+
};
78+
6179
println!("Creating transaction for:");
6280
println!(" {:0.*} HNT", 8, amount.get_decimal());
6381
println!(" =");

0 commit comments

Comments
 (0)