From 98a5dcdb8dfa236a6415e9ca67f35413899bea37 Mon Sep 17 00:00:00 2001 From: cliik Date: Fri, 24 Jun 2022 13:23:17 -0500 Subject: [PATCH] Show QR code for listener address --- Cargo.lock | 7 +++++++ controller/Cargo.toml | 1 + controller/src/controller.rs | 7 ++++++- controller/src/lib.rs | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) 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/controller.rs b/controller/src/controller.rs index 4952aff8e..3af87acf6 100644 --- a/controller/src/controller.rs +++ b/controller/src/controller.rs @@ -31,6 +31,7 @@ use grin_wallet_util::OnionV3Address; use hyper::body; use hyper::header::HeaderValue; use hyper::{Body, Request, Response, StatusCode}; +use qr_code::QrCode; use serde::{Deserialize, Serialize}; use serde_json; use std::collections::HashMap; @@ -351,7 +352,11 @@ where warn!("HTTP Foreign listener started."); if let Some(a) = address { - warn!("Slatepack Address is: {}", a); + let qr_string = match QrCode::new(a.to_string()) { + Ok(qr) => qr.to_string(false, 3), + Err(_) => "Failed to generate QR code!".to_string(), + }; + warn!("Slatepack Address is: {}\n{}", a, qr_string); } api_thread diff --git a/controller/src/lib.rs b/controller/src/lib.rs index c910e11c8..58015544c 100644 --- a/controller/src/lib.rs +++ b/controller/src/lib.rs @@ -21,6 +21,7 @@ extern crate prettytable; extern crate log; #[macro_use] extern crate lazy_static; +extern crate qr_code; use failure; use grin_wallet_api as apiwallet; use grin_wallet_config as config;