Skip to content

Commit 63df5d8

Browse files
feat(ffi): add dash_spv_ffi_config_clear_peers to remove default peers
When creating an SPV config for regtest, a default peer at 127.0.0.1:19899 is added. This doesn't match dashmate's Docker setup which maps Core P2P to different ports (e.g. 20001). FFI consumers (iOS/Swift) couldn't clear these defaults before adding their own peers, causing the SPV client to enter exclusive mode with a dead peer alongside the intended one. Adds dash_spv_ffi_config_clear_peers() so FFI consumers can remove default peers before adding custom ones via add_peer. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fcdffa7 commit 63df5d8

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

dash-spv-ffi/src/config.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,25 @@ pub unsafe extern "C" fn dash_spv_ffi_config_add_peer(
166166
}
167167
}
168168

169+
/// Removes all configured peers from the configuration
170+
///
171+
/// This is useful when the caller wants to start with a clean slate
172+
/// before adding custom peers via `dash_spv_ffi_config_add_peer`.
173+
///
174+
/// # Safety
175+
/// - `config` must be a valid pointer to an FFIClientConfig created by dash_spv_ffi_config_new/mainnet/testnet
176+
/// - The caller must ensure the config pointer remains valid for the duration of this call
177+
#[no_mangle]
178+
pub unsafe extern "C" fn dash_spv_ffi_config_clear_peers(
179+
config: *mut FFIClientConfig,
180+
) -> i32 {
181+
null_check!(config);
182+
183+
let cfg = unsafe { &mut *((*config).inner as *mut ClientConfig) };
184+
cfg.peers.clear();
185+
FFIErrorCode::Success as i32
186+
}
187+
169188
/// Sets the user agent string to advertise in the P2P handshake
170189
///
171190
/// # Safety

0 commit comments

Comments
 (0)