node: remember a created wallet in the store's catalogue
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`.
This commit is contained in:
parent
467510f096
commit
0043fa0b34
3 changed files with 262 additions and 15 deletions
|
|
@ -587,20 +587,27 @@ impl Wire {
|
|||
/// Create a new spend-capable wallet. Returns the 25-word seed once so the
|
||||
/// UI can show a backup screen. The user does not paste a key on this path.
|
||||
/// Requires `ONIONWIRE_WALLET_RPC` pointed at a `--wallet-dir` RPC.
|
||||
///
|
||||
/// The core also records the new wallet in its catalogue (`Node::wallet_create`
|
||||
/// returns the stored row); the seed is what this surface carries.
|
||||
pub async fn create_wallet(&self, password: String) -> WResult<String> {
|
||||
self.node()?
|
||||
Ok(self
|
||||
.node()?
|
||||
.wallet_create(&password)
|
||||
.await
|
||||
.map_err(WireError::new)
|
||||
.map_err(WireError::new)?
|
||||
.seed)
|
||||
}
|
||||
|
||||
/// Import a wallet from an existing 25-word seed. This is the only path
|
||||
/// that takes a user-supplied secret.
|
||||
/// that takes a user-supplied secret. Like a create, the core records the
|
||||
/// imported wallet in its catalogue.
|
||||
pub async fn import_wallet(&self, password: String, seed: String) -> WResult<()> {
|
||||
self.node()?
|
||||
.wallet_restore(&password, &seed)
|
||||
.await
|
||||
.map_err(WireError::new)
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
/// Start the app-owned wallet child (`monero-wallet-rpc`, plus `monerod` for
|
||||
|
|
|
|||
Loading…
Reference in a new issue