@@ -14,6 +14,18 @@ use std::process;
1414use structopt:: StructOpt ;
1515pub 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 ) ]
1931enum 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
3850fn 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