@@ -11,12 +11,16 @@ import org.ldk.batteries.NioPeerHandler
11
11
import org.ldk.enums.Currency
12
12
import org.ldk.enums.Network
13
13
import org.ldk.enums.Recipient
14
+ import org.ldk.enums.RetryableSendFailure
15
+ import org.ldk.impl.bindings.LDKPaymentSendFailure.DuplicatePayment
14
16
import org.ldk.impl.bindings.get_ldk_c_bindings_version
15
17
import org.ldk.impl.bindings.get_ldk_version
16
18
import org.ldk.structs.*
17
19
import org.ldk.structs.Result_Bolt11InvoiceParseOrSemanticErrorZ.Result_Bolt11InvoiceParseOrSemanticErrorZ_OK
18
20
import org.ldk.structs.Result_Bolt11InvoiceSignOrCreationErrorZ.Result_Bolt11InvoiceSignOrCreationErrorZ_OK
19
21
import org.ldk.structs.Result_C2Tuple_ThirtyTwoBytesChannelMonitorZDecodeErrorZ.Result_C2Tuple_ThirtyTwoBytesChannelMonitorZDecodeErrorZ_OK
22
+ import org.ldk.structs.Result_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ.Result_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ_OK
23
+ import org.ldk.structs.Result_NoneRetryableSendFailureZ.Result_NoneRetryableSendFailureZ_Err
20
24
import org.ldk.structs.Result_PublicKeyNoneZ.Result_PublicKeyNoneZ_OK
21
25
import org.ldk.structs.Result_StrSecp256k1ErrorZ.Result_StrSecp256k1ErrorZ_OK
22
26
import org.ldk.util.UInt128
@@ -75,11 +79,9 @@ enum class LdkErrors {
75
79
invoice_payment_fail_must_specify_amount,
76
80
invoice_payment_fail_must_not_specify_amount,
77
81
invoice_payment_fail_invoice,
78
- invoice_payment_fail_sending,
79
- invoice_payment_fail_resend_safe,
80
- invoice_payment_fail_parameter_error,
81
- invoice_payment_fail_partial,
82
- invoice_payment_fail_path_parameter_error,
82
+ invoice_payment_fail_duplicate_payment,
83
+ invoice_payment_fail_payment_expired,
84
+ invoice_payment_fail_route_not_found,
83
85
init_ldk_currency,
84
86
invoice_create_failed,
85
87
init_scorer_failed,
@@ -580,8 +582,8 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
580
582
// MARK: Update methods
581
583
582
584
@ReactMethod
583
- fun updateFees (anchorChannelFee : Double , nonAnchorChannelFee : Double , channelCloseMinimum : Double , minAllowedAnchorChannelRemoteFee : Double , maxAllowedNonAnchorChannelRemoteFee : Double , onChainSweep : Double , minAllowedNonAnchorChannelRemoteFee : Double , promise : Promise ) {
584
- feeEstimator.update(anchorChannelFee.toInt(), nonAnchorChannelFee.toInt(), channelCloseMinimum.toInt(), minAllowedAnchorChannelRemoteFee.toInt(), maxAllowedNonAnchorChannelRemoteFee.toInt(), onChainSweep.toInt(), minAllowedNonAnchorChannelRemoteFee.toInt())
585
+ fun updateFees (anchorChannelFee : Double , nonAnchorChannelFee : Double , channelCloseMinimum : Double , minAllowedAnchorChannelRemoteFee : Double , onChainSweep : Double , minAllowedNonAnchorChannelRemoteFee : Double , promise : Promise ) {
586
+ feeEstimator.update(anchorChannelFee.toInt(), nonAnchorChannelFee.toInt(), channelCloseMinimum.toInt(), minAllowedAnchorChannelRemoteFee.toInt(), onChainSweep.toInt(), minAllowedNonAnchorChannelRemoteFee.toInt())
585
587
handleResolve(promise, LdkCallbackResponses .fees_updated)
586
588
}
587
589
@@ -792,14 +794,27 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
792
794
return handleReject(promise, LdkErrors .invoice_payment_fail_must_not_specify_amount)
793
795
}
794
796
795
- val res = if (isZeroValueInvoice)
796
- UtilMethods .pay_zero_value_invoice(invoice, amountSats.toLong() * 1000 , Retry .timeout(timeoutSeconds.toLong()), channelManager) else
797
- UtilMethods .pay_invoice(invoice, Retry .timeout(timeoutSeconds.toLong()), channelManager)
797
+ val paymentId = invoice.payment_hash()
798
+ val detailsRes = if (isZeroValueInvoice)
799
+ UtilMethods .payment_parameters_from_zero_amount_invoice(invoice, amountSats.toLong()) else
800
+ UtilMethods .payment_parameters_from_invoice(invoice)
801
+
802
+ if (! detailsRes.is_ok) {
803
+ return handleReject(promise, LdkErrors .invoice_payment_fail_invoice)
804
+ }
805
+
806
+ val sendDetails = detailsRes as Result_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ_OK
807
+ val paymentHash = sendDetails.res._a
808
+ val recipientOnion = sendDetails.res._b
809
+ val routeParams = sendDetails.res._c
810
+
811
+ val res = channelManager!! .send_payment(paymentHash, recipientOnion, paymentId, routeParams, Retry .timeout(timeoutSeconds.toLong()))
812
+
798
813
if (res.is_ok) {
799
814
channelManagerPersister.persistPaymentSent(hashMapOf(
800
815
" bolt11_invoice" to paymentRequest,
801
- " description" to (invoice.into_signed_raw().raw_invoice().description()?.into_inner () ? : " " ),
802
- " payment_id" to (res as Result_ThirtyTwoBytesPaymentErrorZ . Result_ThirtyTwoBytesPaymentErrorZ_OK ).res .hexEncodedString(),
816
+ " description" to (invoice.into_signed_raw().raw_invoice().description()?.to_str () ? : " " ),
817
+ " payment_id" to paymentId .hexEncodedString(),
803
818
" payment_hash" to invoice.payment_hash().hexEncodedString(),
804
819
" amount_sat" to if (isZeroValueInvoice) amountSats.toLong() else ((invoice.amount_milli_satoshis() as Option_u64Z .Some ).some.toInt() / 1000 ),
805
820
" unix_timestamp" to (System .currentTimeMillis() / 1000 ).toInt(),
@@ -809,39 +824,24 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
809
824
return handleResolve(promise, LdkCallbackResponses .invoice_payment_success)
810
825
}
811
826
812
- val error = res as ? Result_ThirtyTwoBytesPaymentErrorZ .Result_ThirtyTwoBytesPaymentErrorZ_Err
813
-
814
- val invoiceError = error?.err as ? PaymentError .Invoice
815
- if (invoiceError != null ) {
816
- return handleReject(promise, LdkErrors .invoice_payment_fail_invoice, Error (invoiceError.invoice))
817
- }
818
-
819
- val sendingError = error?.err as ? PaymentError .Sending
820
- if (sendingError != null ) {
821
- val paymentAllFailedResendSafe = sendingError.sending as ? PaymentSendFailure .AllFailedResendSafe
822
- if (paymentAllFailedResendSafe != null ) {
823
- return handleReject(promise, LdkErrors .invoice_payment_fail_resend_safe, Error (paymentAllFailedResendSafe.all_failed_resend_safe.map { it.toString() }.toString()))
824
- }
827
+ val error = res as ? Result_NoneRetryableSendFailureZ_Err
828
+ ? : return handleReject(promise, LdkErrors .invoice_payment_fail_unknown)
825
829
826
- val paymentParameterError = sendingError.sending as ? PaymentSendFailure . ParameterError
827
- if (paymentParameterError != null ) {
828
- return handleReject(promise, LdkErrors .invoice_payment_fail_parameter_error, Error (paymentParameterError.parameter_error.toString()) )
830
+ when (error.err) {
831
+ RetryableSendFailure . LDKRetryableSendFailure_DuplicatePayment -> {
832
+ handleReject(promise, LdkErrors .invoice_payment_fail_duplicate_payment )
829
833
}
830
834
831
- val paymentPartialFailure = sendingError.sending as ? PaymentSendFailure .PartialFailure
832
- if (paymentPartialFailure != null ) {
833
- return handleReject(promise, LdkErrors .invoice_payment_fail_partial, Error (paymentPartialFailure.toString()))
835
+ RetryableSendFailure .LDKRetryableSendFailure_PaymentExpired -> {
836
+ handleReject(promise, LdkErrors .invoice_payment_fail_payment_expired)
834
837
}
835
838
836
- val paymentPathParameterError = sendingError.sending as ? PaymentSendFailure .PathParameterError
837
- if (paymentPathParameterError != null ) {
838
- return handleReject(promise, LdkErrors .invoice_payment_fail_path_parameter_error, Error (paymentPartialFailure.toString()))
839
+ RetryableSendFailure .LDKRetryableSendFailure_RouteNotFound -> {
840
+ handleReject(promise, LdkErrors .invoice_payment_fail_route_not_found)
839
841
}
840
842
841
- return handleReject(promise, LdkErrors .invoice_payment_fail_sending, Error ( " PaymentError.Sending: ${sendingError.sending.name} " ) )
843
+ else -> handleReject(promise, LdkErrors .invoice_payment_fail_unknown )
842
844
}
843
-
844
- return handleReject(promise, LdkErrors .invoice_payment_fail_unknown)
845
845
}
846
846
847
847
@ReactMethod
@@ -963,6 +963,40 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
963
963
promise.resolve(list)
964
964
}
965
965
966
+ @ReactMethod
967
+ fun listChannelMonitors (ignoreOpenChannels : Boolean , promise : Promise ) {
968
+ val channelManager = channelManager ? : return handleReject(promise, LdkErrors .init_channel_manager)
969
+ val keysManager = keysManager ? : return handleReject(promise, LdkErrors .init_keys_manager)
970
+ if (channelStoragePath == " " ) {
971
+ return handleReject(promise, LdkErrors .init_storage_path)
972
+ }
973
+
974
+ val ignoredChannels = if (ignoreOpenChannels)
975
+ channelManager.list_channels().map { it._channel_id .hexEncodedString() }.toTypedArray() else
976
+ arrayOf()
977
+
978
+ val channelFiles = File (channelStoragePath).listFiles()
979
+
980
+ val result = Arguments .createArray()
981
+ for (channelFile in channelFiles) {
982
+ val channelId = channelFile.nameWithoutExtension
983
+
984
+ // Ignore open channels
985
+ if (ignoredChannels.contains(channelId)) {
986
+ continue
987
+ }
988
+
989
+ val channelMonitor = UtilMethods .C2Tuple_ThirtyTwoBytesChannelMonitorZ_read (channelFile.readBytes(), keysManager!! .inner.as_EntropySource(), SignerProvider .new_impl(keysManager!! .signerProvider))
990
+
991
+ if (channelMonitor.is_ok) {
992
+ val channelMonitorResult = (channelMonitor as Result_C2Tuple_ThirtyTwoBytesChannelMonitorZDecodeErrorZ_OK )
993
+ result.pushMap(channelMonitorResult.res._b .asJson(channelMonitorResult.res._a .hexEncodedString()))
994
+ }
995
+ }
996
+
997
+ promise.resolve(result)
998
+ }
999
+
966
1000
@ReactMethod
967
1001
fun networkGraphListNodeIds (promise : Promise ) {
968
1002
val graph = networkGraph?.read_only() ? : return handleReject(promise, LdkErrors .init_network_graph)
@@ -1111,7 +1145,7 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
1111
1145
1112
1146
val output = TxOut (outputValue.toLong(), outputScriptPubKey.hexa())
1113
1147
val outpoint = OutPoint .of(outpointTxId.hexa().reversedArray(), outpointIndex.toInt().toShort())
1114
- val descriptor = SpendableOutputDescriptor .static_output(outpoint, output)
1148
+ val descriptor = SpendableOutputDescriptor .static_output(outpoint, output, byteArrayOf() )
1115
1149
1116
1150
val ldkDescriptors: MutableList <SpendableOutputDescriptor > = arrayListOf ()
1117
1151
ldkDescriptors.add(descriptor)
0 commit comments