sdk: expose wallet_child_refresh — a live wallet-child probe over UniFFI
All checks were successful
ci / test (pull_request) Successful in 5m16s
ci / sdk (pull_request) Successful in 1m17s
android-ci / android (pull_request) Successful in 13m18s
ci / fuzz (pull_request) Successful in 18m36s

Wire::wallet_status() is the cheap cached read (no dial); only
Node::wallet_child_refresh() writes state/height/target_height, and it was
reachable over UniFFI from exactly one place — start_wallet_child. An Android
refresh loop polling wallet_status() therefore shows a frozen sync line.

Add the additive export, reusing the existing child_status mapper so the record
is the same shape as wallet_status(), and the core probe as the only probe
path. Docs: one sentence in docs/WALLET.md, which enumerates the SDK
wallet-child surface.

Tests: SDK-level (a Wire cannot be built offline in this crate — open_wire
bootstraps Arti): the unprobed child maps to the same 'off' record both reads
report, pinned with an exhaustive record literal; and the probe on a stopped
handle is a typed WireError.Stopped.
This commit is contained in:
rust-dev 2026-09-20 00:20:32 -04:00
commit db12f4838b
No known key found for this signature in database
2 changed files with 95 additions and 2 deletions

View file

@ -651,6 +651,32 @@ impl Wire {
Ok(child_status(node.wallet_child_status(), &source))
}
/// One live probe of the app-owned wallet child, returning the same record
/// [`Wire::wallet_status`] reports — from a snapshot that was just taken
/// rather than one left behind by the last start.
///
/// It dials: the child's loopback wallet RPC, and the configured local
/// daemon's `get_info` when the wallet RPC does not answer. That is what
/// makes the chain's height and target move between calls.
///
/// It never spawns and never starts a child: a node with no child is not
/// launched for this call.
///
/// Safe to call from a UI refresh loop, but not free — it makes network
/// calls, so a caller should poll on the order of seconds rather than every
/// frame. [`Wire::wallet_status`] stays the cheap, non-dialing read for
/// first paint.
///
/// The honest limit: with no live child, the core short-circuits and returns
/// the cached `off` / `exited` snapshot, so this can never invent `ready` or
/// any other live state for a child that is not there. `WireError.Stopped`
/// after `shutdown`.
pub async fn wallet_child_refresh(&self) -> WResult<WalletChildStatus> {
let node = self.node()?;
let source = node.wallet_child_config().source;
Ok(child_status(node.wallet_child_refresh().await, &source))
}
/// The chain-source + binary settings the child spawns with, as stored.
/// Returns the defaults (receive-only, binaries by name) when nothing was
/// ever set, so a settings screen can prefill from it safely.
@ -1997,4 +2023,68 @@ mod tests {
assert_eq!(status.height, 0);
assert_eq!(status.target_height, 0);
}
/// A live probe on a node with no child is `off` — the same record the
/// cheap read reports — never an error and never an invented state.
///
/// This crate cannot build the node half of that: `open_wire` is the only
/// constructor of `Wire` and it bootstraps Arti and publishes an onion
/// service, so there is no offline `Node` for a test to hold. What is
/// pinned here is the half the SDK owns — both exported reads hand the same
/// core snapshot to the same `child_status` mapper — plus the record shape,
/// written as an exhaustive literal so a new field on `WalletChildStatus`
/// stops this test compiling. The core's own short-circuit (`wallet_child`
/// is `None` ⇒ return the cached snapshot) is what `src/node.rs`'s tests
/// exercise.
#[test]
fn an_unprobed_child_is_off_whichever_read_reports_it() {
let core = onionwire::wallet_child::WalletChildStatus {
state: WalletChildState::Off,
running: false,
configured: false,
chain_source: "receive-only".to_string(),
height: 0,
target_height: 0,
last_error: None,
};
let source = ChainSource::None;
let want = WalletChildStatus {
state: "off".to_string(),
running: false,
configured: false,
chain_source: "receive-only".to_string(),
chain_in_process: false,
node_available: onionwire::cuprate::available(),
node_state: String::new(),
height: 0,
target_height: 0,
last_error: None,
};
// `wallet_status` maps it once, `wallet_child_refresh` maps the same
// snapshot the same way: one mapper, no second state machine.
for got in [
child_status(core.clone(), &source),
child_status(core, &source),
] {
assert_eq!(got.state, want.state);
assert_eq!(got.running, want.running);
assert_eq!(got.configured, want.configured);
assert_eq!(got.chain_source, want.chain_source);
assert_eq!(got.chain_in_process, want.chain_in_process);
assert_eq!(got.node_available, want.node_available);
assert_eq!(got.node_state, want.node_state);
assert_eq!(got.height, want.height);
assert_eq!(got.target_height, want.target_height);
assert_eq!(got.last_error, want.last_error);
}
}
/// The live probe is an error, not a panic, once the handle is shut down:
/// it goes through the same `node()` accessor as every other call.
#[test]
fn wallet_child_refresh_on_a_stopped_handle_is_stopped_error() {
let err = block_on(stopped_wire().wallet_child_refresh()).expect_err("must fail");
assert!(matches!(err, WireError::Stopped { .. }), "got {err:?}");
}
}