Skip to content
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

fix: new fee type (mempoolMinimum) #168

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions lib/android/src/main/java/com/reactnativeldk/LdkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}
Expand Down
14 changes: 11 additions & 3 deletions lib/ios/Classes/LdkFeeEstimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand All @@ -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
}
}
1 change: 1 addition & 0 deletions lib/ios/Ldk.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/ios/Ldk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion lib/src/ldk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,14 @@ class LDK {
* @returns {Promise<Err<unknown> | Ok<Ok<string> | Err<string>>>}
*/
async updateFees(fees: TFeeUpdateReq): Promise<Result<string>> {
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);
Expand Down
1 change: 1 addition & 0 deletions lib/src/lightning-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
highPriority: 15,
normal: 10,
background: 5,
mempoolMinimum: 1,
});
trustedZeroConfPeers: string[] = [];
broadcastTransaction: TBroadcastTransaction = async (): Promise<any> => {};
Expand Down Expand Up @@ -1703,7 +1704,7 @@
}

private onChannelManagerPendingHtlcsForwardable(
res: TChannelManagerPendingHtlcsForwardable,

Check warning on line 1707 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / Run lint check

'res' is defined but never used. Allowed unused args must match /^_/u
): void {
ldk.processPendingHtlcForwards().catch(console.error);
}
Expand Down
1 change: 1 addition & 0 deletions lib/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export type TFeeUpdateReq = {
highPriority: number;
normal: number;
background: number;
mempoolMinimum: number;
};

export type TPeer = {
Expand Down
Loading