diff --git a/Cargo.lock b/Cargo.lock index 4b1abae1..89857028 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -538,6 +538,12 @@ version = "3.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" +[[package]] +name = "bytemuck" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" + [[package]] name = "byteorder" version = "1.5.0" @@ -1629,6 +1635,17 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "image" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd54d660e773627692c524beaad361aca785a4f9f5730ce91f42aabe5bce3d11" +dependencies = [ + "bytemuck", + "byteorder", + "num-traits", +] + [[package]] name = "indexmap" version = "1.9.3" @@ -1970,6 +1987,7 @@ dependencies = [ "moksha-core", "moksha-wallet", "num-format", + "qrcode", "tokio", "url", ] @@ -2625,6 +2643,15 @@ dependencies = [ "prost 0.12.3", ] +[[package]] +name = "qrcode" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23e719ca51966ff9f5a8436edb00d6115b3c606a0bb27c8f8ca74a38ff2b036d" +dependencies = [ + "image", +] + [[package]] name = "quote" version = "1.0.35" diff --git a/moksha-cli/Cargo.toml b/moksha-cli/Cargo.toml index 00d6bcbc..8ef559b1 100644 --- a/moksha-cli/Cargo.toml +++ b/moksha-cli/Cargo.toml @@ -22,3 +22,4 @@ url = "2.4.1" anyhow = { version = "1.0.75", features = ["backtrace"] } dialoguer = "0.11.0" num-format = "0.4.4" +qrcode = "0.14.0" diff --git a/moksha-cli/src/main.rs b/moksha-cli/src/main.rs index 66e3f842..3294d74c 100644 --- a/moksha-cli/src/main.rs +++ b/moksha-cli/src/main.rs @@ -13,6 +13,8 @@ use moksha_wallet::http::CrossPlatformHttpClient; use moksha_wallet::localstore::sqlite::SqliteLocalStore; use moksha_wallet::wallet::Wallet; use num_format::{Locale, ToFormattedString}; +use qrcode::render::unicode; +use qrcode::QrCode; use std::io::Write; use std::process::exit; use std::str::FromStr; @@ -95,15 +97,19 @@ async fn main() -> anyhow::Result<()> { println!("Mint added successfully "); } Command::Info => { - let wallet_version = env!("CARGO_PKG_VERSION"); + let wallet_version = style(env!("CARGO_PKG_VERSION")).cyan(); let mint_urls = wallet.get_mint_urls().await?; - println!("Version: {}\nDB: {}", wallet_version, db_path,); + let db_path = style(db_path).cyan(); + let term = Term::stdout(); + term.write_line(&format!("Version: {wallet_version}"))?; + term.write_line(&format!("DB: {db_path}"))?; + if mint_urls.is_empty() { - println!("No mints found."); + term.write_line("No mints found.")?; } else { - println!("Mints:"); + term.write_line("Mints:")?; for mint in mint_urls { - println!(" - {}", mint); + term.write_line(&format!(" - {}", mint))?; } } } @@ -381,7 +387,17 @@ async fn main() -> anyhow::Result<()> { quote, .. } = wallet.create_quote_bolt11(&mint_url, amount).await?; - println!("Pay invoice to mint tokens:\n\n{payment_request}"); + + let term = Term::stdout(); + term.write_line(&format!("Pay invoice to mint tokens:\n\n{payment_request}"))?; + + let image = QrCode::new(payment_request)? + .render::() + .dark_color(unicode::Dense1x2::Dark) + .light_color(unicode::Dense1x2::Light) + .build(); + + term.write_line(&image)?; quote } }; diff --git a/moksha-wallet/src/wallet.rs b/moksha-wallet/src/wallet.rs index 56d4f9b3..fb0ed382 100644 --- a/moksha-wallet/src/wallet.rs +++ b/moksha-wallet/src/wallet.rs @@ -24,7 +24,6 @@ use crate::{ }; use lightning_invoice::Bolt11Invoice as LNInvoice; use std::{ - any::Any, collections::{HashMap, HashSet}, str::FromStr, vec,