hanzo_client/apis/
validator_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 GetValidatorError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetValidatorByTokenidError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetValidatorChallengeError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum PostValidatorError {
43 UnknownValue(serde_json::Value),
44}
45
46
47pub async fn get_validator(configuration: &configuration::Configuration, limit: Option<&str>) -> Result<models::ValidatorList, Error<GetValidatorError>> {
49 let p_limit = limit;
51
52 let uri_str = format!("{}/v1/validator", configuration.base_path);
53 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
54
55 if let Some(ref param_value) = p_limit {
56 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
57 }
58 if let Some(ref user_agent) = configuration.user_agent {
59 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
60 }
61 if let Some(ref token) = configuration.bearer_access_token {
62 req_builder = req_builder.bearer_auth(token.to_owned());
63 };
64
65 let req = req_builder.build()?;
66 let resp = configuration.client.execute(req).await?;
67
68 let status = resp.status();
69 let content_type = resp
70 .headers()
71 .get("content-type")
72 .and_then(|v| v.to_str().ok())
73 .unwrap_or("application/octet-stream");
74 let content_type = super::ContentType::from(content_type);
75
76 if !status.is_client_error() && !status.is_server_error() {
77 let content = resp.text().await?;
78 match content_type {
79 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
80 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ValidatorList`"))),
81 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::ValidatorList`")))),
82 }
83 } else {
84 let content = resp.text().await?;
85 let entity: Option<GetValidatorError> = serde_json::from_str(&content).ok();
86 Err(Error::ResponseError(ResponseContent { status, content, entity }))
87 }
88}
89
90pub async fn get_validator_by_tokenid(configuration: &configuration::Configuration, token_id: &str) -> Result<models::SlotView, Error<GetValidatorByTokenidError>> {
92 let p_token_id = token_id;
94
95 let uri_str = format!("{}/v1/validator/{tokenId}", configuration.base_path, tokenId=crate::apis::urlencode(p_token_id));
96 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
97
98 if let Some(ref user_agent) = configuration.user_agent {
99 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
100 }
101 if let Some(ref token) = configuration.bearer_access_token {
102 req_builder = req_builder.bearer_auth(token.to_owned());
103 };
104
105 let req = req_builder.build()?;
106 let resp = configuration.client.execute(req).await?;
107
108 let status = resp.status();
109 let content_type = resp
110 .headers()
111 .get("content-type")
112 .and_then(|v| v.to_str().ok())
113 .unwrap_or("application/octet-stream");
114 let content_type = super::ContentType::from(content_type);
115
116 if !status.is_client_error() && !status.is_server_error() {
117 let content = resp.text().await?;
118 match content_type {
119 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
120 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SlotView`"))),
121 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::SlotView`")))),
122 }
123 } else {
124 let content = resp.text().await?;
125 let entity: Option<GetValidatorByTokenidError> = serde_json::from_str(&content).ok();
126 Err(Error::ResponseError(ResponseContent { status, content, entity }))
127 }
128}
129
130pub async fn get_validator_challenge(configuration: &configuration::Configuration, token_id: Option<&str>) -> Result<models::ChallengeView, Error<GetValidatorChallengeError>> {
132 let p_token_id = token_id;
134
135 let uri_str = format!("{}/v1/validator/challenge", configuration.base_path);
136 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
137
138 if let Some(ref param_value) = p_token_id {
139 req_builder = req_builder.query(&[("tokenId", ¶m_value.to_string())]);
140 }
141 if let Some(ref user_agent) = configuration.user_agent {
142 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
143 }
144 if let Some(ref token) = configuration.bearer_access_token {
145 req_builder = req_builder.bearer_auth(token.to_owned());
146 };
147
148 let req = req_builder.build()?;
149 let resp = configuration.client.execute(req).await?;
150
151 let status = resp.status();
152 let content_type = resp
153 .headers()
154 .get("content-type")
155 .and_then(|v| v.to_str().ok())
156 .unwrap_or("application/octet-stream");
157 let content_type = super::ContentType::from(content_type);
158
159 if !status.is_client_error() && !status.is_server_error() {
160 let content = resp.text().await?;
161 match content_type {
162 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
163 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ChallengeView`"))),
164 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::ChallengeView`")))),
165 }
166 } else {
167 let content = resp.text().await?;
168 let entity: Option<GetValidatorChallengeError> = serde_json::from_str(&content).ok();
169 Err(Error::ResponseError(ResponseContent { status, content, entity }))
170 }
171}
172
173pub async fn post_validator(configuration: &configuration::Configuration, validator_claim: models::ValidatorClaim) -> Result<models::SlotView, Error<PostValidatorError>> {
175 let p_validator_claim = validator_claim;
177
178 let uri_str = format!("{}/v1/validator", configuration.base_path);
179 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
180
181 if let Some(ref user_agent) = configuration.user_agent {
182 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
183 }
184 if let Some(ref token) = configuration.bearer_access_token {
185 req_builder = req_builder.bearer_auth(token.to_owned());
186 };
187 req_builder = req_builder.json(&p_validator_claim);
188
189 let req = req_builder.build()?;
190 let resp = configuration.client.execute(req).await?;
191
192 let status = resp.status();
193 let content_type = resp
194 .headers()
195 .get("content-type")
196 .and_then(|v| v.to_str().ok())
197 .unwrap_or("application/octet-stream");
198 let content_type = super::ContentType::from(content_type);
199
200 if !status.is_client_error() && !status.is_server_error() {
201 let content = resp.text().await?;
202 match content_type {
203 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
204 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SlotView`"))),
205 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::SlotView`")))),
206 }
207 } else {
208 let content = resp.text().await?;
209 let entity: Option<PostValidatorError> = serde_json::from_str(&content).ok();
210 Err(Error::ResponseError(ResponseContent { status, content, entity }))
211 }
212}
213