Skip to content

Commit 84cb376

Browse files
committed
feat: updated ios to ldk 0.0.125
1 parent b102e82 commit 84cb376

File tree

49 files changed

+1373808
-79729
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1373808
-79729
lines changed

example/ios/Podfile.lock

Lines changed: 2 additions & 2 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.154):
319+
- react-native-ldk (0.0.155):
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: 6910154336e57be6702a33acad2191d39a3a214b
624+
react-native-ldk: 9ea2f29a6f96cc55f839ee180caf8dc9e58cd6eb
625625
react-native-randombytes: 421f1c7d48c0af8dbcd471b0324393ebf8fe7846
626626
react-native-tcp-socket: c1b7297619616b4c9caae6889bcb0aba78086989
627627
React-NativeModulesApple: edb5ace14f73f4969df6e7b1f3e41bef0012740f

lib/ios/Classes/BackupClient.swift

Lines changed: 55 additions & 62 deletions
Large diffs are not rendered by default.

lib/ios/Classes/CustomKeysManager.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CustomKeysManager {
2323
self.witnessProgram = witnessProgram
2424
self.witnessProgramVersion = witnessProgramVersion
2525
self.signerProvider = CustomSignerProvider()
26-
self.signerProvider.customKeysManager = self
26+
signerProvider.customKeysManager = self
2727
}
2828

