node: remember a created wallet in the store catalogue #143
Loading…
Reference in a new issue
No description provided.
Delete branch "wt/t_511023b6"
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?
Stacked on #141 (
wt/t_64c9ba3c, basemain, not yet merged): this branch needs thewalletstable andStore::{create_wallet,list_wallets}, so the base here iswt/t_64c9ba3c, notmain. Please retarget tomainafter #141 lands.The bug
Node::wallet_createcreated the wallet on the RPC and returned the seed — nothing else. The file name was the one hardcodedwallet::DEFAULT_WALLET_FILENAME(onionwire), and the child's stored config defaults to that same name, so the first create worked by accident. A second create reusedonionwire, the RPC refused it (the file exists), and no row was ever written: the app could not create another wallet and remembered nothing across restarts (issue #140).The fix
Creation and import now go through the store catalogue.
Node::wallet_create(password) -> Result<CreatedWallet, String>, whereCreatedWalletisrecord: WalletRecordplusseed: String.recordis the stored row (id andcreated_atassigned by the store);seedis the one-time backup phrase the UI already shows.CreatedWallethas a hand-writtenDebugthat redacts the seed.Node::wallet_restore(password, seed) -> Result<WalletRecord, String>— import is a creation path too and had the same hardcoded name.Node::list_wallets() -> Result<Vec<WalletRecord>, String>— a store read, no dial, works with the wallet off.onionwire-<n>for the firstnthe catalogue does not already hold, so several wallets coexist.set_wallet_child_config, which preserves the generated RPC creds). A row the child never opens would still be a broken wallet. The change applies on the nextstart_wallet_child; a running child is not restarted.identity_pubkeyis this node's identity (not unique — identity is the roster key, a wallet is a file) andonion_locatoris read at creation time (a locator, allowed to be empty before the HS publishes). Neither is a key.Surface changes
src/tui.rscreate screen destructuresCreatedWalletfor the seed.crates/onionwire-sdk/src/lib.rs: the UniFFI signatures are unchanged (create_wallet -> String,import_wallet -> ()), so there is no Kotlin change — the SDK unwraps.seedand maps the record to(). Verified withcargo testandcargo clippyinsidecrates/onionwire-sdk.Verification
error[E0599] no method named list_walletsandE0609field access on the oldStringreturn, then green. The child-repoint test was RED atleft: "onionwire"/right: "onionwire-1".src/node.rstest module (notests/*.rscan build aNode): row + identity + locator + seed in the catalogue; a second wallet gets its own file and both survive a reopen; import records a row; a wallet-off install lists an empty catalogue and still refuses to create; the child is re-pointed and the first wallet keeps its file.cargo test --lockedexit 0;cargo clippy --locked --all-targets -- -D warningsclean; both clean incrates/onionwire-sdktoo.Cargo.lockuntouched (no new dependency).rustfmt --edition 2024 --check src/node.rsreports the same 2 inherited hunks as the base; no new ones.Not in this PR: the wallet-selection screen (t_14ac0a3f) and the selection-to-load wiring (t_895853ad) — loading an existing wallet means reading the row and re-pointing the child, which is that card's job.
A wallet created in-app was never remembered: `Node::wallet_create` called the RPC and returned the seed, and the wallet file name was the one hardcoded `wallet::DEFAULT_WALLET_FILENAME` ("onionwire"). A second create reused that name, so the RPC refused it (or opened the first wallet's file) and no row was ever written — the "cannot create a new wallet, and nothing survives a restart" report. Creation and import now go through the catalogue (t_64c9ba3c's `Store::{create_wallet,list_wallets}`): - each create/import gets its own file name, `onionwire-<n>` for the first `n` the catalogue does not hold, so several wallets coexist; - the stored row (id, identity, locator, file, created_at) is returned: `Node::wallet_create` -> `CreatedWallet` (row + the one-time seed, with a redacting `Debug`), `Node::wallet_restore` -> `WalletRecord`; - `Node::list_wallets` reads the catalogue without dialing; - the child config is re-pointed at the new file (read-modify-write, so the sealed RPC creds survive) — a row the child never opens would still be a broken wallet. The SDK keeps its UniFFI signature (`create_wallet -> String` seed, `import_wallet -> ()`), so no Kotlin change: it unwraps `.seed`. TDD: 5 new `src/node.rs` cases (row + list, two wallets + reopen, import, wallet-off empty list, child re-pointed) over a loopback wallet-RPC mock. `cargo test --locked` exit 0, `cargo clippy --locked --all-targets -- -D warnings` clean, and the same two commands are clean in `crates/onionwire-sdk`.