Merge pull request #198 from vacp2p/arjentix/iss-185-wallet-list-all-accounts

feat: add list account subcommand
This commit is contained in:
Daniil Polyakov 2025-11-27 15:08:38 +03:00 committed by GitHub
commit 6a507fdad1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 0 deletions

View File

@ -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"

View File

@ -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)
}
}
}
}