wallet: land the wallet-child stack on main + expose start/stop/status through UniFFI (issue #107) #108
Loading…
Reference in a new issue
No description provided.
Delete branch "wt/t_8a8ff353"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Origin
Forgejo issue sirius/onionwire#107. This is the parent/prerequisite card: land the wallet-child stack on
mainand expose its lifecycle through the UniFFI facade so the Android wallet screen can start the child.What this PR is
main.origin/feat/wallet-child-rpc(wallet child lifecycle + user-chosen ChainSource, then stored wallet config + WalletStatus snapshot + pay/tip readiness guard) rebased ontomainat462b576. Conflicts were resolved by re-applying intent on main's shape:src/store.rs: both sides appended tests tomod at_rest; both were kept. Git's conflict chunking also swallowed one closing brace shared by the two sides (the file did not compile after a naive marker deletion), which is fixed in the same commit.src/node.rstip(): main's newer body wins (tip row, memo,tip_chat_line,sign_receipt) and the branch's readiness guard is applied on top of it (wallet_snapshot()+wallet::NOT_CONFIGURED_MSG).src/node.rshad no test module on the branch and one onmain: main's test module is kept.scripts/publish-release.shis identical tomain(no reintroduced conflict markers):git grep -n -E '^(<<<<<<<|>>>>>>>)' <head>is empty andbash -n scripts/publish-release.shis clean.UniFFI method names (the Android contract, verbatim)
Records:
WalletChildStatus - state, running, configured, chain_source, last_errorandChainConfig - kind (ChainChoice: None/Local/Remote), monerod_bin, monerod_datadir, host, port, wallet_rpc_bin, arti_bin, wallet_filename.stateis a lowercase label:off/connecting/syncing/ready/exited.chain_sourceis the label:receive-only/local node/remote onion daemon/remote daemon. It is derived from the real process plus the last probe — never from env-var presence — and a child that has died is reportedexited, neverready.One-line note for the Android card: call
set_chain_sourcewith absolutewallet_rpc_bin/arti_binpaths fromnativeLibraryDir, thenstart_wallet_child(), then pollwallet_status(). A.oniondaemon also needsarti_bin; the SOCKS child is spawned by the core.2. Node / TUI wiring
Node::start_wallet_child/stop_wallet_child/wallet_child_status/wallet_child_refresh/wallet_child_config/set_wallet_child_config.WalletChild::start(&store)->WalletClient::into_wallet(), so the existing payment spines (pay_invoice,tip,ingest_receipt) talk to the app-owned child. No payment-frame shape changed and the receipt-verification conjunctive match is untouched.with_wallet_rpc_bin/with_arti_binare honoured on the start path (the configured absolute path is what gets spawned) — pinned by a test that asserts the spawned process's own$0and argv.Node::shutdownnow stops the wallet child. Without it, an app exit orphaned the spawn-capablemonero-wallet-rpc(andmonerod), which is whatdocs/WALLET.mdalready claimedstop()did on shutdown.s(start),x(stop),p(probe) and a child status row (rendered only when a chain source is configured, so an unconfigured install renders exactly as before). The/payand/tipkey handlers now runNode::wallet_readinessbefore sending, which is what that guard was written for and until now nothing called.startis idempotent (a live child is reported, not respawned); a spawn failure is an error and leaves no half-started child.3. Settings persistence
ChildConfig - source, wallet_rpc_bin, arti_bin, wallet_filenameis stored in the same sealedwallet_childrecord as the generated RPC creds. The record write is now a read-modify-write (wallet_child::merge_record), so first-start credential generation cannot clobber a saved config and a later save cannot clobber the creds. Validation happens before anything is written.4. Docs
docs/WALLET.mdis reconciled withmainand corrected where the inherited text described things that do not ship here:feat/wallet-create-import; this stack ships the stored config API, not that screen, and now says so;Local mode is not wired yetis replaced by the shipped lifecycle, the five states, and the exact API names for desktop and Android;send_pay/send_tip).docs/THREAT_MODEL.md's additive SOCKS/chain-source wording is unchanged from the branch and was checked againstsrc/wallet_child.rs.docs/PROTOCOL.mdis untouched (no payment-frame change).Known follow-up (not this PR)
The F7 wallet-config screen, the chain-source picker and the wallet/chain TUI redesign live on
origin/feat/wallet-create-import(which also carries an in-process Cuprate chain daemon behind a feature flag). This PR lands the child + SDK contract that #107 needs; landing that UI branch is a separate card, and itstui.rs/tests/tui_spec.rs/tests/tui_frames.rswork is outside this card's file whitelist.Evidence (on this head)
cargo clippy --locked --all-targets --target x86_64-unknown-linux-gnu -- -D warnings-> exit 0cargo test --locked --target x86_64-unknown-linux-gnu-> exit 0, aggregate over every target: 341 passed; 0 failed; 0 ignored (50 in the lib target, the rest across the integration targets; the Tor-dependent ones reportignored/0-test when the network is not available, exactly as onmain).cargo test --locked --lib->test result: ok. 50 passed; 0 failed; 0 ignoredcd crates/onionwire-sdk && cargo test --locked && cargo clippy --locked --all-targets -- -D warnings-> exit 0 (27 unit tests). The SDK has its own lockfile; no root dependency was added, so it did not need regenerating.git grep -n -E '^(<<<<<<<|>>>>>>>)' HEADis empty;bash -n scripts/publish-release.shis clean;git diff origin/main HEAD -- scripts/publish-release.shis empty.start_wallet_child_honours_the_configured_binary,a_died_child_reports_exited_and_never_ready,chain_source_persists_and_keeps_the_sealed_creds,a_rejected_chain_source_is_not_persisted,a_missing_binary_fails_the_start_and_leaves_no_child,a_receive_only_node_reports_off_and_refuses_to_start_a_child,shutdown_stops_the_wallet_child,chain_source_labels_name_what_the_child_dials,child_settings_round_trip_sealed_and_keep_the_creds.mock_walletinsrc/node.rs's tests had to learnget_info:Wallet::transferprobes the chain tip before spending, and the old single-answer mock made every outbound-tip test fail as "not synced". That is a test-harness fix, not a behaviour change.The app now owns monero-wallet-rpc (and monerod when the chain source is local) instead of requiring the user to start them and export ONIONWIRE_WALLET_RPC. - ChainSource enum: None / Local { monerod_bin, datadir } / Remote { host, port }. No default remote node; Remote is only constructed from explicit user input. A .onion Remote is refused without a SOCKS proxy (separate card). - WalletChild in src/wallet_child.rs spawns monero-wallet-rpc with --rpc-bind-ip 127.0.0.1, a random free loopback port, generated --rpc-login, and --wallet-dir /wallet; monerod too for a local source. --trusted-daemon is never passed. - Generated RPC creds are sealed in the encrypted SQLCipher store (wallet_child table, AEAD on top of whole-db encryption), never a plaintext file. The Wallet client is built from the generated loopback URL, not from_env. - Readiness predicate: chain_ready() requires synchronized==true, height>0, height>=target_height; can_spend() and can_verify_receipts() gate on it. Unsynced -> receipts stay verified=0, spend refused with a clear message. - Backend-aware timeouts: local management calls keep 5s; chain-dependent calls (get_info, get_transfers, transfer) get 60s (CHAIN_RPC_TIMEOUT), because a first sync or a remote daemon outlasts 5s and a 5s cap there is what left receipts permanently unverified. - node.rs ingest_receipt gates on can_verify_receipts() instead of configured() alone. - docs/WALLET.md rewritten for the child lifecycle + chain source. Base: feat/wallet-create-import (PR #66). Do not rebase onto main. Co-Authored-By: Hermes Agent <agent@local>The only input path for the wallet was env. Add the same three remote-mode fields as stored config so the F7 screen can set them and headless runs read one source of truth: - `wallet_config` table in the encrypted store (one row; the login is sealed with the store data key under `onionwire/wallet-config/v1`, on top of SQLCipher). Empty URL clears it. `Store::load_wallet_config` / `save_wallet_config`. - `WalletConfig { rpc_url, rpc_login: Zeroizing<String>, no_spend }` with a redacting `Debug`; `Wallet::from_config`, and `Wallet::for_boot` which prefers stored config, falls back to env, and refuses to dial a bad stored endpoint. Node::start* now reads the store before constructing the wallet. - `WalletStatus { configured, connected, last_error, balance_line, receive_address }`: `connected` only ever comes from a probe (`Wallet::status`, get_address + get_balance); config alone leaves it false. `Node::wallet_status` is the cheap draw-path read, `wallet_refresh` the probe that folds into it. - One-shot `Wallet::ping(rpc_url, rpc_login) -> PingResult { ok, status, error }` for the Test-connection button: same loopback/digest rules, errors redacted and capped. - `readiness(configured, connected, no_spend, is_tip) -> Readiness` plus `Node::wallet_readiness` (async, block_on-friendly): not configured → NOT_CONFIGURED_MSG; /tip on a no-spend wallet → VIEW_ONLY_MSG before any dial; configured but not connected → NOT_CONNECTED_MSG; else ready. - `Node::wallet_save_config` persists, validates first, then re-reads so the live wallet and snapshot follow a Save without a restart. - `Node::wallet` is now a Mutex<Wallet> (cloned out before each await) so the wallet can be re-pointed mid-session. Local-mode fields stay reserved: the child lifecycle is t_69ce8e46 and is not wired here. docs/WALLET.md documents the stored config, boot precedence and the exact guard copy. Tests: 38 in tests/wallet.rs including exact-refusal-copy, boot precedence, sealed-on-disk login, ping sanitization and connected-only-after-probe.