From f74085d89bcfb44deb77763dbf25b2b677deac16 Mon Sep 17 00:00:00 2001 From: BitcoinZavior Date: Mon, 5 Aug 2024 11:07:00 -0400 Subject: [PATCH 1/9] Naming conventions Android --- CHANGELOG.md | 4 -- ios/LdkNodeRnModule.m | 24 ----------- ios/LdkNodeRnModule.swift | 78 +++++++++-------------------------- lib/classes/Bindings.d.ts | 6 --- lib/classes/Builder.d.ts | 3 -- lib/classes/NativeLoader.d.ts | 5 --- lib/classes/Node.d.ts | 17 +------- src/classes/Builder.ts | 37 +---------------- src/classes/NativeLoader.ts | 6 +-- src/classes/Node.ts | 8 ---- 10 files changed, 22 insertions(+), 166 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c86e93..55288e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,3 @@ -## [0.3.0] - -This is the new release of `ldk-node-rn` v0.3.0 . - ## [0.2.2] This is a bugfix release that reestablishes compatibility of Swift packages with Xcode 15.3 and later. diff --git a/ios/LdkNodeRnModule.m b/ios/LdkNodeRnModule.m index f9f9f7d..e396aa5 100644 --- a/ios/LdkNodeRnModule.m +++ b/ios/LdkNodeRnModule.m @@ -71,15 +71,6 @@ + (BOOL)requiresMainQueueSetup { return NO; } reject:(RCTPromiseRejectBlock)reject ) -RCT_EXTERN_METHOD( - setLiquiditySourceLsps2: (nonnull NSString*)address - nodeId: (nonnull NSString*)publicKey - token: (nonnull NSString*)token - buildId: (nonnull NSString*)buildId - resolve: (RCTPromiseResolveBlock)resolve - reject:(RCTPromiseRejectBlock)reject -) - RCT_EXTERN_METHOD( setStorageDirPath: (nonnull NSString*)buildId storageDirPath: (nonnull NSString*)storageDirPath @@ -115,21 +106,6 @@ + (BOOL)requiresMainQueueSetup { return NO; } reject:(RCTPromiseRejectBlock)reject ) -RCT_EXTERN_METHOD( - bolt11Payment: (nonnull NSString*)nodeId - resolve: (RCTPromiseResolveBlock)resolve - reject:(RCTPromiseRejectBlock)reject -) - -RCT_EXTERN_METHOD( - receiveViaJitChannel: (nonnull NSString*)nodeId - amountMsat: (nonnull NSNumber*)amountMsat - description: (nonnull NSString*)description - expirySecs: (nonnull NSNumber*)expirySecs - resolve: (RCTPromiseResolveBlock)resolve - reject:(RCTPromiseRejectBlock)reject -) - RCT_EXTERN_METHOD( listeningAddresses: (nonnull NSString*)nodeId resolve: (RCTPromiseResolveBlock)resolve diff --git a/ios/LdkNodeRnModule.swift b/ios/LdkNodeRnModule.swift index e225ea9..411d560 100644 --- a/ios/LdkNodeRnModule.swift +++ b/ios/LdkNodeRnModule.swift @@ -180,21 +180,6 @@ class LdkNodeRnModule: NSObject { resolve(true) } } - - @objc - func setLiquiditySourceLsps2(_ - address: String, - nodeId: String, - token: String, - buildId: String, - resolve: @escaping RCTPromiseResolveBlock, - reject: @escaping RCTPromiseRejectBlock - ) { - DispatchQueue.main.async { [self] in - _builders[buildId]!.setLiquiditySourceLsps2(address: address, nodeId: nodeId, token: token) - resolve(true) - } - } @objc func build(_ @@ -286,24 +271,6 @@ class LdkNodeRnModule: NSObject { resolve(_nodes[nodeId]!.listeningAddresses()) } } - - - @objc - func bolt11Payment( - _ nodeId: String, - resolve: @escaping RCTPromiseResolveBlock, - reject: @escaping RCTPromiseRejectBlock - ) { - DispatchQueue.main.async { [self] in - if let node = _nodes[nodeId] { - resolve(node.bolt11Payment()) - } else { - let error = NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Node not found"]) - reject("Bolt11 Payment error", "Node not found", error) - } - } - } - @objc func newOnchainAddress(_ @@ -330,6 +297,7 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { +// resolve(try _nodes[nodeId]!.sendToOnchainAddress(address: address, amountMsat: UInt64(truncating: amountMsat))) resolve(try _nodes[nodeId]!.onchainPayment().sendToAddress(address: address, amountMsat: UInt64(truncating: amountMsat))) } catch let error { reject("Node sendToOnchainAddress error", "\(error)", error) @@ -346,6 +314,7 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { +// resolve(try _nodes[nodeId]!.sendAllToOnchainAddress(address: address)) resolve(try _nodes[nodeId]!.onchainPayment().sendAllToAddress(address: address)) } catch let error { reject("Node sendAllToOnchainAddress error", "\(error)", error) @@ -362,6 +331,7 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { +// resolve(try _nodes[nodeId]!.spendableOnchainBalanceSats()) resolve(try _nodes[nodeId]!.listBalances().spendableOnchainBalanceSats) } catch let error { reject("Node spendableOnchainBalanceSats error", "\(error)", error) @@ -482,6 +452,7 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { +// let invoice = try _nodes[nodeId]!.sendPayment(invoice: invoice) let invoice = try _nodes[nodeId]!.bolt11Payment().send(invoice: invoice) resolve(invoice) } catch let error { @@ -500,6 +471,7 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { +// let invoice = try _nodes[nodeId]!.sendPaymentUsingAmount(invoice: invoice, amountMsat: UInt64(truncating: amountMsat)) let invoice = try _nodes[nodeId]!.bolt11Payment().sendUsingAmount(invoice: invoice, amountMsat: UInt64(truncating: amountMsat)) resolve(invoice) } catch let error { @@ -518,6 +490,7 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { +// let invoice = try _nodes[nodeId]!.sendSpontaneousPayment(amountMsat: UInt64(truncating: amountMsat), nodeId: pubKey) let invoice = try _nodes[nodeId]!.spontaneousPayment().send(amountMsat: UInt64(truncating: amountMsat), nodeId: pubKey) resolve(invoice) } catch let error { @@ -525,32 +498,6 @@ class LdkNodeRnModule: NSObject { } } } - - @objc - func receiveViaJitChannel(_ - nodeId: String, - amountMsat: NSNumber, - description: String, - expirySecs: NSNumber, - resolve: @escaping RCTPromiseResolveBlock, - reject: @escaping RCTPromiseRejectBlock - ) { - DispatchQueue.main.async { [self] in - do { - let maxFeeLimitMsat: UInt64 = 20002000 - let invoice = try _nodes[nodeId]!.bolt11Payment().receiveViaJitChannel( - amountMsat: UInt64(truncating: amountMsat), - description: description, - expirySecs: UInt32(truncating: expirySecs), - maxLspFeeLimitMsat: maxFeeLimitMsat - ) - resolve(invoice) - } catch let error { - reject("Receive payment invoice error", "\(error)", error) - } - } - } - @objc @@ -564,6 +511,11 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { +// let invoice = try _nodes[nodeId]!.receivePayment( +// amountMsat: UInt64(truncating: amountMsat), +// description: description, +// expirySecs: UInt32(truncating: expirySecs) +// ) let invoice = try _nodes[nodeId]!.bolt11Payment().receive( amountMsat: UInt64(truncating: amountMsat), description: description, @@ -586,6 +538,10 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { +// let invoice = try _nodes[nodeId]!.receiveVariableAmountPayment( +// description: description, +// expirySecs: UInt32(truncating: expirySecs) +// ) let invoice = try _nodes[nodeId]!.bolt11Payment().receiveVariableAmount( description: description, expirySecs: UInt32(truncating: expirySecs) @@ -743,6 +699,7 @@ class LdkNodeRnModule: NSObject { reject: @escaping RCTPromiseRejectBlock ) { DispatchQueue.main.async { [self] in +// resolve(_nodes[nodeId]!.isRunning()) resolve(_nodes[nodeId]!.status().isRunning) } } @@ -758,6 +715,7 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { +// try _nodes[nodeId]!.sendPaymentProbes(invoice: invoice) try _nodes[nodeId]!.bolt11Payment().sendProbes(invoice: invoice) resolve(true) } catch let error { @@ -776,6 +734,7 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { +// try _nodes[nodeId]!.sendPaymentProbesUsingAmount(invoice: invoice, amountMsat: UInt64(truncating: amountMsat)) try _nodes[nodeId]!.bolt11Payment().sendProbesUsingAmount(invoice: invoice, amountMsat: UInt64(truncating: amountMsat)) resolve(true) } catch let error { @@ -794,6 +753,7 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { +// try _nodes[nodeId]!.sendSpontaneousPaymentProbes(amountMsat: UInt64(truncating: amountMsat), nodeId: pubKey) try _nodes[nodeId]!.spontaneousPayment().sendProbes(amountMsat: UInt64(truncating: amountMsat), nodeId: pubKey) resolve(true) } catch let error { diff --git a/lib/classes/Bindings.d.ts b/lib/classes/Bindings.d.ts index 1adaac9..8f1a5a0 100644 --- a/lib/classes/Bindings.d.ts +++ b/lib/classes/Bindings.d.ts @@ -20,12 +20,6 @@ export declare class NetAddress { port: number; constructor(ip: string, port: number); } - -export declare class Bolt11Payment { - nodeId: PublicKey; - constructor(nodeId: PublicKey); -} - export declare class PeerDetails { nodeId: PublicKey; address: NetAddress; diff --git a/lib/classes/Builder.d.ts b/lib/classes/Builder.d.ts index aab2afc..0bbb006 100644 --- a/lib/classes/Builder.d.ts +++ b/lib/classes/Builder.d.ts @@ -44,9 +44,6 @@ export declare class Builder extends NativeLoader { * Configures the [Node] instance to source its gossip data from the Lightning peer-to-peer network. * @returns {Promise} */ - - setLiquiditySourceLsps2(address: string, publicKey:string, token:String): Promise; - setGossipSourceP2p(): Promise; /** * Configures the [Node] instance to source its gossip data from the given RapidGossipSync server. diff --git a/lib/classes/NativeLoader.d.ts b/lib/classes/NativeLoader.d.ts index c274ec2..31878cb 100644 --- a/lib/classes/NativeLoader.d.ts +++ b/lib/classes/NativeLoader.d.ts @@ -24,11 +24,6 @@ export interface NativeLdkNodeRn { setNetwork(buildId: string, network: string): boolean; setListeningAddresses(buildId: string, listeningAddresses: Array): boolean; build(buildId: string): string; - - setLiquiditySourceLsps2(address: string, publicKey: string, token: String, buildId: string): any; - bolt11Payment(nodeId: string): any; - receiveViaJitChannel(nodeId: string, amountMsat: number, description: string, expirySecs: number): any; - start(nodeId: string): boolean; stop(nodeId: string): boolean; syncWallets(nodeId: string): boolean; diff --git a/lib/classes/Node.d.ts b/lib/classes/Node.d.ts index 5705a81..d25201a 100644 --- a/lib/classes/Node.d.ts +++ b/lib/classes/Node.d.ts @@ -1,4 +1,4 @@ -import { Address, ChannelDetails, ChannelId, NetAddress, PaymentDetails, PaymentHash, PeerDetails, PublicKey, Txid, Bolt11Payment } from './Bindings'; +import { Address, ChannelDetails, ChannelId, NetAddress, PaymentDetails, PaymentHash, PeerDetails, PublicKey, Txid } from './Bindings'; import { NativeLoader } from './NativeLoader'; import { ChannelConfig } from './ChannelConfig'; export declare class Node extends NativeLoader { @@ -36,11 +36,6 @@ export declare class Node extends NativeLoader { * Returns listening Addresses * @returns {Promise>} */ - bolt11Payment(): Promise; - /** - * Returns bolt11 Payment - * @returns {Promise} - */ listeningAddresses(): Promise | null>; /** * Retrieve a new on-chain/funding address. @@ -113,8 +108,6 @@ export declare class Node extends NativeLoader { * @returns {Promise} */ sendPayment(invoice: string): Promise; - - bolt11Payment(): Promise; /** * Send a payment given an invoice and an amount in millisatoshi. * This will fail if the amount given is less than the value required by the given invoice. @@ -141,14 +134,6 @@ export declare class Node extends NativeLoader { * @requires [expirySecs] number * @returns {Promise} */ - receiveViaJitChannel(amountMsat: number, description: string, expirySecs: number): Promise; - /** - * Returns a payable invoice that can be used to request and receive a payment for which the amount is to be determined by the user, also known as a "zero-amount" invoice. - * @requires [amountMsat] amount in sats - * @requires [description] - * @requires [expirySecs] number - * @returns {Promise} - */ receivePayment(amountMsat: number, description: string, expirySecs: number): Promise; /** * Returns a payable invoice that can be used to request and receive a payment for which the amount is to be determined by the user, also known as a "zero-amount" invoice. diff --git a/src/classes/Builder.ts b/src/classes/Builder.ts index dd8ab77..102c78b 100644 --- a/src/classes/Builder.ts +++ b/src/classes/Builder.ts @@ -1,19 +1,10 @@ import { Config } from './Config'; import { NativeLoader } from './NativeLoader'; -import { NetAddress, PublicKey } from './Bindings'; +import { NetAddress } from './Bindings'; import { Node } from './Node'; import { addressToString } from '../utils'; -const DefaultServicesMutinynet = { -esploraServerUrl : 'https://mutinynet.ltbl.io/api', -rgsServerUrl : 'https://mutinynet.ltbl.io/snapshot', -lsps2SourceAddress : '44.219.111.31', -lsps2SourcePort : '39735', -lsps2SourcePublicKey :'0371d6fd7d75de2d0372d03ea00e8bacdacb50c27d0eaea0a76a0622eff1f5ef2b', -lsps2SourceToken : 'JZWN9YLW' -}; export class Builder extends NativeLoader { - id: string = ''; /** @@ -26,12 +17,6 @@ export class Builder extends NativeLoader { return this; } - // async fromConfig(config: Config): Promise { - // const builder = new Builder(); - // builder.id = await builder._ldk.fromConfig(config.id); - // return builder; - // } - /** * Configures the [Node] instance to source its wallet entropy from a seed file on disk. * @@ -121,26 +106,6 @@ export class Builder extends NativeLoader { ); } - async setLiquiditySourceLsps2(address: string, publicKey:string, token:String): Promise { - return await this._ldk.setLiquiditySourceLsps2(address, publicKey, token, this.id); - } - -// async createMutinynetBuilder(config?: Config): Promise { -// const builder = config ? await Builder.fromConfig(config) : new Builder(); - -// await builder.setNetwork('signet'); -// await builder.setEsploraServer(DefaultServicesMutinynet.esploraServerUrl); -// await builder.setGossipSourceRgs(DefaultServicesMutinynet.rgsServerUrl); -// await builder.setMutinityNetwork({ -// address: DefaultServicesMutinynet.lsps2SourceAddress, -// port: DefaultServicesMutinynet.lsps2SourcePort, -// publicKey: DefaultServicesMutinynet.lsps2SourcePublicKey, -// token: DefaultServicesMutinynet.lsps2SourceToken, -// }); - -// return builder; -// } - /** * Create node * @returns {Promise} diff --git a/src/classes/NativeLoader.ts b/src/classes/NativeLoader.ts index 1017072..5d4a15f 100644 --- a/src/classes/NativeLoader.ts +++ b/src/classes/NativeLoader.ts @@ -1,5 +1,5 @@ import { ChannelConfig } from './ChannelConfig'; -import { ChannelDetails, NetAddress, PaymentDetails, PeerDetails, PublicKey } from './Bindings'; +import { ChannelDetails, PaymentDetails, PeerDetails } from './Bindings'; import { NativeModules } from 'react-native'; @@ -30,10 +30,6 @@ export interface NativeLdkNodeRn { setListeningAddresses(buildId: string, listeningAddresses: Array): boolean; build(buildId: string): string; - setLiquiditySourceLsps2(address: string, publicKey: string, token: String, buildId: string): any; - bolt11Payment(nodeId: string): any; - receiveViaJitChannel(nodeId: string, amountMsat: number, description: string, expirySecs: number): any; - start(nodeId: string): boolean; stop(nodeId: string): boolean; syncWallets(nodeId: string): boolean; diff --git a/src/classes/Node.ts b/src/classes/Node.ts index 1f9ff84..5c03072 100644 --- a/src/classes/Node.ts +++ b/src/classes/Node.ts @@ -246,10 +246,6 @@ export class Node extends NativeLoader { return await this._ldk.receiveVariableAmountPayment(this.id, description, expirySecs); } - async receiveViaJitChannel(amountMsat: number, description: string, expirySecs: number): Promise{ - return await this._ldk.receiveViaJitChannel(this.id, amountMsat, description, expirySecs); - } - /** * Get list of payments * @returns {Promise>} @@ -377,10 +373,6 @@ export class Node extends NativeLoader { return await this._ldk.sendPaymentProbes(this.id, invoice); } - async bolt11Payment(): Promise { - return await this._ldk.bolt11Payment(this.id); - } - /** * Sends payment probes over all paths of a route that would be used to pay the given * zero-value invoice using the given amount. From 57504c11cd171e21e84b0a34030708a237264b97 Mon Sep 17 00:00:00 2001 From: BitcoinZavior Date: Wed, 7 Aug 2024 11:02:00 -0400 Subject: [PATCH 2/9] ChangeLog Updated --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55288e5..4c86e93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [0.3.0] + +This is the new release of `ldk-node-rn` v0.3.0 . + ## [0.2.2] This is a bugfix release that reestablishes compatibility of Swift packages with Xcode 15.3 and later. From 57e9ee14e1a6bb97d5325cf56453baa050d7d4c8 Mon Sep 17 00:00:00 2001 From: BitcoinZavior Date: Fri, 9 Aug 2024 21:42:00 -0400 Subject: [PATCH 3/9] Unnecessary commented code removed. --- ios/LdkNodeRnModule.swift | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/ios/LdkNodeRnModule.swift b/ios/LdkNodeRnModule.swift index 411d560..d7136a6 100644 --- a/ios/LdkNodeRnModule.swift +++ b/ios/LdkNodeRnModule.swift @@ -297,7 +297,6 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { -// resolve(try _nodes[nodeId]!.sendToOnchainAddress(address: address, amountMsat: UInt64(truncating: amountMsat))) resolve(try _nodes[nodeId]!.onchainPayment().sendToAddress(address: address, amountMsat: UInt64(truncating: amountMsat))) } catch let error { reject("Node sendToOnchainAddress error", "\(error)", error) @@ -314,7 +313,6 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { -// resolve(try _nodes[nodeId]!.sendAllToOnchainAddress(address: address)) resolve(try _nodes[nodeId]!.onchainPayment().sendAllToAddress(address: address)) } catch let error { reject("Node sendAllToOnchainAddress error", "\(error)", error) @@ -331,7 +329,6 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { -// resolve(try _nodes[nodeId]!.spendableOnchainBalanceSats()) resolve(try _nodes[nodeId]!.listBalances().spendableOnchainBalanceSats) } catch let error { reject("Node spendableOnchainBalanceSats error", "\(error)", error) @@ -452,7 +449,6 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { -// let invoice = try _nodes[nodeId]!.sendPayment(invoice: invoice) let invoice = try _nodes[nodeId]!.bolt11Payment().send(invoice: invoice) resolve(invoice) } catch let error { @@ -471,7 +467,6 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { -// let invoice = try _nodes[nodeId]!.sendPaymentUsingAmount(invoice: invoice, amountMsat: UInt64(truncating: amountMsat)) let invoice = try _nodes[nodeId]!.bolt11Payment().sendUsingAmount(invoice: invoice, amountMsat: UInt64(truncating: amountMsat)) resolve(invoice) } catch let error { @@ -490,7 +485,6 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { -// let invoice = try _nodes[nodeId]!.sendSpontaneousPayment(amountMsat: UInt64(truncating: amountMsat), nodeId: pubKey) let invoice = try _nodes[nodeId]!.spontaneousPayment().send(amountMsat: UInt64(truncating: amountMsat), nodeId: pubKey) resolve(invoice) } catch let error { @@ -511,11 +505,6 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { -// let invoice = try _nodes[nodeId]!.receivePayment( -// amountMsat: UInt64(truncating: amountMsat), -// description: description, -// expirySecs: UInt32(truncating: expirySecs) -// ) let invoice = try _nodes[nodeId]!.bolt11Payment().receive( amountMsat: UInt64(truncating: amountMsat), description: description, @@ -538,10 +527,6 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { -// let invoice = try _nodes[nodeId]!.receiveVariableAmountPayment( -// description: description, -// expirySecs: UInt32(truncating: expirySecs) -// ) let invoice = try _nodes[nodeId]!.bolt11Payment().receiveVariableAmount( description: description, expirySecs: UInt32(truncating: expirySecs) @@ -699,7 +684,6 @@ class LdkNodeRnModule: NSObject { reject: @escaping RCTPromiseRejectBlock ) { DispatchQueue.main.async { [self] in -// resolve(_nodes[nodeId]!.isRunning()) resolve(_nodes[nodeId]!.status().isRunning) } } @@ -715,7 +699,6 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { -// try _nodes[nodeId]!.sendPaymentProbes(invoice: invoice) try _nodes[nodeId]!.bolt11Payment().sendProbes(invoice: invoice) resolve(true) } catch let error { @@ -734,7 +717,6 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { -// try _nodes[nodeId]!.sendPaymentProbesUsingAmount(invoice: invoice, amountMsat: UInt64(truncating: amountMsat)) try _nodes[nodeId]!.bolt11Payment().sendProbesUsingAmount(invoice: invoice, amountMsat: UInt64(truncating: amountMsat)) resolve(true) } catch let error { @@ -753,7 +735,6 @@ class LdkNodeRnModule: NSObject { ) { DispatchQueue.main.async { [self] in do { -// try _nodes[nodeId]!.sendSpontaneousPaymentProbes(amountMsat: UInt64(truncating: amountMsat), nodeId: pubKey) try _nodes[nodeId]!.spontaneousPayment().sendProbes(amountMsat: UInt64(truncating: amountMsat), nodeId: pubKey) resolve(true) } catch let error { From dbf68ced43f59837eebcec509036dd883ed771f2 Mon Sep 17 00:00:00 2001 From: BitcoinZavior Date: Sat, 10 Aug 2024 12:47:00 -0400 Subject: [PATCH 4/9] Implemented JIT Payments --- ios/LdkNodeRnModule.m | 24 ++++++++++++++ ios/LdkNodeRnModule.swift | 59 +++++++++++++++++++++++++++++++++++ lib/classes/Bindings.d.ts | 6 ++++ lib/classes/Builder.d.ts | 3 ++ lib/classes/NativeLoader.d.ts | 5 +++ lib/classes/Node.d.ts | 17 +++++++++- src/classes/Builder.ts | 37 +++++++++++++++++++++- src/classes/NativeLoader.ts | 6 +++- src/classes/Node.ts | 8 +++++ 9 files changed, 162 insertions(+), 3 deletions(-) diff --git a/ios/LdkNodeRnModule.m b/ios/LdkNodeRnModule.m index e396aa5..f9f9f7d 100644 --- a/ios/LdkNodeRnModule.m +++ b/ios/LdkNodeRnModule.m @@ -71,6 +71,15 @@ + (BOOL)requiresMainQueueSetup { return NO; } reject:(RCTPromiseRejectBlock)reject ) +RCT_EXTERN_METHOD( + setLiquiditySourceLsps2: (nonnull NSString*)address + nodeId: (nonnull NSString*)publicKey + token: (nonnull NSString*)token + buildId: (nonnull NSString*)buildId + resolve: (RCTPromiseResolveBlock)resolve + reject:(RCTPromiseRejectBlock)reject +) + RCT_EXTERN_METHOD( setStorageDirPath: (nonnull NSString*)buildId storageDirPath: (nonnull NSString*)storageDirPath @@ -106,6 +115,21 @@ + (BOOL)requiresMainQueueSetup { return NO; } reject:(RCTPromiseRejectBlock)reject ) +RCT_EXTERN_METHOD( + bolt11Payment: (nonnull NSString*)nodeId + resolve: (RCTPromiseResolveBlock)resolve + reject:(RCTPromiseRejectBlock)reject +) + +RCT_EXTERN_METHOD( + receiveViaJitChannel: (nonnull NSString*)nodeId + amountMsat: (nonnull NSNumber*)amountMsat + description: (nonnull NSString*)description + expirySecs: (nonnull NSNumber*)expirySecs + resolve: (RCTPromiseResolveBlock)resolve + reject:(RCTPromiseRejectBlock)reject +) + RCT_EXTERN_METHOD( listeningAddresses: (nonnull NSString*)nodeId resolve: (RCTPromiseResolveBlock)resolve diff --git a/ios/LdkNodeRnModule.swift b/ios/LdkNodeRnModule.swift index d7136a6..e225ea9 100644 --- a/ios/LdkNodeRnModule.swift +++ b/ios/LdkNodeRnModule.swift @@ -180,6 +180,21 @@ class LdkNodeRnModule: NSObject { resolve(true) } } + + @objc + func setLiquiditySourceLsps2(_ + address: String, + nodeId: String, + token: String, + buildId: String, + resolve: @escaping RCTPromiseResolveBlock, + reject: @escaping RCTPromiseRejectBlock + ) { + DispatchQueue.main.async { [self] in + _builders[buildId]!.setLiquiditySourceLsps2(address: address, nodeId: nodeId, token: token) + resolve(true) + } + } @objc func build(_ @@ -271,6 +286,24 @@ class LdkNodeRnModule: NSObject { resolve(_nodes[nodeId]!.listeningAddresses()) } } + + + @objc + func bolt11Payment( + _ nodeId: String, + resolve: @escaping RCTPromiseResolveBlock, + reject: @escaping RCTPromiseRejectBlock + ) { + DispatchQueue.main.async { [self] in + if let node = _nodes[nodeId] { + resolve(node.bolt11Payment()) + } else { + let error = NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Node not found"]) + reject("Bolt11 Payment error", "Node not found", error) + } + } + } + @objc func newOnchainAddress(_ @@ -492,6 +525,32 @@ class LdkNodeRnModule: NSObject { } } } + + @objc + func receiveViaJitChannel(_ + nodeId: String, + amountMsat: NSNumber, + description: String, + expirySecs: NSNumber, + resolve: @escaping RCTPromiseResolveBlock, + reject: @escaping RCTPromiseRejectBlock + ) { + DispatchQueue.main.async { [self] in + do { + let maxFeeLimitMsat: UInt64 = 20002000 + let invoice = try _nodes[nodeId]!.bolt11Payment().receiveViaJitChannel( + amountMsat: UInt64(truncating: amountMsat), + description: description, + expirySecs: UInt32(truncating: expirySecs), + maxLspFeeLimitMsat: maxFeeLimitMsat + ) + resolve(invoice) + } catch let error { + reject("Receive payment invoice error", "\(error)", error) + } + } + } + @objc diff --git a/lib/classes/Bindings.d.ts b/lib/classes/Bindings.d.ts index 8f1a5a0..1adaac9 100644 --- a/lib/classes/Bindings.d.ts +++ b/lib/classes/Bindings.d.ts @@ -20,6 +20,12 @@ export declare class NetAddress { port: number; constructor(ip: string, port: number); } + +export declare class Bolt11Payment { + nodeId: PublicKey; + constructor(nodeId: PublicKey); +} + export declare class PeerDetails { nodeId: PublicKey; address: NetAddress; diff --git a/lib/classes/Builder.d.ts b/lib/classes/Builder.d.ts index 0bbb006..aab2afc 100644 --- a/lib/classes/Builder.d.ts +++ b/lib/classes/Builder.d.ts @@ -44,6 +44,9 @@ export declare class Builder extends NativeLoader { * Configures the [Node] instance to source its gossip data from the Lightning peer-to-peer network. * @returns {Promise} */ + + setLiquiditySourceLsps2(address: string, publicKey:string, token:String): Promise; + setGossipSourceP2p(): Promise; /** * Configures the [Node] instance to source its gossip data from the given RapidGossipSync server. diff --git a/lib/classes/NativeLoader.d.ts b/lib/classes/NativeLoader.d.ts index 31878cb..c274ec2 100644 --- a/lib/classes/NativeLoader.d.ts +++ b/lib/classes/NativeLoader.d.ts @@ -24,6 +24,11 @@ export interface NativeLdkNodeRn { setNetwork(buildId: string, network: string): boolean; setListeningAddresses(buildId: string, listeningAddresses: Array): boolean; build(buildId: string): string; + + setLiquiditySourceLsps2(address: string, publicKey: string, token: String, buildId: string): any; + bolt11Payment(nodeId: string): any; + receiveViaJitChannel(nodeId: string, amountMsat: number, description: string, expirySecs: number): any; + start(nodeId: string): boolean; stop(nodeId: string): boolean; syncWallets(nodeId: string): boolean; diff --git a/lib/classes/Node.d.ts b/lib/classes/Node.d.ts index d25201a..5705a81 100644 --- a/lib/classes/Node.d.ts +++ b/lib/classes/Node.d.ts @@ -1,4 +1,4 @@ -import { Address, ChannelDetails, ChannelId, NetAddress, PaymentDetails, PaymentHash, PeerDetails, PublicKey, Txid } from './Bindings'; +import { Address, ChannelDetails, ChannelId, NetAddress, PaymentDetails, PaymentHash, PeerDetails, PublicKey, Txid, Bolt11Payment } from './Bindings'; import { NativeLoader } from './NativeLoader'; import { ChannelConfig } from './ChannelConfig'; export declare class Node extends NativeLoader { @@ -36,6 +36,11 @@ export declare class Node extends NativeLoader { * Returns listening Addresses * @returns {Promise>} */ + bolt11Payment(): Promise; + /** + * Returns bolt11 Payment + * @returns {Promise} + */ listeningAddresses(): Promise | null>; /** * Retrieve a new on-chain/funding address. @@ -108,6 +113,8 @@ export declare class Node extends NativeLoader { * @returns {Promise} */ sendPayment(invoice: string): Promise; + + bolt11Payment(): Promise; /** * Send a payment given an invoice and an amount in millisatoshi. * This will fail if the amount given is less than the value required by the given invoice. @@ -134,6 +141,14 @@ export declare class Node extends NativeLoader { * @requires [expirySecs] number * @returns {Promise} */ + receiveViaJitChannel(amountMsat: number, description: string, expirySecs: number): Promise; + /** + * Returns a payable invoice that can be used to request and receive a payment for which the amount is to be determined by the user, also known as a "zero-amount" invoice. + * @requires [amountMsat] amount in sats + * @requires [description] + * @requires [expirySecs] number + * @returns {Promise} + */ receivePayment(amountMsat: number, description: string, expirySecs: number): Promise; /** * Returns a payable invoice that can be used to request and receive a payment for which the amount is to be determined by the user, also known as a "zero-amount" invoice. diff --git a/src/classes/Builder.ts b/src/classes/Builder.ts index 102c78b..dd8ab77 100644 --- a/src/classes/Builder.ts +++ b/src/classes/Builder.ts @@ -1,10 +1,19 @@ import { Config } from './Config'; import { NativeLoader } from './NativeLoader'; -import { NetAddress } from './Bindings'; +import { NetAddress, PublicKey } from './Bindings'; import { Node } from './Node'; import { addressToString } from '../utils'; +const DefaultServicesMutinynet = { +esploraServerUrl : 'https://mutinynet.ltbl.io/api', +rgsServerUrl : 'https://mutinynet.ltbl.io/snapshot', +lsps2SourceAddress : '44.219.111.31', +lsps2SourcePort : '39735', +lsps2SourcePublicKey :'0371d6fd7d75de2d0372d03ea00e8bacdacb50c27d0eaea0a76a0622eff1f5ef2b', +lsps2SourceToken : 'JZWN9YLW' +}; export class Builder extends NativeLoader { + id: string = ''; /** @@ -17,6 +26,12 @@ export class Builder extends NativeLoader { return this; } + // async fromConfig(config: Config): Promise { + // const builder = new Builder(); + // builder.id = await builder._ldk.fromConfig(config.id); + // return builder; + // } + /** * Configures the [Node] instance to source its wallet entropy from a seed file on disk. * @@ -106,6 +121,26 @@ export class Builder extends NativeLoader { ); } + async setLiquiditySourceLsps2(address: string, publicKey:string, token:String): Promise { + return await this._ldk.setLiquiditySourceLsps2(address, publicKey, token, this.id); + } + +// async createMutinynetBuilder(config?: Config): Promise { +// const builder = config ? await Builder.fromConfig(config) : new Builder(); + +// await builder.setNetwork('signet'); +// await builder.setEsploraServer(DefaultServicesMutinynet.esploraServerUrl); +// await builder.setGossipSourceRgs(DefaultServicesMutinynet.rgsServerUrl); +// await builder.setMutinityNetwork({ +// address: DefaultServicesMutinynet.lsps2SourceAddress, +// port: DefaultServicesMutinynet.lsps2SourcePort, +// publicKey: DefaultServicesMutinynet.lsps2SourcePublicKey, +// token: DefaultServicesMutinynet.lsps2SourceToken, +// }); + +// return builder; +// } + /** * Create node * @returns {Promise} diff --git a/src/classes/NativeLoader.ts b/src/classes/NativeLoader.ts index 5d4a15f..1017072 100644 --- a/src/classes/NativeLoader.ts +++ b/src/classes/NativeLoader.ts @@ -1,5 +1,5 @@ import { ChannelConfig } from './ChannelConfig'; -import { ChannelDetails, PaymentDetails, PeerDetails } from './Bindings'; +import { ChannelDetails, NetAddress, PaymentDetails, PeerDetails, PublicKey } from './Bindings'; import { NativeModules } from 'react-native'; @@ -30,6 +30,10 @@ export interface NativeLdkNodeRn { setListeningAddresses(buildId: string, listeningAddresses: Array): boolean; build(buildId: string): string; + setLiquiditySourceLsps2(address: string, publicKey: string, token: String, buildId: string): any; + bolt11Payment(nodeId: string): any; + receiveViaJitChannel(nodeId: string, amountMsat: number, description: string, expirySecs: number): any; + start(nodeId: string): boolean; stop(nodeId: string): boolean; syncWallets(nodeId: string): boolean; diff --git a/src/classes/Node.ts b/src/classes/Node.ts index 5c03072..1f9ff84 100644 --- a/src/classes/Node.ts +++ b/src/classes/Node.ts @@ -246,6 +246,10 @@ export class Node extends NativeLoader { return await this._ldk.receiveVariableAmountPayment(this.id, description, expirySecs); } + async receiveViaJitChannel(amountMsat: number, description: string, expirySecs: number): Promise{ + return await this._ldk.receiveViaJitChannel(this.id, amountMsat, description, expirySecs); + } + /** * Get list of payments * @returns {Promise>} @@ -373,6 +377,10 @@ export class Node extends NativeLoader { return await this._ldk.sendPaymentProbes(this.id, invoice); } + async bolt11Payment(): Promise { + return await this._ldk.bolt11Payment(this.id); + } + /** * Sends payment probes over all paths of a route that would be used to pay the given * zero-value invoice using the given amount. From 22ee3da726749d90bdd9a3ce6c3f2f3a5fd8f98b Mon Sep 17 00:00:00 2001 From: BitcoinZavior Date: Wed, 14 Aug 2024 13:11:00 -0400 Subject: [PATCH 5/9] Merge pull request for v0.3.0 --- ios/LdkNodeRnModule.m | 24 -------------- ios/LdkNodeRnModule.swift | 59 ----------------------------------- lib/classes/Bindings.d.ts | 6 ---- lib/classes/Builder.d.ts | 3 -- lib/classes/NativeLoader.d.ts | 5 --- lib/classes/Node.d.ts | 17 +--------- src/classes/Builder.ts | 37 +--------------------- src/classes/NativeLoader.ts | 6 +--- src/classes/Node.ts | 8 ----- 9 files changed, 3 insertions(+), 162 deletions(-) diff --git a/ios/LdkNodeRnModule.m b/ios/LdkNodeRnModule.m index f9f9f7d..e396aa5 100644 --- a/ios/LdkNodeRnModule.m +++ b/ios/LdkNodeRnModule.m @@ -71,15 +71,6 @@ + (BOOL)requiresMainQueueSetup { return NO; } reject:(RCTPromiseRejectBlock)reject ) -RCT_EXTERN_METHOD( - setLiquiditySourceLsps2: (nonnull NSString*)address - nodeId: (nonnull NSString*)publicKey - token: (nonnull NSString*)token - buildId: (nonnull NSString*)buildId - resolve: (RCTPromiseResolveBlock)resolve - reject:(RCTPromiseRejectBlock)reject -) - RCT_EXTERN_METHOD( setStorageDirPath: (nonnull NSString*)buildId storageDirPath: (nonnull NSString*)storageDirPath @@ -115,21 +106,6 @@ + (BOOL)requiresMainQueueSetup { return NO; } reject:(RCTPromiseRejectBlock)reject ) -RCT_EXTERN_METHOD( - bolt11Payment: (nonnull NSString*)nodeId - resolve: (RCTPromiseResolveBlock)resolve - reject:(RCTPromiseRejectBlock)reject -) - -RCT_EXTERN_METHOD( - receiveViaJitChannel: (nonnull NSString*)nodeId - amountMsat: (nonnull NSNumber*)amountMsat - description: (nonnull NSString*)description - expirySecs: (nonnull NSNumber*)expirySecs - resolve: (RCTPromiseResolveBlock)resolve - reject:(RCTPromiseRejectBlock)reject -) - RCT_EXTERN_METHOD( listeningAddresses: (nonnull NSString*)nodeId resolve: (RCTPromiseResolveBlock)resolve diff --git a/ios/LdkNodeRnModule.swift b/ios/LdkNodeRnModule.swift index e225ea9..d7136a6 100644 --- a/ios/LdkNodeRnModule.swift +++ b/ios/LdkNodeRnModule.swift @@ -180,21 +180,6 @@ class LdkNodeRnModule: NSObject { resolve(true) } } - - @objc - func setLiquiditySourceLsps2(_ - address: String, - nodeId: String, - token: String, - buildId: String, - resolve: @escaping RCTPromiseResolveBlock, - reject: @escaping RCTPromiseRejectBlock - ) { - DispatchQueue.main.async { [self] in - _builders[buildId]!.setLiquiditySourceLsps2(address: address, nodeId: nodeId, token: token) - resolve(true) - } - } @objc func build(_ @@ -286,24 +271,6 @@ class LdkNodeRnModule: NSObject { resolve(_nodes[nodeId]!.listeningAddresses()) } } - - - @objc - func bolt11Payment( - _ nodeId: String, - resolve: @escaping RCTPromiseResolveBlock, - reject: @escaping RCTPromiseRejectBlock - ) { - DispatchQueue.main.async { [self] in - if let node = _nodes[nodeId] { - resolve(node.bolt11Payment()) - } else { - let error = NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Node not found"]) - reject("Bolt11 Payment error", "Node not found", error) - } - } - } - @objc func newOnchainAddress(_ @@ -525,32 +492,6 @@ class LdkNodeRnModule: NSObject { } } } - - @objc - func receiveViaJitChannel(_ - nodeId: String, - amountMsat: NSNumber, - description: String, - expirySecs: NSNumber, - resolve: @escaping RCTPromiseResolveBlock, - reject: @escaping RCTPromiseRejectBlock - ) { - DispatchQueue.main.async { [self] in - do { - let maxFeeLimitMsat: UInt64 = 20002000 - let invoice = try _nodes[nodeId]!.bolt11Payment().receiveViaJitChannel( - amountMsat: UInt64(truncating: amountMsat), - description: description, - expirySecs: UInt32(truncating: expirySecs), - maxLspFeeLimitMsat: maxFeeLimitMsat - ) - resolve(invoice) - } catch let error { - reject("Receive payment invoice error", "\(error)", error) - } - } - } - @objc diff --git a/lib/classes/Bindings.d.ts b/lib/classes/Bindings.d.ts index 1adaac9..8f1a5a0 100644 --- a/lib/classes/Bindings.d.ts +++ b/lib/classes/Bindings.d.ts @@ -20,12 +20,6 @@ export declare class NetAddress { port: number; constructor(ip: string, port: number); } - -export declare class Bolt11Payment { - nodeId: PublicKey; - constructor(nodeId: PublicKey); -} - export declare class PeerDetails { nodeId: PublicKey; address: NetAddress; diff --git a/lib/classes/Builder.d.ts b/lib/classes/Builder.d.ts index aab2afc..0bbb006 100644 --- a/lib/classes/Builder.d.ts +++ b/lib/classes/Builder.d.ts @@ -44,9 +44,6 @@ export declare class Builder extends NativeLoader { * Configures the [Node] instance to source its gossip data from the Lightning peer-to-peer network. * @returns {Promise} */ - - setLiquiditySourceLsps2(address: string, publicKey:string, token:String): Promise; - setGossipSourceP2p(): Promise; /** * Configures the [Node] instance to source its gossip data from the given RapidGossipSync server. diff --git a/lib/classes/NativeLoader.d.ts b/lib/classes/NativeLoader.d.ts index c274ec2..31878cb 100644 --- a/lib/classes/NativeLoader.d.ts +++ b/lib/classes/NativeLoader.d.ts @@ -24,11 +24,6 @@ export interface NativeLdkNodeRn { setNetwork(buildId: string, network: string): boolean; setListeningAddresses(buildId: string, listeningAddresses: Array): boolean; build(buildId: string): string; - - setLiquiditySourceLsps2(address: string, publicKey: string, token: String, buildId: string): any; - bolt11Payment(nodeId: string): any; - receiveViaJitChannel(nodeId: string, amountMsat: number, description: string, expirySecs: number): any; - start(nodeId: string): boolean; stop(nodeId: string): boolean; syncWallets(nodeId: string): boolean; diff --git a/lib/classes/Node.d.ts b/lib/classes/Node.d.ts index 5705a81..d25201a 100644 --- a/lib/classes/Node.d.ts +++ b/lib/classes/Node.d.ts @@ -1,4 +1,4 @@ -import { Address, ChannelDetails, ChannelId, NetAddress, PaymentDetails, PaymentHash, PeerDetails, PublicKey, Txid, Bolt11Payment } from './Bindings'; +import { Address, ChannelDetails, ChannelId, NetAddress, PaymentDetails, PaymentHash, PeerDetails, PublicKey, Txid } from './Bindings'; import { NativeLoader } from './NativeLoader'; import { ChannelConfig } from './ChannelConfig'; export declare class Node extends NativeLoader { @@ -36,11 +36,6 @@ export declare class Node extends NativeLoader { * Returns listening Addresses * @returns {Promise>} */ - bolt11Payment(): Promise; - /** - * Returns bolt11 Payment - * @returns {Promise} - */ listeningAddresses(): Promise | null>; /** * Retrieve a new on-chain/funding address. @@ -113,8 +108,6 @@ export declare class Node extends NativeLoader { * @returns {Promise} */ sendPayment(invoice: string): Promise; - - bolt11Payment(): Promise; /** * Send a payment given an invoice and an amount in millisatoshi. * This will fail if the amount given is less than the value required by the given invoice. @@ -141,14 +134,6 @@ export declare class Node extends NativeLoader { * @requires [expirySecs] number * @returns {Promise} */ - receiveViaJitChannel(amountMsat: number, description: string, expirySecs: number): Promise; - /** - * Returns a payable invoice that can be used to request and receive a payment for which the amount is to be determined by the user, also known as a "zero-amount" invoice. - * @requires [amountMsat] amount in sats - * @requires [description] - * @requires [expirySecs] number - * @returns {Promise} - */ receivePayment(amountMsat: number, description: string, expirySecs: number): Promise; /** * Returns a payable invoice that can be used to request and receive a payment for which the amount is to be determined by the user, also known as a "zero-amount" invoice. diff --git a/src/classes/Builder.ts b/src/classes/Builder.ts index dd8ab77..102c78b 100644 --- a/src/classes/Builder.ts +++ b/src/classes/Builder.ts @@ -1,19 +1,10 @@ import { Config } from './Config'; import { NativeLoader } from './NativeLoader'; -import { NetAddress, PublicKey } from './Bindings'; +import { NetAddress } from './Bindings'; import { Node } from './Node'; import { addressToString } from '../utils'; -const DefaultServicesMutinynet = { -esploraServerUrl : 'https://mutinynet.ltbl.io/api', -rgsServerUrl : 'https://mutinynet.ltbl.io/snapshot', -lsps2SourceAddress : '44.219.111.31', -lsps2SourcePort : '39735', -lsps2SourcePublicKey :'0371d6fd7d75de2d0372d03ea00e8bacdacb50c27d0eaea0a76a0622eff1f5ef2b', -lsps2SourceToken : 'JZWN9YLW' -}; export class Builder extends NativeLoader { - id: string = ''; /** @@ -26,12 +17,6 @@ export class Builder extends NativeLoader { return this; } - // async fromConfig(config: Config): Promise { - // const builder = new Builder(); - // builder.id = await builder._ldk.fromConfig(config.id); - // return builder; - // } - /** * Configures the [Node] instance to source its wallet entropy from a seed file on disk. * @@ -121,26 +106,6 @@ export class Builder extends NativeLoader { ); } - async setLiquiditySourceLsps2(address: string, publicKey:string, token:String): Promise { - return await this._ldk.setLiquiditySourceLsps2(address, publicKey, token, this.id); - } - -// async createMutinynetBuilder(config?: Config): Promise { -// const builder = config ? await Builder.fromConfig(config) : new Builder(); - -// await builder.setNetwork('signet'); -// await builder.setEsploraServer(DefaultServicesMutinynet.esploraServerUrl); -// await builder.setGossipSourceRgs(DefaultServicesMutinynet.rgsServerUrl); -// await builder.setMutinityNetwork({ -// address: DefaultServicesMutinynet.lsps2SourceAddress, -// port: DefaultServicesMutinynet.lsps2SourcePort, -// publicKey: DefaultServicesMutinynet.lsps2SourcePublicKey, -// token: DefaultServicesMutinynet.lsps2SourceToken, -// }); - -// return builder; -// } - /** * Create node * @returns {Promise} diff --git a/src/classes/NativeLoader.ts b/src/classes/NativeLoader.ts index 1017072..5d4a15f 100644 --- a/src/classes/NativeLoader.ts +++ b/src/classes/NativeLoader.ts @@ -1,5 +1,5 @@ import { ChannelConfig } from './ChannelConfig'; -import { ChannelDetails, NetAddress, PaymentDetails, PeerDetails, PublicKey } from './Bindings'; +import { ChannelDetails, PaymentDetails, PeerDetails } from './Bindings'; import { NativeModules } from 'react-native'; @@ -30,10 +30,6 @@ export interface NativeLdkNodeRn { setListeningAddresses(buildId: string, listeningAddresses: Array): boolean; build(buildId: string): string; - setLiquiditySourceLsps2(address: string, publicKey: string, token: String, buildId: string): any; - bolt11Payment(nodeId: string): any; - receiveViaJitChannel(nodeId: string, amountMsat: number, description: string, expirySecs: number): any; - start(nodeId: string): boolean; stop(nodeId: string): boolean; syncWallets(nodeId: string): boolean; diff --git a/src/classes/Node.ts b/src/classes/Node.ts index 1f9ff84..5c03072 100644 --- a/src/classes/Node.ts +++ b/src/classes/Node.ts @@ -246,10 +246,6 @@ export class Node extends NativeLoader { return await this._ldk.receiveVariableAmountPayment(this.id, description, expirySecs); } - async receiveViaJitChannel(amountMsat: number, description: string, expirySecs: number): Promise{ - return await this._ldk.receiveViaJitChannel(this.id, amountMsat, description, expirySecs); - } - /** * Get list of payments * @returns {Promise>} @@ -377,10 +373,6 @@ export class Node extends NativeLoader { return await this._ldk.sendPaymentProbes(this.id, invoice); } - async bolt11Payment(): Promise { - return await this._ldk.bolt11Payment(this.id); - } - /** * Sends payment probes over all paths of a route that would be used to pay the given * zero-value invoice using the given amount. From 7d256bc9a20a13241685c6a189b369ec7deccd36 Mon Sep 17 00:00:00 2001 From: BitcoinZavior Date: Mon, 19 Aug 2024 19:30:00 -0400 Subject: [PATCH 6/9] Merge pull request for JIT_Payments --- ios/LdkNodeRnModule.m | 24 ++++++++++++++ ios/LdkNodeRnModule.swift | 59 +++++++++++++++++++++++++++++++++++ lib/classes/Bindings.d.ts | 6 ++++ lib/classes/Builder.d.ts | 3 ++ lib/classes/NativeLoader.d.ts | 5 +++ lib/classes/Node.d.ts | 17 +++++++++- src/classes/Builder.ts | 37 +++++++++++++++++++++- src/classes/NativeLoader.ts | 6 +++- src/classes/Node.ts | 8 +++++ 9 files changed, 162 insertions(+), 3 deletions(-) diff --git a/ios/LdkNodeRnModule.m b/ios/LdkNodeRnModule.m index e396aa5..f9f9f7d 100644 --- a/ios/LdkNodeRnModule.m +++ b/ios/LdkNodeRnModule.m @@ -71,6 +71,15 @@ + (BOOL)requiresMainQueueSetup { return NO; } reject:(RCTPromiseRejectBlock)reject ) +RCT_EXTERN_METHOD( + setLiquiditySourceLsps2: (nonnull NSString*)address + nodeId: (nonnull NSString*)publicKey + token: (nonnull NSString*)token + buildId: (nonnull NSString*)buildId + resolve: (RCTPromiseResolveBlock)resolve + reject:(RCTPromiseRejectBlock)reject +) + RCT_EXTERN_METHOD( setStorageDirPath: (nonnull NSString*)buildId storageDirPath: (nonnull NSString*)storageDirPath @@ -106,6 +115,21 @@ + (BOOL)requiresMainQueueSetup { return NO; } reject:(RCTPromiseRejectBlock)reject ) +RCT_EXTERN_METHOD( + bolt11Payment: (nonnull NSString*)nodeId + resolve: (RCTPromiseResolveBlock)resolve + reject:(RCTPromiseRejectBlock)reject +) + +RCT_EXTERN_METHOD( + receiveViaJitChannel: (nonnull NSString*)nodeId + amountMsat: (nonnull NSNumber*)amountMsat + description: (nonnull NSString*)description + expirySecs: (nonnull NSNumber*)expirySecs + resolve: (RCTPromiseResolveBlock)resolve + reject:(RCTPromiseRejectBlock)reject +) + RCT_EXTERN_METHOD( listeningAddresses: (nonnull NSString*)nodeId resolve: (RCTPromiseResolveBlock)resolve diff --git a/ios/LdkNodeRnModule.swift b/ios/LdkNodeRnModule.swift index d7136a6..e225ea9 100644 --- a/ios/LdkNodeRnModule.swift +++ b/ios/LdkNodeRnModule.swift @@ -180,6 +180,21 @@ class LdkNodeRnModule: NSObject { resolve(true) } } + + @objc + func setLiquiditySourceLsps2(_ + address: String, + nodeId: String, + token: String, + buildId: String, + resolve: @escaping RCTPromiseResolveBlock, + reject: @escaping RCTPromiseRejectBlock + ) { + DispatchQueue.main.async { [self] in + _builders[buildId]!.setLiquiditySourceLsps2(address: address, nodeId: nodeId, token: token) + resolve(true) + } + } @objc func build(_ @@ -271,6 +286,24 @@ class LdkNodeRnModule: NSObject { resolve(_nodes[nodeId]!.listeningAddresses()) } } + + + @objc + func bolt11Payment( + _ nodeId: String, + resolve: @escaping RCTPromiseResolveBlock, + reject: @escaping RCTPromiseRejectBlock + ) { + DispatchQueue.main.async { [self] in + if let node = _nodes[nodeId] { + resolve(node.bolt11Payment()) + } else { + let error = NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Node not found"]) + reject("Bolt11 Payment error", "Node not found", error) + } + } + } + @objc func newOnchainAddress(_ @@ -492,6 +525,32 @@ class LdkNodeRnModule: NSObject { } } } + + @objc + func receiveViaJitChannel(_ + nodeId: String, + amountMsat: NSNumber, + description: String, + expirySecs: NSNumber, + resolve: @escaping RCTPromiseResolveBlock, + reject: @escaping RCTPromiseRejectBlock + ) { + DispatchQueue.main.async { [self] in + do { + let maxFeeLimitMsat: UInt64 = 20002000 + let invoice = try _nodes[nodeId]!.bolt11Payment().receiveViaJitChannel( + amountMsat: UInt64(truncating: amountMsat), + description: description, + expirySecs: UInt32(truncating: expirySecs), + maxLspFeeLimitMsat: maxFeeLimitMsat + ) + resolve(invoice) + } catch let error { + reject("Receive payment invoice error", "\(error)", error) + } + } + } + @objc diff --git a/lib/classes/Bindings.d.ts b/lib/classes/Bindings.d.ts index 8f1a5a0..1adaac9 100644 --- a/lib/classes/Bindings.d.ts +++ b/lib/classes/Bindings.d.ts @@ -20,6 +20,12 @@ export declare class NetAddress { port: number; constructor(ip: string, port: number); } + +export declare class Bolt11Payment { + nodeId: PublicKey; + constructor(nodeId: PublicKey); +} + export declare class PeerDetails { nodeId: PublicKey; address: NetAddress; diff --git a/lib/classes/Builder.d.ts b/lib/classes/Builder.d.ts index 0bbb006..aab2afc 100644 --- a/lib/classes/Builder.d.ts +++ b/lib/classes/Builder.d.ts @@ -44,6 +44,9 @@ export declare class Builder extends NativeLoader { * Configures the [Node] instance to source its gossip data from the Lightning peer-to-peer network. * @returns {Promise} */ + + setLiquiditySourceLsps2(address: string, publicKey:string, token:String): Promise; + setGossipSourceP2p(): Promise; /** * Configures the [Node] instance to source its gossip data from the given RapidGossipSync server. diff --git a/lib/classes/NativeLoader.d.ts b/lib/classes/NativeLoader.d.ts index 31878cb..c274ec2 100644 --- a/lib/classes/NativeLoader.d.ts +++ b/lib/classes/NativeLoader.d.ts @@ -24,6 +24,11 @@ export interface NativeLdkNodeRn { setNetwork(buildId: string, network: string): boolean; setListeningAddresses(buildId: string, listeningAddresses: Array): boolean; build(buildId: string): string; + + setLiquiditySourceLsps2(address: string, publicKey: string, token: String, buildId: string): any; + bolt11Payment(nodeId: string): any; + receiveViaJitChannel(nodeId: string, amountMsat: number, description: string, expirySecs: number): any; + start(nodeId: string): boolean; stop(nodeId: string): boolean; syncWallets(nodeId: string): boolean; diff --git a/lib/classes/Node.d.ts b/lib/classes/Node.d.ts index d25201a..5705a81 100644 --- a/lib/classes/Node.d.ts +++ b/lib/classes/Node.d.ts @@ -1,4 +1,4 @@ -import { Address, ChannelDetails, ChannelId, NetAddress, PaymentDetails, PaymentHash, PeerDetails, PublicKey, Txid } from './Bindings'; +import { Address, ChannelDetails, ChannelId, NetAddress, PaymentDetails, PaymentHash, PeerDetails, PublicKey, Txid, Bolt11Payment } from './Bindings'; import { NativeLoader } from './NativeLoader'; import { ChannelConfig } from './ChannelConfig'; export declare class Node extends NativeLoader { @@ -36,6 +36,11 @@ export declare class Node extends NativeLoader { * Returns listening Addresses * @returns {Promise>} */ + bolt11Payment(): Promise; + /** + * Returns bolt11 Payment + * @returns {Promise} + */ listeningAddresses(): Promise | null>; /** * Retrieve a new on-chain/funding address. @@ -108,6 +113,8 @@ export declare class Node extends NativeLoader { * @returns {Promise} */ sendPayment(invoice: string): Promise; + + bolt11Payment(): Promise; /** * Send a payment given an invoice and an amount in millisatoshi. * This will fail if the amount given is less than the value required by the given invoice. @@ -134,6 +141,14 @@ export declare class Node extends NativeLoader { * @requires [expirySecs] number * @returns {Promise} */ + receiveViaJitChannel(amountMsat: number, description: string, expirySecs: number): Promise; + /** + * Returns a payable invoice that can be used to request and receive a payment for which the amount is to be determined by the user, also known as a "zero-amount" invoice. + * @requires [amountMsat] amount in sats + * @requires [description] + * @requires [expirySecs] number + * @returns {Promise} + */ receivePayment(amountMsat: number, description: string, expirySecs: number): Promise; /** * Returns a payable invoice that can be used to request and receive a payment for which the amount is to be determined by the user, also known as a "zero-amount" invoice. diff --git a/src/classes/Builder.ts b/src/classes/Builder.ts index 102c78b..dd8ab77 100644 --- a/src/classes/Builder.ts +++ b/src/classes/Builder.ts @@ -1,10 +1,19 @@ import { Config } from './Config'; import { NativeLoader } from './NativeLoader'; -import { NetAddress } from './Bindings'; +import { NetAddress, PublicKey } from './Bindings'; import { Node } from './Node'; import { addressToString } from '../utils'; +const DefaultServicesMutinynet = { +esploraServerUrl : 'https://mutinynet.ltbl.io/api', +rgsServerUrl : 'https://mutinynet.ltbl.io/snapshot', +lsps2SourceAddress : '44.219.111.31', +lsps2SourcePort : '39735', +lsps2SourcePublicKey :'0371d6fd7d75de2d0372d03ea00e8bacdacb50c27d0eaea0a76a0622eff1f5ef2b', +lsps2SourceToken : 'JZWN9YLW' +}; export class Builder extends NativeLoader { + id: string = ''; /** @@ -17,6 +26,12 @@ export class Builder extends NativeLoader { return this; } + // async fromConfig(config: Config): Promise { + // const builder = new Builder(); + // builder.id = await builder._ldk.fromConfig(config.id); + // return builder; + // } + /** * Configures the [Node] instance to source its wallet entropy from a seed file on disk. * @@ -106,6 +121,26 @@ export class Builder extends NativeLoader { ); } + async setLiquiditySourceLsps2(address: string, publicKey:string, token:String): Promise { + return await this._ldk.setLiquiditySourceLsps2(address, publicKey, token, this.id); + } + +// async createMutinynetBuilder(config?: Config): Promise { +// const builder = config ? await Builder.fromConfig(config) : new Builder(); + +// await builder.setNetwork('signet'); +// await builder.setEsploraServer(DefaultServicesMutinynet.esploraServerUrl); +// await builder.setGossipSourceRgs(DefaultServicesMutinynet.rgsServerUrl); +// await builder.setMutinityNetwork({ +// address: DefaultServicesMutinynet.lsps2SourceAddress, +// port: DefaultServicesMutinynet.lsps2SourcePort, +// publicKey: DefaultServicesMutinynet.lsps2SourcePublicKey, +// token: DefaultServicesMutinynet.lsps2SourceToken, +// }); + +// return builder; +// } + /** * Create node * @returns {Promise} diff --git a/src/classes/NativeLoader.ts b/src/classes/NativeLoader.ts index 5d4a15f..1017072 100644 --- a/src/classes/NativeLoader.ts +++ b/src/classes/NativeLoader.ts @@ -1,5 +1,5 @@ import { ChannelConfig } from './ChannelConfig'; -import { ChannelDetails, PaymentDetails, PeerDetails } from './Bindings'; +import { ChannelDetails, NetAddress, PaymentDetails, PeerDetails, PublicKey } from './Bindings'; import { NativeModules } from 'react-native'; @@ -30,6 +30,10 @@ export interface NativeLdkNodeRn { setListeningAddresses(buildId: string, listeningAddresses: Array): boolean; build(buildId: string): string; + setLiquiditySourceLsps2(address: string, publicKey: string, token: String, buildId: string): any; + bolt11Payment(nodeId: string): any; + receiveViaJitChannel(nodeId: string, amountMsat: number, description: string, expirySecs: number): any; + start(nodeId: string): boolean; stop(nodeId: string): boolean; syncWallets(nodeId: string): boolean; diff --git a/src/classes/Node.ts b/src/classes/Node.ts index 5c03072..1f9ff84 100644 --- a/src/classes/Node.ts +++ b/src/classes/Node.ts @@ -246,6 +246,10 @@ export class Node extends NativeLoader { return await this._ldk.receiveVariableAmountPayment(this.id, description, expirySecs); } + async receiveViaJitChannel(amountMsat: number, description: string, expirySecs: number): Promise{ + return await this._ldk.receiveViaJitChannel(this.id, amountMsat, description, expirySecs); + } + /** * Get list of payments * @returns {Promise>} @@ -373,6 +377,10 @@ export class Node extends NativeLoader { return await this._ldk.sendPaymentProbes(this.id, invoice); } + async bolt11Payment(): Promise { + return await this._ldk.bolt11Payment(this.id); + } + /** * Sends payment probes over all paths of a route that would be used to pay the given * zero-value invoice using the given amount. From ce7d21eb811fb187f0a6452c87f937155fb2c468 Mon Sep 17 00:00:00 2001 From: BitcoinZavior Date: Wed, 21 Aug 2024 19:01:00 -0400 Subject: [PATCH 7/9] Changelog Updated --- CHANGELOG.md | 9 ++++++ ios/LdkNodeRnModule.m | 24 -------------- ios/LdkNodeRnModule.swift | 59 ----------------------------------- lib/classes/Bindings.d.ts | 6 ---- lib/classes/Builder.d.ts | 3 -- lib/classes/NativeLoader.d.ts | 5 --- lib/classes/Node.d.ts | 17 +--------- src/classes/Builder.ts | 37 +--------------------- src/classes/NativeLoader.ts | 6 +--- src/classes/Node.ts | 8 ----- 10 files changed, 12 insertions(+), 162 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c86e93..1c7b574 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ This is the new release of `ldk-node-rn` v0.3.0 . +#### APIs added + +- Exposed `setLiquiditySourceLsps2` method to `Builder` to configure the `Node` instance to source the inbound liquidity. +- Support for sourcing inbound liquidity via LSPS2 just-in-time (JIT) channels has been added. + +#### API changed + +- All available balances outside of channel balances are now exposed via a unified `listBalances` interface method. + ## [0.2.2] This is a bugfix release that reestablishes compatibility of Swift packages with Xcode 15.3 and later. diff --git a/ios/LdkNodeRnModule.m b/ios/LdkNodeRnModule.m index f9f9f7d..e396aa5 100644 --- a/ios/LdkNodeRnModule.m +++ b/ios/LdkNodeRnModule.m @@ -71,15 +71,6 @@ + (BOOL)requiresMainQueueSetup { return NO; } reject:(RCTPromiseRejectBlock)reject ) -RCT_EXTERN_METHOD( - setLiquiditySourceLsps2: (nonnull NSString*)address - nodeId: (nonnull NSString*)publicKey - token: (nonnull NSString*)token - buildId: (nonnull NSString*)buildId - resolve: (RCTPromiseResolveBlock)resolve - reject:(RCTPromiseRejectBlock)reject -) - RCT_EXTERN_METHOD( setStorageDirPath: (nonnull NSString*)buildId storageDirPath: (nonnull NSString*)storageDirPath @@ -115,21 +106,6 @@ + (BOOL)requiresMainQueueSetup { return NO; } reject:(RCTPromiseRejectBlock)reject ) -RCT_EXTERN_METHOD( - bolt11Payment: (nonnull NSString*)nodeId - resolve: (RCTPromiseResolveBlock)resolve - reject:(RCTPromiseRejectBlock)reject -) - -RCT_EXTERN_METHOD( - receiveViaJitChannel: (nonnull NSString*)nodeId - amountMsat: (nonnull NSNumber*)amountMsat - description: (nonnull NSString*)description - expirySecs: (nonnull NSNumber*)expirySecs - resolve: (RCTPromiseResolveBlock)resolve - reject:(RCTPromiseRejectBlock)reject -) - RCT_EXTERN_METHOD( listeningAddresses: (nonnull NSString*)nodeId resolve: (RCTPromiseResolveBlock)resolve diff --git a/ios/LdkNodeRnModule.swift b/ios/LdkNodeRnModule.swift index e225ea9..d7136a6 100644 --- a/ios/LdkNodeRnModule.swift +++ b/ios/LdkNodeRnModule.swift @@ -180,21 +180,6 @@ class LdkNodeRnModule: NSObject { resolve(true) } } - - @objc - func setLiquiditySourceLsps2(_ - address: String, - nodeId: String, - token: String, - buildId: String, - resolve: @escaping RCTPromiseResolveBlock, - reject: @escaping RCTPromiseRejectBlock - ) { - DispatchQueue.main.async { [self] in - _builders[buildId]!.setLiquiditySourceLsps2(address: address, nodeId: nodeId, token: token) - resolve(true) - } - } @objc func build(_ @@ -286,24 +271,6 @@ class LdkNodeRnModule: NSObject { resolve(_nodes[nodeId]!.listeningAddresses()) } } - - - @objc - func bolt11Payment( - _ nodeId: String, - resolve: @escaping RCTPromiseResolveBlock, - reject: @escaping RCTPromiseRejectBlock - ) { - DispatchQueue.main.async { [self] in - if let node = _nodes[nodeId] { - resolve(node.bolt11Payment()) - } else { - let error = NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Node not found"]) - reject("Bolt11 Payment error", "Node not found", error) - } - } - } - @objc func newOnchainAddress(_ @@ -525,32 +492,6 @@ class LdkNodeRnModule: NSObject { } } } - - @objc - func receiveViaJitChannel(_ - nodeId: String, - amountMsat: NSNumber, - description: String, - expirySecs: NSNumber, - resolve: @escaping RCTPromiseResolveBlock, - reject: @escaping RCTPromiseRejectBlock - ) { - DispatchQueue.main.async { [self] in - do { - let maxFeeLimitMsat: UInt64 = 20002000 - let invoice = try _nodes[nodeId]!.bolt11Payment().receiveViaJitChannel( - amountMsat: UInt64(truncating: amountMsat), - description: description, - expirySecs: UInt32(truncating: expirySecs), - maxLspFeeLimitMsat: maxFeeLimitMsat - ) - resolve(invoice) - } catch let error { - reject("Receive payment invoice error", "\(error)", error) - } - } - } - @objc diff --git a/lib/classes/Bindings.d.ts b/lib/classes/Bindings.d.ts index 1adaac9..8f1a5a0 100644 --- a/lib/classes/Bindings.d.ts +++ b/lib/classes/Bindings.d.ts @@ -20,12 +20,6 @@ export declare class NetAddress { port: number; constructor(ip: string, port: number); } - -export declare class Bolt11Payment { - nodeId: PublicKey; - constructor(nodeId: PublicKey); -} - export declare class PeerDetails { nodeId: PublicKey; address: NetAddress; diff --git a/lib/classes/Builder.d.ts b/lib/classes/Builder.d.ts index aab2afc..0bbb006 100644 --- a/lib/classes/Builder.d.ts +++ b/lib/classes/Builder.d.ts @@ -44,9 +44,6 @@ export declare class Builder extends NativeLoader { * Configures the [Node] instance to source its gossip data from the Lightning peer-to-peer network. * @returns {Promise} */ - - setLiquiditySourceLsps2(address: string, publicKey:string, token:String): Promise; - setGossipSourceP2p(): Promise; /** * Configures the [Node] instance to source its gossip data from the given RapidGossipSync server. diff --git a/lib/classes/NativeLoader.d.ts b/lib/classes/NativeLoader.d.ts index c274ec2..31878cb 100644 --- a/lib/classes/NativeLoader.d.ts +++ b/lib/classes/NativeLoader.d.ts @@ -24,11 +24,6 @@ export interface NativeLdkNodeRn { setNetwork(buildId: string, network: string): boolean; setListeningAddresses(buildId: string, listeningAddresses: Array): boolean; build(buildId: string): string; - - setLiquiditySourceLsps2(address: string, publicKey: string, token: String, buildId: string): any; - bolt11Payment(nodeId: string): any; - receiveViaJitChannel(nodeId: string, amountMsat: number, description: string, expirySecs: number): any; - start(nodeId: string): boolean; stop(nodeId: string): boolean; syncWallets(nodeId: string): boolean; diff --git a/lib/classes/Node.d.ts b/lib/classes/Node.d.ts index 5705a81..d25201a 100644 --- a/lib/classes/Node.d.ts +++ b/lib/classes/Node.d.ts @@ -1,4 +1,4 @@ -import { Address, ChannelDetails, ChannelId, NetAddress, PaymentDetails, PaymentHash, PeerDetails, PublicKey, Txid, Bolt11Payment } from './Bindings'; +import { Address, ChannelDetails, ChannelId, NetAddress, PaymentDetails, PaymentHash, PeerDetails, PublicKey, Txid } from './Bindings'; import { NativeLoader } from './NativeLoader'; import { ChannelConfig } from './ChannelConfig'; export declare class Node extends NativeLoader { @@ -36,11 +36,6 @@ export declare class Node extends NativeLoader { * Returns listening Addresses * @returns {Promise>} */ - bolt11Payment(): Promise; - /** - * Returns bolt11 Payment - * @returns {Promise} - */ listeningAddresses(): Promise | null>; /** * Retrieve a new on-chain/funding address. @@ -113,8 +108,6 @@ export declare class Node extends NativeLoader { * @returns {Promise} */ sendPayment(invoice: string): Promise; - - bolt11Payment(): Promise; /** * Send a payment given an invoice and an amount in millisatoshi. * This will fail if the amount given is less than the value required by the given invoice. @@ -141,14 +134,6 @@ export declare class Node extends NativeLoader { * @requires [expirySecs] number * @returns {Promise} */ - receiveViaJitChannel(amountMsat: number, description: string, expirySecs: number): Promise; - /** - * Returns a payable invoice that can be used to request and receive a payment for which the amount is to be determined by the user, also known as a "zero-amount" invoice. - * @requires [amountMsat] amount in sats - * @requires [description] - * @requires [expirySecs] number - * @returns {Promise} - */ receivePayment(amountMsat: number, description: string, expirySecs: number): Promise; /** * Returns a payable invoice that can be used to request and receive a payment for which the amount is to be determined by the user, also known as a "zero-amount" invoice. diff --git a/src/classes/Builder.ts b/src/classes/Builder.ts index dd8ab77..102c78b 100644 --- a/src/classes/Builder.ts +++ b/src/classes/Builder.ts @@ -1,19 +1,10 @@ import { Config } from './Config'; import { NativeLoader } from './NativeLoader'; -import { NetAddress, PublicKey } from './Bindings'; +import { NetAddress } from './Bindings'; import { Node } from './Node'; import { addressToString } from '../utils'; -const DefaultServicesMutinynet = { -esploraServerUrl : 'https://mutinynet.ltbl.io/api', -rgsServerUrl : 'https://mutinynet.ltbl.io/snapshot', -lsps2SourceAddress : '44.219.111.31', -lsps2SourcePort : '39735', -lsps2SourcePublicKey :'0371d6fd7d75de2d0372d03ea00e8bacdacb50c27d0eaea0a76a0622eff1f5ef2b', -lsps2SourceToken : 'JZWN9YLW' -}; export class Builder extends NativeLoader { - id: string = ''; /** @@ -26,12 +17,6 @@ export class Builder extends NativeLoader { return this; } - // async fromConfig(config: Config): Promise { - // const builder = new Builder(); - // builder.id = await builder._ldk.fromConfig(config.id); - // return builder; - // } - /** * Configures the [Node] instance to source its wallet entropy from a seed file on disk. * @@ -121,26 +106,6 @@ export class Builder extends NativeLoader { ); } - async setLiquiditySourceLsps2(address: string, publicKey:string, token:String): Promise { - return await this._ldk.setLiquiditySourceLsps2(address, publicKey, token, this.id); - } - -// async createMutinynetBuilder(config?: Config): Promise { -// const builder = config ? await Builder.fromConfig(config) : new Builder(); - -// await builder.setNetwork('signet'); -// await builder.setEsploraServer(DefaultServicesMutinynet.esploraServerUrl); -// await builder.setGossipSourceRgs(DefaultServicesMutinynet.rgsServerUrl); -// await builder.setMutinityNetwork({ -// address: DefaultServicesMutinynet.lsps2SourceAddress, -// port: DefaultServicesMutinynet.lsps2SourcePort, -// publicKey: DefaultServicesMutinynet.lsps2SourcePublicKey, -// token: DefaultServicesMutinynet.lsps2SourceToken, -// }); - -// return builder; -// } - /** * Create node * @returns {Promise} diff --git a/src/classes/NativeLoader.ts b/src/classes/NativeLoader.ts index 1017072..5d4a15f 100644 --- a/src/classes/NativeLoader.ts +++ b/src/classes/NativeLoader.ts @@ -1,5 +1,5 @@ import { ChannelConfig } from './ChannelConfig'; -import { ChannelDetails, NetAddress, PaymentDetails, PeerDetails, PublicKey } from './Bindings'; +import { ChannelDetails, PaymentDetails, PeerDetails } from './Bindings'; import { NativeModules } from 'react-native'; @@ -30,10 +30,6 @@ export interface NativeLdkNodeRn { setListeningAddresses(buildId: string, listeningAddresses: Array): boolean; build(buildId: string): string; - setLiquiditySourceLsps2(address: string, publicKey: string, token: String, buildId: string): any; - bolt11Payment(nodeId: string): any; - receiveViaJitChannel(nodeId: string, amountMsat: number, description: string, expirySecs: number): any; - start(nodeId: string): boolean; stop(nodeId: string): boolean; syncWallets(nodeId: string): boolean; diff --git a/src/classes/Node.ts b/src/classes/Node.ts index 1f9ff84..5c03072 100644 --- a/src/classes/Node.ts +++ b/src/classes/Node.ts @@ -246,10 +246,6 @@ export class Node extends NativeLoader { return await this._ldk.receiveVariableAmountPayment(this.id, description, expirySecs); } - async receiveViaJitChannel(amountMsat: number, description: string, expirySecs: number): Promise{ - return await this._ldk.receiveViaJitChannel(this.id, amountMsat, description, expirySecs); - } - /** * Get list of payments * @returns {Promise>} @@ -377,10 +373,6 @@ export class Node extends NativeLoader { return await this._ldk.sendPaymentProbes(this.id, invoice); } - async bolt11Payment(): Promise { - return await this._ldk.bolt11Payment(this.id); - } - /** * Sends payment probes over all paths of a route that would be used to pay the given * zero-value invoice using the given amount. From 357315fd754dc6591d54cc912c261e0fa789c4da Mon Sep 17 00:00:00 2001 From: BitcoinZavior Date: Sun, 25 Aug 2024 17:36:00 -0400 Subject: [PATCH 8/9] Updated Changelog For v0.3.0 --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c7b574..5badee5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,16 @@ This is the new release of `ldk-node-rn` v0.3.0 . #### APIs added +- `buildWithFsStore` method is added in the `Builder` class allowing to use the filesystem storage backend. - Exposed `setLiquiditySourceLsps2` method to `Builder` to configure the `Node` instance to source the inbound liquidity. +- `nextEventAsync` method is added to `Node` class that allows polling the event queue asynchronously. +- `status` method has been added to `Node` allowing to retrieve information about the Node's status. +- `config` method added to get the config with which the `Node` was initialized. +- The payment APIs have been restructured to use per-type (bolt11, onchain, bolt12) payment handlers which can be accessed via `node.{type}Payment`. - Support for sourcing inbound liquidity via LSPS2 just-in-time (JIT) channels has been added. +- Support for creating and paying BOLT12 offers and refunds has been added. +- Added `networkGraph` handler method allowing to query the network graph. +- Added `forceCloseChannel` to `Node` class. #### API changed From 6c4397a1d215862beb0d38174a69365dcad5ceec Mon Sep 17 00:00:00 2001 From: BitcoinZavior Date: Wed, 28 Aug 2024 21:21:00 -0400 Subject: [PATCH 9/9] Merge pull request for Updated_CHANGELOG --- ios/LdkNodeRnModule.m | 24 ++++++++++++++ ios/LdkNodeRnModule.swift | 59 +++++++++++++++++++++++++++++++++++ lib/classes/Bindings.d.ts | 6 ++++ lib/classes/Builder.d.ts | 3 ++ lib/classes/NativeLoader.d.ts | 5 +++ lib/classes/Node.d.ts | 17 +++++++++- src/classes/Builder.ts | 37 +++++++++++++++++++++- src/classes/NativeLoader.ts | 6 +++- src/classes/Node.ts | 8 +++++ 9 files changed, 162 insertions(+), 3 deletions(-) diff --git a/ios/LdkNodeRnModule.m b/ios/LdkNodeRnModule.m index e396aa5..f9f9f7d 100644 --- a/ios/LdkNodeRnModule.m +++ b/ios/LdkNodeRnModule.m @@ -71,6 +71,15 @@ + (BOOL)requiresMainQueueSetup { return NO; } reject:(RCTPromiseRejectBlock)reject ) +RCT_EXTERN_METHOD( + setLiquiditySourceLsps2: (nonnull NSString*)address + nodeId: (nonnull NSString*)publicKey + token: (nonnull NSString*)token + buildId: (nonnull NSString*)buildId + resolve: (RCTPromiseResolveBlock)resolve + reject:(RCTPromiseRejectBlock)reject +) + RCT_EXTERN_METHOD( setStorageDirPath: (nonnull NSString*)buildId storageDirPath: (nonnull NSString*)storageDirPath @@ -106,6 +115,21 @@ + (BOOL)requiresMainQueueSetup { return NO; } reject:(RCTPromiseRejectBlock)reject ) +RCT_EXTERN_METHOD( + bolt11Payment: (nonnull NSString*)nodeId + resolve: (RCTPromiseResolveBlock)resolve + reject:(RCTPromiseRejectBlock)reject +) + +RCT_EXTERN_METHOD( + receiveViaJitChannel: (nonnull NSString*)nodeId + amountMsat: (nonnull NSNumber*)amountMsat + description: (nonnull NSString*)description + expirySecs: (nonnull NSNumber*)expirySecs + resolve: (RCTPromiseResolveBlock)resolve + reject:(RCTPromiseRejectBlock)reject +) + RCT_EXTERN_METHOD( listeningAddresses: (nonnull NSString*)nodeId resolve: (RCTPromiseResolveBlock)resolve diff --git a/ios/LdkNodeRnModule.swift b/ios/LdkNodeRnModule.swift index d7136a6..e225ea9 100644 --- a/ios/LdkNodeRnModule.swift +++ b/ios/LdkNodeRnModule.swift @@ -180,6 +180,21 @@ class LdkNodeRnModule: NSObject { resolve(true) } } + + @objc + func setLiquiditySourceLsps2(_ + address: String, + nodeId: String, + token: String, + buildId: String, + resolve: @escaping RCTPromiseResolveBlock, + reject: @escaping RCTPromiseRejectBlock + ) { + DispatchQueue.main.async { [self] in + _builders[buildId]!.setLiquiditySourceLsps2(address: address, nodeId: nodeId, token: token) + resolve(true) + } + } @objc func build(_ @@ -271,6 +286,24 @@ class LdkNodeRnModule: NSObject { resolve(_nodes[nodeId]!.listeningAddresses()) } } + + + @objc + func bolt11Payment( + _ nodeId: String, + resolve: @escaping RCTPromiseResolveBlock, + reject: @escaping RCTPromiseRejectBlock + ) { + DispatchQueue.main.async { [self] in + if let node = _nodes[nodeId] { + resolve(node.bolt11Payment()) + } else { + let error = NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Node not found"]) + reject("Bolt11 Payment error", "Node not found", error) + } + } + } + @objc func newOnchainAddress(_ @@ -492,6 +525,32 @@ class LdkNodeRnModule: NSObject { } } } + + @objc + func receiveViaJitChannel(_ + nodeId: String, + amountMsat: NSNumber, + description: String, + expirySecs: NSNumber, + resolve: @escaping RCTPromiseResolveBlock, + reject: @escaping RCTPromiseRejectBlock + ) { + DispatchQueue.main.async { [self] in + do { + let maxFeeLimitMsat: UInt64 = 20002000 + let invoice = try _nodes[nodeId]!.bolt11Payment().receiveViaJitChannel( + amountMsat: UInt64(truncating: amountMsat), + description: description, + expirySecs: UInt32(truncating: expirySecs), + maxLspFeeLimitMsat: maxFeeLimitMsat + ) + resolve(invoice) + } catch let error { + reject("Receive payment invoice error", "\(error)", error) + } + } + } + @objc diff --git a/lib/classes/Bindings.d.ts b/lib/classes/Bindings.d.ts index 8f1a5a0..1adaac9 100644 --- a/lib/classes/Bindings.d.ts +++ b/lib/classes/Bindings.d.ts @@ -20,6 +20,12 @@ export declare class NetAddress { port: number; constructor(ip: string, port: number); } + +export declare class Bolt11Payment { + nodeId: PublicKey; + constructor(nodeId: PublicKey); +} + export declare class PeerDetails { nodeId: PublicKey; address: NetAddress; diff --git a/lib/classes/Builder.d.ts b/lib/classes/Builder.d.ts index 0bbb006..aab2afc 100644 --- a/lib/classes/Builder.d.ts +++ b/lib/classes/Builder.d.ts @@ -44,6 +44,9 @@ export declare class Builder extends NativeLoader { * Configures the [Node] instance to source its gossip data from the Lightning peer-to-peer network. * @returns {Promise} */ + + setLiquiditySourceLsps2(address: string, publicKey:string, token:String): Promise; + setGossipSourceP2p(): Promise; /** * Configures the [Node] instance to source its gossip data from the given RapidGossipSync server. diff --git a/lib/classes/NativeLoader.d.ts b/lib/classes/NativeLoader.d.ts index 31878cb..c274ec2 100644 --- a/lib/classes/NativeLoader.d.ts +++ b/lib/classes/NativeLoader.d.ts @@ -24,6 +24,11 @@ export interface NativeLdkNodeRn { setNetwork(buildId: string, network: string): boolean; setListeningAddresses(buildId: string, listeningAddresses: Array): boolean; build(buildId: string): string; + + setLiquiditySourceLsps2(address: string, publicKey: string, token: String, buildId: string): any; + bolt11Payment(nodeId: string): any; + receiveViaJitChannel(nodeId: string, amountMsat: number, description: string, expirySecs: number): any; + start(nodeId: string): boolean; stop(nodeId: string): boolean; syncWallets(nodeId: string): boolean; diff --git a/lib/classes/Node.d.ts b/lib/classes/Node.d.ts index d25201a..5705a81 100644 --- a/lib/classes/Node.d.ts +++ b/lib/classes/Node.d.ts @@ -1,4 +1,4 @@ -import { Address, ChannelDetails, ChannelId, NetAddress, PaymentDetails, PaymentHash, PeerDetails, PublicKey, Txid } from './Bindings'; +import { Address, ChannelDetails, ChannelId, NetAddress, PaymentDetails, PaymentHash, PeerDetails, PublicKey, Txid, Bolt11Payment } from './Bindings'; import { NativeLoader } from './NativeLoader'; import { ChannelConfig } from './ChannelConfig'; export declare class Node extends NativeLoader { @@ -36,6 +36,11 @@ export declare class Node extends NativeLoader { * Returns listening Addresses * @returns {Promise>} */ + bolt11Payment(): Promise; + /** + * Returns bolt11 Payment + * @returns {Promise} + */ listeningAddresses(): Promise | null>; /** * Retrieve a new on-chain/funding address. @@ -108,6 +113,8 @@ export declare class Node extends NativeLoader { * @returns {Promise} */ sendPayment(invoice: string): Promise; + + bolt11Payment(): Promise; /** * Send a payment given an invoice and an amount in millisatoshi. * This will fail if the amount given is less than the value required by the given invoice. @@ -134,6 +141,14 @@ export declare class Node extends NativeLoader { * @requires [expirySecs] number * @returns {Promise} */ + receiveViaJitChannel(amountMsat: number, description: string, expirySecs: number): Promise; + /** + * Returns a payable invoice that can be used to request and receive a payment for which the amount is to be determined by the user, also known as a "zero-amount" invoice. + * @requires [amountMsat] amount in sats + * @requires [description] + * @requires [expirySecs] number + * @returns {Promise} + */ receivePayment(amountMsat: number, description: string, expirySecs: number): Promise; /** * Returns a payable invoice that can be used to request and receive a payment for which the amount is to be determined by the user, also known as a "zero-amount" invoice. diff --git a/src/classes/Builder.ts b/src/classes/Builder.ts index 102c78b..dd8ab77 100644 --- a/src/classes/Builder.ts +++ b/src/classes/Builder.ts @@ -1,10 +1,19 @@ import { Config } from './Config'; import { NativeLoader } from './NativeLoader'; -import { NetAddress } from './Bindings'; +import { NetAddress, PublicKey } from './Bindings'; import { Node } from './Node'; import { addressToString } from '../utils'; +const DefaultServicesMutinynet = { +esploraServerUrl : 'https://mutinynet.ltbl.io/api', +rgsServerUrl : 'https://mutinynet.ltbl.io/snapshot', +lsps2SourceAddress : '44.219.111.31', +lsps2SourcePort : '39735', +lsps2SourcePublicKey :'0371d6fd7d75de2d0372d03ea00e8bacdacb50c27d0eaea0a76a0622eff1f5ef2b', +lsps2SourceToken : 'JZWN9YLW' +}; export class Builder extends NativeLoader { + id: string = ''; /** @@ -17,6 +26,12 @@ export class Builder extends NativeLoader { return this; } + // async fromConfig(config: Config): Promise { + // const builder = new Builder(); + // builder.id = await builder._ldk.fromConfig(config.id); + // return builder; + // } + /** * Configures the [Node] instance to source its wallet entropy from a seed file on disk. * @@ -106,6 +121,26 @@ export class Builder extends NativeLoader { ); } + async setLiquiditySourceLsps2(address: string, publicKey:string, token:String): Promise { + return await this._ldk.setLiquiditySourceLsps2(address, publicKey, token, this.id); + } + +// async createMutinynetBuilder(config?: Config): Promise { +// const builder = config ? await Builder.fromConfig(config) : new Builder(); + +// await builder.setNetwork('signet'); +// await builder.setEsploraServer(DefaultServicesMutinynet.esploraServerUrl); +// await builder.setGossipSourceRgs(DefaultServicesMutinynet.rgsServerUrl); +// await builder.setMutinityNetwork({ +// address: DefaultServicesMutinynet.lsps2SourceAddress, +// port: DefaultServicesMutinynet.lsps2SourcePort, +// publicKey: DefaultServicesMutinynet.lsps2SourcePublicKey, +// token: DefaultServicesMutinynet.lsps2SourceToken, +// }); + +// return builder; +// } + /** * Create node * @returns {Promise} diff --git a/src/classes/NativeLoader.ts b/src/classes/NativeLoader.ts index 5d4a15f..1017072 100644 --- a/src/classes/NativeLoader.ts +++ b/src/classes/NativeLoader.ts @@ -1,5 +1,5 @@ import { ChannelConfig } from './ChannelConfig'; -import { ChannelDetails, PaymentDetails, PeerDetails } from './Bindings'; +import { ChannelDetails, NetAddress, PaymentDetails, PeerDetails, PublicKey } from './Bindings'; import { NativeModules } from 'react-native'; @@ -30,6 +30,10 @@ export interface NativeLdkNodeRn { setListeningAddresses(buildId: string, listeningAddresses: Array): boolean; build(buildId: string): string; + setLiquiditySourceLsps2(address: string, publicKey: string, token: String, buildId: string): any; + bolt11Payment(nodeId: string): any; + receiveViaJitChannel(nodeId: string, amountMsat: number, description: string, expirySecs: number): any; + start(nodeId: string): boolean; stop(nodeId: string): boolean; syncWallets(nodeId: string): boolean; diff --git a/src/classes/Node.ts b/src/classes/Node.ts index 5c03072..1f9ff84 100644 --- a/src/classes/Node.ts +++ b/src/classes/Node.ts @@ -246,6 +246,10 @@ export class Node extends NativeLoader { return await this._ldk.receiveVariableAmountPayment(this.id, description, expirySecs); } + async receiveViaJitChannel(amountMsat: number, description: string, expirySecs: number): Promise{ + return await this._ldk.receiveViaJitChannel(this.id, amountMsat, description, expirySecs); + } + /** * Get list of payments * @returns {Promise>} @@ -373,6 +377,10 @@ export class Node extends NativeLoader { return await this._ldk.sendPaymentProbes(this.id, invoice); } + async bolt11Payment(): Promise { + return await this._ldk.bolt11Payment(this.id); + } + /** * Sends payment probes over all paths of a route that would be used to pay the given * zero-value invoice using the given amount.