@@ -9,12 +9,16 @@ import org.ldk.batteries.NioPeerHandler
9
9
import org.ldk.enums.Currency
10
10
import org.ldk.enums.Network
11
11
import org.ldk.enums.Recipient
12
+ import org.ldk.enums.RetryableSendFailure
13
+ import org.ldk.impl.bindings.LDKPaymentSendFailure.DuplicatePayment
12
14
import org.ldk.impl.bindings.get_ldk_c_bindings_version
13
15
import org.ldk.impl.bindings.get_ldk_version
14
16
import org.ldk.structs.*
15
17
import org.ldk.structs.Result_Bolt11InvoiceParseOrSemanticErrorZ.Result_Bolt11InvoiceParseOrSemanticErrorZ_OK
16
18
import org.ldk.structs.Result_Bolt11InvoiceSignOrCreationErrorZ.Result_Bolt11InvoiceSignOrCreationErrorZ_OK
17
19
import org.ldk.structs.Result_C2Tuple_ThirtyTwoBytesChannelMonitorZDecodeErrorZ.Result_C2Tuple_ThirtyTwoBytesChannelMonitorZDecodeErrorZ_OK
20
+ import org.ldk.structs.Result_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ.Result_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ_OK
21
+ import org.ldk.structs.Result_NoneRetryableSendFailureZ.Result_NoneRetryableSendFailureZ_Err
18
22
import org.ldk.structs.Result_PublicKeyNoneZ.Result_PublicKeyNoneZ_OK
19
23
import org.ldk.structs.Result_StrSecp256k1ErrorZ.Result_StrSecp256k1ErrorZ_OK
20
24
import org.ldk.util.UInt128
@@ -73,11 +77,9 @@ enum class LdkErrors {
73
77
invoice_payment_fail_must_specify_amount,
74
78
invoice_payment_fail_must_not_specify_amount,
75
79
invoice_payment_fail_invoice,
76
- invoice_payment_fail_sending,
77
- invoice_payment_fail_resend_safe,
78
- invoice_payment_fail_parameter_error,
79
- invoice_payment_fail_partial,
80
- invoice_payment_fail_path_parameter_error,
80
+ invoice_payment_fail_duplicate_payment,
81
+ invoice_payment_fail_payment_expired,
82
+ invoice_payment_fail_route_not_found,
81
83
init_ldk_currency,
82
84
invoice_create_failed,
83
85
init_scorer_failed,
@@ -564,8 +566,8 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
564
566
// MARK: Update methods
565
567
566
568
@ReactMethod
567
- fun updateFees (anchorChannelFee : Double , nonAnchorChannelFee : Double , channelCloseMinimum : Double , minAllowedAnchorChannelRemoteFee : Double , maxAllowedNonAnchorChannelRemoteFee : Double , onChainSweep : Double , minAllowedNonAnchorChannelRemoteFee : Double , promise : Promise ) {
568
- feeEstimator.update(anchorChannelFee.toInt(), nonAnchorChannelFee.toInt(), channelCloseMinimum.toInt(), minAllowedAnchorChannelRemoteFee.toInt(), maxAllowedNonAnchorChannelRemoteFee.toInt(), onChainSweep.toInt(), minAllowedNonAnchorChannelRemoteFee.toInt())
569
+ fun updateFees (anchorChannelFee : Double , nonAnchorChannelFee : Double , channelCloseMinimum : Double , minAllowedAnchorChannelRemoteFee : Double , onChainSweep : Double , minAllowedNonAnchorChannelRemoteFee : Double , promise : Promise ) {
570
+ feeEstimator.update(anchorChannelFee.toInt(), nonAnchorChannelFee.toInt(), channelCloseMinimum.toInt(), minAllowedAnchorChannelRemoteFee.toInt(), onChainSweep.toInt(), minAllowedNonAnchorChannelRemoteFee.toInt())
569
571
handleResolve(promise, LdkCallbackResponses .fees_updated)
570
572
}
571
573
@@ -772,14 +774,27 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
772
774
return handleReject(promise, LdkErrors .invoice_payment_fail_must_not_specify_amount)
773
775
}
774
776
775
- val res = if (isZeroValueInvoice)
776
- UtilMethods .pay_zero_value_invoice(invoice, amountSats.toLong() * 1000 , Retry .timeout(timeoutSeconds.toLong()), channelManager) else
777
- UtilMethods .pay_invoice(invoice, Retry .timeout(timeoutSeconds.toLong()), channelManager)
777
+ val paymentId = invoice.payment_hash()
778
+ val detailsRes = if (isZeroValueInvoice)
779
+ UtilMethods .payment_parameters_from_zero_amount_invoice(invoice, amountSats.toLong()) else
780
+ UtilMethods .payment_parameters_from_invoice(invoice)
781
+
782
+ if (! detailsRes.is_ok) {
783
+ return handleReject(promise, LdkErrors .invoice_payment_fail_invoice)
784
+ }
785
+
786
+ val sendDetails = detailsRes as Result_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ_OK
787
+ val paymentHash = sendDetails.res._a
788
+ val recipientOnion = sendDetails.res._b
789
+ val routeParams = sendDetails.res._c
790
+
791
+ val res = channelManager!! .send_payment(paymentHash, recipientOnion, paymentId, routeParams, Retry .timeout(timeoutSeconds.toLong()))
792
+
778
793
if (res.is_ok) {
779
794
channelManagerPersister.persistPaymentSent(hashMapOf(
780
795
" bolt11_invoice" to paymentRequest,
781
- " description" to (invoice.into_signed_raw().raw_invoice().description()?.into_inner () ? : " " ),
782
- " payment_id" to (res as Result_ThirtyTwoBytesPaymentErrorZ . Result_ThirtyTwoBytesPaymentErrorZ_OK ).res .hexEncodedString(),
796
+ " description" to (invoice.into_signed_raw().raw_invoice().description()?.to_str () ? : " " ),
797
+ " payment_id" to paymentId .hexEncodedString(),
783
798
" payment_hash" to invoice.payment_hash().hexEncodedString(),
784
799
" amount_sat" to if (isZeroValueInvoice) amountSats.toLong() else ((invoice.amount_milli_satoshis() as Option_u64Z .Some ).some.toInt() / 1000 ),
785
800
" unix_timestamp" to (System .currentTimeMillis() / 1000 ).toInt(),
@@ -789,39 +804,24 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
789
804
return handleResolve(promise, LdkCallbackResponses .invoice_payment_success)
790
805
}
791
806
792
- val error = res as ? Result_ThirtyTwoBytesPaymentErrorZ .Result_ThirtyTwoBytesPaymentErrorZ_Err
807
+ val error = res as ? Result_NoneRetryableSendFailureZ_Err
808
+ ? : return handleReject(promise, LdkErrors .invoice_payment_fail_unknown)
793
809
794
- val invoiceError = error?.err as ? PaymentError .Invoice
795
- if (invoiceError != null ) {
796
- return handleReject(promise, LdkErrors .invoice_payment_fail_invoice, Error (invoiceError.invoice))
797
- }
798
-
799
- val sendingError = error?.err as ? PaymentError .Sending
800
- if (sendingError != null ) {
801
- val paymentAllFailedResendSafe = sendingError.sending as ? PaymentSendFailure .AllFailedResendSafe
802
- if (paymentAllFailedResendSafe != null ) {
803
- return handleReject(promise, LdkErrors .invoice_payment_fail_resend_safe, Error (paymentAllFailedResendSafe.all_failed_resend_safe.map { it.toString() }.toString()))
810
+ when (error.err) {
811
+ RetryableSendFailure .LDKRetryableSendFailure_DuplicatePayment -> {
812
+ handleReject(promise, LdkErrors .invoice_payment_fail_duplicate_payment)
804
813
}
805
814
806
- val paymentParameterError = sendingError.sending as ? PaymentSendFailure .ParameterError
807
- if (paymentParameterError != null ) {
808
- return handleReject(promise, LdkErrors .invoice_payment_fail_parameter_error, Error (paymentParameterError.parameter_error.toString()))
815
+ RetryableSendFailure .LDKRetryableSendFailure_PaymentExpired -> {
816
+ handleReject(promise, LdkErrors .invoice_payment_fail_payment_expired)
809
817
}
810
818
811
- val paymentPartialFailure = sendingError.sending as ? PaymentSendFailure .PartialFailure
812
- if (paymentPartialFailure != null ) {
813
- return handleReject(promise, LdkErrors .invoice_payment_fail_partial, Error (paymentPartialFailure.toString()))
819
+ RetryableSendFailure .LDKRetryableSendFailure_RouteNotFound -> {
820
+ handleReject(promise, LdkErrors .invoice_payment_fail_route_not_found)
814
821
}
815
822
816
- val paymentPathParameterError = sendingError.sending as ? PaymentSendFailure .PathParameterError
817
- if (paymentPathParameterError != null ) {
818
- return handleReject(promise, LdkErrors .invoice_payment_fail_path_parameter_error, Error (paymentPartialFailure.toString()))
819
- }
820
-
821
- return handleReject(promise, LdkErrors .invoice_payment_fail_sending, Error (" PaymentError.Sending" ))
823
+ else -> handleReject(promise, LdkErrors .invoice_payment_fail_unknown)
822
824
}
823
-
824
- return handleReject(promise, LdkErrors .invoice_payment_fail_unknown)
825
825
}
826
826
827
827
@ReactMethod
@@ -1090,7 +1090,7 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
1090
1090
1091
1091
val output = TxOut (outputValue.toLong(), outputScriptPubKey.hexa())
1092
1092
val outpoint = OutPoint .of(outpointTxId.hexa().reversedArray(), outpointIndex.toInt().toShort())
1093
- val descriptor = SpendableOutputDescriptor .static_output(outpoint, output)
1093
+ val descriptor = SpendableOutputDescriptor .static_output(outpoint, output, byteArrayOf() )
1094
1094
1095
1095
val ldkDescriptors: MutableList <SpendableOutputDescriptor > = arrayListOf ()
1096
1096
ldkDescriptors.add(descriptor)
0 commit comments