Skip to content

Commit 7cc3b05

Browse files
authored
unused ffi functions removed from dash-spv-ffi crate (#377)
1 parent 32506e2 commit 7cc3b05

26 files changed

+22
-2113
lines changed

dash-spv-ffi/FFI_API.md

Lines changed: 6 additions & 421 deletions
Large diffs are not rendered by default.

dash-spv-ffi/include/dash_spv_ffi.h

Lines changed: 0 additions & 328 deletions
Large diffs are not rendered by default.

dash-spv-ffi/src/bin/ffi_cli.rs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ fn main() {
7474
.action(ArgAction::Append)
7575
.help("Peer address host:port (repeatable)"),
7676
)
77-
.arg(
78-
Arg::new("workers")
79-
.long("workers")
80-
.value_parser(clap::value_parser!(u32))
81-
.help("Tokio worker threads (0=auto)"),
82-
)
8377
.arg(
8478
Arg::new("log-level")
8579
.long("log-level")
@@ -99,12 +93,6 @@ fn main() {
9993
.action(ArgAction::SetTrue)
10094
.help("Disable masternode list synchronization"),
10195
)
102-
.arg(
103-
Arg::new("no-filters")
104-
.long("no-filters")
105-
.action(ArgAction::SetTrue)
106-
.help("Disable compact filter synchronization"),
107-
)
10896
.get_matches();
10997

11098
// Map network
@@ -115,8 +103,6 @@ fn main() {
115103
_ => FFINetwork::Dash,
116104
};
117105

118-
let disable_filter_sync = matches.get_flag("no-filters");
119-
120106
unsafe {
121107
// Initialize tracing/logging via FFI so `tracing::info!` emits output
122108
let level = matches.get_one::<String>("log-level").map(String::as_str).unwrap_or("info");
@@ -133,12 +119,6 @@ fn main() {
133119
std::process::exit(1);
134120
}
135121

136-
let _ = dash_spv_ffi_config_set_filter_load(cfg, !disable_filter_sync);
137-
138-
if let Some(workers) = matches.get_one::<u32>("workers") {
139-
let _ = dash_spv_ffi_config_set_worker_threads(cfg, *workers);
140-
}
141-
142122
if let Some(height) = matches.get_one::<u32>("start-height") {
143123
let _ = dash_spv_ffi_config_set_start_from_height(cfg, *height);
144124
}
@@ -214,13 +194,9 @@ fn main() {
214194
if !prog_ptr.is_null() {
215195
let prog = &*prog_ptr;
216196
let headers_done = SYNC_COMPLETED.load(Ordering::SeqCst);
217-
let filters_complete = if disable_filter_sync || !prog.filter_sync_available {
218-
false
219-
} else {
220-
prog.filter_header_height >= prog.header_height
221-
&& prog.last_synced_filter_height >= prog.filter_header_height
222-
};
223-
if headers_done && (filters_complete || disable_filter_sync) {
197+
let filters_complete = prog.filter_header_height >= prog.header_height
198+
&& prog.last_synced_filter_height >= prog.filter_header_height;
199+
if headers_done && filters_complete {
224200
dash_spv_ffi_sync_progress_destroy(prog_ptr);
225201
break;
226202
}

dash-spv-ffi/src/broadcast.rs

Lines changed: 0 additions & 77 deletions
This file was deleted.

dash-spv-ffi/src/checkpoints.rs

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{set_last_error, FFIArray, FFIErrorCode};
1+
use crate::{set_last_error, FFIErrorCode};
22
use dash_spv::chain::checkpoints::{mainnet_checkpoints, testnet_checkpoints, CheckpointManager};
33
use dashcore::hashes::Hash;
44
use dashcore::Network;
@@ -120,43 +120,3 @@ pub unsafe extern "C" fn dash_spv_ffi_checkpoint_before_timestamp(
120120
FFIErrorCode::ValidationError as i32
121121
}
122122
}
123-
124-
/// Get all checkpoints between two heights (inclusive).
125-
///
126-
/// Returns an `FFIArray` of `FFICheckpoint` items. The caller owns the memory and
127-
/// must free the array buffer using `dash_spv_ffi_array_destroy` when done.
128-
#[no_mangle]
129-
pub extern "C" fn dash_spv_ffi_checkpoints_between_heights(
130-
network: FFINetwork,
131-
start_height: u32,
132-
end_height: u32,
133-
) -> FFIArray {
134-
match manager_for_network(network) {
135-
Ok(mgr) => {
136-
// Collect checkpoints within inclusive range
137-
let mut out: Vec<FFICheckpoint> = Vec::new();
138-
for &h in mgr.checkpoint_heights() {
139-
if h >= start_height && h <= end_height {
140-
if let Some(cp) = mgr.get_checkpoint(h) {
141-
out.push(FFICheckpoint {
142-
height: cp.height,
143-
block_hash: cp.block_hash.to_byte_array(),
144-
});
145-
}
146-
}
147-
}
148-
FFIArray::new(out)
149-
}
150-
Err(e) => {
151-
set_last_error(&e);
152-
// Return empty array on error
153-
FFIArray {
154-
data: std::ptr::null_mut(),
155-
len: 0,
156-
capacity: 0,
157-
elem_size: std::mem::size_of::<FFICheckpoint>(),
158-
elem_align: std::mem::align_of::<FFICheckpoint>(),
159-
}
160-
}
161-
}
162-
}

dash-spv-ffi/src/client.rs

Lines changed: 2 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ use dash_spv::storage::DiskStorageManager;
99
use dash_spv::types::SyncStage;
1010
use dash_spv::DashSpvClient;
1111
use dash_spv::Hash;
12-
use dashcore::Txid;
1312

1413
use futures::future::{AbortHandle, Abortable};
1514
use once_cell::sync::Lazy;
1615
use std::collections::HashMap;
17-
use std::ffi::{CStr, CString};
16+
use std::ffi::CString;
1817
use std::os::raw::{c_char, c_void};
19-
use std::str::FromStr;
2018
use std::sync::atomic::{AtomicU64, Ordering};
2119
use std::sync::{Arc, Mutex};
2220
use 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

Comments
 (0)