fireblocks_sdk/apis/
contract_templates_api.rs

1// Fireblocks API
2//
3// Fireblocks provides a suite of applications to manage digital asset operations and a complete development platform to build your business on the blockchain.  - Visit our website for more information: [Fireblocks Website](https://fireblocks.com) - Visit our developer docs: [Fireblocks DevPortal](https://developers.fireblocks.com)
4//
5// The version of the OpenAPI document: 1.8.0
6// Contact: developers@fireblocks.com
7// Generated by: https://openapi-generator.tech
8
9use {
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    /// DELETE /tokenization/templates/{contractTemplateId}
24    ///
25    /// Delete a contract by id. allowed only for private contract templates.
26    /// Notice: it is irreversible! </br>Endpoint Permission: Owner, Admin,
27    /// Non-Signing Admin, Signer, and Editor
28    async fn delete_contract_template_by_id(
29        &self,
30        params: DeleteContractTemplateByIdParams,
31    ) -> Result<(), Error<DeleteContractTemplateByIdError>>;
32
33    /// POST /tokenization/templates/{contractTemplateId}/deploy
34    ///
35    /// Deploy a new contract by contract template id. If you wish to deploy a
36    /// token (ERC20, ERC721 etc), and create asset please use `POST
37    /// /tokenization`. </br>Endpoint Permission: Owner, Admin, Non-Signing
38    /// Admin, Signer, Approver, and Editor, Viewer.
39    async fn deploy_contract(
40        &self,
41        params: DeployContractParams,
42    ) -> Result<models::ContractDeployResponse, Error<DeployContractError>>;
43
44    /// GET /tokenization/templates/{contractTemplateId}/constructor
45    ///
46    /// Return contract template's constructor ABI. </br>Endpoint Permission:
47    /// Admin, Non-Signing Admin, Signer, Approver, Editor, Viewer.
48    async fn get_constructor_by_contract_template_id(
49        &self,
50        params: GetConstructorByContractTemplateIdParams,
51    ) -> Result<models::AbiFunction, Error<GetConstructorByContractTemplateIdError>>;
52
53    /// GET /tokenization/templates/{contractTemplateId}
54    ///
55    /// Return detailed information about the contract template. </br>Endpoint
56    /// Permission: Admin, Non-Signing Admin, Signer, Approver, Editor, Viewer.
57    async fn get_contract_template_by_id(
58        &self,
59        params: GetContractTemplateByIdParams,
60    ) -> Result<models::ContractTemplateDto, Error<GetContractTemplateByIdError>>;
61
62    /// GET /tokenization/templates
63    ///
64    /// Return minimal representation of all the contract templates available
65    /// for the workspace. </br>Endpoint Permission: Admin, Non-Signing Admin,
66    /// Signer, Approver, Editor, Viewer.
67    async fn get_contract_templates(
68        &self,
69        params: GetContractTemplatesParams,
70    ) -> Result<models::TemplatesPaginatedResponse, Error<GetContractTemplatesError>>;
71
72    /// GET /tokenization/templates/{contractTemplateId}/function
73    ///
74    /// Return contract template`s function ABI by signature. </br>Endpoint
75    /// Permission: Admin, Non-Signing Admin, Signer, Approver, Editor, Viewer.
76    async fn get_function_abi_by_contract_template_id(
77        &self,
78        params: GetFunctionAbiByContractTemplateIdParams,
79    ) -> Result<models::AbiFunction, Error<GetFunctionAbiByContractTemplateIdError>>;
80
81    /// POST /tokenization/templates
82    ///
83    /// Upload a new contract template. This contract template will be available
84    /// for the workspace. </br>Endpoint Permission: Owner, Admin, Non-Signing
85    /// Admin, Signer, and Editor
86    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/// struct for passing parameters to the method
103/// [`delete_contract_template_by_id`]
104#[derive(Clone, Debug)]
105#[cfg_attr(feature = "bon", derive(::bon::Builder))]
106pub struct DeleteContractTemplateByIdParams {
107    /// The Contract Template identifier
108    pub contract_template_id: String,
109}
110
111/// struct for passing parameters to the method [`deploy_contract`]
112#[derive(Clone, Debug)]
113#[cfg_attr(feature = "bon", derive(::bon::Builder))]
114pub struct DeployContractParams {
115    /// The Contract Template identifier
116    pub contract_template_id: String,
117    pub contract_deploy_request: models::ContractDeployRequest,
118    /// A unique identifier for the request. If the request is sent multiple
119    /// times with the same idempotency key, the server will return the same
120    /// response as the first request. The idempotency key is valid for 24
121    /// hours.
122    pub idempotency_key: Option<String>,
123}
124
125/// struct for passing parameters to the method
126/// [`get_constructor_by_contract_template_id`]
127#[derive(Clone, Debug)]
128#[cfg_attr(feature = "bon", derive(::bon::Builder))]
129pub struct GetConstructorByContractTemplateIdParams {
130    /// The Contract Template identifier
131    pub contract_template_id: String,
132    /// true if you want to get the abi with its docs
133    pub with_docs: Option<bool>,
134}
135
136/// struct for passing parameters to the method [`get_contract_template_by_id`]
137#[derive(Clone, Debug)]
138#[cfg_attr(feature = "bon", derive(::bon::Builder))]
139pub struct GetContractTemplateByIdParams {
140    /// The Contract Template identifier
141    pub contract_template_id: String,
142}
143
144/// struct for passing parameters to the method [`get_contract_templates`]
145#[derive(Clone, Debug)]
146#[cfg_attr(feature = "bon", derive(::bon::Builder))]
147pub struct GetContractTemplatesParams {
148    /// Items per page (max 100)
149    pub limit: Option<f64>,
150    /// Paging offset
151    pub offset: Option<f64>,
152    /// Page cursor to get the next page
153    pub page_cursor: Option<String>,
154    /// Number of items per page, requesting more then max will return max items
155    pub page_size: Option<f64>,
156    /// The type of the contract templates you wish to retrieve. Can accept one
157    /// type, more or none
158    pub r#type: Option<String>,
159    /// For standalone contracts use ON_DEPLOYMENT and for contracts that are
160    /// behind proxies use POST_DEPLOYMENT
161    pub initialization_phase: Option<String>,
162}
163
164/// struct for passing parameters to the method
165/// [`get_function_abi_by_contract_template_id`]
166#[derive(Clone, Debug)]
167#[cfg_attr(feature = "bon", derive(::bon::Builder))]
168pub struct GetFunctionAbiByContractTemplateIdParams {
169    /// The Contract Template identifier
170    pub contract_template_id: String,
171    /// The contract's function signature
172    pub function_signature: String,
173}
174
175/// struct for passing parameters to the method [`upload_contract_template`]
176#[derive(Clone, Debug)]
177#[cfg_attr(feature = "bon", derive(::bon::Builder))]
178pub struct UploadContractTemplateParams {
179    pub contract_upload_request: models::ContractUploadRequest,
180    /// A unique identifier for the request. If the request is sent multiple
181    /// times with the same idempotency key, the server will return the same
182    /// response as the first request. The idempotency key is valid for 24
183    /// hours.
184    pub idempotency_key: Option<String>,
185}
186
187#[async_trait]
188impl ContractTemplatesApi for ContractTemplatesApiClient {
189    /// Delete a contract by id. allowed only for private contract templates.
190    /// Notice: it is irreversible! </br>Endpoint Permission: Owner, Admin,
191    /// Non-Signing Admin, Signer, and Editor
192    async fn delete_contract_template_by_id(
193        &self,
194        params: DeleteContractTemplateByIdParams,
195    ) -> Result<(), Error<DeleteContractTemplateByIdError>> {
196        let DeleteContractTemplateByIdParams {
197            contract_template_id,
198        } = params;
199
200        let local_var_configuration = &self.configuration;
201
202        let local_var_client = &local_var_configuration.client;
203
204        let local_var_uri_str = format!(
205            "{}/tokenization/templates/{contractTemplateId}",
206            local_var_configuration.base_path,
207            contractTemplateId = crate::apis::urlencode(contract_template_id)
208        );
209        let mut local_var_req_builder =
210            local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
211
212        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
213            local_var_req_builder = local_var_req_builder
214                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
215        }
216
217        let local_var_req = local_var_req_builder.build()?;
218        let local_var_resp = local_var_client.execute(local_var_req).await?;
219
220        let local_var_status = local_var_resp.status();
221        let local_var_content = local_var_resp.text().await?;
222
223        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
224            Ok(())
225        } else {
226            let local_var_entity: Option<DeleteContractTemplateByIdError> =
227                serde_json::from_str(&local_var_content).ok();
228            let local_var_error = ResponseContent {
229                status: local_var_status,
230                content: local_var_content,
231                entity: local_var_entity,
232            };
233            Err(Error::ResponseError(local_var_error))
234        }
235    }
236
237    /// Deploy a new contract by contract template id. If you wish to deploy a
238    /// token (ERC20, ERC721 etc), and create asset please use `POST
239    /// /tokenization`. </br>Endpoint Permission: Owner, Admin, Non-Signing
240    /// Admin, Signer, Approver, and Editor, Viewer.
241    async fn deploy_contract(
242        &self,
243        params: DeployContractParams,
244    ) -> Result<models::ContractDeployResponse, Error<DeployContractError>> {
245        let DeployContractParams {
246            contract_template_id,
247            contract_deploy_request,
248            idempotency_key,
249        } = params;
250
251        let local_var_configuration = &self.configuration;
252
253        let local_var_client = &local_var_configuration.client;
254
255        let local_var_uri_str = format!(
256            "{}/tokenization/templates/{contractTemplateId}/deploy",
257            local_var_configuration.base_path,
258            contractTemplateId = crate::apis::urlencode(contract_template_id)
259        );
260        let mut local_var_req_builder =
261            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
262
263        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
264            local_var_req_builder = local_var_req_builder
265                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
266        }
267        if let Some(local_var_param_value) = idempotency_key {
268            local_var_req_builder =
269                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
270        }
271        local_var_req_builder = local_var_req_builder.json(&contract_deploy_request);
272
273        let local_var_req = local_var_req_builder.build()?;
274        let local_var_resp = local_var_client.execute(local_var_req).await?;
275
276        let local_var_status = local_var_resp.status();
277        let local_var_content_type = local_var_resp
278            .headers()
279            .get("content-type")
280            .and_then(|v| v.to_str().ok())
281            .unwrap_or("application/octet-stream");
282        let local_var_content_type = super::ContentType::from(local_var_content_type);
283        let local_var_content = local_var_resp.text().await?;
284
285        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
286            match local_var_content_type {
287                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
288                ContentType::Text => {
289                    return Err(Error::from(serde_json::Error::custom(
290                        "Received `text/plain` content type response that cannot be converted to \
291                         `models::ContractDeployResponse`",
292                    )));
293                }
294                ContentType::Unsupported(local_var_unknown_type) => {
295                    return Err(Error::from(serde_json::Error::custom(format!(
296                        "Received `{local_var_unknown_type}` content type response that cannot be \
297                         converted to `models::ContractDeployResponse`"
298                    ))));
299                }
300            }
301        } else {
302            let local_var_entity: Option<DeployContractError> =
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    /// Return contract template's constructor ABI. </br>Endpoint Permission:
314    /// Admin, Non-Signing Admin, Signer, Approver, Editor, Viewer.
315    async fn get_constructor_by_contract_template_id(
316        &self,
317        params: GetConstructorByContractTemplateIdParams,
318    ) -> Result<models::AbiFunction, Error<GetConstructorByContractTemplateIdError>> {
319        let GetConstructorByContractTemplateIdParams {
320            contract_template_id,
321            with_docs,
322        } = params;
323
324        let local_var_configuration = &self.configuration;
325
326        let local_var_client = &local_var_configuration.client;
327
328        let local_var_uri_str = format!(
329            "{}/tokenization/templates/{contractTemplateId}/constructor",
330            local_var_configuration.base_path,
331            contractTemplateId = crate::apis::urlencode(contract_template_id)
332        );
333        let mut local_var_req_builder =
334            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
335
336        if let Some(ref local_var_str) = with_docs {
337            local_var_req_builder =
338                local_var_req_builder.query(&[("withDocs", &local_var_str.to_string())]);
339        }
340        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
341            local_var_req_builder = local_var_req_builder
342                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
343        }
344
345        let local_var_req = local_var_req_builder.build()?;
346        let local_var_resp = local_var_client.execute(local_var_req).await?;
347
348        let local_var_status = local_var_resp.status();
349        let local_var_content_type = local_var_resp
350            .headers()
351            .get("content-type")
352            .and_then(|v| v.to_str().ok())
353            .unwrap_or("application/octet-stream");
354        let local_var_content_type = super::ContentType::from(local_var_content_type);
355        let local_var_content = local_var_resp.text().await?;
356
357        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
358            match local_var_content_type {
359                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
360                ContentType::Text => {
361                    return Err(Error::from(serde_json::Error::custom(
362                        "Received `text/plain` content type response that cannot be converted to \
363                         `models::AbiFunction`",
364                    )));
365                }
366                ContentType::Unsupported(local_var_unknown_type) => {
367                    return Err(Error::from(serde_json::Error::custom(format!(
368                        "Received `{local_var_unknown_type}` content type response that cannot be \
369                         converted to `models::AbiFunction`"
370                    ))));
371                }
372            }
373        } else {
374            let local_var_entity: Option<GetConstructorByContractTemplateIdError> =
375                serde_json::from_str(&local_var_content).ok();
376            let local_var_error = ResponseContent {
377                status: local_var_status,
378                content: local_var_content,
379                entity: local_var_entity,
380            };
381            Err(Error::ResponseError(local_var_error))
382        }
383    }
384
385    /// Return detailed information about the contract template. </br>Endpoint
386    /// Permission: Admin, Non-Signing Admin, Signer, Approver, Editor, Viewer.
387    async fn get_contract_template_by_id(
388        &self,
389        params: GetContractTemplateByIdParams,
390    ) -> Result<models::ContractTemplateDto, Error<GetContractTemplateByIdError>> {
391        let GetContractTemplateByIdParams {
392            contract_template_id,
393        } = params;
394
395        let local_var_configuration = &self.configuration;
396
397        let local_var_client = &local_var_configuration.client;
398
399        let local_var_uri_str = format!(
400            "{}/tokenization/templates/{contractTemplateId}",
401            local_var_configuration.base_path,
402            contractTemplateId = crate::apis::urlencode(contract_template_id)
403        );
404        let mut local_var_req_builder =
405            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
406
407        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
408            local_var_req_builder = local_var_req_builder
409                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
410        }
411
412        let local_var_req = local_var_req_builder.build()?;
413        let local_var_resp = local_var_client.execute(local_var_req).await?;
414
415        let local_var_status = local_var_resp.status();
416        let local_var_content_type = local_var_resp
417            .headers()
418            .get("content-type")
419            .and_then(|v| v.to_str().ok())
420            .unwrap_or("application/octet-stream");
421        let local_var_content_type = super::ContentType::from(local_var_content_type);
422        let local_var_content = local_var_resp.text().await?;
423
424        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
425            match local_var_content_type {
426                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
427                ContentType::Text => {
428                    return Err(Error::from(serde_json::Error::custom(
429                        "Received `text/plain` content type response that cannot be converted to \
430                         `models::ContractTemplateDto`",
431                    )));
432                }
433                ContentType::Unsupported(local_var_unknown_type) => {
434                    return Err(Error::from(serde_json::Error::custom(format!(
435                        "Received `{local_var_unknown_type}` content type response that cannot be \
436                         converted to `models::ContractTemplateDto`"
437                    ))));
438                }
439            }
440        } else {
441            let local_var_entity: Option<GetContractTemplateByIdError> =
442                serde_json::from_str(&local_var_content).ok();
443            let local_var_error = ResponseContent {
444                status: local_var_status,
445                content: local_var_content,
446                entity: local_var_entity,
447            };
448            Err(Error::ResponseError(local_var_error))
449        }
450    }
451
452    /// Return minimal representation of all the contract templates available
453    /// for the workspace. </br>Endpoint Permission: Admin, Non-Signing Admin,
454    /// Signer, Approver, Editor, Viewer.
455    async fn get_contract_templates(
456        &self,
457        params: GetContractTemplatesParams,
458    ) -> Result<models::TemplatesPaginatedResponse, Error<GetContractTemplatesError>> {
459        let GetContractTemplatesParams {
460            limit,
461            offset,
462            page_cursor,
463            page_size,
464            r#type,
465            initialization_phase,
466        } = params;
467
468        let local_var_configuration = &self.configuration;
469
470        let local_var_client = &local_var_configuration.client;
471
472        let local_var_uri_str = format!(
473            "{}/tokenization/templates",
474            local_var_configuration.base_path
475        );
476        let mut local_var_req_builder =
477            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
478
479        if let Some(ref local_var_str) = limit {
480            local_var_req_builder =
481                local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
482        }
483        if let Some(ref local_var_str) = offset {
484            local_var_req_builder =
485                local_var_req_builder.query(&[("offset", &local_var_str.to_string())]);
486        }
487        if let Some(ref local_var_str) = page_cursor {
488            local_var_req_builder =
489                local_var_req_builder.query(&[("pageCursor", &local_var_str.to_string())]);
490        }
491        if let Some(ref local_var_str) = page_size {
492            local_var_req_builder =
493                local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
494        }
495        if let Some(ref local_var_str) = r#type {
496            local_var_req_builder =
497                local_var_req_builder.query(&[("type", &local_var_str.to_string())]);
498        }
499        if let Some(ref local_var_str) = initialization_phase {
500            local_var_req_builder =
501                local_var_req_builder.query(&[("initializationPhase", &local_var_str.to_string())]);
502        }
503        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
504            local_var_req_builder = local_var_req_builder
505                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
506        }
507
508        let local_var_req = local_var_req_builder.build()?;
509        let local_var_resp = local_var_client.execute(local_var_req).await?;
510
511        let local_var_status = local_var_resp.status();
512        let local_var_content_type = local_var_resp
513            .headers()
514            .get("content-type")
515            .and_then(|v| v.to_str().ok())
516            .unwrap_or("application/octet-stream");
517        let local_var_content_type = super::ContentType::from(local_var_content_type);
518        let local_var_content = local_var_resp.text().await?;
519
520        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
521            match local_var_content_type {
522                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
523                ContentType::Text => {
524                    return Err(Error::from(serde_json::Error::custom(
525                        "Received `text/plain` content type response that cannot be converted to \
526                         `models::TemplatesPaginatedResponse`",
527                    )));
528                }
529                ContentType::Unsupported(local_var_unknown_type) => {
530                    return Err(Error::from(serde_json::Error::custom(format!(
531                        "Received `{local_var_unknown_type}` content type response that cannot be \
532                         converted to `models::TemplatesPaginatedResponse`"
533                    ))));
534                }
535            }
536        } else {
537            let local_var_entity: Option<GetContractTemplatesError> =
538                serde_json::from_str(&local_var_content).ok();
539            let local_var_error = ResponseContent {
540                status: local_var_status,
541                content: local_var_content,
542                entity: local_var_entity,
543            };
544            Err(Error::ResponseError(local_var_error))
545        }
546    }
547
548    /// Return contract template`s function ABI by signature. </br>Endpoint
549    /// Permission: Admin, Non-Signing Admin, Signer, Approver, Editor, Viewer.
550    async fn get_function_abi_by_contract_template_id(
551        &self,
552        params: GetFunctionAbiByContractTemplateIdParams,
553    ) -> Result<models::AbiFunction, Error<GetFunctionAbiByContractTemplateIdError>> {
554        let GetFunctionAbiByContractTemplateIdParams {
555            contract_template_id,
556            function_signature,
557        } = params;
558
559        let local_var_configuration = &self.configuration;
560
561        let local_var_client = &local_var_configuration.client;
562
563        let local_var_uri_str = format!(
564            "{}/tokenization/templates/{contractTemplateId}/function",
565            local_var_configuration.base_path,
566            contractTemplateId = crate::apis::urlencode(contract_template_id)
567        );
568        let mut local_var_req_builder =
569            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
570
571        local_var_req_builder =
572            local_var_req_builder.query(&[("functionSignature", &function_signature.to_string())]);
573        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
574            local_var_req_builder = local_var_req_builder
575                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
576        }
577
578        let local_var_req = local_var_req_builder.build()?;
579        let local_var_resp = local_var_client.execute(local_var_req).await?;
580
581        let local_var_status = local_var_resp.status();
582        let local_var_content_type = local_var_resp
583            .headers()
584            .get("content-type")
585            .and_then(|v| v.to_str().ok())
586            .unwrap_or("application/octet-stream");
587        let local_var_content_type = super::ContentType::from(local_var_content_type);
588        let local_var_content = local_var_resp.text().await?;
589
590        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
591            match local_var_content_type {
592                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
593                ContentType::Text => {
594                    return Err(Error::from(serde_json::Error::custom(
595                        "Received `text/plain` content type response that cannot be converted to \
596                         `models::AbiFunction`",
597                    )));
598                }
599                ContentType::Unsupported(local_var_unknown_type) => {
600                    return Err(Error::from(serde_json::Error::custom(format!(
601                        "Received `{local_var_unknown_type}` content type response that cannot be \
602                         converted to `models::AbiFunction`"
603                    ))));
604                }
605            }
606        } else {
607            let local_var_entity: Option<GetFunctionAbiByContractTemplateIdError> =
608                serde_json::from_str(&local_var_content).ok();
609            let local_var_error = ResponseContent {
610                status: local_var_status,
611                content: local_var_content,
612                entity: local_var_entity,
613            };
614            Err(Error::ResponseError(local_var_error))
615        }
616    }
617
618    /// Upload a new contract template. This contract template will be available
619    /// for the workspace. </br>Endpoint Permission: Owner, Admin, Non-Signing
620    /// Admin, Signer, and Editor
621    async fn upload_contract_template(
622        &self,
623        params: UploadContractTemplateParams,
624    ) -> Result<models::ContractTemplateDto, Error<UploadContractTemplateError>> {
625        let UploadContractTemplateParams {
626            contract_upload_request,
627            idempotency_key,
628        } = params;
629
630        let local_var_configuration = &self.configuration;
631
632        let local_var_client = &local_var_configuration.client;
633
634        let local_var_uri_str = format!(
635            "{}/tokenization/templates",
636            local_var_configuration.base_path
637        );
638        let mut local_var_req_builder =
639            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
640
641        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
642            local_var_req_builder = local_var_req_builder
643                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
644        }
645        if let Some(local_var_param_value) = idempotency_key {
646            local_var_req_builder =
647                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
648        }
649        local_var_req_builder = local_var_req_builder.json(&contract_upload_request);
650
651        let local_var_req = local_var_req_builder.build()?;
652        let local_var_resp = local_var_client.execute(local_var_req).await?;
653
654        let local_var_status = local_var_resp.status();
655        let local_var_content_type = local_var_resp
656            .headers()
657            .get("content-type")
658            .and_then(|v| v.to_str().ok())
659            .unwrap_or("application/octet-stream");
660        let local_var_content_type = super::ContentType::from(local_var_content_type);
661        let local_var_content = local_var_resp.text().await?;
662
663        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
664            match local_var_content_type {
665                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
666                ContentType::Text => {
667                    return Err(Error::from(serde_json::Error::custom(
668                        "Received `text/plain` content type response that cannot be converted to \
669                         `models::ContractTemplateDto`",
670                    )));
671                }
672                ContentType::Unsupported(local_var_unknown_type) => {
673                    return Err(Error::from(serde_json::Error::custom(format!(
674                        "Received `{local_var_unknown_type}` content type response that cannot be \
675                         converted to `models::ContractTemplateDto`"
676                    ))));
677                }
678            }
679        } else {
680            let local_var_entity: Option<UploadContractTemplateError> =
681                serde_json::from_str(&local_var_content).ok();
682            let local_var_error = ResponseContent {
683                status: local_var_status,
684                content: local_var_content,
685                entity: local_var_entity,
686            };
687            Err(Error::ResponseError(local_var_error))
688        }
689    }
690}
691
692/// struct for typed errors of method [`delete_contract_template_by_id`]
693#[derive(Debug, Clone, Serialize, Deserialize)]
694#[serde(untagged)]
695pub enum DeleteContractTemplateByIdError {
696    Status404(models::HttpContractDoesNotExistError),
697    DefaultResponse(models::ErrorSchema),
698    UnknownValue(serde_json::Value),
699}
700
701/// struct for typed errors of method [`deploy_contract`]
702#[derive(Debug, Clone, Serialize, Deserialize)]
703#[serde(untagged)]
704pub enum DeployContractError {
705    Status404(models::HttpContractDoesNotExistError),
706    DefaultResponse(models::ErrorSchema),
707    UnknownValue(serde_json::Value),
708}
709
710/// struct for typed errors of method
711/// [`get_constructor_by_contract_template_id`]
712#[derive(Debug, Clone, Serialize, Deserialize)]
713#[serde(untagged)]
714pub enum GetConstructorByContractTemplateIdError {
715    Status404(models::HttpContractDoesNotExistError),
716    DefaultResponse(models::ErrorSchema),
717    UnknownValue(serde_json::Value),
718}
719
720/// struct for typed errors of method [`get_contract_template_by_id`]
721#[derive(Debug, Clone, Serialize, Deserialize)]
722#[serde(untagged)]
723pub enum GetContractTemplateByIdError {
724    Status404(models::HttpContractDoesNotExistError),
725    DefaultResponse(models::ErrorSchema),
726    UnknownValue(serde_json::Value),
727}
728
729/// struct for typed errors of method [`get_contract_templates`]
730#[derive(Debug, Clone, Serialize, Deserialize)]
731#[serde(untagged)]
732pub enum GetContractTemplatesError {
733    DefaultResponse(models::ErrorSchema),
734    UnknownValue(serde_json::Value),
735}
736
737/// struct for typed errors of method
738/// [`get_function_abi_by_contract_template_id`]
739#[derive(Debug, Clone, Serialize, Deserialize)]
740#[serde(untagged)]
741pub enum GetFunctionAbiByContractTemplateIdError {
742    Status404(models::HttpContractDoesNotExistError),
743    DefaultResponse(models::ErrorSchema),
744    UnknownValue(serde_json::Value),
745}
746
747/// struct for typed errors of method [`upload_contract_template`]
748#[derive(Debug, Clone, Serialize, Deserialize)]
749#[serde(untagged)]
750pub enum UploadContractTemplateError {
751    DefaultResponse(models::ErrorSchema),
752    UnknownValue(serde_json::Value),
753}