wallet: wire the app-owned child into the node and TUI

The module was dead code: nothing started the child, so the payment spines
could only ever see an env-configured monero-wallet-rpc. Now:

- Node::start_wallet_child / stop_wallet_child / wallet_child_status /
  wallet_child_refresh / wallet_child_config / set_wallet_child_config. The
  start path honours the configured absolute binary path, points the node's
  wallet at the child, and shutdown() stops the child rather than orphaning
  a spend-capable RPC behind a loopback socket.
- The status is derived from the real process (try_wait) and the last probe:
  off / connecting / syncing / ready / exited, plus the chain-source label.
  A dead child is never reported ready.
- ChildConfig (source, wallet_rpc_bin, arti_bin, wallet_filename) persists in
  the sealed wallet_child record next to the generated creds; the record is a
  read-modify-write so first-start creds never clobber a saved config.
- TUI: F6 gains s (start) / x (stop) / p (probe) and a child status row, and
  the /pay and /tip key handlers now call the core readiness guard before
  sending.
This commit is contained in:
agent 2026-09-18 09:28:11 -04:00
commit 440a37caf0
No known key found for this signature in database
5 changed files with 1056 additions and 33 deletions

View file

@ -1123,6 +1123,121 @@ async fn status_is_connected_only_after_a_successful_probe() {
assert!(!none.configured() && !none.connected, "{none:?}");
}
// Chain-source labels and the persisted wallet-child settings. The child itself
// spawns processes (see `src/node.rs`'s tests and `src/wallet_child.rs`), so
// these cover the public shapes a config screen and the SDK build on.
#[test]
fn chain_source_labels_name_what_the_child_dials() {
use std::path::PathBuf;
use onionwire::wallet::ChainSource;
assert_eq!(ChainSource::None.label(), "receive-only");
assert_eq!(
ChainSource::Local {
monerod_bin: PathBuf::from("/usr/bin/monerod"),
datadir: PathBuf::from("/var/lib/onionwire"),
}
.label(),
"local node"
);
assert_eq!(
ChainSource::Remote {
host: "daemon.onion".into(),
port: 18089
}
.label(),
"remote onion daemon"
);
assert_eq!(
ChainSource::Remote {
host: "127.0.0.1".into(),
port: 18089
}
.label(),
"remote daemon"
);
// Onion detection needs the suffix, and is case-insensitive.
assert!(
ChainSource::Remote {
host: "ABCDEF.ONION".into(),
port: 1
}
.is_onion()
);
assert!(
!ChainSource::Remote {
host: "notonion.example".into(),
port: 1
}
.is_onion()
);
assert!(!ChainSource::None.is_onion());
}
#[test]
fn child_settings_round_trip_sealed_and_keep_the_creds() {
use std::path::PathBuf;
use onionwire::wallet::ChainSource;
use onionwire::wallet_child::{ChildConfig, merge_record};
let cfg = ChildConfig {
source: ChainSource::Remote {
host: "daemon.onion".into(),
port: 18089,
},
wallet_rpc_bin: PathBuf::from("/data/app/lib/libmonero-wallet-rpc.so"),
arti_bin: PathBuf::from("/data/app/lib/libarti.so"),
wallet_filename: "onionwire".into(),
};
let record = merge_record(None, cfg.record_fields());
// The creds a first start seals live in the same record and must survive a
// later settings save.
let with_creds = merge_record(
Some(&record),
serde_json::json!({"user": "owuser", "pass": "ow-secret"}),
);
let dir = std::env::temp_dir().join(format!("ow-child-cfg-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
let store = Store::open_at_with_passphrase(&dir, "child-cfg-pass").unwrap();
store.save_wallet_child(&with_creds).unwrap();
let raw = store.load_wallet_child().unwrap().expect("record");
assert_eq!(
ChildConfig::from_record(&raw).unwrap().expect("settings"),
cfg,
"the settings survive the sealed round trip"
);
drop(store);
let _ = std::fs::remove_dir_all(&dir);
// A record written before the settings existed is `None`, not a lie.
assert_eq!(
ChildConfig::from_record(r#"{"user":"u","pass":"p"}"#).unwrap(),
None
);
// Receive-only spawns nothing, so empty binaries are not an error there;
// they are for the kinds that spawn.
assert!(ChildConfig::receive_only().validate().is_ok());
let mut local = ChildConfig::receive_only();
local.source = ChainSource::Local {
monerod_bin: PathBuf::new(),
datadir: PathBuf::from("/var/lib/onionwire"),
};
let err = local.validate().expect_err("a local node needs monerod");
assert!(err.to_string().contains("monerod path required"), "{err}");
let mut remote = ChildConfig::receive_only();
remote.source = ChainSource::Remote {
host: "daemon.onion".into(),
port: 0,
};
let err = remote.validate().expect_err("a remote daemon needs a port");
assert!(err.to_string().contains("daemon port required"), "{err}");
}
/// A port nothing is listening on: bind it, read it, drop the listener.
fn freed_loopback_port() -> u16 {
let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap();