Add LNbits Lightning backend integration - #102
Conversation
kwsantiago
left a comment
There was a problem hiding this comment.
This integration looks solid overall. I left some comments, but at a high-level:
- Missing error handling for LNbits-specific API failures vs network failures
- No retry logic for failed HTTP requests (unlike gRPC which may have built-in retry logic)
| private fetchService: FetchService, | ||
| ) {} | ||
|
|
||
| private getApiCredentials() { |
There was a problem hiding this comment.
This function is called on every HTTP request, consider caching credentials in onModuleInit() instead to avoid repeated config lookups.
| } | ||
|
|
||
| private async makeHttpRequest(endpoint: string, options: RequestInit = {}): Promise<any> { | ||
| const credentials = this.getApiCredentials(); |
There was a problem hiding this comment.
Store credentials once during initialization instead of calling getApiCredentials() on every request.
|
|
||
| return await response.json(); | ||
| } catch (error) { | ||
| this.logger.error(`LNbits request failed: ${error.message}`); |
There was a problem hiding this comment.
Does error.message exist on all error types? If so, you may want to wrap in case the throw loses the original error.
| return { | ||
| balance: balanceStr, | ||
| pending_open_balance: '0', | ||
| local_balance: {sat: balanceStr, msat: (parseInt(balanceStr) * 1000).toString()}, |
There was a problem hiding this comment.
parseInt(balanceStr, 10)
| if (address.startsWith('bc1p') || address.startsWith('tb1p')) { | ||
| return LightningAddressType.TAPROOT_PUBKEY; | ||
| } | ||
| return LightningAddressType.UNKOWN; |
| } | ||
|
|
||
| export function mapRequestType(type?: string): LightningRequestType { | ||
| return LightningRequestType.BOLT11_INVOICE; |
There was a problem hiding this comment.
This function always returns BOLT11_INVOICE so why do you have type in the function?
| private readonly logger = new Logger(LightningService.name); | ||
|
|
||
| private grpc_client: any = null; | ||
| private http_client: any = null; |
There was a problem hiding this comment.
Only one of (http_client or grpc_client) is being used at a time, so you may want to make a single client var to simplify.
| private readonly logger = new Logger(LightningWalletKitService.name); | ||
|
|
||
| private grpc_client: any = null; | ||
| private http_client: any = null; |
There was a problem hiding this comment.
Only one of (http_client or grpc_client) is being used at a time, so you may want to make a single client var to simplify.
Implement LNbits as third Lightning backend option alongside LND and CLN.
Add HTTP REST API client, configuration support, and integration into existing Lightning architecture.
Configuration
To use LNbits as Lightning backend, add these lines to your
.envfile:Set Lightning type to lnbits
LIGHTNING_TYPE=lnbits
LNbits server configuration
LIGHTNING_API_URL=https://your.lnbits.server
LIGHTNING_API_KEY=your_wallet_api_key_here
Replace https://your.lnbits.server with your LNbits instance URL and your_wallet_api_key_here with your wallet's API key from LNbits.
Technical Details
• Uses LNbits native /api/v1/wallet endpoint for reliable balance retrieval
• Implements proper units conversion (millisats to sats)
• Follows existing NestJS patterns for dependency injection
• Maintains compatibility with existing LND/CLN integrations