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:
parent
11a021acb3
commit
440a37caf0
5 changed files with 1056 additions and 33 deletions
99
src/tui.rs
99
src/tui.rs
|
|
@ -1537,6 +1537,9 @@ impl App {
|
|||
Screen::Wallet { .. } => match key.code {
|
||||
KeyCode::Esc => self.screen = Screen::Main,
|
||||
KeyCode::Char('r') | KeyCode::Enter => self.wallet_toggle_qr(),
|
||||
KeyCode::Char('s') => self.wallet_child_start(),
|
||||
KeyCode::Char('x') => self.wallet_child_stop(),
|
||||
KeyCode::Char('p') => self.wallet_child_probe(),
|
||||
KeyCode::Char('c') => {
|
||||
self.screen = Screen::WalletSetup(WalletSetup::CreateWarn {
|
||||
typed: String::new(),
|
||||
|
|
@ -1784,6 +1787,59 @@ impl App {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// The core's pay/tip readiness guard, refused before any dial when the
|
||||
/// wallet is unconfigured, view-only (for a tip), or not answering. `true`
|
||||
/// when the send may proceed; the reason is already in the status note when
|
||||
/// it is not.
|
||||
fn wallet_ready(&mut self, is_tip: bool) -> bool {
|
||||
match self
|
||||
.rt
|
||||
.block_on(self.node.wallet_readiness(is_tip))
|
||||
.refusal()
|
||||
{
|
||||
Some(refusal) => {
|
||||
self.status_note = Some(refusal.to_string());
|
||||
false
|
||||
}
|
||||
None => true,
|
||||
}
|
||||
}
|
||||
|
||||
/// Key `s` on the wallet screen: start the app-owned wallet child. The
|
||||
/// balance/address readouts refresh on the next F6 — the child's RPC is not
|
||||
/// answering in the same breath — so this reports the state it reached.
|
||||
fn wallet_child_start(&mut self) {
|
||||
self.status_note = Some(match self.node.start_wallet_child() {
|
||||
Ok(()) => self.wallet_child_note(),
|
||||
Err(e) => format!("wallet child: {e}"),
|
||||
});
|
||||
}
|
||||
|
||||
/// Key `x`: stop the child (idempotent) and drop back to the stored/env
|
||||
/// wallet config.
|
||||
fn wallet_child_stop(&mut self) {
|
||||
self.status_note = Some(match self.node.stop_wallet_child() {
|
||||
Ok(()) => "wallet child stopped".into(),
|
||||
Err(e) => format!("wallet child: {e}"),
|
||||
});
|
||||
}
|
||||
|
||||
/// Key `p`: one probe of the running child — is its RPC answering, and is
|
||||
/// the chain at the tip? The only thing that can report `ready`.
|
||||
fn wallet_child_probe(&mut self) {
|
||||
self.status_note = Some(self.wallet_child_note());
|
||||
}
|
||||
|
||||
/// The child status line, or the copy that names what is missing.
|
||||
fn wallet_child_note(&mut self) -> String {
|
||||
let line = self.rt.block_on(self.node.wallet_child_refresh()).line();
|
||||
if line.is_empty() {
|
||||
"no wallet child configured — set a chain source first".into()
|
||||
} else {
|
||||
line
|
||||
}
|
||||
}
|
||||
|
||||
fn wallet_toggle_qr(&mut self) {
|
||||
let Screen::Wallet {
|
||||
ref mut qr_modal,
|
||||
|
|
@ -2053,6 +2109,9 @@ impl App {
|
|||
return Ok(());
|
||||
};
|
||||
let pk = friend.pubkey.clone();
|
||||
if !self.wallet_ready(false) {
|
||||
return Ok(());
|
||||
}
|
||||
match self.rt.block_on(self.node.pay_invoice(&pk, atomic, memo)) {
|
||||
Ok(()) => self.status_note = Some("invoice sent".into()),
|
||||
Err(e) => self.status_note = Some(e),
|
||||
|
|
@ -2066,6 +2125,9 @@ impl App {
|
|||
return Ok(());
|
||||
};
|
||||
let pk = friend.pubkey.clone();
|
||||
if !self.wallet_ready(true) {
|
||||
return Ok(());
|
||||
}
|
||||
match self.rt.block_on(self.node.tip(&pk, atomic, memo)) {
|
||||
Ok(()) => self.status_note = Some("tip sent".into()),
|
||||
Err(e) => self.status_note = Some(e),
|
||||
|
|
@ -2150,8 +2212,21 @@ impl App {
|
|||
draw_passphrase(f, *kind, entry.first().is_some(), entry.buf())
|
||||
}
|
||||
Screen::Quit { prompt } => draw_quit(f, prompt.typed()),
|
||||
Screen::Wallet { receive_addr, balance, transfers, qr_modal } => {
|
||||
draw_wallet(f, receive_addr, balance, transfers, qr_modal.as_ref())
|
||||
Screen::Wallet {
|
||||
receive_addr,
|
||||
balance,
|
||||
transfers,
|
||||
qr_modal,
|
||||
} => {
|
||||
let child = self.node.wallet_child_line();
|
||||
draw_wallet(
|
||||
f,
|
||||
receive_addr,
|
||||
balance,
|
||||
transfers,
|
||||
qr_modal.as_ref(),
|
||||
&child,
|
||||
)
|
||||
}
|
||||
Screen::WalletSetup(setup) => draw_wallet_setup(f, setup),
|
||||
}
|
||||
|
|
@ -2472,7 +2547,7 @@ match screen {
|
|||
BackupKind::Restore => "type RESTORE Esc cancel ? help",
|
||||
},
|
||||
Screen::Passphrase { .. } => "Enter submit Esc cancel ? help",
|
||||
Screen::Wallet { .. } => "c create i import r qr Esc back ? help",
|
||||
Screen::Wallet { .. } => "c create i import r qr s/x child Esc back ? help",
|
||||
Screen::WalletSetup(WalletSetup::CreateWarn { .. }) => "type SPEND Esc cancel ? help",
|
||||
Screen::WalletSetup(WalletSetup::CreatePass { .. } | WalletSetup::ImportPass { .. }) => {
|
||||
"Enter submit Esc cancel ? help"
|
||||
|
|
@ -2740,6 +2815,7 @@ fn draw_wallet(
|
|||
balance: &str,
|
||||
transfers: &[wallet::TransferRow],
|
||||
modal: Option<&QrModal>,
|
||||
child: &str,
|
||||
) {
|
||||
let area = f.area();
|
||||
if let Some(m) = modal {
|
||||
|
|
@ -2810,14 +2886,17 @@ fn draw_wallet(
|
|||
|
||||
balance
|
||||
{balance}
|
||||
|
||||
recent transfers
|
||||
"
|
||||
);
|
||||
let mut lines: Vec<String> = body
|
||||
.lines()
|
||||
.map(str::to_string)
|
||||
.collect();
|
||||
let mut lines: Vec<String> = body.lines().map(str::to_string).collect();
|
||||
// Only rendered when a chain source is configured or a child was started, so
|
||||
// an unconfigured install shows the same screen it always did.
|
||||
if !child.is_empty() {
|
||||
lines.push(String::new());
|
||||
lines.push(format!(" {child}"));
|
||||
}
|
||||
lines.push(String::new());
|
||||
lines.push("recent transfers".into());
|
||||
if transfers.is_empty() {
|
||||
lines.push(" (none)".into());
|
||||
} else {
|
||||
|
|
@ -2826,7 +2905,7 @@ recent transfers
|
|||
lines.push(format!(" {} {} XMR", t.txid.chars().take(16).collect::<String>(), xmr));
|
||||
}
|
||||
}
|
||||
let help = "c create i import r toggle qr Esc back";
|
||||
let help = "s start child x stop child p probe c create i import r qr Esc back";
|
||||
lines.push("".into());
|
||||
f.render_widget(
|
||||
Paragraph::new(lines.join("\n"))
|
||||
|
|
|
|||
Loading…
Reference in a new issue