Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: better UX for accounts and implicit_accounts commands #1815

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions cli/src/wallet_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use iota_sdk::{
types::{
api::plugins::participation::types::ParticipationEventId,
block::{
address::Bech32Address,
address::{Bech32Address, ToBech32Ext},
output::{
unlock_condition::AddressUnlockCondition, AccountId, BasicOutputBuilder, FoundryId, NativeToken,
NativeTokensBuilder, NftId, Output, OutputId, TokenId,
Expand Down Expand Up @@ -314,7 +314,25 @@ impl FromStr for OutputSelector {

// `accounts` command
pub async fn accounts_command(wallet: &Wallet) -> Result<(), Error> {
print_outputs(wallet.data().await.accounts().cloned().collect(), "Accounts:")
let wallet_data = wallet.data().await;
let accounts = wallet_data.accounts();

println_log_info!("Accounts:\n");

for account in accounts {
let output_id = account.output_id;
let account_id = account.output.as_account().account_id_non_null(&output_id);
let account_address = account_id.to_bech32(wallet.client().get_bech32_hrp().await?);

println_log_info!(
"{:<16} {output_id}\n{:<16} {account_id}\n{:<16} {account_address}\n",
"Output ID:",
"Account ID:",
"Account Address:"
);
}
Comment on lines +322 to +333
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be factored out into a function bc you do the same for the implicit accounts, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the same


Ok(())
}

// `address` command
Expand Down Expand Up @@ -612,10 +630,25 @@ pub async fn implicit_account_transition_command(

// `implicit-accounts` command
pub async fn implicit_accounts_command(wallet: &Wallet) -> Result<(), Error> {
print_outputs(
wallet.data().await.implicit_accounts().cloned().collect(),
"Implicit accounts:",
)
let wallet_data = wallet.data().await;
let implicit_accounts = wallet_data.implicit_accounts();

println_log_info!("Implicit accounts:\n");

for implicit_account in implicit_accounts {
let output_id = implicit_account.output_id;
let account_id = AccountId::from(&output_id);
let account_address = account_id.to_bech32(wallet.client().get_bech32_hrp().await?);

println_log_info!(
"{:<16} {output_id}\n{:<16} {account_id}\n{:<16} {account_address}\n",
"Output ID:",
"Account ID:",
"Account Address:"
);
}

Ok(())
}

// `melt-native-token` command
Expand Down