Revamp the progress of current epoch in get-epoch-info (#7838)
* Revamp the progress of current epoch in get-epoch-info * Incorporate suggested more concise labelling
This commit is contained in:
parent
2d00657756
commit
e710964d05
|
@ -369,30 +369,44 @@ pub fn process_get_block_time(rpc_client: &RpcClient, slot: Slot) -> ProcessResu
|
||||||
Ok(timestamp.to_string())
|
Ok(timestamp.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn slot_to_human_time(slot: Slot) -> String {
|
||||||
|
humantime::format_duration(Duration::from_secs(
|
||||||
|
slot * clock::DEFAULT_TICKS_PER_SLOT / clock::DEFAULT_TICKS_PER_SECOND,
|
||||||
|
))
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn process_get_epoch_info(
|
pub fn process_get_epoch_info(
|
||||||
rpc_client: &RpcClient,
|
rpc_client: &RpcClient,
|
||||||
commitment_config: &CommitmentConfig,
|
commitment_config: &CommitmentConfig,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let epoch_info = rpc_client.get_epoch_info_with_commitment(commitment_config.clone())?;
|
let epoch_info = rpc_client.get_epoch_info_with_commitment(commitment_config.clone())?;
|
||||||
println!();
|
println!();
|
||||||
println_name_value("Current epoch:", &epoch_info.epoch.to_string());
|
println_name_value("Slot:", &epoch_info.absolute_slot.to_string());
|
||||||
println_name_value("Current slot:", &epoch_info.absolute_slot.to_string());
|
println_name_value("Epoch:", &epoch_info.epoch.to_string());
|
||||||
println_name_value(
|
println_name_value(
|
||||||
"Total slots in current epoch:",
|
"Epoch completed percent:",
|
||||||
&epoch_info.slots_in_epoch.to_string(),
|
&format!(
|
||||||
|
"{:>3.3}%",
|
||||||
|
epoch_info.slot_index as f64 / epoch_info.slots_in_epoch as f64 * 100_f64
|
||||||
|
),
|
||||||
);
|
);
|
||||||
let remaining_slots_in_epoch = epoch_info.slots_in_epoch - epoch_info.slot_index;
|
let remaining_slots_in_epoch = epoch_info.slots_in_epoch - epoch_info.slot_index;
|
||||||
println_name_value(
|
println_name_value(
|
||||||
"Remaining slots in current epoch:",
|
"Epoch completed slots:",
|
||||||
&remaining_slots_in_epoch.to_string(),
|
&format!(
|
||||||
);
|
"{}/{} ({} remaining)",
|
||||||
|
epoch_info.slot_index, epoch_info.slots_in_epoch, remaining_slots_in_epoch
|
||||||
let remaining_time_in_epoch = Duration::from_secs(
|
),
|
||||||
remaining_slots_in_epoch * clock::DEFAULT_TICKS_PER_SLOT / clock::DEFAULT_TICKS_PER_SECOND,
|
|
||||||
);
|
);
|
||||||
println_name_value(
|
println_name_value(
|
||||||
"Time remaining in current epoch:",
|
"Epoch completed time:",
|
||||||
&humantime::format_duration(remaining_time_in_epoch).to_string(),
|
&format!(
|
||||||
|
"{}/{} ({} remaining)",
|
||||||
|
slot_to_human_time(epoch_info.slot_index),
|
||||||
|
slot_to_human_time(epoch_info.slots_in_epoch),
|
||||||
|
slot_to_human_time(remaining_slots_in_epoch)
|
||||||
|
),
|
||||||
);
|
);
|
||||||
Ok("".to_string())
|
Ok("".to_string())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue