Skip to content

Commit 827ae97

Browse files
fix
1 parent 40cea47 commit 827ae97

File tree

7 files changed

+58
-17
lines changed

7 files changed

+58
-17
lines changed

dash-spv-ffi/include/dash_spv_ffi.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ typedef struct FFIEventCallbacks {
161161
void *user_data;
162162
} FFIEventCallbacks;
163163

164+
/**
165+
* Opaque handle to the wallet manager owned by the SPV client.
166+
*
167+
* This is intentionally zero-sized so it can be used purely as an FFI handle
168+
* while still allowing Rust to cast to the underlying key-wallet manager
169+
* implementation when necessary.
170+
*/
171+
typedef struct FFIWalletManager {
172+
uint8_t _private[0];
173+
} FFIWalletManager;
174+
164175
/**
165176
* Handle for Core SDK that can be passed to Platform SDK
166177
*/
@@ -546,7 +557,7 @@ int32_t dash_spv_ffi_client_enable_mempool_tracking(struct FFIDashSpvClient *cli
546557
*
547558
* A pointer to the wallet manager wrapper, or NULL if the client is not initialized.
548559
*/
549-
FFIWalletManager *dash_spv_ffi_client_get_wallet_manager(struct FFIDashSpvClient *client) ;
560+
struct FFIWalletManager *dash_spv_ffi_client_get_wallet_manager(struct FFIDashSpvClient *client) ;
550561

551562
/**
552563
* Release a wallet manager obtained from `dash_spv_ffi_client_get_wallet_manager`.
@@ -559,7 +570,7 @@ int32_t dash_spv_ffi_client_enable_mempool_tracking(struct FFIDashSpvClient *cli
559570
* - `manager` must either be null or a pointer previously returned by
560571
* `dash_spv_ffi_client_get_wallet_manager`.
561572
*/
562-
void dash_spv_ffi_wallet_manager_free(FFIWalletManager *manager) ;
573+
void dash_spv_ffi_wallet_manager_free(struct FFIWalletManager *manager) ;
563574

564575
struct FFIClientConfig *dash_spv_ffi_config_new(FFINetwork network) ;
565576

dash-spv-ffi/src/client.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::{
22
null_check, set_last_error, FFIClientConfig, FFIDetailedSyncProgress, FFIErrorCode,
3-
FFIEventCallbacks, FFIMempoolStrategy, FFISpvStats, FFISyncProgress,
3+
FFIEventCallbacks, FFIMempoolStrategy, FFISpvStats, FFISyncProgress, FFIWalletManager,
44
};
55
// Import wallet types from key-wallet-ffi
6-
use key_wallet_ffi::FFIWalletManager;
6+
use key_wallet_ffi::FFIWalletManager as KeyWalletFFIWalletManager;
77

88
use dash_spv::storage::DiskStorageManager;
99
use dash_spv::types::SyncStage;
@@ -1514,9 +1514,9 @@ pub unsafe extern "C" fn dash_spv_ffi_client_get_wallet_manager(
15141514
let runtime = client.runtime.clone();
15151515

15161516
// Create the FFIWalletManager with the cloned Arc
1517-
let manager = FFIWalletManager::from_arc(wallet_arc, runtime);
1517+
let manager = KeyWalletFFIWalletManager::from_arc(wallet_arc, runtime);
15181518

1519-
Box::into_raw(Box::new(manager))
1519+
Box::into_raw(Box::new(manager)) as *mut FFIWalletManager
15201520
} else {
15211521
set_last_error("Client not initialized");
15221522
std::ptr::null_mut()
@@ -1538,5 +1538,5 @@ pub unsafe extern "C" fn dash_spv_ffi_wallet_manager_free(manager: *mut FFIWalle
15381538
return;
15391539
}
15401540

1541-
key_wallet_ffi::wallet_manager::wallet_manager_free(manager);
1541+
key_wallet_ffi::wallet_manager::wallet_manager_free(manager as *mut KeyWalletFFIWalletManager);
15421542
}

dash-spv-ffi/src/types.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ use dash_spv::{ChainState, PeerInfo, SpvStats, SyncProgress};
44
use std::ffi::{CStr, CString};
55
use std::os::raw::{c_char, c_void};
66

7+
/// Opaque handle to the wallet manager owned by the SPV client.
8+
///
9+
/// This is intentionally zero-sized so it can be used purely as an FFI handle
10+
/// while still allowing Rust to cast to the underlying key-wallet manager
11+
/// implementation when necessary.
12+
#[repr(C)]
13+
pub struct FFIWalletManager {
14+
_private: [u8; 0],
15+
}
16+
717
#[repr(C)]
818
pub struct FFIString {
919
pub ptr: *mut c_char,

dash-spv-ffi/tests/test_wallet_manager.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ mod tests {
5555

5656
let wallet_manager = dash_spv_ffi_client_get_wallet_manager(client);
5757
assert!(!wallet_manager.is_null());
58+
let wallet_manager_ptr = wallet_manager as *mut key_wallet_ffi::FFIWalletManager;
5859

5960
// Prepare a serialized wallet using the native manager so we can import it
6061
let mut native_manager = WalletManager::<ManagedWalletInfo>::new();
@@ -74,7 +75,7 @@ mod tests {
7475
let mut error = FFIError::success();
7576
let mut imported_wallet_id = [0u8; 32];
7677
let import_ok = wallet_manager_import_wallet_from_bytes(
77-
wallet_manager,
78+
wallet_manager_ptr,
7879
serialized_wallet.as_ptr(),
7980
serialized_wallet.len(),
8081
imported_wallet_id.as_mut_ptr(),
@@ -87,7 +88,7 @@ mod tests {
8788
let mut ids_ptr: *mut u8 = std::ptr::null_mut();
8889
let mut id_count: usize = 0;
8990
let ids_ok = wallet_manager_get_wallet_ids(
90-
wallet_manager as *const FFIWalletManager,
91+
wallet_manager_ptr as *const FFIWalletManager,
9192
&mut ids_ptr,
9293
&mut id_count,
9394
&mut error as *mut FFIError,
@@ -103,7 +104,7 @@ mod tests {
103104
// Call the describe helper through FFI to ensure the shared instance reports correctly
104105
let mut description_error = FFIError::success();
105106
let description_ptr = key_wallet_ffi::wallet_manager_describe(
106-
wallet_manager as *const FFIWalletManager,
107+
wallet_manager_ptr as *const FFIWalletManager,
107108
FFINetwork::Dash,
108109
&mut description_error as *mut FFIError,
109110
);

dash-spv/src/client/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,11 +2566,13 @@ mod tests {
25662566

25672567
#[tokio::test]
25682568
async fn client_exposes_shared_wallet_manager() {
2569-
let mut config = ClientConfig::default();
2570-
config.network = Network::Dash;
2571-
config.enable_filters = false;
2572-
config.enable_masternodes = false;
2573-
config.enable_mempool_tracking = false;
2569+
let config = ClientConfig {
2570+
network: Network::Dash,
2571+
enable_filters: false,
2572+
enable_masternodes: false,
2573+
enable_mempool_tracking: false,
2574+
..Default::default()
2575+
};
25742576

25752577
let network_manager = MockNetworkManager::new();
25762578
let storage = MemoryStorageManager::new().await.expect("memory storage should initialize");

swift-dash-core-sdk/Sources/DashSPVFFI/include/dash_spv_ffi.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ typedef struct FFIEventCallbacks {
161161
void *user_data;
162162
} FFIEventCallbacks;
163163

164+
/**
165+
* Opaque handle to the wallet manager owned by the SPV client.
166+
*
167+
* This is intentionally zero-sized so it can be used purely as an FFI handle
168+
* while still allowing Rust to cast to the underlying key-wallet manager
169+
* implementation when necessary.
170+
*/
171+
typedef struct FFIWalletManager {
172+
uint8_t _private[0];
173+
} FFIWalletManager;
174+
164175
/**
165176
* Handle for Core SDK that can be passed to Platform SDK
166177
*/
@@ -546,7 +557,7 @@ int32_t dash_spv_ffi_client_enable_mempool_tracking(struct FFIDashSpvClient *cli
546557
*
547558
* A pointer to the wallet manager wrapper, or NULL if the client is not initialized.
548559
*/
549-
FFIWalletManager *dash_spv_ffi_client_get_wallet_manager(struct FFIDashSpvClient *client) ;
560+
struct FFIWalletManager *dash_spv_ffi_client_get_wallet_manager(struct FFIDashSpvClient *client) ;
550561

551562
/**
552563
* Release a wallet manager obtained from `dash_spv_ffi_client_get_wallet_manager`.
@@ -559,7 +570,7 @@ int32_t dash_spv_ffi_client_enable_mempool_tracking(struct FFIDashSpvClient *cli
559570
* - `manager` must either be null or a pointer previously returned by
560571
* `dash_spv_ffi_client_get_wallet_manager`.
561572
*/
562-
void dash_spv_ffi_wallet_manager_free(FFIWalletManager *manager) ;
573+
void dash_spv_ffi_wallet_manager_free(struct FFIWalletManager *manager) ;
563574

564575
struct FFIClientConfig *dash_spv_ffi_config_new(FFINetwork network) ;
565576

swift-dash-core-sdk/Sources/KeyWalletFFI/include/key_wallet_ffi.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3743,6 +3743,12 @@ char *wallet_manager_describe(const FFIWalletManager *manager,
37433743

37443744
/*
37453745
Free a string previously returned by wallet manager APIs.
3746+
3747+
# Safety
3748+
- `value` must be either null or a pointer obtained from
3749+
`wallet_manager_describe` (or other wallet manager FFI helpers that
3750+
specify this free function).
3751+
- The pointer must not be used after this call returns.
37463752
*/
37473753
void wallet_manager_free_string(char *value) ;
37483754

0 commit comments

Comments
 (0)