fireblocks_sdk/apis/
d_app_connections_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 DAppConnectionsApi: Send + Sync {
23    /// POST /connections/wc
24    ///
25    /// Initiate a new Web3 connection.  * Note: After this succeeds, make a request to `PUT /v1/connections/wc/{id}` (below) to approve or reject the new Web3 connection. Learn more about Fireblocks Wallet Link in the following [guide](https://developers.fireblocks.com/docs/web3-wallet-link). </br>Endpoint Permission: Admin, Non-Signing Admin.
26    async fn create(
27        &self,
28        params: CreateParams,
29    ) -> Result<models::CreateConnectionResponse, Error<CreateError>>;
30
31    /// GET /connections
32    ///
33    /// List all open Web3 connections. </br>Endpoint Permission: Admin,
34    /// Non-Signing Admin.
35    async fn get(
36        &self,
37        params: GetParams,
38    ) -> Result<models::GetConnectionsResponse, Error<GetError>>;
39
40    /// DELETE /connections/wc/{id}
41    ///
42    /// Remove an existing Web3 connection.  </br>Endpoint Permission: Admin,
43    /// Non-Signing Admin.
44    async fn remove(&self, params: RemoveParams) -> Result<(), Error<RemoveError>>;
45
46    /// PUT /connections/wc/{id}
47    ///
48    /// Submit a response to *approve* or *reject* an initiated Web3 connection.
49    /// * Note: This call is used to complete your `POST /v1/connections/wc/`
50    /// request. After this succeeds, your new Web3 connection is created and
51    /// functioning.  </br>Endpoint Permission: Admin, Non-Signing Admin.
52    async fn submit(&self, params: SubmitParams) -> Result<(), Error<SubmitError>>;
53}
54
55pub struct DAppConnectionsApiClient {
56    configuration: Arc<configuration::Configuration>,
57}
58
59impl DAppConnectionsApiClient {
60    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
61        Self { configuration }
62    }
63}
64
65/// struct for passing parameters to the method [`create`]
66#[derive(Clone, Debug)]
67#[cfg_attr(feature = "bon", derive(::bon::Builder))]
68pub struct CreateParams {
69    pub create_connection_request: models::CreateConnectionRequest,
70    /// A unique identifier for the request. If the request is sent multiple
71    /// times with the same idempotency key, the server will return the same
72    /// response as the first request. The idempotency key is valid for 24
73    /// hours.
74    pub idempotency_key: Option<String>,
75}
76
77/// struct for passing parameters to the method [`get`]
78#[derive(Clone, Debug)]
79#[cfg_attr(feature = "bon", derive(::bon::Builder))]
80pub struct GetParams {
81    /// List order (ascending or descending)
82    pub order: Option<String>,
83    /// Parsed filter object
84    pub filter: Option<models::GetFilterParameter>,
85    /// Property to sort Web3 connections by.
86    pub sort: Option<String>,
87    /// Amount of results to return in the next page.
88    pub page_size: Option<f64>,
89    /// Cursor to the next page
90    pub next: Option<String>,
91}
92
93/// struct for passing parameters to the method [`remove`]
94#[derive(Clone, Debug)]
95#[cfg_attr(feature = "bon", derive(::bon::Builder))]
96pub struct RemoveParams {
97    /// The ID of the existing Web3 connection to remove.
98    pub id: String,
99}
100
101/// struct for passing parameters to the method [`submit`]
102#[derive(Clone, Debug)]
103#[cfg_attr(feature = "bon", derive(::bon::Builder))]
104pub struct SubmitParams {
105    /// The ID of the initiated Web3 connection to approve.
106    pub id: String,
107    pub respond_to_connection_request: models::RespondToConnectionRequest,
108    /// A unique identifier for the request. If the request is sent multiple
109    /// times with the same idempotency key, the server will return the same
110    /// response as the first request. The idempotency key is valid for 24
111    /// hours.
112    pub idempotency_key: Option<String>,
113}
114
115#[async_trait]
116impl DAppConnectionsApi for DAppConnectionsApiClient {
117    /// Initiate a new Web3 connection.  * Note: After this succeeds, make a request to `PUT /v1/connections/wc/{id}` (below) to approve or reject the new Web3 connection. Learn more about Fireblocks Wallet Link in the following [guide](https://developers.fireblocks.com/docs/web3-wallet-link). </br>Endpoint Permission: Admin, Non-Signing Admin.
118    async fn create(
119        &self,
120        params: CreateParams,
121    ) -> Result<models::CreateConnectionResponse, Error<CreateError>> {
122        let CreateParams {
123            create_connection_request,
124            idempotency_key,
125        } = params;
126
127        let local_var_configuration = &self.configuration;
128
129        let local_var_client = &local_var_configuration.client;
130
131        let local_var_uri_str = format!("{}/connections/wc", local_var_configuration.base_path);
132        let mut local_var_req_builder =
133            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
134
135        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
136            local_var_req_builder = local_var_req_builder
137                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
138        }
139        if let Some(local_var_param_value) = idempotency_key {
140            local_var_req_builder =
141                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
142        }
143        local_var_req_builder = local_var_req_builder.json(&create_connection_request);
144
145        let local_var_req = local_var_req_builder.build()?;
146        let local_var_resp = local_var_client.execute(local_var_req).await?;
147
148        let local_var_status = local_var_resp.status();
149        let local_var_content_type = local_var_resp
150            .headers()
151            .get("content-type")
152            .and_then(|v| v.to_str().ok())
153            .unwrap_or("application/octet-stream");
154        let local_var_content_type = super::ContentType::from(local_var_content_type);
155        let local_var_content = local_var_resp.text().await?;
156
157        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
158            match local_var_content_type {
159                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
160                ContentType::Text => {
161                    return Err(Error::from(serde_json::Error::custom(
162                        "Received `text/plain` content type response that cannot be converted to \
163                         `models::CreateConnectionResponse`",
164                    )))
165                }
166                ContentType::Unsupported(local_var_unknown_type) => {
167                    return Err(Error::from(serde_json::Error::custom(format!(
168                        "Received `{local_var_unknown_type}` content type response that cannot be \
169                         converted to `models::CreateConnectionResponse`"
170                    ))))
171                }
172            }
173        } else {
174            let local_var_entity: Option<CreateError> =
175                serde_json::from_str(&local_var_content).ok();
176            let local_var_error = ResponseContent {
177                status: local_var_status,
178                content: local_var_content,
179                entity: local_var_entity,
180            };
181            Err(Error::ResponseError(local_var_error))
182        }
183    }
184
185    /// List all open Web3 connections. </br>Endpoint Permission: Admin,
186    /// Non-Signing Admin.
187    async fn get(
188        &self,
189        params: GetParams,
190    ) -> Result<models::GetConnectionsResponse, Error<GetError>> {
191        let GetParams {
192            order,
193            filter,
194            sort,
195            page_size,
196            next,
197        } = params;
198
199        let local_var_configuration = &self.configuration;
200
201        let local_var_client = &local_var_configuration.client;
202
203        let local_var_uri_str = format!("{}/connections", local_var_configuration.base_path);
204        let mut local_var_req_builder =
205            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
206
207        if let Some(ref local_var_str) = order {
208            local_var_req_builder =
209                local_var_req_builder.query(&[("order", &local_var_str.to_string())]);
210        }
211        if let Some(ref _local_var_str) = filter {
212            eprintln!("warning filter for dapp not available...skipping");
213            // local_var_req_builder = local_var_req_builder.query(&[("filter",
214            // &local_var_str.to_string())]);
215        }
216        if let Some(ref local_var_str) = sort {
217            local_var_req_builder =
218                local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
219        }
220        if let Some(ref local_var_str) = page_size {
221            local_var_req_builder =
222                local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
223        }
224        if let Some(ref local_var_str) = next {
225            local_var_req_builder =
226                local_var_req_builder.query(&[("next", &local_var_str.to_string())]);
227        }
228        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
229            local_var_req_builder = local_var_req_builder
230                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
231        }
232
233        let local_var_req = local_var_req_builder.build()?;
234        let local_var_resp = local_var_client.execute(local_var_req).await?;
235
236        let local_var_status = local_var_resp.status();
237        let local_var_content_type = local_var_resp
238            .headers()
239            .get("content-type")
240            .and_then(|v| v.to_str().ok())
241            .unwrap_or("application/octet-stream");
242        let local_var_content_type = super::ContentType::from(local_var_content_type);
243        let local_var_content = local_var_resp.text().await?;
244
245        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
246            match local_var_content_type {
247                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
248                ContentType::Text => {
249                    return Err(Error::from(serde_json::Error::custom(
250                        "Received `text/plain` content type response that cannot be converted to \
251                         `models::GetConnectionsResponse`",
252                    )))
253                }
254                ContentType::Unsupported(local_var_unknown_type) => {
255                    return Err(Error::from(serde_json::Error::custom(format!(
256                        "Received `{local_var_unknown_type}` content type response that cannot be \
257                         converted to `models::GetConnectionsResponse`"
258                    ))))
259                }
260            }
261        } else {
262            let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
263            let local_var_error = ResponseContent {
264                status: local_var_status,
265                content: local_var_content,
266                entity: local_var_entity,
267            };
268            Err(Error::ResponseError(local_var_error))
269        }
270    }
271
272    /// Remove an existing Web3 connection.  </br>Endpoint Permission: Admin,
273    /// Non-Signing Admin.
274    async fn remove(&self, params: RemoveParams) -> Result<(), Error<RemoveError>> {
275        let RemoveParams { id } = params;
276
277        let local_var_configuration = &self.configuration;
278
279        let local_var_client = &local_var_configuration.client;
280
281        let local_var_uri_str = format!(
282            "{}/connections/wc/{id}",
283            local_var_configuration.base_path,
284            id = crate::apis::urlencode(id)
285        );
286        let mut local_var_req_builder =
287            local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
288
289        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
290            local_var_req_builder = local_var_req_builder
291                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
292        }
293
294        let local_var_req = local_var_req_builder.build()?;
295        let local_var_resp = local_var_client.execute(local_var_req).await?;
296
297        let local_var_status = local_var_resp.status();
298        let local_var_content = local_var_resp.text().await?;
299
300        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
301            Ok(())
302        } else {
303            let local_var_entity: Option<RemoveError> =
304                serde_json::from_str(&local_var_content).ok();
305            let local_var_error = ResponseContent {
306                status: local_var_status,
307                content: local_var_content,
308                entity: local_var_entity,
309            };
310            Err(Error::ResponseError(local_var_error))
311        }
312    }
313
314    /// Submit a response to *approve* or *reject* an initiated Web3 connection.
315    /// * Note: This call is used to complete your `POST /v1/connections/wc/`
316    /// request. After this succeeds, your new Web3 connection is created and
317    /// functioning.  </br>Endpoint Permission: Admin, Non-Signing Admin.
318    async fn submit(&self, params: SubmitParams) -> Result<(), Error<SubmitError>> {
319        let SubmitParams {
320            id,
321            respond_to_connection_request,
322            idempotency_key,
323        } = params;
324
325        let local_var_configuration = &self.configuration;
326
327        let local_var_client = &local_var_configuration.client;
328
329        let local_var_uri_str = format!(
330            "{}/connections/wc/{id}",
331            local_var_configuration.base_path,
332            id = crate::apis::urlencode(id)
333        );
334        let mut local_var_req_builder =
335            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
336
337        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
338            local_var_req_builder = local_var_req_builder
339                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
340        }
341        if let Some(local_var_param_value) = idempotency_key {
342            local_var_req_builder =
343                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
344        }
345        local_var_req_builder = local_var_req_builder.json(&respond_to_connection_request);
346
347        let local_var_req = local_var_req_builder.build()?;
348        let local_var_resp = local_var_client.execute(local_var_req).await?;
349
350        let local_var_status = local_var_resp.status();
351        let local_var_content = local_var_resp.text().await?;
352
353        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
354            Ok(())
355        } else {
356            let local_var_entity: Option<SubmitError> =
357                serde_json::from_str(&local_var_content).ok();
358            let local_var_error = ResponseContent {
359                status: local_var_status,
360                content: local_var_content,
361                entity: local_var_entity,
362            };
363            Err(Error::ResponseError(local_var_error))
364        }
365    }
366}
367
368/// struct for typed errors of method [`create`]
369#[derive(Debug, Clone, Serialize, Deserialize)]
370#[serde(untagged)]
371pub enum CreateError {
372    Status400(),
373    Status500(),
374    UnknownValue(serde_json::Value),
375}
376
377/// struct for typed errors of method [`get`]
378#[derive(Debug, Clone, Serialize, Deserialize)]
379#[serde(untagged)]
380pub enum GetError {
381    Status400(),
382    Status500(),
383    UnknownValue(serde_json::Value),
384}
385
386/// struct for typed errors of method [`remove`]
387#[derive(Debug, Clone, Serialize, Deserialize)]
388#[serde(untagged)]
389pub enum RemoveError {
390    Status404(),
391    Status500(),
392    UnknownValue(serde_json::Value),
393}
394
395/// struct for typed errors of method [`submit`]
396#[derive(Debug, Clone, Serialize, Deserialize)]
397#[serde(untagged)]
398pub enum SubmitError {
399    Status400(),
400    Status404(),
401    Status500(),
402    UnknownValue(serde_json::Value),
403}