Skip to content

Commit 473136b

Browse files
authored
Improve wallet show output. (#4927)
## Motivation This is the result after a few discussions about what `wallet show` should look like. ## Proposal Add separators between the chains. Format everything in a "Key: Value" style. ## Test Plan Sample output: ``` 2025-11-06T16:46:41.842672Z INFO linera: Reading wallet from file: /tmp/.tmp6RClv1/wallet_0.json 2025-11-06T16:46:41.843635Z INFO linera_service::wallet: Found 4 chains ----------------------- Chain ID: 7471c597d573ef4d53934b9fcc6a05b9d46cb3718244d01ff817234ac2ae8c28 Tags: DEFAULT, ADMIN Parent chain: - Default owner: 0x227d131b5f2e3987daf184f2d22af7e7e0f174d2baca1228a45f12be11e80a5c Timestamp: 2025-11-06 16:46:37.399799 Blocks: 1 Epoch: 0 Latest block hash: 718814dae46334008efb769d5c24521c879cd756bb600c2bb56b09c1609d4c52 ----------------------- Chain ID: 5d719d9ace5441bdd4e4f7469fb3335445813935fdc2acc0dff60162642f2787 Parent chain: - Default owner: 0x929139f3c9b52dac48795038b7427aa5d07333718f74de7ea21c40fc28c11ae6 Timestamp: 2025-11-06 16:46:22.179469 Blocks: 0 Epoch: 0 ----------------------- ``` ## Release Plan - These changes should be backported to `testnet_conway`, then - be released in a new SDK. ## Links - Previous `wallet show` change: #4642 - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent f794632 commit 473136b

File tree

2 files changed

+38
-27
lines changed

2 files changed

+38
-27
lines changed

linera-service/src/cli/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2559,6 +2559,8 @@ async fn run(options: &ClientOptions) -> Result<i32, Error> {
25592559
short,
25602560
owned,
25612561
} => {
2562+
let wallet_path = options.wallet_path()?;
2563+
tracing::info!("Reading wallet from file: {}", wallet_path.display());
25622564
let wallet = options.wallet()?;
25632565
let chain_ids = if let Some(chain_id) = chain_id {
25642566
ensure!(!owned, "Cannot specify both --owned and a chain ID");

linera-service/src/wallet.rs

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@ use linera_base::{
77
};
88
pub use linera_client::wallet::*;
99

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

14-
if total_chains == 0 {
15-
println!("No chains in wallet.");
16-
return;
17-
}
18-
1914
let plural_s = if total_chains == 1 { "" } else { "s" };
20-
println!("\n\x1b[1mWALLET ({total_chains} chain{plural_s} in total)\x1b[0m",);
15+
tracing::info!("Found {total_chains} chain{plural_s}");
2116

2217
let mut chains = chain_ids
2318
.into_iter()
@@ -34,9 +29,9 @@ pub fn pretty_print(wallet: &Wallet, chain_ids: impl IntoIterator<Item = ChainId
3429
(!chain.is_default, !chain.is_admin, root_id, chain_id)
3530
});
3631
for chain in chains {
37-
println!();
3832
chain.print_paragraph();
3933
}
34+
println!("------------------------");
4035
}
4136

4237
struct ChainDetails<'a> {
@@ -65,36 +60,50 @@ impl<'a> ChainDetails<'a> {
6560
}
6661

6762
fn print_paragraph(&self) {
68-
let title = if self.is_admin {
69-
"Admin Chain".to_string()
70-
} else {
71-
match self.origin {
72-
Some(ChainOrigin::Root(i)) => format!("Root Chain {i}"),
73-
_ => "Child Chain".to_string(),
63+
println!("-----------------------");
64+
println!(" {:<20} {}", "Chain ID:", self.user_chain.chain_id);
65+
66+
let mut tags = Vec::new();
67+
if self.is_default {
68+
tags.push("DEFAULT");
69+
}
70+
if self.is_admin {
71+
tags.push("ADMIN");
72+
}
73+
if !tags.is_empty() {
74+
println!("{:<20} {}", "Tags:", tags.join(", "));
75+
}
76+
77+
match self.origin {
78+
Some(ChainOrigin::Root(_)) | None => {
79+
println!("{:<20} -", "Parent chain:");
7480
}
75-
};
76-
let default_marker = if self.is_default { " [DEFAULT]" } else { "" };
81+
Some(ChainOrigin::Child { parent, .. }) => {
82+
println!("{:<20} {parent}", "Parent chain:");
83+
}
84+
}
7785

78-
// Print chain header in bold
79-
println!("\x1b[1m{}{}\x1b[0m", title, default_marker);
80-
println!(" Chain ID: {}", self.user_chain.chain_id);
8186
if let Some(owner) = &self.user_chain.owner {
82-
println!(" Owner: {owner}");
87+
println!("{:<20} {owner}", "Default owner:");
8388
} else {
84-
println!(" Owner: No owner key");
89+
println!("{:<20} No owner key", "Default owner:");
8590
}
86-
println!(" Timestamp: {}", self.user_chain.timestamp);
87-
println!(" Blocks: {}", self.user_chain.next_block_height);
91+
92+
println!("{:<20} {}", "Timestamp:", self.user_chain.timestamp);
93+
println!("{:<20} {}", "Blocks:", self.user_chain.next_block_height);
94+
8895
if let Some(epoch) = self.user_chain.epoch {
89-
println!(" Epoch: {epoch}");
96+
println!("{:<20} {epoch}", "Epoch:");
9097
} else {
91-
println!(" Epoch: -");
98+
println!("{:<20} -", "Epoch:");
9299
}
100+
93101
if let Some(hash) = self.user_chain.block_hash {
94-
println!(" Latest Block: {}", hash);
102+
println!("{:<20} {hash}", "Latest block hash:");
95103
}
104+
96105
if self.user_chain.pending_proposal.is_some() {
97-
println!(" Status: ⚠ Pending proposal");
106+
println!("{:<20} present", "Pending proposal:");
98107
}
99108
}
100109
}

0 commit comments

Comments
 (0)