Skip to content

Commit 83a9c82

Browse files
committed
feat: update android ldk to 0.0.125
1 parent c3e518a commit 83a9c82

File tree

9 files changed

+78
-56
lines changed

9 files changed

+78
-56
lines changed

lib/android/libs/LDK-release.aar

1.95 MB
Binary file not shown.
56.2 KB
Binary file not shown.

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

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

118118
result.putHexString("channel_id", _channel_id._a)
119-
result.putBoolean("is_public", _is_public)
119+
result.putBoolean("is_public", _is_announced)
120120
result.putBoolean("is_usable", _is_usable)
121121
result.putBoolean("is_channel_ready", _is_channel_ready)
122122
result.putBoolean("is_outbound", _is_outbound)
@@ -188,7 +188,7 @@ val NodeInfo.asJson: WritableMap
188188
val shortChannelIds = Arguments.createArray()
189189
_channels.iterator().forEach { shortChannelIds.pushString(it.toString()) }
190190
result.putArray("shortChannelIds", shortChannelIds)
191-
result.putDouble("announcement_info_last_update", (_announcement_info?._last_update ?: 0).toDouble() * 1000)
191+
result.putDouble("announcement_info_last_update", ((_announcement_info as Option_NodeAnnouncementInfoZ.Some).some.last_update()).toDouble() * 1000)
192192
return result
193193
}
194194

@@ -335,7 +335,7 @@ fun ChannelHandshakeConfig.mergeWithMap(map: ReadableMap?): ChannelHandshakeConf
335335
_negotiate_scid_privacy = map.getBoolean("negotiate_scid_privacy")
336336
} catch (_: Exception) {}
337337
try {
338-
_announced_channel = map.getBoolean("announced_channel")
338+
_announce_for_forwarding = map.getBoolean("announced_channel")
339339
} catch (_: Exception) {}
340340
try {
341341
_commit_upfront_shutdown_pubkey = map.getBoolean("commit_upfront_shutdown_pubkey")

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

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import org.ldk.structs.Result_ChannelIdAPIErrorZ.Result_ChannelIdAPIErrorZ_OK
2121
import org.ldk.structs.Result_NoneAPIErrorZ.Result_NoneAPIErrorZ_OK
2222
import org.ldk.structs.Result_NoneRetryableSendFailureZ.Result_NoneRetryableSendFailureZ_Err
2323
import org.ldk.structs.Result_PublicKeyNoneZ.Result_PublicKeyNoneZ_OK
24-
import org.ldk.structs.Result_StrSecp256k1ErrorZ.Result_StrSecp256k1ErrorZ_OK
24+
//import org.ldk.structs.Result_StrSecp256k1ErrorZ.Result_StrSecp256k1ErrorZ_OK
2525
import org.ldk.util.UInt128
2626
import java.io.File
2727
import java.net.InetSocketAddress
@@ -592,8 +592,27 @@ 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, outputSpendingFee: Double, promise: Promise) {
596-
feeEstimator.update(anchorChannelFee.toInt(), nonAnchorChannelFee.toInt(), channelCloseMinimum.toInt(), minAllowedAnchorChannelRemoteFee.toInt(), onChainSweep.toInt(), minAllowedNonAnchorChannelRemoteFee.toInt(), outputSpendingFee.toInt())
595+
fun updateFees(
596+
anchorChannelFee: Double,
597+
nonAnchorChannelFee: Double,
598+
channelCloseMinimum: Double,
599+
minAllowedAnchorChannelRemoteFee: Double,
600+
minAllowedNonAnchorChannelRemoteFee: Double,
601+
outputSpendingFee: Double,
602+
maximumFeeEstimate: Double,
603+
urgentOnChainSweep: Double,
604+
promise: Promise
605+
) {
606+
feeEstimator.update(
607+
anchorChannelFee.toInt(),
608+
nonAnchorChannelFee.toInt(),
609+
channelCloseMinimum.toInt(),
610+
minAllowedAnchorChannelRemoteFee.toInt(),
611+
minAllowedNonAnchorChannelRemoteFee.toInt(),
612+
outputSpendingFee.toInt(),
613+
maximumFeeEstimate.toInt(),
614+
urgentOnChainSweep.toInt(),
615+
)
597616
handleResolve(promise, LdkCallbackResponses.fees_updated)
598617
}
599618

@@ -761,7 +780,7 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
761780
channelManager ?: return handleReject(promise, LdkErrors.init_channel_manager)
762781

763782
val channelIdObj = ChannelId.of(channelId.hexa())
764-
val res = if (force) channelManager!!.force_close_broadcasting_latest_txn(channelIdObj, counterpartyNodeId.hexa()) else channelManager!!.close_channel(channelIdObj, counterpartyNodeId.hexa())
783+
val res = if (force) channelManager!!.force_close_broadcasting_latest_txn(channelIdObj, counterpartyNodeId.hexa(), "Force close") else channelManager!!.close_channel(channelIdObj, counterpartyNodeId.hexa())
765784
if (!res.is_ok) {
766785
return handleReject(promise, LdkErrors.channel_close_fail)
767786
}
@@ -846,9 +865,9 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
846865
channelManager ?: return handleReject(promise, LdkErrors.init_channel_manager)
847866

848867
if (broadcastLatestTx) {
849-
channelManager!!.force_close_all_channels_broadcasting_latest_txn()
868+
channelManager!!.force_close_all_channels_broadcasting_latest_txn("Force close broadcasting latest tx")
850869
} else {
851-
channelManager!!.force_close_all_channels_without_broadcasting_txn()
870+
channelManager!!.force_close_all_channels_without_broadcasting_txn("Force close without broadcasting latest tx")
852871
}
853872

854873
handleResolve(promise, LdkCallbackResponses.close_channel_success)
@@ -1353,15 +1372,15 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
13531372
descriptors,
13541373
emptyArray(),
13551374
changeDestinationScript.hexa(),
1356-
feeEstimator.onChainSweep,
1375+
feeEstimator.urgentOnChainSweep,
13571376
Option_u32Z.none()
13581377
)
13591378
} else {
13601379
keysManager!!.spend_spendable_outputs(
13611380
descriptors,
13621381
emptyArray(),
13631382
changeDestinationScript.hexa(),
1364-
feeEstimator.onChainSweep,
1383+
feeEstimator.urgentOnChainSweep,
13651384
Option_u32Z.none()
13661385
)
13671386
}
@@ -1381,13 +1400,7 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
13811400
fun nodeSign(message: String, promise: Promise) {
13821401
keysManager ?: return handleReject(promise, LdkErrors.init_keys_manager)
13831402

1384-
val res = UtilMethods.sign(message.toByteArray(Charsets.UTF_8), keysManager!!.inner._node_secret_key)
1385-
1386-
if (!res.is_ok) {
1387-
return handleReject(promise, LdkErrors.failed_signing_request)
1388-
}
1389-
1390-
promise.resolve((res as Result_StrSecp256k1ErrorZ_OK).res)
1403+
promise.resolve(UtilMethods.sign(message.toByteArray(Charsets.UTF_8), keysManager!!.inner._node_secret_key))
13911404
}
13921405

