@@ -80,15 +80,22 @@ where
8080
8181 let mut locked_last_sync_height = self . last_sync_height . lock ( ) . unwrap ( ) ;
8282 if cur_height >= locked_last_sync_height. unwrap_or ( 0 ) {
83- self . sync_best_block_updated ( confirmables. clone ( ) , cur_height, & mut locked_last_sync_height) ?;
83+ self . sync_best_block_updated (
84+ confirmables. clone ( ) ,
85+ cur_height,
86+ & mut locked_last_sync_height,
87+ ) ?;
8488 self . sync_transactions_confirmed ( confirmables. clone ( ) ) ?;
8589 self . sync_transaction_unconfirmed ( confirmables. clone ( ) ) ?;
8690 }
8791 // TODO: check whether new outputs have been registered by now and process them
8892 Ok ( ( ) )
8993 }
9094
91- fn sync_best_block_updated ( & self , confirmables : Vec < & ( dyn Confirm + Sync ) > , cur_height : u32 , locked_last_sync_height : & mut MutexGuard < Option < u32 > > ) -> Result < ( ) , Error > {
95+ fn sync_best_block_updated (
96+ & self , confirmables : Vec < & ( dyn Confirm + Sync ) > , cur_height : u32 ,
97+ locked_last_sync_height : & mut MutexGuard < Option < u32 > > ,
98+ ) -> Result < ( ) , Error > {
9299 let client = & * self . blockchain ;
93100
94101 // Inform the interface of the new block.
@@ -101,7 +108,9 @@ where
101108 Ok ( ( ) )
102109 }
103110
104- fn sync_transactions_confirmed ( & self , confirmables : Vec < & ( dyn Confirm + Sync ) > ) -> Result < ( ) , Error > {
111+ fn sync_transactions_confirmed (
112+ & self , confirmables : Vec < & ( dyn Confirm + Sync ) > ,
113+ ) -> Result < ( ) , Error > {
105114 let client = & * self . blockchain ;
106115
107116 // First, check the confirmation status of registered transactions as well as the
@@ -132,11 +141,11 @@ where
132141 let block_header = client. get_header ( block_height) ?;
133142 if let Some ( merkle_proof) = client. get_merkle_proof ( & txid) ? {
134143 confirmed_txs. push ( (
135- tx,
136- block_height,
137- block_header,
138- merkle_proof. pos ,
139- ) ) ;
144+ tx,
145+ block_height,
146+ block_header,
147+ merkle_proof. pos ,
148+ ) ) ;
140149 continue ;
141150 }
142151 }
@@ -147,42 +156,39 @@ where
147156 }
148157
149158 // Check all registered outputs for dependent spending transactions.
150- let registered_outputs: Vec < WatchedOutput > = locked_watched_outputs
151- . iter ( )
152- . chain ( locked_queued_outputs. iter ( ) )
153- . cloned ( )
154- . collect ( ) ;
159+ let registered_outputs: Vec < WatchedOutput > =
160+ locked_watched_outputs. iter ( ) . chain ( locked_queued_outputs. iter ( ) ) . cloned ( ) . collect ( ) ;
155161
156162 // Remember all registered outputs that haven't been spent for future processing.
157163 let mut unspent_registered_outputs = Vec :: new ( ) ;
158164
159165 for output in registered_outputs {
160- if let Some ( output_status) = client
161- . get_output_status ( & output. outpoint . txid , output. outpoint . index as u64 ) ?
162- {
163- if output_status. spent {
164- if let Some ( spending_tx_status) = output_status. status {
165- if spending_tx_status. confirmed {
166- let spending_txid = output_status. txid . unwrap ( ) ;
167- if let Some ( spending_tx) = client. get_tx ( & spending_txid) ? {
168- let block_height = spending_tx_status. block_height . unwrap ( ) ;
169- let block_header = client. get_header ( block_height) ?;
170- if let Some ( merkle_proof) =
171- client. get_merkle_proof ( & spending_txid) ?
172- {
173- confirmed_txs. push ( (
174- spending_tx,
175- block_height,
176- block_header,
177- merkle_proof. pos ,
178- ) ) ;
179- continue ;
180- }
166+ if let Some ( output_status) =
167+ client. get_output_status ( & output. outpoint . txid , output. outpoint . index as u64 ) ?
168+ {
169+ if output_status. spent {
170+ if let Some ( spending_tx_status) = output_status. status {
171+ if spending_tx_status. confirmed {
172+ let spending_txid = output_status. txid . unwrap ( ) ;
173+ if let Some ( spending_tx) = client. get_tx ( & spending_txid) ? {
174+ let block_height = spending_tx_status. block_height . unwrap ( ) ;
175+ let block_header = client. get_header ( block_height) ?;
176+ if let Some ( merkle_proof) =
177+ client. get_merkle_proof ( & spending_txid) ?
178+ {
179+ confirmed_txs. push ( (
180+ spending_tx,
181+ block_height,
182+ block_header,
183+ merkle_proof. pos ,
184+ ) ) ;
185+ continue ;
181186 }
182187 }
183188 }
184189 }
185190 }
191+ }
186192 unspent_registered_outputs. push ( output) ;
187193 }
188194
@@ -192,7 +198,7 @@ where
192198 |( _, block_height1, _, pos1) , ( _, block_height2, _, pos2) | {
193199 block_height1. cmp ( & block_height2) . then_with ( || pos1. cmp ( & pos2) )
194200 } ,
195- ) ;
201+ ) ;
196202 for ( tx, block_height, block_header, pos) in confirmed_txs {
197203 for c in & confirmables {
198204 c. transactions_confirmed ( & block_header, & [ ( pos, & tx) ] , block_height) ;
@@ -207,7 +213,9 @@ where
207213 Ok ( ( ) )
208214 }
209215
210- fn sync_transaction_unconfirmed ( & self , confirmables : Vec < & ( dyn Confirm + Sync ) > ) -> Result < ( ) , Error > {
216+ fn sync_transaction_unconfirmed (
217+ & self , confirmables : Vec < & ( dyn Confirm + Sync ) > ,
218+ ) -> Result < ( ) , Error > {
211219 let client = & * self . blockchain ;
212220 // Query the interface for relevant txids and check whether they have been
213221 // reorged-out of the chain.
@@ -221,7 +229,7 @@ where
221229 . unwrap_or ( None )
222230 . map_or ( true , |status| !status. confirmed )
223231 } )
224- . collect :: < Vec < Txid > > ( ) ;
232+ . collect :: < Vec < Txid > > ( ) ;
225233
226234 // Mark all relevant unconfirmed transactions as unconfirmed.
227235 for txid in & unconfirmed_txids {
0 commit comments