coinbase_mesh/apis/
network_api.rs

1/*
2 * Rosetta
3 *
4 * Build Once. Integrate Your Blockchain Everywhere. 
5 *
6 * The version of the OpenAPI document: 1.4.13
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`network_list`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum NetworkListError {
22    Status500(models::Error),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`network_options`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum NetworkOptionsError {
30    Status500(models::Error),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`network_status`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum NetworkStatusError {
38    Status500(models::Error),
39    UnknownValue(serde_json::Value),
40}
41
42
43/// This endpoint returns a list of NetworkIdentifiers that the Rosetta server supports. 
44pub async fn network_list(configuration: &configuration::Configuration, metadata_request: models::MetadataRequest) -> Result<models::NetworkListResponse, Error<NetworkListError>> {
45    let local_var_configuration = configuration;
46
47    let local_var_client = &local_var_configuration.client;
48
49    let local_var_uri_str = format!("{}/network/list", local_var_configuration.base_path);
50    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
51
52    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
53        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
54    }
55    local_var_req_builder = local_var_req_builder.json(&metadata_request);
56
57    let local_var_req = local_var_req_builder.build()?;
58    let local_var_resp = local_var_client.execute(local_var_req).await?;
59
60    let local_var_status = local_var_resp.status();
61    let local_var_content = local_var_resp.text().await?;
62
63    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
64        serde_json::from_str(&local_var_content).map_err(Error::from)
65    } else {
66        let local_var_entity: Option<NetworkListError> = serde_json::from_str(&local_var_content).ok();
67        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
68        Err(Error::ResponseError(local_var_error))
69    }
70}
71
72/// This endpoint returns the version information and allowed network-specific types for a NetworkIdentifier. Any NetworkIdentifier returned by /network/list should be accessible here.  Because options are retrievable in the context of a NetworkIdentifier, it is possible to define unique options for each network. 
73pub async fn network_options(configuration: &configuration::Configuration, network_request: models::NetworkRequest) -> Result<models::NetworkOptionsResponse, Error<NetworkOptionsError>> {
74    let local_var_configuration = configuration;
75
76    let local_var_client = &local_var_configuration.client;
77
78    let local_var_uri_str = format!("{}/network/options", local_var_configuration.base_path);
79    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
80
81    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
82        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
83    }
84    local_var_req_builder = local_var_req_builder.json(&network_request);
85
86    let local_var_req = local_var_req_builder.build()?;
87    let local_var_resp = local_var_client.execute(local_var_req).await?;
88
89    let local_var_status = local_var_resp.status();
90    let local_var_content = local_var_resp.text().await?;
91
92    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
93        serde_json::from_str(&local_var_content).map_err(Error::from)
94    } else {
95        let local_var_entity: Option<NetworkOptionsError> = serde_json::from_str(&local_var_content).ok();
96        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
97        Err(Error::ResponseError(local_var_error))
98    }
99}
100
101/// This endpoint returns the current status of the network requested. Any NetworkIdentifier returned by /network/list should be accessible here. 
102pub async fn network_status(configuration: &configuration::Configuration, network_request: models::NetworkRequest) -> Result<models::NetworkStatusResponse, Error<NetworkStatusError>> {
103    let local_var_configuration = configuration;
104
105    let local_var_client = &local_var_configuration.client;
106
107    let local_var_uri_str = format!("{}/network/status", local_var_configuration.base_path);
108    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
109
110    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
111        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
112    }
113    local_var_req_builder = local_var_req_builder.json(&network_request);
114
115    let local_var_req = local_var_req_builder.build()?;
116    let local_var_resp = local_var_client.execute(local_var_req).await?;
117
118    let local_var_status = local_var_resp.status();
119    let local_var_content = local_var_resp.text().await?;
120
121    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
122        serde_json::from_str(&local_var_content).map_err(Error::from)
123    } else {
124        let local_var_entity: Option<NetworkStatusError> = serde_json::from_str(&local_var_content).ok();
125        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
126        Err(Error::ResponseError(local_var_error))
127    }
128}
129