Introducing a new way to review your PRs.

Read the announcement

jamaljsr / polar

One-click Bitcoin Lightning networks for local app development & testing

View on GitHub

19 documents · Updated Oct 19, 2026

docs / service-client-architecture

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 capabilityImplementationsSelected serviceResulting view
BitcoinbitcoindBitcoindServiceChain, wallet, address, peer, mining, and fund operations
BitcoinbtcdNot implementedThe common Bitcoin contract is present, but calls fail until a backend service exists
LightningLND, litdLndServiceCommon node, peer, channel, invoice, payment, and event operations
Lightningc-lightningCLightningServiceThe same common Lightning view from the Core Lightning API
LightningeclairEclairServiceThe same common Lightning view from the Eclair API
Tap assetstapd, litdTapdServiceAsset, address, transfer, Universe, and asset-channel operations
Litd sessionslitdLitdServiceSub-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.

ContractMain capability groupsShared result examples
BitcoinServiceReadiness, wallet setup, chain state, addresses, peers, mining, and fundsChain information, wallet balances, transaction IDs, and generated blocks
LightningServiceReadiness, node details, balances, addresses, peers, channels, invoices, payments, and channel eventsNode info, peer records, channel status, payment receipts, and channel event types
TapServiceReadiness, assets, balances, addresses, transfers, minting, Universe data, and asset-channel paymentsAsset records, balances, decoded addresses, transfer IDs, roots, and payment receipts
LitdLibraryReadiness, sub-server status, and sessionsNormalized 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 pathRenderer-side entry pointTransport role
LNDLndProxyClientSends typed LND actions and receives channel event streams through IPC
TapdTapdProxyClientSends typed Tapd and Tap-channel actions through IPC
LitdLitdProxyClientSends status and session actions through IPC
EclaireclairApiUses the general HTTP IPC route for local REST calls and WebSocket events
Core LightningclightningApiCalls the local REST API and maintains its event socket in the renderer service path
Bitcoin CoreBitcoindServiceCreates 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:

LayerOwnsDoes not own
FactoryMapping an implementation label to a serviceBackend request shapes or UI state
Service adapterBackend rules, response mapping, units, and capability checksGlobal store state or Electron channel registration
Proxy client or API helperRequest transport, channel use, and backend API callsCommon UI models or workflow sequencing
Store actionCross-node sequencing and state refreshBackend-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 litd support 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

TriggerConsequenceGuard
A new node implementation is missing from its factory mapA store action cannot obtain a usable serviceAdd the implementation to the factory and its shared service contract before exposing the node type
A service receives a node from another implementationThe adapter rejects the call or applies the wrong backend rulesKeep the adapter cast checks and factory mappings aligned
Eclair wallet balance work has no Bitcoin backendThe balance request fails before it can return a normalized resultPass the network backend node to getBalances
A renderer proxy action or prefix differs from the main-process routeThe request has no matching backend handlerKeep shared IPC channels, proxy clients, and proxy listeners synchronized
A channel event listener is not removedRepeated subscriptions can produce duplicate state updatesPair every node listener setup with removal during node cleanup
A caller requests invoice decoding from Core Lightning or EclairThe common operation rejects because those adapters do not implement itCheck backend capability before using the shared method
A btcd node uses a Bitcoin operationThe not-implemented service throws instead of performing the actionUse a supported Bitcoin implementation or add a btcd adapter

Key files

FileWhy to read it
src/…/index.tsDefines the common Bitcoin, Lightning, Tap, Litd, and factory contracts
src/…/types.tsDefines node implementation labels and the data needed to select a service
src/…/bitcoinFactory.tsShows Bitcoin implementation selection
src/…/lightningFactory.tsShows the LND, Core Lightning, Eclair, and Litd Lightning mapping
src/…/tapFactory.tsShows Tapd and Litd asset-service selection
src/…/lndService.tsShows LND response mapping and common Lightning workflows
src/…/clightningService.tsShows Core Lightning REST data and event mapping
src/…/eclairService.tsShows Eclair mapping and its Bitcoin backend dependency
src/…/tapdService.tsShows Tapd asset and asset-channel mapping
src/…/ipcService.tsDefines renderer request, response, and stream behavior
src/…/lndProxyClient.tsDefines the renderer-side LND proxy client
src/…/tapdProxyClient.tsDefines the renderer-side Tapd proxy client
src/…/litdProxyClient.tsDefines the renderer-side Litd session client
src/…/lightning.tsShows factory use in Lightning state and cross-node workflows
src/…/tap.tsShows factory use in Tap asset state and transfers
src/…/network.tsShows service selection during node readiness