1use {
10 super::{configuration, Error},
11 crate::{apis::ResponseContent, models},
12 async_trait::async_trait,
13 reqwest,
14 serde::{Deserialize, Serialize},
15 std::sync::Arc,
16};
17
18#[async_trait]
19pub trait DeployedContractsApi: Send + Sync {
20 async fn add_contract_abi(
21 &self,
22 params: AddContractAbiParams,
23 ) -> Result<models::ContractWithAbiDto, Error<AddContractAbiError>>;
24 async fn fetch_contract_abi(
25 &self,
26 params: FetchContractAbiParams,
27 ) -> Result<models::ContractWithAbiDto, Error<FetchContractAbiError>>;
28 async fn get_deployed_contract_by_address(
29 &self,
30 params: GetDeployedContractByAddressParams,
31 ) -> Result<models::DeployedContractResponseDto, Error<GetDeployedContractByAddressError>>;
32 async fn get_deployed_contract_by_id(
33 &self,
34 params: GetDeployedContractByIdParams,
35 ) -> Result<models::DeployedContractResponseDto, Error<GetDeployedContractByIdError>>;
36 async fn get_deployed_contracts(
37 &self,
38 params: GetDeployedContractsParams,
39 ) -> Result<models::DeployedContractsPaginatedResponse, Error<GetDeployedContractsError>>;
40}
41
42pub struct DeployedContractsApiClient {
43 configuration: Arc<configuration::Configuration>,
44}
45
46impl DeployedContractsApiClient {
47 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
48 Self { configuration }
49 }
50}
51
52#[derive(Clone, Debug)]
54#[cfg_attr(feature = "bon", derive(::bon::Builder))]
55pub struct AddContractAbiParams {
56 pub add_abi_request_dto: models::AddAbiRequestDto,
57 pub idempotency_key: Option<String>,
62}
63
64#[derive(Clone, Debug)]
66#[cfg_attr(feature = "bon", derive(::bon::Builder))]
67pub struct FetchContractAbiParams {
68 pub fetch_abi_request_dto: models::FetchAbiRequestDto,
69 pub idempotency_key: Option<String>,
74}
75
76#[derive(Clone, Debug)]
79#[cfg_attr(feature = "bon", derive(::bon::Builder))]
80pub struct GetDeployedContractByAddressParams {
81 pub contract_address: String,
83 pub asset_id: String,
85}
86
87#[derive(Clone, Debug)]
89#[cfg_attr(feature = "bon", derive(::bon::Builder))]
90pub struct GetDeployedContractByIdParams {
91 pub id: String,
93}
94
95#[derive(Clone, Debug)]
97#[cfg_attr(feature = "bon", derive(::bon::Builder))]
98pub struct GetDeployedContractsParams {
99 pub page_cursor: Option<String>,
101 pub page_size: Option<f64>,
103 pub contract_address: Option<String>,
105 pub base_asset_id: Option<String>,
107 pub contract_template_id: Option<String>,
109}
110
111#[async_trait]
112impl DeployedContractsApi for DeployedContractsApiClient {
113 async fn add_contract_abi(
116 &self,
117 params: AddContractAbiParams,
118 ) -> Result<models::ContractWithAbiDto, Error<AddContractAbiError>> {
119 let AddContractAbiParams {
120 add_abi_request_dto,
121 idempotency_key,
122 } = params;
123
124 let local_var_configuration = &self.configuration;
125
126 let local_var_client = &local_var_configuration.client;
127
128 let local_var_uri_str = format!(
129 "{}/tokenization/contracts/abi",
130 local_var_configuration.base_path
131 );
132 let mut local_var_req_builder =
133 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
134
135 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
136 local_var_req_builder = local_var_req_builder
137 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
138 }
139 if let Some(local_var_param_value) = idempotency_key {
140 local_var_req_builder =
141 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
142 }
143 local_var_req_builder = local_var_req_builder.json(&add_abi_request_dto);
144
145 let local_var_req = local_var_req_builder.build()?;
146 let local_var_resp = local_var_client.execute(local_var_req).await?;
147
148 let local_var_status = local_var_resp.status();
149 let local_var_content = local_var_resp.text().await?;
150
151 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
152 serde_json::from_str(&local_var_content).map_err(Error::from)
153 } else {
154 let local_var_entity: Option<AddContractAbiError> =
155 serde_json::from_str(&local_var_content).ok();
156 let local_var_error = ResponseContent {
157 status: local_var_status,
158 content: local_var_content,
159 entity: local_var_entity,
160 };
161 Err(Error::ResponseError(local_var_error))
162 }
163 }
164
165 async fn fetch_contract_abi(
169 &self,
170 params: FetchContractAbiParams,
171 ) -> Result<models::ContractWithAbiDto, Error<FetchContractAbiError>> {
172 let FetchContractAbiParams {
173 fetch_abi_request_dto,
174 idempotency_key,
175 } = params;
176
177 let local_var_configuration = &self.configuration;
178
179 let local_var_client = &local_var_configuration.client;
180
181 let local_var_uri_str = format!(
182 "{}/tokenization/contracts/fetch_abi",
183 local_var_configuration.base_path
184 );
185 let mut local_var_req_builder =
186 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
187
188 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
189 local_var_req_builder = local_var_req_builder
190 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
191 }
192 if let Some(local_var_param_value) = idempotency_key {
193 local_var_req_builder =
194 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
195 }
196 local_var_req_builder = local_var_req_builder.json(&fetch_abi_request_dto);
197
198 let local_var_req = local_var_req_builder.build()?;
199 let local_var_resp = local_var_client.execute(local_var_req).await?;
200
201 let local_var_status = local_var_resp.status();
202 let local_var_content = local_var_resp.text().await?;
203
204 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
205 serde_json::from_str(&local_var_content).map_err(Error::from)
206 } else {
207 let local_var_entity: Option<FetchContractAbiError> =
208 serde_json::from_str(&local_var_content).ok();
209 let local_var_error = ResponseContent {
210 status: local_var_status,
211 content: local_var_content,
212 entity: local_var_entity,
213 };
214 Err(Error::ResponseError(local_var_error))
215 }
216 }
217
218 async fn get_deployed_contract_by_address(
222 &self,
223 params: GetDeployedContractByAddressParams,
224 ) -> Result<models::DeployedContractResponseDto, Error<GetDeployedContractByAddressError>> {
225 let GetDeployedContractByAddressParams {
226 contract_address,
227 asset_id,
228 } = params;
229
230 let local_var_configuration = &self.configuration;
231
232 let local_var_client = &local_var_configuration.client;
233
234 let local_var_uri_str = format!(
235 "{}/tokenization/contracts/{assetId}/{contractAddress}",
236 local_var_configuration.base_path,
237 contractAddress = crate::apis::urlencode(contract_address),
238 assetId = crate::apis::urlencode(asset_id)
239 );
240 let mut local_var_req_builder =
241 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
242
243 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
244 local_var_req_builder = local_var_req_builder
245 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
246 }
247
248 let local_var_req = local_var_req_builder.build()?;
249 let local_var_resp = local_var_client.execute(local_var_req).await?;
250
251 let local_var_status = local_var_resp.status();
252 let local_var_content = local_var_resp.text().await?;
253
254 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
255 serde_json::from_str(&local_var_content).map_err(Error::from)
256 } else {
257 let local_var_entity: Option<GetDeployedContractByAddressError> =
258 serde_json::from_str(&local_var_content).ok();
259 let local_var_error = ResponseContent {
260 status: local_var_status,
261 content: local_var_content,
262 entity: local_var_entity,
263 };
264 Err(Error::ResponseError(local_var_error))
265 }
266 }
267
268 async fn get_deployed_contract_by_id(
271 &self,
272 params: GetDeployedContractByIdParams,
273 ) -> Result<models::DeployedContractResponseDto, Error<GetDeployedContractByIdError>> {
274 let GetDeployedContractByIdParams { id } = params;
275
276 let local_var_configuration = &self.configuration;
277
278 let local_var_client = &local_var_configuration.client;
279
280 let local_var_uri_str = format!(
281 "{}/tokenization/contracts/{id}",
282 local_var_configuration.base_path,
283 id = crate::apis::urlencode(id)
284 );
285 let mut local_var_req_builder =
286 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
287
288 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
289 local_var_req_builder = local_var_req_builder
290 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
291 }
292
293 let local_var_req = local_var_req_builder.build()?;
294 let local_var_resp = local_var_client.execute(local_var_req).await?;
295
296 let local_var_status = local_var_resp.status();
297 let local_var_content = local_var_resp.text().await?;
298
299 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
300 serde_json::from_str(&local_var_content).map_err(Error::from)
301 } else {
302 let local_var_entity: Option<GetDeployedContractByIdError> =
303 serde_json::from_str(&local_var_content).ok();
304 let local_var_error = ResponseContent {
305 status: local_var_status,
306 content: local_var_content,
307 entity: local_var_entity,
308 };
309 Err(Error::ResponseError(local_var_error))
310 }
311 }
312
313 async fn get_deployed_contracts(
317 &self,
318 params: GetDeployedContractsParams,
319 ) -> Result<models::DeployedContractsPaginatedResponse, Error<GetDeployedContractsError>> {
320 let GetDeployedContractsParams {
321 page_cursor,
322 page_size,
323 contract_address,
324 base_asset_id,
325 contract_template_id,
326 } = params;
327
328 let local_var_configuration = &self.configuration;
329
330 let local_var_client = &local_var_configuration.client;
331
332 let local_var_uri_str = format!(
333 "{}/tokenization/contracts",
334 local_var_configuration.base_path
335 );
336 let mut local_var_req_builder =
337 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
338
339 if let Some(ref local_var_str) = page_cursor {
340 local_var_req_builder =
341 local_var_req_builder.query(&[("pageCursor", &local_var_str.to_string())]);
342 }
343 if let Some(ref local_var_str) = page_size {
344 local_var_req_builder =
345 local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
346 }
347 if let Some(ref local_var_str) = contract_address {
348 local_var_req_builder =
349 local_var_req_builder.query(&[("contractAddress", &local_var_str.to_string())]);
350 }
351 if let Some(ref local_var_str) = base_asset_id {
352 local_var_req_builder =
353 local_var_req_builder.query(&[("baseAssetId", &local_var_str.to_string())]);
354 }
355 if let Some(ref local_var_str) = contract_template_id {
356 local_var_req_builder =
357 local_var_req_builder.query(&[("contractTemplateId", &local_var_str.to_string())]);
358 }
359 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
360 local_var_req_builder = local_var_req_builder
361 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
362 }
363
364 let local_var_req = local_var_req_builder.build()?;
365 let local_var_resp = local_var_client.execute(local_var_req).await?;
366
367 let local_var_status = local_var_resp.status();
368 let local_var_content = local_var_resp.text().await?;
369
370 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
371 serde_json::from_str(&local_var_content).map_err(Error::from)
372 } else {
373 let local_var_entity: Option<GetDeployedContractsError> =
374 serde_json::from_str(&local_var_content).ok();
375 let local_var_error = ResponseContent {
376 status: local_var_status,
377 content: local_var_content,
378 entity: local_var_entity,
379 };
380 Err(Error::ResponseError(local_var_error))
381 }
382 }
383}
384
385#[derive(Debug, Clone, Serialize, Deserialize)]
387#[serde(untagged)]
388pub enum AddContractAbiError {
389 Status409(),
390 DefaultResponse(models::ErrorSchema),
391 UnknownValue(serde_json::Value),
392}
393
394#[derive(Debug, Clone, Serialize, Deserialize)]
396#[serde(untagged)]
397pub enum FetchContractAbiError {
398 Status404(),
399 DefaultResponse(models::ErrorSchema),
400 UnknownValue(serde_json::Value),
401}
402
403#[derive(Debug, Clone, Serialize, Deserialize)]
405#[serde(untagged)]
406pub enum GetDeployedContractByAddressError {
407 DefaultResponse(models::ErrorSchema),
408 UnknownValue(serde_json::Value),
409}
410
411#[derive(Debug, Clone, Serialize, Deserialize)]
413#[serde(untagged)]
414pub enum GetDeployedContractByIdError {
415 DefaultResponse(models::ErrorSchema),
416 UnknownValue(serde_json::Value),
417}
418
419#[derive(Debug, Clone, Serialize, Deserialize)]
421#[serde(untagged)]
422pub enum GetDeployedContractsError {
423 DefaultResponse(models::ErrorSchema),
424 UnknownValue(serde_json::Value),
425}