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..7a1a4df --- /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 `list-accounts` 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,