@@ -23,7 +23,7 @@ pub use bdk_chain::keychain::Balance;
23
23
use bdk_chain:: {
24
24
indexed_tx_graph:: IndexedAdditions ,
25
25
keychain:: { KeychainTxOutIndex , LocalChangeSet , LocalUpdate } ,
26
- local_chain:: { self , LocalChain , UpdateNotConnectedError } ,
26
+ local_chain:: { self , CannotConnectError , CheckPoint , CheckPointIter , LocalChain } ,
27
27
tx_graph:: { CanonicalTx , TxGraph } ,
28
28
Append , BlockId , ChainPosition , ConfirmationTime , ConfirmationTimeAnchor , FullTxOut ,
29
29
IndexedTxGraph , Persist , PersistBackend ,
@@ -32,8 +32,8 @@ use bitcoin::consensus::encode::serialize;
32
32
use bitcoin:: secp256k1:: Secp256k1 ;
33
33
use bitcoin:: util:: psbt;
34
34
use bitcoin:: {
35
- Address , BlockHash , EcdsaSighashType , LockTime , Network , OutPoint , SchnorrSighashType , Script ,
36
- Sequence , Transaction , TxOut , Txid , Witness ,
35
+ Address , EcdsaSighashType , LockTime , Network , OutPoint , SchnorrSighashType , Script , Sequence ,
36
+ Transaction , TxOut , Txid , Witness ,
37
37
} ;
38
38
use core:: fmt;
39
39
use core:: ops:: Deref ;
@@ -245,7 +245,7 @@ impl<D> Wallet<D> {
245
245
} ;
246
246
247
247
let changeset = db. load_from_persistence ( ) . map_err ( NewError :: Persist ) ?;
248
- chain. apply_changeset ( changeset. chain_changeset ) ;
248
+ chain. apply_changeset ( & changeset. chain_changeset ) ;
249
249
indexed_graph. apply_additions ( changeset. indexed_additions ) ;
250
250
251
251
let persist = Persist :: new ( db) ;
@@ -370,19 +370,19 @@ impl<D> Wallet<D> {
370
370
. graph ( )
371
371
. filter_chain_unspents (
372
372
& self . chain ,
373
- self . chain . tip ( ) . unwrap_or_default ( ) ,
373
+ self . chain . tip ( ) . map ( |cp| cp . block_id ( ) ) . unwrap_or_default ( ) ,
374
374
self . indexed_graph . index . outpoints ( ) . iter ( ) . cloned ( ) ,
375
375
)
376
376
. map ( |( ( k, i) , full_txo) | new_local_utxo ( k, i, full_txo) )
377
377
}
378
378
379
379
/// Get all the checkpoints the wallet is currently storing indexed by height.
380
- pub fn checkpoints ( & self ) -> & BTreeMap < u32 , BlockHash > {
381
- self . chain . blocks ( )
380
+ pub fn checkpoints ( & self ) -> CheckPointIter {
381
+ self . chain . iter_checkpoints ( )
382
382
}
383
383
384
384
/// Returns the latest checkpoint.
385
- pub fn latest_checkpoint ( & self ) -> Option < BlockId > {
385
+ pub fn latest_checkpoint ( & self ) -> Option < CheckPoint > {
386
386
self . chain . tip ( )
387
387
}
388
388
@@ -420,7 +420,7 @@ impl<D> Wallet<D> {
420
420
. graph ( )
421
421
. filter_chain_unspents (
422
422
& self . chain ,
423
- self . chain . tip ( ) . unwrap_or_default ( ) ,
423
+ self . chain . tip ( ) . map ( |cp| cp . block_id ( ) ) . unwrap_or_default ( ) ,
424
424
core:: iter:: once ( ( spk_i, op) ) ,
425
425
)
426
426
. map ( |( ( k, i) , full_txo) | new_local_utxo ( k, i, full_txo) )
@@ -437,7 +437,7 @@ impl<D> Wallet<D> {
437
437
let canonical_tx = CanonicalTx {
438
438
observed_as : graph. get_chain_position (
439
439
& self . chain ,
440
- self . chain . tip ( ) . unwrap_or_default ( ) ,
440
+ self . chain . tip ( ) . map ( |cp| cp . block_id ( ) ) . unwrap_or_default ( ) ,
441
441
txid,
442
442
) ?,
443
443
node : graph. get_tx_node ( txid) ?,
@@ -460,7 +460,7 @@ impl<D> Wallet<D> {
460
460
pub fn insert_checkpoint (
461
461
& mut self ,
462
462
block_id : BlockId ,
463
- ) -> Result < bool , local_chain:: InsertBlockNotMatchingError >
463
+ ) -> Result < bool , local_chain:: InsertBlockError >
464
464
where
465
465
D : PersistBackend < ChangeSet > ,
466
466
{
@@ -500,17 +500,17 @@ impl<D> Wallet<D> {
500
500
// anchor tx to checkpoint with lowest height that is >= position's height
501
501
let anchor = self
502
502
. chain
503
- . blocks ( )
503
+ . heights ( )
504
504
. range ( height..)
505
505
. next ( )
506
506
. ok_or ( InsertTxError :: ConfirmationHeightCannotBeGreaterThanTip {
507
- tip_height : self . chain . tip ( ) . map ( |b| b. height ) ,
507
+ tip_height : self . chain . tip ( ) . map ( |b| b. height ( ) ) ,
508
508
tx_height : height,
509
509
} )
510
- . map ( |( & anchor_height, & anchor_hash ) | ConfirmationTimeAnchor {
510
+ . map ( |( & anchor_height, & hash ) | ConfirmationTimeAnchor {
511
511
anchor_block : BlockId {
512
512
height : anchor_height,
513
- hash : anchor_hash ,
513
+ hash,
514
514
} ,
515
515
confirmation_height : height,
516
516
confirmation_time : time,
@@ -531,17 +531,18 @@ impl<D> Wallet<D> {
531
531
pub fn transactions (
532
532
& self ,
533
533
) -> impl Iterator < Item = CanonicalTx < ' _ , Transaction , ConfirmationTimeAnchor > > + ' _ {
534
- self . indexed_graph
535
- . graph ( )
536
- . list_chain_txs ( & self . chain , self . chain . tip ( ) . unwrap_or_default ( ) )
534
+ self . indexed_graph . graph ( ) . list_chain_txs (
535
+ & self . chain ,
536
+ self . chain . tip ( ) . map ( |cp| cp. block_id ( ) ) . unwrap_or_default ( ) ,
537
+ )
537
538
}
538
539
539
540
/// Return the balance, separated into available, trusted-pending, untrusted-pending and immature
540
541
/// values.
541
542
pub fn get_balance ( & self ) -> Balance {
542
543
self . indexed_graph . graph ( ) . balance (
543
544
& self . chain ,
544
- self . chain . tip ( ) . unwrap_or_default ( ) ,
545
+ self . chain . tip ( ) . map ( |cp| cp . block_id ( ) ) . unwrap_or_default ( ) ,
545
546
self . indexed_graph . index . outpoints ( ) . iter ( ) . cloned ( ) ,
546
547
|& ( k, _) , _| k == KeychainKind :: Internal ,
547
548
)
@@ -715,8 +716,7 @@ impl<D> Wallet<D> {
715
716
None => self
716
717
. chain
717
718
. tip ( )
718
- . and_then ( |cp| cp. height . into ( ) )
719
- . map ( |height| LockTime :: from_height ( height) . expect ( "Invalid height" ) ) ,
719
+ . map ( |cp| LockTime :: from_height ( cp. height ( ) ) . expect ( "Invalid height" ) ) ,
720
720
h => h,
721
721
} ;
722
722
@@ -1030,7 +1030,7 @@ impl<D> Wallet<D> {
1030
1030
) -> Result < TxBuilder < ' _ , D , DefaultCoinSelectionAlgorithm , BumpFee > , Error > {
1031
1031
let graph = self . indexed_graph . graph ( ) ;
1032
1032
let txout_index = & self . indexed_graph . index ;
1033
- let chain_tip = self . chain . tip ( ) . unwrap_or_default ( ) ;
1033
+ let chain_tip = self . chain . tip ( ) . map ( |cp| cp . block_id ( ) ) . unwrap_or_default ( ) ;
1034
1034
1035
1035
let mut tx = graph
1036
1036
. get_tx ( txid)
@@ -1265,7 +1265,7 @@ impl<D> Wallet<D> {
1265
1265
psbt : & mut psbt:: PartiallySignedTransaction ,
1266
1266
sign_options : SignOptions ,
1267
1267
) -> Result < bool , Error > {
1268
- let chain_tip = self . chain . tip ( ) . unwrap_or_default ( ) ;
1268
+ let chain_tip = self . chain . tip ( ) . map ( |cp| cp . block_id ( ) ) . unwrap_or_default ( ) ;
1269
1269
1270
1270
let tx = & psbt. unsigned_tx ;
1271
1271
let mut finished = true ;
@@ -1288,7 +1288,7 @@ impl<D> Wallet<D> {
1288
1288
} ) ;
1289
1289
let current_height = sign_options
1290
1290
. assume_height
1291
- . or ( self . chain . tip ( ) . map ( |b| b. height ) ) ;
1291
+ . or ( self . chain . tip ( ) . map ( |b| b. height ( ) ) ) ;
1292
1292
1293
1293
debug ! (
1294
1294
"Input #{} - {}, using `confirmation_height` = {:?}, `current_height` = {:?}" ,
@@ -1433,7 +1433,7 @@ impl<D> Wallet<D> {
1433
1433
must_only_use_confirmed_tx : bool ,
1434
1434
current_height : Option < u32 > ,
1435
1435
) -> ( Vec < WeightedUtxo > , Vec < WeightedUtxo > ) {
1436
- let chain_tip = self . chain . tip ( ) . unwrap_or_default ( ) ;
1436
+ let chain_tip = self . chain . tip ( ) . map ( |cp| cp . block_id ( ) ) . unwrap_or_default ( ) ;
1437
1437
// must_spend <- manually selected utxos
1438
1438
// may_spend <- all other available utxos
1439
1439
let mut may_spend = self . get_available_utxos ( ) ;
@@ -1697,24 +1697,25 @@ impl<D> Wallet<D> {
1697
1697
}
1698
1698
1699
1699
/// Applies an update to the wallet and stages the changes (but does not [`commit`] them).
1700
- ///
1701
- /// This returns whether the `update` resulted in any changes.
1700
+ /// Returns whether the `update` resulted in any changes.
1702
1701
///
1703
1702
/// Usually you create an `update` by interacting with some blockchain data source and inserting
1704
1703
/// transactions related to your wallet into it.
1705
1704
///
1706
1705
/// [`commit`]: Self::commit
1707
- pub fn apply_update ( & mut self , update : Update ) -> Result < bool , UpdateNotConnectedError >
1706
+ pub fn apply_update ( & mut self , update : Update ) -> Result < bool , CannotConnectError >
1708
1707
where
1709
1708
D : PersistBackend < ChangeSet > ,
1710
1709
{
1711
- let mut changeset: ChangeSet = self . chain . apply_update ( update. chain ) ?. into ( ) ;
1710
+ let mut changeset = ChangeSet :: from ( self . chain . apply_update ( update. chain ) ?) ;
1712
1711
let ( _, index_additions) = self
1713
1712
. indexed_graph
1714
1713
. index
1715
1714
. reveal_to_target_multi ( & update. keychain ) ;
1716
1715
changeset. append ( ChangeSet :: from ( IndexedAdditions :: from ( index_additions) ) ) ;
1717
- changeset. append ( self . indexed_graph . apply_update ( update. graph ) . into ( ) ) ;
1716
+ changeset. append ( ChangeSet :: from (
1717
+ self . indexed_graph . apply_update ( update. graph ) ,
1718
+ ) ) ;
1718
1719
1719
1720
let changed = !changeset. is_empty ( ) ;
1720
1721
self . persist . stage ( changeset) ;
0 commit comments