Skip to content

Commit 4766519

Browse files
committed
fix: handle output spending fee
1 parent 452c098 commit 4766519

File tree

7 files changed

+21
-16
lines changed

7 files changed

+21
-16
lines changed

lib/android/src/main/java/com/reactnativeldk/LdkModule.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,8 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
592592
//MARK: Update methods
593593

594594
@ReactMethod
595-
fun updateFees(anchorChannelFee: Double, nonAnchorChannelFee: Double, channelCloseMinimum: Double, minAllowedAnchorChannelRemoteFee: Double, onChainSweep: Double, minAllowedNonAnchorChannelRemoteFee: Double, promise: Promise) {
596-
feeEstimator.update(anchorChannelFee.toInt(), nonAnchorChannelFee.toInt(), channelCloseMinimum.toInt(), minAllowedAnchorChannelRemoteFee.toInt(), onChainSweep.toInt(), minAllowedNonAnchorChannelRemoteFee.toInt())
595+
fun updateFees(anchorChannelFee: Double, nonAnchorChannelFee: Double, channelCloseMinimum: Double, minAllowedAnchorChannelRemoteFee: Double, onChainSweep: Double, minAllowedNonAnchorChannelRemoteFee: Double, outputSpendingFee: Double, promise: Promise) {
596+
feeEstimator.update(anchorChannelFee.toInt(), nonAnchorChannelFee.toInt(), channelCloseMinimum.toInt(), minAllowedAnchorChannelRemoteFee.toInt(), onChainSweep.toInt(), minAllowedNonAnchorChannelRemoteFee.toInt(), outputSpendingFee.toInt())
597597
handleResolve(promise, LdkCallbackResponses.fees_updated)
598598
}
599599

lib/android/src/main/java/com/reactnativeldk/classes/LdkFeeEstimator.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ class LdkFeeEstimator {
1111
var minAllowedAnchorChannelRemoteFee: Int = 0
1212
var onChainSweep: Int = 0
1313
var minAllowedNonAnchorChannelRemoteFee: Int = 0
14+
var outputSpendingFee: Int = 0
1415

15-
fun update(anchorChannelFee: Int, nonAnchorChannelFee: Int, channelCloseMinimum: Int, minAllowedAnchorChannelRemoteFee: Int, onChainSweep: Int, minAllowedNonAnchorChannelRemoteFee: Int) {
16+
fun update(anchorChannelFee: Int, nonAnchorChannelFee: Int, channelCloseMinimum: Int, minAllowedAnchorChannelRemoteFee: Int, onChainSweep: Int, minAllowedNonAnchorChannelRemoteFee: Int, outputSpendingFee: Int) {
1617
this.anchorChannelFee = anchorChannelFee
1718
this.nonAnchorChannelFee = nonAnchorChannelFee
1819
this.channelCloseMinimum = channelCloseMinimum
1920
this.minAllowedAnchorChannelRemoteFee = minAllowedAnchorChannelRemoteFee
2021
this.onChainSweep = onChainSweep
2122
this.minAllowedNonAnchorChannelRemoteFee = minAllowedNonAnchorChannelRemoteFee
23+
this.outputSpendingFee = outputSpendingFee
2224

2325
LdkEventEmitter.send(EventTypes.native_log, "Fee estimator updated")
2426
}
@@ -31,10 +33,7 @@ class LdkFeeEstimator {
3133
ConfirmationTarget.LDKConfirmationTarget_MinAllowedAnchorChannelRemoteFee -> minAllowedAnchorChannelRemoteFee
3234
ConfirmationTarget.LDKConfirmationTarget_OnChainSweep -> onChainSweep
3335
ConfirmationTarget.LDKConfirmationTarget_MinAllowedNonAnchorChannelRemoteFee -> minAllowedNonAnchorChannelRemoteFee
34-
else -> {
35-
LdkEventEmitter.send(EventTypes.native_log, "ERROR: New ConfirmationTarget added. Update LdkFeeEstimator.")
36-
return@new_impl 0
37-
}
36+
ConfirmationTarget.LDKConfirmationTarget_OutputSpendingFee -> outputSpendingFee
3837
}
3938
}
4039
}

lib/ios/Classes/LdkFeeEstimator.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,23 @@ class LdkFeeEstimator: FeeEstimator {
1515
private var minAllowedAnchorChannelRemoteFee: UInt32 = 0
1616
private var onChainSweep: UInt32 = 0
1717
private var minAllowedNonAnchorChannelRemoteFee: UInt32 = 0
18-
19-
func update(anchorChannelFee: UInt32, nonAnchorChannelFee: UInt32, channelCloseMinimum: UInt32, minAllowedAnchorChannelRemoteFee: UInt32, onChainSweep: UInt32, minAllowedNonAnchorChannelRemoteFee: UInt32) {
18+
private var outputSpendingFee: UInt32 = 0
19+
20+
func update(anchorChannelFee: UInt32, nonAnchorChannelFee: UInt32, channelCloseMinimum: UInt32, minAllowedAnchorChannelRemoteFee: UInt32, onChainSweep: UInt32, minAllowedNonAnchorChannelRemoteFee: UInt32, outputSpendingFee: UInt32) {
2021
self.anchorChannelFee = anchorChannelFee
2122
self.nonAnchorChannelFee = nonAnchorChannelFee
2223
self.channelCloseMinimum = channelCloseMinimum
2324
self.minAllowedAnchorChannelRemoteFee = minAllowedAnchorChannelRemoteFee
2425
self.onChainSweep = onChainSweep
2526
self.minAllowedNonAnchorChannelRemoteFee = minAllowedNonAnchorChannelRemoteFee
27+
self.outputSpendingFee = outputSpendingFee
2628

2729
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Fee estimator updated")
2830
}
29-
31+
3032
override func getEstSatPer1000Weight(confirmationTarget: Bindings.ConfirmationTarget) -> UInt32 {
3133
let target = confirmationTarget
32-
34+
3335
switch target {
3436
case .AnchorChannelFee:
3537
return anchorChannelFee
@@ -43,9 +45,8 @@ class LdkFeeEstimator: FeeEstimator {
4345
return onChainSweep
4446
case .MinAllowedNonAnchorChannelRemoteFee:
4547
return minAllowedNonAnchorChannelRemoteFee
46-
@unknown default:
47-
LdkEventEmitter.shared.send(withEvent: .native_log, body: "ERROR: New ConfirmationTarget added. Update LdkFeeEstimator.")
48-
return 0
48+
case .OutputSpendingFee:
49+
return outputSpendingFee
4950
}
5051
}
5152
}

lib/ios/Ldk.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,14 +618,15 @@ class Ldk: NSObject {
618618
// MARK: Update methods
619619

620620
@objc
621-
func updateFees(_ anchorChannelFee: NSInteger, nonAnchorChannelFee: NSInteger, channelCloseMinimum: NSInteger, minAllowedAnchorChannelRemoteFee: NSInteger, onChainSweep: NSInteger, minAllowedNonAnchorChannelRemoteFee: NSInteger, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
621+
func updateFees(_ anchorChannelFee: NSInteger, nonAnchorChannelFee: NSInteger, channelCloseMinimum: NSInteger, minAllowedAnchorChannelRemoteFee: NSInteger, onChainSweep: NSInteger, minAllowedNonAnchorChannelRemoteFee: NSInteger, outputSpendingFee: NSInteger, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
622622
feeEstimator.update(
623623
anchorChannelFee: UInt32(anchorChannelFee),
624624
nonAnchorChannelFee: UInt32(nonAnchorChannelFee),
625625
channelCloseMinimum: UInt32(channelCloseMinimum),
626626
minAllowedAnchorChannelRemoteFee: UInt32(minAllowedAnchorChannelRemoteFee),
627627
onChainSweep: UInt32(onChainSweep),
628-
minAllowedNonAnchorChannelRemoteFee: UInt32(minAllowedNonAnchorChannelRemoteFee)
628+
minAllowedNonAnchorChannelRemoteFee: UInt32(minAllowedNonAnchorChannelRemoteFee),
629+
outputSpendingFee: UInt32(outputSpendingFee)
629630
)
630631
return handleResolve(resolve, .fees_updated)
631632
}

lib/src/ldk.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ class LDK {
346346
minAllowedAnchorChannelRemoteFee,
347347
onChainSweep,
348348
minAllowedNonAnchorChannelRemoteFee,
349+
outputSpendingFee,
349350
} = fees;
350351
try {
351352
const satsPerKw = 250;
@@ -356,6 +357,7 @@ class LDK {
356357
minAllowedAnchorChannelRemoteFee * satsPerKw,
357358
onChainSweep * satsPerKw,
358359
minAllowedNonAnchorChannelRemoteFee * satsPerKw,
360+
outputSpendingFee * satsPerKw,
359361
);
360362
this.writeDebugToLog('updateFees', fees);
361363
return ok(res);

lib/src/lightning-manager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class LightningManager {
140140
minAllowedAnchorChannelRemoteFee: 5,
141141
minAllowedNonAnchorChannelRemoteFee: 5,
142142
onChainSweep: 5,
143+
outputSpendingFee: 5,
143144
});
144145
broadcastTransaction: TBroadcastTransaction = async (): Promise<any> => {};
145146
lspLogEvent: TLspLogEvent | undefined;

lib/src/utils/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ export type TFeeUpdateReq = {
252252
minAllowedAnchorChannelRemoteFee: number;
253253
onChainSweep: number;
254254
minAllowedNonAnchorChannelRemoteFee: number;
255+
outputSpendingFee: number;
255256
};
256257

257258
export type TPeer = {

0 commit comments

Comments
 (0)