Bitcoin and Lightning service clients
The renderer service layer gives application features one set of operations for local Bitcoin, Lightning, Litd, and Tap nodes. Factories select a service from each node's implementation, while each service hides backend response shapes and transport rules. Electron proxy clients carry selected requests to the main process when the node API must stay behind the desktop boundary.
Service selection
Factories choose the adapter for a node at the point where a store action needs it. This keeps application flows focused on capabilities rather than on whether a node uses Bitcoin Core RPC, an LND API, a REST API, or a Tapd API.
| Node capability | Implementations | Selected service | Resulting view |
|---|---|---|---|
| Bitcoin | bitcoind | BitcoindService | Chain, wallet, address, peer, mining, and fund operations |
| Bitcoin | btcd | Not implemented | The common Bitcoin contract is present, but calls fail until a backend service exists |
| Lightning | LND, litd | LndService | Common node, peer, channel, invoice, payment, and event operations |
| Lightning | c-lightning | CLightningService | The same common Lightning view from the Core Lightning API |
| Lightning | eclair | EclairService | The same common Lightning view from the Eclair API |
| Tap assets | tapd, litd | TapdService | Asset, address, transfer, Universe, and asset-channel operations |
| Litd sessions | litd | LitdService | Sub-server status and remote access session operations |
The litd implementation has more than one service view. The Lightning factory treats it as LND-compatible, the Tap factory treats it as Tapd-compatible, and the separate Litd service handles Litd sessions. The node's role in a feature determines which factory the feature uses.
The following diagram shows how a feature reaches a backend through the selected service.
flowchart LR
Feature[Renderer feature] --> Factory[Capability factory]
Factory --> Service[Common service contract]
Service --> Adapter[Backend service adapter]
Adapter --> Client[Renderer proxy client or API helper]
Client --> Boundary[Electron IPC or local API boundary]
Boundary --> Backend[Local node backend]
Factory mappings
BitcoinFactory, LightningFactory, and TapFactory map implementation labels to service objects. Their public result is a common contract defined in src/…/index.ts, so store models can request a service without selecting a backend themselves.
References: src/…/bitcoinFactory.ts• L6-29 src/…/lightningFactory.ts• L7-32 src/…/tapFactory.ts• L5-27 src/…/index.ts• L157-214
Common service contracts
The service contracts define the capabilities that application features can rely on. They also define the normalized data that the UI and store models receive after each backend adapter maps its native response.
| Contract | Main capability groups | Shared result examples |
|---|---|---|
BitcoinService | Readiness, wallet setup, chain state, addresses, peers, mining, and funds | Chain information, wallet balances, transaction IDs, and generated blocks |
LightningService | Readiness, node details, balances, addresses, peers, channels, invoices, payments, and channel events | Node info, peer records, channel status, payment receipts, and channel event types |
TapService | Readiness, assets, balances, addresses, transfers, minting, Universe data, and asset-channel payments | Asset records, balances, decoded addresses, transfer IDs, roots, and payment receipts |
LitdLibrary | Readiness, sub-server status, and sessions | Normalized session state, type, keys, and time values |
The normalized Lightning model uses one channel shape for open and pending channels. It uses one event vocabulary for the different event forms reported by LND, Core Lightning, and Eclair. Tap services apply the same idea to asset records and payment receipts.
References: src/…/index.ts• L157-204 src/…/index.ts• L214-272 src/…/types.ts• L6-83 src/…/types.ts• L5-59 src/…/types.ts• L1-13
Backend response mapping
Each Lightning adapter turns backend names, units, status values, and record layouts into the shared service types. This lets a caller use one flow for node details, peers, channels, invoices, and payments while the adapter handles backend-specific rules.
LND reads open and pending channel groups and combines them into one list. Core Lightning and Eclair map their channel states into the common status values. Eclair obtains wallet balances from its Bitcoin backend because its service does not own the wallet data needed for that view.
References: src/…/lndService.ts• L11-70 src/…/clightningService.ts• L52-118 src/…/eclairService.ts• L33-122 src/…/eclairService.ts• L51-63
Electron client boundary
Renderer proxy clients provide typed calls for node APIs that run through the Electron main process. The client adds the service channel and node payload, then returns the main-process result as a promise. Stream clients use the same boundary for long-lived channel event updates.
The main transport paths are different because the backends expose different interfaces:
| Backend path | Renderer-side entry point | Transport role |
|---|---|---|
| LND | LndProxyClient | Sends typed LND actions and receives channel event streams through IPC |
| Tapd | TapdProxyClient | Sends typed Tapd and Tap-channel actions through IPC |
| Litd | LitdProxyClient | Sends status and session actions through IPC |
| Eclair | eclairApi | Uses the general HTTP IPC route for local REST calls and WebSocket events |
| Core Lightning | clightningApi | Calls the local REST API and maintains its event socket in the renderer service path |
| Bitcoin Core | BitcoindService | Creates a local Bitcoin Core RPC client for the node's RPC port |
The IPC sender gives each request a unique reply channel. This prevents concurrent calls from receiving each other's responses. It also turns an error returned by the main process into a rejected service call.
The following diagram shows the two broad transport patterns used by the service layer.
sequenceDiagram
participant R as Renderer service
participant C as Proxy client
participant M as Electron main process
participant N as Local node API
R->>C: Call capability
C->>M: IPC request with node and data
M->>N: Authenticated local API request
N-->>M: Backend response or stream event
M-->>C: IPC response or event
C-->>R: Normalized service result
Request and event paths
The LND, Tapd, and Litd clients use service-specific IPC prefixes. Eclair uses the general app HTTP channel because its API is a local HTTP endpoint. These clients keep feature code separate from channel names and backend request structures.
Event subscriptions follow the node lifecycle. A service creates a listener for channel changes and removes it when the node is no longer used. The normalized callback reports Pending, Open, Closed, or Unknown instead of exposing each backend's event format.
References: src/…/ipcService.ts• L5-13 src/…/ipcService.ts• L30-92 src/…/lndProxyClient.ts• L15-117 src/…/tapdProxyClient.ts• L6-90 src/…/litdProxyClient.ts• L6-36 src/…/eclairApi.ts• L10-34 src/…/eclairApi.ts• L56-101
Service-driven workflows
Store actions use factories as the handoff between application state and node APIs. A Lightning action selects a service for the source node, while a Bitcoin or Tap action selects the service for the node involved in that operation. This allows one user flow to cross service boundaries without exposing backend details to the UI.
Common relationships include:
- A Lightning deposit gets a new address from the Lightning service, sends coins through the Bitcoin service, then waits for the nodes to process the mined blocks.
- A Lightning channel action uses the source adapter to connect to the destination and open or close the channel. The store then waits for chain confirmation before it refreshes channel state.
- An Eclair balance request uses the selected Bitcoin service because Eclair relies on its Bitcoin backend for wallet data.
- A Tap asset-channel action uses the Tap service for asset operations and the Lightning service for node identity or invoice data.
The child pages Lightning service capabilities and Tap asset services describe those capability groups in more detail.
Readiness and state updates
Node startup waits through the service that owns each capability. Bitcoin and ordinary Lightning nodes use their selected factory service. Litd readiness uses LitdService so all enabled Litd sub-servers are ready. Tap nodes use the Tap factory service. Once readiness succeeds, the store marks the node started and refreshes the related state.
References: src/…/network.ts• L864-931 src/…/lightning.ts• L130-159 src/…/lightning.ts• L186-249 src/…/tap.ts• L191-218
Cross-service operations
Some operations need more than one node capability. The store keeps these relationships at the workflow level rather than adding Bitcoin or Lightning behavior to another backend adapter. This preserves the boundary between a service's normalized operation and the larger action that coordinates confirmation, state refresh, and chart updates.
Tap asset payments show this relationship clearly. The Litd model checks asset-channel state, uses the Tap service to create or send the asset payment, and uses the Lightning service to decode the invoice. The result then drives the normal Lightning and designer refresh path.
References: src/…/lit.ts• L117-183 src/…/tap.ts• L240-309 src/…/tap.ts• L315-364 src/…/lightning.ts• L186-203
Capability boundaries
The factory layer selects a service, the service layer presents a common contract, and the proxy client or API helper carries the backend request. Each layer has a separate reason to change:
| Layer | Owns | Does not own |
|---|---|---|
| Factory | Mapping an implementation label to a service | Backend request shapes or UI state |
| Service adapter | Backend rules, response mapping, units, and capability checks | Global store state or Electron channel registration |
| Proxy client or API helper | Request transport, channel use, and backend API calls | Common UI models or workflow sequencing |
| Store action | Cross-node sequencing and state refresh | Backend-specific response parsing |
An implementation guard protects each adapter from receiving the wrong node type. A missing factory mapping or an unsupported operation is therefore a capability problem, not a transport choice that callers should solve themselves.
References: src/…/bitcoindService.ts• L14-35 src/…/lndService.ts• L308-313 src/…/clightningService.ts• L284-291 src/…/eclairService.ts• L308-319 src/…/tapdService.ts• L213-218 src/…/notImplementedService.ts• L6-40 src/…/notImplementedService.ts• L6-82
Change checklist
When these files or sections are changed, remember to consider these:
- Keep implementation labels aligned across shared/types.ts, each factory map, and the service's node validation guard.
- Keep each normalized result field aligned with every backend mapper and with the store models that consume it.
- Keep
litdsupport aligned across the LND, Tap, and Litd service views because one node can enter all three paths. - Keep proxy prefixes and action names aligned across the renderer client, shared IPC channels, and main-process listener.
- Preserve the backend dependency for Eclair wallet balances and Tap asset-channel invoice flows when service contracts change.
- Keep stream subscription and removal behavior paired when channel event payloads or node identity keys change.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A new node implementation is missing from its factory map | A store action cannot obtain a usable service | Add the implementation to the factory and its shared service contract before exposing the node type |
| A service receives a node from another implementation | The adapter rejects the call or applies the wrong backend rules | Keep the adapter cast checks and factory mappings aligned |
| Eclair wallet balance work has no Bitcoin backend | The balance request fails before it can return a normalized result | Pass the network backend node to getBalances |
| A renderer proxy action or prefix differs from the main-process route | The request has no matching backend handler | Keep shared IPC channels, proxy clients, and proxy listeners synchronized |
| A channel event listener is not removed | Repeated subscriptions can produce duplicate state updates | Pair every node listener setup with removal during node cleanup |
| A caller requests invoice decoding from Core Lightning or Eclair | The common operation rejects because those adapters do not implement it | Check backend capability before using the shared method |
A btcd node uses a Bitcoin operation | The not-implemented service throws instead of performing the action | Use a supported Bitcoin implementation or add a btcd adapter |
Key files
| File | Why to read it |
|---|---|
| src/…/index.ts | Defines the common Bitcoin, Lightning, Tap, Litd, and factory contracts |
| src/…/types.ts | Defines node implementation labels and the data needed to select a service |
| src/…/bitcoinFactory.ts | Shows Bitcoin implementation selection |
| src/…/lightningFactory.ts | Shows the LND, Core Lightning, Eclair, and Litd Lightning mapping |
| src/…/tapFactory.ts | Shows Tapd and Litd asset-service selection |
| src/…/lndService.ts | Shows LND response mapping and common Lightning workflows |
| src/…/clightningService.ts | Shows Core Lightning REST data and event mapping |
| src/…/eclairService.ts | Shows Eclair mapping and its Bitcoin backend dependency |
| src/…/tapdService.ts | Shows Tapd asset and asset-channel mapping |
| src/…/ipcService.ts | Defines renderer request, response, and stream behavior |
| src/…/lndProxyClient.ts | Defines the renderer-side LND proxy client |
| src/…/tapdProxyClient.ts | Defines the renderer-side Tapd proxy client |
| src/…/litdProxyClient.ts | Defines the renderer-side Litd session client |
| src/…/lightning.ts | Shows factory use in Lightning state and cross-node workflows |
| src/…/tap.ts | Shows factory use in Tap asset state and transfers |
| src/…/network.ts | Shows service selection during node readiness |