A walletdb-compatible key/value backend implemented over database/sql,
built only for js && wasm (every file carries that build tag). It emulates
btcwallet/walletdb buckets/cursors on top of a relational table so
lwwallet can run the wallet stack in the browser (SQLite via
go-wasmsqlite), where the native BoltDB/kvdb backends are unavailable.
db(unexported) — implementswalletdb.DB. Constructed viaNewSqlBackend(ctx, cfg *Config).View/Updatedrive read/read-write transactions with retry via a caller-suppliedresetfunc.Config— driver name, DSN, timeout, schema, table-name prefix, per-backendSQLiteCmdReplacements, andWithTxLevelLock(forces a single-writer in-process lock).readWriteTx/readWriteBucket/readWriteCursor(unexported) — transaction, bucket, and cursor implementations backingwalletdb.ReadTx/walletdb.ReadWriteBucket/walletdb.ReadWriteCursor; buckets and nested buckets are simulated as rows in a single<prefix>_kvtable, with each row'sparent_idself-referencing the row of the bucket it belongs to (NULLfor the top-level bucket).Init(maxConnections int)— initializes the process-global connection pool (dbConnSet) that dedups connections by DSN across callers.
- Depends on:
btcwallet/walletdb(interface being implemented),lnd/sqldb(shared SQL error classification). - Depended on by:
lwwallet(wasm builds only, viainternal/sqlbase).
- Every file is
//go:build js && wasm; this package does not build (and cannot be exercised) on nativeGOOS/GOARCH— useGOOS=js GOARCH=wasm go build ./internal/sqlbaseorgo docto inspect it. DefaultNumTxRetries = 50:Update/Viewretry on transaction errors that permit repetition, calling the caller'sresetbefore each retry.WithTxLevelLockserializes all read-write transactions through a single in-process lock; omit it only for backends that tolerate concurrent writers.- Buckets/cursors are simulated over SQL tables, not a native KV store — key
ordering and cursor semantics must match
walletdb's contract exactly, or callers built againstwalletdb(e.g. the wallet's key-derivation state) silently misbehave.
- ARCHITECTURE.md — System-wide package map.