2929
// We drop all occurences of `SpendableOutputDescriptor::StaticOutput` (since they will be
@@ -41,7 +41,7 @@ class CustomKeysManager {
4141

4242
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Spending \(onlyNonStatic.count) non static outputs")
4343

44-
let res = self.inner.asOutputSpender().spendSpendableOutputs(
44+
let res = inner.asOutputSpender().spendSpendableOutputs(
4545
descriptors: onlyNonStatic,
4646
outputs: outputs,
4747
changeDestinationScript: changeDestinationScript,
@@ -63,7 +63,7 @@ class CustomSignerProvider: SignerProvider {
6363
override func getShutdownScriptpubkey() -> Bindings.Result_ShutdownScriptNoneZ {
6464
let res = ShutdownScript.newWitnessProgram(witnessProgram: .init(version: customKeysManager!.witnessProgramVersion, program: customKeysManager!.witnessProgram))
6565
if res.isOk() {
66-
//To record which addresses should be watched for close channel funds
66+
// To record which addresses should be watched for close channel funds
6767
LdkEventEmitter.shared.send(withEvent: .used_close_address, body: customKeysManager!.address)
6868
return Bindings.Result_ShutdownScriptNoneZ.initWithOk(o: res.getValue()!)
6969
}
@@ -76,7 +76,7 @@ class CustomSignerProvider: SignerProvider {
7676
return .initWithErr()
7777
}
7878

79-
override func deriveChannelSigner(channelValueSatoshis: UInt64, channelKeysId: [UInt8]) -> Bindings.WriteableEcdsaChannelSigner {
79+
override func deriveChannelSigner(channelValueSatoshis: UInt64, channelKeysId: [UInt8]) -> Bindings.EcdsaChannelSigner {
8080
return customKeysManager!.inner.asSignerProvider().deriveChannelSigner(
8181
channelValueSatoshis: channelValueSatoshis,
8282
channelKeysId: channelKeysId
@@ -91,7 +91,7 @@ class CustomSignerProvider: SignerProvider {
9191
)
9292
}
9393

94-
override func readChanSigner(reader: [UInt8]) -> Bindings.Result_WriteableEcdsaChannelSignerDecodeErrorZ {
94+
override func readChanSigner(reader: [UInt8]) -> Bindings.Result_EcdsaChannelSignerDecodeErrorZ {
9595
return customKeysManager!.inner.asSignerProvider().readChanSigner(reader: reader)
9696
}
9797
}

lib/ios/Classes/LdkChannelManagerPersister.swift

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ import LightningDevKit
1010

1111
class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
1212
// Custom function to manage any unlikely missing info from the event object
13-
func handleEventError(_ event: Event) {
13+
func handleEventError(_ event: Event) -> Result_NoneReplayEventZ {
1414
LdkEventEmitter.shared.send(
1515
withEvent: .native_log,
1616
body: "Error missing details for handle_event of type \(event.getValueType())"
1717
)
18+
19+
return .initWithErr(e: .init())
1820
}
1921

20-
func handleEvent(event: Event) {
22+
func handleEvent(event: Event) -> Result_NoneReplayEventZ {
2123
// Follows ldk-sample event handling structure
2224
// https://github.com/lightningdevkit/ldk-sample/blob/c0a722430b8fbcb30310d64487a32aae839da3e8/src/main.rs#L600
2325
switch event.getValueType() {
@@ -35,7 +37,7 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
3537
"value_satoshis": fundingGeneration.getChannelValueSatoshis()
3638
]
3739
)
38-
return
40+
return .initWithOk()
3941
case .PaymentClaimable:
4042
guard let paymentClaimable = event.getValueAsPaymentClaimable() else {
4143
return handleEventError(event)
@@ -62,7 +64,7 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
6264

6365
// Save to disk for TX history
6466
persistPaymentClaimed(body)
65-
return
67+
return .initWithOk()
6668
case .PaymentSent:
6769
guard let paymentSent = event.getValueAsPaymentSent() else {
6870
return handleEventError(event)
@@ -84,7 +86,7 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
8486

8587
// Save to disk for tx history
8688
persistPaymentSent(body)
87-
return
89+
return .initWithOk()
8890
case .OpenChannelRequest:
8991
// Use if we ever manually accept inbound channels. Setting in initConfig.
9092
guard let openChannelRequest = event.getValueAsOpenChannelRequest() else {
@@ -102,7 +104,7 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
102104
"requires_anchors_zero_fee_htlc_tx": openChannelRequest.getChannelType().requiresAnchorsZeroFeeHtlcTx()
103105
] as [String: Any]
104106
)
105-
return
107+
return .initWithOk()
106108
case .PaymentPathSuccessful:
107109
guard let paymentPathSuccessful = event.getValueAsPaymentPathSuccessful() else {
108110
return handleEventError(event)
@@ -119,7 +121,7 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
119121
"path_hops": paymentPathSuccessful.getPath().getHops().map { $0.asJson }
120122
] as [String: Any]
121123
)
122-
return
124+
return .initWithOk()
123125
case .PaymentPathFailed:
124126
guard let paymentPathFailed = event.getValueAsPaymentPathFailed() else {
125127
return handleEventError(event)
@@ -147,14 +149,14 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
147149
"state": paymentPathFailed.getPaymentFailedPermanently() ? "failed" : "pending"
148150
]
149151
)
150-
return
152+
return .initWithOk()
151153
case .PaymentFailed:
152154
guard let paymentFailed = event.getValueAsPaymentFailed() else {
153155
return handleEventError(event)
154156
}
155157

156158
let paymentId = Data(paymentFailed.getPaymentId()).hexEncodedString()
157-
let paymentHash = Data(paymentFailed.getPaymentHash()).hexEncodedString()
159+
let paymentHash = Data(paymentFailed.getPaymentHash() ?? []).hexEncodedString()
158160

159161
LdkEventEmitter.shared.send(
160162
withEvent: .channel_manager_payment_failed,
@@ -174,10 +176,10 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
174176
"state": "failed"
175177
]
176178
)
177-
return
179+
return .initWithOk()
178180
case .PaymentForwarded:
179181
// Unused on mobile
180-
return
182+
return .initWithOk()
181183
case .PendingHTLCsForwardable:
182184
guard let pendingHtlcsForwardable = event.getValueAsPendingHtlcsForwardable() else {
183185
return handleEventError(event)
@@ -189,7 +191,7 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
189191
"time_forwardable": pendingHtlcsForwardable.getTimeForwardable()
190192
]
191193
)
192-
return
194+
return .initWithOk()
193195
case .SpendableOutputs:
194196
guard let spendableOutputs = event.getValueAsSpendableOutputs() else {
195197
return handleEventError(event)
@@ -201,7 +203,7 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
201203
"outputsSerialized": spendableOutputs.getOutputs().map { Data($0.write()).hexEncodedString() }
202204
]
203205
)
204-
return
206+
return .initWithOk()
205207
case .ChannelClosed:
206208
guard let channelClosed = event.getValueAsChannelClosed() else {
207209
return handleEventError(event)
@@ -252,7 +254,7 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
252254
]
253255
)
254256

255-
return
257+
return .initWithOk()
256258
case .DiscardFunding:
257259
guard let discardFunding = event.getValueAsDiscardFunding() else {
258260
return handleEventError(event)
@@ -263,10 +265,10 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
263265
withEvent: .channel_manager_discard_funding,
264266
body: [
265267
"channel_id": Data(discardFunding.getChannelId().getA() ?? []).hexEncodedString(),
266-
"tx": Data(discardFunding.getTransaction()).hexEncodedString()
268+
"tx": Data(discardFunding.getChannelId().getA() ?? []).hexEncodedString()
267269
]
268270
)
269-
return
271+
return .initWithOk()
270272
case .PaymentClaimed:
271273
guard let paymentClaimed = event.getValueAsPaymentClaimed() else {
272274
return handleEventError(event)
@@ -293,13 +295,13 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
293295

294296
// Save to disk for TX history
295297
persistPaymentClaimed(body)
296-
return
298+
return .initWithOk()
297299
case .ChannelReady:
298300
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Unused Persister event: ChannelReady")
299-
return
301+
return .initWithOk()
300302
case .ChannelPending:
301303
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Unused Persister event: ChannelPending")
302-
return
304+
return .initWithOk()
303305
case .BumpTransaction:
304306
guard let bumpTransaction = event.getValueAsBumpTransaction() else {
305307
return handleEventError(event)
@@ -315,29 +317,38 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
315317
]
316318

317319
LdkEventEmitter.shared.send(withEvent: .lsp_log, body: body)
318-
return
320+
return .initWithOk()
319321
}
320322

321323
LdkEventEmitter.shared.send(withEvent: .native_log, body: "BumpTransaction event not handled")
322-
return
324+
return .initWithOk()
323325
case .ProbeFailed:
324326
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Unused Persister event: ProbeFailed")
325-
return
327+
return .initWithOk()
326328
case .ProbeSuccessful:
327329
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Unused Persister event: ProbeSuccessful")
328-
return
329-
case .InvoiceRequestFailed:
330-
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Unused Persister event: InvoiceRequestFailed")
331-
return
330+
return .initWithOk()
332331
case .HTLCIntercepted:
333332
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Unused Persister event: HTLCIntercepted")
334-
return
333+
return .initWithOk()
335334
case .HTLCHandlingFailed:
336335
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Unused Persister event: HTLCHandlingFailed")
337-
return
336+
return .initWithOk()
338337
case .ConnectionNeeded:
339338
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Unused Persister event: ConnectionNeeded")
340-
return
339+
return .initWithOk()
340+
case .FundingTxBroadcastSafe:
341+
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Unused Persister event: FundingTxBroadcastSafe")
342+
return .initWithOk()
343+
case .InvoiceReceived:
344+
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Unused Persister event: InvoiceReceived")
345+
return .initWithOk()
346+
case .OnionMessageIntercepted:
347+
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Unused Persister event: OnionMessageIntercepted")
348+
return .initWithOk()
349+
case .OnionMessagePeerConnected:
350+
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Unused Persister event: OnionMessagePeerConnected")
351+
return .initWithOk()
341352
}
342353
}
343354

lib/ios/Classes/LdkFeeEstimator.swift

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,29 @@ class LdkFeeEstimator: FeeEstimator {
1616
private var onChainSweep: UInt32 = 0
1717
private var minAllowedNonAnchorChannelRemoteFee: UInt32 = 0
1818
private var outputSpendingFee: UInt32 = 0
19+
private var maximumFeeEstimate: UInt32 = 0
20+
private var urgentOnChainSweep: UInt32 = 0
1921

20-
func update(anchorChannelFee: UInt32, nonAnchorChannelFee: UInt32, channelCloseMinimum: UInt32, minAllowedAnchorChannelRemoteFee: UInt32, onChainSweep: UInt32, minAllowedNonAnchorChannelRemoteFee: UInt32, outputSpendingFee: UInt32) {
22+
func update(
23+
anchorChannelFee: UInt32,
24+
nonAnchorChannelFee: UInt32,
25+
channelCloseMinimum: UInt32,
26+
minAllowedAnchorChannelRemoteFee: UInt32,
27+
onChainSweep: UInt32,
28+
minAllowedNonAnchorChannelRemoteFee: UInt32,
29+
outputSpendingFee: UInt32,
30+
maximumFeeEstimate: UInt32,
31+
urgentOnChainSweep: UInt32
32+
) {
2133
self.anchorChannelFee = anchorChannelFee
2234
self.nonAnchorChannelFee = nonAnchorChannelFee
2335
self.channelCloseMinimum = channelCloseMinimum
2436
self.minAllowedAnchorChannelRemoteFee = minAllowedAnchorChannelRemoteFee
2537
self.onChainSweep = onChainSweep
2638
self.minAllowedNonAnchorChannelRemoteFee = minAllowedNonAnchorChannelRemoteFee
2739
self.outputSpendingFee = outputSpendingFee
40+
self.maximumFeeEstimate = maximumFeeEstimate
41+
self.urgentOnChainSweep = urgentOnChainSweep
2842

2943
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Fee estimator updated")
3044
}
@@ -41,12 +55,14 @@ class LdkFeeEstimator: FeeEstimator {
4155
return channelCloseMinimum
4256
case .MinAllowedAnchorChannelRemoteFee:
4357
return minAllowedAnchorChannelRemoteFee
44-
case .OnChainSweep:
45-
return onChainSweep
4658
case .MinAllowedNonAnchorChannelRemoteFee:
4759
return minAllowedNonAnchorChannelRemoteFee
4860
case .OutputSpendingFee:
4961
return outputSpendingFee
62+
case .MaximumFeeEstimate:
63+
return maximumFeeEstimate
64+
case .UrgentOnChainSweep:
65+
return urgentOnChainSweep
5066
}
5167
}
5268
}

lib/ios/Classes/LdkPersist.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99
import LightningDevKit
1010

1111
class LdkPersister: Persist {
12-
private func handleChannel(_ channelFundingOutpoint: Bindings.OutPoint, _ data: ChannelMonitor, _ updateId: Bindings.MonitorUpdateId) -> ChannelMonitorUpdateStatus {
12+
private func handleChannel(_ channelFundingOutpoint: Bindings.OutPoint, _ data: ChannelMonitor) -> ChannelMonitorUpdateStatus {
1313
guard let channelId = data.channelId().getA() else {
1414
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Error. Missing channelFundingOutpoint.getTxid(). Cannot persist channel")
1515
return .UnrecoverableError
@@ -28,7 +28,7 @@ class LdkPersister: Persist {
2828

2929
let isNew = !FileManager().fileExists(atPath: channelStoragePath.path)
3030

31-
//If we're not remotely backing up no need to update status later
31+
// If we're not remotely backing up no need to update status later
3232
if BackupClient.skipRemoteBackup {
3333
try Data(data.write()).write(to: channelStoragePath)
3434
if isNew {
@@ -43,21 +43,21 @@ class LdkPersister: Persist {
4343
return
4444
}
4545

46-
//Callback for when the persist queue queue entry is processed
46+
// Callback for when the persist queue queue entry is processed
4747
do {
4848
try Data(data.write()).write(to: channelStoragePath)
4949
} catch {
50-
//If this fails we can't do much but LDK will retry on startup
50+
// If this fails we can't do much but LDK will retry on startup
5151
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Error. Failed to locally persist channel (\(channelIdHex)). \(error.localizedDescription)")
5252
return
5353
}
5454

55-
//Update chainmonitor with successful persist
56-
let res = Ldk.chainMonitor?.channelMonitorUpdated(fundingTxo: channelFundingOutpoint, completedUpdateId: updateId)
55+
// Update chainmonitor with successful persist
56+
let res = Ldk.chainMonitor?.channelMonitorUpdated(fundingTxo: channelFundingOutpoint, completedUpdateId: data.getLatestUpdateId())
5757
if let error = res?.getError() {
5858
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Error. Failed to update chain monitor for channel (\(channelIdHex)) Error \(error.getValueType()).")
5959
} else {
60-
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Persisted channel \(channelIdHex). Update ID: \(updateId.hash())")
60+
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Persisted channel \(channelIdHex). Update ID: \(data.getLatestUpdateId())")
6161
if isNew {
6262
LdkEventEmitter.shared.send(withEvent: .new_channel, body: body)
6363
}
@@ -70,12 +70,12 @@ class LdkPersister: Persist {
7070
return ChannelMonitorUpdateStatus.UnrecoverableError
7171
}
7272
}
73-
74-
override func persistNewChannel(channelFundingOutpoint: Bindings.OutPoint, data: Bindings.ChannelMonitor, updateId: Bindings.MonitorUpdateId) -> Bindings.ChannelMonitorUpdateStatus {
75-
return handleChannel(channelFundingOutpoint, data, updateId)
73+
74+
override func persistNewChannel(channelFundingOutpoint: Bindings.OutPoint, monitor: Bindings.ChannelMonitor) -> Bindings.ChannelMonitorUpdateStatus {
75+
return handleChannel(channelFundingOutpoint, monitor)
7676
}
7777

78-
override func updatePersistedChannel(channelFundingOutpoint: Bindings.OutPoint, update: Bindings.ChannelMonitorUpdate, data: Bindings.ChannelMonitor, updateId: Bindings.MonitorUpdateId) -> Bindings.ChannelMonitorUpdateStatus {
79-
return handleChannel(channelFundingOutpoint, data, updateId)
78+
override func updatePersistedChannel(channelFundingOutpoint: Bindings.OutPoint, monitorUpdate: Bindings.ChannelMonitorUpdate, monitor: Bindings.ChannelMonitor) -> Bindings.ChannelMonitorUpdateStatus {
79+
return handleChannel(channelFundingOutpoint, monitor)
8080
}
8181
}

0 commit comments

Comments
 (0)