* cli-output: Minor refactor of CliFees (cherry picked from commitebd56f7ff4
) * CLI: Support querying fees by blockhash (cherry picked from commit21e08b5b2c
) Co-authored-by: Trent Nelson <trent@solana.com>
This commit is contained in:
@@ -1406,17 +1406,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<Slot>,
|
||||
}
|
||||
|
||||
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(
|
||||
@@ -1424,8 +1424,51 @@ impl fmt::Display for CliFees {
|
||||
"Lamports per signature:",
|
||||
&self.lamports_per_signature.to_string(),
|
||||
)?;
|
||||
writeln_name_value(f, "Last valid slot:", &self.last_valid_slot.to_string())?;
|
||||
Ok(())
|
||||
let last_valid_slot = self
|
||||
.last_valid_slot
|
||||
.map(|s| s.to_string())
|
||||
.unwrap_or_default();
|
||||
writeln_name_value(f, "Last valid slot:", &last_valid_slot)
|
||||
}
|
||||
}
|
||||
|
||||
#[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 }
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user