@@ -23,7 +23,7 @@ pub use bdk_chain::keychain::Balance;
2323use bdk_chain:: {
2424 indexed_tx_graph:: IndexedAdditions ,
2525 keychain:: { KeychainTxOutIndex , LocalChangeSet , LocalUpdate } ,
26- local_chain:: { self , LocalChain , UpdateNotConnectedError } ,
26+ local_chain:: { self , CannotConnectError , CheckPoint , CheckPointIter , LocalChain } ,
2727 tx_graph:: { CanonicalTx , TxGraph } ,
2828 Append , BlockId , ChainPosition , ConfirmationTime , ConfirmationTimeAnchor , FullTxOut ,
2929 IndexedTxGraph , Persist , PersistBackend ,
@@ -32,8 +32,8 @@ use bitcoin::consensus::encode::serialize;
3232use bitcoin:: secp256k1:: Secp256k1 ;
3333use bitcoin:: util:: psbt;
3434use 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 ,
3737} ;
3838use core:: fmt;
3939use core:: ops:: Deref ;
@@ -245,7 +245,7 @@ impl<D> Wallet<D> {
245245 } ;
246246
247247 let changeset = db. load_from_persistence ( ) . map_err ( NewError :: Persist ) ?;
248- chain. apply_changeset ( changeset. chain_changeset ) ;
248+ chain. apply_changeset ( & changeset. chain_changeset ) ;
249249 indexed_graph. apply_additions ( changeset. indexed_additions ) ;
250250
251251 let persist = Persist :: new ( db) ;
@@ -370,19 +370,19 @@ impl<D> Wallet<D> {
370370 . graph ( )
371371 . filter_chain_unspents (
372372 & self . chain ,
373- self . chain . tip ( ) . unwrap_or_default ( ) ,
373+ self . chain . tip ( ) . map ( |cp| cp . block_id ( ) ) . unwrap_or_default ( ) ,
374374 self . indexed_graph . index . outpoints ( ) . iter ( ) . cloned ( ) ,
375375 )
376376 . map ( |( ( k, i) , full_txo) | new_local_utxo ( k, i, full_txo) )
377377 }
378378
379379 /// 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 ( None )
382382 }
383383
384384 /// Returns the latest checkpoint.
385- pub fn latest_checkpoint ( & self ) -> Option < BlockId > {
385+ pub fn latest_checkpoint ( & self ) -> Option < CheckPoint > {
386386 self . chain . tip ( )
387387 }
388388
@@ -420,7 +420,7 @@ impl<D> Wallet<D> {
420420 . graph ( )
421421 . filter_chain_unspents (
422422 & self . chain ,
423- self . chain . tip ( ) . unwrap_or_default ( ) ,
423+ self . chain . tip ( ) . map ( |cp| cp . block_id ( ) ) . unwrap_or_default ( ) ,
424424 core:: iter:: once ( ( spk_i, op) ) ,
425425 )
426426 . map ( |( ( k, i) , full_txo) | new_local_utxo ( k, i, full_txo) )
@@ -437,7 +437,7 @@ impl<D> Wallet<D> {
437437 let canonical_tx = CanonicalTx {
438438 observed_as : graph. get_chain_position (
439439 & self . chain ,
440- self . chain . tip ( ) . unwrap_or_default ( ) ,
440+ self . chain . tip ( ) . map ( |cp| cp . block_id ( ) ) . unwrap_or_default ( ) ,
441441 txid,
442442 ) ?,
443443 node : graph. get_tx_node ( txid) ?,
@@ -460,11 +460,11 @@ impl<D> Wallet<D> {
460460 pub fn insert_checkpoint (
461461 & mut self ,
462462 block_id : BlockId ,
463- ) -> Result < bool , local_chain:: InsertBlockNotMatchingError >
463+ ) -> Result < bool , local_chain:: InsertBlockError >
464464 where
465465 D : PersistBackend < ChangeSet > ,
466466 {
467- let changeset = self . chain . insert_block ( block_id) ?;
467+ let ( _ , changeset) = self . chain . get_or_insert ( block_id) ?;
468468 let changed = !changeset. is_empty ( ) ;
469469 self . persist . stage ( changeset. into ( ) ) ;
470470 Ok ( changed)
@@ -500,18 +500,15 @@ impl<D> Wallet<D> {
500500 // anchor tx to checkpoint with lowest height that is >= position's height
501501 let anchor = self
502502 . chain
503- . blocks ( )
503+ . checkpoints ( )
504504 . range ( height..)
505505 . next ( )
506506 . ok_or ( InsertTxError :: ConfirmationHeightCannotBeGreaterThanTip {
507- tip_height : self . chain . tip ( ) . map ( |b| b. height ) ,
507+ tip_height : self . chain . tip ( ) . map ( |b| b. height ( ) ) ,
508508 tx_height : height,
509509 } )
510- . map ( |( & anchor_height, & anchor_hash) | ConfirmationTimeAnchor {
511- anchor_block : BlockId {
512- height : anchor_height,
513- hash : anchor_hash,
514- } ,
510+ . map ( |( & _, cp) | ConfirmationTimeAnchor {
511+ anchor_block : cp. block_id ( ) ,
515512 confirmation_height : height,
516513 confirmation_time : time,
517514 } ) ?;
@@ -531,17 +528,18 @@ impl<D> Wallet<D> {
531528 pub fn transactions (
532529 & self ,
533530 ) -> impl Iterator < Item = CanonicalTx < ' _ , Transaction , ConfirmationTimeAnchor > > + ' _ {
534- self . indexed_graph
535- . graph ( )
536- . list_chain_txs ( & self . chain , self . chain . tip ( ) . unwrap_or_default ( ) )
531+ self . indexed_graph . graph ( ) . list_chain_txs (
532+ & self . chain ,
533+ self . chain . tip ( ) . map ( |cp| cp. block_id ( ) ) . unwrap_or_default ( ) ,
534+ )
537535 }
538536
539537 /// Return the balance, separated into available, trusted-pending, untrusted-pending and immature
540538 /// values.
541539 pub fn get_balance ( & self ) -> Balance {
542540 self . indexed_graph . graph ( ) . balance (
543541 & self . chain ,
544- self . chain . tip ( ) . unwrap_or_default ( ) ,
542+ self . chain . tip ( ) . map ( |cp| cp . block_id ( ) ) . unwrap_or_default ( ) ,
545543 self . indexed_graph . index . outpoints ( ) . iter ( ) . cloned ( ) ,
546544 |& ( k, _) , _| k == KeychainKind :: Internal ,
547545 )
@@ -715,8 +713,7 @@ impl<D> Wallet<D> {
715713 None => self
716714 . chain
717715 . tip ( )
718- . and_then ( |cp| cp. height . into ( ) )
719- . map ( |height| LockTime :: from_height ( height) . expect ( "Invalid height" ) ) ,
716+ . map ( |cp| LockTime :: from_height ( cp. height ( ) ) . expect ( "Invalid height" ) ) ,
720717 h => h,
721718 } ;
722719
@@ -1030,7 +1027,7 @@ impl<D> Wallet<D> {
10301027 ) -> Result < TxBuilder < ' _ , D , DefaultCoinSelectionAlgorithm , BumpFee > , Error > {
10311028 let graph = self . indexed_graph . graph ( ) ;
10321029 let txout_index = & self . indexed_graph . index ;
1033- let chain_tip = self . chain . tip ( ) . unwrap_or_default ( ) ;
1030+ let chain_tip = self . chain . tip ( ) . map ( |cp| cp . block_id ( ) ) . unwrap_or_default ( ) ;
10341031
10351032 let mut tx = graph
10361033 . get_tx ( txid)
@@ -1265,7 +1262,7 @@ impl<D> Wallet<D> {
12651262 psbt : & mut psbt:: PartiallySignedTransaction ,
12661263 sign_options : SignOptions ,
12671264 ) -> Result < bool , Error > {
1268- let chain_tip = self . chain . tip ( ) . unwrap_or_default ( ) ;
1265+ let chain_tip = self . chain . tip ( ) . map ( |cp| cp . block_id ( ) ) . unwrap_or_default ( ) ;
12691266
12701267 let tx = & psbt. unsigned_tx ;
12711268 let mut finished = true ;
@@ -1288,7 +1285,7 @@ impl<D> Wallet<D> {
12881285 } ) ;
12891286 let current_height = sign_options
12901287 . assume_height
1291- . or ( self . chain . tip ( ) . map ( |b| b. height ) ) ;
1288+ . or ( self . chain . tip ( ) . map ( |b| b. height ( ) ) ) ;
12921289
12931290 debug ! (
12941291 "Input #{} - {}, using `confirmation_height` = {:?}, `current_height` = {:?}" ,
@@ -1433,7 +1430,7 @@ impl<D> Wallet<D> {
14331430 must_only_use_confirmed_tx : bool ,
14341431 current_height : Option < u32 > ,
14351432 ) -> ( Vec < WeightedUtxo > , Vec < WeightedUtxo > ) {
1436- let chain_tip = self . chain . tip ( ) . unwrap_or_default ( ) ;
1433+ let chain_tip = self . chain . tip ( ) . map ( |cp| cp . block_id ( ) ) . unwrap_or_default ( ) ;
14371434 // must_spend <- manually selected utxos
14381435 // may_spend <- all other available utxos
14391436 let mut may_spend = self . get_available_utxos ( ) ;
@@ -1704,11 +1701,11 @@ impl<D> Wallet<D> {
17041701 /// transactions related to your wallet into it.
17051702 ///
17061703 /// [`commit`]: Self::commit
1707- pub fn apply_update ( & mut self , update : Update ) -> Result < bool , UpdateNotConnectedError >
1704+ pub fn apply_update ( & mut self , update : Update ) -> Result < bool , CannotConnectError >
17081705 where
17091706 D : PersistBackend < ChangeSet > ,
17101707 {
1711- let mut changeset: ChangeSet = self . chain . apply_update ( update. chain ) ? . into ( ) ;
1708+ let mut changeset = ChangeSet :: from ( self . chain . apply_update ( update. tip ) ? ) ;
17121709 let ( _, index_additions) = self
17131710 . indexed_graph
17141711 . index
0 commit comments