@@ -45,27 +45,27 @@ enum CallbackInfo {
4545}
4646
4747/// # Safety
48- ///
48+ ///
4949/// `CallbackInfo` is only `Send` if the following conditions are met:
5050/// - All callback functions must be safe to call from any thread
5151/// - The `user_data` pointer must either:
5252/// - Point to thread-safe data (i.e., data that implements `Send`)
5353/// - Be properly synchronized by the caller (e.g., using mutexes)
5454/// - Be null
55- ///
55+ ///
5656/// The caller is responsible for ensuring these conditions are met. Violating
5757/// these requirements will result in undefined behavior.
5858unsafe impl Send for CallbackInfo { }
5959
6060/// # Safety
61- ///
61+ ///
6262/// `CallbackInfo` is only `Sync` if the following conditions are met:
6363/// - All callback functions must be safe to call concurrently from multiple threads
6464/// - The `user_data` pointer must either:
6565/// - Point to thread-safe data (i.e., data that implements `Sync`)
6666/// - Be properly synchronized by the caller (e.g., using mutexes)
6767/// - Be null
68- ///
68+ ///
6969/// The caller is responsible for ensuring these conditions are met. Violating
7070/// these requirements will result in undefined behavior.
7171unsafe impl Sync for CallbackInfo { }
@@ -157,9 +157,10 @@ pub unsafe extern "C" fn dash_spv_ffi_client_new(
157157 let config = & ( * config) ;
158158 let runtime = match tokio:: runtime:: Builder :: new_multi_thread ( )
159159 . thread_name ( "dash-spv-worker" )
160- . worker_threads ( 1 ) // Reduce threads for mobile
160+ . worker_threads ( 1 ) // Reduce threads for mobile
161161 . enable_all ( )
162- . build ( ) {
162+ . build ( )
163+ {
163164 Ok ( rt) => Arc :: new ( rt) ,
164165 Err ( e) => {
165166 set_last_error ( & format ! ( "Failed to create runtime: {}" , e) ) ;
@@ -360,25 +361,25 @@ pub unsafe extern "C" fn dash_spv_ffi_client_stop(client: *mut FFIDashSpvClient)
360361}
361362
362363/// Sync the SPV client to the chain tip.
363- ///
364+ ///
364365/// # Safety
365- ///
366+ ///
366367/// This function is unsafe because:
367368/// - `client` must be a valid pointer to an initialized `FFIDashSpvClient`
368369/// - `user_data` must satisfy thread safety requirements:
369370/// - If non-null, it must point to data that is safe to access from multiple threads
370371/// - The caller must ensure proper synchronization if the data is mutable
371372/// - The data must remain valid for the entire duration of the sync operation
372373/// - `completion_callback` must be thread-safe and can be called from any thread
373- ///
374+ ///
374375/// # Parameters
375- ///
376+ ///
376377/// - `client`: Pointer to the SPV client
377378/// - `completion_callback`: Optional callback invoked on completion
378379/// - `user_data`: Optional user data pointer passed to callbacks
379- ///
380+ ///
380381/// # Returns
381- ///
382+ ///
382383/// 0 on success, error code on failure
383384#[ no_mangle]
384385pub unsafe extern "C" fn dash_spv_ffi_client_sync_to_tip (
@@ -418,7 +419,10 @@ pub unsafe extern "C" fn dash_spv_ffi_client_sync_to_tip(
418419 {
419420 if let Some ( callback) = completion_callback {
420421 let msg = CString :: new ( "Sync completed successfully" )
421- . unwrap_or_else ( |_| CString :: new ( "Sync completed" ) . expect ( "hardcoded string is safe" ) ) ;
422+ . unwrap_or_else ( |_| {
423+ CString :: new ( "Sync completed" )
424+ . expect ( "hardcoded string is safe" )
425+ } ) ;
422426 // SAFETY: The callback and user_data are safely managed through the registry
423427 // The registry ensures proper lifetime management and thread safety
424428 callback ( true , msg. as_ptr ( ) , user_data) ;
@@ -440,7 +444,8 @@ pub unsafe extern "C" fn dash_spv_ffi_client_sync_to_tip(
440444 if let Some ( callback) = completion_callback {
441445 let msg = match CString :: new ( format ! ( "Sync failed: {}" , e) ) {
442446 Ok ( s) => s,
443- Err ( _) => CString :: new ( "Sync failed" ) . expect ( "hardcoded string is safe" ) ,
447+ Err ( _) => CString :: new ( "Sync failed" )
448+ . expect ( "hardcoded string is safe" ) ,
444449 } ;
445450 // SAFETY: The callback and user_data are safely managed through the registry
446451 // The registry ensures proper lifetime management and thread safety
@@ -544,26 +549,26 @@ pub unsafe extern "C" fn dash_spv_ffi_client_test_sync(client: *mut FFIDashSpvCl
544549}
545550
546551/// Sync the SPV client to the chain tip with detailed progress updates.
547- ///
552+ ///
548553/// # Safety
549- ///
554+ ///
550555/// This function is unsafe because:
551556/// - `client` must be a valid pointer to an initialized `FFIDashSpvClient`
552557/// - `user_data` must satisfy thread safety requirements:
553558/// - If non-null, it must point to data that is safe to access from multiple threads
554559/// - The caller must ensure proper synchronization if the data is mutable
555560/// - The data must remain valid for the entire duration of the sync operation
556561/// - Both `progress_callback` and `completion_callback` must be thread-safe and can be called from any thread
557- ///
562+ ///
558563/// # Parameters
559- ///
564+ ///
560565/// - `client`: Pointer to the SPV client
561566/// - `progress_callback`: Optional callback invoked periodically with sync progress
562567/// - `completion_callback`: Optional callback invoked on completion
563568/// - `user_data`: Optional user data pointer passed to all callbacks
564- ///
569+ ///
565570/// # Returns
566- ///
571+ ///
567572/// 0 on success, error code on failure
568573#[ no_mangle]
569574pub unsafe extern "C" fn dash_spv_ffi_client_sync_to_tip_with_progress (
@@ -674,8 +679,11 @@ pub unsafe extern "C" fn dash_spv_ffi_client_sync_to_tip_with_progress(
674679 {
675680 match monitor_result {
676681 Ok ( _) => {
677- let msg = CString :: new ( "Sync completed successfully" )
678- . unwrap_or_else ( |_| CString :: new ( "Sync completed" ) . expect ( "hardcoded string is safe" ) ) ;
682+ let msg =
683+ CString :: new ( "Sync completed successfully" ) . unwrap_or_else ( |_| {
684+ CString :: new ( "Sync completed" )
685+ . expect ( "hardcoded string is safe" )
686+ } ) ;
679687 // SAFETY: The callback and user_data are safely managed through the registry.
680688 // The registry ensures proper lifetime management and thread safety.
681689 // The string pointer is only valid for the duration of the callback.
@@ -686,7 +694,9 @@ pub unsafe extern "C" fn dash_spv_ffi_client_sync_to_tip_with_progress(
686694 Err ( e) => {
687695 let msg = match CString :: new ( format ! ( "Sync failed: {}" , e) ) {
688696 Ok ( s) => s,
689- Err ( _) => CString :: new ( "Sync failed" ) . expect ( "hardcoded string is safe" ) ,
697+ Err ( _) => {
698+ CString :: new ( "Sync failed" ) . expect ( "hardcoded string is safe" )
699+ }
690700 } ;
691701 // SAFETY: Same as above
692702 callback ( false , msg. as_ptr ( ) , user_data) ;
0 commit comments