Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
87eb512
Revert "chore: run `cargo fmt`"
PastaPastaPasta Aug 11, 2025
6de2b6e
sync from genesis working kind of
pauldelucia Jul 21, 2025
a93514a
synced fully
pauldelucia Jul 21, 2025
1299583
progress
pauldelucia Jul 25, 2025
d653d5c
ok
pauldelucia Jul 25, 2025
b65ce5e
fix(swift-sdk): remove DashSPVFFI target for unified SDK compatibility
Jul 16, 2025
62749d9
fix: handle filter sync skip properly in sequential sync manager
Jul 16, 2025
57fc858
fix: improve masternode sync robustness and completion handling
pauldelucia Jul 25, 2025
5119212
ok
pauldelucia Jul 25, 2025
48e4a9e
works
pauldelucia Jul 28, 2025
cc6ee0e
feat: make header storage batched and atomic
pauldelucia Jul 30, 2025
c955fbf
delete some logs
pauldelucia Jul 30, 2025
5764d83
fix logging of states and ask only one peer for mnlist diffs
pauldelucia Jul 31, 2025
ddec914
transition to fully synced
pauldelucia Jul 31, 2025
5f6690c
remove "received command" log
pauldelucia Aug 1, 2025
97d42a8
big refactor, working very well
pauldelucia Aug 3, 2025
a3db70c
fix: storing duplicate headers when manually stopped spv
pauldelucia Aug 4, 2025
92aeda8
chore: run `cargo fmt`
PastaPastaPasta Aug 4, 2025
5d441c7
build: add test-utils workspace member and dependencies
Jul 22, 2025
ad92210
feat(dash): add LLMQ DKG window calculations and fix intervals
Jul 22, 2025
438fe30
feat(swift-sdk): expose FFI client handle for Platform SDK integration
Jul 22, 2025
7d5f747
refactor(dash-spv-ffi): improve error handling traits
Jul 22, 2025
8a59c82
test(dash-spv-ffi): add platform integration tests and documentation
Jul 22, 2025
66facd9
refactor(ffi): replace underscore-prefixed parameters with standard n…
Jul 23, 2025
2055768
feat: update mainnet checkpoints to match dash-cli
PastaPastaPasta Jul 23, 2025
79617fe
docs(dash-spv): improve storage API documentation
PastaPastaPasta Jul 24, 2025
886a9e4
sync from genesis working kind of
pauldelucia Jul 21, 2025
15849d6
checkpoints working - values for 1900000 fixed. others probably need …
pauldelucia Aug 4, 2025
598be81
sync from checkpoint works well
pauldelucia Aug 5, 2025
cbed4a1
chore: run `cargo fmt`
PastaPastaPasta Aug 11, 2025
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["dash", "dash-network", "dash-network-ffi", "hashes", "internals", "fuzz", "rpc-client", "rpc-json", "rpc-integration-test", "key-wallet", "key-wallet-ffi", "dash-spv", "dash-spv-ffi"]
members = ["dash", "dash-network", "dash-network-ffi", "hashes", "internals", "fuzz", "rpc-client", "rpc-json", "rpc-integration-test", "key-wallet", "key-wallet-ffi", "dash-spv", "dash-spv-ffi", "test-utils"]
resolver = "2"

[workspace.package]
Expand Down
791 changes: 791 additions & 0 deletions PLAN.md

Large diffs are not rendered by default.

145 changes: 145 additions & 0 deletions dash-spv-ffi/CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Overview

dash-spv-ffi provides C-compatible FFI bindings for the Dash SPV (Simplified Payment Verification) client. It wraps the Rust dash-spv library to enable usage from C, Swift, and other languages via a stable ABI.

## Build Commands

### Rust Library Build
```bash
# Debug build
cargo build

# Release build (recommended for production)
cargo build --release

# Build for specific iOS targets
cargo build --release --target aarch64-apple-ios
cargo build --release --target aarch64-apple-ios-sim
```

### Header Generation
The C header is auto-generated by the build script. To regenerate manually:
```bash
cbindgen --config cbindgen.toml --crate dash-spv-ffi --output include/dash_spv_ffi.h
```

### Unified SDK Build
For iOS integration with platform-ios:
```bash
# First build dash-spv-ffi for iOS targets (REQUIRED!)
cargo build --release --target aarch64-apple-ios
cargo build --release --target aarch64-apple-ios-sim

# Then build the unified SDK
cd ../../platform-ios/packages/rs-sdk-ffi
./build_ios.sh

# Copy to iOS project
cp -R build/DashUnifiedSDK.xcframework ../../../dashpay-ios/DashPayiOS/Libraries/
```

