Skip to content

Commit 7c5bad8

Browse files
authored
Merge pull request #275 from synonymdev/new-fee
fix: handle output spending fee
2 parents 452c098 + 4201c97 commit 7c5bad8

File tree

13 files changed

+30
-20
lines changed

13 files changed

+30
-20
lines changed

example/ios/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ PODS:
316316
- React-jsinspector (0.72.4)
317317
- React-logger (0.72.4):
318318
- glog
319-
- react-native-ldk (0.0.151):
319+
- react-native-ldk (0.0.152):
320320
- React
321321
- react-native-randombytes (3.6.1):
322322
- React-Core
@@ -621,7 +621,7 @@ SPEC CHECKSUMS:
621621
React-jsiexecutor: c7f826e40fa9cab5d37cab6130b1af237332b594
622622
React-jsinspector: aaed4cf551c4a1c98092436518c2d267b13a673f
623623
React-logger: da1ebe05ae06eb6db4b162202faeafac4b435e77
624-
react-native-ldk: a7e71785237dd3d12dc52b4287abd88c865f5262
624+
react-native-ldk: 1d25080cfadac349eab355725da66de140fbc7a8
625625
react-native-randombytes: 421f1c7d48c0af8dbcd471b0324393ebf8fe7846
626626
react-native-tcp-socket: c1b7297619616b4c9caae6889bcb0aba78086989
627627
React-NativeModulesApple: edb5ace14f73f4969df6e7b1f3e41bef0012740f
@@ -650,4 +650,4 @@ SPEC CHECKSUMS:
650650

651651
PODFILE CHECKSUM: 940323d07de591a59a2ab39fc0ef7b7d6dc89c0d
652652

653-
COCOAPODS: 1.15.2
653+
COCOAPODS: 1.16.2

example/ldk/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export const setupLdk = async (
134134
maxAllowedNonAnchorChannelRemoteFee: 10,
135135
onChainSweep: 10,
136136
minAllowedNonAnchorChannelRemoteFee: 10,
137+
outputSpendingFee: 10,
137138
}),
138139
getTransactionData,
139140
getTransactionPosition,

example/tests/eclair.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ describe('Eclair', function () {
112112
anchorChannelFee: 10,
113113
nonAnchorChannelFee: 20,
114114
channelCloseMinimum: 5,
115+
outputSpendingFee: 10,
115116
});
116117
},
117118
});

example/tests/unit.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ describe('Unit', function () {
7171
minAllowedAnchorChannelRemoteFee: 5,
7272
minAllowedNonAnchorChannelRemoteFee: 5,
7373
onChainSweep: 5,
74+
outputSpendingFee: 5,
7475
});
7576
},
7677
getTransactionData: async () => ({
@@ -214,6 +215,7 @@ describe('Unit', function () {
214215
minAllowedAnchorChannelRemoteFee: 5,
215216
minAllowedNonAnchorChannelRemoteFee: 5,
216217
onChainSweep: 5,
218+
outputSpendingFee: 5,
217219
});
218220
},
219221
getTransactionData: async () => ({

example/tests/utils/test-profile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export default class TestProfile {
8282
anchorChannelFee: 2,
8383
nonAnchorChannelFee: 3,
8484
channelCloseMinimum: 1,
85+
outputSpendingFee: 5,
8586
}),
8687
getTransactionData: this.getTransactionData,
8788
getTransactionPosition: this.getTransactionPosition,

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.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ @interface RCT_EXTERN_MODULE(Ldk, NSObject)
5151
minAllowedAnchorChannelRemoteFee:(NSInteger *)minAllowedAnchorChannelRemoteFee
5252
onChainSweep:(NSInteger *)onChainSweep
5353
minAllowedNonAnchorChannelRemoteFee:(NSInteger *)minAllowedNonAnchorChannelRemoteFee
54+
outputSpendingFee:(NSInteger *)outputSpendingFee
5455
resolve:(RCTPromiseResolveBlock)resolve
5556
reject:(RCTPromiseRejectBlock)reject)
5657
RCT_EXTERN_METHOD(setLogLevel:(NSString *)level

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
}

0 commit comments

Comments
 (0)