From a9ab605fa78d5b18b47f4dc9a238446c162d0784 Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 19 Sep 2023 09:43:32 +0200 Subject: [PATCH] fix: new fee type (mempoolMinimum) --- .../src/main/java/com/reactnativeldk/LdkModule.kt | 4 ++-- .../com/reactnativeldk/classes/LdkFeeEstimator.kt | 10 +++++++++- lib/ios/Classes/LdkFeeEstimator.swift | 14 +++++++++++--- lib/ios/Ldk.m | 1 + lib/ios/Ldk.swift | 4 ++-- lib/src/ldk.ts | 3 ++- lib/src/lightning-manager.ts | 1 + lib/src/utils/types.ts | 1 + 8 files changed, 29 insertions(+), 9 deletions(-) diff --git a/lib/android/src/main/java/com/reactnativeldk/LdkModule.kt b/lib/android/src/main/java/com/reactnativeldk/LdkModule.kt index fab631e6..65f3071f 100644 --- a/lib/android/src/main/java/com/reactnativeldk/LdkModule.kt +++ b/lib/android/src/main/java/com/reactnativeldk/LdkModule.kt @@ -512,8 +512,8 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod //MARK: Update methods @ReactMethod - fun updateFees(high: Double, normal: Double, low: Double, promise: Promise) { - feeEstimator.update(high.toInt(), normal.toInt(), low.toInt()) + fun updateFees(high: Double, normal: Double, low: Double, mempoolMinimum: Double, promise: Promise) { + feeEstimator.update(high.toInt(), normal.toInt(), low.toInt(), mempoolMinimum.toInt()) handleResolve(promise, LdkCallbackResponses.fees_updated) } diff --git a/lib/android/src/main/java/com/reactnativeldk/classes/LdkFeeEstimator.kt b/lib/android/src/main/java/com/reactnativeldk/classes/LdkFeeEstimator.kt index 1b06ec07..46f791dc 100644 --- a/lib/android/src/main/java/com/reactnativeldk/classes/LdkFeeEstimator.kt +++ b/lib/android/src/main/java/com/reactnativeldk/classes/LdkFeeEstimator.kt @@ -8,6 +8,7 @@ class LdkFeeEstimator { var high: Int = 0 var normal: Int = 0 var low: Int = 0 + var mempoolMinimum: Int = 0 var feeEstimator = FeeEstimator.new_impl { target: ConfirmationTarget -> if (target.equals(ConfirmationTarget.LDKConfirmationTarget_HighPriority)) { return@new_impl high @@ -21,13 +22,20 @@ class LdkFeeEstimator { return@new_impl low } + if (target.equals(ConfirmationTarget.LDKConfirmationTarget_MempoolMinimum)) { + return@new_impl mempoolMinimum + } + + LdkEventEmitter.send(EventTypes.native_log, "WARNING: New ConfirmationTarget added. Update LdkFeeEstimator.") + return@new_impl normal } - fun update(high: Int, normal: Int, low: Int) { + fun update(high: Int, normal: Int, low: Int, mempoolMinimum: Int) { this.high = high this.normal = normal this.low = low + this.mempoolMinimum = mempoolMinimum LdkEventEmitter.send(EventTypes.native_log, "Fee estimator updated") } diff --git a/lib/ios/Classes/LdkFeeEstimator.swift b/lib/ios/Classes/LdkFeeEstimator.swift index 289af1f9..1b2a1319 100644 --- a/lib/ios/Classes/LdkFeeEstimator.swift +++ b/lib/ios/Classes/LdkFeeEstimator.swift @@ -12,12 +12,14 @@ class LdkFeeEstimator: FeeEstimator { private var high: UInt32 = 0 private var normal: UInt32 = 0 private var low: UInt32 = 0 + private var mempoolMinimum: UInt32 = 0 - func update(high: UInt32, normal: UInt32, low: UInt32) { + func update(high: UInt32, normal: UInt32, low: UInt32, mempoolMinimum: UInt32) { self.high = high self.normal = normal self.low = low - + self.mempoolMinimum = mempoolMinimum + LdkEventEmitter.shared.send(withEvent: .native_log, body: "Fee estimator updated") } @@ -35,7 +37,13 @@ class LdkFeeEstimator: FeeEstimator { if case ConfirmationTarget.Background = target { return low } - + + if case ConfirmationTarget.MempoolMinimum = target { + return mempoolMinimum + } + + LdkEventEmitter.shared.send(withEvent: .native_log, body: "WARNING: New ConfirmationTarget added. Update LdkFeeEstimator.") + return normal } } diff --git a/lib/ios/Ldk.m b/lib/ios/Ldk.m index 5c036434..e201ff34 100644 --- a/lib/ios/Ldk.m +++ b/lib/ios/Ldk.m @@ -39,6 +39,7 @@ @interface RCT_EXTERN_MODULE(Ldk, NSObject) RCT_EXTERN_METHOD(updateFees:(NSInteger *)high normal:(NSInteger *)normal low:(NSInteger *)low + mempoolMinimum:(NSInteger *)mempoolMinimum resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) RCT_EXTERN_METHOD(setLogLevel:(NSString *)level diff --git a/lib/ios/Ldk.swift b/lib/ios/Ldk.swift index 61a4e09a..4e2c2d36 100644 --- a/lib/ios/Ldk.swift +++ b/lib/ios/Ldk.swift @@ -526,8 +526,8 @@ class Ldk: NSObject { //MARK: Update methods @objc - func updateFees(_ high: NSInteger, normal: NSInteger, low: NSInteger, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { - feeEstimator.update(high: UInt32(high), normal: UInt32(normal), low: UInt32(low)) + func updateFees(_ high: NSInteger, normal: NSInteger, low: NSInteger, mempoolMinimum: NSInteger, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + feeEstimator.update(high: UInt32(high), normal: UInt32(normal), low: UInt32(low), mempoolMinimum: UInt32(mempoolMinimum)) return handleResolve(resolve, .fees_updated) } diff --git a/lib/src/ldk.ts b/lib/src/ldk.ts index 3e9c3475..bfed2ab4 100644 --- a/lib/src/ldk.ts +++ b/lib/src/ldk.ts @@ -304,13 +304,14 @@ class LDK { * @returns {Promise | Ok | Err>>} */ async updateFees(fees: TFeeUpdateReq): Promise> { - const { highPriority, normal, background } = fees; + const { highPriority, normal, background, mempoolMinimum } = fees; try { const satsPerKw = 250; const res = await NativeLDK.updateFees( highPriority * satsPerKw, normal * satsPerKw, background * satsPerKw, + mempoolMinimum * satsPerKw, ); this.writeDebugToLog('updateFees', fees); return ok(res); diff --git a/lib/src/lightning-manager.ts b/lib/src/lightning-manager.ts index 1253e818..9dffc129 100644 --- a/lib/src/lightning-manager.ts +++ b/lib/src/lightning-manager.ts @@ -127,6 +127,7 @@ class LightningManager { highPriority: 15, normal: 10, background: 5, + mempoolMinimum: 1, }); trustedZeroConfPeers: string[] = []; broadcastTransaction: TBroadcastTransaction = async (): Promise => {}; diff --git a/lib/src/utils/types.ts b/lib/src/utils/types.ts index 7d05178a..49833f27 100644 --- a/lib/src/utils/types.ts +++ b/lib/src/utils/types.ts @@ -235,6 +235,7 @@ export type TFeeUpdateReq = { highPriority: number; normal: number; background: number; + mempoolMinimum: number; }; export type TPeer = {