multiversx_sdk/gateway/
gateway_network_config.rs

1use crate::data::network_config::{NetworkConfig, NetworkConfigResponse};
2use anyhow::anyhow;
3
4use super::{GatewayRequest, GatewayRequestType, NETWORK_CONFIG_ENDPOINT};
5
6/// Retrieves the network configuration from the proxy.
7pub struct NetworkConfigRequest;
8
9impl GatewayRequest for NetworkConfigRequest {
10    type Payload = ();
11    type DecodedJson = NetworkConfigResponse;
12    type Result = NetworkConfig;
13
14    fn request_type(&self) -> GatewayRequestType {
15        GatewayRequestType::Get
16    }
17
18    fn get_endpoint(&self) -> String {
19        NETWORK_CONFIG_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.config),
26        }
27    }
28}