Skip to main content

aptos_client_icp/apis/
general_api.rs

1/*
2 * Aptos Node API
3 *
4 * The Aptos Node API is a RESTful API for client applications to interact with the Aptos blockchain.
5 *
6 * The version of the OpenAPI document: 1.2.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, Error};
12use crate::{apis::ResponseContent, models};
13use serde::{Deserialize, Serialize};
14
15/// struct for typed errors of method [`get_ledger_info`]
16#[derive(Debug, Clone, Serialize, Deserialize)]
17#[serde(untagged)]
18pub enum GetLedgerInfoError {
19    Status400(models::AptosError),
20    Status403(models::AptosError),
21    Status500(models::AptosError),
22    Status503(models::AptosError),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`healthy`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum HealthyError {
30    Status503(models::AptosError),
31    Status500(models::AptosError),
32    UnknownValue(serde_json::Value),
33}
34
35/// struct for typed errors of method [`info`]
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum InfoError {
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`spec`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum SpecError {
46    UnknownValue(serde_json::Value),
47}
48
49/// Get the latest ledger information, including data such as chain ID, role type, ledger versions, epoch, etc.
50pub async fn get_ledger_info(
51    configuration: &configuration::Configuration,
52) -> Result<models::IndexResponse, Error<GetLedgerInfoError>> {
53    let local_var_configuration = configuration;
54
55    let local_var_client = &local_var_configuration.client;
56
57    let local_var_uri_str = format!("{}/", local_var_configuration.base_path);
58    let mut local_var_req_builder =
59        local_var_client.request(crate::http::HttpMethod::GET, local_var_uri_str.as_str());
60
61    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
62        local_var_req_builder =
63            local_var_req_builder.header("User-Agent".to_string(), local_var_user_agent.clone());
64    }
65
66    let local_var_req = local_var_req_builder.build()?;
67    let local_var_resp = local_var_client.execute(local_var_req).await?;
68
69    let local_var_status = local_var_resp.status();
70    let local_var_content = local_var_resp.text().await?;
71
72    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
73        serde_json::from_str(&local_var_content).map_err(Error::from)
74    } else {
75        let local_var_entity: Option<GetLedgerInfoError> =
76            serde_json::from_str(&local_var_content).ok();
77        let local_var_error = ResponseContent {
78            status: local_var_status,
79            content: local_var_content,
80            entity: local_var_entity,
81        };
82        Err(Error::ResponseError(local_var_error))
83    }
84}
85
86/// By default this endpoint just checks that it can get the latest ledger info and then returns 200.  If the duration_secs param is provided, this endpoint will return a 200 if the following condition is true:  `server_latest_ledger_info_timestamp >= server_current_time_timestamp - duration_secs`
87pub async fn healthy(
88    configuration: &configuration::Configuration,
89    duration_secs: Option<i32>,
90) -> Result<models::HealthCheckSuccess, Error<HealthyError>> {
91    let local_var_configuration = configuration;
92
93    let local_var_client = &local_var_configuration.client;
94
95    let local_var_uri_str = format!("{}/-/healthy", local_var_configuration.base_path);
96    let mut local_var_req_builder =
97        local_var_client.request(crate::http::HttpMethod::GET, local_var_uri_str.as_str());
98
99    if let Some(ref local_var_str) = duration_secs {
100        local_var_req_builder =
101            local_var_req_builder.query(&[("duration_secs", &local_var_str.to_string())]);
102    }
103    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
104        local_var_req_builder =
105            local_var_req_builder.header("User-Agent".to_string(), local_var_user_agent.clone());
106    }
107
108    let local_var_req = local_var_req_builder.build()?;
109    let local_var_resp = local_var_client.execute(local_var_req).await?;
110
111    let local_var_status = local_var_resp.status();
112    let local_var_content = local_var_resp.text().await?;
113
114    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
115        serde_json::from_str(&local_var_content).map_err(Error::from)
116    } else {
117        let local_var_entity: Option<HealthyError> = serde_json::from_str(&local_var_content).ok();
118        let local_var_error = ResponseContent {
119            status: local_var_status,
120            content: local_var_content,
121            entity: local_var_entity,
122        };
123        Err(Error::ResponseError(local_var_error))
124    }
125}
126
127pub async fn info(
128    configuration: &configuration::Configuration,
129) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<InfoError>> {
130    let local_var_configuration = configuration;
131
132    let local_var_client = &local_var_configuration.client;
133
134    let local_var_uri_str = format!("{}/info", local_var_configuration.base_path);
135    let mut local_var_req_builder =
136        local_var_client.request(crate::http::HttpMethod::GET, local_var_uri_str.as_str());
137
138    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
139        local_var_req_builder =
140            local_var_req_builder.header("User-Agent".to_string(), local_var_user_agent.clone());
141    }
142
143    let local_var_req = local_var_req_builder.build()?;
144    let local_var_resp = local_var_client.execute(local_var_req).await?;
145
146    let local_var_status = local_var_resp.status();
147    let local_var_content = local_var_resp.text().await?;
148
149    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
150        serde_json::from_str(&local_var_content).map_err(Error::from)
151    } else {
152        let local_var_entity: Option<InfoError> = serde_json::from_str(&local_var_content).ok();
153        let local_var_error = ResponseContent {
154            status: local_var_status,
155            content: local_var_content,
156            entity: local_var_entity,
157        };
158        Err(Error::ResponseError(local_var_error))
159    }
160}
161
162/// Provides a UI that you can use to explore the API. You can also retrieve the API directly at `/spec.yaml` and `/spec.json`.
163pub async fn spec(
164    configuration: &configuration::Configuration,
165) -> Result<String, Error<SpecError>> {
166    let local_var_configuration = configuration;
167
168    let local_var_client = &local_var_configuration.client;
169
170    let local_var_uri_str = format!("{}/spec", local_var_configuration.base_path);
171    let mut local_var_req_builder =
172        local_var_client.request(crate::http::HttpMethod::GET, local_var_uri_str.as_str());
173
174    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
175        local_var_req_builder =
176            local_var_req_builder.header("User-Agent".to_string(), local_var_user_agent.clone());
177    }
178
179    let local_var_req = local_var_req_builder.build()?;
180    let local_var_resp = local_var_client.execute(local_var_req).await?;
181
182    let local_var_status = local_var_resp.status();
183    let local_var_content = local_var_resp.text().await?;
184
185    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
186        serde_json::from_str(&local_var_content).map_err(Error::from)
187    } else {
188        let local_var_entity: Option<SpecError> = serde_json::from_str(&local_var_content).ok();
189        let local_var_error = ResponseContent {
190            status: local_var_status,
191            content: local_var_content,
192            entity: local_var_entity,
193        };
194        Err(Error::ResponseError(local_var_error))
195    }
196}