diff --git a/cli-output/src/cli_output.rs b/cli-output/src/cli_output.rs index a4270084a1..b53ec039fd 100644 --- a/cli-output/src/cli_output.rs +++ b/cli-output/src/cli_output.rs @@ -1457,17 +1457,17 @@ impl fmt::Display for CliSupply { #[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct CliFees { +pub struct CliFeesInner { pub slot: Slot, pub blockhash: String, pub lamports_per_signature: u64, - pub last_valid_slot: Slot, + pub last_valid_slot: Option, } -impl QuietDisplay for CliFees {} -impl VerboseDisplay for CliFees {} +impl QuietDisplay for CliFeesInner {} +impl VerboseDisplay for CliFeesInner {} -impl fmt::Display for CliFees { +impl fmt::Display for CliFeesInner { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { writeln_name_value(f, "Blockhash:", &self.blockhash)?; writeln_name_value( @@ -1480,6 +1480,46 @@ impl fmt::Display for CliFees { } } +#[derive(Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct CliFees { + #[serde(flatten, skip_serializing_if = "Option::is_none")] + pub inner: Option, +} + +impl QuietDisplay for CliFees {} +impl VerboseDisplay for CliFees {} + +impl fmt::Display for CliFees { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self.inner.as_ref() { + Some(inner) => write!(f, "{}", inner), + None => write!(f, "Fees unavailable"), + } + } +} + +impl CliFees { + pub fn some( + slot: Slot, + blockhash: Hash, + lamports_per_signature: u64, + last_valid_slot: Option, + ) -> Self { + Self { + inner: Some(CliFeesInner { + slot, + blockhash: blockhash.to_string(), + lamports_per_signature, + last_valid_slot, + }), + } + } + pub fn none() -> Self { + Self { inner: None } + } +} + #[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct CliTokenAccount { diff --git a/cli/src/cluster_query.rs b/cli/src/cluster_query.rs index 6d53e4f8db..a3986aec48 100644 --- a/cli/src/cluster_query.rs +++ b/cli/src/cluster_query.rs @@ -823,12 +823,12 @@ pub fn process_cluster_version(rpc_client: &RpcClient, config: &CliConfig) -> Pr pub fn process_fees(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult { let result = rpc_client.get_recent_blockhash_with_commitment(config.commitment)?; let (recent_blockhash, fee_calculator, last_valid_slot) = result.value; - let fees = CliFees { - slot: result.context.slot, - blockhash: recent_blockhash.to_string(), - lamports_per_signature: fee_calculator.lamports_per_signature, + let fees = CliFees::some( + result.context.slot, + recent_blockhash, + fee_calculator.lamports_per_signature, last_valid_slot, - }; + ); Ok(config.output_format.formatted_string(&fees)) }