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