Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 2 additions & 36 deletions dash-spv-ffi/FFI_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This document provides a comprehensive reference for all FFI (Foreign Function I

**Auto-generated**: This documentation is automatically generated from the source code. Do not edit manually.

**Total Functions**: 70
**Total Functions**: 68

## Table of Contents

Expand Down Expand Up @@ -34,7 +34,7 @@ Functions: 4

### Configuration

Functions: 27
Functions: 25

| Function | Description | Module |
|----------|-------------|--------|
Expand All @@ -54,15 +54,13 @@ Functions: 27
| `dash_spv_ffi_config_set_max_mempool_transactions` | Sets the maximum number of mempool transactions to track # Safety -... | config |
| `dash_spv_ffi_config_set_max_peers` | Sets the maximum number of peers to connect to # Safety - `config` must be... | config |
| `dash_spv_ffi_config_set_mempool_strategy` | Sets the mempool synchronization strategy # Safety - `config` must be a... | config |
| `dash_spv_ffi_config_set_mempool_timeout` | Sets the mempool transaction timeout in seconds # Safety - `config` must be... | config |
| `dash_spv_ffi_config_set_mempool_tracking` | Enables or disables mempool tracking # Safety - `config` must be a valid... | config |
| `dash_spv_ffi_config_set_persist_mempool` | Sets whether to persist mempool state to disk # Safety - `config` must be a... | config |
| `dash_spv_ffi_config_set_relay_transactions` | Sets whether to relay transactions (currently a no-op) # Safety - `config`... | config |
| `dash_spv_ffi_config_set_restrict_to_configured_peers` | Restrict connections strictly to configured peers (disable DNS discovery and... | config |
| `dash_spv_ffi_config_set_start_from_height` | Sets the starting block height for synchronization # Safety - `config` must... | config |
| `dash_spv_ffi_config_set_user_agent` | Sets the user agent string to advertise in the P2P handshake # Safety -... | config |
| `dash_spv_ffi_config_set_validation_mode` | Sets the validation mode for the SPV client # Safety - `config` must be a... | config |
| `dash_spv_ffi_config_set_wallet_creation_time` | Sets the wallet creation timestamp for synchronization optimization #... | config |
| `dash_spv_ffi_config_set_worker_threads` | Sets the number of Tokio worker threads for the FFI runtime (0 = auto) #... | config |
| `dash_spv_ffi_config_testnet` | No description | config |

Expand Down Expand Up @@ -475,22 +473,6 @@ Sets the mempool synchronization strategy # Safety - `config` must be a valid p

---

#### `dash_spv_ffi_config_set_mempool_timeout`

```c
dash_spv_ffi_config_set_mempool_timeout(config: *mut FFIClientConfig, timeout_secs: u64,) -> i32
```

**Description:**
Sets the mempool transaction timeout in seconds # Safety - `config` must be a valid pointer to an FFIClientConfig created by dash_spv_ffi_config_new/mainnet/testnet - The caller must ensure the config pointer remains valid for the duration of this call

**Safety:**
- `config` must be a valid pointer to an FFIClientConfig created by dash_spv_ffi_config_new/mainnet/testnet - The caller must ensure the config pointer remains valid for the duration of this call

**Module:** `config`

---

#### `dash_spv_ffi_config_set_mempool_tracking`

```c
Expand Down Expand Up @@ -603,22 +585,6 @@ Sets the validation mode for the SPV client # Safety - `config` must be a valid

---

#### `dash_spv_ffi_config_set_wallet_creation_time`

```c
dash_spv_ffi_config_set_wallet_creation_time(config: *mut FFIClientConfig, timestamp: u32,) -> i32
```

**Description:**
Sets the wallet creation timestamp for synchronization optimization # Safety - `config` must be a valid pointer to an FFIClientConfig created by dash_spv_ffi_config_new/mainnet/testnet - The caller must ensure the config pointer remains valid for the duration of this call

**Safety:**
- `config` must be a valid pointer to an FFIClientConfig created by dash_spv_ffi_config_new/mainnet/testnet - The caller must ensure the config pointer remains valid for the duration of this call

**Module:** `config`

---

#### `dash_spv_ffi_config_set_worker_threads`

```c
Expand Down
24 changes: 0 additions & 24 deletions dash-spv-ffi/include/dash_spv_ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -763,18 +763,6 @@ int32_t dash_spv_ffi_config_set_max_mempool_transactions(struct FFIClientConfig
uint32_t max_transactions)
;

/**
* Sets the mempool transaction timeout in seconds
*
* # Safety
* - `config` must be a valid pointer to an FFIClientConfig created by dash_spv_ffi_config_new/mainnet/testnet
* - The caller must ensure the config pointer remains valid for the duration of this call
*/

int32_t dash_spv_ffi_config_set_mempool_timeout(struct FFIClientConfig *config,
uint64_t timeout_secs)
;

/**
* Sets whether to fetch full mempool transaction data
*
Expand Down Expand Up @@ -831,18 +819,6 @@ int32_t dash_spv_ffi_config_set_start_from_height(struct FFIClientConfig *config
uint32_t height)
;

/**
* Sets the wallet creation timestamp for synchronization optimization
*
* # Safety
* - `config` must be a valid pointer to an FFIClientConfig created by dash_spv_ffi_config_new/mainnet/testnet
* - The caller must ensure the config pointer remains valid for the duration of this call
*/

int32_t dash_spv_ffi_config_set_wallet_creation_time(struct FFIClientConfig *config,
uint32_t timestamp)
;

const char *dash_spv_ffi_get_last_error(void) ;

void dash_spv_ffi_clear_error(void) ;
Expand Down
34 changes: 0 additions & 34 deletions dash-spv-ffi/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,23 +436,6 @@ pub unsafe extern "C" fn dash_spv_ffi_config_set_max_mempool_transactions(
FFIErrorCode::Success as i32
}

/// Sets the mempool transaction timeout in seconds
///
/// # Safety
/// - `config` must be a valid pointer to an FFIClientConfig created by dash_spv_ffi_config_new/mainnet/testnet
/// - The caller must ensure the config pointer remains valid for the duration of this call
#[no_mangle]
pub unsafe extern "C" fn dash_spv_ffi_config_set_mempool_timeout(
config: *mut FFIClientConfig,
timeout_secs: u64,
) -> i32 {
null_check!(config);

let config = unsafe { &mut *((*config).inner as *mut ClientConfig) };
config.mempool_timeout_secs = timeout_secs;
FFIErrorCode::Success as i32
}

/// Sets whether to fetch full mempool transaction data
///
/// # Safety
Expand Down Expand Up @@ -539,20 +522,3 @@ pub unsafe extern "C" fn dash_spv_ffi_config_set_start_from_height(
config.start_from_height = Some(height);
FFIErrorCode::Success as i32
}

/// Sets the wallet creation timestamp for synchronization optimization
///
/// # Safety
/// - `config` must be a valid pointer to an FFIClientConfig created by dash_spv_ffi_config_new/mainnet/testnet
/// - The caller must ensure the config pointer remains valid for the duration of this call
#[no_mangle]
pub unsafe extern "C" fn dash_spv_ffi_config_set_wallet_creation_time(
config: *mut FFIClientConfig,
timestamp: u32,
) -> i32 {
null_check!(config);

let config = unsafe { &mut *((*config).inner as *mut ClientConfig) };
config.wallet_creation_time = Some(timestamp);
FFIErrorCode::Success as i32
}
39 changes: 4 additions & 35 deletions dash-spv/src/client/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ pub struct ClientConfig {
/// Maximum number of peers to connect to.
pub max_peers: u32,

/// Log level for tracing.
pub log_level: String,

/// Optional user agent string to advertise in the P2P version message.
/// If not set, a sensible default is used (includes crate version).
pub user_agent: Option<String>,
Expand All @@ -66,9 +63,6 @@ pub struct ClientConfig {
/// Maximum number of unconfirmed transactions to track.
pub max_mempool_transactions: usize,

/// Time after which unconfirmed transactions are pruned (seconds).
pub mempool_timeout_secs: u64,

/// Whether to fetch transactions from INV messages immediately.
pub fetch_mempool_transactions: bool,

Expand All @@ -78,10 +72,6 @@ pub struct ClientConfig {
/// Start syncing from a specific block height.
/// The client will use the nearest checkpoint at or before this height.
pub start_from_height: Option<u32>,

/// Wallet creation time as Unix timestamp.
/// Used to determine appropriate checkpoint for sync.
pub wallet_creation_time: Option<u32>,
}

impl Default for ClientConfig {
Expand All @@ -95,17 +85,14 @@ impl Default for ClientConfig {
enable_filters: true,
enable_masternodes: true,
max_peers: 8,
log_level: "info".to_string(),
user_agent: None,
// Mempool defaults
enable_mempool_tracking: true,
mempool_strategy: MempoolStrategy::FetchAll,
max_mempool_transactions: 1000,
mempool_timeout_secs: 3600, // 1 hour
fetch_mempool_transactions: true,
persist_mempool: false,
start_from_height: None,
wallet_creation_time: None,
}
}
}
Expand Down Expand Up @@ -172,12 +159,6 @@ impl ClientConfig {
self
}

/// Set log level.
pub fn with_log_level(mut self, level: &str) -> Self {
self.log_level = level.to_string();
self
}

/// Set custom user agent string for the P2P handshake.
/// The library will lightly validate and normalize it during handshake.
pub fn with_user_agent(mut self, agent: impl Into<String>) -> Self {
Expand All @@ -198,12 +179,6 @@ impl ClientConfig {
self
}

/// Set mempool transaction timeout.
pub fn with_mempool_timeout(mut self, timeout_secs: u64) -> Self {
self.mempool_timeout_secs = timeout_secs;
self
}

/// Enable or disable mempool persistence.
pub fn with_mempool_persistence(mut self, enabled: bool) -> Self {
self.persist_mempool = enabled;
Expand All @@ -225,16 +200,10 @@ impl ClientConfig {
}

// Mempool validation
if self.enable_mempool_tracking {
if self.max_mempool_transactions == 0 {
return Err(
"max_mempool_transactions must be > 0 when mempool tracking is enabled"
.to_string(),
);
}
if self.mempool_timeout_secs == 0 {
return Err("mempool_timeout_secs must be > 0".to_string());
}
if self.enable_mempool_tracking && self.max_mempool_transactions == 0 {
return Err(
"max_mempool_transactions must be > 0 when mempool tracking is enabled".to_string()
);
}

Ok(())
Expand Down
42 changes: 0 additions & 42 deletions dash-spv/src/client/config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ mod tests {
assert!(config.enable_filters);
assert!(config.enable_masternodes);
assert_eq!(config.max_peers, 8);
assert_eq!(config.log_level, "info");

// Mempool defaults
assert!(config.enable_mempool_tracking);
assert_eq!(config.mempool_strategy, MempoolStrategy::FetchAll);
assert_eq!(config.max_mempool_transactions, 1000);
assert_eq!(config.mempool_timeout_secs, 3600);
assert!(config.fetch_mempool_transactions);
assert!(!config.persist_mempool);
}
Expand Down Expand Up @@ -52,22 +50,18 @@ mod tests {
let config = ClientConfig::mainnet()
.with_storage_path(path.clone())
.with_validation_mode(ValidationMode::Basic)
.with_log_level("debug")
.with_mempool_tracking(MempoolStrategy::BloomFilter)
.with_max_mempool_transactions(500)
.with_mempool_timeout(7200)
.with_mempool_persistence(true)
.with_start_height(100000);

assert_eq!(config.storage_path, Some(path));
assert_eq!(config.validation_mode, ValidationMode::Basic);
assert_eq!(config.log_level, "debug");

// Mempool settings
assert!(config.enable_mempool_tracking);
assert_eq!(config.mempool_strategy, MempoolStrategy::BloomFilter);
assert_eq!(config.max_mempool_transactions, 500);
assert_eq!(config.mempool_timeout_secs, 7200);
assert!(config.persist_mempool);
assert_eq!(config.start_from_height, Some(100000));
}
Expand Down Expand Up @@ -125,41 +119,5 @@ mod tests {
assert!(result.unwrap_err().contains("max_mempool_transactions must be > 0"));
}

#[test]
fn test_validation_invalid_mempool_timeout() {
let config = ClientConfig {
enable_mempool_tracking: true,
mempool_timeout_secs: 0,
..Default::default()
};

let result = config.validate();
assert!(result.is_err());
assert_eq!(result.unwrap_err(), "mempool_timeout_secs must be > 0");
}

// Removed selective strategy validation test; Selective variant no longer exists

#[test]
fn test_wallet_creation_time() {
let config = ClientConfig {
wallet_creation_time: Some(1234567890),
..Default::default()
};

assert_eq!(config.wallet_creation_time, Some(1234567890));
}

#[test]
fn test_clone_config() {
let mut original = ClientConfig::mainnet();
original.max_peers = 16;
original = original.with_log_level("debug");

let cloned = original.clone();

assert_eq!(cloned.network, original.network);
assert_eq!(cloned.max_peers, original.max_peers);
assert_eq!(cloned.log_level, original.log_level);
}
}
3 changes: 1 addition & 2 deletions dash-spv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Create configuration for mainnet
//! let config = ClientConfig::mainnet()
//! .with_storage_path("/path/to/data".into())
//! .with_log_level("info");
//! .with_storage_path("/path/to/data".into());
//!
//! // Create the required components
//! let network = PeerNetworkManager::new(&config).await?;
Expand Down
Loading