Skip to content

Commit b85ab4c

Browse files
committed
phoenix handle null channels
1 parent afab5b1 commit b85ab4c

File tree

3 files changed

+6
-238
lines changed

3 files changed

+6
-238
lines changed

bindings/lni_nodejs/index.d.ts

Lines changed: 3 additions & 234 deletions
Original file line numberDiff line numberDiff line change
@@ -3,237 +3,6 @@
33

44
/* auto-generated by NAPI-RS */
55

6-
export interface PhoenixdConfig {
7-
url: string
8-
password: string
9-
socks5Proxy?: string
10-
acceptInvalidCerts?: boolean
11-
httpTimeout?: number
12-
}
13-
export interface PhoenixdNode {
14-
config: PhoenixdConfig
15-
}
16-
export interface Bolt11Resp {
17-
amountSat: number
18-
paymentHash: string
19-
serialized: string
20-
}
21-
export interface PhoenixPayInvoiceResp {
22-
amountSat: number
23-
routingFeeSat: number
24-
paymentId: string
25-
paymentHash: string
26-
preimage: string
27-
}
28-
export interface ClnConfig {
29-
url: string
30-
rune: string
31-
socks5Proxy?: string
32-
acceptInvalidCerts?: boolean
33-
httpTimeout?: number
34-
}
35-
export interface ClnNode {
36-
config: ClnConfig
37-
}
38-
export interface LndConfig {
39-
url: string
40-
macaroon: string
41-
socks5Proxy?: string
42-
acceptInvalidCerts?: boolean
43-
httpTimeout?: number
44-
}
45-
export interface LndNode {
46-
config: LndConfig
47-
}
48-
export const enum InvoiceType {
49-
Bolt11 = 'Bolt11',
50-
Bolt12 = 'Bolt12'
51-
}
52-
export interface TlvRecord {
53-
type: number
54-
value: string
55-
}
56-
export interface NodeInfo {
57-
alias: string
58-
color: string
59-
pubkey: string
60-
network: string
61-
blockHeight: number
62-
blockHash: string
63-
sendBalanceMsat: number
64-
receiveBalanceMsat: number
65-
feeCreditBalanceMsat: number
66-
unsettledSendBalanceMsat: number
67-
unsettledReceiveBalanceMsat: number
68-
pendingOpenSendBalance: number
69-
pendingOpenReceiveBalance: number
70-
}
71-
export interface Transaction {
72-
type: string
73-
invoice: string
74-
description: string
75-
descriptionHash: string
76-
preimage: string
77-
paymentHash: string
78-
amountMsats: number
79-
feesPaid: number
80-
createdAt: number
81-
expiresAt: number
82-
settledAt: number
83-
payerNote?: string
84-
externalId?: string
85-
}
86-
export interface NodeConnectionInfo {
87-
pubkey: string
88-
address: string
89-
port: number
90-
}
91-
export interface Channel {
92-
localBalance: number
93-
localSpendableBalance: number
94-
remoteBalance: number
95-
id: string
96-
remotePubkey: string
97-
fundingTxId: string
98-
fundingTxVout: number
99-
active: boolean
100-
public: boolean
101-
internalChannel: string
102-
confirmations: number
103-
confirmationsRequired: number
104-
forwardingFeeBaseMsat: number
105-
unspendablePunishmentReserve: number
106-
counterpartyUnspendablePunishmentReserve: number
107-
error: string
108-
isOutbound: boolean
109-
}
110-
export interface NodeStatus {
111-
isReady: boolean
112-
internalNodeStatus: string
113-
}
114-
export interface ConnectPeerRequest {
115-
pubkey: string
116-
address: string
117-
port: number
118-
}
119-
export interface OpenChannelRequest {
120-
pubkey: string
121-
amountMsats: number
122-
public: boolean
123-
}
124-
export interface OpenChannelResponse {
125-
fundingTxId: string
126-
}
127-
export interface CloseChannelRequest {
128-
channelId: string
129-
nodeId: string
130-
force: boolean
131-
}
132-
export interface UpdateChannelRequest {
133-
channelId: string
134-
nodeId: string
135-
forwardingFeeBaseMsat: number
136-
maxDustHtlcExposureFromFeeRateMultiplier: number
137-
}
138-
export interface CloseChannelResponse {
139-
140-
}
141-
export interface PendingBalanceDetails {
142-
channelId: string
143-
nodeId: string
144-
amountMsats: number
145-
fundingTxId: string
146-
fundingTxVout: number
147-
}
148-
export interface OnchainBalanceResponse {
149-
spendable: number
150-
total: number
151-
reserved: number
152-
pendingBalancesFromChannelClosures: number
153-
pendingBalancesDetails: Array<PendingBalanceDetails>
154-
internalBalances: string
155-
}
156-
export interface PeerDetails {
157-
nodeId: string
158-
address: string
159-
isPersisted: boolean
160-
isConnected: boolean
161-
}
162-
export interface LightningBalanceResponse {
163-
totalSpendable: number
164-
totalReceivable: number
165-
nextMaxSpendable: number
166-
nextMaxReceivable: number
167-
nextMaxSpendableMpp: number
168-
nextMaxReceivableMpp: number
169-
}
170-
export interface PayInvoiceResponse {
171-
paymentHash: string
172-
preimage: string
173-
feeMsats: number
174-
}
175-
export interface PayKeysendResponse {
176-
fee: number
177-
}
178-
export interface BalancesResponse {
179-
onchain: OnchainBalanceResponse
180-
lightning: LightningBalanceResponse
181-
}
182-
export interface PaymentFailedEventProperties {
183-
transaction: Transaction
184-
reason: string
185-
}
186-
export interface ListTransactionsParams {
187-
from: number
188-
limit: number
189-
paymentHash?: string
190-
}
191-
export interface CreateInvoiceParams {
192-
invoiceType: InvoiceType
193-
amountMsats?: number
194-
offer?: string
195-
description?: string
196-
descriptionHash?: string
197-
expiry?: number
198-
rPreimage?: string
199-
isBlinded?: boolean
200-
isKeysend?: boolean
201-
isAmp?: boolean
202-
isPrivate?: boolean
203-
}
204-
export interface PayCode {
205-
offerId: string
206-
bolt12: string
207-
label?: string
208-
active?: boolean
209-
singleUse?: boolean
210-
used?: boolean
211-
}
212-
export interface PayInvoiceParams {
213-
invoice: string
214-
feeLimitMsat?: number
215-
feeLimitPercentage?: number
216-
timeoutSeconds?: number
217-
amountMsats?: number
218-
maxParts?: number
219-
firstHopPubkey?: string
220-
lastHopPubkey?: string
221-
allowSelfPayment?: boolean
222-
isAmp?: boolean
223-
}
224-
export interface OnInvoiceEventParams {
225-
paymentHash: string
226-
pollingDelaySec: number
227-
maxPollingSec: number
228-
}
229-
export interface Payment {
230-
paymentId: string
231-
circId: string
232-
round: number
233-
relayFingerprint: string
234-
updatedAt: number
235-
amountMsats: number
236-
}
2376
export declare class PhoenixdNode {
2387
constructor(config: PhoenixdConfig)
2398
getUrl(): string
@@ -243,7 +12,7 @@ export declare class PhoenixdNode {
24312
createInvoice(params: CreateInvoiceParams): Transaction
24413
payInvoice(params: PayInvoiceParams): PayInvoiceResponse
24514
getOffer(): PayCode
246-
lookupInvoice(paymentHash: string): Transaction
15+
lookupInvoice(params: LookupInvoiceParams): Transaction
24716
payOffer(offer: string, amountMsats: number, payerNote?: string | undefined | null): PayInvoiceResponse
24817
listTransactions(params: ListTransactionsParams): Array<Transaction>
24918
onInvoiceEvents(params: OnInvoiceEventParams, callback: (arg0: string, arg1?: Transaction | undefined | null) => void): void
@@ -259,7 +28,7 @@ export declare class ClnNode {
25928
getOffer(search?: string | undefined | null): PayCode
26029
listOffers(search?: string | undefined | null): Array<PayCode>
26130
payOffer(offer: string, amountMsats: number, payerNote?: string | undefined | null): PayInvoiceResponse
262-
lookupInvoice(paymentHash: string): Transaction
31+
lookupInvoice(params: LookupInvoiceParams): Transaction
26332
listTransactions(params: ListTransactionsParams): Array<Transaction>
26433
decode(str: string): string
26534
onInvoiceEvents(params: OnInvoiceEventParams, callback: (arg0: string, arg1?: Transaction | undefined | null) => void): void
@@ -275,7 +44,7 @@ export declare class LndNode {
27544
getOffer(search?: string | undefined | null): PayCode
27645
listOffers(search?: string | undefined | null): Array<PayCode>
27746
payOffer(offer: string, amountMsats: number, payerNote?: string | undefined | null): PayInvoiceResponse
278-
lookupInvoice(paymentHash: string): Transaction
47+
lookupInvoice(params: LookupInvoiceParams): Transaction
27948
listTransactions(params: ListTransactionsParams): Array<Transaction>
28049
decode(str: string): string
28150
onInvoiceEvents(params: OnInvoiceEventParams, callback: (arg0: string, arg1?: Transaction | undefined | null) => void): void

bindings/lni_nodejs/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,8 @@ if (!nativeBinding) {
310310
throw new Error(`Failed to load native binding`)
311311
}
312312

313-
const { InvoiceType, PhoenixdNode, ClnNode, LndNode } = nativeBinding
313+
const { PhoenixdNode, ClnNode, LndNode } = nativeBinding
314314

315-
module.exports.InvoiceType = InvoiceType
316315
module.exports.PhoenixdNode = PhoenixdNode
317316
module.exports.ClnNode = ClnNode
318317
module.exports.LndNode = LndNode

crates/lni/phoenixd/api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ pub fn get_info(config: &PhoenixdConfig) -> Result<NodeInfo, ApiError> {
7373
network: "bitcoin".to_string(),
7474
block_height: 0,
7575
block_hash: "".to_string(),
76-
send_balance_msat: info.channels[0].balance_sat * 1000,
77-
receive_balance_msat: info.channels[0].inbound_liquidity_sat * 1000,
76+
send_balance_msat: info.channels.first().map_or(0, |c| c.balance_sat * 1000),
77+
receive_balance_msat: info.channels.first().map_or(0, |c| c.inbound_liquidity_sat * 1000),
7878
fee_credit_balance_msat: balance.fee_credit_sat * 1000,
7979
..Default::default()
8080
};

0 commit comments

Comments
 (0)