fireblocks_sdk/apis/
deployed_contracts_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 DeployedContractsApi: Send + Sync {
23    /// POST /tokenization/contracts/abi
24    ///
25    /// Save contract ABI for the tenant. </br>Endpoint Permission: Owner,
26    /// Admin, Non-Signing Admin, Signer, and Editor.
27    async fn add_contract_abi(
28        &self,
29        params: AddContractAbiParams,
30    ) -> Result<models::ContractWithAbiDto, Error<AddContractAbiError>>;
31
32    /// POST /tokenization/contracts/fetch_abi
33    ///
34    /// Fetch the ABI. If not found fetch the ABI from the block explorer.
35    /// </br>Endpoint Permission: Admin, Non-Signing Admin, Signer, Approver,
36    /// Editor, Viewer.
37    async fn fetch_contract_abi(
38        &self,
39        params: FetchContractAbiParams,
40    ) -> Result<models::ContractWithAbiDto, Error<FetchContractAbiError>>;
41
42    /// GET /tokenization/contracts/{assetId}/{contractAddress}
43    ///
44    /// Return deployed contract data by blockchain native asset id and contract
45    /// address. </br>Endpoint Permission: Admin, Non-Signing Admin, Signer,
46    /// Approver, Editor, Viewer.
47    async fn get_deployed_contract_by_address(
48        &self,
49        params: GetDeployedContractByAddressParams,
50    ) -> Result<models::DeployedContractResponseDto, Error<GetDeployedContractByAddressError>>;
51
52    /// GET /tokenization/contracts/{id}
53    ///
54    /// Return deployed contract data by id. </br>Endpoint Permission: Admin,
55    /// Non-Signing Admin, Signer, Approver, Editor, Viewer.
56    async fn get_deployed_contract_by_id(
57        &self,
58        params: GetDeployedContractByIdParams,
59    ) -> Result<models::DeployedContractResponseDto, Error<GetDeployedContractByIdError>>;
60
61    /// GET /tokenization/contracts
62    ///
63    /// Return a filtered lean representation of the deployed contracts data on
64    /// all blockchains (paginated). </br>Endpoint Permission: Admin,
65    /// Non-Signing Admin, Signer, Approver, Editor, Viewer.
66    async fn get_deployed_contracts(
67        &self,
68        params: GetDeployedContractsParams,
69    ) -> Result<models::DeployedContractsPaginatedResponse, Error<GetDeployedContractsError>>;
70}
71
72pub struct DeployedContractsApiClient {
73    configuration: Arc<configuration::Configuration>,
74}
75
76impl DeployedContractsApiClient {
77    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
78        Self { configuration }
79    }
80}
81
82/// struct for passing parameters to the method
83/// [`DeployedContractsApi::add_contract_abi`]
84#[derive(Clone, Debug)]
85#[cfg_attr(feature = "bon", derive(::bon::Builder))]
86pub struct AddContractAbiParams {
87    pub add_abi_request_dto: models::AddAbiRequestDto,
88    /// A unique identifier for the request. If the request is sent multiple
89    /// times with the same idempotency key, the server will return the same
90    /// response as the first request. The idempotency key is valid for 24
91    /// hours.
92    pub idempotency_key: Option<String>,
93}
94
95/// struct for passing parameters to the method
96/// [`DeployedContractsApi::fetch_contract_abi`]
97#[derive(Clone, Debug)]
98#[cfg_attr(feature = "bon", derive(::bon::Builder))]
99pub struct FetchContractAbiParams {
100    pub fetch_abi_request_dto: models::FetchAbiRequestDto,
101    /// A unique identifier for the request. If the request is sent multiple
102    /// times with the same idempotency key, the server will return the same
103    /// response as the first request. The idempotency key is valid for 24
104    /// hours.
105    pub idempotency_key: Option<String>,
106}
107
108/// struct for passing parameters to the method
109/// [`DeployedContractsApi::get_deployed_contract_by_address`]
110#[derive(Clone, Debug)]
111#[cfg_attr(feature = "bon", derive(::bon::Builder))]
112pub struct GetDeployedContractByAddressParams {
113    /// The contract's onchain address
114    pub contract_address: String,
115    /// The blockchain base asset ID
116    pub asset_id: String,
117}
118
119/// struct for passing parameters to the method
120/// [`DeployedContractsApi::get_deployed_contract_by_id`]
121#[derive(Clone, Debug)]
122#[cfg_attr(feature = "bon", derive(::bon::Builder))]
123pub struct GetDeployedContractByIdParams {
124    /// The deployed contract data identifier
125    pub id: String,
126}
127
128/// struct for passing parameters to the method
129/// [`DeployedContractsApi::get_deployed_contracts`]
130#[derive(Clone, Debug)]
131#[cfg_attr(feature = "bon", derive(::bon::Builder))]
132pub struct GetDeployedContractsParams {
133    /// Page cursor to get the next page
134    pub page_cursor: Option<String>,
135    /// Number of items per page, requesting more then max will return max items
136    pub page_size: Option<f64>,
137    /// The contract's onchain address
138    pub contract_address: Option<String>,
139    /// The blockchain asset ID
140    pub base_asset_id: Option<String>,
141    /// The contract template identifier
142    pub contract_template_id: Option<String>,
143}
144
145#[async_trait]
146impl DeployedContractsApi for DeployedContractsApiClient {
147    /// Save contract ABI for the tenant. </br>Endpoint Permission: Owner,
148    /// Admin, Non-Signing Admin, Signer, and Editor.
149    async fn add_contract_abi(
150        &self,
151        params: AddContractAbiParams,
152    ) -> Result<models::ContractWithAbiDto, Error<AddContractAbiError>> {
153        let AddContractAbiParams {
154            add_abi_request_dto,
155            idempotency_key,
156        } = params;
157
158        let local_var_configuration = &self.configuration;
159
160        let local_var_client = &local_var_configuration.client;
161
162        let local_var_uri_str = format!(
163            "{}/tokenization/contracts/abi",
164            local_var_configuration.base_path
165        );
166        let mut local_var_req_builder =
167            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
168
169        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
170            local_var_req_builder = local_var_req_builder
171                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
172        }
173        if let Some(local_var_param_value) = idempotency_key {
174            local_var_req_builder =
175                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
176        }
177        local_var_req_builder = local_var_req_builder.json(&add_abi_request_dto);
178
179        let local_var_req = local_var_req_builder.build()?;
180        let local_var_resp = local_var_client.execute(local_var_req).await?;
181
182        let local_var_status = local_var_resp.status();
183        let local_var_content_type = local_var_resp
184            .headers()
185            .get("content-type")
186            .and_then(|v| v.to_str().ok())
187            .unwrap_or("application/octet-stream");
188        let local_var_content_type = super::ContentType::from(local_var_content_type);
189        let local_var_content = local_var_resp.text().await?;
190
191        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
192            match local_var_content_type {
193                ContentType::Json => {
194                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
195                }
196                ContentType::Text => {
197                    return Err(Error::from(serde_json::Error::custom(
198                        "Received `text/plain` content type response that cannot be converted to \
199                         `models::ContractWithAbiDto`",
200                    )));
201                }
202                ContentType::Unsupported(local_var_unknown_type) => {
203                    return Err(Error::from(serde_json::Error::custom(format!(
204                        "Received `{local_var_unknown_type}` content type response that cannot be \
205                         converted to `models::ContractWithAbiDto`"
206                    ))));
207                }
208            }
209        } else {
210            let local_var_entity: Option<AddContractAbiError> =
211                serde_json::from_str(&local_var_content).ok();
212            let local_var_error = ResponseContent {
213                status: local_var_status,
214                content: local_var_content,
215                entity: local_var_entity,
216            };
217            Err(Error::ResponseError(local_var_error))
218        }
219    }
220
221    /// Fetch the ABI. If not found fetch the ABI from the block explorer.
222    /// </br>Endpoint Permission: Admin, Non-Signing Admin, Signer, Approver,
223    /// Editor, Viewer.
224    async fn fetch_contract_abi(
225        &self,
226        params: FetchContractAbiParams,
227    ) -> Result<models::ContractWithAbiDto, Error<FetchContractAbiError>> {
228        let FetchContractAbiParams {
229            fetch_abi_request_dto,
230            idempotency_key,
231        } = params;
232
233        let local_var_configuration = &self.configuration;
234
235        let local_var_client = &local_var_configuration.client;
236
237        let local_var_uri_str = format!(
238            "{}/tokenization/contracts/fetch_abi",
239            local_var_configuration.base_path
240        );
241        let mut local_var_req_builder =
242            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
243
244        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
245            local_var_req_builder = local_var_req_builder
246                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
247        }
248        if let Some(local_var_param_value) = idempotency_key {
249            local_var_req_builder =
250                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
251        }
252        local_var_req_builder = local_var_req_builder.json(&fetch_abi_request_dto);
253
254        let local_var_req = local_var_req_builder.build()?;
255        let local_var_resp = local_var_client.execute(local_var_req).await?;
256
257        let local_var_status = local_var_resp.status();
258        let local_var_content_type = local_var_resp
259            .headers()
260            .get("content-type")
261            .and_then(|v| v.to_str().ok())
262            .unwrap_or("application/octet-stream");
263        let local_var_content_type = super::ContentType::from(local_var_content_type);
264        let local_var_content = local_var_resp.text().await?;
265
266        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
267            match local_var_content_type {
268                ContentType::Json => {
269                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
270                }
271                ContentType::Text => {
272                    return Err(Error::from(serde_json::Error::custom(
273                        "Received `text/plain` content type response that cannot be converted to \
274                         `models::ContractWithAbiDto`",
275                    )));
276                }
277                ContentType::Unsupported(local_var_unknown_type) => {
278                    return Err(Error::from(serde_json::Error::custom(format!(
279                        "Received `{local_var_unknown_type}` content type response that cannot be \
280                         converted to `models::ContractWithAbiDto`"
281                    ))));
282                }
283            }
284        } else {
285            let local_var_entity: Option<FetchContractAbiError> =
286                serde_json::from_str(&local_var_content).ok();
287            let local_var_error = ResponseContent {
288                status: local_var_status,
289                content: local_var_content,
290                entity: local_var_entity,
291            };
292            Err(Error::ResponseError(local_var_error))
293        }
294    }
295
296    /// Return deployed contract data by blockchain native asset id and contract
297    /// address. </br>Endpoint Permission: Admin, Non-Signing Admin, Signer,
298    /// Approver, Editor, Viewer.
299    async fn get_deployed_contract_by_address(
300        &self,
301        params: GetDeployedContractByAddressParams,
302    ) -> Result<models::DeployedContractResponseDto, Error<GetDeployedContractByAddressError>> {
303        let GetDeployedContractByAddressParams {
304            contract_address,
305            asset_id,
306        } = params;
307
308        let local_var_configuration = &self.configuration;
309
310        let local_var_client = &local_var_configuration.client;
311
312        let local_var_uri_str = format!(
313            "{}/tokenization/contracts/{assetId}/{contractAddress}",
314            local_var_configuration.base_path,
315            contractAddress = crate::apis::urlencode(contract_address),
316            assetId = crate::apis::urlencode(asset_id)
317        );
318        let mut local_var_req_builder =
319            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
320
321        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
322            local_var_req_builder = local_var_req_builder
323                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
324        }
325
326        let local_var_req = local_var_req_builder.build()?;
327        let local_var_resp = local_var_client.execute(local_var_req).await?;
328
329        let local_var_status = local_var_resp.status();
330        let local_var_content_type = local_var_resp
331            .headers()
332            .get("content-type")
333            .and_then(|v| v.to_str().ok())
334            .unwrap_or("application/octet-stream");
335        let local_var_content_type = super::ContentType::from(local_var_content_type);
336        let local_var_content = local_var_resp.text().await?;
337
338        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
339            match local_var_content_type {
340                ContentType::Json => {
341                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
342                }
343                ContentType::Text => {
344                    return Err(Error::from(serde_json::Error::custom(
345                        "Received `text/plain` content type response that cannot be converted to \
346                         `models::DeployedContractResponseDto`",
347                    )));
348                }
349                ContentType::Unsupported(local_var_unknown_type) => {
350                    return Err(Error::from(serde_json::Error::custom(format!(
351                        "Received `{local_var_unknown_type}` content type response that cannot be \
352                         converted to `models::DeployedContractResponseDto`"
353                    ))));
354                }
355            }
356        } else {
357            let local_var_entity: Option<GetDeployedContractByAddressError> =
358                serde_json::from_str(&local_var_content).ok();
359            let local_var_error = ResponseContent {
360                status: local_var_status,
361                content: local_var_content,
362                entity: local_var_entity,
363            };
364            Err(Error::ResponseError(local_var_error))
365        }
366    }
367
368    /// Return deployed contract data by id. </br>Endpoint Permission: Admin,
369    /// Non-Signing Admin, Signer, Approver, Editor, Viewer.
370    async fn get_deployed_contract_by_id(
371        &self,
372        params: GetDeployedContractByIdParams,
373    ) -> Result<models::DeployedContractResponseDto, Error<GetDeployedContractByIdError>> {
374        let GetDeployedContractByIdParams { id } = params;
375
376        let local_var_configuration = &self.configuration;
377
378        let local_var_client = &local_var_configuration.client;
379
380        let local_var_uri_str = format!(
381            "{}/tokenization/contracts/{id}",
382            local_var_configuration.base_path,
383            id = crate::apis::urlencode(id)
384        );
385        let mut local_var_req_builder =
386            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
387
388        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
389            local_var_req_builder = local_var_req_builder
390                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
391        }
392
393        let local_var_req = local_var_req_builder.build()?;
394        let local_var_resp = local_var_client.execute(local_var_req).await?;
395
396        let local_var_status = local_var_resp.status();
397        let local_var_content_type = local_var_resp
398            .headers()
399            .get("content-type")
400            .and_then(|v| v.to_str().ok())
401            .unwrap_or("application/octet-stream");
402        let local_var_content_type = super::ContentType::from(local_var_content_type);
403        let local_var_content = local_var_resp.text().await?;
404
405        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
406            match local_var_content_type {
407                ContentType::Json => {
408                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
409                }
410                ContentType::Text => {
411                    return Err(Error::from(serde_json::Error::custom(
412                        "Received `text/plain` content type response that cannot be converted to \
413                         `models::DeployedContractResponseDto`",
414                    )));
415                }
416                ContentType::Unsupported(local_var_unknown_type) => {
417                    return Err(Error::from(serde_json::Error::custom(format!(
418                        "Received `{local_var_unknown_type}` content type response that cannot be \
419                         converted to `models::DeployedContractResponseDto`"
420                    ))));
421                }
422            }
423        } else {
424            let local_var_entity: Option<GetDeployedContractByIdError> =
425                serde_json::from_str(&local_var_content).ok();
426            let local_var_error = ResponseContent {
427                status: local_var_status,
428                content: local_var_content,
429                entity: local_var_entity,
430            };
431            Err(Error::ResponseError(local_var_error))
432        }
433    }
434
435    /// Return a filtered lean representation of the deployed contracts data on
436    /// all blockchains (paginated). </br>Endpoint Permission: Admin,
437    /// Non-Signing Admin, Signer, Approver, Editor, Viewer.
438    async fn get_deployed_contracts(
439        &self,
440        params: GetDeployedContractsParams,
441    ) -> Result<models::DeployedContractsPaginatedResponse, Error<GetDeployedContractsError>> {
442        let GetDeployedContractsParams {
443            page_cursor,
444            page_size,
445            contract_address,
446            base_asset_id,
447            contract_template_id,
448        } = params;
449
450        let local_var_configuration = &self.configuration;
451
452        let local_var_client = &local_var_configuration.client;
453
454        let local_var_uri_str = format!(
455            "{}/tokenization/contracts",
456            local_var_configuration.base_path
457        );
458        let mut local_var_req_builder =
459            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
460
461        if let Some(ref param_value) = page_cursor {
462            local_var_req_builder =
463                local_var_req_builder.query(&[("pageCursor", &param_value.to_string())]);
464        }
465        if let Some(ref param_value) = page_size {
466            local_var_req_builder =
467                local_var_req_builder.query(&[("pageSize", &param_value.to_string())]);
468        }
469        if let Some(ref param_value) = contract_address {
470            local_var_req_builder =
471                local_var_req_builder.query(&[("contractAddress", &param_value.to_string())]);
472        }
473        if let Some(ref param_value) = base_asset_id {
474            local_var_req_builder =
475                local_var_req_builder.query(&[("baseAssetId", &param_value.to_string())]);
476        }
477        if let Some(ref param_value) = contract_template_id {
478            local_var_req_builder =
479                local_var_req_builder.query(&[("contractTemplateId", &param_value.to_string())]);
480        }
481        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
482            local_var_req_builder = local_var_req_builder
483                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
484        }
485
486        let local_var_req = local_var_req_builder.build()?;
487        let local_var_resp = local_var_client.execute(local_var_req).await?;
488
489        let local_var_status = local_var_resp.status();
490        let local_var_content_type = local_var_resp
491            .headers()
492            .get("content-type")
493            .and_then(|v| v.to_str().ok())
494            .unwrap_or("application/octet-stream");
495        let local_var_content_type = super::ContentType::from(local_var_content_type);
496        let local_var_content = local_var_resp.text().await?;
497
498        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
499            match local_var_content_type {
500                ContentType::Json => {
501                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
502                }
503                ContentType::Text => {
504                    return Err(Error::from(serde_json::Error::custom(
505                        "Received `text/plain` content type response that cannot be converted to \
506                         `models::DeployedContractsPaginatedResponse`",
507                    )));
508                }
509                ContentType::Unsupported(local_var_unknown_type) => {
510                    return Err(Error::from(serde_json::Error::custom(format!(
511                        "Received `{local_var_unknown_type}` content type response that cannot be \
512                         converted to `models::DeployedContractsPaginatedResponse`"
513                    ))));
514                }
515            }
516        } else {
517            let local_var_entity: Option<GetDeployedContractsError> =
518                serde_json::from_str(&local_var_content).ok();
519            let local_var_error = ResponseContent {
520                status: local_var_status,
521                content: local_var_content,
522                entity: local_var_entity,
523            };
524            Err(Error::ResponseError(local_var_error))
525        }
526    }
527}
528
529/// struct for typed errors of method [`DeployedContractsApi::add_contract_abi`]
530#[derive(Debug, Clone, Serialize, Deserialize)]
531#[serde(untagged)]
532pub enum AddContractAbiError {
533    Status409(),
534    DefaultResponse(models::ErrorSchema),
535    UnknownValue(serde_json::Value),
536}
537
538/// struct for typed errors of method
539/// [`DeployedContractsApi::fetch_contract_abi`]
540#[derive(Debug, Clone, Serialize, Deserialize)]
541#[serde(untagged)]
542pub enum FetchContractAbiError {
543    Status404(),
544    DefaultResponse(models::ErrorSchema),
545    UnknownValue(serde_json::Value),
546}
547
548/// struct for typed errors of method
549/// [`DeployedContractsApi::get_deployed_contract_by_address`]
550#[derive(Debug, Clone, Serialize, Deserialize)]
551#[serde(untagged)]
552pub enum GetDeployedContractByAddressError {
553    DefaultResponse(models::ErrorSchema),
554    UnknownValue(serde_json::Value),
555}
556
557/// struct for typed errors of method
558/// [`DeployedContractsApi::get_deployed_contract_by_id`]
559#[derive(Debug, Clone, Serialize, Deserialize)]
560#[serde(untagged)]
561pub enum GetDeployedContractByIdError {
562    DefaultResponse(models::ErrorSchema),
563    UnknownValue(serde_json::Value),
564}
565
566/// struct for typed errors of method
567/// [`DeployedContractsApi::get_deployed_contracts`]
568#[derive(Debug, Clone, Serialize, Deserialize)]
569#[serde(untagged)]
570pub enum GetDeployedContractsError {
571    DefaultResponse(models::ErrorSchema),
572    UnknownValue(serde_json::Value),
573}