From ea10013f0461ace35f6f5af267026aa7e9ebe350 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Wed, 2 Dec 2020 13:16:39 -0700 Subject: [PATCH 1/2] Add credits_observed to verbose and json CliStakeStake prints --- cli-output/src/cli_output.rs | 29 ++++++++++++++++++++++++++--- cli/src/main.rs | 5 ++++- cli/src/stake.rs | 1 + 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/cli-output/src/cli_output.rs b/cli-output/src/cli_output.rs index ce28b5905113ea..444449137509ff 100644 --- a/cli-output/src/cli_output.rs +++ b/cli-output/src/cli_output.rs @@ -541,7 +541,15 @@ impl CliStakeVec { } impl QuietDisplay for CliStakeVec {} -impl VerboseDisplay for CliStakeVec {} +impl VerboseDisplay for CliStakeVec { + fn write_str(&self, w: &mut dyn std::fmt::Write) -> std::fmt::Result { + for state in &self.0 { + writeln!(w)?; + VerboseDisplay::write_str(state, w)?; + } + Ok(()) + } +} impl fmt::Display for CliStakeVec { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -562,7 +570,12 @@ pub struct CliKeyedStakeState { } impl QuietDisplay for CliKeyedStakeState {} -impl VerboseDisplay for CliKeyedStakeState {} +impl VerboseDisplay for CliKeyedStakeState { + fn write_str(&self, w: &mut dyn std::fmt::Write) -> std::fmt::Result { + writeln!(w, "Stake Pubkey: {}", self.stake_pubkey)?; + VerboseDisplay::write_str(&self.stake_state, w) + } +} impl fmt::Display for CliKeyedStakeState { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -658,6 +671,8 @@ pub struct CliStakeState { pub stake_type: CliStakeType, pub account_balance: u64, #[serde(skip_serializing_if = "Option::is_none")] + pub credits_observed: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub delegated_stake: Option, #[serde(skip_serializing_if = "Option::is_none")] pub delegated_vote_account_address: Option, @@ -686,7 +701,15 @@ pub struct CliStakeState { } impl QuietDisplay for CliStakeState {} -impl VerboseDisplay for CliStakeState {} +impl VerboseDisplay for CliStakeState { + fn write_str(&self, w: &mut dyn std::fmt::Write) -> std::fmt::Result { + write!(w, "{}", self)?; + if let Some(credits) = self.credits_observed { + writeln!(w, "Credits Observed: {}", credits)?; + } + Ok(()) + } +} impl fmt::Display for CliStakeState { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/cli/src/main.rs b/cli/src/main.rs index 2420cc3ca94235..ce91301ffe6750 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -168,7 +168,7 @@ pub fn parse_args<'a>( let CliCommandInfo { command, signers } = parse_command(&matches, &default_signer, &mut wallet_manager)?; - let output_format = matches + let mut output_format = matches .value_of("output_format") .map(|value| match value { "json" => OutputFormat::Json, @@ -176,6 +176,9 @@ pub fn parse_args<'a>( _ => unreachable!(), }) .unwrap_or(OutputFormat::Display); + if output_format == OutputFormat::Display && matches.is_present("verbose") { + output_format = OutputFormat::DisplayVerbose; + } let commitment = matches .subcommand_name() diff --git a/cli/src/stake.rs b/cli/src/stake.rs index fe1d7fbe059793..db0d5c55b19c89 100644 --- a/cli/src/stake.rs +++ b/cli/src/stake.rs @@ -1528,6 +1528,7 @@ pub fn build_stake_state( CliStakeState { stake_type: CliStakeType::Stake, account_balance, + credits_observed: Some(stake.credits_observed), delegated_stake: Some(stake.delegation.stake), delegated_vote_account_address: if stake.delegation.voter_pubkey != Pubkey::default() From e0b37be17517c05591f71405b3543f1c3c2e18f3 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Wed, 2 Dec 2020 13:46:55 -0700 Subject: [PATCH 2/2] Review comments --- cli/src/main.rs | 14 ++++++++------ cli/src/stake.rs | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index ce91301ffe6750..5425b238ab94b0 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -168,17 +168,19 @@ pub fn parse_args<'a>( let CliCommandInfo { command, signers } = parse_command(&matches, &default_signer, &mut wallet_manager)?; - let mut output_format = matches + let verbose = matches.is_present("verbose"); + let output_format = matches .value_of("output_format") .map(|value| match value { "json" => OutputFormat::Json, "json-compact" => OutputFormat::JsonCompact, _ => unreachable!(), }) - .unwrap_or(OutputFormat::Display); - if output_format == OutputFormat::Display && matches.is_present("verbose") { - output_format = OutputFormat::DisplayVerbose; - } + .unwrap_or(if verbose { + OutputFormat::DisplayVerbose + } else { + OutputFormat::Display + }); let commitment = matches .subcommand_name() @@ -201,7 +203,7 @@ pub fn parse_args<'a>( keypair_path: default_signer_path, rpc_client: None, rpc_timeout, - verbose: matches.is_present("verbose"), + verbose, output_format, commitment, send_transaction_config: RpcSendTransactionConfig::default(), diff --git a/cli/src/stake.rs b/cli/src/stake.rs index db0d5c55b19c89..68eb7fb59e74d0 100644 --- a/cli/src/stake.rs +++ b/cli/src/stake.rs @@ -1580,6 +1580,7 @@ pub fn build_stake_state( CliStakeState { stake_type: CliStakeType::Initialized, account_balance, + credits_observed: Some(0), authorized: Some(authorized.into()), lockup, use_lamports_unit,