Skip to main content

dfns_sdk_rust/vaults/
mod.rs

1// Code generated by rust-sdk-generator. DO NOT EDIT.
2
3pub mod delegated;
4pub mod types;
5
6#[allow(unused_imports)]
7use types::*;
8
9/// Client for vaults operations.
10#[derive(Clone)]
11pub struct VaultsClient {
12    client: crate::client::Client,
13}
14
15impl VaultsClient {
16    pub fn new(client: crate::client::Client) -> Self {
17        VaultsClient { client }
18    }
19
20    /// Retrieves the list of Vaults in your organization.
21    pub async fn list_vaults(
22        &self,
23        query: Option<ListVaultsQuery>,
24    ) -> Result<ListVaultsResponse, crate::error::Error> {
25        let mut path = String::from("/vaults");
26        if let Some(query) = &query {
27            let mut q: Vec<String> = Vec::new();
28            if let Some(v) = &query.limit {
29                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
30            }
31            if let Some(v) = &query.pagination_token {
32                q.push(format!(
33                    "paginationToken={}",
34                    urlencoding::encode(&v.to_string())
35                ));
36            }
37            if !q.is_empty() {
38                path.push('?');
39                path.push_str(&q.join("&"));
40            }
41        }
42        self.client
43            .request::<ListVaultsResponse>(reqwest::Method::GET, &path, None, false)
44            .await
45    }
46
47    /// Creates a new Vault.
48    pub async fn create_vault(
49        &self,
50        body: CreateVaultRequest,
51    ) -> Result<CreateVaultResponse, crate::error::Error> {
52        let path = String::from("/vaults");
53        let body = serde_json::to_value(&body)?;
54        self.client
55            .request::<CreateVaultResponse>(reqwest::Method::POST, &path, Some(&body), true)
56            .await
57    }
58
59    /// Creates a vault address (managed wallet) on an EVM or Bitcoin network.
60    pub async fn create_vault_address(
61        &self,
62        vault_id: String,
63        body: CreateVaultAddressRequest,
64    ) -> Result<CreateVaultAddressResponse, crate::error::Error> {
65        let path = format!("/vaults/{}/addresses", urlencoding::encode(&vault_id));
66        let body = serde_json::to_value(&body)?;
67        self.client
68            .request::<CreateVaultAddressResponse>(reqwest::Method::POST, &path, Some(&body), true)
69            .await
70    }
71
72    /// Lists a vault's locks, active and released.
73    pub async fn list_vault_locks(
74        &self,
75        vault_id: String,
76        query: Option<ListVaultLocksQuery>,
77    ) -> Result<ListVaultLocksResponse, crate::error::Error> {
78        let mut path = format!("/vaults/{}/locks", urlencoding::encode(&vault_id));
79        if let Some(query) = &query {
80            let mut q: Vec<String> = Vec::new();
81            if let Some(v) = &query.limit {
82                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
83            }
84            if let Some(v) = &query.pagination_token {
85                q.push(format!(
86                    "paginationToken={}",
87                    urlencoding::encode(&v.to_string())
88                ));
89            }
90            if let Some(v) = &query.network {
91                q.push(format!("network={}", urlencoding::encode(&v.to_string())));
92            }
93            if let Some(v) = &query.tid {
94                q.push(format!("tid={}", urlencoding::encode(&v.to_string())));
95            }
96            if !q.is_empty() {
97                path.push('?');
98                path.push_str(&q.join("&"));
99            }
100        }
101        self.client
102            .request::<ListVaultLocksResponse>(reqwest::Method::GET, &path, None, false)
103            .await
104    }
105
106    /// Locks funds from the vault's available balance for off-chain settlement or escrow.
107    pub async fn create_vault_lock(
108        &self,
109        vault_id: String,
110        body: CreateVaultLockRequest,
111    ) -> Result<CreateVaultLockResponse, crate::error::Error> {
112        let path = format!("/vaults/{}/locks", urlencoding::encode(&vault_id));
113        let body = serde_json::to_value(&body)?;
114        self.client
115            .request::<CreateVaultLockResponse>(reqwest::Method::POST, &path, Some(&body), true)
116            .await
117    }
118
119    /// Creates a transfer out of a vault, reserving the amount and estimated fee from the vault's available balance.
120    pub async fn create_vault_transfer(
121        &self,
122        vault_id: String,
123        body: CreateVaultTransferRequest,
124    ) -> Result<CreateVaultTransferResponse, crate::error::Error> {
125        let path = format!("/vaults/{}/transfers", urlencoding::encode(&vault_id));
126        let body = serde_json::to_value(&body)?;
127        self.client
128            .request::<CreateVaultTransferResponse>(reqwest::Method::POST, &path, Some(&body), true)
129            .await
130    }
131
132    /// Retrieves a vault lock by its ID.
133    pub async fn get_vault_lock(
134        &self,
135        vault_id: String,
136        lock_id: String,
137    ) -> Result<GetVaultLockResponse, crate::error::Error> {
138        let path = format!(
139            "/vaults/{}/locks/{}",
140            urlencoding::encode(&vault_id),
141            urlencoding::encode(&lock_id)
142        );
143        self.client
144            .request::<GetVaultLockResponse>(reqwest::Method::GET, &path, None, false)
145            .await
146    }
147
148    /// Releases a lock, returning the locked funds to the vault's available balance. Owner only.
149    pub async fn delete_vault_lock(
150        &self,
151        vault_id: String,
152        lock_id: String,
153    ) -> Result<DeleteVaultLockResponse, crate::error::Error> {
154        let path = format!(
155            "/vaults/{}/locks/{}",
156            urlencoding::encode(&vault_id),
157            urlencoding::encode(&lock_id)
158        );
159        self.client
160            .request::<DeleteVaultLockResponse>(reqwest::Method::DELETE, &path, None, true)
161            .await
162    }
163
164    /// Retrieves a Vault by its ID.
165    pub async fn get_vault(
166        &self,
167        vault_id: String,
168    ) -> Result<GetVaultResponse, crate::error::Error> {
169        let path = format!("/vaults/{}", urlencoding::encode(&vault_id));
170        self.client
171            .request::<GetVaultResponse>(reqwest::Method::GET, &path, None, false)
172            .await
173    }
174
175    /// Updates an existing Vault.
176    pub async fn update_vault(
177        &self,
178        vault_id: String,
179        body: UpdateVaultRequest,
180    ) -> Result<UpdateVaultResponse, crate::error::Error> {
181        let path = format!("/vaults/{}", urlencoding::encode(&vault_id));
182        let body = serde_json::to_value(&body)?;
183        self.client
184            .request::<UpdateVaultResponse>(reqwest::Method::PUT, &path, Some(&body), true)
185            .await
186    }
187
188    /// Lists a vault's assets with balances (available/quarantined/locked) and USD valuation.
189    pub async fn list_vault_assets(
190        &self,
191        vault_id: String,
192        query: Option<ListVaultAssetsQuery>,
193    ) -> Result<ListVaultAssetsResponse, crate::error::Error> {
194        let mut path = format!("/vaults/{}/assets", urlencoding::encode(&vault_id));
195        if let Some(query) = &query {
196            let mut q: Vec<String> = Vec::new();
197            if let Some(v) = &query.show_unverified {
198                q.push(format!(
199                    "showUnverified={}",
200                    urlencoding::encode(&v.to_string())
201                ));
202            }
203            if let Some(v) = &query.network {
204                q.push(format!("network={}", urlencoding::encode(&v.to_string())));
205            }
206            if !q.is_empty() {
207                path.push('?');
208                path.push_str(&q.join("&"));
209            }
210        }
211        self.client
212            .request::<ListVaultAssetsResponse>(reqwest::Method::GET, &path, None, false)
213            .await
214    }
215
216    /// Lists a vault's balance entries.
217    pub async fn list_vault_balances(
218        &self,
219        vault_id: String,
220        query: Option<ListVaultBalancesQuery>,
221    ) -> Result<ListVaultBalancesResponse, crate::error::Error> {
222        let mut path = format!("/vaults/{}/balances", urlencoding::encode(&vault_id));
223        if let Some(query) = &query {
224            let mut q: Vec<String> = Vec::new();
225            if let Some(v) = &query.limit {
226                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
227            }
228            if let Some(v) = &query.pagination_token {
229                q.push(format!(
230                    "paginationToken={}",
231                    urlencoding::encode(&v.to_string())
232                ));
233            }
234            if let Some(v) = &query.kind {
235                q.push(format!("kind={}", urlencoding::encode(&v.to_string())));
236            }
237            if let Some(v) = &query.network {
238                q.push(format!("network={}", urlencoding::encode(&v.to_string())));
239            }
240            if let Some(v) = &query.tid {
241                q.push(format!("tid={}", urlencoding::encode(&v.to_string())));
242            }
243            if !q.is_empty() {
244                path.push('?');
245                path.push_str(&q.join("&"));
246            }
247        }
248        self.client
249            .request::<ListVaultBalancesResponse>(reqwest::Method::GET, &path, None, false)
250            .await
251    }
252
253    /// Releases quarantined funds into the available balance.
254    pub async fn release_quarantine(
255        &self,
256        vault_id: String,
257        quarantine_id: String,
258        body: ReleaseQuarantineRequest,
259    ) -> Result<ReleaseQuarantineResponse, crate::error::Error> {
260        let path = format!(
261            "/vaults/{}/quarantines/{}/release",
262            urlencoding::encode(&vault_id),
263            urlencoding::encode(&quarantine_id)
264        );
265        let body = serde_json::to_value(&body)?;
266        self.client
267            .request::<ReleaseQuarantineResponse>(reqwest::Method::POST, &path, Some(&body), true)
268            .await
269    }
270
271    /// Add tags to a vault.
272    pub async fn tag_vault(
273        &self,
274        vault_id: String,
275        body: TagVaultRequest,
276    ) -> Result<TagVaultResponse, crate::error::Error> {
277        let path = format!("/vaults/{}/tags", urlencoding::encode(&vault_id));
278        let body = serde_json::to_value(&body)?;
279        self.client
280            .request::<TagVaultResponse>(reqwest::Method::PUT, &path, Some(&body), true)
281            .await
282    }
283
284    /// Removes the specified tags from a vault.
285    pub async fn untag_vault(
286        &self,
287        vault_id: String,
288        body: UntagVaultRequest,
289    ) -> Result<UntagVaultResponse, crate::error::Error> {
290        let path = format!("/vaults/{}/tags", urlencoding::encode(&vault_id));
291        let body = serde_json::to_value(&body)?;
292        self.client
293            .request::<UntagVaultResponse>(reqwest::Method::DELETE, &path, Some(&body), true)
294            .await
295    }
296}