From 0bb328435fc79c7303b03b5ffa031753b65a27ed Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Thu, 29 Aug 2024 17:11:00 -0600 Subject: [PATCH 1/2] Add `list-accounts` command. --- src/commands.rs | 1 + src/commands/list_accounts.rs | 33 +++++++++++++++++++++++++++++++++ src/commands/sync.rs | 1 + src/main.rs | 4 ++++ 4 files changed, 39 insertions(+) create mode 100644 src/commands/list_accounts.rs diff --git a/src/commands.rs b/src/commands.rs index fa3ce15..2e929bb 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -2,6 +2,7 @@ pub(crate) mod balance; pub(crate) mod enhance; pub(crate) mod import_ufvk; pub(crate) mod init; +pub(crate) mod list_accounts; pub(crate) mod list_tx; pub(crate) mod list_unspent; pub(crate) mod propose; diff --git a/src/commands/list_accounts.rs b/src/commands/list_accounts.rs new file mode 100644 index 0000000..3b35dd7 --- /dev/null +++ b/src/commands/list_accounts.rs @@ -0,0 +1,33 @@ +use gumdrop::Options; + +use zcash_client_backend::data_api::{Account, WalletRead}; +use zcash_client_sqlite::WalletDb; + +use crate::data::{get_db_paths, get_wallet_network}; + +// Options accepted for the `import-ufvk` command +#[derive(Debug, Options)] +pub(crate) struct Command {} + +impl Command { + pub(crate) fn run(self, wallet_dir: Option) -> anyhow::Result<()> { + let params = get_wallet_network(wallet_dir.as_ref())?; + let (_, db_data) = get_db_paths(wallet_dir.as_ref()); + let db_data = WalletDb::for_path(db_data, params)?; + + for (i, account_id) in db_data.get_account_ids()?.iter().enumerate() { + let account = db_data.get_account(*account_id)?.unwrap(); + + println!("Account {}", i); + println!(" Uivk: {}", account.uivk().encode(¶ms)); + println!( + " Ufvk: {}", + account + .ufvk() + .map_or("None".to_owned(), |k| k.encode(¶ms)) + ); + println!(" Source: {:?}", account.source()); + } + Ok(()) + } +} diff --git a/src/commands/sync.rs b/src/commands/sync.rs index 98d9c34..52d45b4 100644 --- a/src/commands/sync.rs +++ b/src/commands/sync.rs @@ -105,6 +105,7 @@ impl Command { // 2) Pass the commitment tree data to the database. update_subtree_roots(&mut client, &mut db_data).await?; + #[allow(clippy::too_many_arguments)] async fn running( shutdown: &mut ShutdownListener, client: &mut CompactTxStreamerClient, diff --git a/src/main.rs b/src/main.rs index 00ae9ea..1041aa7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,6 +57,9 @@ enum Command { #[options(help = "get the balance in the wallet")] Balance(commands::balance::Command), + #[options(help = "list the accounts in the wallet")] + ListAccounts(commands::list_accounts::Command), + #[options(help = "list the transactions in the wallet")] ListTx(commands::list_tx::Command), @@ -134,6 +137,7 @@ fn main() -> Result<(), anyhow::Error> { } Some(Command::Enhance(command)) => command.run(opts.wallet_dir).await, Some(Command::Balance(command)) => command.run(opts.wallet_dir).await, + Some(Command::ListAccounts(command)) => command.run(opts.wallet_dir), Some(Command::ListTx(command)) => command.run(opts.wallet_dir), Some(Command::ListUnspent(command)) => command.run(opts.wallet_dir), Some(Command::Propose(command)) => command.run(opts.wallet_dir).await, From 8e74d4e8a4385c5f703bcfbcf88616d9a5e4441f Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 10 Sep 2024 19:52:38 +0100 Subject: [PATCH 2/2] list-accounts: Apply suggestions from code review --- src/commands/list_accounts.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/commands/list_accounts.rs b/src/commands/list_accounts.rs index 3b35dd7..7a1a4df 100644 --- a/src/commands/list_accounts.rs +++ b/src/commands/list_accounts.rs @@ -5,7 +5,7 @@ use zcash_client_sqlite::WalletDb; use crate::data::{get_db_paths, get_wallet_network}; -// Options accepted for the `import-ufvk` command +// Options accepted for the `list-accounts` command #[derive(Debug, Options)] pub(crate) struct Command {} @@ -19,9 +19,9 @@ impl Command { let account = db_data.get_account(*account_id)?.unwrap(); println!("Account {}", i); - println!(" Uivk: {}", account.uivk().encode(¶ms)); + println!(" UIVK: {}", account.uivk().encode(¶ms)); println!( - " Ufvk: {}", + " UFVK: {}", account .ufvk() .map_or("None".to_owned(), |k| k.encode(¶ms))