tui: F7 wallet setup — RPC endpoint and chain source on screen

`wallet::NOT_CONFIGURED_MSG` has always said "open F7 to set it up" and there
was no F7. This is that screen.

- `FunctionKey::Setup` on `F7`, live on Main, the settings menu and peer
  payments, same invariant `F9` follows.
- `Screen::WalletSetupConfig` carries `WalletSetupConfigState`: a snapshot of
  plain data taken when the screen opens, never a handle onto `Node`.
- Rows: the wallet RPC endpoint and its login (never rendered back — the row
  says `hidden · set`, `Debug` redacts it), the view-only toggle, and a chain
  picker over all four `ChainSource` cases with their own fields.
- `Node::set_remote_daemon` / `set_local_monerod` / `set_receive_only`, so the
  TUI can reach what only the Android API could, plus `F6`'s in-process source.
- An untouched chain row is not written, so an F7 save cannot silently undo the
  in-process choice; picking a remote daemon says who is trusted in the same
  frame, one line, lowercase.
- `Ctrl-T` tests the endpoint and shows the sanitized `PingResult::line()`.
  Saving never dials. A rejected form writes nothing — the node validates.
- Docs that claimed there is no F7 (`docs/TUI.md`, `docs/WALLET.md`) now
  describe the screen; the settings menu's `endpoint` row names the key.

(cherry picked from commit a48d40bc4e)
This commit is contained in:
agent 2026-09-26 23:18:46 -04:00
commit a37712f3af
No known key found for this signature in database
4 changed files with 1335 additions and 22 deletions

View file

