Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
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
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions packages/rs-platform-wallet-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ cbindgen = "0.27"
[features]
default = []
mocks = []
# Opt-in Orchard / shielded support. Pulls in the heavy
# `grovedb-commitment-tree` + `zip32` dependencies via
# `platform-wallet/shielded`. Builds that don't enable this feature
# omit every `shielded_*` FFI symbol cleanly.
shielded = ["platform-wallet/shielded"]
67 changes: 67 additions & 0 deletions packages/rs-platform-wallet-ffi/src/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
use crate::platform_address_sync::{
PlatformAddressSyncMetricsFFI, PlatformAddressSyncWalletResultFFI,
};
use crate::shielded_types::ShieldedSyncWalletResultFFI;
use platform_wallet::events::{EventHandler, PlatformEventHandler, WalletEvent};
#[cfg(feature = "shielded")]
use platform_wallet::manager::shielded_sync::{ShieldedSyncPassSummary, WalletShieldedOutcome};
use platform_wallet::{PlatformAddressSyncSummary, WalletSyncOutcome};
use std::os::raw::{c_char, c_void};

Expand Down Expand Up @@ -31,6 +34,19 @@ pub struct EventHandlerCallbacks {
sync_unix_seconds: u64,
),
>,
/// Called when a shielded sync pass completes (only emitted when
/// the `shielded` feature is enabled in the FFI build). The
/// callback slot is plumbed unconditionally so the C ABI is
/// stable across feature toggles, but is only invoked when
/// shielded support is compiled in.
pub on_shielded_sync_completed_fn: Option<
unsafe extern "C" fn(
context: *mut c_void,
results: *const ShieldedSyncWalletResultFFI,
count: usize,
sync_unix_seconds: u64,
),
>,
}

// SAFETY: The context pointer is managed by the FFI caller who must ensure
Expand Down Expand Up @@ -140,4 +156,55 @@ impl PlatformEventHandler for FFIEventHandler {
);
}
}

#[cfg(feature = "shielded")]
fn on_shielded_sync_completed(&self, summary: &ShieldedSyncPassSummary) {
let Some(cb) = self.callbacks.on_shielded_sync_completed_fn else {
return;
};

if summary.wallet_results.is_empty() {
unsafe {
cb(
self.callbacks.context,
std::ptr::null(),
0,
summary.sync_unix_seconds,
);
}
return;
}

let mut owned_errors = Vec::new();
let mut results = Vec::with_capacity(summary.wallet_results.len());
for (&wallet_id, outcome) in &summary.wallet_results {
match outcome {
WalletShieldedOutcome::Ok(result) => {
results.push(ShieldedSyncWalletResultFFI::ok(wallet_id, result));
}
WalletShieldedOutcome::Skipped => {
results.push(ShieldedSyncWalletResultFFI::skipped(wallet_id));
}
WalletShieldedOutcome::Err(error) => {
let error_message = std::ffi::CString::new(error.as_str()).ok();
let error_ptr = error_message
.as_ref()
.map_or(std::ptr::null(), |message| message.as_ptr());
if let Some(error_message) = error_message {
owned_errors.push(error_message);
}
results.push(ShieldedSyncWalletResultFFI::err(wallet_id, error_ptr));
}
}
}

unsafe {
cb(
self.callbacks.context,
results.as_ptr(),
results.len(),
summary.sync_unix_seconds,
);
}
}
}
6 changes: 6 additions & 0 deletions packages/rs-platform-wallet-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ pub mod platform_address_types;
pub mod platform_addresses;
pub mod platform_wallet_info;
mod runtime;
#[cfg(feature = "shielded")]
pub mod shielded_sync;
pub mod shielded_types;
pub mod sign_with_mnemonic_resolver;
pub mod spv;
pub mod token_persistence;
Expand Down Expand Up @@ -103,6 +106,9 @@ pub use platform_address_sync::*;
pub use platform_address_types::*;
pub use platform_addresses::*;
pub use platform_wallet_info::*;
#[cfg(feature = "shielded")]
pub use shielded_sync::*;
pub use shielded_types::*;
pub use sign_with_mnemonic_resolver::*;
pub use spv::*;
pub use token_persistence::*;
Expand Down
Loading
Loading