@@ -308,6 +308,68 @@ impl AccountBalance {
308
308
}
309
309
}
310
310
311
+ /// A type that describes what FVK components are known to the wallet for an account.
312
+ #[ derive( Clone , Copy , Debug ) ]
313
+ pub struct AccountSources < AccountId > {
314
+ account_id : AccountId ,
315
+ use_orchard : bool ,
316
+ use_sapling : bool ,
317
+ use_transparent : bool ,
318
+ }
319
+
320
+ impl < AccountId : Copy > AccountSources < AccountId > {
321
+ /// Constructs AccountSources from its constituent parts
322
+ pub fn new (
323
+ account_id : AccountId ,
324
+ use_orchard : bool ,
325
+ use_sapling : bool ,
326
+ use_transparent : bool ,
327
+ ) -> Self {
328
+ Self {
329
+ account_id,
330
+ use_orchard,
331
+ use_sapling,
332
+ use_transparent,
333
+ }
334
+ }
335
+
336
+ /// Returns the id for the account to which this metadata applies.
337
+ pub fn account_id ( & self ) -> AccountId {
338
+ self . account_id
339
+ }
340
+
341
+ /// Returns whether the account has an Orchard balance and spendability determination
342
+ /// capability.
343
+ pub fn use_orchard ( & self ) -> bool {
344
+ self . use_orchard
345
+ }
346
+
347
+ /// Returns whether the account has an Sapling balance and spendability determination
348
+ /// capability.
349
+ pub fn use_sapling ( & self ) -> bool {
350
+ self . use_sapling
351
+ }
352
+
353
+ /// Returns whether the account has a Transparent balance determination capability.
354
+ pub fn use_transparent ( & self ) -> bool {
355
+ self . use_transparent
356
+ }
357
+
358
+ /// Restricts the sources to be used to those for which the given [`UnifiedSpendingKey`]
359
+ /// provides a spending capability.
360
+ pub fn filter_with_usk ( & mut self , usk : & UnifiedSpendingKey ) {
361
+ self . use_orchard &= usk. has_orchard ( ) ;
362
+ self . use_sapling &= usk. has_sapling ( ) ;
363
+ self . use_transparent &= usk. has_transparent ( ) ;
364
+ }
365
+
366
+ /// Returns the [`UnifiedAddressRequest`] that will produce a [`UnifiedAddress`] having
367
+ /// receivers corresponding to the spending capabilities described by this value.
368
+ pub fn to_unified_address_request ( & self ) -> Option < UnifiedAddressRequest > {
369
+ UnifiedAddressRequest :: new ( self . use_orchard , self . use_sapling , self . use_transparent )
370
+ }
371
+ }
372
+
311
373
/// A polymorphic ratio type, usually used for rational numbers.
312
374
#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
313
375
pub struct Ratio < T > {
@@ -444,9 +506,8 @@ pub trait InputSource {
444
506
/// be included.
445
507
fn select_spendable_notes (
446
508
& self ,
447
- account : Self :: AccountId ,
509
+ inputs_from : AccountSources < Self :: AccountId > ,
448
510
target_value : NonNegativeAmount ,
449
- sources : & [ ShieldedProtocol ] ,
450
511
anchor_height : BlockHeight ,
451
512
exclude : & [ Self :: NoteRef ] ,
452
513
) -> Result < Vec < ReceivedNote < Self :: NoteRef , Note > > , Self :: Error > ;
@@ -606,7 +667,7 @@ pub trait WalletRead {
606
667
fn get_account_for_ufvk (
607
668
& self ,
608
669
ufvk : & UnifiedFullViewingKey ,
609
- ) -> Result < Option < Self :: AccountId > , Self :: Error > ;
670
+ ) -> Result < Option < AccountSources < Self :: AccountId > > , Self :: Error > ;
610
671
611
672
/// Returns the wallet balances and sync status for an account given the specified minimum
612
673
/// number of confirmations, or `Ok(None)` if the wallet has no balance data available.
@@ -1372,9 +1433,10 @@ pub mod testing {
1372
1433
} ;
1373
1434
1374
1435
use super :: {
1375
- chain:: CommitmentTreeRoot , scanning:: ScanRange , AccountBirthday , BlockMetadata ,
1376
- DecryptedTransaction , InputSource , NullifierQuery , ScannedBlock , SentTransaction ,
1377
- WalletCommitmentTrees , WalletRead , WalletSummary , WalletWrite , SAPLING_SHARD_HEIGHT ,
1436
+ chain:: CommitmentTreeRoot , scanning:: ScanRange , AccountBirthday , AccountSources ,
1437
+ BlockMetadata , DecryptedTransaction , InputSource , NullifierQuery , ScannedBlock ,
1438
+ SentTransaction , WalletCommitmentTrees , WalletRead , WalletSummary , WalletWrite ,
1439
+ SAPLING_SHARD_HEIGHT ,
1378
1440
} ;
1379
1441
1380
1442
#[ cfg( feature = "transparent-inputs" ) ]
@@ -1425,9 +1487,8 @@ pub mod testing {
1425
1487
1426
1488
fn select_spendable_notes (
1427
1489
& self ,
1428
- _account : Self :: AccountId ,
1490
+ _inputs_from : AccountSources < Self :: AccountId > ,
1429
1491
_target_value : NonNegativeAmount ,
1430
- _sources : & [ ShieldedProtocol ] ,
1431
1492
_anchor_height : BlockHeight ,
1432
1493
_exclude : & [ Self :: NoteRef ] ,
1433
1494
) -> Result < Vec < ReceivedNote < Self :: NoteRef , Note > > , Self :: Error > {
@@ -1523,7 +1584,7 @@ pub mod testing {
1523
1584
fn get_account_for_ufvk (
1524
1585
& self ,
1525
1586
_ufvk : & UnifiedFullViewingKey ,
1526
- ) -> Result < Option < Self :: AccountId > , Self :: Error > {
1587
+ ) -> Result < Option < AccountSources < Self :: AccountId > > , Self :: Error > {
1527
1588
Ok ( None )
1528
1589
}
1529
1590
0 commit comments