Compare commits

..
Author SHA1 Message Date
agent
8331a2dde6
wallet: app-owned child lifecycle + user-chosen ChainSource
All checks were successful
ci / test (pull_request) Successful in 4m1s
ci / sdk (pull_request) Successful in 1m2s
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>
2026-09-14 19:57:21 -04:00

View file

@ -110,10 +110,7 @@ impl WalletChild {
/// is reaped here so a later `stop` is a no-op. /// is reaped here so a later `stop` is a no-op.
pub fn running(&self) -> bool { pub fn running(&self) -> bool {
let _ = self.reap_exited(); let _ = self.reap_exited();
self.monerod self.monerod.lock().map(|g| g.is_some()).unwrap_or(false)
.lock()
.map(|g| g.is_some())
.unwrap_or(false)
|| self.wallet_rpc.lock().map(|g| g.is_some()).unwrap_or(false) || self.wallet_rpc.lock().map(|g| g.is_some()).unwrap_or(false)
} }
@ -454,10 +451,8 @@ mod tests {
use std::io::Write; use std::io::Write;
fn tmp_dir(tag: &str) -> PathBuf { fn tmp_dir(tag: &str) -> PathBuf {
let dir = std::env::temp_dir().join(format!( let dir =
"onionwire-child-{tag}-{}", std::env::temp_dir().join(format!("onionwire-child-{tag}-{}", std::process::id()));
std::process::id()
));
let _ = fs::remove_dir_all(&dir); let _ = fs::remove_dir_all(&dir);
dir dir
} }
@ -472,7 +467,11 @@ mod tests {
let mut f = fs::File::create(&path).unwrap(); let mut f = fs::File::create(&path).unwrap();
writeln!(f, "#!/bin/sh").unwrap(); writeln!(f, "#!/bin/sh").unwrap();
writeln!(f, ": > '{}'", log.display()).unwrap(); writeln!(f, ": > '{}'", log.display()).unwrap();
writeln!(f, "for a in \"$@\"; do printf '%s\\n' \"$a\" >> '{}'; done", log.display()) writeln!(
f,
"for a in \"$@\"; do printf '%s\\n' \"$a\" >> '{}'; done",
log.display()
)
.unwrap(); .unwrap();
writeln!(f, "sleep 30").unwrap(); writeln!(f, "sleep 30").unwrap();
drop(f); drop(f);
@ -572,7 +571,10 @@ mod tests {
.collect(); .collect();
assert!(pairs.contains(&("--rpc-bind-ip", "127.0.0.1")), "{argv:?}"); assert!(pairs.contains(&("--rpc-bind-ip", "127.0.0.1")), "{argv:?}");
assert!(pairs.contains(&("--rpc-bind-port", "39127")), "{argv:?}"); assert!(pairs.contains(&("--rpc-bind-port", "39127")), "{argv:?}");
assert!(pairs.contains(&("--rpc-login", "owuser:owpass")), "{argv:?}"); assert!(
pairs.contains(&("--rpc-login", "owuser:owpass")),
"{argv:?}"
);
assert!( assert!(
pairs.contains(&("--wallet-dir", dir.to_str().unwrap())), pairs.contains(&("--wallet-dir", dir.to_str().unwrap())),
"{argv:?}" "{argv:?}"
@ -640,7 +642,10 @@ mod tests {
); );
let rpc_argv = wait_for_argv(&rpc_log); let rpc_argv = wait_for_argv(&rpc_log);
assert!(rpc_argv.iter().any(|a| a == "--rpc-bind-ip"), "{rpc_argv:?}"); assert!(
rpc_argv.iter().any(|a| a == "--rpc-bind-ip"),
"{rpc_argv:?}"
);
assert!(rpc_argv.iter().any(|a| a == "127.0.0.1"), "{rpc_argv:?}"); assert!(rpc_argv.iter().any(|a| a == "127.0.0.1"), "{rpc_argv:?}");
assert!(rpc_argv.iter().any(|a| a == "--rpc-login"), "{rpc_argv:?}"); assert!(rpc_argv.iter().any(|a| a == "--rpc-login"), "{rpc_argv:?}");
assert!(rpc_argv.iter().any(|a| a == "--wallet-dir"), "{rpc_argv:?}"); assert!(rpc_argv.iter().any(|a| a == "--wallet-dir"), "{rpc_argv:?}");
@ -665,7 +670,10 @@ mod tests {
.expect("login"); .expect("login");
let (user, pass) = login_arg.split_once(':').expect("user:pass"); let (user, pass) = login_arg.split_once(':').expect("user:pass");
assert_ne!(user, pass, "user and password must be independent"); assert_ne!(user, pass, "user and password must be independent");
assert!(url.contains(user) && url.contains(pass), "{url} vs {login_arg}"); assert!(
url.contains(user) && url.contains(pass),
"{url} vs {login_arg}"
);
// Creds live sealed in the store, and nothing in the wallet dir holds // Creds live sealed in the store, and nothing in the wallet dir holds
// them in the clear. // them in the clear.
@ -675,9 +683,7 @@ mod tests {
let path = entry.unwrap().path(); let path = entry.unwrap().path();
let body = fs::read(&path).unwrap_or_default(); let body = fs::read(&path).unwrap_or_default();
assert!( assert!(
!body !body.windows(pass.len()).any(|w| w == pass.as_bytes()),
.windows(pass.len())
.any(|w| w == pass.as_bytes()),
"{} holds the RPC password in the clear", "{} holds the RPC password in the clear",
path.display() path.display()
); );