dfns-sdk-rust 0.2.0

Dfns API SDK for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
// Code generated by rust-sdk-generator. DO NOT EDIT.

pub mod delegated;
pub mod types;

#[allow(unused_imports)]
use types::*;

/// Client for wallets operations.
#[derive(Clone)]
pub struct WalletsClient {
    client: crate::client::Client,
}

impl WalletsClient {
    pub fn new(client: crate::client::Client) -> Self {
        WalletsClient { client }
    }

    /// Aborts a transaction that is currently in 'Executing' status and has not yet been signed. Sets the transaction status to 'Failed' and removes it from the retry queue.
    ///
    ///   This is useful when a transaction is stuck in the execution pipeline (e.g., during construct or sign phase) and you want to abort it without waiting for it to fail on its own.
    ///
    pub async fn abort_transaction(
        &self,
        wallet_id: String,
        transaction_id: String,
    ) -> Result<AbortTransactionResponse, crate::error::Error> {
        let path = format!(
            "/wallets/{}/transactions/{}/abort",
            urlencoding::encode(&wallet_id),
            urlencoding::encode(&transaction_id)
        );
        self.client
            .request::<AbortTransactionResponse>(reqwest::Method::PUT, &path, None, true)
            .await
    }

    /// Aborts a transfer that is currently in 'Executing' status and has not yet been signed. Sets the transfer status to 'Failed' and removes it from the retry queue.
    ///
    ///   This is useful when a transfer is stuck in the execution pipeline (e.g., during construct or sign phase) and you want to abort it without waiting for it to fail on its own.
    ///
    pub async fn abort_transfer(
        &self,
        wallet_id: String,
        transfer_id: String,
    ) -> Result<AbortTransferResponse, crate::error::Error> {
        let path = format!(
            "/wallets/{}/transfers/{}/abort",
            urlencoding::encode(&wallet_id),
            urlencoding::encode(&transfer_id)
        );
        self.client
            .request::<AbortTransferResponse>(reqwest::Method::PUT, &path, None, true)
            .await
    }

    /// Activates a wallet by deploying the account contract on-chain, making it ready for transactions.
    ///
    ///     This operation is required for wallets on networks where you need to explicitly activate your account on-chain
    ///     before it can be used for transactions.
    pub async fn activate_wallet(
        &self,
        wallet_id: String,
        body: ActivateWalletRequest,
    ) -> Result<ActivateWalletResponse, crate::error::Error> {
        let path = format!("/wallets/{}/activate", urlencoding::encode(&wallet_id));
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<ActivateWalletResponse>(reqwest::Method::POST, &path, Some(&body), true)
            .await
    }

