hanzo_client/apis/
web3_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetWeb3ChainsError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetWeb3ChainsByChainError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetWeb3TokensByChainByAddressError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum PostWeb3RpcByChainError {
43 UnknownValue(serde_json::Value),
44}
45
46
47pub async fn get_web3_chains(configuration: &configuration::Configuration, ) -> Result<models::ChainList, Error<GetWeb3ChainsError>> {
49
50 let uri_str = format!("{}/v1/web3/chains", configuration.base_path);
51 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
52
53 if let Some(ref user_agent) = configuration.user_agent {
54 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
55 }
56 if let Some(ref token) = configuration.bearer_access_token {
57 req_builder = req_builder.bearer_auth(token.to_owned());
58 };
59
60 let req = req_builder.build()?;
61 let resp = configuration.client.execute(req).await?;
62
63 let status = resp.status();
64 let content_type = resp
65 .headers()
66 .get("content-type")
67 .and_then(|v| v.to_str().ok())
68 .unwrap_or("application/octet-stream");
69 let content_type = super::ContentType::from(content_type);
70
71 if !status.is_client_error() && !status.is_server_error() {
72 let content = resp.text().await?;
73 match content_type {
74 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
75 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ChainList`"))),
76 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::ChainList`")))),
77 }
78 } else {
79 let content = resp.text().await?;
80 let entity: Option<GetWeb3ChainsError> = serde_json::from_str(&content).ok();
81 Err(Error::ResponseError(ResponseContent { status, content, entity }))
82 }
83}
84
85pub async fn get_web3_chains_by_chain(configuration: &configuration::Configuration, chain: &str) -> Result<models::ChainStatus, Error<GetWeb3ChainsByChainError>> {
87 let p_chain = chain;
89
90 let uri_str = format!("{}/v1/web3/chains/{chain}", configuration.base_path, chain=crate::apis::urlencode(p_chain));
91 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
92
93 if let Some(ref user_agent) = configuration.user_agent {
94 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
95 }
96 if let Some(ref token) = configuration.bearer_access_token {
97 req_builder = req_builder.bearer_auth(token.to_owned());
98 };
99
100 let req = req_builder.build()?;
101 let resp = configuration.client.execute(req).await?;
102
103 let status = resp.status();
104 let content_type = resp
105 .headers()
106 .get("content-type")
107 .and_then(|v| v.to_str().ok())
108 .unwrap_or("application/octet-stream");
109 let content_type = super::ContentType::from(content_type);
110
111 if !status.is_client_error() && !status.is_server_error() {
112 let content = resp.text().await?;
113 match content_type {
114 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
115 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ChainStatus`"))),
116 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::ChainStatus`")))),
117 }
118 } else {
119 let content = resp.text().await?;
120 let entity: Option<GetWeb3ChainsByChainError> = serde_json::from_str(&content).ok();
121 Err(Error::ResponseError(ResponseContent { status, content, entity }))
122 }
123}
124
125pub async fn get_web3_tokens_by_chain_by_address(configuration: &configuration::Configuration, chain: &str, address: &str) -> Result<models::Balances, Error<GetWeb3TokensByChainByAddressError>> {
127 let p_chain = chain;
129 let p_address = address;
130
131 let uri_str = format!("{}/v1/web3/tokens/{chain}/{address}", configuration.base_path, chain=crate::apis::urlencode(p_chain), address=crate::apis::urlencode(p_address));
132 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
133
134 if let Some(ref user_agent) = configuration.user_agent {
135 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
136 }
137 if let Some(ref token) = configuration.bearer_access_token {
138 req_builder = req_builder.bearer_auth(token.to_owned());
139 };
140
141 let req = req_builder.build()?;
142 let resp = configuration.client.execute(req).await?;
143
144 let status = resp.status();
145 let content_type = resp
146 .headers()
147 .get("content-type")
148 .and_then(|v| v.to_str().ok())
149 .unwrap_or("application/octet-stream");
150 let content_type = super::ContentType::from(content_type);
151
152 if !status.is_client_error() && !status.is_server_error() {
153 let content = resp.text().await?;
154 match content_type {
155 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
156 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Balances`"))),
157 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::Balances`")))),
158 }
159 } else {
160 let content = resp.text().await?;
161 let entity: Option<GetWeb3TokensByChainByAddressError> = serde_json::from_str(&content).ok();
162 Err(Error::ResponseError(ResponseContent { status, content, entity }))
163 }
164}
165
166pub async fn post_web3_rpc_by_chain(configuration: &configuration::Configuration, chain: &str, rpc_in: models::RpcIn) -> Result<models::RpcOut, Error<PostWeb3RpcByChainError>> {
168 let p_chain = chain;
170 let p_rpc_in = rpc_in;
171
172 let uri_str = format!("{}/v1/web3/rpc/{chain}", configuration.base_path, chain=crate::apis::urlencode(p_chain));
173 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
174
175 if let Some(ref user_agent) = configuration.user_agent {
176 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
177 }
178 if let Some(ref token) = configuration.bearer_access_token {
179 req_builder = req_builder.bearer_auth(token.to_owned());
180 };
181 req_builder = req_builder.json(&p_rpc_in);
182
183 let req = req_builder.build()?;
184 let resp = configuration.client.execute(req).await?;
185
186 let status = resp.status();
187 let content_type = resp
188 .headers()
189 .get("content-type")
190 .and_then(|v| v.to_str().ok())
191 .unwrap_or("application/octet-stream");
192 let content_type = super::ContentType::from(content_type);
193
194 if !status.is_client_error() && !status.is_server_error() {
195 let content = resp.text().await?;
196 match content_type {
197 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
198 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RpcOut`"))),
199 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::RpcOut`")))),
200 }
201 } else {
202 let content = resp.text().await?;
203 let entity: Option<PostWeb3RpcByChainError> = serde_json::from_str(&content).ok();
204 Err(Error::ResponseError(ResponseContent { status, content, entity }))
205 }
206}
207