Skip to content

Commit 885ed8a

Browse files
authored
Merge pull request #261 from synonymdev/ldk-123
LDK 123
2 parents b3718c7 + 36be24a commit 885ed8a

File tree

38 files changed

+61588
-43713
lines changed

38 files changed

+61588
-43713
lines changed

lib/android/libs/LDK-release.aar

1.38 MB
Binary file not shown.
124 KB
Binary file not shown.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ val ChannelDetails.asJson: WritableMap
115115
get() {
116116
val result = Arguments.createMap()
117117

118-
result.putHexString("channel_id", _channel_id)
118+
result.putHexString("channel_id", _channel_id._a)
119119
result.putBoolean("is_public", _is_public)
120120
result.putBoolean("is_usable", _is_usable)
121121
result.putBoolean("is_channel_ready", _is_channel_ready)
@@ -205,7 +205,7 @@ fun ChannelMonitor.asJson(channelId: String): WritableMap {
205205
val result = Arguments.createMap()
206206
result.putString("channel_id", channelId)
207207
result.putInt("funding_txo_index", _funding_txo._a._index.toInt())
208-
result.putHexString("funding_txo_txid", _funding_txo._a.to_channel_id().reversedArray())
208+
result.putHexString("funding_txo_txid", _funding_txo._a._txid.reversedArray())
209209
result.putHexString("counterparty_node_id", _counterparty_node_id)
210210

211211
val balances = Arguments.createArray()

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -622,14 +622,14 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
622622

623623
LdkEventEmitter.send(EventTypes.native_log, "Checking for dropped peers")
624624

625-
val currentlyConnected = peerManager!!._peer_node_ids
625+
val currentlyConnected = peerManager!!.list_peers().map { it._counterparty_node_id.hexEncodedString() }
626626

627627
addedPeers.forEach { peer ->
628628
val pubKey = peer["pubKey"] as String
629629
val address = peer["address"] as String
630630
val port = peer["port"] as Double
631631

632-
if (currentlyConnected.map { it._a.hexEncodedString() }.contains(pubKey)) {
632+
if (currentlyConnected.contains(pubKey)) {
633633
return
634634
}
635635

@@ -654,8 +654,8 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
654654
peerHandler ?: return handleReject(promise, LdkErrors.init_peer_handler)
655655

656656
//If peer is already connected don't add again
657-
val currentList = peerManager!!._peer_node_ids
658-
if (currentList.map { it._a.hexEncodedString() }.contains(pubKey)) {
657+
val currentList = peerManager!!.list_peers().map { it._counterparty_node_id.hexEncodedString() }
658+
if (currentList.contains(pubKey)) {
659659
return handleResolve(promise, LdkCallbackResponses.peer_already_connected)
660660
}
661661

@@ -724,7 +724,7 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
724724
fun acceptChannel(temporaryChannelId: String, counterPartyNodeId: String, trustedPeer0Conf: Boolean, promise: Promise) {
725725
channelManager ?: return handleReject(promise, LdkErrors.init_channel_manager)
726726

727-
val temporaryChannelId = temporaryChannelId.hexa()
727+
val temporaryChannelId = ChannelId.of(temporaryChannelId.hexa())
728728
val counterPartyNodeId = counterPartyNodeId.hexa()
729729
val userChannelIdBytes = ByteArray(16)
730730
Random().nextBytes(userChannelIdBytes)
@@ -755,7 +755,8 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
755755
fun closeChannel(channelId: String, counterpartyNodeId: String, force: Boolean, promise: Promise) {
756756
channelManager ?: return handleReject(promise, LdkErrors.init_channel_manager)
757757

758-
val res = if (force) channelManager!!.force_close_broadcasting_latest_txn(channelId.hexa(), counterpartyNodeId.hexa()) else channelManager!!.close_channel(channelId.hexa(), counterpartyNodeId.hexa())
758+
val channelIdObj = ChannelId.of(channelId.hexa())
759+
val res = if (force) channelManager!!.force_close_broadcasting_latest_txn(channelIdObj, counterpartyNodeId.hexa()) else channelManager!!.close_channel(channelIdObj, counterpartyNodeId.hexa())
759760
if (!res.is_ok) {
760761
return handleReject(promise, LdkErrors.channel_close_fail)
761762
}
@@ -981,9 +982,9 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
981982
peerManager ?: return handleReject(promise, LdkErrors.init_peer_manager)
982983

983984
val res = Arguments.createArray()
984-
val list = peerManager!!._peer_node_ids
985+
val list = peerManager!!.list_peers()
985986
list.iterator().forEach {
986-
res.pushString(it._a.hexEncodedString())
987+
res.pushString(it._counterparty_node_id.hexEncodedString())
987988
}
988989

989990
promise.resolve(res)
@@ -1034,7 +1035,7 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
10341035
}
10351036

10361037
val ignoredChannels = if (ignoreOpenChannels)
1037-
channelManager.list_channels().map { it._channel_id.hexEncodedString() }.toTypedArray() else
1038+
channelManager.list_channels().map { it._channel_id._a.hexEncodedString() }.toTypedArray() else
10381039
arrayOf()
10391040

10401041
val channelFiles = File(channelStoragePath).listFiles()
@@ -1241,7 +1242,7 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
12411242
return handleReject(promise, LdkErrors.init_keys_manager)
12421243
}
12431244

1244-
val openChannelIds = channelManager!!.list_channels().map { it._channel_id.hexEncodedString() }
1245+
val openChannelIds = channelManager!!.list_channels().map { it._channel_id._a.hexEncodedString() }
12451246

12461247
//Get list of files in this path
12471248
val channelFiles = File(channelStoragePath).listFiles()
@@ -1271,7 +1272,7 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
12711272
}
12721273

12731274
val res = if (useInner) {
1274-
keysManager!!.inner.spend_spendable_outputs(
1275+
keysManager!!.inner.as_OutputSpender().spend_spendable_outputs(
12751276
descriptors,
12761277
emptyArray(),
12771278
changeDestinationScript.hexa(),
@@ -1354,10 +1355,10 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
13541355
logDump.add("RGS last sync time unavailable.")
13551356
}
13561357

1357-
peerManager?._peer_node_ids?.let { peers ->
1358+
peerManager?.list_peers()?.let { peers ->
13581359
if (peers.isNotEmpty()) {
13591360
peers.forEach { peer ->
1360-
logDump.add("Connected peer: ${peer._a.hexEncodedString()}")
1361+
logDump.add("Connected peer: ${peer._counterparty_node_id.hexEncodedString()}")
13611362
}
13621363
} else {
13631364
logDump.add("No connected peers")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class CustomKeysManager(
4747

4848
LdkEventEmitter.send(EventTypes.native_log, "Spending ${onlyNonStatic.count()} non static outputs")
4949

50-
return inner.spend_spendable_outputs(
50+
return inner.as_OutputSpender().spend_spendable_outputs(
5151
onlyNonStatic,
5252
outputs,
5353
changeDestinationScript,

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class LdkChannelManagerPersister: ChannelManagerConstructor.EventHandler {
1818
override fun handle_event(event: Event) {
1919
(event as? Event.FundingGenerationReady)?.let { fundingGenerationReady ->
2020
val body = Arguments.createMap()
21-
body.putHexString("temp_channel_id", fundingGenerationReady.temporary_channel_id)
21+
body.putHexString("temp_channel_id", fundingGenerationReady.temporary_channel_id._a)
2222
body.putHexString("output_script", fundingGenerationReady.output_script)
2323
body.putString("user_channel_id", fundingGenerationReady.user_channel_id.leBytes.hexEncodedString())
2424
body.putInt("value_satoshis", fundingGenerationReady.channel_value_satoshis.toInt())
@@ -29,7 +29,7 @@ class LdkChannelManagerPersister: ChannelManagerConstructor.EventHandler {
2929
val body = Arguments.createMap()
3030
body.putHexString("payment_hash", paymentClaimable.payment_hash)
3131
body.putInt("amount_sat", paymentClaimable.amount_msat.toInt() / 1000)
32-
(paymentClaimable.purpose as? PaymentPurpose.InvoicePayment)?.let {
32+
(paymentClaimable.purpose as? PaymentPurpose.Bolt11InvoicePayment)?.let {
3333
body.putHexString("payment_preimage", (it.payment_preimage as Option_ThirtyTwoBytesZ.Some).some)
3434
body.putHexString("payment_secret", it.payment_secret)
3535
}
@@ -60,7 +60,7 @@ class LdkChannelManagerPersister: ChannelManagerConstructor.EventHandler {
6060
(event as? Event.OpenChannelRequest)?.let { openChannelRequest ->
6161
//Use if we ever manually accept inbound channels. Setting in initConfig.
6262
val body = Arguments.createMap()
63-
body.putHexString("temp_channel_id", openChannelRequest.temporary_channel_id)
63+
body.putHexString("temp_channel_id", openChannelRequest.temporary_channel_id._a)
6464
body.putHexString("counterparty_node_id", openChannelRequest.counterparty_node_id)
6565
body.putInt("push_sat", openChannelRequest.push_msat.toInt() / 1000)
6666
body.putInt("funding_satoshis", openChannelRequest.funding_satoshis.toInt())
@@ -143,10 +143,9 @@ class LdkChannelManagerPersister: ChannelManagerConstructor.EventHandler {
143143
(event as? Event.ChannelClosed)?.let { channelClosed ->
144144
val body = Arguments.createMap()
145145
body.putString("user_channel_id", channelClosed.user_channel_id.leBytes.hexEncodedString())
146-
body.putHexString("channel_id", channelClosed.channel_id)
146+
body.putHexString("channel_id", channelClosed.channel_id._a)
147147
val reasonString = when (channelClosed.reason) {
148148
is ClosureReason.CommitmentTxConfirmed -> "CommitmentTxConfirmed"
149-
is ClosureReason.CooperativeClosure -> "CooperativeClosure"
150149
is ClosureReason.CounterpartyCoopClosedUnfundedChannel -> "CounterpartyCoopClosedUnfundedChannel"
151150
is ClosureReason.CounterpartyForceClosed -> "CounterpartyForceClosed"
152151
is ClosureReason.DisconnectedPeer -> "DisconnectedPeer"
@@ -155,6 +154,10 @@ class LdkChannelManagerPersister: ChannelManagerConstructor.EventHandler {
155154
is ClosureReason.HolderForceClosed -> "HolderForceClosed"
156155
is ClosureReason.OutdatedChannelManager -> "OutdatedChannelManager"
157156
is ClosureReason.ProcessingError -> "ProcessingError"
157+
is ClosureReason.CounterpartyInitiatedCooperativeClosure -> "CounterpartyInitiatedCooperativeClosure"
158+
is ClosureReason.LegacyCooperativeClosure -> "LegacyCooperativeClosure"
159+
is ClosureReason.LocallyInitiatedCooperativeClosure -> "LocallyInitiatedCooperativeClosure"
160+
is ClosureReason.HTLCsTimedOut -> "HTLCsTimedOut"
158161
else -> "Unknown"
159162
}
160163
body.putString("reason", reasonString)
@@ -164,7 +167,7 @@ class LdkChannelManagerPersister: ChannelManagerConstructor.EventHandler {
164167

165168
(event as? Event.DiscardFunding)?.let { discardFunding ->
166169
val body = Arguments.createMap()
167-
body.putHexString("channel_id", discardFunding.channel_id)
170+
body.putHexString("channel_id", discardFunding.channel_id._a)
168171
body.putHexString("tx", discardFunding.transaction)
169172
return LdkEventEmitter.send(EventTypes.channel_manager_discard_funding, body)
170173
}
@@ -173,7 +176,7 @@ class LdkChannelManagerPersister: ChannelManagerConstructor.EventHandler {
173176
val body = Arguments.createMap()
174177
body.putHexString("payment_hash", paymentClaimed.payment_hash)
175178
body.putInt("amount_sat", paymentClaimed.amount_msat.toInt() / 1000)
176-
(paymentClaimed.purpose as? PaymentPurpose.InvoicePayment)?.let {
179+
(paymentClaimed.purpose as? PaymentPurpose.Bolt11InvoicePayment)?.let {
177180
body.putHexString("payment_preimage", (it.payment_preimage as Option_ThirtyTwoBytesZ.Some).some)
178181
body.putHexString("payment_secret", it.payment_secret)
179182
}

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@ import org.ldk.structs.Persist.PersistInterface
88
import java.io.File
99

1010
class LdkPersister {
11-
fun handleChannel(id: OutPoint, data: ChannelMonitor, update_id: MonitorUpdateId): ChannelMonitorUpdateStatus {
11+
fun handleChannel(channelFundingOutpoint: OutPoint, data: ChannelMonitor, update_id: MonitorUpdateId): ChannelMonitorUpdateStatus {
12+
val channelId = data.channel_id()._a.hexEncodedString()
1213
val body = Arguments.createMap()
13-
body.putHexString("channel_id", id.to_channel_id())
14+
body.putString("channel_id", channelId)
1415
body.putHexString("counterparty_node_id", data._counterparty_node_id)
1516

1617
try {
1718
if (LdkModule.channelStoragePath == "") {
1819
throw Exception("Channel storage path not set")
1920
}
2021

21-
val channelId = id.to_channel_id().hexEncodedString()
22-
2322
val file = File(LdkModule.channelStoragePath + "/" + channelId + ".bin")
2423

2524
val isNew = !file.exists()
@@ -34,24 +33,24 @@ class LdkPersister {
3433

3534
BackupClient.addToPersistQueue(BackupClient.Label.CHANNEL_MONITOR(channelId=channelId), data.write()) { error ->
3635
if (error != null) {
37-
LdkEventEmitter.send(EventTypes.native_log, "Failed to persist channel (${id.to_channel_id().hexEncodedString()}) to remote backup: $error")
36+
LdkEventEmitter.send(EventTypes.native_log, "Failed to persist channel (${channelId}) to remote backup: $error")
3837
return@addToPersistQueue
3938
}
4039

4140
try {
4241
file.writeBytes(data.write())
4342
} catch (e: Exception) {
4443
//If this fails we can't do much but LDK will retry on startup
45-
LdkEventEmitter.send(EventTypes.native_log, "Failed to locally persist channel (${id.to_channel_id().hexEncodedString()}) to disk")
44+
LdkEventEmitter.send(EventTypes.native_log, "Failed to locally persist channel (${channelId}) to disk")
4645
return@addToPersistQueue
4746
}
4847

4948
//Update chain monitor with successful persist
50-
val res = LdkModule.chainMonitor?.channel_monitor_updated(id, update_id)
49+
val res = LdkModule.chainMonitor?.channel_monitor_updated(channelFundingOutpoint, update_id)
5150
if (res == null || !res.is_ok) {
52-
LdkEventEmitter.send(EventTypes.native_log, "Failed to update chain monitor with persisted channel (${id.to_channel_id().hexEncodedString()})")
51+
LdkEventEmitter.send(EventTypes.native_log, "Failed to update chain monitor with persisted channel (${channelId})")
5352
} else {
54-
LdkEventEmitter.send(EventTypes.native_log, "Persisted channel (${id.to_channel_id().hexEncodedString()}) to disk")
53+
LdkEventEmitter.send(EventTypes.native_log, "Persisted channel (${channelId}) to disk")
5554
if (isNew) {
5655
LdkEventEmitter.send(EventTypes.new_channel, body)
5756
}
@@ -65,12 +64,16 @@ class LdkPersister {
6564
}
6665

6766
var persister = Persist.new_impl(object : PersistInterface {
68-
override fun persist_new_channel(id: OutPoint, data: ChannelMonitor, update_id: MonitorUpdateId): ChannelMonitorUpdateStatus {
69-
return handleChannel(id, data, update_id)
67+
override fun persist_new_channel(channelFundingOutpoint: OutPoint, data: ChannelMonitor, update_id: MonitorUpdateId): ChannelMonitorUpdateStatus {
68+
return handleChannel(channelFundingOutpoint, data, update_id)
69+
}
70+
71+
override fun update_persisted_channel(channelFundingOutpoint: OutPoint, update: ChannelMonitorUpdate?, data: ChannelMonitor, update_id: MonitorUpdateId): ChannelMonitorUpdateStatus {
72+
return handleChannel(channelFundingOutpoint, data, update_id)
7073
}
7174

72-
override fun update_persisted_channel(id: OutPoint, update: ChannelMonitorUpdate?, data: ChannelMonitor, update_id: MonitorUpdateId): ChannelMonitorUpdateStatus {
73-
return handleChannel(id, data, update_id)
75+
override fun archive_persisted_channel(p0: OutPoint?) {
76+
TODO("Not yet implemented")
7477
}
7578
})
7679
}

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,

0 commit comments

Comments
 (0)