Skip to main content

hanzo_client/apis/
explorer_api.rs

1/*
2 * Hanzo Cloud API
3 *
4 * The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
5 *
6 * The version of the OpenAPI document: v1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`get_explorer_indexers`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetExplorerIndexersError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_explorer_oracles`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetExplorerOraclesError {
29    UnknownValue(serde_json::Value),
30}
31
32
33/// Reports the deployment's chain indexer(s) and how far each has indexed. Identity and health come from the indexer's /health; the latest indexed block (height + time) from its /v1/explorer/blocks. The row EXISTS if EITHER call reaches the indexer; when the indexer is entirely unreachable the answer degrades to an honest-EMPTY list at 200, not a 502. No chain HEAD is exposed by the indexer REST, so `lag` is honestly omitted rather than fabricated.
34pub async fn get_explorer_indexers(configuration: &configuration::Configuration, ) -> Result<models::IndexersOut, Error<GetExplorerIndexersError>> {
35
36    let uri_str = format!("{}/v1/explorer/indexers", configuration.base_path);
37    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
38
39    if let Some(ref user_agent) = configuration.user_agent {
40        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
41    }
42    if let Some(ref token) = configuration.bearer_access_token {
43        req_builder = req_builder.bearer_auth(token.to_owned());
44    };
45
46    let req = req_builder.build()?;
47    let resp = configuration.client.execute(req).await?;
48
49    let status = resp.status();
50    let content_type = resp
51        .headers()
52        .get("content-type")
53        .and_then(|v| v.to_str().ok())
54        .unwrap_or("application/octet-stream");
55    let content_type = super::ContentType::from(content_type);
56
57    if !status.is_client_error() && !status.is_server_error() {
58        let content = resp.text().await?;
59        match content_type {
60            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
61            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::IndexersOut`"))),
62            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::IndexersOut`")))),
63        }
64    } else {
65        let content = resp.text().await?;
66        let entity: Option<GetExplorerIndexersError> = serde_json::from_str(&content).ok();
67        Err(Error::ResponseError(ResponseContent { status, content, entity }))
68    }
69}
70
71/// Reports the on-chain price/data oracles from the graph's O-Chain PriceFeed registry. A reachable graph with no feeds answers an honest empty list; an unreachable or erroring graph likewise degrades to an empty list at 200 rather than a 502, so the console never error-toasts. No feed is ever fabricated.
72pub async fn get_explorer_oracles(configuration: &configuration::Configuration, ) -> Result<models::OraclesOut, Error<GetExplorerOraclesError>> {
73
74    let uri_str = format!("{}/v1/explorer/oracles", configuration.base_path);
75    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
76
77    if let Some(ref user_agent) = configuration.user_agent {
78        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
79    }
80    if let Some(ref token) = configuration.bearer_access_token {
81        req_builder = req_builder.bearer_auth(token.to_owned());
82    };
83
84    let req = req_builder.build()?;
85    let resp = configuration.client.execute(req).await?;
86
87    let status = resp.status();
88    let content_type = resp
89        .headers()
90        .get("content-type")
91        .and_then(|v| v.to_str().ok())
92        .unwrap_or("application/octet-stream");
93    let content_type = super::ContentType::from(content_type);
94
95    if !status.is_client_error() && !status.is_server_error() {
96        let content = resp.text().await?;
97        match content_type {
98            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
99            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OraclesOut`"))),
100            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::OraclesOut`")))),
101        }
102    } else {
103        let content = resp.text().await?;
104        let entity: Option<GetExplorerOraclesError> = serde_json::from_str(&content).ok();
105        Err(Error::ResponseError(ResponseContent { status, content, entity }))
106    }
107}
108