@@ -9,14 +9,12 @@ use dash_spv::storage::DiskStorageManager;
99use dash_spv:: types:: SyncStage ;
1010use dash_spv:: DashSpvClient ;
1111use dash_spv:: Hash ;
12- use dashcore:: Txid ;
1312
1413use futures:: future:: { AbortHandle , Abortable } ;
1514use once_cell:: sync:: Lazy ;
1615use std:: collections:: HashMap ;
17- use std:: ffi:: { CStr , CString } ;
16+ use std:: ffi:: CString ;
1817use std:: os:: raw:: { c_char, c_void} ;
19- use std:: str:: FromStr ;
2018use std:: sync:: atomic:: { AtomicU64 , Ordering } ;
2119use std:: sync:: { Arc , Mutex } ;
2220use std:: time:: Duration ;
@@ -513,23 +511,7 @@ pub unsafe extern "C" fn dash_spv_ffi_client_stop(client: *mut FFIDashSpvClient)
513511 }
514512}
515513
516- /// Performs a test synchronization of the SPV client
517- ///
518- /// # Parameters
519- /// - `client`: Pointer to an FFIDashSpvClient instance
520- ///
521- /// # Returns
522- /// - `0` on success
523- /// - Negative error code on failure
524- ///
525- /// # Safety
526- /// This function is unsafe because it dereferences a raw pointer.
527- /// The caller must ensure that the client pointer is valid.
528- #[ no_mangle]
529- pub unsafe extern "C" fn dash_spv_ffi_client_test_sync ( client : * mut FFIDashSpvClient ) -> i32 {
530- null_check ! ( client) ;
531-
532- let client = & ( * client) ;
514+ pub fn client_test_sync ( client : & FFIDashSpvClient ) -> i32 {
533515 let result = client. runtime . block_on ( async {
534516 let spv_client = {
535517 let mut guard = client. inner . lock ( ) . unwrap ( ) ;
@@ -1033,34 +1015,6 @@ pub unsafe extern "C" fn dash_spv_ffi_client_clear_storage(client: *mut FFIDashS
10331015 }
10341016}
10351017
1036- /// Check if compact filter sync is currently available.
1037- ///
1038- /// # Safety
1039- /// - `client` must be a valid, non-null pointer.
1040- #[ no_mangle]
1041- pub unsafe extern "C" fn dash_spv_ffi_client_is_filter_sync_available (
1042- client : * mut FFIDashSpvClient ,
1043- ) -> bool {
1044- null_check ! ( client, false ) ;
1045-
1046- let client = & ( * client) ;
1047- let inner = client. inner . clone ( ) ;
1048-
1049- client. runtime . block_on ( async {
1050- let spv_client = {
1051- let mut guard = inner. lock ( ) . unwrap ( ) ;
1052- match guard. take ( ) {
1053- Some ( client) => client,
1054- None => return false ,
1055- }
1056- } ;
1057- let res = spv_client. is_filter_sync_available ( ) . await ;
1058- let mut guard = inner. lock ( ) . unwrap ( ) ;
1059- * guard = Some ( spv_client) ;
1060- res
1061- } )
1062- }
1063-
10641018/// Set event callbacks for the client.
10651019///
10661020/// # Safety
@@ -1144,99 +1098,6 @@ pub unsafe extern "C" fn dash_spv_ffi_sync_progress_destroy(progress: *mut FFISy
11441098
11451099// Wallet operations
11461100
1147- /// Request a rescan of the blockchain from a given height (not yet implemented).
1148- ///
1149- /// # Safety
1150- /// - `client` must be a valid, non-null pointer.
1151- #[ no_mangle]
1152- pub unsafe extern "C" fn dash_spv_ffi_client_rescan_blockchain (
1153- client : * mut FFIDashSpvClient ,
1154- _from_height : u32 ,
1155- ) -> i32 {
1156- null_check ! ( client) ;
1157-
1158- let client = & ( * client) ;
1159- let inner = client. inner . clone ( ) ;
1160-
1161- let result: Result < ( ) , dash_spv:: SpvError > = client. runtime . block_on ( async {
1162- let mut guard = inner. lock ( ) . unwrap ( ) ;
1163- if let Some ( ref mut _spv_client) = * guard {
1164- // TODO: rescan_from_height not yet implemented in dash-spv
1165- Err ( dash_spv:: SpvError :: Config ( "Not implemented" . to_string ( ) ) )
1166- } else {
1167- Err ( dash_spv:: SpvError :: Storage ( dash_spv:: StorageError :: NotFound (
1168- "Client not initialized" . to_string ( ) ,
1169- ) ) )
1170- }
1171- } ) ;
1172-
1173- match result {
1174- Ok ( _) => FFIErrorCode :: Success as i32 ,
1175- Err ( e) => {
1176- set_last_error ( & format ! ( "Failed to rescan blockchain: {}" , e) ) ;
1177- FFIErrorCode :: from ( e) as i32
1178- }
1179- }
1180- }
1181-
1182- /// Record that we attempted to send a transaction by its txid.
1183- ///
1184- /// # Safety
1185- /// - `client` and `txid` must be valid, non-null pointers.
1186- #[ no_mangle]
1187- pub unsafe extern "C" fn dash_spv_ffi_client_record_send (
1188- client : * mut FFIDashSpvClient ,
1189- txid : * const c_char ,
1190- ) -> i32 {
1191- null_check ! ( client) ;
1192- null_check ! ( txid) ;
1193-
1194- let txid_str = match CStr :: from_ptr ( txid) . to_str ( ) {
1195- Ok ( s) => s,
1196- Err ( e) => {
1197- set_last_error ( & format ! ( "Invalid UTF-8 in txid: {}" , e) ) ;
1198- return FFIErrorCode :: InvalidArgument as i32 ;
1199- }
1200- } ;
1201-
1202- let txid = match Txid :: from_str ( txid_str) {
1203- Ok ( t) => t,
1204- Err ( e) => {
1205- set_last_error ( & format ! ( "Invalid txid: {}" , e) ) ;
1206- return FFIErrorCode :: InvalidArgument as i32 ;
1207- }
1208- } ;
1209-
1210- let client = & ( * client) ;
1211- let inner = client. inner . clone ( ) ;
1212-
1213- let result = client. runtime . block_on ( async {
1214- let spv_client = {
1215- let mut guard = inner. lock ( ) . unwrap ( ) ;
1216- match guard. take ( ) {
1217- Some ( client) => client,
1218- None => {
1219- return Err ( dash_spv:: SpvError :: Storage ( dash_spv:: StorageError :: NotFound (
1220- "Client not initialized" . to_string ( ) ,
1221- ) ) )
1222- }
1223- }
1224- } ;
1225- let res = spv_client. record_send ( txid) . await ;
1226- let mut guard = inner. lock ( ) . unwrap ( ) ;
1227- * guard = Some ( spv_client) ;
1228- res
1229- } ) ;
1230-
1231- match result {
1232- Ok ( ( ) ) => FFIErrorCode :: Success as i32 ,
1233- Err ( e) => {
1234- set_last_error ( & e. to_string ( ) ) ;
1235- FFIErrorCode :: from ( e) as i32
1236- }
1237- }
1238- }
1239-
12401101/// Get the wallet manager from the SPV client
12411102///
12421103/// Returns a pointer to an `FFIWalletManager` wrapper that clones the underlying
0 commit comments