ark_rest/apis/
wallet_service_api.rs1use super::configuration;
12use super::ContentType;
13use super::Error;
14use crate::apis::ResponseContent;
15use crate::models;
16use reqwest;
17use serde::de::Error as _;
18use serde::Deserialize;
19use serde::Serialize;
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
23#[serde(untagged)]
24pub enum WalletServiceDeriveAddressError {
25 DefaultResponse(models::Status),
26 UnknownValue(serde_json::Value),
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum WalletServiceGetBalanceError {
33 DefaultResponse(models::Status),
34 UnknownValue(serde_json::Value),
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum WalletServiceLockError {
41 DefaultResponse(models::Status),
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum WalletServiceWithdrawError {
49 DefaultResponse(models::Status),
50 UnknownValue(serde_json::Value),
51}
52
53pub async fn wallet_service_derive_address(
54 configuration: &configuration::Configuration,
55) -> Result<models::DeriveAddressResponse, Error<WalletServiceDeriveAddressError>> {
56 let uri_str = format!("{}/v1/admin/wallet/address", configuration.base_path);
57 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
58
59 if let Some(ref user_agent) = configuration.user_agent {
60 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
61 }
62
63 let req = req_builder.build()?;
64 let resp = configuration.client.execute(req).await?;
65
66 let status = resp.status();
67 let content_type = resp
68 .headers()
69 .get("content-type")
70 .and_then(|v| v.to_str().ok())
71 .unwrap_or("application/octet-stream");
72 let content_type = super::ContentType::from(content_type);
73
74 if !status.is_client_error() && !status.is_server_error() {
75 let content = resp.text().await?;
76 match content_type {
77 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
78 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeriveAddressResponse`"))),
79 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::DeriveAddressResponse`")))),
80 }
81 } else {
82 let content = resp.text().await?;
83 let entity: Option<WalletServiceDeriveAddressError> = serde_json::from_str(&content).ok();
84 Err(Error::ResponseError(ResponseContent {
85 status,
86 content,
87 entity,
88 }))
89 }
90}
91
92pub async fn wallet_service_get_balance(
93 configuration: &configuration::Configuration,
94) -> Result<models::GetBalanceResponse, Error<WalletServiceGetBalanceError>> {
95 let uri_str = format!("{}/v1/admin/wallet/balance", configuration.base_path);
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
102 let req = req_builder.build()?;
103 let resp = configuration.client.execute(req).await?;
104
105 let status = resp.status();
106 let content_type = resp
107 .headers()
108 .get("content-type")
109 .and_then(|v| v.to_str().ok())
110 .unwrap_or("application/octet-stream");
111 let content_type = super::ContentType::from(content_type);
112
113 if !status.is_client_error() && !status.is_server_error() {
114 let content = resp.text().await?;
115 match content_type {
116 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
117 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetBalanceResponse`"))),
118 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::GetBalanceResponse`")))),
119 }
120 } else {
121 let content = resp.text().await?;
122 let entity: Option<WalletServiceGetBalanceError> = serde_json::from_str(&content).ok();
123 Err(Error::ResponseError(ResponseContent {
124 status,
125 content,
126 entity,
127 }))
128 }
129}
130
131pub async fn wallet_service_lock(
132 configuration: &configuration::Configuration,
133 body: serde_json::Value,
134) -> Result<serde_json::Value, Error<WalletServiceLockError>> {
135 let p_body = body;
137
138 let uri_str = format!("{}/v1/admin/wallet/lock", configuration.base_path);
139 let mut req_builder = configuration
140 .client
141 .request(reqwest::Method::POST, &uri_str);
142
143 if let Some(ref user_agent) = configuration.user_agent {
144 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
145 }
146 req_builder = req_builder.json(&p_body);
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 `serde_json::Value`"))),
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 `serde_json::Value`")))),
165 }
166 } else {
167 let content = resp.text().await?;
168 let entity: Option<WalletServiceLockError> = serde_json::from_str(&content).ok();
169 Err(Error::ResponseError(ResponseContent {
170 status,
171 content,
172 entity,
173 }))
174 }
175}
176
177pub async fn wallet_service_withdraw(
178 configuration: &configuration::Configuration,
179 withdraw_request: models::WithdrawRequest,
180) -> Result<models::WithdrawResponse, Error<WalletServiceWithdrawError>> {
181 let p_withdraw_request = withdraw_request;
183
184 let uri_str = format!("{}/v1/admin/wallet/withdraw", configuration.base_path);
185 let mut req_builder = configuration
186 .client
187 .request(reqwest::Method::POST, &uri_str);
188
189 if let Some(ref user_agent) = configuration.user_agent {
190 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
191 }
192 req_builder = req_builder.json(&p_withdraw_request);
193
194 let req = req_builder.build()?;
195 let resp = configuration.client.execute(req).await?;
196
197 let status = resp.status();
198 let content_type = resp
199 .headers()
200 .get("content-type")
201 .and_then(|v| v.to_str().ok())
202 .unwrap_or("application/octet-stream");
203 let content_type = super::ContentType::from(content_type);
204
205 if !status.is_client_error() && !status.is_server_error() {
206 let content = resp.text().await?;
207 match content_type {
208 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
209 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::WithdrawResponse`"))),
210 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::WithdrawResponse`")))),
211 }
212 } else {
213 let content = resp.text().await?;
214 let entity: Option<WalletServiceWithdrawError> = serde_json::from_str(&content).ok();
215 Err(Error::ResponseError(ResponseContent {
216 status,
217 content,
218 entity,
219 }))
220 }
221}