Skip to content

Commit 61a4378

Browse files
committed
cln nodejs
1 parent e7343aa commit 61a4378

File tree

10 files changed

+264
-238
lines changed

10 files changed

+264
-238
lines changed

bindings/lni_nodejs/index.d.ts

Lines changed: 7 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -3,173 +3,6 @@
33

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

6-
export interface PhoenixdConfig {
7-
url: string
8-
password: string
9-
}
10-
export interface PhoenixdNode {
11-
url: string
12-
password: string
13-
}
14-
export interface Bolt11Resp {
15-
amountSat: number
16-
paymentHash: string
17-
serialized: string
18-
}
19-
export interface PhoenixdMakeInvoiceParams {
20-
invoiceType: InvoiceType
21-
amountMsats: number
22-
description?: string
23-
descriptionHash?: string
24-
expiry?: number
25-
}
26-
export interface ListTransactionsParams {
27-
from: number
28-
until: number
29-
limit: number
30-
offset: number
31-
unpaid: boolean
32-
invoiceType: string
33-
}
34-
export const enum InvoiceType {
35-
Bolt11 = 'Bolt11',
36-
Bolt12 = 'Bolt12'
37-
}
38-
export interface TlvRecord {
39-
type: number
40-
value: string
41-
}
42-
export interface NodeInfo {
43-
alias: string
44-
color: string
45-
pubkey: string
46-
network: string
47-
blockHeight: number
48-
blockHash: string
49-
}
50-
export interface Transaction {
51-
type: string
52-
invoice: string
53-
description: string
54-
descriptionHash: string
55-
preimage: string
56-
paymentHash: string
57-
amountMsats: number
58-
feesPaid: number
59-
createdAt: number
60-
expiresAt: number
61-
settledAt: number
62-
payerNote?: string
63-
externalId?: string
64-
}
65-
export interface NodeConnectionInfo {
66-
pubkey: string
67-
address: string
68-
port: number
69-
}
70-
export interface Channel {
71-
localBalance: number
72-
localSpendableBalance: number
73-
remoteBalance: number
74-
id: string
75-
remotePubkey: string
76-
fundingTxId: string
77-
fundingTxVout: number
78-
active: boolean
79-
public: boolean
80-
internalChannel: string
81-
confirmations: number
82-
confirmationsRequired: number
83-
forwardingFeeBaseMsat: number
84-
unspendablePunishmentReserve: number
85-
counterpartyUnspendablePunishmentReserve: number
86-
error: string
87-
isOutbound: boolean
88-
}
89-
export interface NodeStatus {
90-
isReady: boolean
91-
internalNodeStatus: string
92-
}
93-
export interface ConnectPeerRequest {
94-
pubkey: string
95-
address: string
96-
port: number
97-
}
98-
export interface OpenChannelRequest {
99-
pubkey: string
100-
amountMsats: number
101-
public: boolean
102-
}
103-
export interface OpenChannelResponse {
104-
fundingTxId: string
105-
}
106-
export interface CloseChannelRequest {
107-
channelId: string
108-
nodeId: string
109-
force: boolean
110-
}
111-
export interface UpdateChannelRequest {
112-
channelId: string
113-
nodeId: string
114-
forwardingFeeBaseMsat: number
115-
maxDustHtlcExposureFromFeeRateMultiplier: number
116-
}
117-
export interface CloseChannelResponse {
118-
119-
}
120-
export interface PendingBalanceDetails {
121-
channelId: string
122-
nodeId: string
123-
amountMsats: number
124-
fundingTxId: string
125-
fundingTxVout: number
126-
}
127-
export interface OnchainBalanceResponse {
128-
spendable: number
129-
total: number
130-
reserved: number
131-
pendingBalancesFromChannelClosures: number
132-
pendingBalancesDetails: Array<PendingBalanceDetails>
133-
internalBalances: string
134-
}
135-
export interface PeerDetails {
136-
nodeId: string
137-
address: string
138-
isPersisted: boolean
139-
isConnected: boolean
140-
}
141-
export interface LightningBalanceResponse {
142-
totalSpendable: number
143-
totalReceivable: number
144-
nextMaxSpendable: number
145-
nextMaxReceivable: number
146-
nextMaxSpendableMpp: number
147-
nextMaxReceivableMpp: number
148-
}
149-
export interface PayInvoiceResponse {
150-
paymentHash: string
151-
preimage: string
152-
fee: number
153-
}
154-
export interface PayKeysendResponse {
155-
fee: number
156-
}
157-
export interface BalancesResponse {
158-
onchain: OnchainBalanceResponse
159-
lightning: LightningBalanceResponse
160-
}
161-
export interface PaymentFailedEventProperties {
162-
transaction: Transaction
163-
reason: string
164-
}
165-
export interface Payment {
166-
paymentId: string
167-
circId: string
168-
round: number
169-
relayFingerprint: string
170-
updatedAt: number
171-
amountMsats: number
172-
}
1736
export declare class PhoenixdNode {
1747
constructor(config: PhoenixdConfig)
1758
getUrl(): string
@@ -181,9 +14,11 @@ export declare class PhoenixdNode {
18114
payOffer(offer: string, amountMsats: number, payerNote?: string | undefined | null): Promise<PayInvoiceResponse>
18215
listTransactions(params: ListTransactionsParams): Promise<Array<Transaction>>
18316
}
184-
export declare class Db {
185-
constructor(path: string)
186-
save(): void
187-
writePayment(payment: Payment): void
188-
lookupPayment(paymentId: string): Payment | null
17+
export declare class ClnNode {
18+
constructor(config: ClnConfig)
19+
getUrl(): string
20+
getRune(): string
21+
getConfig(): ClnConfig
22+
getInfo(): Promise<NodeInfo>
23+
payOffer(offer: string, amountMsats: number, payerNote?: string | undefined | null): Promise<PayInvoiceResponse>
18924
}

bindings/lni_nodejs/index.js

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

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

315-
module.exports.InvoiceType = InvoiceType
316315
module.exports.PhoenixdNode = PhoenixdNode
317-
module.exports.Db = Db
316+
module.exports.ClnNode = ClnNode

bindings/lni_nodejs/main.mjs

Lines changed: 92 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,95 @@
1-
import { PhoenixdNode, InvoiceType, Db } from "./index.js";
1+
import { PhoenixdNode, ClnNode } from "./index.js";
22
import dotenv from "dotenv";
33
dotenv.config();
44

5-
const config = {
6-
url: process.env.PHOENIXD_URL,
7-
password: process.env.PHOENIXD_PASSWORD,
8-
test_hash: process.env.PHOENIXD_TEST_PAYMENT_HASH,
9-
};
10-
const node = new PhoenixdNode(config);
11-
const info = await node.getInfo();
12-
console.log("Node info:", info);
13-
14-
const configRes = await node.getConfig();
15-
console.log("Config:", configRes.url);
16-
17-
const invoice = await node.makeInvoice({
18-
amountMsats: 1000,
19-
description: "test invoice",
20-
invoiceType: InvoiceType.Bolt11,
21-
});
22-
console.log("Invoice:", invoice);
23-
24-
const lookupInvoice = await node.lookupInvoice(process.env.PHOENIXD_TEST_PAYMENT_HASH);
25-
console.log("lookupInvoice:", lookupInvoice);
26-
27-
const payOffer = await node.payOffer(process.env.TEST_OFFER, 3000, 'payment from lni nodejs');
28-
console.log("payOffer:", payOffer);
29-
30-
const txns = await node.listTransactions({
31-
from: 0,
32-
until: 0,
33-
limit: 10,
34-
offset: 0,
35-
unpaid: false,
36-
invoiceType: "all",
37-
});
38-
console.log("Transactions:", txns);
39-
40-
// const db = new Db("test.json");
41-
// db.writePayment({
42-
// paymentId: "1",
43-
// circId: "1",
44-
// round: 1,
45-
// relayFingerprint: "1",
46-
// updatedAt: 1,
47-
// amountMsats: 1,
48-
// amount_msats: 1000,
49-
// });
5+
async function phoenixd() {
6+
const config = {
7+
url: process.env.PHOENIXD_URL,
8+
password: process.env.PHOENIXD_PASSWORD,
9+
test_hash: process.env.PHOENIXD_TEST_PAYMENT_HASH,
10+
};
11+
const node = new PhoenixdNode(config);
12+
const info = await node.getInfo();
13+
console.log("Node info:", info);
14+
15+
const configRes = await node.getConfig();
16+
console.log("Config:", configRes.url);
17+
18+
const invoice = await node.makeInvoice({
19+
amountMsats: 1000,
20+
description: "test invoice",
21+
invoiceType: "Bolt11",
22+
});
23+
console.log("Invoice:", invoice);
24+
25+
const lookupInvoice = await node.lookupInvoice(
26+
process.env.PHOENIXD_TEST_PAYMENT_HASH
27+
);
28+
console.log("lookupInvoice:", lookupInvoice);
29+
30+
const payOffer = await node.payOffer(
31+
process.env.TEST_RECEIVER_OFFER,
32+
3000,
33+
"payment from lni nodejs"
34+
);
35+
console.log("payOffer:", payOffer);
36+
37+
const txns = await node.listTransactions({
38+
from: 0,
39+
until: 0,
40+
limit: 10,
41+
offset: 0,
42+
unpaid: false,
43+
invoiceType: "all",
44+
});
45+
console.log("Transactions:", txns);
46+
}
47+
48+
async function cln() {
49+
const config = {
50+
url: process.env.CLN_URL,
51+
rune: process.env.CLN_RUNE,
52+
};
53+
const node = new ClnNode(config);
54+
const info = await node.getInfo();
55+
console.log("Node info:", info);
56+
57+
// const configRes = await node.getConfig();
58+
// console.log("Config:", configRes.url);
59+
60+
// const invoice = await node.makeInvoice({
61+
// amountMsats: 1000,
62+
// description: "test invoice",
63+
// invoiceType: InvoiceType.Bolt11,
64+
// });
65+
// console.log("Invoice:", invoice);
66+
67+
// const lookupInvoice = await node.lookupInvoice(
68+
// process.env.PHOENIXD_TEST_PAYMENT_HASH
69+
// );
70+
// console.log("lookupInvoice:", lookupInvoice);
71+
72+
const payOffer = await node.payOffer(
73+
process.env.TEST_RECEIVER_OFFER,
74+
3000,
75+
"payment from lni nodejs"
76+
);
77+
console.log("payOffer:", payOffer);
78+
79+
// const txns = await node.listTransactions({
80+
// from: 0,
81+
// until: 0,
82+
// limit: 10,
83+
// offset: 0,
84+
// unpaid: false,
85+
// invoiceType: "all",
86+
// });
87+
// console.log("Transactions:", txns);
88+
}
89+
90+
async function main() {
91+
// phoenixd();
92+
cln();
93+
}
94+
95+
main();

0 commit comments

Comments
 (0)