multiversx_sdk/gateway/
gateway_network_economics.rs

1use crate::data::network_economics::{NetworkEconomics, NetworkEconomicsResponse};
2use anyhow::anyhow;
3
4use super::{GatewayRequest, GatewayRequestType, NETWORK_ECONOMICS_ENDPOINT};
5
6/// Retrieves the network economics from the proxy.
7pub struct NetworkEconimicsRequest;
8
9impl GatewayRequest for NetworkEconimicsRequest {
10    type Payload = ();
11    type DecodedJson = NetworkEconomicsResponse;
12    type Result = NetworkEconomics;
13
14    fn request_type(&self) -> GatewayRequestType {
15        GatewayRequestType::Get
16    }
17
18    fn get_endpoint(&self) -> String {
19        NETWORK_ECONOMICS_ENDPOINT.to_owned()
20    }
21
22    fn process_json(&self, decoded: Self::DecodedJson) -> anyhow::Result<Self::Result> {
23        match decoded.data {
24            None => Err(anyhow!("{}", decoded.error)),
25            Some(b) => Ok(b.metrics),
26        }
27    }
28}