Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
179 commits
Select commit Hold shift + click to select a range
f107236
fix(platform-wallet): classify Core's broadcast verdicts and plan the…
jeanpierreroma Sep 25, 2026
8fc59af
chore(platform-wallet): log each node's answer to a broadcast probe; …
jeanpierreroma Sep 29, 2026
64b00b8
feat(platform-wallet): probe unconfirmed sends whose broadcast outcom…
jeanpierreroma Sep 29, 2026
91455b7
feat(platform-wallet-ffi,swift-sdk): deliver broadcast-probe verdicts…
jeanpierreroma Sep 29, 2026
9d14476
chore(platform-wallet): log the height and trigger of each broadcast …
jeanpierreroma Sep 29, 2026
c5f3a17
fix(platform-wallet): address review of the broadcast probe
jeanpierreroma Sep 29, 2026
4506258
fix(platform-wallet): second review pass on the broadcast resolver
jeanpierreroma Sep 29, 2026
9f7ec32
refactor(platform-wallet): move the abandon planner to its own change
jeanpierreroma Sep 29, 2026
3e0e112
fix(platform-wallet): third review pass on the broadcast resolver
jeanpierreroma Sep 29, 2026
e0650a1
fix(platform-wallet): fourth review pass on the broadcast resolver
jeanpierreroma Sep 29, 2026
3c5e1a4
fix(platform-wallet): fifth review pass on the broadcast resolver
jeanpierreroma Sep 29, 2026
c17b576
fix(platform-wallet): sixth review pass on the broadcast resolver
jeanpierreroma Sep 29, 2026
b8bbda7
refactor(platform-wallet): run the broadcast resolver as one actor task
jeanpierreroma Sep 29, 2026
150355a
fix(platform-wallet): eighth review pass on the broadcast resolver
jeanpierreroma Sep 29, 2026
de8a8df
fix(platform-wallet): ninth review pass on the broadcast resolver
jeanpierreroma Sep 29, 2026
9ceb6c4
fix(platform-wallet): tenth review pass on the broadcast resolver
jeanpierreroma Sep 29, 2026
ce4d6aa
fix(platform-wallet): eleventh review pass on the broadcast resolver
jeanpierreroma Sep 29, 2026
750e720
fix(platform-wallet): twelfth review pass on the broadcast resolver
jeanpierreroma Sep 29, 2026
4d607e6
fix(platform-wallet): thirteenth review pass on the broadcast resolver
jeanpierreroma Sep 29, 2026
d1acc1b
refactor(platform-wallet): drop the forced-probe dedup from the broad…
jeanpierreroma Sep 30, 2026
dfb8811
fix(platform-wallet): fifteenth review pass on the broadcast resolver
jeanpierreroma Sep 30, 2026
e554418
fix(platform-wallet): sixteenth review pass on the broadcast resolver
jeanpierreroma Sep 30, 2026
0bb14a2
fix(platform-wallet): seventeenth review pass on the broadcast resolver
jeanpierreroma Sep 30, 2026
f44785f
fix(platform-wallet): eighteenth review pass on the broadcast resolver
jeanpierreroma Sep 30, 2026
fc6606b
fix(platform-wallet): nineteenth review pass on the broadcast resolver
jeanpierreroma Sep 30, 2026
8978342
fix(platform-wallet): twentieth review pass on the broadcast resolver
jeanpierreroma Sep 30, 2026
cf55790
fix(platform-wallet): twenty-first review pass on the broadcast resolver
jeanpierreroma Sep 30, 2026
4de07e2
fix(platform-wallet): twenty-second review pass on the broadcast reso…
jeanpierreroma Sep 30, 2026
4008d90
refactor(platform-wallet): clear broadcast verdicts from wallet events
jeanpierreroma Sep 30, 2026
7f91f5c
fix(platform-wallet): twenty-fourth review pass on the broadcast reso…
jeanpierreroma Sep 30, 2026
7c1a285
fix(platform-wallet): twenty-fifth review pass on the broadcast resolver
jeanpierreroma Sep 30, 2026
dcb2d7b
fix(platform-wallet): twenty-sixth review pass on the broadcast resolver
jeanpierreroma Sep 30, 2026
7dbf83b
fix(platform-wallet): twenty-seventh review pass on the broadcast res…
jeanpierreroma Sep 30, 2026
2d0333c
fix(platform-wallet): twenty-eighth review pass on the broadcast reso…
jeanpierreroma Sep 30, 2026
026c83f
fix(platform-wallet): twenty-ninth review pass on the broadcast resolver
jeanpierreroma Sep 30, 2026
f298cdb
fix(platform-wallet): thirtieth review pass on the broadcast resolver
jeanpierreroma Sep 30, 2026
4f0ba99
fix(platform-wallet): thirty-first review pass on the broadcast resolver
jeanpierreroma Sep 30, 2026
23c22dd
fix(platform-wallet): thirty-second review pass on the broadcast reso…
jeanpierreroma Sep 30, 2026
683ff6f
refactor(platform-wallet): one probe per Uncertain report, no re-rooting
jeanpierreroma Sep 30, 2026
ebe1482
fix(platform-wallet): thirty-fourth review pass on the broadcast reso…
jeanpierreroma Sep 30, 2026
5eb00b6
fix(platform-wallet): thirty-fifth review pass on the broadcast resolver
jeanpierreroma Sep 30, 2026
21bcccd
fix(platform-wallet): thirty-sixth review pass on the broadcast resolver
jeanpierreroma Sep 30, 2026
fedad58
fix(platform-wallet): Mined takes two nodes; thirty-seventh review pass
jeanpierreroma Sep 30, 2026
dc84d0a
fix(platform-wallet): a node that has it in a block rules out Dead
jeanpierreroma Sep 30, 2026
f84f2e6
fix(platform-wallet): remember "seen in a block" across probes; thirt…
jeanpierreroma Sep 30, 2026
50d1eec
fix(platform-wallet): add up "in a block" reports into a Mined quorum…
jeanpierreroma Sep 30, 2026
bb47d6a
fix(platform-wallet): stop a running probe pass on a rewind
jeanpierreroma Sep 30, 2026
fbc1c6b
fix(platform-wallet): hold the change of a send the network has not a…
jeanpierreroma Oct 2, 2026
cdc07ff
fix(platform-wallet): hold every coin of an unresolved send, not only…
jeanpierreroma Oct 2, 2026
5fcf610
fix(platform-wallet): exclude unresolved-send coins through key-walle…
jeanpierreroma Oct 2, 2026
3634e3a
fix(platform-wallet): review follow-ups to the unresolved-send hold
jeanpierreroma Oct 2, 2026
b59f0b8
fix(platform-wallet): deterministic, synchronous acceptance and one s…
jeanpierreroma Oct 2, 2026
df35c9b
build(deps): pin rust-dashcore to the outpoint-exclusion branch (rust…
jeanpierreroma Oct 2, 2026
efca50f
fix(platform-wallet-ffi): pass the probe callback in the shielded tes…
jeanpierreroma Oct 2, 2026
ddf3bee
revert: drop the unresolved-send hold and the rust-dashcore#1100 pin
jeanpierreroma Oct 3, 2026
f4937c4
fix(platform-wallet): spend only final coins, and say when funds wait…
jeanpierreroma Oct 3, 2026
ed513b0
fix(platform-wallet): call a missing-input refusal dead only when its…
jeanpierreroma Oct 3, 2026
d177a71
fix(platform-wallet): keep the resolver task joinable when a stop is …
jeanpierreroma Oct 3, 2026
7e72863
fix(platform-wallet): accept a send a peer echoes after its Uncertain…
jeanpierreroma Oct 3, 2026
7c60abd
fix(platform-wallet): price the fee before calling a shortfall "waiti…
jeanpierreroma Oct 3, 2026
9710e76
test(platform-wallet): prove a stop tears down the running probe; nam…
jeanpierreroma Oct 3, 2026
23d7d09
test(platform-wallet): name the scripted parent-lookup queue type
jeanpierreroma Oct 3, 2026
47d84a0
fix(platform-wallet): quorum per refusal class, ChainLocked parents, …
jeanpierreroma Oct 3, 2026
7c9fddf
fix(platform-wallet): drop a late acceptance once its send settled
jeanpierreroma Oct 3, 2026
95e4a52
fix(platform-wallet): size code 59 at the build's fee rate, amount an…
jeanpierreroma Oct 3, 2026
8df6c94
refactor(platform-wallet): drop the Dead probe verdict
jeanpierreroma Oct 3, 2026
fdbd4f0
fix(platform-wallet): check the shortfall fees and price every output
jeanpierreroma Oct 3, 2026
5c658b5
fix(platform-wallet): refuse a selected input that is not final any more
jeanpierreroma Oct 3, 2026
ad1d25e
fix(platform-wallet): price a waiting shortfall with the drain, a zer…
jeanpierreroma Oct 3, 2026
e6ba44e
docs(platform-wallet): document the final-inputs API migration
jeanpierreroma Oct 3, 2026
4b5f9c9
fix(platform-wallet-ffi): keep FFITransactionBuilder C-representable
jeanpierreroma Oct 3, 2026
0fbb611
fix(platform-wallet): persist a send's InstantSend lock on its row
jeanpierreroma Oct 3, 2026
bdebf35
fix(platform-wallet): an own send is one the wallet signed
jeanpierreroma Oct 4, 2026
8a87b82
fix(platform-wallet)!: decide code 59 with a key-wallet trial build
jeanpierreroma Oct 4, 2026
c32b338
fix(platform-wallet): fund the waiting-coins trial the way the build …
jeanpierreroma Oct 4, 2026
d826f30
fix(platform-wallet): trial clones nothing without waiting coins, rel…
jeanpierreroma Oct 4, 2026
1a8631f
fix(platform-wallet-ffi): check only the fee rate the build uses
jeanpierreroma Oct 4, 2026
643ca81
fix(platform-wallet): no waiting promise on a coin an in-flight broad…
jeanpierreroma Oct 4, 2026
30ca085
fix(platform-wallet): pass over pinned coins in the trial; factory co…
jeanpierreroma Oct 4, 2026
c171358
fix(platform-wallet): trial leaves every change pool alone; pinned se…
jeanpierreroma Oct 4, 2026
14eec6a
refactor(platform-wallet): one funding fold for the build and its trial
jeanpierreroma Oct 4, 2026
85816b2
fix(platform-wallet): make the trial only when a coin is waiting
jeanpierreroma Oct 4, 2026
479600b
fix(platform-wallet): refuse a pinned chosen input by name; one scan …
jeanpierreroma Oct 4, 2026
630d11e
fix(platform-wallet): one pin snapshot per finalize, checked before f…
jeanpierreroma Oct 4, 2026
e807041
refactor(platform-wallet): prune the fence map in one place, snapshot…
jeanpierreroma Oct 4, 2026
7c7e859
fix(platform-wallet-ffi): refuse an overflowing fee rate where it is set
jeanpierreroma Oct 4, 2026
c7151fa
fix(platform-wallet): outside seeds stay candidates; factory dropped …
jeanpierreroma Oct 4, 2026
2532b26
fix(platform-wallet): leave out chosen inputs no funding account can …
jeanpierreroma Oct 4, 2026
cb60da8
fix(platform-wallet): never drop a chosen input silently
jeanpierreroma Oct 4, 2026
51eb651
fix(platform-wallet): typed refusal for an unusable chosen input; R16…
jeanpierreroma Oct 4, 2026
f622aad
fix(platform-wallet): waiting coins may also cure too many inputs; R1…
jeanpierreroma Oct 4, 2026
6a14c06
fix(platform-wallet): one ancestry walk per pass; node-reported minin…
jeanpierreroma Oct 4, 2026
c3a38d7
fix(platform-wallet): withdraw stale mined evidence with what it carried
jeanpierreroma Oct 4, 2026
76d058a
fix(platform-wallet): count mined grace from the reported block; keep…
jeanpierreroma Oct 4, 2026
280a46a
fix(platform-wallet): drop a needless conversion of the lookup height
jeanpierreroma Oct 4, 2026
f5d4903
fix(platform-wallet): bound and sanity-check node-named block heights…
jeanpierreroma Oct 4, 2026
3dab0e0
test(platform-wallet): expect the typed refusal from a trial that nee…
jeanpierreroma Oct 4, 2026
072c07e
fix(platform-wallet): judge passed-block reports only while following…
jeanpierreroma Oct 4, 2026
b57c5e5
fix(platform-wallet): judge a probe answer by the run's anchor when i…
jeanpierreroma Oct 4, 2026
cc572f4
refactor(platform-wallet)!: make node-reported Mined advisory and non…
jeanpierreroma Oct 4, 2026
006dbad
test(platform-wallet): pin roots() walk cost and the echo's clear
jeanpierreroma Oct 4, 2026
f24bd70
fix(platform-wallet): duplicate prevouts in the trial, lookup normali…
jeanpierreroma Oct 4, 2026
e7d5330
fix(platform-wallet): check chosen inputs and lookup replies once, an…
jeanpierreroma Oct 4, 2026
7737ba1
fix(platform-wallet): keep uncertainty entries across re-registration…
jeanpierreroma Oct 4, 2026
bbb025b
fix(platform-wallet): tie uncertainty lookups to their entry; a misma…
jeanpierreroma Oct 4, 2026
86ea4be
fix(platform-wallet): one refusal order for build and trial; re-regis…
jeanpierreroma Oct 4, 2026
3c7a951
refactor(platform-wallet): expire uncertain sends instead of tracking…
jeanpierreroma Oct 4, 2026
7805d18
fix(platform-wallet): run echo windows on one followed clock
jeanpierreroma Oct 4, 2026
5a8df0a
fix(platform-wallet): a catch-up jump holds the echo clock; one pass …
jeanpierreroma Oct 4, 2026
1d7b8a7
docs(platform-wallet): immature coinbase matures; pin helper lifetime…
jeanpierreroma Oct 4, 2026
f1315ce
Merge origin/v5.0-dev into fix/resolve-unknown-broadcast
jeanpierreroma Oct 4, 2026
70240c0
fix(platform-wallet): pre-signing resident check refuses unspendable …
jeanpierreroma Oct 4, 2026
5e9eecb
fix(platform-wallet): refuse unspendable coins across the whole input…
jeanpierreroma Oct 4, 2026
71da918
test(platform-wallet): hold the task in the stop regressions instead …
jeanpierreroma Oct 4, 2026
f61b2c3
test(platform-wallet): make the concurrent-stop regression determinis…
jeanpierreroma Oct 4, 2026
6941645
fix(platform-wallet): probe again once the network is back, not at th…
jeanpierreroma Oct 5, 2026
334d597
fix(platform-wallet): retry every unanswered root, anchor end-of-catc…
jeanpierreroma Oct 5, 2026
d8e8192
fix(platform-wallet): retry unanswered probes by anchored pass with b…
jeanpierreroma Oct 5, 2026
4fceeda
fix(platform-wallet): retry only passes that followed the tip; log ev…
jeanpierreroma Oct 5, 2026
9c34315
fix(platform-wallet): close the remaining recovery gaps in completion…
jeanpierreroma Oct 5, 2026
8ba4459
refactor(platform-wallet): simplify network recovery; answered beside…
jeanpierreroma Oct 5, 2026
217c8ce
fix(platform-wallet): a completion leaves an unanswered height to its…
jeanpierreroma Oct 5, 2026
5a2688a
fix(platform-wallet): an unanswered root is due at the next height; o…
jeanpierreroma Oct 5, 2026
be51cf4
fix(platform-wallet): retry forced passes without windows; no second …
jeanpierreroma Oct 5, 2026
975c7ae
fix(platform-wallet): an empty retry costs nothing; a node's answer s…
jeanpierreroma Oct 5, 2026
e557f47
fix(platform-wallet): keep the anchored mark when a probe joins a wai…
jeanpierreroma Oct 5, 2026
c42d3ea
fix(platform-wallet): classify broken streams by source; retry only c…
jeanpierreroma Oct 5, 2026
9b0b453
fix(platform-wallet): a channel that never opened, or a gateway's pla…
jeanpierreroma Oct 5, 2026
cb90fb8
Merge branch 'v5.0-dev' into fix/resolve-unknown-broadcast
jeanpierreroma Oct 5, 2026
70c3a1f
fix(platform-wallet): fence an Uncertain holder lookup to the report …
jeanpierreroma Oct 5, 2026
bc501c9
fix(platform-wallet): withdraw report lookups with a wallet; name the…
jeanpierreroma Oct 5, 2026
2e54ac4
fix(platform-wallet): bound each pass's probes and let an Uncertain s…
jeanpierreroma Oct 5, 2026
546f821
fix(platform-wallet): queue backlog roots by first sight; keep window…
jeanpierreroma Oct 5, 2026
6ca498e
fix(platform-wallet): keep Uncertain sends first through a backlog; n…
jeanpierreroma Oct 5, 2026
80d4f00
fix(platform-wallet): keep reported sends first for good; the forced …
jeanpierreroma Oct 5, 2026
3a93004
fix(platform-wallet): share a pass between reported and other roots; …
jeanpierreroma Oct 5, 2026
4e1881a
fix(platform-wallet): give way once per height; a retry does not take…
jeanpierreroma Oct 5, 2026
aacb0a9
fix(platform-wallet): spend the per-height yield only when it drops r…
jeanpierreroma Oct 5, 2026
17e3fa8
fix(platform-wallet): a yield hands no anchor on; key the allowance o…
jeanpierreroma Oct 5, 2026
95e831f
fix(platform-wallet): a panicking probe goes to the back of the queue…
jeanpierreroma Oct 5, 2026
aa9b0cd
fix(platform-wallet): keep a finished report across a wallet change; …
jeanpierreroma Oct 5, 2026
caa81e2
docs(platform-wallet): report lookups and the give-way rule as they n…
jeanpierreroma Oct 5, 2026
d2c3b1a
test(platform-wallet): deliver the finished lookup after the wallet c…
jeanpierreroma Oct 5, 2026
9e7257f
test(platform-wallet): pin the reissuance test to the new lookup's re…
jeanpierreroma Oct 5, 2026
28e5934
Merge branch 'v5.0-dev' into fix/resolve-unknown-broadcast
romchornyi Oct 12, 2026
d96c457
fix(platform-wallet): probe a send only under its wallet generation's…
jeanpierreroma Oct 12, 2026
6676b56
fix(platform-wallet): withdraw an abandoned teardown's request; unwin…
jeanpierreroma Oct 12, 2026
26517a7
fix(platform-wallet): keep a forced probe a removal stopped; roll a l…
jeanpierreroma Oct 12, 2026
ae5f49a
fix(platform-wallet): leave the rollbacks ungated; undo a stopped pro…
jeanpierreroma Oct 12, 2026
9f85ccb
refactor(platform-wallet): wait a removal out inside the gated probe
jeanpierreroma Oct 12, 2026
a48cb85
fix(platform-wallet): keep a finished probe's verdict when a removal …
jeanpierreroma Oct 12, 2026
a9babfb
fix(swift-sdk): drop probe verdicts queued for a wallet deleted meanw…
jeanpierreroma Oct 12, 2026
6b4a742
Merge remote-tracking branch 'origin/v5.0-dev' into fix/resolve-unkno…
jeanpierreroma Oct 12, 2026
44d5d39
refactor(platform-wallet): narrow this branch to the broadcast probe …
jeanpierreroma Oct 12, 2026
6f59c3a
fix(platform-wallet): bound the probing of a root and wake an idle wa…
jeanpierreroma Oct 12, 2026
9f16bef
Merge remote-tracking branch 'origin/v5.0-dev' into fix/resolve-unkno…
jeanpierreroma Oct 13, 2026
990ee4c
fix(platform-wallet): bound the roots one report or retry forces in a…
jeanpierreroma Oct 13, 2026
97fb634
fix(platform-wallet): look an echo up again when a wallet changes und…
jeanpierreroma Oct 13, 2026
e7690ee
fix(platform-wallet): run the pass at the tip when a sync's completio…
jeanpierreroma Oct 13, 2026
3c27f1d
test(platform-wallet): drive the lossless wake through the manager's …
jeanpierreroma Oct 13, 2026
81bed29
fix(platform-wallet): finish a removal only once the resolver is past it
jeanpierreroma Oct 13, 2026
d2cb5fe
Merge remote-tracking branch 'origin/v5.0-dev' into fix/resolve-unkno…
jeanpierreroma Oct 13, 2026
343c7fc
fix(platform-wallet): keep named forced roots and tighten the overtak…
jeanpierreroma Oct 13, 2026
69ab258
fix(platform-wallet): wait for the resolver after the removal is comp…
jeanpierreroma Oct 13, 2026
1612897
fix(platform-wallet): second local review of the resolver fixes
jeanpierreroma Oct 13, 2026
a8ffadc
fix(platform-wallet): third local review of the resolver fixes
jeanpierreroma Oct 13, 2026
12ca35e
Merge remote-tracking branch 'origin/v5.0-dev' into fix/resolve-unkno…
jeanpierreroma Oct 13, 2026
c23604d
fix(platform-wallet): recover a lost height step and a late echo afte…
jeanpierreroma Oct 13, 2026
0c96e22
fix(platform-wallet): take the wallet's height from the pass a comple…
jeanpierreroma Oct 13, 2026
bba5408
refactor(platform-wallet)!: drop the Mined probe verdict
jeanpierreroma Oct 13, 2026
e8c1fb6
Merge remote-tracking branch 'origin/v5.0-dev' into fix/resolve-unkno…
jeanpierreroma Oct 13, 2026
17ec1ca
refactor(platform-wallet): simplify what is left after the Mined verdict
jeanpierreroma Oct 13, 2026
ef801dd
fix(platform-wallet): keep the found height apart from the step curso…
jeanpierreroma Oct 13, 2026
efb536d
fix(platform-wallet): take the lost-step recovery back out, keep the …
jeanpierreroma Oct 13, 2026
7c17750
test(platform-wallet): assert the probe request's own deadline in its…
jeanpierreroma Oct 13, 2026
641675f
test(platform-wallet): pin how the DAPI broadcaster reads each answer
jeanpierreroma Oct 14, 2026
3468910
fix(platform-wallet): forget a send a forced read finds gone, and loo…
jeanpierreroma Oct 14, 2026
374d70f
Merge branch 'v5.0-dev' into fix/resolve-unknown-broadcast
romchornyi Oct 14, 2026
fa73ece
Merge branch 'v5.1-dev' into fix/resolve-unknown-broadcast
jeanpierreroma Oct 19, 2026
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
196 changes: 196 additions & 0 deletions packages/rs-platform-wallet-ffi/src/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ use crate::platform_address_sync::{
PlatformAddressSyncMetricsFFI, PlatformAddressSyncWalletResultFFI,
};
use crate::shielded_types::ShieldedSyncWalletResultFFI;
use dashcore::Txid;
use platform_wallet::broadcast_probe::ProbeVerdict;
use platform_wallet::events::{EventHandler, PlatformEventHandler, WalletEvent};
use platform_wallet::manager::dpns_sync::{DpnsSyncPassSummary, WalletDpnsSyncOutcome};
#[cfg(feature = "shielded")]
use platform_wallet::manager::shielded_sync::{ShieldedSyncPassSummary, WalletShieldedOutcome};
use platform_wallet::{PlatformAddressSyncSummary, WalletSyncOutcome};
use std::ffi::CString;
use std::os::raw::{c_char, c_void};

/// Current layout version of [`EventHandlerCallbacksExtension`].
Expand Down Expand Up @@ -49,6 +52,32 @@ pub type DpnsMarketplaceSyncCompletedFn = unsafe extern "C" fn(
sync_unix_seconds: u64,
);

/// Verdict codes for [`OutgoingTransactionProbedFn`].
/// A node holds the send, in its mempool or in a block.
pub const OUTGOING_PROBE_VERDICT_ACCEPTED: u8 = 0;
/// Reserved; not emitted by this version.
pub const OUTGOING_PROBE_VERDICT_DEAD: u8 = 1;
pub const OUTGOING_PROBE_VERDICT_UNRESOLVED: u8 = 2;
/// Not a verdict: drop whatever was kept for the send's earlier verdict. Sent
/// when the send settled or left the wallet, when its wallet was removed, and
/// for every send when probing is turned off — so it does not mean the send
/// settled. `reason` is null.
pub const OUTGOING_PROBE_VERDICT_CLEARED: u8 = 3;

/// A verdict on an unconfirmed send whose broadcast outcome was unknown.
/// `wallet_id` and `txid` point to 32 bytes each; `txid` is in wire
/// (internal) byte order — reverse it for the display hex. `verdict` is one of
/// the `OUTGOING_PROBE_VERDICT_*` codes; `reason` is null for `ACCEPTED` and
/// `CLEARED`, otherwise a NUL-terminated diagnostic string (never user-facing
/// copy). All pointers are valid only for the duration of the call.
pub type OutgoingTransactionProbedFn = unsafe extern "C" fn(
context: *mut c_void,
wallet_id: *const u8,
txid: *const u8,
verdict: u8,
reason: *const c_char,
);

/// Size/version-tagged event extension. It shares the legacy event
/// vtable's context and destructor; only callback pointers are copied.
/// This avoids growing [`EventHandlerCallbacks`] and over-reading callers
Expand All @@ -70,6 +99,17 @@ pub struct EventHandlerCallbacksExtension {
sync_unix_seconds: u64,
),
>,
/// Appended within version 1: a host whose `struct_size` stops before
/// this slot simply never receives it. See [`OutgoingTransactionProbedFn`].
pub on_outgoing_transaction_probed_fn: Option<
unsafe extern "C" fn(
context: *mut c_void,
wallet_id: *const u8,
txid: *const u8,
verdict: u8,
reason: *const c_char,
),
>,
}

