Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show slatepack QR codes #655

Merged
merged 2 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions controller/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
19 changes: 19 additions & 0 deletions controller/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>(
Expand Down Expand Up @@ -451,6 +453,7 @@ where
args.outfile,
true,
false,
args.slatepack_qr,
)?;
}
Err(e) => return Err(e.into()),
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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>(
Expand Down Expand Up @@ -679,6 +690,7 @@ where
args.outfile,
false,
false,
args.slatepack_qr,
)?;
Ok(())
}
Expand Down Expand Up @@ -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>(
Expand Down Expand Up @@ -841,6 +854,7 @@ where
args.outfile,
false,
true,
args.slatepack_qr,
)?;

Ok(())
Expand All @@ -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>(
Expand Down Expand Up @@ -882,6 +898,7 @@ where
args.outfile,
false,
false,
args.slatepack_qr,
)?;
Ok(())
}
Expand All @@ -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
Expand Down Expand Up @@ -1004,6 +1022,7 @@ where
args.outfile,
true,
false,
args.slatepack_qr,
)?;
Ok(())
}
Expand Down
20 changes: 20 additions & 0 deletions src/bin/grin-wallet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions src/cmd/wallet_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
})
}

Expand Down Expand Up @@ -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,
})
}

Expand Down Expand Up @@ -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,
})
}

Expand Down Expand Up @@ -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,
})
}

Expand Down Expand Up @@ -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 {
Expand All @@ -681,6 +695,7 @@ pub fn parse_issue_invoice_args(
target_slate_version,
},
outfile,
slatepack_qr: slatepack_qr,
})
}

Expand Down Expand Up @@ -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(),
Expand All @@ -769,6 +786,7 @@ pub fn parse_process_invoice_args(
skip_tor: args.is_present("manual"),
outfile,
bridge,
slatepack_qr: slatepack_qr,
})
}

Expand Down