diff --git a/wallet/Cargo.toml b/wallet/Cargo.toml index b04d67e8..74eb5bc2 100644 --- a/wallet/Cargo.toml +++ b/wallet/Cargo.toml @@ -19,6 +19,7 @@ borsh.workspace = true base58.workspace = true hex = "0.4.3" rand.workspace = true +itertools = "0.14.0" [dependencies.key_protocol] path = "../key_protocol" diff --git a/wallet/src/cli/account.rs b/wallet/src/cli/account.rs index 79371c87..d1e361a3 100644 --- a/wallet/src/cli/account.rs +++ b/wallet/src/cli/account.rs @@ -1,6 +1,7 @@ use anyhow::Result; use base58::ToBase58; use clap::Subcommand; +use itertools::Itertools as _; use nssa::{Account, AccountId, program::Program}; use serde::Serialize; @@ -83,6 +84,9 @@ pub enum AccountSubcommand { New(NewSubcommand), /// Sync private accounts SyncPrivate {}, + /// List all accounts owned by the wallet + #[command(visible_alias = "ls")] + List {}, } /// Represents generic register CLI subcommand @@ -294,6 +298,23 @@ impl WalletSubcommand for AccountSubcommand { Ok(SubcommandReturnValue::SyncedToBlock(curr_last_block)) } + AccountSubcommand::List {} => { + let user_data = &wallet_core.storage.user_data; + let accounts = user_data + .pub_account_signing_keys + .keys() + .map(|id| format!("Public/{id}")) + .chain( + user_data + .user_private_accounts + .keys() + .map(|id| format!("Private/{id}")), + ) + .format(",\n"); + + println!("{accounts}"); + Ok(SubcommandReturnValue::Empty) + } } } }