Cli: add cluster-date subcommand, and make block-time slot optional (#9878)

* Add CliBlockTime struct

* Add cli cluster-date subcommand

* Make slot param optional; also jsonify

* Make prints prettier
This commit is contained in:
Tyera Eulberg
2020-05-05 09:42:03 -06:00
committed by GitHub
parent 16af67d5e1
commit b2672fd623
3 changed files with 82 additions and 19 deletions

View File

@@ -839,3 +839,26 @@ impl From<&Lockout> for CliLockout {
}
}
}
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CliBlockTime {
pub slot: Slot,
pub timestamp: UnixTimestamp,
}
impl fmt::Display for CliBlockTime {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln_name_value(f, "Block:", &self.slot.to_string())?;
writeln_name_value(
f,
"Date:",
&format!(
"{} (UnixTimestamp: {})",
DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(self.timestamp, 0), Utc)
.to_rfc3339_opts(SecondsFormat::Secs, true),
self.timestamp
),
)
}
}