@ -669,6 +669,49 @@ impl Node {
self.set_wallet_child_config(&cfg)
}
/// Point the wallet child at a chain daemon the user runs elsewhere.
/// Same shape as [`Self::set_in_process_cuprate`]: read-modify-write on the
/// stored settings, an empty `wallet_rpc_bin` filled in, and validation
/// before anything is written. A `.onion` host needs no special case here —
/// the child pulls in the SOCKS proxy for it (`ChainSource::is_onion`).
pub fn set_remote_daemon(&self, host: &str, port: u16) -> Result<(), String> {
let mut cfg = self.wallet_child_config();
if cfg.wallet_rpc_bin.as_os_str().is_empty() {
cfg.wallet_rpc_bin = PathBuf::from("monero-wallet-rpc");
}
cfg.source = ChainSource::Remote {
host: host.trim().to_string(),
port,
};
self.set_wallet_child_config(&cfg)
}
/// Spawn a local `monerod`. Datadirs are split exactly as they are for the
/// in-process daemon so a pruned store cannot mix with a full one.
pub fn set_local_monerod(&self, monerod_bin: &Path, prune: bool) -> Result<(), String> {
let mut cfg = self.wallet_child_config();
if cfg.wallet_rpc_bin.as_os_str().is_empty() {
cfg.wallet_rpc_bin = PathBuf::from("monero-wallet-rpc");
}
cfg.source = ChainSource::Local {
monerod_bin: monerod_bin.to_path_buf(),
datadir: self
.home
.join("chain")
.join(if prune { "mainnet-pruned" } else { "mainnet-full" }),
prune,
};
self.set_wallet_child_config(&cfg)
}
/// Back to zero: no wallet child, no daemon, no spend. The way out of a
/// misconfigured chain source.
pub fn set_receive_only(&self) -> Result<(), String> {
let mut cfg = self.wallet_child_config();
cfg.source = ChainSource::None;
self.set_wallet_child_config(&cfg)
}
/// Start the app-owned wallet child, point this node's wallet at it, and
/// **open its wallet file**.
///
@ -3585,6 +3628,182 @@ pub(crate) mod tests {
);
}
/// The F7 screen's three chain-source choices each round-trip through the
/// sealed record, and `receive-only` is the way back to zero.
#[tokio::test]
async fn the_setup_screen_persists_each_chain_source() {
let dir = tempfile::tempdir().unwrap();
let home = dir.path().join("child");
let node = offline_node(&home, Arc::new(NoDial));
assert_eq!(
node.wallet_child_config().source,
ChainSource::None,
"a fresh install is receive-only"
);
node.set_remote_daemon("127.0.0.1", 18089)
.expect("remote daemon");
let remote = node.wallet_child_config();
assert_eq!(
remote.source,
ChainSource::Remote {
host: "127.0.0.1".into(),
port: 18089,
}
);
assert!(!remote.source.is_onion());
assert_eq!(
remote.wallet_rpc_bin,
PathBuf::from("monero-wallet-rpc"),
"an empty binary is filled in, like the in-process source"
);
node.set_remote_daemon("peer.onion", 18089)
.expect("onion daemon");
assert!(
node.wallet_child_config().source.is_onion(),
"a .onion host is the source's own SOCKS case, not a special one"
);
node.set_local_monerod(Path::new("/opt/monerod"), true)
.expect("local node");
assert_eq!(
node.wallet_child_config().source,
ChainSource::Local {
monerod_bin: PathBuf::from("/opt/monerod"),
datadir: home.join("chain").join("mainnet-pruned"),
prune: true,
}
);
node.set_receive_only().expect("receive-only");
assert_eq!(node.wallet_child_config().source, ChainSource::None);
// The last write is what a restart sees.
node.set_local_monerod(Path::new("/opt/monerod"), false)
.expect("local node");
drop(node);
let node = offline_node(&home, Arc::new(NoDial));
assert_eq!(
node.wallet_child_config().source,
ChainSource::Local {
monerod_bin: PathBuf::from("/opt/monerod"),
datadir: home.join("chain").join("mainnet-full"),
prune: false,
},
"the source outlives the process"
);
}
/// A chain source the user typed wrong is rejected before it is written, so
/// a bad form never points the child at nothing.
#[tokio::test]
async fn a_rejected_setup_chain_source_is_not_persisted() {
let dir = tempfile::tempdir().unwrap();
let node = offline_node(&dir.path().join("child"), Arc::new(NoDial));
node.set_remote_daemon("127.0.0.1", 18089)
.expect("remote daemon");
let saved = node.wallet_child_config();
let err = node
.set_remote_daemon(" ", 18089)
.expect_err("an empty host is refused");
assert!(err.contains("daemon host required"), "{err}");
let err = node
.set_remote_daemon("127.0.0.1", 0)
.expect_err("port 0 is refused");
assert!(err.contains("daemon port required"), "{err}");
let err = node
.set_local_monerod(Path::new(""), false)
.expect_err("an empty binary path is refused");
assert!(err.contains("monerod path required"), "{err}");
assert_eq!(
node.wallet_child_config(),
saved,
"a rejected source leaves the stored one alone"
);
}
/// The F7 screen's save round-trips through the sealed record, and a save
/// can never lock the wallet out of itself: the file passphrase the screen
/// does not carry is preserved.
#[tokio::test]
async fn a_screen_save_round_trips_and_keeps_the_wallet_passphrase() {
let dir = tempfile::tempdir().unwrap();
let node = offline_node(&dir.path().join("child"), Arc::new(NoDial));
assert!(
node.wallet_config().is_none(),
"a fresh install has stored nothing"
);
node.wallet_save_config(&WalletConfig::new(
"http://127.0.0.1:18083/json_rpc",
"ow:hunter2",
false,
))
.expect("save");
let read = node.wallet_config().expect("the save is readable");
assert_eq!(read.rpc_url, "http://127.0.0.1:18083/json_rpc");
assert_eq!(read.rpc_login.as_str(), "ow:hunter2");
assert!(!read.no_spend);
assert_eq!(read.wallet_passphrase.as_str(), "");
assert!(
node.wallet_status().configured(),
"the live snapshot follows the save"
);
// The file passphrase is sealed by the open path, not by this screen.
node.seal_wallet_passphrase("wallet-file-pass")
.expect("seal");
assert_eq!(
node.wallet_config().expect("stored").wallet_passphrase.as_str(),
"wallet-file-pass"
);
// A screen save (which never holds the file passphrase) keeps the stored
// one instead of blanking it — a save can never lock the wallet out of
// itself. A passphrase a caller hands `wallet_save_config` is ignored
// for the same reason: the file's passphrase is not the screen's.
let mut screen_save =
WalletConfig::new("http://127.0.0.1:18083/json_rpc", "ow:hunter2", true);
screen_save.wallet_passphrase = Zeroizing::new("not-the-files".to_string());
node.wallet_save_config(&screen_save).expect("resave");
let read = node.wallet_config().expect("the resave is readable");
assert!(read.no_spend, "the view-only toggle reached the store");
assert_eq!(read.wallet_passphrase.as_str(), "wallet-file-pass");
}
/// A rejected form leaves the stored config exactly as it was. The node is
/// the validator — the screen does not reimplement it.
#[tokio::test]
async fn a_rejected_wallet_config_is_not_persisted() {
let dir = tempfile::tempdir().unwrap();
let node = offline_node(&dir.path().join("child"), Arc::new(NoDial));
node.wallet_save_config(&WalletConfig::new(
"http://127.0.0.1:18083/json_rpc",
"ow:hunter2",
false,
))
.expect("save");
let before = node.wallet_config().expect("stored");
for bad in [
WalletConfig::new("", "ow:hunter2", false),
WalletConfig::new("http://192.0.2.10:18083/json_rpc", "ow:hunter2", false),
WalletConfig::new("http://127.0.0.1:18083/json_rpc", "", false),
] {
let err = node
.wallet_save_config(&bad)
.expect_err("a bad form is refused");
assert!(!err.is_empty());
assert_eq!(
node.wallet_config().expect("stored"),
before,
"the stored config is intact"
);
}
}
/// `shutdown` stops the processes the app owns: an exit must not orphan a
/// spend-capable wallet RPC behind a loopback socket.
#[tokio::test]