**Important**: The unified SDK build process (`build_ios.sh`) merges dash-spv-ffi with platform SDK. You MUST build dash-spv-ffi first or changes won't be included!

## Testing

### Rust Tests
```bash
# Run all tests
cargo test

# Run specific test
cargo test test_client_lifecycle

# Run with output
cargo test -- --nocapture

# Run tests with real Dash node (requires DASH_SPV_IP env var)
DASH_SPV_IP=192.168.1.100 cargo test -- --ignored
```

### C Tests
```bash
cd tests/c_tests

# Build and run all tests
make test

# Run specific test
make test_basic && ./test_basic

# Clean build artifacts
make clean
```

## Architecture

### Core Components

**FFI Wrapper Layer** (`src/`):
- `client.rs` - SPV client operations (connect, sync, broadcast)
- `config.rs` - Client configuration (network, peers, validation)
- `wallet.rs` - Wallet operations (addresses, balances, UTXOs)
- `callbacks.rs` - Async callback system for progress/events
- `types.rs` - FFI-safe type conversions
- `error.rs` - Thread-local error handling
- `platform_integration.rs` - Platform SDK integration support

**Key Design Patterns**:
1. **Opaque Pointers**: Complex Rust types are exposed as opaque pointers (`FFIDashSpvClient*`)
2. **Explicit Memory Management**: All FFI types have corresponding `_destroy()` functions
3. **Error Handling**: Uses thread-local storage for error propagation
4. **Callbacks**: Async operations use C function pointers for progress/completion

### FFI Safety Rules

1. **String Handling**:
- Rust strings are returned as `*const c_char` (caller must free with `dash_string_free`)
- Input strings are `*const c_char` (borrowed, not freed)

2. **Memory Ownership**:
- Functions returning pointers transfer ownership (caller must destroy)
- Functions taking pointers borrow (caller retains ownership)

3. **Thread Safety**:
- Client operations are thread-safe
- Callbacks may be invoked from any thread

### Integration with Unified SDK

This crate can be used standalone or as part of the unified SDK:
- **Standalone**: Produces `libdash_spv_ffi.a` with `dash_spv_ffi.h`
- **Unified**: Combined with platform SDK in `DashUnifiedSDK.xcframework`

The unified SDK merges headers and resolves type conflicts between Core and Platform layers.

## Common Development Tasks

### Adding New FFI Functions
1. Implement Rust function in appropriate module with `#[no_mangle] extern "C"`
2. Add cbindgen annotations for complex types
3. Run `cargo build` to regenerate header
4. Add corresponding test in `tests/unit/`
5. Add C test in `tests/c_tests/`

### Debugging FFI Issues
- Check `dash_spv_ffi_get_last_error()` for error details
- Use `RUST_LOG=debug` for verbose logging
- Verify memory management (matching create/destroy calls)
- Test with AddressSanitizer: `RUSTFLAGS="-Z sanitizer=address" cargo test`

### Platform-Specific Builds
- iOS: Use `--target aarch64-apple-ios` or `aarch64-apple-ios-sim`
- Android: Use appropriate NDK target
- Linux/macOS: Default target works

## Dependencies

Key dependencies from Cargo.toml:
- `dash-spv` - Core SPV implementation (local path)
- `dashcore` - Dash protocol types (local path)
- `tokio` - Async runtime
- `cbindgen` - C header generation (build dependency)
1 change: 1 addition & 0 deletions dash-spv-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ tracing = "0.1"
tempfile = "3.8"
serial_test = "3.0"
env_logger = "0.10"
dashcore-test-utils = { path = "../test-utils" }

[build-dependencies]
cbindgen = "0.26"
Expand Down
1 change: 1 addition & 0 deletions dash-spv-ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::sync::Mutex;
static LAST_ERROR: Mutex<Option<CString>> = Mutex::new(None);

#[repr(C)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum FFIErrorCode {
Success = 0,
NullPointer = 1,
Expand Down
19 changes: 19 additions & 0 deletions dash-spv-ffi/tests/test_platform_integration_minimal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! Minimal platform integration test to verify FFI functions

use dash_spv_ffi::*;
use std::ptr;

#[test]
fn test_basic_null_checks() {
unsafe {
// Test null pointer handling
let handle = ffi_dash_spv_get_core_handle(ptr::null_mut());
assert!(handle.is_null());

// Test error code
let mut height: u32 = 0;
let result =
ffi_dash_spv_get_platform_activation_height(ptr::null_mut(), &mut height as *mut u32);
assert_eq!(result.error_code, FFIErrorCode::NullPointer as i32);
}
}
Loading
Loading