Skip to content
Closed
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
12 changes: 12 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[target.wasm32-unknown-unknown]
rustflags = [
"-C", "target-feature=+crt-static",
"-C", "link-arg=--import-memory",
"-C", "link-arg=--initial-memory=2097152",
"-C", "link-arg=--max-memory=2097152",
"-C", "link-arg=--stack-first",
"-C", "link-arg=--export-table",
]

# [build]
# target = "wasm32-unknown-unknown" # Commented out to allow workspace to build for native
39 changes: 25 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
[package]
name = "sp_client"
version = "0.1.0"
edition = "2021"

[lib]
name = "sp_client"
crate-type = ["lib", "staticlib", "cdylib"]
[workspace]
members = [
"sp-client",
"backend-blindbit-native",
"backend-blindbit-wasm",
]
resolver = "2"

[dependencies]
[workspace.dependencies]
# Core dependencies - shared across crates
silentpayments = "0.4"
anyhow = "1.0"
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107"
bitcoin = { version = "0.31.1", features = ["serde", "rand", "base64"] }
rayon = "1.10.0"
bip39 = { version = "2.2.0" }
futures = "0.3"
log = "0.4"
async-trait = "0.1"
reqwest = { version = "0.12.4", features = ["rustls-tls", "gzip", "json"], default-features = false, optional = true }
hex = { version = "0.4.3", features = ["serde"], optional = true }
hex = { version = "0.4.3", features = ["serde"] }
bdk_coin_select = "0.4.0"

[features]
blindbit-backend = ["reqwest", "hex"]
# Performance dependencies (optional)
rayon = "1.10.0"

# Native backend dependencies
reqwest = { version = "0.12.4", features = ["rustls-tls", "gzip", "json"], default-features = false }

# WASM dependencies (for future use)
wasm-bindgen = "0.2"

[workspace.package]
name = "sp-client"
version = "0.1.0"
edition = "2021"
repository = "https://github.com/cygnet3/sp-client"
90 changes: 90 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Compilation Testing Guide

This workspace is designed to support multiple architectures with clean separation. Here's how to test all compilation scenarios:

## Quick Test All Scenarios

```bash
./test-compilation.sh
```

## Manual Testing Commands

### Core Client Tests
```bash
# Default compilation (native)
cargo check -p sp-client

# With parallel processing feature
cargo check -p sp-client --features parallel

# No features
cargo check -p sp-client --no-default-features

# WASM compilation (should work)
cargo check -p sp-client --target wasm32-unknown-unknown
```

### Backend Tests
```bash
# Native compilation (should work)
cargo check -p backend-blindbit-native

# WASM compilation (should FAIL)
cargo check -p backend-blindbit-native --target wasm32-unknown-unknown
```

### Workspace Tests
```bash
# All features
cargo check --workspace --all-features

# No features
cargo check --workspace --no-default-features

# Default
cargo check --workspace
```

## Expected Results

| Command | Target | Result |
|---------|--------|--------|
| `sp-client` | native | ✅ Pass |
| `sp-client` | wasm32 | ✅ Pass |
| `backend-blindbit-native` | native | ✅ Pass |
| `backend-blindbit-native` | wasm32 | ❌ Fail (expected) |
| `workspace` | native | ✅ Pass |

## Architecture Goals

- **Core client (`sp-client`)**: Architecture-agnostic, minimal dependencies
- **Native backend (`backend-blindbit-native`)**: Native-only, full functionality
- **Future WASM backend (`backend-blindbit-wasm`)**: WASM-specific implementation
- **Future backends**: `backend-electrum-native`, `backend-esplora-native`, etc.

## Feature Flags

- `parallel`: Enable parallel processing in core client (native performance optimization)
- No backend-specific feature flags needed - use separate crates instead

## CI/CD Integration

Add these commands to your CI pipeline:

```yaml
# Test all compilation scenarios
- name: Test compilation scenarios
run: ./test-compilation.sh

# Test specific targets
- name: Test WASM
run: cargo check -p sp-client --target wasm32-unknown-unknown

- name: Test native backend fails on WASM
run: |
if cargo check -p backend-blindbit-native --target wasm32-unknown-unknown; then
echo "ERROR: Backend should not compile for WASM"
exit 1
fi
```
29 changes: 29 additions & 0 deletions backend-blindbit-native/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "backend-blindbit-native"
version.workspace = true
edition.workspace = true
repository.workspace = true

[dependencies]
# Core client dependency
sp-client = { path = "../sp-client" }

# Async and futures
futures.workspace = true
async-trait.workspace = true
log.workspace = true

# Native-specific dependencies
rayon.workspace = true
reqwest.workspace = true

# Re-export some core types for convenience
bitcoin.workspace = true
anyhow.workspace = true
silentpayments.workspace = true
serde.workspace = true
serde_json.workspace = true
hex.workspace = true

[features]
default = []
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use async_trait::async_trait;
use bitcoin::{absolute::Height, Amount};
use futures::Stream;

use super::structs::{BlockData, SpentIndexData, UtxoData};
use sp_client::{BlockData, SpentIndexData, UtxoData};

#[async_trait]
pub trait ChainBackend {
Expand Down
6 changes: 6 additions & 0 deletions backend-blindbit-native/src/backend/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mod backend;
mod blindbit;

pub use backend::ChainBackend;
pub use blindbit::BlindbitBackend;
pub use blindbit::BlindbitClient;
10 changes: 10 additions & 0 deletions backend-blindbit-native/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![allow(clippy::module_inception)]
mod backend;
mod scanner;

// Re-export backend functionality
pub use backend::{BlindbitBackend, BlindbitClient, ChainBackend};
pub use scanner::SpScanner;

// Re-export core client for convenience (includes Updater)
pub use sp_client::*;
Loading
Loading