Skip to content

Commit

Permalink
rebase 5.3.X [PATCH 112/142] Show QR code for listener address (mimbl…
Browse files Browse the repository at this point in the history
  • Loading branch information
bayk committed Aug 9, 2024
1 parent e71b38f commit 991d3ca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
29 changes: 24 additions & 5 deletions controller/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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;

Expand All @@ -51,9 +52,11 @@ use crate::impls::tor::{bridge as tor_bridge, proxy as tor_proxy};
use crate::keychain::Keychain;
use chrono::Utc;
use easy_jsonrpc_mw::{Handler, MaybeReply};
use ed25519_dalek::PublicKey as DalekPublicKey;
use grin_wallet_impls::tor;
use grin_wallet_libwallet::proof::crypto;
use grin_wallet_libwallet::proof::proofaddress;
use grin_wallet_libwallet::proof::proofaddress::ProvableAddress;
use grin_wallet_util::grin_core::core::TxKernel;
use grin_wallet_util::grin_p2p;
use grin_wallet_util::grin_p2p::libp2p_connection;
Expand Down Expand Up @@ -987,12 +990,15 @@ where
);
}

// Check if wallet has been opened first
{
// Check if wallet has been opened first, get slatepack public key
let slatepack_pk = {
let mut w_lock = wallet.lock();
let lc = w_lock.lc_provider()?;
let _ = lc.wallet_inst()?;
}
let w = w_lock.lc_provider()?.wallet_inst()?;
let keychain = w.keychain(keychain_mask.lock().as_ref())?;
let slatepack_secret = proofaddress::payment_proof_address_dalek_secret(&keychain, None)?;
let slatepack_pk = DalekPublicKey::from(&slatepack_secret);
slatepack_pk
};

// need to keep in scope while the main listener is running
let tor_info = match use_tor {
Expand Down Expand Up @@ -1038,6 +1044,19 @@ where
.map_err(|e| ErrorKind::GenericError(format!("API thread failed to start, {}", e)))?;

warn!("HTTP Foreign listener started.");

{
let address = ProvableAddress::from_tor_pub_key(&slatepack_pk);
let qr_string = match QrCode::new(address.public_key.clone()) {
Ok(qr) => qr.to_string(false, 3),
Err(_) => "Failed to generate QR code!".to_string(),
};
warn!(
"Slatepack Address is: {}\n{}",
address.public_key, qr_string
);
}

*FOREIGN_API_RUNNING.write().unwrap() = true;

// Starting libp2p listener
Expand Down
2 changes: 1 addition & 1 deletion src/bin/mwc-wallet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ subcommands:
help: Request a payment proof from the recipient. If sending to a Tor address, the address will be filled automatically.
long: proof
- proof_address:
help: Recipient proof address. If not using Tor, must be provided seprarately by the recipient
help: Recipient proof address. If not using Tor, must be provided separately by the recipient
short: z
long: proof_address
takes_value: true
Expand Down

0 comments on commit 991d3ca

Please sign in to comment.