diff --git a/Cargo.lock b/Cargo.lock index 427fba74e..d920fe39a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1544,6 +1544,7 @@ dependencies = [ "lazy_static", "log", "prettytable-rs", + "qr_code", "rand 0.7.3", "remove_dir_all 0.7.0", "ring", @@ -2866,6 +2867,12 @@ dependencies = [ "unicode-xid 0.2.2", ] +[[package]] +name = "qr_code" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5520fbcd7da152a449261c5a533a1c7fad044e9e8aa9528cfec3f464786c7926" + [[package]] name = "quick-error" version = "1.2.3" diff --git a/controller/Cargo.toml b/controller/Cargo.toml index c56942327..b07a46204 100644 --- a/controller/Cargo.toml +++ b/controller/Cargo.toml @@ -29,6 +29,7 @@ url = "2.1" chrono = { version = "0.4.11", features = ["serde"] } easy-jsonrpc-mw = "0.5.4" lazy_static = "1" +qr_code = "1.1.0" grin_wallet_util = { path = "../util", version = "5.2.0-alpha.1" } diff --git a/controller/src/command.rs b/controller/src/command.rs index 4e7acb377..8528b7ade 100644 --- a/controller/src/command.rs +++ b/controller/src/command.rs @@ -30,6 +30,7 @@ use crate::util::secp::key::SecretKey; use crate::util::{Mutex, ZeroingString}; use crate::{controller, display}; use ::core::time; +use qr_code::QrCode; use serde_json as json; use std::convert::TryFrom; use std::fs::File; @@ -335,6 +336,7 @@ pub struct SendArgs { pub skip_tor: bool, pub outfile: Option, pub bridge: Option, + pub slatepack_qr: bool, } pub fn send( @@ -451,6 +453,7 @@ where args.outfile, true, false, + args.slatepack_qr, )?; } Err(e) => return Err(e.into()), @@ -466,6 +469,7 @@ pub fn output_slatepack( out_file_override: Option, lock: bool, finalizing: bool, + show_qr: bool, ) -> Result<(), libwallet::Error> where L: WalletLCProvider<'static, C, K> + 'static, @@ -527,6 +531,12 @@ where println!(); println!("{}", out_file_name); println!(); + if show_qr { + if let Ok(qr_string) = QrCode::new(message) { + println!("{}", qr_string.to_string(false, 3)); + println!(); + } + } if address.is_some() { println!("The slatepack data is encrypted for the recipient only"); } else { @@ -610,6 +620,7 @@ pub struct ReceiveArgs { pub skip_tor: bool, pub outfile: Option, pub bridge: Option, + pub slatepack_qr: bool, } pub fn receive( @@ -679,6 +690,7 @@ where args.outfile, false, false, + args.slatepack_qr, )?; Ok(()) } @@ -772,6 +784,7 @@ pub struct FinalizeArgs { pub fluff: bool, pub nopost: bool, pub outfile: Option, + pub slatepack_qr: bool, } pub fn finalize( @@ -841,6 +854,7 @@ where args.outfile, false, true, + args.slatepack_qr, )?; Ok(()) @@ -854,6 +868,8 @@ pub struct IssueInvoiceArgs { pub issue_args: IssueInvoiceTxArgs, /// output file override pub outfile: Option, + /// show slatepack as QR code + pub slatepack_qr: bool, } pub fn issue_invoice_tx( @@ -882,6 +898,7 @@ where args.outfile, false, false, + args.slatepack_qr, )?; Ok(()) } @@ -898,6 +915,7 @@ pub struct ProcessInvoiceArgs { pub skip_tor: bool, pub outfile: Option, pub bridge: Option, + pub slatepack_qr: bool, } /// Process invoice @@ -1004,6 +1022,7 @@ where args.outfile, true, false, + args.slatepack_qr, )?; Ok(()) } diff --git a/src/bin/grin-wallet.yml b/src/bin/grin-wallet.yml index 0df007057..0f15afeaa 100644 --- a/src/bin/grin-wallet.yml +++ b/src/bin/grin-wallet.yml @@ -177,6 +177,10 @@ subcommands: short: g long: bridge takes_value: true + - slatepack_qr: + help: Show slatepack data as QR code + short: q + long: slatepack_qr - unpack: about: Unpack and display an armored Slatepack Message, decrypting if possible args: @@ -207,6 +211,10 @@ subcommands: short: g long: bridge takes_value: true + - slatepack_qr: + help: Show slatepack data as QR code + short: q + long: slatepack_qr - finalize: about: Processes a Slatepack Message to finalize a transfer. args: @@ -228,6 +236,10 @@ subcommands: short: u long: outfile takes_value: true + - slatepack_qr: + help: Show slatepack data as QR code + short: q + long: slatepack_qr - invoice: about: Initialize an invoice transaction, outputting a Slatepack Message with the result args: @@ -244,6 +256,10 @@ subcommands: short: u long: outfile takes_value: true + - slatepack_qr: + help: Show slatepack data as QR code + short: q + long: slatepack_qr - pay: about: Spend coins to pay the provided invoice transaction args: @@ -295,6 +311,10 @@ subcommands: short: g long: bridge takes_value: true + - slatepack_qr: + help: Show slatepack data as QR code + short: q + long: slatepack_qr - outputs: about: Raw wallet output info (list of outputs) - txs: diff --git a/src/cmd/wallet_args.rs b/src/cmd/wallet_args.rs index 75c0afdf7..97a468db8 100644 --- a/src/cmd/wallet_args.rs +++ b/src/cmd/wallet_args.rs @@ -520,6 +520,8 @@ pub fn parse_send_args(args: &ArgMatches) -> Result None, }; + let slatepack_qr = args.is_present("slatepack_qr"); + Ok(command::SendArgs { amount: amount, minimum_confirmations: min_c, @@ -536,6 +538,7 @@ pub fn parse_send_args(args: &ArgMatches) -> Result Result Result Result