Show slatepack QR codes (#655)

* Show slatepack QR codes

* Make slatepack QR codes optional

Co-authored-by: cliik <cliik@example.com>
This commit is contained in:
cliik 2022-07-12 09:32:26 +00:00 committed by GitHub
parent 407f7df111
commit 95bb4c477e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 0 deletions

7
Cargo.lock generated
View file

@ -1544,6 +1544,7 @@ dependencies = [
"lazy_static", "lazy_static",
"log", "log",
"prettytable-rs", "prettytable-rs",
"qr_code",
"rand 0.7.3", "rand 0.7.3",
"remove_dir_all 0.7.0", "remove_dir_all 0.7.0",
"ring", "ring",
@ -2866,6 +2867,12 @@ dependencies = [
"unicode-xid 0.2.2", "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]] [[package]]
name = "quick-error" name = "quick-error"
version = "1.2.3" version = "1.2.3"

View file

@ -29,6 +29,7 @@ url = "2.1"
chrono = { version = "0.4.11", features = ["serde"] } chrono = { version = "0.4.11", features = ["serde"] }
easy-jsonrpc-mw = "0.5.4" easy-jsonrpc-mw = "0.5.4"
lazy_static = "1" lazy_static = "1"
qr_code = "1.1.0"
grin_wallet_util = { path = "../util", version = "5.2.0-alpha.1" } grin_wallet_util = { path = "../util", version = "5.2.0-alpha.1" }

View file

@ -30,6 +30,7 @@ use crate::util::secp::key::SecretKey;
use crate::util::{Mutex, ZeroingString}; use crate::util::{Mutex, ZeroingString};
use crate::{controller, display}; use crate::{controller, display};
use ::core::time; use ::core::time;
use qr_code::QrCode;
use serde_json as json; use serde_json as json;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::fs::File; use std::fs::File;
@ -335,6 +336,7 @@ pub struct SendArgs {
pub skip_tor: bool, pub skip_tor: bool,
pub outfile: Option<String>, pub outfile: Option<String>,
pub bridge: Option<String>, pub bridge: Option<String>,
pub slatepack_qr: bool,
} }
pub fn send<L, C, K>( pub fn send<L, C, K>(
@ -451,6 +453,7 @@ where
args.outfile, args.outfile,
true, true,
false, false,
args.slatepack_qr,
)?; )?;
} }
Err(e) => return Err(e.into()), Err(e) => return Err(e.into()),
@ -466,6 +469,7 @@ pub fn output_slatepack<L, C, K>(
out_file_override: Option<String>, out_file_override: Option<String>,
lock: bool, lock: bool,
finalizing: bool, finalizing: bool,
show_qr: bool,
) -> Result<(), libwallet::Error> ) -> Result<(), libwallet::Error>
where where
L: WalletLCProvider<'static, C, K> + 'static, L: WalletLCProvider<'static, C, K> + 'static,
@ -527,6 +531,12 @@ where
println!(); println!();
println!("{}", out_file_name); println!("{}", out_file_name);
println!(); println!();
if show_qr {
if let Ok(qr_string) = QrCode::new(message) {
println!("{}", qr_string.to_string(false, 3));
println!();
}
}
if address.is_some() { if address.is_some() {
println!("The slatepack data is encrypted for the recipient only"); println!("The slatepack data is encrypted for the recipient only");
} else { } else {
@ -610,6 +620,7 @@ pub struct ReceiveArgs {
pub skip_tor: bool, pub skip_tor: bool,
pub outfile: Option<String>, pub outfile: Option<String>,
pub bridge: Option<String>, pub bridge: Option<String>,
pub slatepack_qr: bool,
} }
pub fn receive<L, C, K>( pub fn receive<L, C, K>(
@ -679,6 +690,7 @@ where
args.outfile, args.outfile,
false, false,
false, false,
args.slatepack_qr,
)?; )?;
Ok(()) Ok(())
} }
@ -772,6 +784,7 @@ pub struct FinalizeArgs {
pub fluff: bool, pub fluff: bool,
pub nopost: bool, pub nopost: bool,
pub outfile: Option<String>, pub outfile: Option<String>,
pub slatepack_qr: bool,
} }
pub fn finalize<L, C, K>( pub fn finalize<L, C, K>(
@ -841,6 +854,7 @@ where
args.outfile, args.outfile,
false, false,
true, true,
args.slatepack_qr,
)?; )?;
Ok(()) Ok(())
@ -854,6 +868,8 @@ pub struct IssueInvoiceArgs {
pub issue_args: IssueInvoiceTxArgs, pub issue_args: IssueInvoiceTxArgs,
/// output file override /// output file override
pub outfile: Option<String>, pub outfile: Option<String>,
/// show slatepack as QR code
pub slatepack_qr: bool,
} }
pub fn issue_invoice_tx<L, C, K>( pub fn issue_invoice_tx<L, C, K>(
@ -882,6 +898,7 @@ where
args.outfile, args.outfile,
false, false,
false, false,
args.slatepack_qr,
)?; )?;
Ok(()) Ok(())
} }
@ -898,6 +915,7 @@ pub struct ProcessInvoiceArgs {
pub skip_tor: bool, pub skip_tor: bool,
pub outfile: Option<String>, pub outfile: Option<String>,
pub bridge: Option<String>, pub bridge: Option<String>,
pub slatepack_qr: bool,
} }
/// Process invoice /// Process invoice
@ -1004,6 +1022,7 @@ where
args.outfile, args.outfile,
true, true,
false, false,
args.slatepack_qr,
)?; )?;
Ok(()) Ok(())
} }

