@@ -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 ( )
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,7 +460,7 @@ 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 {
@@ -500,17 +500,17 @@ 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+ . heights ( )
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 {
510+ . map ( |( & anchor_height, & hash ) | ConfirmationTimeAnchor {
511511 anchor_block : BlockId {
512512 height : anchor_height,
513- hash : anchor_hash ,
513+ hash,
514514 } ,
515515 confirmation_height : height,
516516 confirmation_time : time,
@@ -531,17 +531,18 @@ impl<D> Wallet<D> {
531531 pub fn transactions (
532532 & self ,
533533 ) -> 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+ )
537538 }
538539
539540 /// Return the balance, separated into available, trusted-pending, untrusted-pending and immature
540541 /// values.
541542 pub fn get_balance ( & self ) -> Balance {
542543 self . indexed_graph . graph ( ) . balance (
543544 & self . chain ,
544- self . chain . tip ( ) . unwrap_or_default ( ) ,
545+ self . chain . tip ( ) . map ( |cp| cp . block_id ( ) ) . unwrap_or_default ( ) ,
545546 self . indexed_graph . index . outpoints ( ) . iter ( ) . cloned ( ) ,
546547 |& ( k, _) , _| k == KeychainKind :: Internal ,
547548 )
@@ -715,8 +716,7 @@ impl<D> Wallet<D> {
715716 None => self
716717 . chain
717718 . 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" ) ) ,
720720 h => h,
721721 } ;
722722
@@ -1030,7 +1030,7 @@ impl<D> Wallet<D> {
10301030 ) -> Result < TxBuilder < ' _ , D , DefaultCoinSelectionAlgorithm , BumpFee > , Error > {
10311031 let graph = self . indexed_graph . graph ( ) ;
10321032 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 ( ) ;
10341034
10351035 let mut tx = graph
10361036 . get_tx ( txid)
@@ -1265,7 +1265,7 @@ impl<D> Wallet<D> {
12651265 psbt : & mut psbt:: PartiallySignedTransaction ,
12661266 sign_options : SignOptions ,
12671267 ) -> 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 ( ) ;
12691269
12701270 let tx = & psbt. unsigned_tx ;
12711271 let mut finished = true ;
@@ -1288,7 +1288,7 @@ impl<D> Wallet<D> {
12881288 } ) ;
12891289 let current_height = sign_options
12901290 . assume_height
1291- . or ( self . chain . tip ( ) . map ( |b| b. height ) ) ;
1291+ . or ( self . chain . tip ( ) . map ( |b| b. height ( ) ) ) ;
12921292
12931293 debug ! (
12941294 "Input #{} - {}, using `confirmation_height` = {:?}, `current_height` = {:?}" ,
@@ -1433,7 +1433,7 @@ impl<D> Wallet<D> {
14331433 must_only_use_confirmed_tx : bool ,
14341434 current_height : Option < u32 > ,
14351435 ) -> ( 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 ( ) ;
14371437 // must_spend <- manually selected utxos
14381438 // may_spend <- all other available utxos
14391439 let mut may_spend = self . get_available_utxos ( ) ;
@@ -1697,24 +1697,25 @@ impl<D> Wallet<D> {
16971697 }
16981698
16991699 /// 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.
17021701 ///
17031702 /// Usually you create an `update` by interacting with some blockchain data source and inserting
17041703 /// transactions related to your wallet into it.
17051704 ///
17061705 /// [`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 >
17081707 where
17091708 D : PersistBackend < ChangeSet > ,
17101709 {
1711- let mut changeset: ChangeSet = self . chain . apply_update ( update. chain ) ?. into ( ) ;
1710+ let mut changeset = ChangeSet :: from ( self . chain . apply_update ( update. chain ) ?) ;
17121711 let ( _, index_additions) = self
17131712 . indexed_graph
17141713 . index
17151714 . reveal_to_target_multi ( & update. keychain ) ;
17161715 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+ ) ) ;
17181719
17191720 let changed = !changeset. is_empty ( ) ;
17201721 self . persist . stage ( changeset) ;
0 commit comments