@@ -80,15 +80,22 @@ where
80
80
81
81
let mut locked_last_sync_height = self . last_sync_height . lock ( ) . unwrap ( ) ;
82
82
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
+ ) ?;
84
88
self . sync_transactions_confirmed ( confirmables. clone ( ) ) ?;
85
89
self . sync_transaction_unconfirmed ( confirmables. clone ( ) ) ?;
86
90
}
87
91
// TODO: check whether new outputs have been registered by now and process them
88
92
Ok ( ( ) )
89
93
}
90
94
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 > {
92
99
let client = & * self . blockchain ;
93
100
94
101
// Inform the interface of the new block.
@@ -101,7 +108,9 @@ where
101
108
Ok ( ( ) )
102
109
}
103
110
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 > {
105
114
let client = & * self . blockchain ;
106
115
107
116
// First, check the confirmation status of registered transactions as well as the
@@ -132,11 +141,11 @@ where
132
141
let block_header = client. get_header ( block_height) ?;
133
142
if let Some ( merkle_proof) = client. get_merkle_proof ( & txid) ? {
134
143
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
+ ) ) ;
140
149
continue ;
141
150
}
142
151
}
@@ -147,42 +156,39 @@ where
147
156
}
148
157
149
158
// 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 ( ) ;
155
161
156
162
// Remember all registered outputs that haven't been spent for future processing.
157
163
let mut unspent_registered_outputs = Vec :: new ( ) ;
158
164
159
165
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 ;
181
186
}
182
187
}
183
188
}
184
189
}
185
190
}
191
+ }
186
192
unspent_registered_outputs. push ( output) ;
187
193
}
188
194
@@ -192,7 +198,7 @@ where
192
198
|( _, block_height1, _, pos1) , ( _, block_height2, _, pos2) | {
193
199
block_height1. cmp ( & block_height2) . then_with ( || pos1. cmp ( & pos2) )
194
200
} ,
195
- ) ;
201
+ ) ;
196
202
for ( tx, block_height, block_header, pos) in confirmed_txs {
197
203
for c in & confirmables {
198
204
c. transactions_confirmed ( & block_header, & [ ( pos, & tx) ] , block_height) ;
@@ -207,7 +213,9 @@ where
207
213
Ok ( ( ) )
208
214
}
209
215
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 > {
211
219
let client = & * self . blockchain ;
212
220
// Query the interface for relevant txids and check whether they have been
213
221
// reorged-out of the chain.
@@ -221,7 +229,7 @@ where
221
229
. unwrap_or ( None )
222
230
. map_or ( true , |status| !status. confirmed )
223
231
} )
224
- . collect :: < Vec < Txid > > ( ) ;
232
+ . collect :: < Vec < Txid > > ( ) ;
225
233
226
234
// Mark all relevant unconfirmed transactions as unconfirmed.
227
235
for txid in & unconfirmed_txids {
0 commit comments