fireblocks_sdk/apis/
contract_interactions_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 ContractInteractionsApi: Send + Sync {
23    /// GET /contract_interactions/base_asset_id/{baseAssetId}/contract_address/
24    /// {contractAddress}/functions
25    ///
26    /// Return deployed contract's ABI by blockchain native asset id and
27    /// contract address. </br>Endpoint Permission: Endpoint Permission: Admin,
28    /// Non-Signing Admin, Signer, Approver, Editor, and Viewer.
29    async fn get_deployed_contract_abi(
30        &self,
31        params: GetDeployedContractAbiParams,
32    ) -> Result<models::ContractAbiResponseDto, Error<GetDeployedContractAbiError>>;
33
34    /// GET /contract_interactions/base_asset_id/{baseAssetId}/tx_hash/{txHash}/
35    /// receipt
36    ///
37    /// Retrieve the transaction receipt by blockchain native asset ID and
38    /// transaction hash  </br>Endpoint Permission: Admin, Non-Signing Admin,
39    /// Signer, Approver, Editor, and Viewer.
40    async fn get_transaction_receipt(
41        &self,
42        params: GetTransactionReceiptParams,
43    ) -> Result<models::TransactionReceiptResponse, Error<GetTransactionReceiptError>>;
44
45    /// POST /contract_interactions/base_asset_id/{baseAssetId}/
46    /// contract_address/{contractAddress}/functions/read
47    ///
48    /// Call a read function on a deployed contract by blockchain native asset
49    /// id and contract address. </br>Endpoint Permission: Endpoint Permission:
50    /// Owner, Admin, Non-Signing Admin, Signer, and Editor.
51    async fn read_call_function(
52        &self,
53        params: ReadCallFunctionParams,
54    ) -> Result<Vec<models::ParameterWithValue>, Error<ReadCallFunctionError>>;
55
56    /// POST /contract_interactions/base_asset_id/{baseAssetId}/
57    /// contract_address/{contractAddress}/functions/write
58    ///
59    /// Call a write function on a deployed contract by blockchain native asset
60    /// id and contract address. This creates an onchain transaction, thus it is
61    /// an async operation. It returns a transaction id that can be polled for
62    /// status check.  </br>Endpoint Permission: Owner, Admin, Non-Signing
63    /// Admin, Signer, and Editor.
64    async fn write_call_function(
65        &self,
66        params: WriteCallFunctionParams,
67    ) -> Result<models::WriteCallFunctionResponseDto, Error<WriteCallFunctionError>>;
68}
69
70pub struct ContractInteractionsApiClient {
71    configuration: Arc<configuration::Configuration>,
72}
73
74impl ContractInteractionsApiClient {
75    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
76        Self { configuration }
77    }
78}
79
80/// struct for passing parameters to the method
81/// [`ContractInteractionsApi::get_deployed_contract_abi`]
82#[derive(Clone, Debug)]
83#[cfg_attr(feature = "bon", derive(::bon::Builder))]
84pub struct GetDeployedContractAbiParams {
85    /// The contract's onchain address
86    pub contract_address: String,
87    /// The blockchain base assetId
88    pub base_asset_id: String,
89    /// A unique identifier for the request. If the request is sent multiple
90    /// times with the same idempotency key, the server will return the same
91    /// response as the first request. The idempotency key is valid for 24
92    /// hours.
93    pub idempotency_key: Option<String>,
94}
95
96/// struct for passing parameters to the method
97/// [`ContractInteractionsApi::get_transaction_receipt`]
98#[derive(Clone, Debug)]
99#[cfg_attr(feature = "bon", derive(::bon::Builder))]
100pub struct GetTransactionReceiptParams {
101    /// The blockchain base assetId
102    pub base_asset_id: String,
103    /// The transaction hash
104    pub tx_hash: String,
105}
106
107/// struct for passing parameters to the method
108/// [`ContractInteractionsApi::read_call_function`]
109#[derive(Clone, Debug)]
110#[cfg_attr(feature = "bon", derive(::bon::Builder))]
111pub struct ReadCallFunctionParams {
112    /// The contract's onchain address
113    pub contract_address: String,
114    /// The blockchain base assetId
115    pub base_asset_id: String,
116    pub read_call_function_dto: models::ReadCallFunctionDto,
117    /// A unique identifier for the request. If the request is sent multiple
118    /// times with the same idempotency key, the server will return the same
119    /// response as the first request. The idempotency key is valid for 24
120    /// hours.
121    pub idempotency_key: Option<String>,
122}
123
124/// struct for passing parameters to the method
125/// [`ContractInteractionsApi::write_call_function`]
126#[derive(Clone, Debug)]
127#[cfg_attr(feature = "bon", derive(::bon::Builder))]
128pub struct WriteCallFunctionParams {
129    /// The contract's onchain address
130    pub contract_address: String,
131    /// The blockchain base assetId
132    pub base_asset_id: String,
133    pub write_call_function_dto: models::WriteCallFunctionDto,
134    /// A unique identifier for the request. If the request is sent multiple
135    /// times with the same idempotency key, the server will return the same
136    /// response as the first request. The idempotency key is valid for 24
137    /// hours.
138    pub idempotency_key: Option<String>,
139}
140
141#[async_trait]
142impl ContractInteractionsApi for ContractInteractionsApiClient {
143    /// Return deployed contract's ABI by blockchain native asset id and
144    /// contract address. </br>Endpoint Permission: Endpoint Permission: Admin,
145    /// Non-Signing Admin, Signer, Approver, Editor, and Viewer.
146    async fn get_deployed_contract_abi(
147        &self,
148        params: GetDeployedContractAbiParams,
149    ) -> Result<models::ContractAbiResponseDto, Error<GetDeployedContractAbiError>> {
150        let GetDeployedContractAbiParams {
151            contract_address,
152            base_asset_id,
153            idempotency_key,
154        } = params;
155
156        let local_var_configuration = &self.configuration;
157
158        let local_var_client = &local_var_configuration.client;
159
160        let local_var_uri_str = format!(
161            "{}/contract_interactions/base_asset_id/{baseAssetId}/contract_address/\
162             {contractAddress}/functions",
163            local_var_configuration.base_path,
164            contractAddress = crate::apis::urlencode(contract_address),
165            baseAssetId = crate::apis::urlencode(base_asset_id)
166        );
167        let mut local_var_req_builder =
168            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
169
170        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
171            local_var_req_builder = local_var_req_builder
172                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
173        }
174        if let Some(local_var_param_value) = idempotency_key {
175            local_var_req_builder =
176                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
177        }
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::ContractAbiResponseDto`",
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::ContractAbiResponseDto`"
206                    ))));
207                }
208            }
209        } else {
210            let local_var_entity: Option<GetDeployedContractAbiError> =
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    /// Retrieve the transaction receipt by blockchain native asset ID and
222    /// transaction hash  </br>Endpoint Permission: Admin, Non-Signing Admin,
223    /// Signer, Approver, Editor, and Viewer.
224    async fn get_transaction_receipt(
225        &self,
226        params: GetTransactionReceiptParams,
227    ) -> Result<models::TransactionReceiptResponse, Error<GetTransactionReceiptError>> {
228        let GetTransactionReceiptParams {
229            base_asset_id,
230            tx_hash,
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            "{}/contract_interactions/base_asset_id/{baseAssetId}/tx_hash/{txHash}/receipt",
239            local_var_configuration.base_path,
240            baseAssetId = crate::apis::urlencode(base_asset_id),
241            txHash = crate::apis::urlencode(tx_hash)
242        );
243        let mut local_var_req_builder =
244            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
245
246        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
247            local_var_req_builder = local_var_req_builder
248                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
249        }
250
251        let local_var_req = local_var_req_builder.build()?;
252        let local_var_resp = local_var_client.execute(local_var_req).await?;
253
254        let local_var_status = local_var_resp.status();
255        let local_var_content_type = local_var_resp
256            .headers()
257            .get("content-type")
258            .and_then(|v| v.to_str().ok())
259            .unwrap_or("application/octet-stream");
260        let local_var_content_type = super::ContentType::from(local_var_content_type);
261        let local_var_content = local_var_resp.text().await?;
262
263        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
264            match local_var_content_type {
265                ContentType::Json => {
266                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
267                }
268                ContentType::Text => {
269                    return Err(Error::from(serde_json::Error::custom(
270                        "Received `text/plain` content type response that cannot be converted to \
271                         `models::TransactionReceiptResponse`",
272                    )));
273                }
274                ContentType::Unsupported(local_var_unknown_type) => {
275                    return Err(Error::from(serde_json::Error::custom(format!(
276                        "Received `{local_var_unknown_type}` content type response that cannot be \
277                         converted to `models::TransactionReceiptResponse`"
278                    ))));
279                }
280            }
281        } else {
282            let local_var_entity: Option<GetTransactionReceiptError> =
283                serde_json::from_str(&local_var_content).ok();
284            let local_var_error = ResponseContent {
285                status: local_var_status,
286                content: local_var_content,
287                entity: local_var_entity,
288            };
289            Err(Error::ResponseError(local_var_error))
290        }
291    }
292
293    /// Call a read function on a deployed contract by blockchain native asset
294    /// id and contract address. </br>Endpoint Permission: Endpoint Permission:
295    /// Owner, Admin, Non-Signing Admin, Signer, and Editor.
296    async fn read_call_function(
297        &self,
298        params: ReadCallFunctionParams,
299    ) -> Result<Vec<models::ParameterWithValue>, Error<ReadCallFunctionError>> {
300        let ReadCallFunctionParams {
301            contract_address,
302            base_asset_id,
303            read_call_function_dto,
304            idempotency_key,
305        } = params;
306
307        let local_var_configuration = &self.configuration;
308
309        let local_var_client = &local_var_configuration.client;
310
311        let local_var_uri_str = format!(
312            "{}/contract_interactions/base_asset_id/{baseAssetId}/contract_address/\
313             {contractAddress}/functions/read",
314            local_var_configuration.base_path,
315            contractAddress = crate::apis::urlencode(contract_address),
316            baseAssetId = crate::apis::urlencode(base_asset_id)
317        );
318        let mut local_var_req_builder =
319            local_var_client.request(reqwest::Method::POST, 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        if let Some(local_var_param_value) = idempotency_key {
326            local_var_req_builder =
327                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
328        }
329        local_var_req_builder = local_var_req_builder.json(&read_call_function_dto);
330
331        let local_var_req = local_var_req_builder.build()?;
332        let local_var_resp = local_var_client.execute(local_var_req).await?;
333
334        let local_var_status = local_var_resp.status();
335        let local_var_content_type = local_var_resp
336            .headers()
337            .get("content-type")
338            .and_then(|v| v.to_str().ok())
339            .unwrap_or("application/octet-stream");
340        let local_var_content_type = super::ContentType::from(local_var_content_type);
341        let local_var_content = local_var_resp.text().await?;
342
343        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
344            match local_var_content_type {
345                ContentType::Json => {
346                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
347                }
348                ContentType::Text => {
349                    return Err(Error::from(serde_json::Error::custom(
350                        "Received `text/plain` content type response that cannot be converted to \
351                         `Vec&lt;models::ParameterWithValue&gt;`",
352                    )));
353                }
354                ContentType::Unsupported(local_var_unknown_type) => {
355                    return Err(Error::from(serde_json::Error::custom(format!(
356                        "Received `{local_var_unknown_type}` content type response that cannot be \
357                         converted to `Vec&lt;models::ParameterWithValue&gt;`"
358                    ))));
359                }
360            }
361        } else {
362            let local_var_entity: Option<ReadCallFunctionError> =
363                serde_json::from_str(&local_var_content).ok();
364            let local_var_error = ResponseContent {
365                status: local_var_status,
366                content: local_var_content,
367                entity: local_var_entity,
368            };
369            Err(Error::ResponseError(local_var_error))
370        }
371    }
372
373    /// Call a write function on a deployed contract by blockchain native asset
374    /// id and contract address. This creates an onchain transaction, thus it is
375    /// an async operation. It returns a transaction id that can be polled for
376    /// status check.  </br>Endpoint Permission: Owner, Admin, Non-Signing
377    /// Admin, Signer, and Editor.
378    async fn write_call_function(
379        &self,
380        params: WriteCallFunctionParams,
381    ) -> Result<models::WriteCallFunctionResponseDto, Error<WriteCallFunctionError>> {
382        let WriteCallFunctionParams {
383            contract_address,
384            base_asset_id,
385            write_call_function_dto,
386            idempotency_key,
387        } = params;
388
389        let local_var_configuration = &self.configuration;
390
391        let local_var_client = &local_var_configuration.client;
392
393        let local_var_uri_str = format!(
394            "{}/contract_interactions/base_asset_id/{baseAssetId}/contract_address/\
395             {contractAddress}/functions/write",
396            local_var_configuration.base_path,
397            contractAddress = crate::apis::urlencode(contract_address),
398            baseAssetId = crate::apis::urlencode(base_asset_id)
399        );
400        let mut local_var_req_builder =
401            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
402
403        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
404            local_var_req_builder = local_var_req_builder
405                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
406        }
407        if let Some(local_var_param_value) = idempotency_key {
408            local_var_req_builder =
409                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
410        }
411        local_var_req_builder = local_var_req_builder.json(&write_call_function_dto);
412
413        let local_var_req = local_var_req_builder.build()?;
414        let local_var_resp = local_var_client.execute(local_var_req).await?;
415
416        let local_var_status = local_var_resp.status();
417        let local_var_content_type = local_var_resp
418            .headers()
419            .get("content-type")
420            .and_then(|v| v.to_str().ok())
421            .unwrap_or("application/octet-stream");
422        let local_var_content_type = super::ContentType::from(local_var_content_type);
423        let local_var_content = local_var_resp.text().await?;
424
425        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
426            match local_var_content_type {
427                ContentType::Json => {
428                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
429                }
430                ContentType::Text => {
431                    return Err(Error::from(serde_json::Error::custom(
432                        "Received `text/plain` content type response that cannot be converted to \
433                         `models::WriteCallFunctionResponseDto`",
434                    )));
435                }
436                ContentType::Unsupported(local_var_unknown_type) => {
437                    return Err(Error::from(serde_json::Error::custom(format!(
438                        "Received `{local_var_unknown_type}` content type response that cannot be \
439                         converted to `models::WriteCallFunctionResponseDto`"
440                    ))));
441                }
442            }
443        } else {
444            let local_var_entity: Option<WriteCallFunctionError> =
445                serde_json::from_str(&local_var_content).ok();
446            let local_var_error = ResponseContent {
447                status: local_var_status,
448                content: local_var_content,
449                entity: local_var_entity,
450            };
451            Err(Error::ResponseError(local_var_error))
452        }
453    }
454}
455
456/// struct for typed errors of method
457/// [`ContractInteractionsApi::get_deployed_contract_abi`]
458#[derive(Debug, Clone, Serialize, Deserialize)]
459#[serde(untagged)]
460pub enum GetDeployedContractAbiError {
461    DefaultResponse(models::ErrorSchema),
462    UnknownValue(serde_json::Value),
463}
464
465/// struct for typed errors of method
466/// [`ContractInteractionsApi::get_transaction_receipt`]
467#[derive(Debug, Clone, Serialize, Deserialize)]
468#[serde(untagged)]
469pub enum GetTransactionReceiptError {
470    DefaultResponse(models::ErrorSchema),
471    UnknownValue(serde_json::Value),
472}
473
474/// struct for typed errors of method
475/// [`ContractInteractionsApi::read_call_function`]
476#[derive(Debug, Clone, Serialize, Deserialize)]
477#[serde(untagged)]
478pub enum ReadCallFunctionError {
479    DefaultResponse(models::ErrorSchema),
480    UnknownValue(serde_json::Value),
481}
482
483/// struct for typed errors of method
484/// [`ContractInteractionsApi::write_call_function`]
485#[derive(Debug, Clone, Serialize, Deserialize)]
486#[serde(untagged)]
487pub enum WriteCallFunctionError {
488    DefaultResponse(models::ErrorSchema),
489    UnknownValue(serde_json::Value),
490}