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::{apis::ResponseContent, models},
12    async_trait::async_trait,
13    reqwest,
14    serde::{Deserialize, Serialize},
15    std::sync::Arc,
16};
17
18#[async_trait]
19pub trait ContractInteractionsApi: Send + Sync {
20    async fn get_deployed_contract_abi(
21        &self,
22        params: GetDeployedContractAbiParams,
23    ) -> Result<models::ContractAbiResponseDto, Error<GetDeployedContractAbiError>>;
24    async fn get_transaction_receipt(
25        &self,
26        params: GetTransactionReceiptParams,
27    ) -> Result<models::TransactionReceiptResponse, Error<GetTransactionReceiptError>>;
28    async fn read_call_function(
29        &self,
30        params: ReadCallFunctionParams,
31    ) -> Result<Vec<models::ParameterWithValue>, Error<ReadCallFunctionError>>;
32    async fn write_call_function(
33        &self,
34        params: WriteCallFunctionParams,
35    ) -> Result<models::WriteCallFunctionResponseDto, Error<WriteCallFunctionError>>;
36}
37
38pub struct ContractInteractionsApiClient {
39    configuration: Arc<configuration::Configuration>,
40}
41
42impl ContractInteractionsApiClient {
43    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
44        Self { configuration }
45    }
46}
47
48/// struct for passing parameters to the method [`get_deployed_contract_abi`]
49#[derive(Clone, Debug)]
50#[cfg_attr(feature = "bon", derive(::bon::Builder))]
51pub struct GetDeployedContractAbiParams {
52    /// The contract's onchain address
53    pub contract_address: String,
54    /// The blockchain base assetId
55    pub base_asset_id: String,
56    /// A unique identifier for the request. If the request is sent multiple
57    /// times with the same idempotency key, the server will return the same
58    /// response as the first request. The idempotency key is valid for 24
59    /// hours.
60    pub idempotency_key: Option<String>,
61}
62
63/// struct for passing parameters to the method [`get_transaction_receipt`]
64#[derive(Clone, Debug)]
65#[cfg_attr(feature = "bon", derive(::bon::Builder))]
66pub struct GetTransactionReceiptParams {
67    /// The blockchain base assetId
68    pub base_asset_id: String,
69    /// The transaction hash
70    pub tx_hash: String,
71}
72
73/// struct for passing parameters to the method [`read_call_function`]
74#[derive(Clone, Debug)]
75#[cfg_attr(feature = "bon", derive(::bon::Builder))]
76pub struct ReadCallFunctionParams {
77    /// The contract's onchain address
78    pub contract_address: String,
79    /// The blockchain base assetId
80    pub base_asset_id: String,
81    pub read_call_function_dto: models::ReadCallFunctionDto,
82    /// A unique identifier for the request. If the request is sent multiple
83    /// times with the same idempotency key, the server will return the same
84    /// response as the first request. The idempotency key is valid for 24
85    /// hours.
86    pub idempotency_key: Option<String>,
87}
88
89/// struct for passing parameters to the method [`write_call_function`]
90#[derive(Clone, Debug)]
91#[cfg_attr(feature = "bon", derive(::bon::Builder))]
92pub struct WriteCallFunctionParams {
93    /// The contract's onchain address
94    pub contract_address: String,
95    /// The blockchain base assetId
96    pub base_asset_id: String,
97    pub write_call_function_dto: models::WriteCallFunctionDto,
98    /// A unique identifier for the request. If the request is sent multiple
99    /// times with the same idempotency key, the server will return the same
100    /// response as the first request. The idempotency key is valid for 24
101    /// hours.
102    pub idempotency_key: Option<String>,
103}
104
105#[async_trait]
106impl ContractInteractionsApi for ContractInteractionsApiClient {
107    /// Return deployed contract's ABI by blockchain native asset id and
108    /// contract address. </br>Endpoint Permission: Admin, Non-Signing Admin.
109    async fn get_deployed_contract_abi(
110        &self,
111        params: GetDeployedContractAbiParams,
112    ) -> Result<models::ContractAbiResponseDto, Error<GetDeployedContractAbiError>> {
113        let GetDeployedContractAbiParams {
114            contract_address,
115            base_asset_id,
116            idempotency_key,
117        } = params;
118
119        let local_var_configuration = &self.configuration;
120
121        let local_var_client = &local_var_configuration.client;
122
123        let local_var_uri_str = format!(
124            "{}/contract_interactions/base_asset_id/{baseAssetId}/contract_address/\
125             {contractAddress}/functions",
126            local_var_configuration.base_path,
127            contractAddress = crate::apis::urlencode(contract_address),
128            baseAssetId = crate::apis::urlencode(base_asset_id)
129        );
130        let mut local_var_req_builder =
131            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
132
133        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
134            local_var_req_builder = local_var_req_builder
135                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
136        }
137        if let Some(local_var_param_value) = idempotency_key {
138            local_var_req_builder =
139                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
140        }
141
142        let local_var_req = local_var_req_builder.build()?;
143        let local_var_resp = local_var_client.execute(local_var_req).await?;
144
145        let local_var_status = local_var_resp.status();
146        let local_var_content = local_var_resp.text().await?;
147
148        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
149            serde_json::from_str(&local_var_content).map_err(Error::from)
150        } else {
151            let local_var_entity: Option<GetDeployedContractAbiError> =
152                serde_json::from_str(&local_var_content).ok();
153            let local_var_error = ResponseContent {
154                status: local_var_status,
155                content: local_var_content,
156                entity: local_var_entity,
157            };
158            Err(Error::ResponseError(local_var_error))
159        }
160    }
161
162    /// Retrieve the transaction receipt by blockchain native asset ID and
163    /// transaction hash  </br>Endpoint Permission: Admin, Non-Signing Admin.
164    async fn get_transaction_receipt(
165        &self,
166        params: GetTransactionReceiptParams,
167    ) -> Result<models::TransactionReceiptResponse, Error<GetTransactionReceiptError>> {
168        let GetTransactionReceiptParams {
169            base_asset_id,
170            tx_hash,
171        } = params;
172
173        let local_var_configuration = &self.configuration;
174
175        let local_var_client = &local_var_configuration.client;
176
177        let local_var_uri_str = format!(
178            "{}/contract_interactions/base_asset_id/{baseAssetId}/tx_hash/{txHash}/receipt",
179            local_var_configuration.base_path,
180            baseAssetId = crate::apis::urlencode(base_asset_id),
181            txHash = crate::apis::urlencode(tx_hash)
182        );
183        let mut local_var_req_builder =
184            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
185
186        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
187            local_var_req_builder = local_var_req_builder
188                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
189        }
190
191        let local_var_req = local_var_req_builder.build()?;
192        let local_var_resp = local_var_client.execute(local_var_req).await?;
193
194        let local_var_status = local_var_resp.status();
195        let local_var_content = local_var_resp.text().await?;
196
197        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
198            serde_json::from_str(&local_var_content).map_err(Error::from)
199        } else {
200            let local_var_entity: Option<GetTransactionReceiptError> =
201                serde_json::from_str(&local_var_content).ok();
202            let local_var_error = ResponseContent {
203                status: local_var_status,
204                content: local_var_content,
205                entity: local_var_entity,
206            };
207            Err(Error::ResponseError(local_var_error))
208        }
209    }
210
211    /// Call a read function on a deployed contract by blockchain native asset
212    /// id and contract address. </br>Endpoint Permission: Admin, Non-Signing
213    /// Admin.
214    async fn read_call_function(
215        &self,
216        params: ReadCallFunctionParams,
217    ) -> Result<Vec<models::ParameterWithValue>, Error<ReadCallFunctionError>> {
218        let ReadCallFunctionParams {
219            contract_address,
220            base_asset_id,
221            read_call_function_dto,
222            idempotency_key,
223        } = params;
224
225        let local_var_configuration = &self.configuration;
226
227        let local_var_client = &local_var_configuration.client;
228
229        let local_var_uri_str = format!(
230            "{}/contract_interactions/base_asset_id/{baseAssetId}/contract_address/\
231             {contractAddress}/functions/read",
232            local_var_configuration.base_path,
233            contractAddress = crate::apis::urlencode(contract_address),
234            baseAssetId = crate::apis::urlencode(base_asset_id)
235        );
236        let mut local_var_req_builder =
237            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
238
239        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
240            local_var_req_builder = local_var_req_builder
241                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
242        }
243        if let Some(local_var_param_value) = idempotency_key {
244            local_var_req_builder =
245                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
246        }
247        local_var_req_builder = local_var_req_builder.json(&read_call_function_dto);
248
249        let local_var_req = local_var_req_builder.build()?;
250        let local_var_resp = local_var_client.execute(local_var_req).await?;
251
252        let local_var_status = local_var_resp.status();
253        let local_var_content = local_var_resp.text().await?;
254
255        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
256            serde_json::from_str(&local_var_content).map_err(Error::from)
257        } else {
258            let local_var_entity: Option<ReadCallFunctionError> =
259                serde_json::from_str(&local_var_content).ok();
260            let local_var_error = ResponseContent {
261                status: local_var_status,
262                content: local_var_content,
263                entity: local_var_entity,
264            };
265            Err(Error::ResponseError(local_var_error))
266        }
267    }
268
269    /// Call a write function on a deployed contract by blockchain native asset
270    /// id and contract address. This creates an onchain transaction, thus it is
271    /// an async operation. It returns a transaction id that can be polled for
272    /// status check.  </br>Endpoint Permission: Admin, Non-Signing Admin.
273    async fn write_call_function(
274        &self,
275        params: WriteCallFunctionParams,
276    ) -> Result<models::WriteCallFunctionResponseDto, Error<WriteCallFunctionError>> {
277        let WriteCallFunctionParams {
278            contract_address,
279            base_asset_id,
280            write_call_function_dto,
281            idempotency_key,
282        } = params;
283
284        let local_var_configuration = &self.configuration;
285
286        let local_var_client = &local_var_configuration.client;
287
288        let local_var_uri_str = format!(
289            "{}/contract_interactions/base_asset_id/{baseAssetId}/contract_address/\
290             {contractAddress}/functions/write",
291            local_var_configuration.base_path,
292            contractAddress = crate::apis::urlencode(contract_address),
293            baseAssetId = crate::apis::urlencode(base_asset_id)
294        );
295        let mut local_var_req_builder =
296            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
297
298        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
299            local_var_req_builder = local_var_req_builder
300                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
301        }
302        if let Some(local_var_param_value) = idempotency_key {
303            local_var_req_builder =
304                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
305        }
306        local_var_req_builder = local_var_req_builder.json(&write_call_function_dto);
307
308        let local_var_req = local_var_req_builder.build()?;
309        let local_var_resp = local_var_client.execute(local_var_req).await?;
310
311        let local_var_status = local_var_resp.status();
312        let local_var_content = local_var_resp.text().await?;
313
314        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
315            serde_json::from_str(&local_var_content).map_err(Error::from)
316        } else {
317            let local_var_entity: Option<WriteCallFunctionError> =
318                serde_json::from_str(&local_var_content).ok();
319            let local_var_error = ResponseContent {
320                status: local_var_status,
321                content: local_var_content,
322                entity: local_var_entity,
323            };
324            Err(Error::ResponseError(local_var_error))
325        }
326    }
327}
328
329/// struct for typed errors of method [`get_deployed_contract_abi`]
330#[derive(Debug, Clone, Serialize, Deserialize)]
331#[serde(untagged)]
332pub enum GetDeployedContractAbiError {
333    DefaultResponse(models::ErrorSchema),
334    UnknownValue(serde_json::Value),
335}
336
337/// struct for typed errors of method [`get_transaction_receipt`]
338#[derive(Debug, Clone, Serialize, Deserialize)]
339#[serde(untagged)]
340pub enum GetTransactionReceiptError {
341    DefaultResponse(models::ErrorSchema),
342    UnknownValue(serde_json::Value),
343}
344
345/// struct for typed errors of method [`read_call_function`]
346#[derive(Debug, Clone, Serialize, Deserialize)]
347#[serde(untagged)]
348pub enum ReadCallFunctionError {
349    DefaultResponse(models::ErrorSchema),
350    UnknownValue(serde_json::Value),
351}
352
353/// struct for typed errors of method [`write_call_function`]
354#[derive(Debug, Clone, Serialize, Deserialize)]
355#[serde(untagged)]
356pub enum WriteCallFunctionError {
357    DefaultResponse(models::ErrorSchema),
358    UnknownValue(serde_json::Value),
359}