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
29 changes: 1 addition & 28 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**: 67
**Total Functions**: 66

## Table of Contents

Expand All @@ -13,7 +13,6 @@ This document provides a comprehensive reference for all FFI (Foreign Function I
- [Synchronization](#synchronization)
- [Address Monitoring](#address-monitoring)
- [Transaction Management](#transaction-management)
- [Mempool Operations](#mempool-operations)
- [Platform Integration](#platform-integration)
- [Event Callbacks](#event-callbacks)
- [Error Handling](#error-handling)
Expand Down Expand Up @@ -95,14 +94,6 @@ Functions: 3
| `dash_spv_ffi_unconfirmed_transaction_destroy` | Destroys an FFIUnconfirmedTransaction and all its associated resources #... | types |
| `dash_spv_ffi_unconfirmed_transaction_destroy_raw_tx` | Destroys the raw transaction bytes allocated for an FFIUnconfirmedTransaction... | types |

### Mempool Operations

Functions: 1

| Function | Description | Module |
|----------|-------------|--------|
| `dash_spv_ffi_client_enable_mempool_tracking` | Enable mempool tracking with a given strategy | client |

### Platform Integration

Functions: 4
Expand Down Expand Up @@ -776,24 +767,6 @@ Destroys the raw transaction bytes allocated for an FFIUnconfirmedTransaction #

---

### Mempool Operations - Detailed

#### `dash_spv_ffi_client_enable_mempool_tracking`

```c
dash_spv_ffi_client_enable_mempool_tracking(client: *mut FFIDashSpvClient, strategy: FFIMempoolStrategy,) -> i32
```

**Description:**
Enable mempool tracking with a given strategy. # Safety - `client` must be a valid, non-null pointer.

**Safety:**
- `client` must be a valid, non-null pointer.

**Module:** `client`

---

### Platform Integration - Detailed

#### `ffi_dash_spv_get_core_handle`
Expand Down
21 changes: 5 additions & 16 deletions dash-spv-ffi/include/dash_spv_ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ typedef enum FFISyncStage {
Failed = 9,
} FFISyncStage;

typedef enum FFIMempoolStrategy {
FetchAll = 0,
BloomFilter = 1,
} FFIMempoolStrategy;

typedef enum DashSpvValidationMode {
None = 0,
Basic = 1,
Full = 2,
} DashSpvValidationMode;

typedef enum FFIMempoolStrategy {
FetchAll = 0,
BloomFilter = 1,
} FFIMempoolStrategy;

typedef struct FFIDashSpvClient FFIDashSpvClient;

/**
Expand Down Expand Up @@ -482,17 +482,6 @@ int32_t dash_spv_ffi_client_rescan_blockchain(struct FFIDashSpvClient *client,
uint32_t _from_height)
;

/**
* Enable mempool tracking with a given strategy.
*
* # Safety
* - `client` must be a valid, non-null pointer.
*/

int32_t dash_spv_ffi_client_enable_mempool_tracking(struct FFIDashSpvClient *client,
enum FFIMempoolStrategy strategy)
;

/**
* Record that we attempted to send a transaction by its txid.
*
Expand Down
45 changes: 1 addition & 44 deletions dash-spv-ffi/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
null_check, set_last_error, FFIClientConfig, FFIDetailedSyncProgress, FFIErrorCode,
FFIEventCallbacks, FFIMempoolStrategy, FFISpvStats, FFISyncProgress, FFIWalletManager,
FFIEventCallbacks, FFISpvStats, FFISyncProgress, FFIWalletManager,
};
// Import wallet types from key-wallet-ffi
use key_wallet_ffi::FFIWalletManager as KeyWalletFFIWalletManager;
Expand Down Expand Up @@ -1253,49 +1253,6 @@ pub unsafe extern "C" fn dash_spv_ffi_client_rescan_blockchain(
}
}

/// Enable mempool tracking with a given strategy.
///
/// # Safety
/// - `client` must be a valid, non-null pointer.
#[no_mangle]
pub unsafe extern "C" fn dash_spv_ffi_client_enable_mempool_tracking(
client: *mut FFIDashSpvClient,
strategy: FFIMempoolStrategy,
) -> i32 {
null_check!(client);

let client = &(*client);
let inner = client.inner.clone();

let mempool_strategy = strategy.into();

let result = client.runtime.block_on(async {
let mut spv_client = {
let mut guard = inner.lock().unwrap();
match guard.take() {
Some(client) => client,
None => {
return Err(dash_spv::SpvError::Storage(dash_spv::StorageError::NotFound(
"Client not initialized".to_string(),
)))
}
}
};
let res = spv_client.enable_mempool_tracking(mempool_strategy).await;
let mut guard = inner.lock().unwrap();
*guard = Some(spv_client);
res
});

match result {
Ok(()) => FFIErrorCode::Success as i32,
Err(e) => {
set_last_error(&e.to_string());
FFIErrorCode::from(e) as i32
}
}
}

/// Record that we attempted to send a transaction by its txid.
///
/// # Safety
Expand Down
26 changes: 1 addition & 25 deletions dash-spv/src/client/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,9 @@ use crate::network::NetworkManager;
use crate::storage::StorageManager;
use key_wallet_manager::wallet_interface::WalletInterface;

use super::{config, DashSpvClient};
use super::DashSpvClient;

impl<W: WalletInterface, N: NetworkManager, S: StorageManager> DashSpvClient<W, N, S> {
/// Enable mempool tracking with the specified strategy.
pub async fn enable_mempool_tracking(
&mut self,
strategy: config::MempoolStrategy,
) -> Result<()> {
// Update config
self.config.enable_mempool_tracking = true;
self.config.mempool_strategy = strategy;

// Initialize mempool filter if not already done
if self.mempool_filter.is_none() {
// TODO: Get monitored addresses from wallet
self.mempool_filter = Some(Arc::new(MempoolFilter::new(
self.config.mempool_strategy,
self.config.max_mempool_transactions,
self.mempool_state.clone(),
HashSet::new(), // Will be populated from wallet's monitored addresses
self.config.network,
)));
}

Ok(())
}

/// Get mempool balance for an address.
pub async fn get_mempool_balance(
&self,
Expand Down
8 changes: 1 addition & 7 deletions dash-spv/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,10 @@ mod tests {

let test_address = Address::dummy(config.network, 0);

let mut client = DashSpvClient::new(config, network_manager, storage, wallet)
let client = DashSpvClient::new(config, network_manager, storage, wallet)
.await
.expect("client construction must succeed");

// Enable mempool tracking to initialize mempool_filter
client
.enable_mempool_tracking(crate::client::config::MempoolStrategy::BloomFilter)
.await
.expect("enable mempool tracking must succeed");

// Create a transaction that sends 10 Dash to the test address
let tx = Transaction {
version: 2,
Expand Down
Loading