Skip to content

Commit

Permalink
Merge pull request #226 from synonymdev/ldk-121
Browse files Browse the repository at this point in the history
feat: update bindings to 0.0.121
  • Loading branch information
Jasonvdb committed Mar 22, 2024
2 parents 94b0741 + 5ba9f2e commit d99ad68
Show file tree
Hide file tree
Showing 42 changed files with 53,163 additions and 41,170 deletions.
Binary file modified lib/android/libs/LDK-release.aar
Binary file not shown.
Binary file modified lib/android/libs/ldk-java-javadoc.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/android/src/main/java/com/reactnativeldk/Helpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ val Bolt11Invoice.asJson: WritableMap
val rawInvoice = signedInv.raw_invoice()

if (amount_milli_satoshis() is Option_u64Z.Some) result.putInt("amount_satoshis", ((amount_milli_satoshis() as Option_u64Z.Some).some.toInt() / 1000)) else result.putNull("amount_satoshis")
result.putString("description", rawInvoice.description()?.into_inner())
result.putString("description", rawInvoice.description()?.to_str())
result.putBoolean("check_signature", signedInv.check_signature())
result.putBoolean("is_expired", is_expired)
result.putInt("duration_since_epoch", duration_since_epoch().toInt())
Expand Down
76 changes: 38 additions & 38 deletions lib/android/src/main/java/com/reactnativeldk/LdkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ import org.ldk.batteries.NioPeerHandler
import org.ldk.enums.Currency
import org.ldk.enums.Network
import org.ldk.enums.Recipient
import org.ldk.enums.RetryableSendFailure
import org.ldk.impl.bindings.LDKPaymentSendFailure.DuplicatePayment
import org.ldk.impl.bindings.get_ldk_c_bindings_version
import org.ldk.impl.bindings.get_ldk_version
import org.ldk.structs.*
import org.ldk.structs.Result_Bolt11InvoiceParseOrSemanticErrorZ.Result_Bolt11InvoiceParseOrSemanticErrorZ_OK
import org.ldk.structs.Result_Bolt11InvoiceSignOrCreationErrorZ.Result_Bolt11InvoiceSignOrCreationErrorZ_OK
import org.ldk.structs.Result_C2Tuple_ThirtyTwoBytesChannelMonitorZDecodeErrorZ.Result_C2Tuple_ThirtyTwoBytesChannelMonitorZDecodeErrorZ_OK
import org.ldk.structs.Result_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ.Result_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ_OK
import org.ldk.structs.Result_NoneRetryableSendFailureZ.Result_NoneRetryableSendFailureZ_Err
import org.ldk.structs.Result_PublicKeyNoneZ.Result_PublicKeyNoneZ_OK
import org.ldk.structs.Result_StrSecp256k1ErrorZ.Result_StrSecp256k1ErrorZ_OK
import org.ldk.util.UInt128
Expand Down Expand Up @@ -73,11 +77,9 @@ enum class LdkErrors {
invoice_payment_fail_must_specify_amount,
invoice_payment_fail_must_not_specify_amount,
invoice_payment_fail_invoice,
invoice_payment_fail_sending,
invoice_payment_fail_resend_safe,
invoice_payment_fail_parameter_error,
invoice_payment_fail_partial,
invoice_payment_fail_path_parameter_error,
invoice_payment_fail_duplicate_payment,
invoice_payment_fail_payment_expired,
invoice_payment_fail_route_not_found,
init_ldk_currency,
invoice_create_failed,
init_scorer_failed,
Expand Down Expand Up @@ -564,8 +566,8 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
//MARK: Update methods

@ReactMethod
fun updateFees(anchorChannelFee: Double, nonAnchorChannelFee: Double, channelCloseMinimum: Double, minAllowedAnchorChannelRemoteFee: Double, maxAllowedNonAnchorChannelRemoteFee: Double, onChainSweep: Double, minAllowedNonAnchorChannelRemoteFee: Double, promise: Promise) {
feeEstimator.update(anchorChannelFee.toInt(), nonAnchorChannelFee.toInt(), channelCloseMinimum.toInt(), minAllowedAnchorChannelRemoteFee.toInt(), maxAllowedNonAnchorChannelRemoteFee.toInt(), onChainSweep.toInt(), minAllowedNonAnchorChannelRemoteFee.toInt())
fun updateFees(anchorChannelFee: Double, nonAnchorChannelFee: Double, channelCloseMinimum: Double, minAllowedAnchorChannelRemoteFee: Double, onChainSweep: Double, minAllowedNonAnchorChannelRemoteFee: Double, promise: Promise) {
feeEstimator.update(anchorChannelFee.toInt(), nonAnchorChannelFee.toInt(), channelCloseMinimum.toInt(), minAllowedAnchorChannelRemoteFee.toInt(), onChainSweep.toInt(), minAllowedNonAnchorChannelRemoteFee.toInt())
handleResolve(promise, LdkCallbackResponses.fees_updated)
}

Expand Down Expand Up @@ -772,14 +774,27 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
return handleReject(promise, LdkErrors.invoice_payment_fail_must_not_specify_amount)
}

val res = if (isZeroValueInvoice)
UtilMethods.pay_zero_value_invoice(invoice, amountSats.toLong() * 1000, Retry.timeout(timeoutSeconds.toLong()), channelManager) else
UtilMethods.pay_invoice(invoice, Retry.timeout(timeoutSeconds.toLong()), channelManager)
val paymentId = invoice.payment_hash()
val detailsRes = if (isZeroValueInvoice)
UtilMethods.payment_parameters_from_zero_amount_invoice(invoice, amountSats.toLong()) else
UtilMethods.payment_parameters_from_invoice(invoice)

if (!detailsRes.is_ok) {
return handleReject(promise, LdkErrors.invoice_payment_fail_invoice)
}

val sendDetails = detailsRes as Result_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ_OK
val paymentHash = sendDetails.res._a
val recipientOnion = sendDetails.res._b
val routeParams = sendDetails.res._c

val res = channelManager!!.send_payment(paymentHash, recipientOnion, paymentId, routeParams, Retry.timeout(timeoutSeconds.toLong()))

if (res.is_ok) {
channelManagerPersister.persistPaymentSent(hashMapOf(
"bolt11_invoice" to paymentRequest,
"description" to (invoice.into_signed_raw().raw_invoice().description()?.into_inner() ?: ""),
"payment_id" to (res as Result_ThirtyTwoBytesPaymentErrorZ.Result_ThirtyTwoBytesPaymentErrorZ_OK).res.hexEncodedString(),
"description" to (invoice.into_signed_raw().raw_invoice().description()?.to_str() ?: ""),
"payment_id" to paymentId.hexEncodedString(),
"payment_hash" to invoice.payment_hash().hexEncodedString(),
"amount_sat" to if (isZeroValueInvoice) amountSats.toLong() else ((invoice.amount_milli_satoshis() as Option_u64Z.Some).some.toInt() / 1000),
"unix_timestamp" to (System.currentTimeMillis() / 1000).toInt(),
Expand All @@ -789,39 +804,24 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
return handleResolve(promise, LdkCallbackResponses.invoice_payment_success)
}

val error = res as? Result_ThirtyTwoBytesPaymentErrorZ.Result_ThirtyTwoBytesPaymentErrorZ_Err
val error = res as? Result_NoneRetryableSendFailureZ_Err
?: return handleReject(promise, LdkErrors.invoice_payment_fail_unknown)

val invoiceError = error?.err as? PaymentError.Invoice
if (invoiceError != null) {
return handleReject(promise, LdkErrors.invoice_payment_fail_invoice, Error(invoiceError.invoice))
}

val sendingError = error?.err as? PaymentError.Sending
if (sendingError != null) {
val paymentAllFailedResendSafe = sendingError.sending as? PaymentSendFailure.AllFailedResendSafe
if (paymentAllFailedResendSafe != null) {
return handleReject(promise, LdkErrors.invoice_payment_fail_resend_safe, Error(paymentAllFailedResendSafe.all_failed_resend_safe.map { it.toString() }.toString()))
when (error.err) {
RetryableSendFailure.LDKRetryableSendFailure_DuplicatePayment -> {
handleReject(promise, LdkErrors.invoice_payment_fail_duplicate_payment)
}

val paymentParameterError = sendingError.sending as? PaymentSendFailure.ParameterError
if (paymentParameterError != null) {
return handleReject(promise, LdkErrors.invoice_payment_fail_parameter_error, Error(paymentParameterError.parameter_error.toString()))
RetryableSendFailure.LDKRetryableSendFailure_PaymentExpired -> {
handleReject(promise, LdkErrors.invoice_payment_fail_payment_expired)
}

val paymentPartialFailure = sendingError.sending as? PaymentSendFailure.PartialFailure
if (paymentPartialFailure != null) {
return handleReject(promise, LdkErrors.invoice_payment_fail_partial, Error(paymentPartialFailure.toString()))
RetryableSendFailure.LDKRetryableSendFailure_RouteNotFound -> {
handleReject(promise, LdkErrors.invoice_payment_fail_route_not_found)
}

val paymentPathParameterError = sendingError.sending as? PaymentSendFailure.PathParameterError
if (paymentPathParameterError != null) {
return handleReject(promise, LdkErrors.invoice_payment_fail_path_parameter_error, Error(paymentPartialFailure.toString()))
}

return handleReject(promise, LdkErrors.invoice_payment_fail_sending, Error("PaymentError.Sending"))
else -> handleReject(promise, LdkErrors.invoice_payment_fail_unknown)
}

return handleReject(promise, LdkErrors.invoice_payment_fail_unknown)
}

@ReactMethod
Expand Down Expand Up @@ -1090,7 +1090,7 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod

val output = TxOut(outputValue.toLong(), outputScriptPubKey.hexa())
val outpoint = OutPoint.of(outpointTxId.hexa().reversedArray(), outpointIndex.toInt().toShort())
val descriptor = SpendableOutputDescriptor.static_output(outpoint, output)
val descriptor = SpendableOutputDescriptor.static_output(outpoint, output, byteArrayOf())

val ldkDescriptors: MutableList<SpendableOutputDescriptor> = arrayListOf()
ldkDescriptors.add(descriptor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import org.ldk.structs.Result_ShutdownScriptNoneZ
import org.ldk.structs.Result_TransactionNoneZ
import org.ldk.structs.Result_WriteableEcdsaChannelSignerDecodeErrorZ
import org.ldk.structs.ShutdownScript
import org.ldk.structs.SignerProvider
import org.ldk.structs.SignerProvider.SignerProviderInterface
import org.ldk.structs.SpendableOutputDescriptor
import org.ldk.structs.TxOut
import org.ldk.structs.WitnessProgram
import org.ldk.structs.WriteableEcdsaChannelSigner
import org.ldk.util.UInt128
import org.ldk.util.WitnessVersion
Expand Down Expand Up @@ -59,15 +59,13 @@ class CustomKeysManager(
class CustomSignerProvider : SignerProviderInterface {
lateinit var customKeysManager: CustomKeysManager

override fun get_destination_script(): Result_CVec_u8ZNoneZ {
override fun get_destination_script(p0: ByteArray?): Result_CVec_u8ZNoneZ {
return Result_CVec_u8ZNoneZ.ok(customKeysManager.destinationScriptPublicKey)
}

override fun get_shutdown_scriptpubkey(): Result_ShutdownScriptNoneZ {
val res = ShutdownScript.new_witness_program(
WitnessVersion(customKeysManager.witnessProgramVersion),
customKeysManager.witnessProgram
)
val witness = WitnessProgram(customKeysManager.witnessProgram, WitnessVersion(customKeysManager.witnessProgramVersion))
val res = ShutdownScript.new_witness_program(witness)

return if (res.is_ok) {
Result_ShutdownScriptNoneZ.ok((res as Result_ShutdownScriptInvalidShutdownScriptZ.Result_ShutdownScriptInvalidShutdownScriptZ_OK).res)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ class LdkFeeEstimator {
var nonAnchorChannelFee: Int = 0
var channelCloseMinimum: Int = 0
var minAllowedAnchorChannelRemoteFee: Int = 0
var maxAllowedNonAnchorChannelRemoteFee: Int = 0
var onChainSweep: Int = 0
var minAllowedNonAnchorChannelRemoteFee: Int = 0

fun update(anchorChannelFee: Int, nonAnchorChannelFee: Int, channelCloseMinimum: Int, minAllowedAnchorChannelRemoteFee: Int, maxAllowedNonAnchorChannelRemoteFee: Int, onChainSweep: Int, minAllowedNonAnchorChannelRemoteFee: Int) {
fun update(anchorChannelFee: Int, nonAnchorChannelFee: Int, channelCloseMinimum: Int, minAllowedAnchorChannelRemoteFee: Int, onChainSweep: Int, minAllowedNonAnchorChannelRemoteFee: Int) {
this.anchorChannelFee = anchorChannelFee
this.nonAnchorChannelFee = nonAnchorChannelFee
this.channelCloseMinimum = channelCloseMinimum
this.minAllowedAnchorChannelRemoteFee = minAllowedAnchorChannelRemoteFee
this.maxAllowedNonAnchorChannelRemoteFee = maxAllowedNonAnchorChannelRemoteFee
this.onChainSweep = onChainSweep
this.minAllowedNonAnchorChannelRemoteFee = minAllowedNonAnchorChannelRemoteFee

Expand All @@ -31,7 +29,6 @@ class LdkFeeEstimator {
ConfirmationTarget.LDKConfirmationTarget_NonAnchorChannelFee -> nonAnchorChannelFee
ConfirmationTarget.LDKConfirmationTarget_ChannelCloseMinimum -> channelCloseMinimum
ConfirmationTarget.LDKConfirmationTarget_MinAllowedAnchorChannelRemoteFee -> minAllowedAnchorChannelRemoteFee
ConfirmationTarget.LDKConfirmationTarget_MaxAllowedNonAnchorChannelRemoteFee -> maxAllowedNonAnchorChannelRemoteFee
ConfirmationTarget.LDKConfirmationTarget_OnChainSweep -> onChainSweep
ConfirmationTarget.LDKConfirmationTarget_MinAllowedNonAnchorChannelRemoteFee -> minAllowedNonAnchorChannelRemoteFee
else -> {
Expand Down
4 changes: 2 additions & 2 deletions lib/ios/Classes/CustomKeysManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ class CustomKeysManager {
class CustomSignerProvider: SignerProvider {
weak var customKeysManager: CustomKeysManager?

override func getDestinationScript() -> Bindings.Result_CVec_u8ZNoneZ {
override func getDestinationScript(channelKeysId: [UInt8]) -> Bindings.Result_CVec_u8ZNoneZ {
let destinationScriptPublicKey = customKeysManager!.destinationScriptPublicKey
return Bindings.Result_CVec_u8ZNoneZ.initWithOk(o: destinationScriptPublicKey)
}

override func getShutdownScriptpubkey() -> Bindings.Result_ShutdownScriptNoneZ {
let res = ShutdownScript.newWitnessProgram(version: customKeysManager!.witnessProgramVersion, program: customKeysManager!.witnessProgram)
let res = ShutdownScript.newWitnessProgram(witnessProgram: .init(version: customKeysManager!.witnessProgramVersion, program: customKeysManager!.witnessProgram))
if res.isOk() {
return Bindings.Result_ShutdownScriptNoneZ.initWithOk(o: res.getValue()!)
}
Expand Down
5 changes: 3 additions & 2 deletions lib/ios/Classes/LdkChannelManagerPersister.swift
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,7 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
}

LdkEventEmitter.shared.send(withEvent: .native_log, body: "TODO📣: BumpTransaction")

return

case .ProbeFailed:
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Unused Persister event: ProbeFailed")
return
Expand All @@ -314,6 +312,9 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
case .HTLCHandlingFailed:
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Unused Persister event: HTLCHandlingFailed")
return
case .ConnectionNeeded:
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Unused Persister event: ConnectionNeeded")
return
}
}

Expand Down
6 changes: 1 addition & 5 deletions lib/ios/Classes/LdkFeeEstimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ class LdkFeeEstimator: FeeEstimator {
private var nonAnchorChannelFee: UInt32 = 0
private var channelCloseMinimum: UInt32 = 0
private var minAllowedAnchorChannelRemoteFee: UInt32 = 0
private var maxAllowedNonAnchorChannelRemoteFee: UInt32 = 0
private var onChainSweep: UInt32 = 0
private var minAllowedNonAnchorChannelRemoteFee: UInt32 = 0

func update(anchorChannelFee: UInt32, nonAnchorChannelFee: UInt32, channelCloseMinimum: UInt32, minAllowedAnchorChannelRemoteFee: UInt32, maxAllowedNonAnchorChannelRemoteFee: UInt32, onChainSweep: UInt32, minAllowedNonAnchorChannelRemoteFee: UInt32) {
func update(anchorChannelFee: UInt32, nonAnchorChannelFee: UInt32, channelCloseMinimum: UInt32, minAllowedAnchorChannelRemoteFee: UInt32, onChainSweep: UInt32, minAllowedNonAnchorChannelRemoteFee: UInt32) {
self.anchorChannelFee = anchorChannelFee
self.nonAnchorChannelFee = nonAnchorChannelFee
self.channelCloseMinimum = channelCloseMinimum
self.minAllowedAnchorChannelRemoteFee = minAllowedAnchorChannelRemoteFee
self.maxAllowedNonAnchorChannelRemoteFee = maxAllowedNonAnchorChannelRemoteFee
self.onChainSweep = onChainSweep
self.minAllowedNonAnchorChannelRemoteFee = minAllowedNonAnchorChannelRemoteFee

Expand All @@ -41,8 +39,6 @@ class LdkFeeEstimator: FeeEstimator {
return channelCloseMinimum
case .MinAllowedAnchorChannelRemoteFee:
return minAllowedAnchorChannelRemoteFee
case .MaxAllowedNonAnchorChannelRemoteFee:
return maxAllowedNonAnchorChannelRemoteFee
case .OnChainSweep:
return onChainSweep
case .MinAllowedNonAnchorChannelRemoteFee:
Expand Down
46 changes: 2 additions & 44 deletions lib/ios/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,11 @@ extension Bolt11Invoice {
//Break down to get the decription. Will crash if all on a single line.
let signedRawInvoice = intoSignedRaw()
let rawInvoice = signedRawInvoice.rawInvoice()
let description = rawInvoice.description()
let descriptionString = description?.intoInner() ?? ""
let description = rawInvoice.description()?.intoInner().getA() ?? ""

return [
"amount_satoshis": amountMilliSatoshis() != nil ? amountMilliSatoshis()! / 1000 : nil,
"description": descriptionString,
"description": description,
"check_signature": checkSignature().isOk(),
"is_expired": isExpired(),
"duration_since_epoch": durationSinceEpoch(),
Expand Down Expand Up @@ -465,47 +464,6 @@ extension ChainMonitor {
}
}

func handlePaymentSendFailure(_ reject: RCTPromiseRejectBlock, error: Bindings.PaymentSendFailure) {
switch error.getValueType() {
case .AllFailedResendSafe:
// let errorMessage = ""
// error.getValueAsAllFailedRetrySafe()?.forEach({ apiError in
// apiError.getValueType() //TODO iterate through all
// })

return handleReject(reject, .invoice_payment_fail_resend_safe, nil, error.getValueAsAllFailedResendSafe().map { $0.description } )
case .ParameterError:
guard let parameterError = error.getValueAsParameterError() else {
return handleReject(reject, .invoice_payment_fail_parameter_error)
}

let parameterErrorType = parameterError.getValueType()

switch parameterErrorType {
case .APIMisuseError:
return handleReject(reject, .invoice_payment_fail_parameter_error, nil, "parameterError.getValueType().debugDescription")
case .FeeRateTooHigh:
return handleReject(reject, .invoice_payment_fail_parameter_error, nil, parameterError.getValueAsFeeRateTooHigh()?.getErr())
case .InvalidRoute:
return handleReject(reject, .invoice_payment_fail_parameter_error, nil, parameterError.getValueAsInvalidRoute()?.getErr())
case .ChannelUnavailable:
return handleReject(reject, .invoice_payment_fail_parameter_error, nil, parameterError.getValueAsChannelUnavailable()?.getErr())
case .IncompatibleShutdownScript:
return handleReject(reject, .invoice_payment_fail_parameter_error, nil, "IncompatibleShutdownScript")
case .MonitorUpdateInProgress:
return handleReject(reject, .invoice_payment_fail_parameter_error, nil, "MonitorUpdateInProgress")
@unknown default:
return handleReject(reject, .invoice_payment_fail_parameter_error, nil, error.getValueAsParameterError().debugDescription)
}
case .PartialFailure:
return handleReject(reject, .invoice_payment_fail_partial, nil, error.getValueAsPartialFailure().debugDescription)
case .PathParameterError:
return handleReject(reject, .invoice_payment_fail_path_parameter_error, nil, error.getValueAsPartialFailure().debugDescription)
default:
return handleReject(reject, .invoice_payment_fail_sending)
}
}

/// Helper for returning real network and currency as a tuple from a string
/// - Parameter network: network name from JS
/// - Returns: network and currency tuple
Expand Down
Loading

0 comments on commit d99ad68

Please sign in to comment.