pub struct GetBlockCountCommand {}
Implementations§
Source§impl GetBlockCountCommand
impl GetBlockCountCommand
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/example.rs (line 54)
53fn get_block_height(client: &Client) -> u64 {
54 let block_count = GetBlockCountCommand::new().call(client);
55 return block_count.unwrap().0;
56}
57
58fn get_time_since_last_block(client: &Client) -> Seconds {
59 let block_count = GetBlockCountCommand::new().call(client);
60 let arg = TargetBlockArgument::Height(block_count.unwrap().0);
61 let maybe_block_stats_response = GetBlockStatsCommand::new(arg).call(client);
62 let time_of_last_block = match maybe_block_stats_response {
63 Ok(block_stats_response) => match block_stats_response {
64 GetBlockStatsCommandResponse::AllStats(response) => response.time,
65 GetBlockStatsCommandResponse::SelectiveStats(response) => response.time.unwrap(),
66 },
67 Err(_) => panic!("panic"),
68 };
69 let current_datetime = chrono::offset::Utc::now();
70 let current_timestamp = current_datetime.timestamp();
71 let datetime_of_last_block = Utc.timestamp(time_of_last_block as i64, 0);
72 let difference = current_datetime.signed_duration_since(datetime_of_last_block);
73 Seconds(difference.num_seconds())
74
75 //match SystemTime::now().duration_since(time_of_last_block) {
76 // Ok(seconds) => Ok(seconds.as_secs()),
77 // Err(err) => Err(err),
78 //}
79}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GetBlockCountCommand
impl RefUnwindSafe for GetBlockCountCommand
impl Send for GetBlockCountCommand
impl Sync for GetBlockCountCommand
impl Unpin for GetBlockCountCommand
impl UnwindSafe for GetBlockCountCommand
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more