multiversx_sdk_http/gateway_http_proxy/
http_block.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use anyhow::Result;
use multiversx_sdk::{
    data::hyperblock::HyperBlock,
    gateway::{GetHyperBlockRequest, NetworkStatusRequest},
};

use super::GatewayHttpProxy;

impl GatewayHttpProxy {
    // get_hyper_block_by_hash retrieves a hyper block's info by hash from the network
    pub async fn get_hyper_block_by_hash(&self, hash: &str) -> Result<HyperBlock> {
        self.http_request(GetHyperBlockRequest::by_hash(hash)).await
    }

    // get_hyper_block_by_nonce retrieves a hyper block's info by nonce from the network
    pub async fn get_hyper_block_by_nonce(&self, nonce: u64) -> Result<HyperBlock> {
        self.http_request(GetHyperBlockRequest::by_nonce(nonce))
            .await
    }

    // get_latest_hyper_block_nonce retrieves the latest hyper block (metachain) nonce from the network
    pub async fn get_latest_hyper_block_nonce(&self) -> Result<u64> {
        let network_status = self.http_request(NetworkStatusRequest::default()).await?;
        Ok(network_status.nonce)
    }
}