multiversx_sdk_http/gateway_http_proxy/
http_block.rs

1use anyhow::Result;
2use multiversx_sdk::{
3    data::hyperblock::HyperBlock,
4    gateway::{GetHyperBlockRequest, NetworkStatusRequest},
5};
6
7use super::GatewayHttpProxy;
8
9impl GatewayHttpProxy {
10    // get_hyper_block_by_hash retrieves a hyper block's info by hash from the network
11    pub async fn get_hyper_block_by_hash(&self, hash: &str) -> Result<HyperBlock> {
12        self.http_request(GetHyperBlockRequest::by_hash(hash)).await
13    }
14
15    // get_hyper_block_by_nonce retrieves a hyper block's info by nonce from the network
16    pub async fn get_hyper_block_by_nonce(&self, nonce: u64) -> Result<HyperBlock> {
17        self.http_request(GetHyperBlockRequest::by_nonce(nonce))
18            .await
19    }
20
21    // get_latest_hyper_block_nonce retrieves the latest hyper block (metachain) nonce from the network
22    pub async fn get_latest_hyper_block_nonce(&self) -> Result<u64> {
23        let network_status = self.http_request(NetworkStatusRequest::default()).await?;
24        Ok(network_status.nonce)
25    }
26}