cli-output: Minor refactor of CliFees
This commit is contained in:
committed by
Trent Nelson
parent
3998807dcc
commit
ebd56f7ff4
@ -1457,17 +1457,17 @@ impl fmt::Display for CliSupply {
|
|||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct CliFees {
|
pub struct CliFeesInner {
|
||||||
pub slot: Slot,
|
pub slot: Slot,
|
||||||
pub blockhash: String,
|
pub blockhash: String,
|
||||||
pub lamports_per_signature: u64,
|
pub lamports_per_signature: u64,
|
||||||
pub last_valid_slot: Slot,
|
pub last_valid_slot: Option<Slot>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl QuietDisplay for CliFees {}
|
impl QuietDisplay for CliFeesInner {}
|
||||||
impl VerboseDisplay for CliFees {}
|
impl VerboseDisplay for CliFeesInner {}
|
||||||
|
|
||||||
impl fmt::Display for CliFees {
|
impl fmt::Display for CliFeesInner {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
writeln_name_value(f, "Blockhash:", &self.blockhash)?;
|
writeln_name_value(f, "Blockhash:", &self.blockhash)?;
|
||||||
writeln_name_value(
|
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<CliFeesInner>,
|
||||||
|
}
|
||||||
|
|
||||||
|
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<Slot>,
|
||||||
|
) -> 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)]
|
#[derive(Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct CliTokenAccount {
|
pub struct CliTokenAccount {
|
||||||
|
@ -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 {
|
pub fn process_fees(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult {
|
||||||
let result = rpc_client.get_recent_blockhash_with_commitment(config.commitment)?;
|
let result = rpc_client.get_recent_blockhash_with_commitment(config.commitment)?;
|
||||||
let (recent_blockhash, fee_calculator, last_valid_slot) = result.value;
|
let (recent_blockhash, fee_calculator, last_valid_slot) = result.value;
|
||||||
let fees = CliFees {
|
let fees = CliFees::some(
|
||||||
slot: result.context.slot,
|
result.context.slot,
|
||||||
blockhash: recent_blockhash.to_string(),
|
recent_blockhash,
|
||||||
lamports_per_signature: fee_calculator.lamports_per_signature,
|
fee_calculator.lamports_per_signature,
|
||||||
last_valid_slot,
|
last_valid_slot,
|
||||||
};
|
);
|
||||||
Ok(config.output_format.formatted_string(&fees))
|
Ok(config.output_format.formatted_string(&fees))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user