Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions linera-service/src/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2559,6 +2559,8 @@ async fn run(options: &ClientOptions) -> Result<i32, Error> {
short,
owned,
} => {
let wallet_path = options.wallet_path()?;
tracing::info!("Reading wallet from file: {}", wallet_path.display());
let wallet = options.wallet()?;
let chain_ids = if let Some(chain_id) = chain_id {
ensure!(!owned, "Cannot specify both --owned and a chain ID");
Expand Down
63 changes: 36 additions & 27 deletions linera-service/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@ use linera_base::{
};
pub use linera_client::wallet::*;

pub fn pretty_print(wallet: &Wallet, chain_ids: impl IntoIterator<Item = ChainId>) {
pub fn pretty_print(wallet: &Wallet, chain_ids: Vec<ChainId>) {
let chain_ids: Vec<_> = chain_ids.into_iter().collect();
let total_chains = chain_ids.len();

if total_chains == 0 {
println!("No chains in wallet.");
return;
}

let plural_s = if total_chains == 1 { "" } else { "s" };
println!("\n\x1b[1mWALLET ({total_chains} chain{plural_s} in total)\x1b[0m",);
tracing::info!("Found {total_chains} chain{plural_s}");

let mut chains = chain_ids
.into_iter()
Expand All @@ -34,9 +29,9 @@ pub fn pretty_print(wallet: &Wallet, chain_ids: impl IntoIterator<Item = ChainId
(!chain.is_default, !chain.is_admin, root_id, chain_id)
});
for chain in chains {
println!();
chain.print_paragraph();
}
println!("------------------------");
}

struct ChainDetails<'a> {
Expand Down Expand Up @@ -65,36 +60,50 @@ impl<'a> ChainDetails<'a> {
}

fn print_paragraph(&self) {
let title = if self.is_admin {
"Admin Chain".to_string()
} else {
match self.origin {
Some(ChainOrigin::Root(i)) => format!("Root Chain {i}"),
_ => "Child Chain".to_string(),
println!("-----------------------");
println!(" {:<20} {}", "Chain ID:", self.user_chain.chain_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

We could almost remove the indentation if we wanted now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you prefer that?

Do you mean remove the two leading spaces, or remove the alignment of the values?

Copy link
Contributor

Choose a reason for hiding this comment

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

the leading spaces


let mut tags = Vec::new();
if self.is_default {
tags.push("DEFAULT");
}
if self.is_admin {
tags.push("ADMIN");
}
if !tags.is_empty() {
println!("{:<20} {}", "Tags:", tags.join(", "));
}

match self.origin {
Some(ChainOrigin::Root(_)) | None => {
println!("{:<20} -", "Parent chain:");
}
};
let default_marker = if self.is_default { " [DEFAULT]" } else { "" };
Some(ChainOrigin::Child { parent, .. }) => {
println!("{:<20} {parent}", "Parent chain:");
}
}

// Print chain header in bold
println!("\x1b[1m{}{}\x1b[0m", title, default_marker);
println!(" Chain ID: {}", self.user_chain.chain_id);
if let Some(owner) = &self.user_chain.owner {
println!(" Owner: {owner}");
println!("{:<20} {owner}", "Default owner:");
} else {
println!(" Owner: No owner key");
println!("{:<20} No owner key", "Default owner:");
}
println!(" Timestamp: {}", self.user_chain.timestamp);
println!(" Blocks: {}", self.user_chain.next_block_height);

println!("{:<20} {}", "Timestamp:", self.user_chain.timestamp);
println!("{:<20} {}", "Blocks:", self.user_chain.next_block_height);

if let Some(epoch) = self.user_chain.epoch {
println!(" Epoch: {epoch}");
println!("{:<20} {epoch}", "Epoch:");
} else {
println!(" Epoch: -");
println!("{:<20} -", "Epoch:");
}

if let Some(hash) = self.user_chain.block_hash {
println!(" Latest Block: {}", hash);
println!("{:<20} {hash}", "Latest block hash:");
}

if self.user_chain.pending_proposal.is_some() {
println!(" Status: ⚠ Pending proposal");
println!("{:<20} present", "Pending proposal:");
}
}
}
Loading