GetBlockCountCommand

Struct GetBlockCountCommand 

Source
pub struct GetBlockCountCommand {}

Implementations§

Source§

impl GetBlockCountCommand

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.