Skip to content

Commit 2a0cab2

Browse files
authored
Search (#10)
* search cln * phoenix search * fix type * phoenix handle null channels * phoenixd create offer bolt12 * fix bolt12 params
1 parent e9e891e commit 2a0cab2

File tree

13 files changed

+440
-375
lines changed

13 files changed

+440
-375
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

bindings/lni_nodejs/src/cln.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use lni::{cln::lib::ClnConfig, CreateInvoiceParams, PayInvoiceParams};
1+
use lni::{cln::lib::ClnConfig, CreateInvoiceParams, LookupInvoiceParams, PayInvoiceParams};
22
use napi::bindgen_prelude::*;
33
use napi_derive::napi;
44
#[napi]
@@ -84,9 +84,10 @@ impl ClnNode {
8484
}
8585

8686
#[napi]
87-
pub fn lookup_invoice(&self, payment_hash: String) -> napi::Result<lni::Transaction> {
88-
let txn = lni::cln::api::lookup_invoice(&self.inner, Some(payment_hash), None, None)
89-
.map_err(|e| napi::Error::from_reason(e.to_string()))?;
87+
pub fn lookup_invoice(&self, params: LookupInvoiceParams) -> napi::Result<lni::Transaction> {
88+
let txn =
89+
lni::cln::api::lookup_invoice(&self.inner, params.payment_hash, None, None, params.search)
90+
.map_err(|e| napi::Error::from_reason(e.to_string()))?;
9091
Ok(txn)
9192
}
9293

@@ -95,8 +96,9 @@ impl ClnNode {
9596
&self,
9697
params: lni::types::ListTransactionsParams,
9798
) -> napi::Result<Vec<lni::Transaction>> {
98-
let txns = lni::cln::api::list_transactions(&self.inner, params.from, params.limit)
99-
.map_err(|e| napi::Error::from_reason(e.to_string()))?;
99+
let txns =
100+
lni::cln::api::list_transactions(&self.inner, params.from, params.limit, params.search)
101+
.map_err(|e| napi::Error::from_reason(e.to_string()))?;
100102
Ok(txns)
101103
}
102104

bindings/lni_nodejs/src/lnd.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use lni::{lnd::lib::LndConfig, CreateInvoiceParams, PayInvoiceParams};
1+
use lni::{lnd::lib::LndConfig, CreateInvoiceParams, LookupInvoiceParams, PayInvoiceParams};
22
use napi::bindgen_prelude::*;
33
use napi_derive::napi;
44
#[napi]
@@ -82,9 +82,10 @@ impl LndNode {
8282
}
8383

8484
#[napi]
85-
pub fn lookup_invoice(&self, payment_hash: String) -> napi::Result<lni::Transaction> {
86-
let txn = lni::lnd::api::lookup_invoice(&self.inner, Some(payment_hash))
87-
.map_err(|e| napi::Error::from_reason(e.to_string()))?;
85+
pub fn lookup_invoice(&self, params: LookupInvoiceParams) -> napi::Result<lni::Transaction> {
86+
let txn =
87+
lni::lnd::api::lookup_invoice(&self.inner, params.payment_hash, None, None, params.search)
88+
.map_err(|e| napi::Error::from_reason(e.to_string()))?;
8889
Ok(txn)
8990
}
9091

@@ -93,8 +94,9 @@ impl LndNode {
9394
&self,
9495
params: lni::types::ListTransactionsParams,
9596
) -> napi::Result<Vec<lni::Transaction>> {
96-
let txns = lni::lnd::api::list_transactions(&self.inner, params.from, params.limit)
97-
.map_err(|e| napi::Error::from_reason(e.to_string()))?;
97+
let txns =
98+
lni::lnd::api::list_transactions(&self.inner, params.from, params.limit, params.search)
99+
.map_err(|e| napi::Error::from_reason(e.to_string()))?;
98100
Ok(txns)
99101
}
100102

bindings/lni_nodejs/src/phoenixd.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use lni::{phoenixd::lib::PhoenixdConfig, CreateInvoiceParams, PayInvoiceParams};
1+
use lni::{
2+
phoenixd::lib::PhoenixdConfig, CreateInvoiceParams, LookupInvoiceParams, PayInvoiceParams,
3+
};
24
use napi::bindgen_prelude::*;
35
use napi_derive::napi;
46

@@ -65,9 +67,15 @@ impl PhoenixdNode {
6567
}
6668

6769
#[napi]
68-
pub fn lookup_invoice(&self, payment_hash: String) -> napi::Result<lni::Transaction> {
69-
let txn = lni::phoenixd::api::lookup_invoice(&self.inner, payment_hash)
70-
.map_err(|e| napi::Error::from_reason(e.to_string()))?;
70+
pub fn lookup_invoice(&self, params: LookupInvoiceParams) -> napi::Result<lni::Transaction> {
71+
let txn = lni::phoenixd::api::lookup_invoice(
72+
&self.inner,
73+
params.payment_hash,
74+
None,
75+
None,
76+
params.search,
77+
)
78+
.map_err(|e| napi::Error::from_reason(e.to_string()))?;
7179
Ok(txn)
7280
}
7381

@@ -88,7 +96,7 @@ impl PhoenixdNode {
8896
&self,
8997
params: crate::ListTransactionsParams,
9098
) -> napi::Result<Vec<lni::Transaction>> {
91-
let txns = lni::phoenixd::api::list_transactions(&self.inner, params.from, params.limit, None)
99+
let txns = lni::phoenixd::api::list_transactions(&self.inner, params)
92100
.map_err(|e| napi::Error::from_reason(e.to_string()))?;
93101
Ok(txns)
94102
}

0 commit comments

Comments
 (0)