-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from zcash/zconvi_demo
Add QR code display to `list-addresses` and a `generate-address` command.
- Loading branch information
Showing
6 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use clap::Args; | ||
use uuid::Uuid; | ||
use zcash_client_backend::data_api::{Account, WalletWrite}; | ||
use zcash_client_sqlite::{util::SystemClock, WalletDb}; | ||
use zcash_keys::keys::UnifiedAddressRequest; | ||
|
||
use crate::{commands::select_account, config::get_wallet_network, data::get_db_paths}; | ||
|
||
#[cfg(feature = "qr")] | ||
use qrcode::{render::unicode, QrCode}; | ||
|
||
// Options accepted for the `list-addresses` command | ||
#[derive(Debug, Args)] | ||
pub(crate) struct Command { | ||
/// The UUID of the account to list addresses for | ||
account_id: Option<Uuid>, | ||
|
||
/// A flag indicating whether a QR code should be displayed for the address. | ||
#[cfg(feature = "qr")] | ||
#[arg(long, default_value = "true")] | ||
display_qr: bool, | ||
} | ||
|
||
impl Command { | ||
pub(crate) fn run(self, wallet_dir: Option<String>) -> anyhow::Result<()> { | ||
let params = get_wallet_network(wallet_dir.as_ref())?; | ||
let (_, db_data) = get_db_paths(wallet_dir.as_ref()); | ||
let mut db_data = WalletDb::for_path(db_data, params, SystemClock)?; | ||
|
||
let account = select_account(&db_data, self.account_id)?; | ||
|
||
println!("Account {:?}", account.id()); | ||
let (ua, _) = db_data | ||
.get_next_available_address(account.id(), UnifiedAddressRequest::AllAvailableKeys)? | ||
.unwrap(); | ||
let ua_str = ua.encode(¶ms); | ||
println!(" Address: {}", ua_str); | ||
|
||
#[cfg(feature = "qr")] | ||
if self.display_qr { | ||
let code = QrCode::new(ua_str)?; | ||
let ua_qr = code | ||
.render::<unicode::Dense1x2>() | ||
.dark_color(unicode::Dense1x2::Light) | ||
.light_color(unicode::Dense1x2::Dark) | ||
.quiet_zone(true) | ||
.build(); | ||
println!("{}", ua_qr); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters