store: a wallet catalogue in the encrypted db (wallets table + CRUD) #141
Loading…
Reference in a new issue
No description provided.
Delete branch "wt/t_64c9ba3c"
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?
What
A created wallet was not remembered: a wallet existed only as a file under
$ONIONWIRE_HOME/walletplus the single-rowwallet_childconfig describing the one the child is currently pointed at. There was no list, so a restart had nothing to read back, and a second create had no distinct file name to use.This lands the schema half (card t_64c9ba3c) of the decomposition of #140:
wallets(id, name, identity_pubkey, onion_locator, wallet_filename, created_at), created by the additiveCREATE TABLE IF NOT EXISTSbatch on every open, so an existing install gains it in placeStore::create_wallet(&NewWallet) -> WalletRecord(returns the stored row, id + created_at assigned),get_wallet_by_id,list_wallets(oldest first, id breaks a created_at tie),delete_wallet(bool)NewWallet/WalletRecordre-exported from the crate rootSchema decisions
wallet_filenameis UNIQUE. Creating a second wallet is not a rewrite of the first: it gets its own file name, otherwise both wallets open the same file and the second create reads as a failure. A duplicate returns a named error and leaves the first row untouched.identity_pubkeyis NOT unique: identity is the pubkey and it is the roster key, while a wallet is one file. Several wallets may belong to one identity.onion_locatoris a locator, not an identity: it rotates (F4) and is allowed empty before the HS publishes. Stale locators are expected, never treated as an error.nameis optional; a blank or whitespace-only label is stored as SQL NULL, never as an empty string.delete_walletdrops the catalogue row only. The wallet file on disk and recorded payments stay put.Crate choice
No new dependency. The store is already
rusqlitewith thebundled-sqlcipher-vendored-opensslfeature and a rawPRAGMA keyas the first statement after open;sqlxhas no SQLCipher path, so adding it would mean a second connection path into the db that is not encrypted.rusqlitestays.Tests
TDD, RED first (the new tests did not compile:
E0422 no struct NewWallet,E0599 no method create_wallet/list_wallets/get_wallet_by_id).tests/store.rs: fields round-trip; two wallets coexist and survive a reopen; a duplicate filename is rejected and the first row is intact; delete removes only that row and an unknown id reports false; blank label plus a blank-filename rejection.src/store.rsmod at_rest: a store with thewalletstable dropped re-gains it on reopen (the upgrade path) and the API works on the recreated table.Verification on this branch:
Scope note: this PR is schema + CRUD only. The creation path (
t_511023b6), the wallet-selection screen (t_14ac0a3f) and the wiring (t_895853ad) are separate cards; the store API above is what they build on.No braces in this body on purpose (Forgejo consumes template syntax in PR bodies).