@@ -49,25 +49,6 @@ async fn get_tx_confirmations(esplora_url: &str, txid: Txid, chain_tip_height: u
4949 . unwrap_or ( 0 )
5050}
5151
52- /// Helper function to filter bridge status items based on confirmations
53- async fn filter_by_confirmations < T > (
54- txid : Txid ,
55- item : T ,
56- config : & BridgeMonitoringConfig ,
57- chain_tip_height : u64 ,
58- ) -> Option < ( T , u64 ) >
59- where
60- T : Clone ,
61- {
62- let confirmations = get_tx_confirmations ( config. esplora_url ( ) , txid, chain_tip_height) . await ;
63-
64- if confirmations < config. max_tx_confirmations ( ) {
65- Some ( ( item, confirmations) )
66- } else {
67- None
68- }
69- }
70-
7152/// Determine which cached deposit entries should be purged
7253async fn determine_deposits_to_purge (
7354 cache : & BridgeStatusCache ,
@@ -148,7 +129,9 @@ async fn determine_reimbursements_to_purge(
148129 ReimbursementStatus :: Complete => reimbursement_info
149130 . payout_txid
150131 . unwrap_or ( reimbursement_info. claim_txid ) ,
151- ReimbursementStatus :: Challenged | ReimbursementStatus :: InProgress => unreachable ! ( ) ,
132+ ReimbursementStatus :: Challenged
133+ | ReimbursementStatus :: InProgress
134+ | ReimbursementStatus :: NotStarted => unreachable ! ( ) ,
152135 } ;
153136
154137 let current_confirmations =
@@ -208,13 +191,13 @@ pub async fn bridge_monitoring_task(context: Arc<BridgeMonitoringContext>) {
208191 let cache = context. status_cache . read ( ) . await ;
209192 let deposits: Vec < Txid > = cache
210193 . filter_deposits ( |s| matches ! ( s, DepositStatus :: InProgress ) )
211- . into_iter ( )
212- . map ( |( txid, _) | txid)
194+ . iter ( )
195+ . map ( |( txid, _) | * txid)
213196 . collect ( ) ;
214197 let withdrawals: Vec < Buf32 > = cache
215198 . filter_withdrawals ( |s| matches ! ( s, WithdrawalStatus :: InProgress ) )
216- . into_iter ( )
217- . map ( |( request_id, _) | request_id)
199+ . iter ( )
200+ . map ( |( request_id, _) | * request_id)
218201 . collect ( ) ;
219202 let reimbursements: Vec < Txid > = cache
220203 . filter_reimbursements ( |s| {
@@ -223,8 +206,8 @@ pub async fn bridge_monitoring_task(context: Arc<BridgeMonitoringContext>) {
223206 ReimbursementStatus :: InProgress | ReimbursementStatus :: Challenged
224207 )
225208 } )
226- . into_iter ( )
227- . map ( |( txid, _) | txid)
209+ . iter ( )
210+ . map ( |( txid, _) | * txid)
228211 . collect ( ) ;
229212 ( deposits, withdrawals, reimbursements)
230213 } ;
@@ -233,8 +216,8 @@ pub async fn bridge_monitoring_task(context: Arc<BridgeMonitoringContext>) {
233216 let deposit_updates: Vec < ( Txid , DepositInfo , u64 ) > =
234217 get_deposits ( & context. config , chain_tip_height, & active_deposits)
235218 . await
236- . into_iter ( )
237- . map ( |( info, confirmations) | ( info. deposit_request_txid , info, confirmations) )
219+ . iter ( )
220+ . map ( |( info, confirmations) | ( info. deposit_request_txid , * info, * confirmations) )
238221 . collect ( ) ;
239222
240223 {
@@ -251,8 +234,8 @@ pub async fn bridge_monitoring_task(context: Arc<BridgeMonitoringContext>) {
251234 let withdrawal_updates: Vec < ( Buf32 , WithdrawalInfo , u64 ) > =
252235 get_withdrawals ( & context. config , chain_tip_height, & active_withdrawals)
253236 . await
254- . into_iter ( )
255- . map ( |( info, confirmations) | ( info. withdrawal_request_txid , info, confirmations) )
237+ . iter ( )
238+ . map ( |( info, confirmations) | ( info. withdrawal_request_txid , * info, * confirmations) )
256239 . collect ( ) ;
257240
258241 {
@@ -269,8 +252,8 @@ pub async fn bridge_monitoring_task(context: Arc<BridgeMonitoringContext>) {
269252 let reimbursement_updates: Vec < ( Txid , ReimbursementInfo , u64 ) > =
270253 get_reimbursements ( & context. config , chain_tip_height, & active_reimbursements)
271254 . await
272- . into_iter ( )
273- . map ( |( info, confirmations) | ( info. claim_txid , info, confirmations) )
255+ . iter ( )
256+ . map ( |( info, confirmations) | ( info. claim_txid , * info, * confirmations) )
274257 . collect ( ) ;
275258
276259 {
@@ -388,15 +371,10 @@ async fn get_deposits(
388371 RpcDepositStatus :: InProgress => unreachable ! ( ) , // Already matched
389372 } ;
390373
391- if let Some ( result) = filter_by_confirmations (
392- txid,
393- DepositInfo :: from ( & dep_info) ,
394- config,
395- chain_tip_height,
396- )
397- . await
398- {
399- deposit_infos. push ( result) ;
374+ let confirmations =
375+ get_tx_confirmations ( config. esplora_url ( ) , txid, chain_tip_height) . await ;
376+ if confirmations < config. max_tx_confirmations ( ) {
377+ deposit_infos. push ( ( DepositInfo :: from ( & dep_info) , confirmations) ) ;
400378 }
401379 }
402380 }
@@ -471,15 +449,11 @@ async fn get_withdrawals(
471449 withdrawal_infos. push ( ( WithdrawalInfo :: from ( & wd_info) , 0 ) ) ;
472450 }
473451 RpcWithdrawalStatus :: Complete { fulfillment_txid } => {
474- if let Some ( result) = filter_by_confirmations (
475- * fulfillment_txid,
476- WithdrawalInfo :: from ( & wd_info) ,
477- config,
478- chain_tip_height,
479- )
480- . await
481- {
482- withdrawal_infos. push ( result) ;
452+ let confirmations =
453+ get_tx_confirmations ( config. esplora_url ( ) , * fulfillment_txid, chain_tip_height)
454+ . await ;
455+ if confirmations < config. max_tx_confirmations ( ) {
456+ withdrawal_infos. push ( ( WithdrawalInfo :: from ( & wd_info) , confirmations) ) ;
483457 }
484458 }
485459 }
@@ -563,15 +537,10 @@ async fn get_reimbursements(
563537 | RpcReimbursementStatus :: InProgress { .. }
564538 | RpcReimbursementStatus :: Challenged { .. } => unreachable ! ( ) , // Already matched
565539 } ;
566- if let Some ( result) = filter_by_confirmations (
567- txid,
568- ReimbursementInfo :: from ( & claim_info) ,
569- config,
570- chain_tip_height,
571- )
572- . await
573- {
574- reimbursement_infos. push ( result) ;
540+ let confirmations =
541+ get_tx_confirmations ( config. esplora_url ( ) , txid, chain_tip_height) . await ;
542+ if confirmations < config. max_tx_confirmations ( ) {
543+ reimbursement_infos. push ( ( ReimbursementInfo :: from ( & claim_info) , confirmations) ) ;
575544 }
576545 }
577546 }
0 commit comments