1use {
10 super::{Error, configuration},
11 crate::{
12 apis::{ContentType, ResponseContent},
13 models,
14 },
15 async_trait::async_trait,
16 reqwest,
17 serde::{Deserialize, Serialize, de::Error as _},
18 std::sync::Arc,
19};
20
21#[async_trait]
22pub trait ContractTemplatesApi: Send + Sync {
23 async fn delete_contract_template_by_id(
29 &self,
30 params: DeleteContractTemplateByIdParams,
31 ) -> Result<(), Error<DeleteContractTemplateByIdError>>;
32
33 async fn deploy_contract(
40 &self,
41 params: DeployContractParams,
42 ) -> Result<models::ContractDeployResponse, Error<DeployContractError>>;
43
44 async fn get_constructor_by_contract_template_id(
49 &self,
50 params: GetConstructorByContractTemplateIdParams,
51 ) -> Result<models::AbiFunction, Error<GetConstructorByContractTemplateIdError>>;
52
53 async fn get_contract_template_by_id(
58 &self,
59 params: GetContractTemplateByIdParams,
60 ) -> Result<models::ContractTemplateDto, Error<GetContractTemplateByIdError>>;
61
62 async fn get_contract_templates(
68 &self,
69 params: GetContractTemplatesParams,
70 ) -> Result<models::TemplatesPaginatedResponse, Error<GetContractTemplatesError>>;
71
72 async fn get_function_abi_by_contract_template_id(
77 &self,
78 params: GetFunctionAbiByContractTemplateIdParams,
79 ) -> Result<models::AbiFunction, Error<GetFunctionAbiByContractTemplateIdError>>;
80
81 async fn upload_contract_template(
87 &self,
88 params: UploadContractTemplateParams,
89 ) -> Result<models::ContractTemplateDto, Error<UploadContractTemplateError>>;
90}
91
92pub struct ContractTemplatesApiClient {
93 configuration: Arc<configuration::Configuration>,
94}
95
96impl ContractTemplatesApiClient {
97 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
98 Self { configuration }
99 }
100}
101
102#[derive(Clone, Debug)]
105#[cfg_attr(feature = "bon", derive(::bon::Builder))]
106pub struct DeleteContractTemplateByIdParams {
107 pub contract_template_id: String,
109}
110
111#[derive(Clone, Debug)]
114#[cfg_attr(feature = "bon", derive(::bon::Builder))]
115pub struct DeployContractParams {
116 pub contract_template_id: String,
118 pub contract_deploy_request: models::ContractDeployRequest,
119 pub idempotency_key: Option<String>,
124}
125
126#[derive(Clone, Debug)]
129#[cfg_attr(feature = "bon", derive(::bon::Builder))]
130pub struct GetConstructorByContractTemplateIdParams {
131 pub contract_template_id: String,
133 pub with_docs: Option<bool>,
135}
136
137#[derive(Clone, Debug)]
140#[cfg_attr(feature = "bon", derive(::bon::Builder))]
141pub struct GetContractTemplateByIdParams {
142 pub contract_template_id: String,
144}
145
146#[derive(Clone, Debug)]
149#[cfg_attr(feature = "bon", derive(::bon::Builder))]
150pub struct GetContractTemplatesParams {
151 pub limit: Option<f64>,
153 pub offset: Option<f64>,
155 pub page_cursor: Option<String>,
157 pub page_size: Option<f64>,
159 pub r#type: Option<String>,
162 pub initialization_phase: Option<String>,
165}
166
167#[derive(Clone, Debug)]
170#[cfg_attr(feature = "bon", derive(::bon::Builder))]
171pub struct GetFunctionAbiByContractTemplateIdParams {
172 pub contract_template_id: String,
174 pub function_signature: String,
176}
177
178#[derive(Clone, Debug)]
181#[cfg_attr(feature = "bon", derive(::bon::Builder))]
182pub struct UploadContractTemplateParams {
183 pub contract_upload_request: models::ContractUploadRequest,
184 pub idempotency_key: Option<String>,
189}
190
191#[async_trait]
192impl ContractTemplatesApi for ContractTemplatesApiClient {
193 async fn delete_contract_template_by_id(
197 &self,
198 params: DeleteContractTemplateByIdParams,
199 ) -> Result<(), Error<DeleteContractTemplateByIdError>> {
200 let DeleteContractTemplateByIdParams {
201 contract_template_id,
202 } = params;
203
204 let local_var_configuration = &self.configuration;
205
206 let local_var_client = &local_var_configuration.client;
207
208 let local_var_uri_str = format!(
209 "{}/tokenization/templates/{contractTemplateId}",
210 local_var_configuration.base_path,
211 contractTemplateId = crate::apis::urlencode(contract_template_id)
212 );
213 let mut local_var_req_builder =
214 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
215
216 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
217 local_var_req_builder = local_var_req_builder
218 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
219 }
220
221 let local_var_req = local_var_req_builder.build()?;
222 let local_var_resp = local_var_client.execute(local_var_req).await?;
223
224 let local_var_status = local_var_resp.status();
225 let local_var_content = local_var_resp.text().await?;
226
227 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
228 Ok(())
229 } else {
230 let local_var_entity: Option<DeleteContractTemplateByIdError> =
231 serde_json::from_str(&local_var_content).ok();
232 let local_var_error = ResponseContent {
233 status: local_var_status,
234 content: local_var_content,
235 entity: local_var_entity,
236 };
237 Err(Error::ResponseError(local_var_error))
238 }
239 }
240
241 async fn deploy_contract(
246 &self,
247 params: DeployContractParams,
248 ) -> Result<models::ContractDeployResponse, Error<DeployContractError>> {
249 let DeployContractParams {
250 contract_template_id,
251 contract_deploy_request,
252 idempotency_key,
253 } = params;
254
255 let local_var_configuration = &self.configuration;
256
257 let local_var_client = &local_var_configuration.client;
258
259 let local_var_uri_str = format!(
260 "{}/tokenization/templates/{contractTemplateId}/deploy",
261 local_var_configuration.base_path,
262 contractTemplateId = crate::apis::urlencode(contract_template_id)
263 );
264 let mut local_var_req_builder =
265 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
266
267 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
268 local_var_req_builder = local_var_req_builder
269 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
270 }
271 if let Some(local_var_param_value) = idempotency_key {
272 local_var_req_builder =
273 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
274 }
275 local_var_req_builder = local_var_req_builder.json(&contract_deploy_request);
276
277 let local_var_req = local_var_req_builder.build()?;
278 let local_var_resp = local_var_client.execute(local_var_req).await?;
279
280 let local_var_status = local_var_resp.status();
281 let local_var_content_type = local_var_resp
282 .headers()
283 .get("content-type")
284 .and_then(|v| v.to_str().ok())
285 .unwrap_or("application/octet-stream");
286 let local_var_content_type = super::ContentType::from(local_var_content_type);
287 let local_var_content = local_var_resp.text().await?;
288
289 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
290 match local_var_content_type {
291 ContentType::Json => {
292 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
293 }
294 ContentType::Text => {
295 return Err(Error::from(serde_json::Error::custom(
296 "Received `text/plain` content type response that cannot be converted to \
297 `models::ContractDeployResponse`",
298 )));
299 }
300 ContentType::Unsupported(local_var_unknown_type) => {
301 return Err(Error::from(serde_json::Error::custom(format!(
302 "Received `{local_var_unknown_type}` content type response that cannot be \
303 converted to `models::ContractDeployResponse`"
304 ))));
305 }
306 }
307 } else {
308 let local_var_entity: Option<DeployContractError> =
309 serde_json::from_str(&local_var_content).ok();
310 let local_var_error = ResponseContent {
311 status: local_var_status,
312 content: local_var_content,
313 entity: local_var_entity,
314 };
315 Err(Error::ResponseError(local_var_error))
316 }
317 }
318
319 async fn get_constructor_by_contract_template_id(
322 &self,
323 params: GetConstructorByContractTemplateIdParams,
324 ) -> Result<models::AbiFunction, Error<GetConstructorByContractTemplateIdError>> {
325 let GetConstructorByContractTemplateIdParams {
326 contract_template_id,
327 with_docs,
328 } = params;
329
330 let local_var_configuration = &self.configuration;
331
332 let local_var_client = &local_var_configuration.client;
333
334 let local_var_uri_str = format!(
335 "{}/tokenization/templates/{contractTemplateId}/constructor",
336 local_var_configuration.base_path,
337 contractTemplateId = crate::apis::urlencode(contract_template_id)
338 );
339 let mut local_var_req_builder =
340 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
341
342 if let Some(ref param_value) = with_docs {
343 local_var_req_builder =
344 local_var_req_builder.query(&[("withDocs", ¶m_value.to_string())]);
345 }
346 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
347 local_var_req_builder = local_var_req_builder
348 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
349 }
350
351 let local_var_req = local_var_req_builder.build()?;
352 let local_var_resp = local_var_client.execute(local_var_req).await?;
353
354 let local_var_status = local_var_resp.status();
355 let local_var_content_type = local_var_resp
356 .headers()
357 .get("content-type")
358 .and_then(|v| v.to_str().ok())
359 .unwrap_or("application/octet-stream");
360 let local_var_content_type = super::ContentType::from(local_var_content_type);
361 let local_var_content = local_var_resp.text().await?;
362
363 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
364 match local_var_content_type {
365 ContentType::Json => {
366 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
367 }
368 ContentType::Text => {
369 return Err(Error::from(serde_json::Error::custom(
370 "Received `text/plain` content type response that cannot be converted to \
371 `models::AbiFunction`",
372 )));
373 }
374 ContentType::Unsupported(local_var_unknown_type) => {
375 return Err(Error::from(serde_json::Error::custom(format!(
376 "Received `{local_var_unknown_type}` content type response that cannot be \
377 converted to `models::AbiFunction`"
378 ))));
379 }
380 }
381 } else {
382 let local_var_entity: Option<GetConstructorByContractTemplateIdError> =
383 serde_json::from_str(&local_var_content).ok();
384 let local_var_error = ResponseContent {
385 status: local_var_status,
386 content: local_var_content,
387 entity: local_var_entity,
388 };
389 Err(Error::ResponseError(local_var_error))
390 }
391 }
392
393 async fn get_contract_template_by_id(
396 &self,
397 params: GetContractTemplateByIdParams,
398 ) -> Result<models::ContractTemplateDto, Error<GetContractTemplateByIdError>> {
399 let GetContractTemplateByIdParams {
400 contract_template_id,
401 } = params;
402
403 let local_var_configuration = &self.configuration;
404
405 let local_var_client = &local_var_configuration.client;
406
407 let local_var_uri_str = format!(
408 "{}/tokenization/templates/{contractTemplateId}",
409 local_var_configuration.base_path,
410 contractTemplateId = crate::apis::urlencode(contract_template_id)
411 );
412 let mut local_var_req_builder =
413 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
414
415 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
416 local_var_req_builder = local_var_req_builder
417 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
418 }
419
420 let local_var_req = local_var_req_builder.build()?;
421 let local_var_resp = local_var_client.execute(local_var_req).await?;
422
423 let local_var_status = local_var_resp.status();
424 let local_var_content_type = local_var_resp
425 .headers()
426 .get("content-type")
427 .and_then(|v| v.to_str().ok())
428 .unwrap_or("application/octet-stream");
429 let local_var_content_type = super::ContentType::from(local_var_content_type);
430 let local_var_content = local_var_resp.text().await?;
431
432 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
433 match local_var_content_type {
434 ContentType::Json => {
435 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
436 }
437 ContentType::Text => {
438 return Err(Error::from(serde_json::Error::custom(
439 "Received `text/plain` content type response that cannot be converted to \
440 `models::ContractTemplateDto`",
441 )));
442 }
443 ContentType::Unsupported(local_var_unknown_type) => {
444 return Err(Error::from(serde_json::Error::custom(format!(
445 "Received `{local_var_unknown_type}` content type response that cannot be \
446 converted to `models::ContractTemplateDto`"
447 ))));
448 }
449 }
450 } else {
451 let local_var_entity: Option<GetContractTemplateByIdError> =
452 serde_json::from_str(&local_var_content).ok();
453 let local_var_error = ResponseContent {
454 status: local_var_status,
455 content: local_var_content,
456 entity: local_var_entity,
457 };
458 Err(Error::ResponseError(local_var_error))
459 }
460 }
461
462 async fn get_contract_templates(
466 &self,
467 params: GetContractTemplatesParams,
468 ) -> Result<models::TemplatesPaginatedResponse, Error<GetContractTemplatesError>> {
469 let GetContractTemplatesParams {
470 limit,
471 offset,
472 page_cursor,
473 page_size,
474 r#type,
475 initialization_phase,
476 } = params;
477
478 let local_var_configuration = &self.configuration;
479
480 let local_var_client = &local_var_configuration.client;
481
482 let local_var_uri_str = format!(
483 "{}/tokenization/templates",
484 local_var_configuration.base_path
485 );
486 let mut local_var_req_builder =
487 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
488
489 if let Some(ref param_value) = limit {
490 local_var_req_builder =
491 local_var_req_builder.query(&[("limit", ¶m_value.to_string())]);
492 }
493 if let Some(ref param_value) = offset {
494 local_var_req_builder =
495 local_var_req_builder.query(&[("offset", ¶m_value.to_string())]);
496 }
497 if let Some(ref param_value) = page_cursor {
498 local_var_req_builder =
499 local_var_req_builder.query(&[("pageCursor", ¶m_value.to_string())]);
500 }
501 if let Some(ref param_value) = page_size {
502 local_var_req_builder =
503 local_var_req_builder.query(&[("pageSize", ¶m_value.to_string())]);
504 }
505 if let Some(ref param_value) = r#type {
506 local_var_req_builder =
507 local_var_req_builder.query(&[("type", ¶m_value.to_string())]);
508 }
509 if let Some(ref param_value) = initialization_phase {
510 local_var_req_builder =
511 local_var_req_builder.query(&[("initializationPhase", ¶m_value.to_string())]);
512 }
513 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
514 local_var_req_builder = local_var_req_builder
515 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
516 }
517
518 let local_var_req = local_var_req_builder.build()?;
519 let local_var_resp = local_var_client.execute(local_var_req).await?;
520
521 let local_var_status = local_var_resp.status();
522 let local_var_content_type = local_var_resp
523 .headers()
524 .get("content-type")
525 .and_then(|v| v.to_str().ok())
526 .unwrap_or("application/octet-stream");
527 let local_var_content_type = super::ContentType::from(local_var_content_type);
528 let local_var_content = local_var_resp.text().await?;
529
530 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
531 match local_var_content_type {
532 ContentType::Json => {
533 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
534 }
535 ContentType::Text => {
536 return Err(Error::from(serde_json::Error::custom(
537 "Received `text/plain` content type response that cannot be converted to \
538 `models::TemplatesPaginatedResponse`",
539 )));
540 }
541 ContentType::Unsupported(local_var_unknown_type) => {
542 return Err(Error::from(serde_json::Error::custom(format!(
543 "Received `{local_var_unknown_type}` content type response that cannot be \
544 converted to `models::TemplatesPaginatedResponse`"
545 ))));
546 }
547 }
548 } else {
549 let local_var_entity: Option<GetContractTemplatesError> =
550 serde_json::from_str(&local_var_content).ok();
551 let local_var_error = ResponseContent {
552 status: local_var_status,
553 content: local_var_content,
554 entity: local_var_entity,
555 };
556 Err(Error::ResponseError(local_var_error))
557 }
558 }
559
560 async fn get_function_abi_by_contract_template_id(
563 &self,
564 params: GetFunctionAbiByContractTemplateIdParams,
565 ) -> Result<models::AbiFunction, Error<GetFunctionAbiByContractTemplateIdError>> {
566 let GetFunctionAbiByContractTemplateIdParams {
567 contract_template_id,
568 function_signature,
569 } = params;
570
571 let local_var_configuration = &self.configuration;
572
573 let local_var_client = &local_var_configuration.client;
574
575 let local_var_uri_str = format!(
576 "{}/tokenization/templates/{contractTemplateId}/function",
577 local_var_configuration.base_path,
578 contractTemplateId = crate::apis::urlencode(contract_template_id)
579 );
580 let mut local_var_req_builder =
581 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
582
583 local_var_req_builder =
584 local_var_req_builder.query(&[("functionSignature", &function_signature.to_string())]);
585 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
586 local_var_req_builder = local_var_req_builder
587 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
588 }
589
590 let local_var_req = local_var_req_builder.build()?;
591 let local_var_resp = local_var_client.execute(local_var_req).await?;
592
593 let local_var_status = local_var_resp.status();
594 let local_var_content_type = local_var_resp
595 .headers()
596 .get("content-type")
597 .and_then(|v| v.to_str().ok())
598 .unwrap_or("application/octet-stream");
599 let local_var_content_type = super::ContentType::from(local_var_content_type);
600 let local_var_content = local_var_resp.text().await?;
601
602 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
603 match local_var_content_type {
604 ContentType::Json => {
605 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
606 }
607 ContentType::Text => {
608 return Err(Error::from(serde_json::Error::custom(
609 "Received `text/plain` content type response that cannot be converted to \
610 `models::AbiFunction`",
611 )));
612 }
613 ContentType::Unsupported(local_var_unknown_type) => {
614 return Err(Error::from(serde_json::Error::custom(format!(
615 "Received `{local_var_unknown_type}` content type response that cannot be \
616 converted to `models::AbiFunction`"
617 ))));
618 }
619 }
620 } else {
621 let local_var_entity: Option<GetFunctionAbiByContractTemplateIdError> =
622 serde_json::from_str(&local_var_content).ok();
623 let local_var_error = ResponseContent {
624 status: local_var_status,
625 content: local_var_content,
626 entity: local_var_entity,
627 };
628 Err(Error::ResponseError(local_var_error))
629 }
630 }
631
632 async fn upload_contract_template(
636 &self,
637 params: UploadContractTemplateParams,
638 ) -> Result<models::ContractTemplateDto, Error<UploadContractTemplateError>> {
639 let UploadContractTemplateParams {
640 contract_upload_request,
641 idempotency_key,
642 } = params;
643
644 let local_var_configuration = &self.configuration;
645
646 let local_var_client = &local_var_configuration.client;
647
648 let local_var_uri_str = format!(
649 "{}/tokenization/templates",
650 local_var_configuration.base_path
651 );
652 let mut local_var_req_builder =
653 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
654
655 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
656 local_var_req_builder = local_var_req_builder
657 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
658 }
659 if let Some(local_var_param_value) = idempotency_key {
660 local_var_req_builder =
661 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
662 }
663 local_var_req_builder = local_var_req_builder.json(&contract_upload_request);
664
665 let local_var_req = local_var_req_builder.build()?;
666 let local_var_resp = local_var_client.execute(local_var_req).await?;
667
668 let local_var_status = local_var_resp.status();
669 let local_var_content_type = local_var_resp
670 .headers()
671 .get("content-type")
672 .and_then(|v| v.to_str().ok())
673 .unwrap_or("application/octet-stream");
674 let local_var_content_type = super::ContentType::from(local_var_content_type);
675 let local_var_content = local_var_resp.text().await?;
676
677 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
678 match local_var_content_type {
679 ContentType::Json => {
680 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
681 }
682 ContentType::Text => {
683 return Err(Error::from(serde_json::Error::custom(
684 "Received `text/plain` content type response that cannot be converted to \
685 `models::ContractTemplateDto`",
686 )));
687 }
688 ContentType::Unsupported(local_var_unknown_type) => {
689 return Err(Error::from(serde_json::Error::custom(format!(
690 "Received `{local_var_unknown_type}` content type response that cannot be \
691 converted to `models::ContractTemplateDto`"
692 ))));
693 }
694 }
695 } else {
696 let local_var_entity: Option<UploadContractTemplateError> =
697 serde_json::from_str(&local_var_content).ok();
698 let local_var_error = ResponseContent {
699 status: local_var_status,
700 content: local_var_content,
701 entity: local_var_entity,
702 };
703 Err(Error::ResponseError(local_var_error))
704 }
705 }
706}
707
708#[derive(Debug, Clone, Serialize, Deserialize)]
711#[serde(untagged)]
712pub enum DeleteContractTemplateByIdError {
713 Status404(models::HttpContractDoesNotExistError),
714 DefaultResponse(models::ErrorSchema),
715 UnknownValue(serde_json::Value),
716}
717
718#[derive(Debug, Clone, Serialize, Deserialize)]
720#[serde(untagged)]
721pub enum DeployContractError {
722 Status404(models::HttpContractDoesNotExistError),
723 DefaultResponse(models::ErrorSchema),
724 UnknownValue(serde_json::Value),
725}
726
727#[derive(Debug, Clone, Serialize, Deserialize)]
730#[serde(untagged)]
731pub enum GetConstructorByContractTemplateIdError {
732 Status404(models::HttpContractDoesNotExistError),
733 DefaultResponse(models::ErrorSchema),
734 UnknownValue(serde_json::Value),
735}
736
737#[derive(Debug, Clone, Serialize, Deserialize)]
740#[serde(untagged)]
741pub enum GetContractTemplateByIdError {
742 Status404(models::HttpContractDoesNotExistError),
743 DefaultResponse(models::ErrorSchema),
744 UnknownValue(serde_json::Value),
745}
746
747#[derive(Debug, Clone, Serialize, Deserialize)]
750#[serde(untagged)]
751pub enum GetContractTemplatesError {
752 DefaultResponse(models::ErrorSchema),
753 UnknownValue(serde_json::Value),
754}
755
756#[derive(Debug, Clone, Serialize, Deserialize)]
759#[serde(untagged)]
760pub enum GetFunctionAbiByContractTemplateIdError {
761 Status404(models::HttpContractDoesNotExistError),
762 DefaultResponse(models::ErrorSchema),
763 UnknownValue(serde_json::Value),
764}
765
766#[derive(Debug, Clone, Serialize, Deserialize)]
769#[serde(untagged)]
770pub enum UploadContractTemplateError {
771 DefaultResponse(models::ErrorSchema),
772 UnknownValue(serde_json::Value),
773}