Skip to content

Commit 2363fa8

Browse files
committed
feat: ios updated ldk to 123
1 parent 7c4ee09 commit 2363fa8

File tree

33 files changed

+61549
-43681
lines changed

33 files changed

+61549
-43681
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.145):
319+
- react-native-ldk (0.0.147):
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: 496216796eafbd77c43cd5228342460a242cf7ed
624+
react-native-ldk: 71275a0c18172fa1646bc2a38a62560ded090da5
625625
react-native-randombytes: 421f1c7d48c0af8dbcd471b0324393ebf8fe7846
626626
react-native-tcp-socket: c1b7297619616b4c9caae6889bcb0aba78086989
627627
React-NativeModulesApple: edb5ace14f73f4969df6e7b1f3e41bef0012740f

lib/ios/Classes/CustomKeysManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.spendSpendableOutputs(
44+
let res = self.inner.asOutputSpender().spendSpendableOutputs(
4545
descriptors: onlyNonStatic,
4646
outputs: outputs,
4747
changeDestinationScript: changeDestinationScript,

lib/ios/Classes/LdkChannelManagerPersister.swift

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
2929
LdkEventEmitter.shared.send(
3030
withEvent: .channel_manager_funding_generation_ready,
3131
body: [
32-
"temp_channel_id": Data(fundingGeneration.getTemporaryChannelId()).hexEncodedString(),
32+
"temp_channel_id": Data(fundingGeneration.getTemporaryChannelId().getA() ?? []).hexEncodedString(),
3333
"output_script": Data(fundingGeneration.getOutputScript()).hexEncodedString(),
3434
"user_channel_id": Data(fundingGeneration.getUserChannelId()).hexEncodedString(),
3535
"value_satoshis": fundingGeneration.getChannelValueSatoshis(),
@@ -41,8 +41,8 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
4141
return handleEventError(event)
4242
}
4343

44-
let paymentPreimage = paymentClaimable.getPurpose().getValueAsInvoicePayment()?.getPaymentPreimage()
45-
let paymentSecret = paymentClaimable.getPurpose().getValueAsInvoicePayment()?.getPaymentSecret()
44+
let paymentPreimage = paymentClaimable.getPurpose().getValueAsBolt11InvoicePayment()?.getPaymentPreimage()
45+
let paymentSecret = paymentClaimable.getPurpose().getValueAsBolt11InvoicePayment()?.getPaymentSecret()
4646
let spontaneousPayment = paymentClaimable.getPurpose().getValueAsSpontaneousPayment()
4747

4848
let body: [String: Encodable] = [
@@ -93,7 +93,7 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
9393
LdkEventEmitter.shared.send(
9494
withEvent: .channel_manager_open_channel_request,
9595
body: [
96-
"temp_channel_id": Data(openChannelRequest.getTemporaryChannelId()).hexEncodedString(),
96+
"temp_channel_id": Data(openChannelRequest.getTemporaryChannelId().getA() ?? []).hexEncodedString(),
9797
"counterparty_node_id": Data(openChannelRequest.getCounterpartyNodeId()).hexEncodedString(),
9898
"push_sat": openChannelRequest.getPushMsat() / 1000,
9999
"funding_satoshis": openChannelRequest.getFundingSatoshis(),
@@ -211,8 +211,6 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
211211
switch channelClosed.getReason().getValueType() {
212212
case .CommitmentTxConfirmed:
213213
reasonString = "CommitmentTxConfirmed"
214-
case .CooperativeClosure:
215-
reasonString = "CooperativeClosure"
216214
case .CounterpartyCoopClosedUnfundedChannel:
217215
reasonString = "CounterpartyCoopClosedUnfundedChannel"
218216
case .CounterpartyForceClosed:
@@ -229,15 +227,23 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
229227
reasonString = "OutdatedChannelManager"
230228
case .ProcessingError:
231229
reasonString = "ProcessingError"
232-
default:
230+
case .CounterpartyInitiatedCooperativeClosure:
231+
reasonString = "CounterpartyInitiatedCooperativeClosure"
232+
case .LegacyCooperativeClosure:
233+
reasonString = "LegacyCooperativeClosure"
234+
case .LocallyInitiatedCooperativeClosure:
235+
reasonString = "LocallyInitiatedCooperativeClosure"
236+
case .HTLCsTimedOut:
237+
reasonString = "HTLCsTimedOut"
238+
@unknown default:
233239
reasonString = "Unknown"
234240
}
235241

236242
LdkEventEmitter.shared.send(
237243
withEvent: .channel_manager_channel_closed,
238244
body: [
239245
"user_channel_id": Data(channelClosed.getUserChannelId()).hexEncodedString(),
240-
"channel_id": Data(channelClosed.getChannelId()).hexEncodedString(),
246+
"channel_id": Data(channelClosed.getChannelId().getA() ?? []).hexEncodedString(),
241247
"reason": reasonString
242248
]
243249
)
@@ -252,7 +258,7 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
252258
LdkEventEmitter.shared.send(
253259
withEvent: .channel_manager_discard_funding,
254260
body: [
255-
"channel_id": Data(discardFunding.getChannelId()).hexEncodedString(),
261+
"channel_id": Data(discardFunding.getChannelId().getA() ?? []).hexEncodedString(),
256262
"tx": Data(discardFunding.getTransaction()).hexEncodedString()
257263
]
258264
)
@@ -262,8 +268,8 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
262268
return handleEventError(event)
263269
}
264270

265-
let paymentPreimage = paymentClaimed.getPurpose().getValueAsInvoicePayment()?.getPaymentPreimage()
266-
let paymentSecret = paymentClaimed.getPurpose().getValueAsInvoicePayment()?.getPaymentSecret()
271+
let paymentPreimage = paymentClaimed.getPurpose().getValueAsBolt11InvoicePayment()?.getPaymentPreimage()
272+
let paymentSecret = paymentClaimed.getPurpose().getValueAsBolt11InvoicePayment()?.getPaymentSecret()
267273
let spontaneousPayment = paymentClaimed.getPurpose().getValueAsSpontaneousPayment()
268274

269275
let body: [String: Encodable] = [

lib/ios/Classes/LdkPersist.swift

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

1111
class LdkPersister: Persist {
12-
private func handleChannel(_ channelId: OutPoint, _ data: ChannelMonitor, _ updateId: Bindings.MonitorUpdateId) -> ChannelMonitorUpdateStatus {
13-
let channelIdHex = Data(channelId.toChannelId()).hexEncodedString()
12+
private func handleChannel(_ channelFundingOutpoint: Bindings.OutPoint, _ data: ChannelMonitor, _ updateId: Bindings.MonitorUpdateId) -> ChannelMonitorUpdateStatus {
13+
guard let txId = channelFundingOutpoint.getTxid() else {
14+
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Error. Missing channelFundingOutpoint.getTxid(). Cannot persist channel")
15+
return .UnrecoverableError
16+
}
17+
18+
let channelIdHex = Data(txId).hexEncodedString()
1419
let body = [
1520
"channel_id": channelIdHex,
1621
"counterparty_node_id": Data(data.getCounterpartyNodeId() ?? []).hexEncodedString()
@@ -48,7 +53,7 @@ class LdkPersister: Persist {
4853
}
4954

5055
//Update chainmonitor with successful persist
51-
let res = Ldk.chainMonitor?.channelMonitorUpdated(fundingTxo: channelId, completedUpdateId: updateId)
56+
let res = Ldk.chainMonitor?.channelMonitorUpdated(fundingTxo: channelFundingOutpoint, completedUpdateId: updateId)
5257
if let error = res?.getError() {
5358
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Error. Failed to update chain monitor for channel (\(channelIdHex)) Error \(error.getValueType()).")
5459
} else {
@@ -66,11 +71,11 @@ class LdkPersister: Persist {
6671
}
6772
}
6873

69-
override func persistNewChannel(channelId: Bindings.OutPoint, data: Bindings.ChannelMonitor, updateId: Bindings.MonitorUpdateId) -> Bindings.ChannelMonitorUpdateStatus {
70-
return handleChannel(channelId, data, updateId)
74+
override func persistNewChannel(channelFundingOutpoint: Bindings.OutPoint, data: Bindings.ChannelMonitor, updateId: Bindings.MonitorUpdateId) -> Bindings.ChannelMonitorUpdateStatus {
75+
return handleChannel(channelFundingOutpoint, data, updateId)
7176
}
7277

73-
override func updatePersistedChannel(channelId: Bindings.OutPoint, update: Bindings.ChannelMonitorUpdate, data: Bindings.ChannelMonitor, updateId: Bindings.MonitorUpdateId) -> Bindings.ChannelMonitorUpdateStatus {
74-
return handleChannel(channelId, data, updateId)
78+
override func updatePersistedChannel(channelFundingOutpoint: Bindings.OutPoint, update: Bindings.ChannelMonitorUpdate, data: Bindings.ChannelMonitor, updateId: Bindings.MonitorUpdateId) -> Bindings.ChannelMonitorUpdateStatus {
79+
return handleChannel(channelFundingOutpoint, data, updateId)
7580
}
7681
}

lib/ios/Helpers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ extension ChannelDetails {
114114
let shortChannelId = getShortChannelId() != nil ? String(getShortChannelId()!) : ""
115115

116116
return [
117-
"channel_id": Data(getChannelId() ?? []).hexEncodedString(),
117+
"channel_id": Data(getChannelId().getA() ?? []).hexEncodedString(),
118118
"is_public": getIsPublic(),
119119
"is_usable": getIsUsable(),
120120
"is_channel_ready": getIsChannelReady(),

lib/ios/Ldk.swift

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ class Ldk: NSObject {
507507
currentBlockchainHeight = blockHeight
508508
addForegroundObserver()
509509
startDroppedPeerTimer()
510-
510+
511511
return handleResolve(resolve, .channel_manager_init_success)
512512
}
513513

@@ -659,7 +659,7 @@ class Ldk: NSObject {
659659
guard let self else { return }
660660

661661
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Starting timer to check for dropped peers")
662-
662+
663663
droppedPeerTimer = Timer.scheduledTimer(
664664
timeInterval: 5.0,
665665
target: self,
@@ -698,7 +698,9 @@ class Ldk: NSObject {
698698

699699
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Checking for dropped peers")
700700

701-
let currentList = peerManager.getPeerNodeIds().map { Data($0.0).hexEncodedString() }
701+
let currentList = peerManager
702+
.listPeers()
703+
.map { Data($0.getCounterpartyNodeId()).hexEncodedString() }
702704

703705
addedPeers.forEach { (address, port, pubKey) in
704706
guard !currentList.contains(pubKey) else {
@@ -735,7 +737,10 @@ class Ldk: NSObject {
735737
}
736738

737739
//If peer is already connected don't add again
738-
let currentList = peerManager.getPeerNodeIds().map { Data($0.0).hexEncodedString() }
740+
let currentList = peerManager
741+
.listPeers()
742+
.map { Data($0.getCounterpartyNodeId()).hexEncodedString() }
743+
739744
guard !currentList.contains(String(pubKey)) else {
740745
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Skipping new peer connection, already connected to \(pubKey)")
741746
return handleResolve(resolve, .peer_already_connected)
@@ -818,7 +823,7 @@ class Ldk: NSObject {
818823
return handleReject(reject, .init_channel_manager)
819824
}
820825

821-
let temporaryChannelId = String(temporaryChannelId).hexaBytes
826+
let temporaryChannelId = Bindings.ChannelId.initWith(aArg: String(temporaryChannelId).hexaBytes)
822827
let counterpartyNodeId = String(counterPartyNodeId).hexaBytes
823828

824829
var userChannelId = Data(count: 32)
@@ -860,7 +865,7 @@ class Ldk: NSObject {
860865
return handleReject(reject, .init_channel_manager)
861866
}
862867

863-
let channelId = String(channelId).hexaBytes
868+
let channelId = Bindings.ChannelId.initWith(aArg: String(channelId).hexaBytes)
864869
let counterpartyNodeId = String(counterPartyNodeId).hexaBytes
865870

866871
let res = force ?
@@ -1124,7 +1129,7 @@ class Ldk: NSObject {
11241129
return handleReject(reject, .init_peer_manager)
11251130
}
11261131

1127-
return resolve(peerManager.getPeerNodeIds().map { Data($0.0).hexEncodedString() })
1132+
return resolve(peerManager.listPeers().map { Data($0.getCounterpartyNodeId()).hexEncodedString() })
11281133
}
11291134

11301135
@objc
@@ -1168,7 +1173,10 @@ class Ldk: NSObject {
11681173
return handleReject(reject, .init_storage_path)
11691174
}
11701175

1171-
let excludeChannelIds = ignoreOpenChannels ? channelManager.listChannels().map { Data($0.getChannelId() ?? []).hexEncodedString() }.filter { $0 != "" } : []
1176+
let excludeChannelIds = ignoreOpenChannels ? channelManager
1177+
.listChannels()
1178+
.map { Data($0.getChannelId().getA() ?? []).hexEncodedString() }
1179+
.filter { $0 != "" } : []
11721180

11731181
let channelFiles = try! FileManager.default.contentsOfDirectory(at: channelStoragePath, includingPropertiesForKeys: nil)
11741182

@@ -1391,7 +1399,10 @@ class Ldk: NSObject {
13911399
return handleReject(reject, .init_storage_path)
13921400
}
13931401

1394-
let openChannelIds = channelManager.listChannels().map { Data($0.getChannelId() ?? []).hexEncodedString() }.filter { $0 != "" }
1402+
let openChannelIds = channelManager
1403+
.listChannels()
1404+
.map { Data($0.getChannelId().getA() ?? []).hexEncodedString() }
1405+
.filter { $0 != "" }
13951406

13961407
let channelFiles = try! FileManager.default.contentsOfDirectory(at: channelStoragePath, includingPropertiesForKeys: nil)
13971408

@@ -1500,10 +1511,10 @@ class Ldk: NSObject {
15001511
logDump.append("RGS last sync time unavailable.")
15011512
}
15021513

1503-
if let peers = peerManager?.getPeerNodeIds() {
1514+
if let peers = peerManager?.listPeers() {
15041515
if peers.count > 0 {
1505-
peers.forEach { (pubKey, address) in
1506-
logDump.append("Connected peer: \(Data(pubKey).hexEncodedString())")
1516+
peers.forEach { (peer) in
1517+
logDump.append("Connected peer: \(Data(peer.getCounterpartyNodeId()).hexEncodedString())")
15071518
}
15081519
} else {
15091520
logDump.append("No connected peers")

lib/ios/LightningDevKit.xcframework/Info.plist

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,32 @@
88
<key>DebugSymbolsPath</key>
99
<string>dSYMs</string>
1010
<key>LibraryIdentifier</key>
11-
<string>ios-arm64</string>
11+
<string>ios-arm64_x86_64-simulator</string>
1212
<key>LibraryPath</key>
1313
<string>LightningDevKit.framework</string>
1414
<key>SupportedArchitectures</key>
1515
<array>
1616
<string>arm64</string>
17+
<string>x86_64</string>
1718
</array>
1819
<key>SupportedPlatform</key>
1920
<string>ios</string>
21+
<key>SupportedPlatformVariant</key>
22+
<string>simulator</string>
2023
</dict>
2124
<dict>
2225
<key>DebugSymbolsPath</key>
2326
<string>dSYMs</string>
2427
<key>LibraryIdentifier</key>
25-
<string>ios-arm64_x86_64-simulator</string>
28+
<string>ios-arm64</string>
2629
<key>LibraryPath</key>
2730
<string>LightningDevKit.framework</string>
2831
<key>SupportedArchitectures</key>
2932
<array>
3033
<string>arm64</string>
31-
<string>x86_64</string>
3234
</array>
3335
<key>SupportedPlatform</key>
3436
<string>ios</string>
35-
<key>SupportedPlatformVariant</key>
36-
<string>simulator</string>
3737
</dict>
3838
</array>
3939
<key>CFBundlePackageType</key>

0 commit comments

Comments
 (0)