11use bdk_chain:: {
22 bitcoin:: { OutPoint , ScriptBuf , Transaction , Txid } ,
3- keychain:: WalletUpdate ,
43 local_chain:: { self , CheckPoint } ,
54 tx_graph:: { self , TxGraph } ,
65 Anchor , BlockId , ConfirmationHeightAnchor , ConfirmationTimeAnchor ,
@@ -15,7 +14,8 @@ use std::{
1514/// We assume that a block of this depth and deeper cannot be reorged.
1615const ASSUME_FINAL_DEPTH : u32 = 8 ;
1716
18- /// Represents an update fetched from an Electrum server, but excludes full transactions.
17+ /// Represents an update fetched from an Electrum server, but excludes full
18+ /// transactions.
1919///
2020/// To provide a complete update to [`TxGraph`], you'll need to call [`Self::missing_full_txs`] to
2121/// determine the full transactions missing from [`TxGraph`]. Then call [`Self::finalize`] to fetch
@@ -58,7 +58,7 @@ impl<K, A: Anchor> ElectrumUpdate<K, A> {
5858 client : & Client ,
5959 seen_at : Option < u64 > ,
6060 missing : Vec < Txid > ,
61- ) -> Result < WalletUpdate < K , A > , Error > {
61+ ) -> Result < ( TxGraph < A > , BTreeMap < K , u32 > , local_chain :: CheckPoint ) , Error > {
6262 let new_txs = client. batch_transaction_get ( & missing) ?;
6363 let mut graph_update = TxGraph :: < A > :: new ( new_txs) ;
6464 for ( txid, anchors) in self . graph_update {
@@ -69,14 +69,7 @@ impl<K, A: Anchor> ElectrumUpdate<K, A> {
6969 let _ = graph_update. insert_anchor ( txid, anchor) ;
7070 }
7171 }
72- Ok ( WalletUpdate {
73- last_active_indices : self . keychain_update ,
74- graph : graph_update,
75- chain : local_chain:: Update {
76- tip : self . new_tip ,
77- introduce_older_blocks : true ,
78- } ,
79- } )
72+ Ok ( ( graph_update, self . keychain_update , self . new_tip ) )
8073 }
8174}
8275
@@ -92,13 +85,19 @@ impl<K> ElectrumUpdate<K, ConfirmationHeightAnchor> {
9285 client : & Client ,
9386 seen_at : Option < u64 > ,
9487 missing : Vec < Txid > ,
95- ) -> Result < WalletUpdate < K , ConfirmationTimeAnchor > , Error > {
96- let update = self . finalize ( client, seen_at, missing) ?;
88+ ) -> Result <
89+ (
90+ TxGraph < ConfirmationTimeAnchor > ,
91+ BTreeMap < K , u32 > ,
92+ local_chain:: CheckPoint ,
93+ ) ,
94+ Error ,
95+ > {
96+ let ( graph, keychain_update, update_tip) = self . finalize ( client, seen_at, missing) ?;
9797
9898 let relevant_heights = {
9999 let mut visited_heights = HashSet :: new ( ) ;
100- update
101- . graph
100+ graph
102101 . all_anchors ( )
103102 . iter ( )
104103 . map ( |( a, _) | a. confirmation_height_upper_bound ( ) )
@@ -118,7 +117,7 @@ impl<K> ElectrumUpdate<K, ConfirmationHeightAnchor> {
118117 . collect :: < HashMap < u32 , u64 > > ( ) ;
119118
120119 let graph_changeset = {
121- let old_changeset = TxGraph :: default ( ) . apply_update ( update . graph . clone ( ) ) ;
120+ let old_changeset = TxGraph :: default ( ) . apply_update ( graph. clone ( ) ) ;
122121 tx_graph:: ChangeSet {
123122 txs : old_changeset. txs ,
124123 txouts : old_changeset. txouts ,
@@ -140,15 +139,10 @@ impl<K> ElectrumUpdate<K, ConfirmationHeightAnchor> {
140139 }
141140 } ;
142141
143- Ok ( WalletUpdate {
144- last_active_indices : update. last_active_indices ,
145- graph : {
146- let mut graph = TxGraph :: default ( ) ;
147- graph. apply_changeset ( graph_changeset) ;
148- graph
149- } ,
150- chain : update. chain ,
151- } )
142+ let mut update = TxGraph :: default ( ) ;
143+ update. apply_changeset ( graph_changeset) ;
144+
145+ Ok ( ( update, keychain_update, update_tip) )
152146 }
153147}
154148
@@ -457,7 +451,6 @@ fn populate_with_outpoints<K>(
457451 } ;
458452
459453 let anchor = determine_tx_anchor ( cps, res. height , res. tx_hash ) ;
460-
461454 let tx_entry = update. graph_update . entry ( res. tx_hash ) . or_default ( ) ;
462455 if let Some ( anchor) = anchor {
463456 tx_entry. insert ( anchor) ;
0 commit comments