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