View file

@ -177,6 +177,10 @@ subcommands:
short: g short: g
long: bridge long: bridge
takes_value: true takes_value: true
- slatepack_qr:
help: Show slatepack data as QR code
short: q
long: slatepack_qr
- unpack: - unpack:
about: Unpack and display an armored Slatepack Message, decrypting if possible about: Unpack and display an armored Slatepack Message, decrypting if possible
args: args:
@ -207,6 +211,10 @@ subcommands:
short: g short: g
long: bridge long: bridge
takes_value: true takes_value: true
- slatepack_qr:
help: Show slatepack data as QR code
short: q
long: slatepack_qr
- finalize: - finalize:
about: Processes a Slatepack Message to finalize a transfer. about: Processes a Slatepack Message to finalize a transfer.
args: args:
@ -228,6 +236,10 @@ subcommands:
short: u short: u
long: outfile long: outfile
takes_value: true takes_value: true
- slatepack_qr:
help: Show slatepack data as QR code
short: q
long: slatepack_qr
- invoice: - invoice:
about: Initialize an invoice transaction, outputting a Slatepack Message with the result about: Initialize an invoice transaction, outputting a Slatepack Message with the result
args: args:
@ -244,6 +256,10 @@ subcommands:
short: u short: u
long: outfile long: outfile
takes_value: true takes_value: true
- slatepack_qr:
help: Show slatepack data as QR code
short: q
long: slatepack_qr
- pay: - pay:
about: Spend coins to pay the provided invoice transaction about: Spend coins to pay the provided invoice transaction
args: args:
@ -295,6 +311,10 @@ subcommands:
short: g short: g
long: bridge long: bridge
takes_value: true takes_value: true
- slatepack_qr:
help: Show slatepack data as QR code
short: q
long: slatepack_qr
- outputs: - outputs:
about: Raw wallet output info (list of outputs) about: Raw wallet output info (list of outputs)
- txs: - txs:

View file

