mirror of
https://github.com/mimblewimble/grin-wallet.git
synced 2025-01-20 19:11:09 +03:00
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:
parent
407f7df111
commit
95bb4c477e
5 changed files with 65 additions and 0 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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" }
|
||||
|
||||
|
|
|
@ -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<String>,
|
||||
pub bridge: Option<String>,
|
||||
pub slatepack_qr: bool,
|
||||
}
|
||||
|
||||
pub fn send<L, C, K>(
|
||||
|
@ -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<L, C, K>(
|
|||
out_file_override: Option<String>,
|
||||
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<String>,
|
||||
pub bridge: Option<String>,
|
||||
pub slatepack_qr: bool,
|
||||
}
|
||||
|
||||
pub fn receive<L, C, K>(
|
||||
|
@ -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<String>,
|
||||
pub slatepack_qr: bool,
|
||||
}
|
||||
|
||||
pub fn finalize<L, C, K>(
|
||||
|
@ -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<String>,
|
||||
/// show slatepack as QR code
|
||||
pub slatepack_qr: bool,
|
||||
}
|
||||
|
||||
pub fn issue_invoice_tx<L, C, K>(
|
||||
|
@ -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<String>,
|
||||
pub bridge: Option<String>,
|
||||
pub slatepack_qr: bool,
|
||||
}
|
||||
|
||||
/// Process invoice
|
||||
|
@ -1004,6 +1022,7 @@ where
|
|||
args.outfile,
|
||||
true,
|
||||
false,
|
||||
args.slatepack_qr,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -520,6 +520,8 @@ pub fn parse_send_args(args: &ArgMatches) -> Result<command::SendArgs, ParseErro
|
|||
None => 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<command::SendArgs, ParseErro
|
|||
outfile,
|
||||
skip_tor: args.is_present("manual"),
|
||||
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 slatepack_qr = args.is_present("slatepack_qr");
|
||||
|
||||
Ok(command::ReceiveArgs {
|
||||
input_file,
|
||||
input_slatepack_message,
|
||||
skip_tor: args.is_present("manual"),
|
||||
outfile,
|
||||
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 slatepack_qr = args.is_present("slatepack_qr");
|
||||
|
||||
Ok(command::ReceiveArgs {
|
||||
input_file,
|
||||
input_slatepack_message,
|
||||
skip_tor: args.is_present("manual"),
|
||||
outfile,
|
||||
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 slatepack_qr = args.is_present("slatepack_qr");
|
||||
|
||||
Ok(command::FinalizeArgs {
|
||||
input_file,
|
||||
input_slatepack_message,
|
||||
fluff: fluff,
|
||||
nopost: nopost,
|
||||
outfile,
|
||||
slatepack_qr: slatepack_qr,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -673,6 +685,8 @@ pub fn parse_issue_invoice_args(
|
|||
|
||||
let outfile = parse_optional(args, "outfile")?;
|
||||
|
||||
let slatepack_qr = args.is_present("slatepack_qr");
|
||||
|
||||
Ok(command::IssueInvoiceArgs {
|
||||
dest: dest.into(),
|
||||
issue_args: IssueInvoiceTxArgs {
|
||||
|
@ -681,6 +695,7 @@ pub fn parse_issue_invoice_args(
|
|||
target_slate_version,
|
||||
},
|
||||
outfile,
|
||||
slatepack_qr: slatepack_qr,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -758,6 +773,8 @@ pub fn parse_process_invoice_args(
|
|||
|
||||
let bridge = parse_optional(args, "bridge")?;
|
||||
|
||||
let slatepack_qr = args.is_present("slatepack_qr");
|
||||
|
||||
Ok(command::ProcessInvoiceArgs {
|
||||
minimum_confirmations: min_c,
|
||||
selection_strategy: selection_strategy.to_owned(),
|
||||
|
@ -769,6 +786,7 @@ pub fn parse_process_invoice_args(
|
|||
skip_tor: args.is_present("manual"),
|
||||
outfile,
|
||||
bridge,
|
||||
slatepack_qr: slatepack_qr,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue