Skip to main content

dfns_sdk_rust/vaults/
mod.rs

1// Code generated by rust-sdk-generator. DO NOT EDIT.
2
3pub mod types;
4
5#[allow(unused_imports)]
6use types::*;
7
8/// Client for vaults operations.
9#[derive(Clone)]
10pub struct VaultsClient {
11    client: crate::client::Client,
12}
13
14impl VaultsClient {
15    pub fn new(client: crate::client::Client) -> Self {
16        VaultsClient { client }
17    }
18
19    /// Retrieves the list of Vaults in your organization.
20    pub async fn list_vaults(
21        &self,
22        query: Option<ListVaultsQuery>,
23    ) -> Result<ListVaultsResponse, crate::error::Error> {
24        let mut path = String::from("/vaults");
25        if let Some(query) = &query {
26            let mut q: Vec<String> = Vec::new();
27            if let Some(v) = &query.limit {
28                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
29            }
30            if let Some(v) = &query.pagination_token {
31                q.push(format!(
32                    "paginationToken={}",
33                    urlencoding::encode(&v.to_string())
34                ));
35            }
36            if !q.is_empty() {
37                path.push('?');
38                path.push_str(&q.join("&"));
39            }
40        }
41        self.client
42            .request::<ListVaultsResponse>(reqwest::Method::GET, &path, None, false)
43            .await
44    }
45
46    /// Creates a new Vault.
47    pub async fn create_vault(
48        &self,
49        body: CreateVaultRequest,
50    ) -> Result<CreateVaultResponse, crate::error::Error> {
51        let path = String::from("/vaults");
52        let body = serde_json::to_value(&body)?;
53        self.client
54            .request::<CreateVaultResponse>(reqwest::Method::POST, &path, Some(&body), true)
55            .await
56    }
57
58    /// Creates a vault address (managed wallet) on an EVM or Bitcoin network.
59    pub async fn create_vault_address(
60        &self,
61        vault_id: String,
62        body: CreateVaultAddressRequest,
63    ) -> Result<CreateVaultAddressResponse, crate::error::Error> {
64        let path = format!("/vaults/{}/addresses", urlencoding::encode(&vault_id));
65        let body = serde_json::to_value(&body)?;
66        self.client
67            .request::<CreateVaultAddressResponse>(reqwest::Method::POST, &path, Some(&body), true)
68            .await
69    }
70
71    /// Creates a transfer out of a vault, reserving the amount and estimated fee from the vault's available balance.
72    pub async fn create_vault_transfer(
73        &self,
74        vault_id: String,
75        body: CreateVaultTransferRequest,
76    ) -> Result<CreateVaultTransferResponse, crate::error::Error> {
77        let path = format!("/vaults/{}/transfers", urlencoding::encode(&vault_id));
78        let body = serde_json::to_value(&body)?;
79        self.client
80            .request::<CreateVaultTransferResponse>(reqwest::Method::POST, &path, Some(&body), true)
81            .await
82    }
83
84    /// Retrieves a Vault by its ID.
85    pub async fn get_vault(
86        &self,
87        vault_id: String,
88    ) -> Result<GetVaultResponse, crate::error::Error> {
89        let path = format!("/vaults/{}", urlencoding::encode(&vault_id));
90        self.client
91            .request::<GetVaultResponse>(reqwest::Method::GET, &path, None, false)
92            .await
93    }
94
95    /// Updates an existing Vault.
96    pub async fn update_vault(
97        &self,
98        vault_id: String,
99        body: UpdateVaultRequest,
100    ) -> Result<UpdateVaultResponse, crate::error::Error> {
101        let path = format!("/vaults/{}", urlencoding::encode(&vault_id));
102        let body = serde_json::to_value(&body)?;
103        self.client
104            .request::<UpdateVaultResponse>(reqwest::Method::PUT, &path, Some(&body), true)
105            .await
106    }
107
108    /// Lists a vault's assets with balances (available/quarantined/locked) and USD valuation.
109    pub async fn list_vault_assets(
110        &self,
111        vault_id: String,
112        query: Option<ListVaultAssetsQuery>,
113    ) -> Result<ListVaultAssetsResponse, crate::error::Error> {
114        let mut path = format!("/vaults/{}/assets", urlencoding::encode(&vault_id));
115        if let Some(query) = &query {
116            let mut q: Vec<String> = Vec::new();
117            if let Some(v) = &query.show_unverified {
118                q.push(format!(
119                    "showUnverified={}",
120                    urlencoding::encode(&v.to_string())
121                ));
122            }
123            if let Some(v) = &query.network {
124                q.push(format!("network={}", urlencoding::encode(&v.to_string())));
125            }
126            if !q.is_empty() {
127                path.push('?');
128                path.push_str(&q.join("&"));
129            }
130        }
131        self.client
132            .request::<ListVaultAssetsResponse>(reqwest::Method::GET, &path, None, false)
133            .await
134    }
135
136    /// Lists a vault's balance entries.
137    pub async fn list_vault_balances(
138        &self,
139        vault_id: String,
140        query: Option<ListVaultBalancesQuery>,
141    ) -> Result<ListVaultBalancesResponse, crate::error::Error> {
142        let mut path = format!("/vaults/{}/balances", urlencoding::encode(&vault_id));
143        if let Some(query) = &query {
144            let mut q: Vec<String> = Vec::new();
145            if let Some(v) = &query.limit {
146                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
147            }
148            if let Some(v) = &query.pagination_token {
149                q.push(format!(
150                    "paginationToken={}",
151                    urlencoding::encode(&v.to_string())
152                ));
153            }
154            if let Some(v) = &query.kind {
155                q.push(format!("kind={}", urlencoding::encode(&v.to_string())));
156            }
157            if let Some(v) = &query.network {
158                q.push(format!("network={}", urlencoding::encode(&v.to_string())));
159            }
160            if let Some(v) = &query.tid {
161                q.push(format!("tid={}", urlencoding::encode(&v.to_string())));
162            }
163            if !q.is_empty() {
164                path.push('?');
165                path.push_str(&q.join("&"));
166            }
167        }
168        self.client
169            .request::<ListVaultBalancesResponse>(reqwest::Method::GET, &path, None, false)
170            .await
171    }
172
173    /// Releases quarantined funds into the available balance.
174    pub async fn release_quarantine(
175        &self,
176        vault_id: String,
177        quarantine_id: String,
178        body: ReleaseQuarantineRequest,
179    ) -> Result<ReleaseQuarantineResponse, crate::error::Error> {
180        let path = format!(
181            "/vaults/{}/quarantines/{}/release",
182            urlencoding::encode(&vault_id),
183            urlencoding::encode(&quarantine_id)
184        );
185        let body = serde_json::to_value(&body)?;
186        self.client
187            .request::<ReleaseQuarantineResponse>(reqwest::Method::POST, &path, Some(&body), true)
188            .await
189    }
190
191    /// Add tags to a vault.
192    pub async fn tag_vault(
193        &self,
194        vault_id: String,
195        body: TagVaultRequest,
196    ) -> Result<TagVaultResponse, crate::error::Error> {
197        let path = format!("/vaults/{}/tags", urlencoding::encode(&vault_id));
198        let body = serde_json::to_value(&body)?;
199        self.client
200            .request::<TagVaultResponse>(reqwest::Method::PUT, &path, Some(&body), true)
201            .await
202    }
203
204    /// Removes the specified tags from a vault.
205    pub async fn untag_vault(
206        &self,
207        vault_id: String,
208        body: UntagVaultRequest,
209    ) -> Result<UntagVaultResponse, crate::error::Error> {
210        let path = format!("/vaults/{}/tags", urlencoding::encode(&vault_id));
211        let body = serde_json::to_value(&body)?;
212        self.client
213            .request::<UntagVaultResponse>(reqwest::Method::DELETE, &path, Some(&body), true)
214            .await
215    }
216}