From 842b56670064c692eb0bdb3e0115f0c1b093d612 Mon Sep 17 00:00:00 2001 From: darepo-doc-bot Date: Sun, 28 Jun 2026 07:52:28 +0000 Subject: [PATCH] docs: nightly doc-gardening sweep 2026-06-28 Automated sweep via .claude/skills/doc-gardening. Updates per-package CLAUDE.md/AGENTS.md, docs/index.md entries, and ARCHITECTURE.md as needed. New packages documented (from wasm-wallet-bindings PR #803): - cmd/walletdk-wasm: browser WASM entry point over mobile facade - sdk/walletdk/mobile: gomobile-safe JSON facade over sdk/walletdk New packages documented (pre-existing, missing docs): - chainfees: chainfee.Estimator implementations and combinators - coinselect: coin-type-agnostic largest-first selector - internal/sqlbase: WASM-only SQL walletdb backend for lwwallet Updated stale packages: - sdk/walletdk: add GetExitPlan, SweepWallet RPC methods; new Entry DTOs (EntryPhase, EntryProgress, EntryRequest, EntryFailureCode, FailureCode field); error reconstruction mechanism via errmap.go - oor: add ErrOutputPolicyViolation, ErrUserBalanceExceeded typed submit errors (PR #807) Infra: - db: sync AGENTS.md to CLAUDE.md (pre-existing drift) - ARCHITECTURE.md: add five new packages to layer tables - docs/index.md: add walletdk_mobile.md entry --- ARCHITECTURE.md | 5 ++ chainfees/AGENTS.md | 48 ++++++++++++++++++ chainfees/CLAUDE.md | 48 ++++++++++++++++++ cmd/walletdk-wasm/AGENTS.md | 52 +++++++++++++++++++ cmd/walletdk-wasm/CLAUDE.md | 52 +++++++++++++++++++ coinselect/AGENTS.md | 49 ++++++++++++++++++ coinselect/CLAUDE.md | 49 ++++++++++++++++++ db/AGENTS.md | 16 +++--- docs/index.md | 1 + internal/sqlbase/AGENTS.md | 39 +++++++++++++++ internal/sqlbase/CLAUDE.md | 39 +++++++++++++++ oor/AGENTS.md | 16 ++++++ oor/CLAUDE.md | 16 ++++++ sdk/walletdk/AGENTS.md | 58 ++++++++++++++++++--- sdk/walletdk/CLAUDE.md | 40 ++++++++++++++- sdk/walletdk/mobile/AGENTS.md | 94 +++++++++++++++++++++++++++++++++++ sdk/walletdk/mobile/CLAUDE.md | 94 +++++++++++++++++++++++++++++++++++ 17 files changed, 699 insertions(+), 17 deletions(-) create mode 100644 chainfees/AGENTS.md create mode 100644 chainfees/CLAUDE.md create mode 100644 cmd/walletdk-wasm/AGENTS.md create mode 100644 cmd/walletdk-wasm/CLAUDE.md create mode 100644 coinselect/AGENTS.md create mode 100644 coinselect/CLAUDE.md create mode 100644 internal/sqlbase/AGENTS.md create mode 100644 internal/sqlbase/CLAUDE.md create mode 100644 sdk/walletdk/mobile/AGENTS.md create mode 100644 sdk/walletdk/mobile/CLAUDE.md diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index ad59aaf2b..5ae4bb5fe 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -28,6 +28,7 @@ package may import from a higher layer. | [`lib/recovery`](lib/recovery/) | Immutable recovery proof graph, session state machine, TLV codec for unilateral exit | | [`unrollplan`](unrollplan/) | Pure dependency-resolution planner driving unilateral-exit broadcast/sweep ordering | | [`vhtlcrecovery`](vhtlcrecovery/) | Durable control-plane types for vHTLC on-chain recovery jobs (action, state, script parameters, swap linkage) | +| [`coinselect`](coinselect/) | Coin-type-agnostic coin-selection algorithm (largest-first) shared by vtxo and swapwallet; no wallet or RPC dependencies | ### Layer 2: Infrastructure (Chain, Storage, Messaging) @@ -43,6 +44,8 @@ package may import from a higher layer. | [`lwwallet`](lwwallet/) | Lightweight in-process wallet (btcwallet + Esplora, no external LND) | | [`btcwbackend`](btcwbackend/) | Neutrino-backed wallet backend (btcwallet + compact block filters) | | [`walletcore`](walletcore/) | Shared wallet abstractions and boarding logic used by lwwallet and btcwbackend | +| [`chainfees`](chainfees/) | `chainfee.Estimator` implementations and combinators (WalletKit, mempool.space, MinEstimator) | +| [`internal/sqlbase`](internal/sqlbase/) | WASM-only SQL walletdb backend for lwwallet (js/wasm build tag); maps btcwallet nested-bucket semantics to SQL | | [`proofkeys`](proofkeys/) | Interface for wallet-managed key derivation and indexer proof signing | | [`fraud`](fraud/) | Fraud detection actor: watches OOR ancestor outpoints on-chain and triggers unilateral exit when an ancestor is spent | | [`vhtlcrecovery/coordinator`](vhtlcrecovery/coordinator/) | Runtime coordinator for durable vHTLC recovery jobs: arms, escalates into unroll, cancels, and reconciles after restart | @@ -61,10 +64,12 @@ package may import from a higher layer. | [`sdk/ark`](sdk/ark/) | Consumer-facing Go SDK facade: remote or embedded daemon access with typed models | | [`sdk/swaps`](sdk/swaps/) | Lightning-to-Ark / Ark-to-Lightning atomic swap SDK with durable FSM flows | | [`sdk/walletdk`](sdk/walletdk/) | Wallet-shaped SDK facade for host apps: embeds the daemon in-process, dials it over a private bufconn transport, exposes typed methods for the seven core wallet verbs (create, unlock, send, recv, list, balance, exit). The highest-level layer in the stack; wraps `walletdkrpc.WalletService`. Wallet RPC methods gated behind `walletdkrpc` (which transitively requires `swapruntime`) | +| [`sdk/walletdk/mobile`](sdk/walletdk/mobile/) | Gomobile-safe JSON-bytes-in/out facade over sdk/walletdk for iOS/Android/WASM targets; singleton lifecycle, pull-based Subscribe | | [`swapwallet`](swapwallet/) | Optional daemon-side `walletdkrpc.WalletService` implementation (build tags `walletdkrpc swapruntime`): composes the swap subsystem, cooperative leave, boarding, ledger, and unilateral-exit registry behind one flat, swap-vocabulary-free wallet API | | [`swapclientserver`](swapclientserver/) | Optional daemon-side swap subserver (build tag `swapruntime`): translates `swapclientrpc` RPCs into `sdk/swaps` operations and manages the daemon-local worker registry | | [`cmd/darepod`](cmd/darepod/) | Daemon entry point | | [`cmd/darepocli`](cmd/darepocli/) | CLI client | +| [`cmd/walletdk-wasm`](cmd/walletdk-wasm/) | Browser/WASM entry point: installs `walletdkCall` JS bridge over sdk/walletdk/mobile (js/wasm only) | | [`timeout`](timeout/) | Generic timeout scheduling actor | | [`indexer`](indexer/) | Server indexing client for receive script registration | | [`arkrpc`](arkrpc/) | Server-side gRPC service definitions (ArkService, IndexerService) | diff --git a/chainfees/AGENTS.md b/chainfees/AGENTS.md new file mode 100644 index 000000000..3a910c1c1 --- /dev/null +++ b/chainfees/AGENTS.md @@ -0,0 +1,48 @@ +# chainfees + +## Purpose + +Provides reusable `chainfee.Estimator` implementations and combinators for +wallet and daemon chain backends. Bundles three concrete estimators — +`WalletKitEstimator` (queries lnd WalletKit), `MempoolSpaceEstimator` (queries +mempool.space API), and `MinEstimator` (selects the lowest successful estimate +across a set of child estimators) — so backends can compose fee estimation +strategies without re-implementing the interface. + +## Key Types + +- `WalletKitEstimator` — proxies fee estimates to an lndclient WalletKitClient + with configurable timeout and optional degraded-mode fallback on error. +- `WalletKitEstimatorConfig` — config for `WalletKitEstimator`: client, + logger, timeout, fallback flag. +- `MempoolSpaceEstimator` — queries the mempool.space recommended-fee endpoint + with configurable URL, cache TTL, and chain params. Caches the last + successful response to avoid hammering the API on every block. +- `MempoolSpaceConfig` — config for `MempoolSpaceEstimator`. +- `MinEstimator` — queries multiple child estimators and returns the minimum + successful relay fee per KW. +- `NamedEstimator` — wraps a child estimator with a stable name for logging. + +## Relationships + +- **Depends on**: `lnd/lnwallet/chainfee` (Estimator interface), + `lndclient` (WalletKitClient), `btcd/btcutil`, `btclog`. +- **Depended on by**: `darepod` (daemon fee estimation), + `chainbackends` (lnd-backed fee estimation adapter). +- **Sends**: nothing. +- **Receives**: nothing. + +## Invariants + +- All three exported estimator types implement + `github.com/lightningnetwork/lnd/lnwallet/chainfee.Estimator`. +- `MempoolSpaceEstimator` caches the last successful response at the + configured TTL; concurrent callers share the cached estimate without + issuing duplicate HTTP requests. +- `WalletKitEstimator` with the fallback flag returns a static relay fee + rather than propagating errors, so fee estimation can degrade gracefully + when lnd is temporarily unreachable. + +## Deep Docs + +- [ARCHITECTURE.md](../ARCHITECTURE.md) — System-wide package map. diff --git a/chainfees/CLAUDE.md b/chainfees/CLAUDE.md new file mode 100644 index 000000000..3a910c1c1 --- /dev/null +++ b/chainfees/CLAUDE.md @@ -0,0 +1,48 @@ +# chainfees + +## Purpose + +Provides reusable `chainfee.Estimator` implementations and combinators for +wallet and daemon chain backends. Bundles three concrete estimators — +`WalletKitEstimator` (queries lnd WalletKit), `MempoolSpaceEstimator` (queries +mempool.space API), and `MinEstimator` (selects the lowest successful estimate +across a set of child estimators) — so backends can compose fee estimation +strategies without re-implementing the interface. + +## Key Types + +- `WalletKitEstimator` — proxies fee estimates to an lndclient WalletKitClient + with configurable timeout and optional degraded-mode fallback on error. +- `WalletKitEstimatorConfig` — config for `WalletKitEstimator`: client, + logger, timeout, fallback flag. +- `MempoolSpaceEstimator` — queries the mempool.space recommended-fee endpoint + with configurable URL, cache TTL, and chain params. Caches the last + successful response to avoid hammering the API on every block. +- `MempoolSpaceConfig` — config for `MempoolSpaceEstimator`. +- `MinEstimator` — queries multiple child estimators and returns the minimum + successful relay fee per KW. +- `NamedEstimator` — wraps a child estimator with a stable name for logging. + +## Relationships + +- **Depends on**: `lnd/lnwallet/chainfee` (Estimator interface), + `lndclient` (WalletKitClient), `btcd/btcutil`, `btclog`. +- **Depended on by**: `darepod` (daemon fee estimation), + `chainbackends` (lnd-backed fee estimation adapter). +- **Sends**: nothing. +- **Receives**: nothing. + +## Invariants + +- All three exported estimator types implement + `github.com/lightningnetwork/lnd/lnwallet/chainfee.Estimator`. +- `MempoolSpaceEstimator` caches the last successful response at the + configured TTL; concurrent callers share the cached estimate without + issuing duplicate HTTP requests. +- `WalletKitEstimator` with the fallback flag returns a static relay fee + rather than propagating errors, so fee estimation can degrade gracefully + when lnd is temporarily unreachable. + +## Deep Docs + +- [ARCHITECTURE.md](../ARCHITECTURE.md) — System-wide package map. diff --git a/cmd/walletdk-wasm/AGENTS.md b/cmd/walletdk-wasm/AGENTS.md new file mode 100644 index 000000000..2ee514bc8 --- /dev/null +++ b/cmd/walletdk-wasm/AGENTS.md @@ -0,0 +1,52 @@ +# cmd/walletdk-wasm + +## Purpose + +Browser/WASM entry point for the embedded walletdk runtime. Installs a global +`walletdkCall(method, request)` JavaScript function via `syscall/js` and +dispatches each call to the corresponding `sdk/walletdk/mobile` verb, returning +a JS Promise. The daemon, swap, and OOR machinery all run in-process inside the +browser VM with no separate gateway. The bridge never reaches `walletdk.Client` +directly — it always goes through the mobile facade so WASM behavior stays in +sync with the gomobile bindings. + +Only compiles with `GOOS=js GOARCH=wasm -tags "mobile walletdkrpc swapruntime"`. +`stub.go` provides an empty build so `go build ./...` succeeds on other targets. + +## Key Types + +- `main` — installs `walletdkCall` on `js.Global()`, dispatches a + `walletdk-ready` custom event, then parks the Go runtime so exported + callbacks remain live for the page lifetime. +- `walletCall` — the single JS entry point; dispatches the method name to the + corresponding `mobile.*` verb and wraps the result in a Promise. +- `subscriptionHandle` — wraps `*mobile.Subscription` as a JS object with + `next()` (Promise → next entry JSON or null at EOF) and `close()` methods. + +## Relationships + +- **Depends on**: `sdk/walletdk/mobile` (all wallet operations proxied through + the mobile facade). +- **Depended on by**: browser host applications, React Native WASM bridges. +- **Sends**: nothing (invokes mobile facade functions in goroutines). +- **Receives** ← JS host: `walletdkCall(method, request)` invocations. + +## Invariants + +- `walletCall` is the only JS-exported function; all verb dispatch happens + inside its switch. Additional `js.Func` values outside `promise()` must be + released manually — `promise()` already releases its own executor immediately + after the Promise constructor returns to prevent per-call handle leaks. +- The browser data dir defaults to `/darepo` (injected by `startConfig`). + Without this override, `os.UserHomeDir` fails under `wasm_exec.js` with + `"$HOME is not defined"` and aborts start before the wallet boots. Callers + may override via `data_dir` in the start request. +- This package must not import `sdk/walletdk` directly; all access goes through + the `mobile` facade to keep the WASM bridge and gomobile bindings in sync. + +## Deep Docs + +- [sdk/walletdk/mobile/CLAUDE.md](../../sdk/walletdk/mobile/CLAUDE.md) — + The gomobile facade this package wraps. +- [sdk/walletdk/CLAUDE.md](../../sdk/walletdk/CLAUDE.md) — Underlying Go SDK. +- [ARCHITECTURE.md](../../ARCHITECTURE.md) — System-wide package map. diff --git a/cmd/walletdk-wasm/CLAUDE.md b/cmd/walletdk-wasm/CLAUDE.md new file mode 100644 index 000000000..2ee514bc8 --- /dev/null +++ b/cmd/walletdk-wasm/CLAUDE.md @@ -0,0 +1,52 @@ +# cmd/walletdk-wasm + +## Purpose + +Browser/WASM entry point for the embedded walletdk runtime. Installs a global +`walletdkCall(method, request)` JavaScript function via `syscall/js` and +dispatches each call to the corresponding `sdk/walletdk/mobile` verb, returning +a JS Promise. The daemon, swap, and OOR machinery all run in-process inside the +browser VM with no separate gateway. The bridge never reaches `walletdk.Client` +directly — it always goes through the mobile facade so WASM behavior stays in +sync with the gomobile bindings. + +Only compiles with `GOOS=js GOARCH=wasm -tags "mobile walletdkrpc swapruntime"`. +`stub.go` provides an empty build so `go build ./...` succeeds on other targets. + +## Key Types + +- `main` — installs `walletdkCall` on `js.Global()`, dispatches a + `walletdk-ready` custom event, then parks the Go runtime so exported + callbacks remain live for the page lifetime. +- `walletCall` — the single JS entry point; dispatches the method name to the + corresponding `mobile.*` verb and wraps the result in a Promise. +- `subscriptionHandle` — wraps `*mobile.Subscription` as a JS object with + `next()` (Promise → next entry JSON or null at EOF) and `close()` methods. + +## Relationships + +- **Depends on**: `sdk/walletdk/mobile` (all wallet operations proxied through + the mobile facade). +- **Depended on by**: browser host applications, React Native WASM bridges. +- **Sends**: nothing (invokes mobile facade functions in goroutines). +- **Receives** ← JS host: `walletdkCall(method, request)` invocations. + +## Invariants + +- `walletCall` is the only JS-exported function; all verb dispatch happens + inside its switch. Additional `js.Func` values outside `promise()` must be + released manually — `promise()` already releases its own executor immediately + after the Promise constructor returns to prevent per-call handle leaks. +- The browser data dir defaults to `/darepo` (injected by `startConfig`). + Without this override, `os.UserHomeDir` fails under `wasm_exec.js` with + `"$HOME is not defined"` and aborts start before the wallet boots. Callers + may override via `data_dir` in the start request. +- This package must not import `sdk/walletdk` directly; all access goes through + the `mobile` facade to keep the WASM bridge and gomobile bindings in sync. + +## Deep Docs + +- [sdk/walletdk/mobile/CLAUDE.md](../../sdk/walletdk/mobile/CLAUDE.md) — + The gomobile facade this package wraps. +- [sdk/walletdk/CLAUDE.md](../../sdk/walletdk/CLAUDE.md) — Underlying Go SDK. +- [ARCHITECTURE.md](../../ARCHITECTURE.md) — System-wide package map. diff --git a/coinselect/AGENTS.md b/coinselect/AGENTS.md new file mode 100644 index 000000000..ebe042389 --- /dev/null +++ b/coinselect/AGENTS.md @@ -0,0 +1,49 @@ +# coinselect + +## Purpose + +Provides a single, coin-type-agnostic coin-selection algorithm shared across +the client. The package holds no wallet, actor, or RPC dependencies so every +layer that needs a covering subset — the VTXO manager's reservation path and +the swap wallet's send preview alike — selects through the same generic code +rather than growing parallel implementations. + +## Key Types + +- `Request` — selection parameters: `Target` amount, `MinChange` floor, + `SweepAll` flag. `SweepAll` takes precedence and ignores `Target` and + `MinChange`. +- `Result[T]` — selection outcome: `Selected` subset, `Total`, `Change`. +- `AmountFunc[T]` — callback to extract a `btcutil.Amount` from a candidate + of type `T`. + +## Selection Errors + +- `ErrSelectionShortfall` — candidate set cannot cover target; `Result.Total` + carries the full candidate sum so callers can render a precise message. +- `ErrChangeBelowMin` — covering selection exists but change is below the + requested minimum and no exact-fit set was found. +- `ErrNoCandidates` — empty candidate set passed to the selector. +- `ErrInvalidTarget` — non-positive target in a bounded selection. + +## Relationships + +- **Depends on**: `btcd/btcutil` (amount type). +- **Depended on by**: `vtxo` (VTXO manager reservation path), + `swapwallet` (send-preview coin selection). +- **Sends**: nothing. +- **Receives**: nothing. + +## Invariants + +- `SweepAll` takes precedence: when set, `Target` and `MinChange` are ignored + and every candidate is selected. +- The selector is policy-free: it reports why a pass failed via typed errors + and leaves layer-specific diagnostics (e.g. locked liquidity vs. true + shortfall) to callers. +- Error values carry no total on `ErrNoCandidates` and `ErrInvalidTarget`; + only `ErrSelectionShortfall` and `ErrChangeBelowMin` populate `Result.Total`. + +## Deep Docs + +- [ARCHITECTURE.md](../ARCHITECTURE.md) — System-wide package map. diff --git a/coinselect/CLAUDE.md b/coinselect/CLAUDE.md new file mode 100644 index 000000000..ebe042389 --- /dev/null +++ b/coinselect/CLAUDE.md @@ -0,0 +1,49 @@ +# coinselect + +## Purpose + +Provides a single, coin-type-agnostic coin-selection algorithm shared across +the client. The package holds no wallet, actor, or RPC dependencies so every +layer that needs a covering subset — the VTXO manager's reservation path and +the swap wallet's send preview alike — selects through the same generic code +rather than growing parallel implementations. + +## Key Types + +- `Request` — selection parameters: `Target` amount, `MinChange` floor, + `SweepAll` flag. `SweepAll` takes precedence and ignores `Target` and + `MinChange`. +- `Result[T]` — selection outcome: `Selected` subset, `Total`, `Change`. +- `AmountFunc[T]` — callback to extract a `btcutil.Amount` from a candidate + of type `T`. + +## Selection Errors + +- `ErrSelectionShortfall` — candidate set cannot cover target; `Result.Total` + carries the full candidate sum so callers can render a precise message. +- `ErrChangeBelowMin` — covering selection exists but change is below the + requested minimum and no exact-fit set was found. +- `ErrNoCandidates` — empty candidate set passed to the selector. +- `ErrInvalidTarget` — non-positive target in a bounded selection. + +## Relationships + +- **Depends on**: `btcd/btcutil` (amount type). +- **Depended on by**: `vtxo` (VTXO manager reservation path), + `swapwallet` (send-preview coin selection). +- **Sends**: nothing. +- **Receives**: nothing. + +## Invariants + +- `SweepAll` takes precedence: when set, `Target` and `MinChange` are ignored + and every candidate is selected. +- The selector is policy-free: it reports why a pass failed via typed errors + and leaves layer-specific diagnostics (e.g. locked liquidity vs. true + shortfall) to callers. +- Error values carry no total on `ErrNoCandidates` and `ErrInvalidTarget`; + only `ErrSelectionShortfall` and `ErrChangeBelowMin` populate `Result.Total`. + +## Deep Docs + +- [ARCHITECTURE.md](../ARCHITECTURE.md) — System-wide package map. diff --git a/db/AGENTS.md b/db/AGENTS.md index 00ce565e9..535be0224 100644 --- a/db/AGENTS.md +++ b/db/AGENTS.md @@ -147,6 +147,14 @@ For field-level detail, use `go doc github.com/lightninglabs/darepo-client/db.