@@ -230,6 +230,16 @@ impl FFIDashSpvClient {
230230 confirmed, unconfirmed, total) ;
231231 callbacks. call_balance_update ( confirmed, unconfirmed) ;
232232 }
233+ dash_spv:: types:: SpvEvent :: FilterHeadersProgress { filter_header_height, header_height, percentage } => {
234+ tracing:: info!( "📊 Filter headers progress event: filter={}, header={}, pct={:.2}" ,
235+ filter_header_height, header_height, percentage) ;
236+ callbacks
237+ . call_filter_headers_progress (
238+ filter_header_height,
239+ header_height,
240+ percentage,
241+ ) ;
242+ }
233243 dash_spv:: types:: SpvEvent :: TransactionDetected { ref txid, confirmed, ref addresses, amount, block_height, .. } => {
234244 tracing:: info!( "💸 Transaction detected: txid={}, confirmed={}, amount={}, addresses={:?}, height={:?}" ,
235245 txid, confirmed, amount, addresses, block_height) ;
@@ -717,6 +727,8 @@ pub unsafe extern "C" fn dash_spv_ffi_client_sync_to_tip_with_progress(
717727 let inner = client. inner . clone ( ) ;
718728 let runtime = client. runtime . clone ( ) ;
719729 let sync_callbacks = client. sync_callbacks . clone ( ) ;
730+ // Shared flag to coordinate internal threads during sync
731+ let sync_running = Arc :: new ( AtomicBool :: new ( true ) ) ;
720732
721733 // Take progress receiver from client
722734 let progress_receiver = {
@@ -772,6 +784,7 @@ pub unsafe extern "C" fn dash_spv_ffi_client_sync_to_tip_with_progress(
772784 // Spawn sync task in a separate thread with safe callback access
773785 let runtime_handle = runtime. handle ( ) . clone ( ) ;
774786 let sync_callbacks_clone = sync_callbacks. clone ( ) ;
787+ let sync_running_for_join = sync_running. clone ( ) ;
775788 let sync_handle = std:: thread:: spawn ( move || {
776789 // Run monitoring loop
777790 let monitor_result = runtime_handle. block_on ( async move {
@@ -792,6 +805,9 @@ pub unsafe extern "C" fn dash_spv_ffi_client_sync_to_tip_with_progress(
792805 res
793806 } ) ;
794807
808+ // Signal background handlers to stop
809+ sync_running_for_join. store ( false , Ordering :: Relaxed ) ;
810+
795811 // Send completion callback and cleanup
796812 {
797813 let mut cb_guard = sync_callbacks_clone. lock ( ) . unwrap ( ) ;
@@ -843,6 +859,8 @@ pub unsafe extern "C" fn dash_spv_ffi_client_sync_to_tip_with_progress(
843859 FFIErrorCode :: Success as i32
844860}
845861
862+ // Note: filter headers progress is forwarded via FFIEventCallbacks.on_filter_headers_progress
863+
846864/// Cancels the sync operation.
847865///
848866/// **Note**: This function currently only stops the SPV client and clears sync callbacks,
@@ -1021,6 +1039,10 @@ pub unsafe extern "C" fn dash_spv_ffi_client_set_event_callbacks(
10211039 tracing:: info!( " Block callback: {}" , callbacks. on_block. is_some( ) ) ;
10221040 tracing:: info!( " Transaction callback: {}" , callbacks. on_transaction. is_some( ) ) ;
10231041 tracing:: info!( " Balance update callback: {}" , callbacks. on_balance_update. is_some( ) ) ;
1042+ tracing:: info!(
1043+ " Filter headers progress callback: {}" ,
1044+ callbacks. on_filter_headers_progress. is_some( )
1045+ ) ;
10241046
10251047 let mut event_callbacks = client. event_callbacks . lock ( ) . unwrap ( ) ;
10261048 * event_callbacks = callbacks;
0 commit comments