Skip to content

Commit

Permalink
Merge pull request #40 from nuttycom/feature/list_accounts
Browse files Browse the repository at this point in the history
Add `list-accounts` command.
  • Loading branch information
str4d authored Sep 10, 2024
2 parents 3c077ae + 8e74d4e commit 2ffb85e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 33 additions & 0 deletions src/commands/list_accounts.rs
Original file line number Diff line number Diff line change
@@ -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<String>) -> 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(&params));
println!(
" UFVK: {}",
account
.ufvk()
.map_or("None".to_owned(), |k| k.encode(&params))
);
println!(" Source: {:?}", account.source());
}
Ok(())
}
}
1 change: 1 addition & 0 deletions src/commands/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<P: Parameters + Send + 'static>(
shutdown: &mut ShutdownListener,
client: &mut CompactTxStreamerClient<Channel>,
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2ffb85e

Please sign in to comment.