    /// Retrieves a list of transactions requests for the specified wallet.
    pub async fn list_transactions(
        &self,
        wallet_id: String,
        query: Option<ListTransactionsQuery>,
    ) -> Result<ListTransactionsResponse, crate::error::Error> {
        let mut path = format!("/wallets/{}/transactions", urlencoding::encode(&wallet_id));
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            if let Some(v) = &query.limit {
                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.pagination_token {
                q.push(format!(
                    "paginationToken={}",
                    urlencoding::encode(&v.to_string())
                ));
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<ListTransactionsResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Sign & Broadcast transaction enables communication with any arbitrary smart contract of the target blockchain. You can construct a transaction that performs a complex task and this endpoint will sign the transaction, add the signature and broadcast it to chain. It can be used to call smart contract functions like mint tokens and even deploy new smart contracts.
    ///
    /// | Status      | Definition                                                                                                                                      |
    /// |-------------|-------------------------------------------------------------------------------------------------------------------------------------------------|
    pub async fn sign_and_broadcast_transaction(
        &self,
        wallet_id: String,
        body: SignAndBroadcastTransactionRequest,
    ) -> Result<SignAndBroadcastTransactionResponse, crate::error::Error> {
        let path = format!("/wallets/{}/transactions", urlencoding::encode(&wallet_id));
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<SignAndBroadcastTransactionResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                true,
            )
            .await
    }

    /// Cancels an EVM transaction by creating a replacement transaction with the same nonce. The new transaction sends 0 value to the same address, effectively nullifying the original transaction.
    ///   
    ///   This endpoint works for:
    ///   - EVM-compatible networks (Ethereum, Polygon, BSC, etc.)
    pub async fn cancel_transaction(
        &self,
        wallet_id: String,
        transaction_id: String,
    ) -> Result<CancelTransactionResponse, crate::error::Error> {
        let path = format!(
            "/wallets/{}/transactions/{}/cancel",
            urlencoding::encode(&wallet_id),
            urlencoding::encode(&transaction_id)
        );
        self.client
            .request::<CancelTransactionResponse>(reqwest::Method::POST, &path, None, true)
            .await
    }

    /// Cancels an EVM transfer by creating a replacement transaction with the same nonce. The new transaction sends 0 value to the same address, effectively nullifying the original transfer.
    ///   
    ///   This endpoint works for:
    ///   - EVM-compatible networks (Ethereum, Polygon, BSC, etc.)
    pub async fn cancel_transfer(
        &self,
        wallet_id: String,
        transfer_id: String,
    ) -> Result<CancelTransferResponse, crate::error::Error> {
        let path = format!(
            "/wallets/{}/transfers/{}/cancel",
            urlencoding::encode(&wallet_id),
            urlencoding::encode(&transfer_id)
        );
        self.client
            .request::<CancelTransferResponse>(reqwest::Method::POST, &path, None, true)
            .await
    }

    /// Proxies a request to the Canton Ledger API associated with this wallet, using the validator's OAuth2 credentials. Restricted to a curated allow-list of read-style resources. Used to satisfy the Canton WalletConnect `canton_ledgerApi` method.
    pub async fn proxy_arequest_to_the_canton_ledger_api(
        &self,
        wallet_id: String,
        body: ProxyARequestToTheCantonLedgerApiRequest,
    ) -> Result<serde_json::Value, crate::error::Error> {
        let path = format!(
            "/wallets/{}/canton/ledger-api",
            urlencoding::encode(&wallet_id)
        );
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<serde_json::Value>(reqwest::Method::POST, &path, Some(&body), false)
            .await
    }

    /// Speeds up a transaction by creating a replacement transaction with the same parameters but higher gas fees.
    ///   
    ///   This endpoint only works for:
    ///   - EVM-compatible networks (Ethereum, Polygon, BSC, etc.)
    pub async fn speed_up_transaction(
        &self,
        wallet_id: String,
        transaction_id: String,
    ) -> Result<SpeedUpTransactionResponse, crate::error::Error> {
        let path = format!(
            "/wallets/{}/transactions/{}/speed-up",
            urlencoding::encode(&wallet_id),
            urlencoding::encode(&transaction_id)
        );
        self.client
            .request::<SpeedUpTransactionResponse>(reqwest::Method::POST, &path, None, true)
            .await
    }

    /// Speeds up a transfer by creating a replacement transaction with the same parameters but higher gas fees.
    ///   
    ///   This endpoint only works for:
    ///   - EVM-compatible networks (Ethereum, Polygon, BSC, etc.)
    pub async fn speed_up_transfer(
        &self,
        wallet_id: String,
        transfer_id: String,
    ) -> Result<SpeedUpTransferResponse, crate::error::Error> {
        let path = format!(
            "/wallets/{}/transfers/{}/speed-up",
            urlencoding::encode(&wallet_id),
            urlencoding::encode(&transfer_id)
        );
        self.client
            .request::<SpeedUpTransferResponse>(reqwest::Method::POST, &path, None, true)
            .await
    }

    /// Retrieves the list of Wallets in your organization. You can filter the results by owner (either by owner id or owner username). Pagination is supported via limit and paginationToken parameters.
    pub async fn list_wallets(
        &self,
        query: Option<ListWalletsQuery>,
    ) -> Result<ListWalletsResponse, crate::error::Error> {
        let mut path = String::from("/wallets");
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            if let Some(v) = &query.limit {
                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.pagination_token {
                q.push(format!(
                    "paginationToken={}",
                    urlencoding::encode(&v.to_string())
                ));
            }
            if let Some(v) = &query.owner {
                q.push(format!("owner={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.owner_id {
                q.push(format!("ownerId={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.owner_username {
                q.push(format!(
                    "ownerUsername={}",
                    urlencoding::encode(&v.to_string())
                ));
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<ListWalletsResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Creates a new Wallet associated with the given chain (such as Bitcoin or Ethereum ). Returns a new wallet entity.
    pub async fn create_wallet(
        &self,
        body: CreateWalletRequest,
    ) -> Result<CreateWalletResponse, crate::error::Error> {
        let path = String::from("/wallets");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateWalletResponse>(reqwest::Method::POST, &path, Some(&body), true)
            .await
    }

    /// Retrieve information about a specific transaction.
    pub async fn get_transaction(
        &self,
        wallet_id: String,
        transaction_id: String,
    ) -> Result<GetTransactionResponse, crate::error::Error> {
        let path = format!(
            "/wallets/{}/transactions/{}",
            urlencoding::encode(&wallet_id),
            urlencoding::encode(&transaction_id)
        );
        self.client
            .request::<GetTransactionResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Retrieves a Wallet Transfer Request by its ID.
    pub async fn get_transfer(
        &self,
        wallet_id: String,
        transfer_id: String,
    ) -> Result<GetTransferResponse, crate::error::Error> {
        let path = format!(
            "/wallets/{}/transfers/{}",
            urlencoding::encode(&wallet_id),
            urlencoding::encode(&transfer_id)
        );
        self.client
            .request::<GetTransferResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Retrieves a Wallet information by its ID.
    pub async fn get_wallet(
        &self,
        wallet_id: String,
    ) -> Result<GetWalletResponse, crate::error::Error> {
        let path = format!("/wallets/{}", urlencoding::encode(&wallet_id));
        self.client
            .request::<GetWalletResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Updates the name of an existing wallet.
    pub async fn update_wallet(
        &self,
        wallet_id: String,
        body: UpdateWalletRequest,
    ) -> Result<UpdateWalletResponse, crate::error::Error> {
        let path = format!("/wallets/{}", urlencoding::encode(&wallet_id));
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<UpdateWalletResponse>(reqwest::Method::PUT, &path, Some(&body), true)
            .await
    }

    /// Retrieves a list of assets owned by the specified wallet.  Return values vary by chain as shown below.
    pub async fn get_wallet_assets(
        &self,
        wallet_id: String,
        query: Option<GetWalletAssetsQuery>,
    ) -> Result<GetWalletAssetsResponse, crate::error::Error> {
        let mut path = format!("/wallets/{}/assets", urlencoding::encode(&wallet_id));
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            if let Some(v) = &query.net_worth {
                q.push(format!("netWorth={}", urlencoding::encode(&v.to_string())));
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<GetWalletAssetsResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Retrieves a list of historical on chain activities for the specified wallet.
    ///
    /// The list reflects the indexed on-chain activity: it includes confirmed transactions only.
    ///
    pub async fn get_wallet_history(
        &self,
        wallet_id: String,
        query: Option<GetWalletHistoryQuery>,
    ) -> Result<GetWalletHistoryResponse, crate::error::Error> {
        let mut path = format!("/wallets/{}/history", urlencoding::encode(&wallet_id));
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            if let Some(v) = &query.limit {
                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.pagination_token {
                q.push(format!(
                    "paginationToken={}",
                    urlencoding::encode(&v.to_string())
                ));
            }
            if let Some(v) = &query.direction {
                q.push(format!("direction={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.kind {
                q.push(format!("kind={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.contract {
                q.push(format!("contract={}", urlencoding::encode(&v.to_string())));
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<GetWalletHistoryResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Retrieves a list of NFTs owned by the specified Wallet.
    pub async fn get_wallet_nfts(
        &self,
        wallet_id: String,
    ) -> Result<GetWalletNftsResponse, crate::error::Error> {
        let path = format!("/wallets/{}/nfts", urlencoding::encode(&wallet_id));
        self.client
            .request::<GetWalletNftsResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// <Warning>
    /// This endpoint is not enabled by default. [Contact Dfns](https://support.dfns.co) to have it activated.
    /// </Warning>
    ///
    pub async fn import_wallet(
        &self,
        body: ImportWalletRequest,
    ) -> Result<ImportWalletResponse, crate::error::Error> {
        let path = String::from("/wallets/import");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<ImportWalletResponse>(reqwest::Method::POST, &path, Some(&body), true)
            .await
    }

    /// Retrieves a list of transfer requests for the specified wallet.
    pub async fn list_transfers(
        &self,
        wallet_id: String,
        query: Option<ListTransfersQuery>,
    ) -> Result<ListTransfersResponse, crate::error::Error> {
        let mut path = format!("/wallets/{}/transfers", urlencoding::encode(&wallet_id));
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            if let Some(v) = &query.limit {
                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.pagination_token {
                q.push(format!(
                    "paginationToken={}",
                    urlencoding::encode(&v.to_string())
                ));
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<ListTransfersResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Transfer an asset out of the specified wallet to a destination address.
    /// For all fungible token transfers, the transfer amount must be specified in the minimum denomination of that token.
    /// For example, use the amount in Satoshi for a Bitcoin transfer, or the amount in Wei for an Ethereum transfer etc.
    ///
    pub async fn transfer_asset(
        &self,
        wallet_id: String,
        body: TransferAssetRequest,
    ) -> Result<TransferAssetResponse, crate::error::Error> {
        let path = format!("/wallets/{}/transfers", urlencoding::encode(&wallet_id));
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<TransferAssetResponse>(reqwest::Method::POST, &path, Some(&body), true)
            .await
    }

    /// Add a [Tag](https://docs.dfns.co/api-reference/wallets/tags) to a wallet.
    pub async fn tag_wallet(
        &self,
        wallet_id: String,
        body: TagWalletRequest,
    ) -> Result<TagWalletResponse, crate::error::Error> {
        let path = format!("/wallets/{}/tags", urlencoding::encode(&wallet_id));
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<TagWalletResponse>(reqwest::Method::PUT, &path, Some(&body), true)
            .await
    }

    /// Removes the specified tags from a wallet.
    pub async fn untag_wallet(
        &self,
        wallet_id: String,
        body: UntagWalletRequest,
    ) -> Result<UntagWalletResponse, crate::error::Error> {
        let path = format!("/wallets/{}/tags", urlencoding::encode(&wallet_id));
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<UntagWalletResponse>(reqwest::Method::DELETE, &path, Some(&body), true)
            .await
    }

    /// Retrieve information about a specific offer received on your wallet.
    pub async fn get_offer(
        &self,
        wallet_id: String,
        offer_id: String,
    ) -> Result<GetOfferResponse, crate::error::Error> {
        let path = format!(
            "/wallets/{}/offers/{}",
            urlencoding::encode(&wallet_id),
            urlencoding::encode(&offer_id)
        );
        self.client
            .request::<GetOfferResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// List all offers received on a specific wallet.
    pub async fn list_offers(
        &self,
        wallet_id: String,
        query: Option<ListOffersQuery>,
    ) -> Result<ListOffersResponse, crate::error::Error> {
        let mut path = format!("/wallets/{}/offers", urlencoding::encode(&wallet_id));
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            if let Some(v) = &query.limit {
                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.pagination_token {
                q.push(format!(
                    "paginationToken={}",
                    urlencoding::encode(&v.to_string())
                ));
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<ListOffersResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Accept an offer received on your wallet.
    pub async fn accept_offer(
        &self,
        wallet_id: String,
        offer_id: String,
    ) -> Result<AcceptOfferResponse, crate::error::Error> {
        let path = format!(
            "/wallets/{}/offers/{}/accept",
            urlencoding::encode(&wallet_id),
            urlencoding::encode(&offer_id)
        );
        self.client
            .request::<AcceptOfferResponse>(reqwest::Method::PUT, &path, None, true)
            .await
    }

    /// Reject an offer received on your wallet.
    pub async fn reject_offer(
        &self,
        wallet_id: String,
        offer_id: String,
    ) -> Result<RejectOfferResponse, crate::error::Error> {
        let path = format!(
            "/wallets/{}/offers/{}/reject",
            urlencoding::encode(&wallet_id),
            urlencoding::encode(&offer_id)
        );
        self.client
            .request::<RejectOfferResponse>(reqwest::Method::PUT, &path, None, true)
            .await
    }

    /// Retrieve the transaction history across all wallets within a specified timeframe. The time range is unbounded, but the CSV export is capped at 100,000 rows.
    pub async fn list_org_wallet_history(
        &self,
        query: Option<ListOrgWalletHistoryQuery>,
    ) -> Result<serde_json::Value, crate::error::Error> {
        let mut path = String::from("/wallets/all/history");
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            if let Some(v) = &query.limit {
                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.pagination_token {
                q.push(format!(
                    "paginationToken={}",
                    urlencoding::encode(&v.to_string())
                ));
            }
            q.push(format!(
                "startTime={}",
                urlencoding::encode(&query.start_time.to_string())
            ));
            q.push(format!(
                "endTime={}",
                urlencoding::encode(&query.end_time.to_string())
            ));
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<serde_json::Value>(reqwest::Method::GET, &path, None, false)
            .await
    }
}