@ -520,6 +520,8 @@ pub fn parse_send_args(args: &ArgMatches) -> Result<command::SendArgs, ParseErro
None => None, None => None,
}; };
let slatepack_qr = args.is_present("slatepack_qr");
Ok(command::SendArgs { Ok(command::SendArgs {
amount: amount, amount: amount,
minimum_confirmations: min_c, minimum_confirmations: min_c,
@ -536,6 +538,7 @@ pub fn parse_send_args(args: &ArgMatches) -> Result<command::SendArgs, ParseErro
outfile, outfile,
skip_tor: args.is_present("manual"), skip_tor: args.is_present("manual"),
bridge: bridge, bridge: bridge,
slatepack_qr: slatepack_qr,
}) })
} }
@ -563,12 +566,15 @@ pub fn parse_receive_args(args: &ArgMatches) -> Result<command::ReceiveArgs, Par
let bridge = parse_optional(args, "bridge")?; let bridge = parse_optional(args, "bridge")?;
let slatepack_qr = args.is_present("slatepack_qr");
Ok(command::ReceiveArgs { Ok(command::ReceiveArgs {
input_file, input_file,
input_slatepack_message, input_slatepack_message,
skip_tor: args.is_present("manual"), skip_tor: args.is_present("manual"),
outfile, outfile,
bridge, bridge,
slatepack_qr: slatepack_qr,
}) })
} }
@ -596,12 +602,15 @@ pub fn parse_unpack_args(args: &ArgMatches) -> Result<command::ReceiveArgs, Pars
let bridge = parse_optional(args, "bridge")?; let bridge = parse_optional(args, "bridge")?;
let slatepack_qr = args.is_present("slatepack_qr");
Ok(command::ReceiveArgs { Ok(command::ReceiveArgs {
input_file, input_file,
input_slatepack_message, input_slatepack_message,
skip_tor: args.is_present("manual"), skip_tor: args.is_present("manual"),
outfile, outfile,
bridge, bridge,
slatepack_qr: slatepack_qr,
}) })
} }
@ -629,12 +638,15 @@ pub fn parse_finalize_args(args: &ArgMatches) -> Result<command::FinalizeArgs, P
let outfile = parse_optional(args, "outfile")?; let outfile = parse_optional(args, "outfile")?;
let slatepack_qr = args.is_present("slatepack_qr");
Ok(command::FinalizeArgs { Ok(command::FinalizeArgs {
input_file, input_file,
input_slatepack_message, input_slatepack_message,
fluff: fluff, fluff: fluff,
nopost: nopost, nopost: nopost,
outfile, outfile,
slatepack_qr: slatepack_qr,
}) })
} }
@ -673,6 +685,8 @@ pub fn parse_issue_invoice_args(
let outfile = parse_optional(args, "outfile")?; let outfile = parse_optional(args, "outfile")?;
let slatepack_qr = args.is_present("slatepack_qr");
Ok(command::IssueInvoiceArgs { Ok(command::IssueInvoiceArgs {
dest: dest.into(), dest: dest.into(),
issue_args: IssueInvoiceTxArgs { issue_args: IssueInvoiceTxArgs {
@ -681,6 +695,7 @@ pub fn parse_issue_invoice_args(
target_slate_version, target_slate_version,
}, },
outfile, outfile,
slatepack_qr: slatepack_qr,
}) })
} }
@ -758,6 +773,8 @@ pub fn parse_process_invoice_args(
let bridge = parse_optional(args, "bridge")?; let bridge = parse_optional(args, "bridge")?;
let slatepack_qr = args.is_present("slatepack_qr");
Ok(command::ProcessInvoiceArgs { Ok(command::ProcessInvoiceArgs {
minimum_confirmations: min_c, minimum_confirmations: min_c,
selection_strategy: selection_strategy.to_owned(), selection_strategy: selection_strategy.to_owned(),
@ -769,6 +786,7 @@ pub fn parse_process_invoice_args(
skip_tor: args.is_present("manual"), skip_tor: args.is_present("manual"),
outfile, outfile,
bridge, bridge,
slatepack_qr: slatepack_qr,
}) })
} }