13931406
@ReactMethod

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import com.reactnativeldk.hexEncodedString
99
import com.reactnativeldk.hexa
1010
import com.reactnativeldk.putDateOrNull
1111
import org.json.JSONObject
12-
import org.ldk.structs.Result_StrSecp256k1ErrorZ.Result_StrSecp256k1ErrorZ_OK
1312
import org.ldk.structs.UtilMethods
1413
import java.net.HttpURLConnection
1514
import java.net.URL
@@ -458,12 +457,7 @@ class BackupClient {
458457
throw BackupError.requiresSetup
459458
}
460459

461-
val res = UtilMethods.sign("$signedMessagePrefix$message".toByteArray(Charsets.UTF_8), secretKey)
462-
if (!res.is_ok) {
463-
throw BackupError.signingError
464-
}
465-
466-
return (res as Result_StrSecp256k1ErrorZ_OK).res
460+
return UtilMethods.sign("$signedMessagePrefix$message".toByteArray(Charsets.UTF_8), secretKey)
467461
}
468462

469463
private fun verifySignature(message: String, signature: String, pubKey: String): Boolean {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ package com.reactnativeldk.classes
22

33
import com.reactnativeldk.EventTypes
44
import com.reactnativeldk.LdkEventEmitter
5+
import org.ldk.structs.EcdsaChannelSigner
56
import org.ldk.structs.KeysManager
67
import org.ldk.structs.Option_u32Z
78
import org.ldk.structs.Result_CVec_u8ZNoneZ
9+
import org.ldk.structs.Result_EcdsaChannelSignerDecodeErrorZ
810
import org.ldk.structs.Result_ShutdownScriptInvalidShutdownScriptZ
911
import org.ldk.structs.Result_ShutdownScriptNoneZ
1012
import org.ldk.structs.Result_TransactionNoneZ
11-
import org.ldk.structs.Result_WriteableEcdsaChannelSignerDecodeErrorZ
1213
import org.ldk.structs.ShutdownScript
1314
import org.ldk.structs.SignerProvider.SignerProviderInterface
1415
import org.ldk.structs.SpendableOutputDescriptor
1516
import org.ldk.structs.TxOut
1617
import org.ldk.structs.WitnessProgram
17-
import org.ldk.structs.WriteableEcdsaChannelSigner
1818
import org.ldk.util.UInt128
1919
import org.ldk.util.WitnessVersion
2020

@@ -79,15 +79,15 @@ class CustomSignerProvider : SignerProviderInterface {
7979
override fun derive_channel_signer(
8080
channel_value_satoshis: Long,
8181
channel_keys_id: ByteArray?
82-
): WriteableEcdsaChannelSigner {
82+
): EcdsaChannelSigner {
8383
return customKeysManager.inner.as_SignerProvider().derive_channel_signer(channel_value_satoshis, channel_keys_id)
8484
}
8585

8686
override fun generate_channel_keys_id(p0: Boolean, p1: Long, p2: UInt128?): ByteArray {
8787
return customKeysManager.inner.as_SignerProvider().generate_channel_keys_id(p0, p1, p2)
8888
}
8989

90-
override fun read_chan_signer(p0: ByteArray?): Result_WriteableEcdsaChannelSignerDecodeErrorZ {
90+
override fun read_chan_signer(p0: ByteArray?): Result_EcdsaChannelSignerDecodeErrorZ? {
9191
return customKeysManager.inner.as_SignerProvider().read_chan_signer(p0!!)
9292
}
9393
}

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

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ import org.ldk.structs.Event.BumpTransaction
1212
import org.ldk.structs.Option_ThirtyTwoBytesZ
1313
import org.ldk.structs.Option_u64Z
1414
import org.ldk.structs.PaymentPurpose
15+
import org.ldk.structs.Result_NoneReplayEventZ
1516
import java.io.File
1617

1718
class LdkChannelManagerPersister: ChannelManagerConstructor.EventHandler {
18-
override fun handle_event(event: Event) {
19+
override fun handle_event(event: Event): Result_NoneReplayEventZ {
1920
(event as? Event.FundingGenerationReady)?.let { fundingGenerationReady ->
2021
val body = Arguments.createMap()
2122
body.putHexString("temp_channel_id", fundingGenerationReady.temporary_channel_id._a)
2223
body.putHexString("output_script", fundingGenerationReady.output_script)
2324
body.putHexString("user_channel_id", fundingGenerationReady.user_channel_id.leBytes)
2425
body.putInt("value_satoshis", fundingGenerationReady.channel_value_satoshis.toInt())
25-
return LdkEventEmitter.send(EventTypes.channel_manager_funding_generation_ready, body)
26+
LdkEventEmitter.send(EventTypes.channel_manager_funding_generation_ready, body)
2627
}
2728

2829
(event as? Event.PaymentClaimable)?.let { paymentClaimable ->
@@ -40,7 +41,7 @@ class LdkChannelManagerPersister: ChannelManagerConstructor.EventHandler {
4041
body.putString("state", "pending")
4142

4243
persistPaymentClaimed(body)
43-
return LdkEventEmitter.send(EventTypes.channel_manager_payment_claimable, body)
44+
LdkEventEmitter.send(EventTypes.channel_manager_payment_claimable, body)
4445
}
4546

4647
(event as? Event.PaymentSent)?.let { paymentSent ->
@@ -54,7 +55,7 @@ class LdkChannelManagerPersister: ChannelManagerConstructor.EventHandler {
5455

5556
persistPaymentSent(body.toHashMap())
5657

57-
return LdkEventEmitter.send(EventTypes.channel_manager_payment_sent, body)
58+
LdkEventEmitter.send(EventTypes.channel_manager_payment_sent, body)
5859
}
5960

6061
(event as? Event.OpenChannelRequest)?.let { openChannelRequest ->
@@ -67,7 +68,7 @@ class LdkChannelManagerPersister: ChannelManagerConstructor.EventHandler {
6768
body.putBoolean("requires_zero_conf", openChannelRequest.channel_type.requires_zero_conf())
6869
body.putBoolean("supports_zero_conf", openChannelRequest.channel_type.supports_zero_conf())
6970
body.putBoolean("requires_anchors_zero_fee_htlc_tx", openChannelRequest.channel_type.requires_anchors_zero_fee_htlc_tx())
70-
return LdkEventEmitter.send(EventTypes.channel_manager_open_channel_request, body)
71+
LdkEventEmitter.send(EventTypes.channel_manager_open_channel_request, body)
7172
}
7273

7374
(event as? Event.PaymentPathSuccessful)?.let { paymentPathSuccessful ->
@@ -80,7 +81,7 @@ class LdkChannelManagerPersister: ChannelManagerConstructor.EventHandler {
8081
event.path._hops.forEach { pathHops.pushMap(it.asJson) }
8182
body.putArray("path_hops", pathHops)
8283

83-
return LdkEventEmitter.send(EventTypes.channel_manager_payment_path_successful, body)
84+
LdkEventEmitter.send(EventTypes.channel_manager_payment_path_successful, body)
8485
}
8586

8687
(event as? Event.PaymentPathFailed)?.let { paymentPathFailed ->
@@ -102,22 +103,22 @@ class LdkChannelManagerPersister: ChannelManagerConstructor.EventHandler {
102103
))
103104
}
104105

105-
return LdkEventEmitter.send(EventTypes.channel_manager_payment_path_failed, body)
106+
LdkEventEmitter.send(EventTypes.channel_manager_payment_path_failed, body)
106107
}
107108

108109
(event as? Event.PaymentFailed)?.let { paymentFailed ->
109110
val body = Arguments.createMap()
110111
body.putHexString("payment_id", paymentFailed.payment_id)
111-
body.putHexString("payment_hash", paymentFailed.payment_hash)
112+
body.putHexString("payment_hash", (paymentFailed.payment_hash as Option_ThirtyTwoBytesZ.Some).some)
112113

113114
persistPaymentSent(hashMapOf(
114115
"payment_id" to paymentFailed.payment_id!!.hexEncodedString(),
115-
"payment_hash" to paymentFailed.payment_hash.hexEncodedString(),
116+
"payment_hash" to (paymentFailed.payment_hash as Option_ThirtyTwoBytesZ.Some).some.hexEncodedString(),
116117
"unix_timestamp" to (System.currentTimeMillis() / 1000).toInt(),
117118
"state" to "failed"
118119
))
119120

120-
return LdkEventEmitter.send(EventTypes.channel_manager_payment_failed, body)
121+
LdkEventEmitter.send(EventTypes.channel_manager_payment_failed, body)
121122
}
122123

123124
(event as? Event.PaymentForwarded)?.let { paymentForwarded ->
@@ -127,7 +128,7 @@ class LdkChannelManagerPersister: ChannelManagerConstructor.EventHandler {
127128
(event as? Event.PendingHTLCsForwardable)?.let { pendingHTLCsForwardable ->
128129
val body = Arguments.createMap()
129130
body.putInt("time_forwardable", pendingHTLCsForwardable.time_forwardable.toInt())
130-
return LdkEventEmitter.send(EventTypes.channel_manager_pending_htlcs_forwardable, body)
131+
LdkEventEmitter.send(EventTypes.channel_manager_pending_htlcs_forwardable, body)
131132
}
132133

133134
(event as? Event.SpendableOutputs)?.let { spendableOutputs ->
@@ -137,7 +138,7 @@ class LdkChannelManagerPersister: ChannelManagerConstructor.EventHandler {
137138
outputs.pushHexString(it.write())
138139
}
139140
body.putArray("outputsSerialized", outputs)
140-
return LdkEventEmitter.send(EventTypes.channel_manager_spendable_outputs, body)
141+
LdkEventEmitter.send(EventTypes.channel_manager_spendable_outputs, body)
141142
}
142143

143144
(event as? Event.ChannelClosed)?.let { channelClosed ->
@@ -170,14 +171,14 @@ class LdkChannelManagerPersister: ChannelManagerConstructor.EventHandler {
170171

171172
println("Channel closed: ${channelClosed.channel_id._a.hexEncodedString()}")
172173

173-
return LdkEventEmitter.send(EventTypes.channel_manager_channel_closed, body)
174+
LdkEventEmitter.send(EventTypes.channel_manager_channel_closed, body)
174175
}
175176

176177
(event as? Event.DiscardFunding)?.let { discardFunding ->
177178
val body = Arguments.createMap()
178179
body.putHexString("channel_id", discardFunding.channel_id._a)
179-
body.putHexString("tx", discardFunding.transaction)
180-
return LdkEventEmitter.send(EventTypes.channel_manager_discard_funding, body)
180+
body.putHexString("tx", discardFunding.channel_id._a)
181+
LdkEventEmitter.send(EventTypes.channel_manager_discard_funding, body)
181182
}
182183

183184
(event as? Event.PaymentClaimed)?.let { paymentClaimed ->
@@ -195,7 +196,7 @@ class LdkChannelManagerPersister: ChannelManagerConstructor.EventHandler {
195196
body.putString("state", "successful")
196197

197198
persistPaymentClaimed(body)
198-
return LdkEventEmitter.send(EventTypes.channel_manager_payment_claimed, body)
199+
LdkEventEmitter.send(EventTypes.channel_manager_payment_claimed, body)
199200
}
200201

201202
(event as? Event.ChannelReady)?.let { channelReady ->
@@ -212,9 +213,11 @@ class LdkChannelManagerPersister: ChannelManagerConstructor.EventHandler {
212213
body.putString("commitment_tx", channelClose.commitment_tx.hexEncodedString())
213214
body.putInt("commitment_tx_fee", channelClose.commitment_tx_fee_satoshis.toInt())
214215
body.putInt("pending_htlcs_count", channelClose.pending_htlcs.size)
215-
return LdkEventEmitter.send(EventTypes.lsp_log, body)
216+
LdkEventEmitter.send(EventTypes.lsp_log, body)
216217
}
217218
}
219+
220+
return Result_NoneReplayEventZ.ok()
218221
}
219222

220223
override fun persist_manager(channel_manager_bytes: ByteArray?) {

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,29 @@ class LdkFeeEstimator {
99
var nonAnchorChannelFee: Int = 0
1010
var channelCloseMinimum: Int = 0
1111
var minAllowedAnchorChannelRemoteFee: Int = 0
12-
var onChainSweep: Int = 0
1312
var minAllowedNonAnchorChannelRemoteFee: Int = 0
1413
var outputSpendingFee: Int = 0
14+
var maximumFeeEstimate: Int = 0
15+
var urgentOnChainSweep: Int = 0
1516

16-
fun update(anchorChannelFee: Int, nonAnchorChannelFee: Int, channelCloseMinimum: Int, minAllowedAnchorChannelRemoteFee: Int, onChainSweep: Int, minAllowedNonAnchorChannelRemoteFee: Int, outputSpendingFee: Int) {
17+
fun update(
18+
anchorChannelFee: Int,
19+
nonAnchorChannelFee: Int,
20+
channelCloseMinimum: Int,
21+
minAllowedAnchorChannelRemoteFee: Int,
22+
minAllowedNonAnchorChannelRemoteFee: Int,
23+
outputSpendingFee: Int,
24+
maximumFeeEstimate: Int,
25+
urgentOnChainSweep: Int
26+
) {
1727
this.anchorChannelFee = anchorChannelFee
1828
this.nonAnchorChannelFee = nonAnchorChannelFee
1929
this.channelCloseMinimum = channelCloseMinimum
2030
this.minAllowedAnchorChannelRemoteFee = minAllowedAnchorChannelRemoteFee
21-
this.onChainSweep = onChainSweep
2231
this.minAllowedNonAnchorChannelRemoteFee = minAllowedNonAnchorChannelRemoteFee
2332
this.outputSpendingFee = outputSpendingFee
33+
this.maximumFeeEstimate = maximumFeeEstimate
34+
this.urgentOnChainSweep = urgentOnChainSweep
2435

2536
LdkEventEmitter.send(EventTypes.native_log, "Fee estimator updated")
2637
}
@@ -31,9 +42,10 @@ class LdkFeeEstimator {
3142
ConfirmationTarget.LDKConfirmationTarget_NonAnchorChannelFee -> nonAnchorChannelFee
3243
ConfirmationTarget.LDKConfirmationTarget_ChannelCloseMinimum -> channelCloseMinimum
3344
ConfirmationTarget.LDKConfirmationTarget_MinAllowedAnchorChannelRemoteFee -> minAllowedAnchorChannelRemoteFee
34-
ConfirmationTarget.LDKConfirmationTarget_OnChainSweep -> onChainSweep
3545
ConfirmationTarget.LDKConfirmationTarget_MinAllowedNonAnchorChannelRemoteFee -> minAllowedNonAnchorChannelRemoteFee
3646
ConfirmationTarget.LDKConfirmationTarget_OutputSpendingFee -> outputSpendingFee
47+
ConfirmationTarget.LDKConfirmationTarget_MaximumFeeEstimate -> maximumFeeEstimate
48+
ConfirmationTarget.LDKConfirmationTarget_UrgentOnChainSweep -> urgentOnChainSweep
3749
}
3850
}
3951
}

0 commit comments

Comments
 (0)