impl Default for EventHandlerCallbacksExtension {
Expand All @@ -79,6 +119,7 @@ impl Default for EventHandlerCallbacksExtension {
version: PLATFORM_WALLET_EVENT_CALLBACKS_EXTENSION_VERSION,
reserved: 0,
on_dpns_marketplace_sync_completed_fn: None,
on_outgoing_transaction_probed_fn: None,
}
}
}
Expand Down Expand Up @@ -189,16 +230,19 @@ unsafe impl Sync for EventHandlerCallbacks {}
pub(crate) struct FFIEventHandler {
callbacks: EventHandlerCallbacks,
dpns_sync_callback: Option<DpnsMarketplaceSyncCompletedFn>,
outgoing_probe_callback: Option<OutgoingTransactionProbedFn>,
}

impl FFIEventHandler {
pub fn new(
callbacks: EventHandlerCallbacks,
dpns_sync_callback: Option<DpnsMarketplaceSyncCompletedFn>,
outgoing_probe_callback: Option<OutgoingTransactionProbedFn>,
) -> Self {
Self {
callbacks,
dpns_sync_callback,
outgoing_probe_callback,
}
}
}
Expand Down Expand Up @@ -250,6 +294,53 @@ impl EventHandler for FFIEventHandler {
}

impl PlatformEventHandler for FFIEventHandler {
fn on_outgoing_transaction_cleared(&self, wallet_id: &[u8; 32], txid: &Txid) {
let Some(callback) = self.outgoing_probe_callback else {
return;
};
let txid_bytes: &[u8] = txid.as_ref();
unsafe {
callback(
self.callbacks.context,
wallet_id.as_ptr(),
txid_bytes.as_ptr(),
OUTGOING_PROBE_VERDICT_CLEARED,
std::ptr::null(),
);
}
}

fn on_outgoing_transaction_probed(
&self,
wallet_id: &[u8; 32],
txid: &Txid,
verdict: &ProbeVerdict,
) {
let Some(callback) = self.outgoing_probe_callback else {
return;
};
let (code, reason) = match verdict {
// The host does not need to tell a mempool from a block: both mean
// the payment is going through.
ProbeVerdict::Accepted => (OUTGOING_PROBE_VERDICT_ACCEPTED, None),
ProbeVerdict::Unresolved { reason } => {
(OUTGOING_PROBE_VERDICT_UNRESOLVED, Some(reason))
}
};
// A reason is a node's text: strip interior NULs rather than lose it.
let reason = reason.and_then(|reason| CString::new(reason.replace('\0', "")).ok());
let txid_bytes: &[u8] = txid.as_ref();
unsafe {
callback(
self.callbacks.context,
wallet_id.as_ptr(),
txid_bytes.as_ptr(),
code,
reason.as_ref().map_or(std::ptr::null(), |r| r.as_ptr()),
);
}
}

fn on_dpns_marketplace_sync_completed(&self, summary: &DpnsSyncPassSummary) {
let Some(callback) = self.dpns_sync_callback else {
return;
Expand Down Expand Up @@ -496,6 +587,7 @@ mod release_tests {
release_fn: None,
},
None,
None,
);
handler.on_shielded_sync_completed(&ShieldedSyncPassSummary {
wallet_results: BTreeMap::from([
Expand Down Expand Up @@ -567,6 +659,7 @@ mod release_tests {
release_fn: Some(count_release),
},
None,
None,
));
let straggler = Arc::clone(&handler);

Expand All @@ -577,3 +670,106 @@ mod release_tests {
assert_eq!(releases.load(Ordering::SeqCst), 1);
}
}

#[cfg(test)]
mod outgoing_probe_callback_tests {
use std::ffi::CStr;
use std::sync::Mutex;

use dashcore::hashes::Hash;
use platform_wallet::broadcast_probe::ProbeVerdict;

use super::*;

/// (wallet_id, txid, verdict, reason) of one call.
type Call = ([u8; 32], [u8; 32], u8, Option<String>);

static CALLS: Mutex<Vec<Call>> = Mutex::new(Vec::new());

unsafe extern "C" fn record(
_context: *mut c_void,
wallet_id: *const u8,
txid: *const u8,
verdict: u8,
reason: *const c_char,
) {
let wallet_id = std::ptr::read(wallet_id as *const [u8; 32]);
let txid = std::ptr::read(txid as *const [u8; 32]);
let reason =
(!reason.is_null()).then(|| CStr::from_ptr(reason).to_string_lossy().into_owned());
CALLS
.lock()
.expect("calls")
.push((wallet_id, txid, verdict, reason));
}

fn handler(probe: Option<OutgoingTransactionProbedFn>) -> FFIEventHandler {
FFIEventHandler::new(
EventHandlerCallbacks {
context: std::ptr::null_mut(),
on_wallet_event_fn: None,
on_error_fn: None,
on_platform_address_sync_completed_fn: None,
on_shielded_sync_completed_fn: None,
..unsafe { std::mem::zeroed() }
},
None,
probe,
)
}

/// One test drives every case so the shared capture is never raced by a
/// parallel test.
#[test]
fn should_deliver_each_verdict_with_its_code_wire_txid_and_reason() {
CALLS.lock().expect("calls").clear();
let wallet = [7u8; 32];
let txid = dashcore::Txid::from_byte_array([
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32,
]);
let with_callback = handler(Some(record));

with_callback.on_outgoing_transaction_probed(&wallet, &txid, &ProbeVerdict::Accepted);
with_callback.on_outgoing_transaction_probed(
&wallet,
&txid,
&ProbeVerdict::Unresolved {
reason: "no quorum".to_string(),
},
);
with_callback.on_outgoing_transaction_probed(
&wallet,
&txid,
&ProbeVerdict::Unresolved {
reason: "odd\0node".to_string(),
},
);
with_callback.on_outgoing_transaction_cleared(&wallet, &txid);
// A host without the slot receives nothing.
handler(None).on_outgoing_transaction_probed(&wallet, &txid, &ProbeVerdict::Accepted);
handler(None).on_outgoing_transaction_cleared(&wallet, &txid);

let calls = CALLS.lock().expect("calls").clone();
let wire: [u8; 32] = *txid.as_byte_array();
assert_eq!(
calls,
vec![
(wallet, wire, OUTGOING_PROBE_VERDICT_ACCEPTED, None),
(
wallet,
wire,
OUTGOING_PROBE_VERDICT_UNRESOLVED,
Some("no quorum".to_string())
),
(
wallet,
wire,
OUTGOING_PROBE_VERDICT_UNRESOLVED,
Some("oddnode".to_string())
),
(wallet, wire, OUTGOING_PROBE_VERDICT_CLEARED, None),
]
);
}
}
Loading
Loading