Skip to content

core lightning #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 9 additions & 169 deletions bindings/lni_nodejs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,170 +3,6 @@

/* auto-generated by NAPI-RS */

export interface PhoenixdConfig {
url: string
password: string
}
export interface PhoenixdNode {
url: string
password: string
}
export interface Bolt11Resp {
amountSat: number
paymentHash: string
serialized: string
}
export interface PhoenixdMakeInvoiceParams {
invoiceType: InvoiceType
amountMsats: number
description?: string
descriptionHash?: string
expiry?: number
}
export interface ListTransactionsParams {
from: number
until: number
limit: number
offset: number
unpaid: boolean
invoiceType: string
}
export const enum InvoiceType {
Bolt11 = 'Bolt11',
Bolt12 = 'Bolt12'
}
export interface TlvRecord {
type: number
value: string
}
export interface NodeInfo {
alias: string
color: string
pubkey: string
network: string
blockHeight: number
blockHash: string
}
export interface Transaction {
type: string
invoice: string
description: string
descriptionHash: string
preimage: string
paymentHash: string
amountMsats: number
feesPaid: number
createdAt: number
expiresAt: number
settledAt: number
}
export interface NodeConnectionInfo {
pubkey: string
address: string
port: number
}
export interface Channel {
localBalance: number
localSpendableBalance: number
remoteBalance: number
id: string
remotePubkey: string
fundingTxId: string
fundingTxVout: number
active: boolean
public: boolean
internalChannel: string
confirmations: number
confirmationsRequired: number
forwardingFeeBaseMsat: number
unspendablePunishmentReserve: number
counterpartyUnspendablePunishmentReserve: number
error: string
isOutbound: boolean
}
export interface NodeStatus {
isReady: boolean
internalNodeStatus: string
}
export interface ConnectPeerRequest {
pubkey: string
address: string
port: number
}
export interface OpenChannelRequest {
pubkey: string
amountMsats: number
public: boolean
}
export interface OpenChannelResponse {
fundingTxId: string
}
export interface CloseChannelRequest {
channelId: string
nodeId: string
force: boolean
}
export interface UpdateChannelRequest {
channelId: string
nodeId: string
forwardingFeeBaseMsat: number
maxDustHtlcExposureFromFeeRateMultiplier: number
}
export interface CloseChannelResponse {

}
export interface PendingBalanceDetails {
channelId: string
nodeId: string
amountMsats: number
fundingTxId: string
fundingTxVout: number
}
export interface OnchainBalanceResponse {
spendable: number
total: number
reserved: number
pendingBalancesFromChannelClosures: number
pendingBalancesDetails: Array<PendingBalanceDetails>
internalBalances: string
}
export interface PeerDetails {
nodeId: string
address: string
isPersisted: boolean
isConnected: boolean
}
export interface LightningBalanceResponse {
totalSpendable: number
totalReceivable: number
nextMaxSpendable: number
nextMaxReceivable: number
nextMaxSpendableMpp: number
nextMaxReceivableMpp: number
}
export interface PayInvoiceResponse {
preimage: string
fee: number
}
export interface PayKeysendResponse {
fee: number
}
export interface BalancesResponse {
onchain: OnchainBalanceResponse
lightning: LightningBalanceResponse
}
export interface PaymentFailedEventProperties {
transaction: Transaction
reason: string
}
export interface Payment {
paymentId: string
circId: string
round: number
relayFingerprint: string
updatedAt: number
amountMsats: number
}
export declare class PhoenixdNode {
constructor(config: PhoenixdConfig)
getUrl(): string
Expand All @@ -178,9 +14,13 @@ export declare class PhoenixdNode {
payOffer(offer: string, amountMsats: number, payerNote?: string | undefined | null): Promise<PayInvoiceResponse>
listTransactions(params: ListTransactionsParams): Promise<Array<Transaction>>
}
export declare class Db {
constructor(path: string)
save(): void
writePayment(payment: Payment): void
lookupPayment(paymentId: string): Payment | null
export declare class ClnNode {
constructor(config: ClnConfig)
getUrl(): string
getRune(): string
getConfig(): ClnConfig
getInfo(): Promise<NodeInfo>
lookupInvoice(paymentHash: string): Promise<Transaction>
payOffer(offer: string, amountMsats: number, payerNote?: string | undefined | null): Promise<PayInvoiceResponse>
listTransactions(params: ListTransactionsParams): Promise<Array<Transaction>>
}
5 changes: 2 additions & 3 deletions bindings/lni_nodejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`)
}

const { InvoiceType, PhoenixdNode, Db } = nativeBinding
const { PhoenixdNode, ClnNode } = nativeBinding

module.exports.InvoiceType = InvoiceType
module.exports.PhoenixdNode = PhoenixdNode
module.exports.Db = Db
module.exports.ClnNode = ClnNode
130 changes: 84 additions & 46 deletions bindings/lni_nodejs/main.mjs
Original file line number Diff line number Diff line change
@@ -1,49 +1,87 @@
import { PhoenixdNode, InvoiceType, Db } from "./index.js";
import { PhoenixdNode, ClnNode } from "./index.js";
import dotenv from "dotenv";
dotenv.config();

const config = {
url: process.env.PHOENIXD_URL,
password: process.env.PHOENIXD_PASSWORD,
test_hash: process.env.PHOENIXD_TEST_PAYMENT_HASH,
};
const node = new PhoenixdNode(config);
const info = await node.getInfo();
console.log("Node info:", info);

const configRes = await node.getConfig();
console.log("Config:", configRes.url);

const invoice = await node.makeInvoice({
amountMsats: 1000,
description: "test invoice",
invoiceType: InvoiceType.Bolt11,
});
console.log("Invoice:", invoice);

const lookupInvoice = await node.lookupInvoice(process.env.PHOENIXD_TEST_PAYMENT_HASH);
console.log("lookupInvoice:", lookupInvoice);

const payOffer = await node.payOffer(process.env.TEST_OFFER, 3000, 'payment from lni nodejs');
console.log("payOffer:", payOffer);

const txns = await node.listTransactions({
from: 0,
until: 0,
limit: 10,
offset: 0,
unpaid: false,
invoiceType: "all",
});
console.log("Transactions:", txns);

// const db = new Db("test.json");
// db.writePayment({
// paymentId: "1",
// circId: "1",
// round: 1,
// relayFingerprint: "1",
// updatedAt: 1,
// amountMsats: 1,
// amount_msats: 1000,
// });
async function phoenixd() {
const config = {
url: process.env.PHOENIXD_URL,
password: process.env.PHOENIXD_PASSWORD,
test_hash: process.env.PHOENIXD_TEST_PAYMENT_HASH,
};
const node = new PhoenixdNode(config);
const info = await node.getInfo();
console.log("Node info:", info);

const configRes = await node.getConfig();
console.log("Config:", configRes.url);

const invoice = await node.makeInvoice({
amountMsats: 1000,
description: "test invoice",
invoiceType: "Bolt11",
});
console.log("Invoice:", invoice);

const lookupInvoice = await node.lookupInvoice(
process.env.PHOENIXD_TEST_PAYMENT_HASH
);
console.log("lookupInvoice:", lookupInvoice);

const payOffer = await node.payOffer(
process.env.TEST_RECEIVER_OFFER,
3000,
"payment from lni nodejs"
);
console.log("payOffer:", payOffer);

const txns = await node.listTransactions({
from: 0,
until: 0,
});
console.log("Transactions:", txns);
}

async function cln() {
const config = {
url: process.env.CLN_URL,
rune: process.env.CLN_RUNE,
};
const node = new ClnNode(config);
const info = await node.getInfo();
console.log("Node info:", info);

const configRes = await node.getConfig();
console.log("Config:", configRes.url);

const invoice = await node.makeInvoice({
amountMsats: 1000,
description: "test invoice",
invoiceType: InvoiceType.Bolt11,
});
console.log("Invoice:", invoice);

const lookupInvoice = await node.lookupInvoice(
process.env.CLN_TEST_PAYMENT_HASH
);
console.log("lookupInvoice:", lookupInvoice);

const payOffer = await node.payOffer(
process.env.TEST_RECEIVER_OFFER,
3000,
"payment from lni nodejs"
);
console.log("payOffer:", payOffer);

const txns = await node.listTransactions({
from: 0,
limit: 10,
});
console.log("Transactions:", txns);
}

async function main() {
phoenixd();
cln();
}

main();
Loading