Skip to content

feat: add UniFFI callback traits for event dispatch#12

Merged
xdustinface merged 4 commits into
v0.42-devfrom
claude/issue-8-20260313-1122
Mar 13, 2026
Merged

feat: add UniFFI callback traits for event dispatch#12
xdustinface merged 4 commits into
v0.42-devfrom
claude/issue-8-20260313-1122

Conversation

@xdustinface
Copy link
Copy Markdown
Owner

Defines UniFFI-compatible event types and callback trait for event dispatch.

Closes #8

  • SyncEvent and NetworkEvent enums with UniFFI derives
  • SpvEventListener callback trait with #[uniffi::export(with_foreign)]
  • Compiles with cargo check -p dash-spv --features uniffi

…tListener

Defines two new `#[derive(uniffi::Enum)]` types in `bridge/mod.rs`:
- `SyncEvent`: flattened bridge version of the internal sync event enum,
  covering all 14 variants with primitive-only fields (BlockHash → String,
  SocketAddr → String, complex types decomposed).
- `NetworkEvent`: bridge version of the internal network event enum
  (PeerConnected, PeerDisconnected, PeersUpdated) using String for addresses.

Expands `SpvEventListener` with:
- `on_sync_event(&self, event: SyncEvent)`
- `on_network_event(&self, event: NetworkEvent)`
- Updated `on_sync_progress` signature with `current_height` and `target_height`

Removes the obsolete `start_mock_sync` placeholder and updates tests.

Closes #8

Co-authored-by: Kevin Rombach <xdustinface@users.noreply.github.com>
@xdustinface
Copy link
Copy Markdown
Owner Author

@claude CI fails with clippy error: called iter().cloned().collect() on a slice to create a Vec. Calling to_vec() is both faster and more readable. Fix this by replacing .iter().cloned().collect() with .to_vec() in the relevant code.

@claude
Copy link
Copy Markdown

claude Bot commented Mar 13, 2026

Claude finished @xdustinface's task in 44s —— View job


Fixing Clippy Lint Error

  • Gather context
  • Find .iter().cloned().collect() usage in code
  • Replace with .to_vec()
  • Commit and push changes

Summary

Fixed two clippy lint warnings in dash-spv/src/bridge/mod.rs:

  • Line 302: events.iter().cloned().collect()events.to_vec() (in test_sync_event_variants)
  • Line 322: events.iter().cloned().collect()events.to_vec() (in test_network_event_variants)

Committed as 47e98a0 and pushed to claude/issue-8-20260313-1122.

Co-authored-by: Kevin Rombach <xdustinface@users.noreply.github.com>
@xdustinface
Copy link
Copy Markdown
Owner Author

@claude CI is still failing on pre-commit checks. It looks like a cargo fmt issue — the code has formatting differences. Please run cargo fmt and commit the result.

@claude
Copy link
Copy Markdown

claude Bot commented Mar 13, 2026

Claude finished @xdustinface's task in 7m 4s —— View job


Fixing Cargo Fmt Formatting Issues

  • Gather context — CI log confirmed cargo fmt modified files
  • Identify formatting difference — import ordering in tests module
  • Apply fix — reorder use std::sync::Mutex before use super::*
  • Commit and push — 50a9314

Summary

The cargo fmt hook was failing because imports in the #[cfg(test)] module were not in the order that rustfmt requires. With reorder_imports = true and group_imports = "StdExternalCrate" set in rustfmt.toml, standard library imports (std::sync::Mutex) must come before local/parent imports (super::*), separated by a blank line.

Change in dash-spv/src/bridge/mod.rs:

// Before
use super::*;
use std::sync::Mutex;

// After
use std::sync::Mutex;

use super::*;

Committed as 50a9314 and pushed to claude/issue-8-20260313-1122.
|

@codecov-commenter
Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Co-authored-by: Kevin Rombach <xdustinface@users.noreply.github.com>
@xdustinface
Copy link
Copy Markdown
Owner Author

@claude Pre-commit is STILL failing with formatting issues. Please run cargo fmt --all (not just cargo fmt) to format ALL crate code including tests, then commit and push.

@claude
Copy link
Copy Markdown

claude Bot commented Mar 13, 2026

Claude finished @xdustinface's task in 2m 2s —— View job


Fixing Cargo Fmt (All Crates)

  • Gather context — downloaded CI log, found exact diff from cargo fmt hook
  • Apply formatting changes manually to dash-spv/src/bridge/mod.rs
  • Commit and push — 62cc9d0

Summary

The cargo fmt --all hook was expanding struct literals that fit on one line into multi-line form (rustfmt's trailing_comma and line-width rules). Applied all changes from the CI diff manually:

  • on_sync_progress: collapsed 4-line method chain to single line
  • assert!(matches!(...)): expanded to multi-line form
  • test_sync_event_variants vec: expanded 8 single-line struct literals to multi-line with trailing commas (SyncStart, BlockHeadersStored, BlockHeaderSyncComplete, FilterHeadersStored, FilterHeadersSyncComplete, FiltersStored, FiltersSyncComplete, BlocksNeeded, MasternodeStateUpdated, ChainLockReceived, InstantLockReceived, SyncComplete)
  • test_network_event_variants vec: expanded PeerConnected and PeerDisconnected to multi-line

Committed as 62cc9d0 and pushed to claude/issue-8-20260313-1122.
|

Co-authored-by: Kevin Rombach <xdustinface@users.noreply.github.com>
@xdustinface xdustinface merged commit 92b0405 into v0.42-dev Mar 13, 2026
52 checks passed
@xdustinface xdustinface deleted the claude/issue-8-20260313-1122 branch March 13, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add UniFFI callback traits for event dispatch

2 participants