From 5502fccd64611f16f5ebba3759c68b1a4d69b537 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 24 Oct 2023 00:48:26 +0000 Subject: [PATCH] Update auto-generated bindings to LDK 0.0.118 --- lightning-c-bindings/include/ldk_rust_types.h | 8 +- lightning-c-bindings/include/lightning.h | 2222 +++++++++++------ lightning-c-bindings/include/lightningpp.hpp | 423 ++-- lightning-c-bindings/src/c_types/derived.rs | 954 ++++--- .../src/lightning/blinded_path/mod.rs | 19 +- .../src/lightning/blinded_path/payment.rs | 24 +- .../src/lightning/chain/chaininterface.rs | 197 +- .../src/lightning/chain/chainmonitor.rs | 27 +- .../src/lightning/chain/channelmonitor.rs | 36 +- .../src/lightning/chain/mod.rs | 18 +- .../src/lightning/chain/transaction.rs | 4 +- .../src/lightning/events/bump_transaction.rs | 417 +--- .../src/lightning/events/mod.rs | 198 +- .../src/lightning/ln/chan_utils.rs | 56 +- .../src/lightning/ln/channelmanager.rs | 255 +- .../src/lightning/ln/features.rs | 32 +- lightning-c-bindings/src/lightning/ln/msgs.rs | 336 ++- .../src/lightning/ln/outbound_payment.rs | 48 +- .../src/lightning/ln/peer_handler.rs | 126 +- .../src/lightning/ln/script.rs | 6 +- lightning-c-bindings/src/lightning/ln/wire.rs | 2 + .../src/lightning/offers/invoice.rs | 10 +- .../src/lightning/offers/invoice_error.rs | 14 +- .../src/lightning/offers/invoice_request.rs | 8 +- .../src/lightning/offers/offer.rs | 18 +- .../src/lightning/offers/parse.rs | 22 +- .../src/lightning/offers/refund.rs | 14 +- .../src/lightning/onion_message/messenger.rs | 314 ++- .../src/lightning/onion_message/offers.rs | 38 +- .../src/lightning/onion_message/packet.rs | 174 +- .../src/lightning/routing/gossip.rs | 96 +- .../src/lightning/routing/router.rs | 57 +- .../src/lightning/routing/scoring.rs | 75 +- .../src/lightning/routing/utxo.rs | 33 +- lightning-c-bindings/src/lightning/sign.rs | 546 +++- .../src/lightning/util/config.rs | 44 +- .../src/lightning/util/errors.rs | 14 + .../src/lightning/util/logger.rs | 13 +- .../src/lightning/util/persist.rs | 8 +- .../src/lightning/util/ser.rs | 12 +- .../src/lightning/util/string.rs | 4 +- .../src/lightning/util/wakers.rs | 3 +- .../src/lightning_background_processor.rs | 5 + .../src/lightning_invoice/mod.rs | 104 +- .../src/lightning_invoice/payment.rs | 20 + .../src/lightning_persister/fs_store.rs | 6 +- .../src/lightning_rapid_gossip_sync/error.rs | 10 + 47 files changed, 4650 insertions(+), 2420 deletions(-) diff --git a/lightning-c-bindings/include/ldk_rust_types.h b/lightning-c-bindings/include/ldk_rust_types.h index a8f431a..f8e660e 100644 --- a/lightning-c-bindings/include/ldk_rust_types.h +++ b/lightning-c-bindings/include/ldk_rust_types.h @@ -24,6 +24,10 @@ struct nativeDelayedPaymentOutputDescriptorOpaque; typedef struct nativeDelayedPaymentOutputDescriptorOpaque LDKnativeDelayedPaymentOutputDescriptor; struct nativeStaticPaymentOutputDescriptorOpaque; typedef struct nativeStaticPaymentOutputDescriptorOpaque LDKnativeStaticPaymentOutputDescriptor; +struct nativeChannelDerivationParametersOpaque; +typedef struct nativeChannelDerivationParametersOpaque LDKnativeChannelDerivationParameters; +struct nativeHTLCDescriptorOpaque; +typedef struct nativeHTLCDescriptorOpaque LDKnativeHTLCDescriptor; struct LDKChannelSigner; struct nativeInMemorySignerOpaque; typedef struct nativeInMemorySignerOpaque LDKnativeInMemorySigner; @@ -121,12 +125,8 @@ struct nativeNodeAliasOpaque; typedef struct nativeNodeAliasOpaque LDKnativeNodeAlias; struct nativeNodeInfoOpaque; typedef struct nativeNodeInfoOpaque LDKnativeNodeInfo; -struct nativeChannelDerivationParametersOpaque; -typedef struct nativeChannelDerivationParametersOpaque LDKnativeChannelDerivationParameters; struct nativeAnchorDescriptorOpaque; typedef struct nativeAnchorDescriptorOpaque LDKnativeAnchorDescriptor; -struct nativeHTLCDescriptorOpaque; -typedef struct nativeHTLCDescriptorOpaque LDKnativeHTLCDescriptor; struct nativeInputOpaque; typedef struct nativeInputOpaque LDKnativeInput; struct nativeUtxoOpaque; diff --git a/lightning-c-bindings/include/lightning.h b/lightning-c-bindings/include/lightning.h index 7c9183c..cc60687 100644 --- a/lightning-c-bindings/include/lightning.h +++ b/lightning-c-bindings/include/lightning.h @@ -150,6 +150,10 @@ typedef enum LDKBolt12SemanticError { * A payer id was expected but was missing. */ LDKBolt12SemanticError_MissingPayerId, + /** + * The payment id for a refund or request is already in use. + */ + LDKBolt12SemanticError_DuplicatePaymentId, /** * Blinded paths were expected but were missing. */ @@ -316,28 +320,111 @@ typedef enum LDKChannelShutdownState { */ typedef enum LDKConfirmationTarget { /** - * We'd like a transaction to confirm in the future, but don't want to commit most of the fees - * required to do so yet. The remaining fees will come via a Child-Pays-For-Parent (CPFP) fee - * bump of the transaction. + * We have some funds available on chain which we need to spend prior to some expiry time at + * which point our counterparty may be able to steal them. Generally we have in the high tens + * to low hundreds of blocks to get our transaction on-chain, but we shouldn't risk too low a + * fee - this should be a relatively high priority feerate. + */ + LDKConfirmationTarget_OnChainSweep, + /** + * The highest feerate we will allow our channel counterparty to have in a non-anchor channel. + * + * This is the feerate on the transaction which we (or our counterparty) will broadcast in + * order to close the channel unilaterally. Because our counterparty must ensure they can + * always broadcast the latest state, this value being too low will cause immediate + * force-closures. * - * The feerate returned should be the absolute minimum feerate required to enter most node - * mempools across the network. Note that if you are not able to obtain this feerate estimate, - * you should likely use the furthest-out estimate allowed by your fee estimator. + * Allowing this value to be too high can allow our counterparty to burn our HTLC outputs to + * dust, which can result in HTLCs failing or force-closures (when the dust HTLCs exceed + * [`ChannelConfig::max_dust_htlc_exposure`]). + * + * Because most nodes use a feerate estimate which is based on a relatively high priority + * transaction entering the current mempool, setting this to a small multiple of your current + * high priority feerate estimate should suffice. + * + * [`ChannelConfig::max_dust_htlc_exposure`]: crate::util::config::ChannelConfig::max_dust_htlc_exposure */ - LDKConfirmationTarget_MempoolMinimum, + LDKConfirmationTarget_MaxAllowedNonAnchorChannelRemoteFee, /** - * We are happy with a transaction confirming slowly, at least within a day or so worth of - * blocks. + * This is the lowest feerate we will allow our channel counterparty to have in an anchor + * channel in order to close the channel if a channel party goes away. + * + * This needs to be sufficient to get into the mempool when the channel needs to + * be force-closed. Setting too high may result in force-closures if our counterparty attempts + * to use a lower feerate. Because this is for anchor channels, we can always bump the feerate + * later; the feerate here only needs to be sufficient to enter the mempool. + * + * A good estimate is the expected mempool minimum at the time of force-closure. Obviously this + * is not an estimate which is very easy to calculate because we do not know the future. Using + * a simple long-term fee estimate or tracking of the mempool minimum is a good approach to + * ensure you can always close the channel. A future change to Bitcoin's P2P network + * (package relay) may obviate the need for this entirely. + */ + LDKConfirmationTarget_MinAllowedAnchorChannelRemoteFee, + /** + * The lowest feerate we will allow our channel counterparty to have in a non-anchor channel. + * + * This is the feerate on the transaction which we (or our counterparty) will broadcast in + * order to close the channel if a channel party goes away. Setting this value too high will + * cause immediate force-closures in order to avoid having an unbroadcastable state. + * + * This feerate represents the fee we pick now, which must be sufficient to enter a block at an + * arbitrary time in the future. Obviously this is not an estimate which is very easy to + * calculate. This can leave channels subject to being unable to close if feerates rise, and in + * general you should prefer anchor channels to ensure you can increase the feerate when the + * transactions need broadcasting. + * + * Do note some fee estimators round up to the next full sat/vbyte (ie 250 sats per kw), + * causing occasional issues with feerate disagreements between an initiator that wants a + * feerate of 1.1 sat/vbyte and a receiver that wants 1.1 rounded up to 2. If your fee + * estimator rounds subtracting 250 to your desired feerate here can help avoid this issue. + * + * [`ChannelConfig::max_dust_htlc_exposure`]: crate::util::config::ChannelConfig::max_dust_htlc_exposure + */ + LDKConfirmationTarget_MinAllowedNonAnchorChannelRemoteFee, + /** + * This is the feerate on the transaction which we (or our counterparty) will broadcast in + * order to close the channel if a channel party goes away. + * + * This needs to be sufficient to get into the mempool when the channel needs to + * be force-closed. Setting too low may result in force-closures. Because this is for anchor + * channels, it can be a low value as we can always bump the feerate later. + * + * A good estimate is the expected mempool minimum at the time of force-closure. Obviously this + * is not an estimate which is very easy to calculate because we do not know the future. Using + * a simple long-term fee estimate or tracking of the mempool minimum is a good approach to + * ensure you can always close the channel. A future change to Bitcoin's P2P network + * (package relay) may obviate the need for this entirely. */ - LDKConfirmationTarget_Background, + LDKConfirmationTarget_AnchorChannelFee, /** - * We'd like a transaction to confirm without major delayed, i.e., within the next 12-24 blocks. + * Lightning is built around the ability to broadcast a transaction in the future to close our + * channel and claim all pending funds. In order to do so, non-anchor channels are built with + * transactions which we need to be able to broadcast at some point in the future. + * + * This feerate represents the fee we pick now, which must be sufficient to enter a block at an + * arbitrary time in the future. Obviously this is not an estimate which is very easy to + * calculate, so most lightning nodes use some relatively high-priority feerate using the + * current mempool. This leaves channels subject to being unable to close if feerates rise, and + * in general you should prefer anchor channels to ensure you can increase the feerate when the + * transactions need broadcasting. + * + * Since this should represent the feerate of a channel close that does not need fee + * bumping, this is also used as an upper bound for our attempted feerate when doing cooperative + * closure of any channel. */ - LDKConfirmationTarget_Normal, + LDKConfirmationTarget_NonAnchorChannelFee, /** - * We'd like a transaction to confirm in the next few blocks. + * When cooperatively closing a channel, this is the minimum feerate we will accept. + * Recommended at least within a day or so worth of blocks. + * + * This will also be used when initiating a cooperative close of a channel. When closing a + * channel you can override this fee by using + * [`ChannelManager::close_channel_with_feerate_and_script`]. + * + * [`ChannelManager::close_channel_with_feerate_and_script`]: crate::ln::channelmanager::ChannelManager::close_channel_with_feerate_and_script */ - LDKConfirmationTarget_HighPriority, + LDKConfirmationTarget_ChannelCloseMinimum, /** * Must be last for serialization purposes */ @@ -2128,6 +2215,112 @@ typedef struct LDKCResult_C2Tuple_CVec_u8ZusizeZNoneZ { bool result_ok; } LDKCResult_C2Tuple_CVec_u8ZusizeZNoneZ; + + +/** + * The parameters required to derive a channel signer via [`SignerProvider`]. + */ +typedef struct MUST_USE_STRUCT LDKChannelDerivationParameters { + /** + * A pointer to the opaque Rust object. + * Nearly everywhere, inner must be non-null, however in places where + * the Rust equivalent takes an Option, it may be set to null to indicate None. + */ + LDKnativeChannelDerivationParameters *inner; + /** + * Indicates that this is the only struct which contains the same pointer. + * Rust functions which take ownership of an object provided via an argument require + * this to be true and invalidate the object pointed to by inner. + */ + bool is_owned; +} LDKChannelDerivationParameters; + +/** + * The contents of CResult_ChannelDerivationParametersDecodeErrorZ + */ +typedef union LDKCResult_ChannelDerivationParametersDecodeErrorZPtr { + /** + * A pointer to the contents in the success state. + * Reading from this pointer when `result_ok` is not set is undefined. + */ + struct LDKChannelDerivationParameters *result; + /** + * A pointer to the contents in the error state. + * Reading from this pointer when `result_ok` is set is undefined. + */ + struct LDKDecodeError *err; +} LDKCResult_ChannelDerivationParametersDecodeErrorZPtr; + +/** + * A CResult_ChannelDerivationParametersDecodeErrorZ represents the result of a fallible operation, + * containing a crate::lightning::sign::ChannelDerivationParameters on success and a crate::lightning::ln::msgs::DecodeError on failure. + * `result_ok` indicates the overall state, and the contents are provided via `contents`. + */ +typedef struct LDKCResult_ChannelDerivationParametersDecodeErrorZ { + /** + * The contents of this CResult_ChannelDerivationParametersDecodeErrorZ, accessible via either + * `err` or `result` depending on the state of `result_ok`. + */ + union LDKCResult_ChannelDerivationParametersDecodeErrorZPtr contents; + /** + * Whether this CResult_ChannelDerivationParametersDecodeErrorZ represents a success state. + */ + bool result_ok; +} LDKCResult_ChannelDerivationParametersDecodeErrorZ; + + + +/** + * A descriptor used to sign for a commitment transaction's HTLC output. + */ +typedef struct MUST_USE_STRUCT LDKHTLCDescriptor { + /** + * A pointer to the opaque Rust object. + * Nearly everywhere, inner must be non-null, however in places where + * the Rust equivalent takes an Option, it may be set to null to indicate None. + */ + LDKnativeHTLCDescriptor *inner; + /** + * Indicates that this is the only struct which contains the same pointer. + * Rust functions which take ownership of an object provided via an argument require + * this to be true and invalidate the object pointed to by inner. + */ + bool is_owned; +} LDKHTLCDescriptor; + +/** + * The contents of CResult_HTLCDescriptorDecodeErrorZ + */ +typedef union LDKCResult_HTLCDescriptorDecodeErrorZPtr { + /** + * A pointer to the contents in the success state. + * Reading from this pointer when `result_ok` is not set is undefined. + */ + struct LDKHTLCDescriptor *result; + /** + * A pointer to the contents in the error state. + * Reading from this pointer when `result_ok` is set is undefined. + */ + struct LDKDecodeError *err; +} LDKCResult_HTLCDescriptorDecodeErrorZPtr; + +/** + * A CResult_HTLCDescriptorDecodeErrorZ represents the result of a fallible operation, + * containing a crate::lightning::sign::HTLCDescriptor on success and a crate::lightning::ln::msgs::DecodeError on failure. + * `result_ok` indicates the overall state, and the contents are provided via `contents`. + */ +typedef struct LDKCResult_HTLCDescriptorDecodeErrorZ { + /** + * The contents of this CResult_HTLCDescriptorDecodeErrorZ, accessible via either + * `err` or `result` depending on the state of `result_ok`. + */ + union LDKCResult_HTLCDescriptorDecodeErrorZPtr contents; + /** + * Whether this CResult_HTLCDescriptorDecodeErrorZ represents a success state. + */ + bool result_ok; +} LDKCResult_HTLCDescriptorDecodeErrorZ; + /** * The contents of CResult_NoneNoneZ */ @@ -2510,26 +2703,6 @@ typedef struct MUST_USE_STRUCT LDKHTLCOutputInCommitment { -/** - * A descriptor used to sign for a commitment transaction's HTLC output. - */ -typedef struct MUST_USE_STRUCT LDKHTLCDescriptor { - /** - * A pointer to the opaque Rust object. - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeHTLCDescriptor *inner; - /** - * Indicates that this is the only struct which contains the same pointer. - * Rust functions which take ownership of an object provided via an argument require - * this to be true and invalidate the object pointed to by inner. - */ - bool is_owned; -} LDKHTLCDescriptor; - - - /** * This class tracks the per-transaction information needed to build a closing transaction and will * actually build it and sign. @@ -2735,23 +2908,17 @@ typedef struct LDKEcdsaChannelSigner { */ struct LDKCResult_NoneNoneZ (*validate_counterparty_revocation)(const void *this_arg, uint64_t idx, const uint8_t (*secret)[32]); /** - * Creates a signature for a holder's commitment transaction and its claiming HTLC transactions. + * Creates a signature for a holder's commitment transaction. * * This will be called * - with a non-revoked `commitment_tx`. * - with the latest `commitment_tx` when we initiate a force-close. - * - with the previous `commitment_tx`, just to get claiming HTLC - * signatures, if we are reacting to a [`ChannelMonitor`] - * [replica](https://github.com/lightningdevkit/rust-lightning/blob/main/GLOSSARY.md#monitor-replicas) - * that decided to broadcast before it had been updated to the latest `commitment_tx`. * * This may be called multiple times for the same transaction. * * An external signer implementation should check that the commitment has not been revoked. - * - * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor */ - struct LDKCResult_C2Tuple_ECDSASignatureCVec_ECDSASignatureZZNoneZ (*sign_holder_commitment_and_htlcs)(const void *this_arg, const struct LDKHolderCommitmentTransaction *NONNULL_PTR commitment_tx); + struct LDKCResult_ECDSASignatureNoneZ (*sign_holder_commitment)(const void *this_arg, const struct LDKHolderCommitmentTransaction *NONNULL_PTR commitment_tx); /** * Create a signature for the given input in a transaction spending an HTLC transaction output * or a commitment transaction `to_local` output when our counterparty broadcasts an old state. @@ -2793,11 +2960,14 @@ typedef struct LDKEcdsaChannelSigner { /** * Computes the signature for a commitment transaction's HTLC output used as an input within * `htlc_tx`, which spends the commitment transaction at index `input`. The signature returned - * must be be computed using [`EcdsaSighashType::All`]. Note that this should only be used to - * sign HTLC transactions from channels supporting anchor outputs after all additional - * inputs/outputs have been added to the transaction. + * must be be computed using [`EcdsaSighashType::All`]. + * + * Note that this may be called for HTLCs in the penultimate commitment transaction if a + * [`ChannelMonitor`] [replica](https://github.com/lightningdevkit/rust-lightning/blob/main/GLOSSARY.md#monitor-replicas) + * broadcasts it before receiving the update for the latest commitment transaction. * * [`EcdsaSighashType::All`]: bitcoin::blockdata::transaction::EcdsaSighashType::All + * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor */ struct LDKCResult_ECDSASignatureNoneZ (*sign_holder_htlc_transaction)(const void *this_arg, struct LDKTransaction htlc_tx, uintptr_t input, const struct LDKHTLCDescriptor *NONNULL_PTR htlc_descriptor); /** @@ -5464,12 +5634,12 @@ typedef struct LDKUtxoLookup { void *this_arg; /** * Returns the transaction output of a funding transaction encoded by [`short_channel_id`]. - * Returns an error if `genesis_hash` is for a different chain or if such a transaction output - * is unknown. + * Returns an error if `chain_hash` is for a different chain or if such a transaction output is + * unknown. * * [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id */ - struct LDKUtxoResult (*get_utxo)(const void *this_arg, const uint8_t (*genesis_hash)[32], uint64_t short_channel_id); + struct LDKUtxoResult (*get_utxo)(const void *this_arg, const uint8_t (*chain_hash)[32], uint64_t short_channel_id); /** * Frees any resources associated with this object given its this_arg pointer. * Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. @@ -7498,92 +7668,6 @@ typedef struct LDKCOption_CVec_SocketAddressZZ { }; } LDKCOption_CVec_SocketAddressZZ; - - -/** - * The parameters required to derive a channel signer via [`SignerProvider`]. - */ -typedef struct MUST_USE_STRUCT LDKChannelDerivationParameters { - /** - * A pointer to the opaque Rust object. - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeChannelDerivationParameters *inner; - /** - * Indicates that this is the only struct which contains the same pointer. - * Rust functions which take ownership of an object provided via an argument require - * this to be true and invalidate the object pointed to by inner. - */ - bool is_owned; -} LDKChannelDerivationParameters; - -/** - * The contents of CResult_ChannelDerivationParametersDecodeErrorZ - */ -typedef union LDKCResult_ChannelDerivationParametersDecodeErrorZPtr { - /** - * A pointer to the contents in the success state. - * Reading from this pointer when `result_ok` is not set is undefined. - */ - struct LDKChannelDerivationParameters *result; - /** - * A pointer to the contents in the error state. - * Reading from this pointer when `result_ok` is set is undefined. - */ - struct LDKDecodeError *err; -} LDKCResult_ChannelDerivationParametersDecodeErrorZPtr; - -/** - * A CResult_ChannelDerivationParametersDecodeErrorZ represents the result of a fallible operation, - * containing a crate::lightning::events::bump_transaction::ChannelDerivationParameters on success and a crate::lightning::ln::msgs::DecodeError on failure. - * `result_ok` indicates the overall state, and the contents are provided via `contents`. - */ -typedef struct LDKCResult_ChannelDerivationParametersDecodeErrorZ { - /** - * The contents of this CResult_ChannelDerivationParametersDecodeErrorZ, accessible via either - * `err` or `result` depending on the state of `result_ok`. - */ - union LDKCResult_ChannelDerivationParametersDecodeErrorZPtr contents; - /** - * Whether this CResult_ChannelDerivationParametersDecodeErrorZ represents a success state. - */ - bool result_ok; -} LDKCResult_ChannelDerivationParametersDecodeErrorZ; - -/** - * The contents of CResult_HTLCDescriptorDecodeErrorZ - */ -typedef union LDKCResult_HTLCDescriptorDecodeErrorZPtr { - /** - * A pointer to the contents in the success state. - * Reading from this pointer when `result_ok` is not set is undefined. - */ - struct LDKHTLCDescriptor *result; - /** - * A pointer to the contents in the error state. - * Reading from this pointer when `result_ok` is set is undefined. - */ - struct LDKDecodeError *err; -} LDKCResult_HTLCDescriptorDecodeErrorZPtr; - -/** - * A CResult_HTLCDescriptorDecodeErrorZ represents the result of a fallible operation, - * containing a crate::lightning::events::bump_transaction::HTLCDescriptor on success and a crate::lightning::ln::msgs::DecodeError on failure. - * `result_ok` indicates the overall state, and the contents are provided via `contents`. - */ -typedef struct LDKCResult_HTLCDescriptorDecodeErrorZ { - /** - * The contents of this CResult_HTLCDescriptorDecodeErrorZ, accessible via either - * `err` or `result` depending on the state of `result_ok`. - */ - union LDKCResult_HTLCDescriptorDecodeErrorZPtr contents; - /** - * Whether this CResult_HTLCDescriptorDecodeErrorZ represents a success state. - */ - bool result_ok; -} LDKCResult_HTLCDescriptorDecodeErrorZ; - /** * A dynamically-allocated array of crate::lightning::ln::chan_utils::HTLCOutputInCommitments of arbitrary size. * This corresponds to std::vector in C++ @@ -7601,7 +7685,7 @@ typedef struct LDKCVec_HTLCOutputInCommitmentZ { } LDKCVec_HTLCOutputInCommitmentZ; /** - * A dynamically-allocated array of crate::lightning::events::bump_transaction::HTLCDescriptors of arbitrary size. + * A dynamically-allocated array of crate::lightning::sign::HTLCDescriptors of arbitrary size. * This corresponds to std::vector in C++ */ typedef struct LDKCVec_HTLCDescriptorZ { @@ -8409,6 +8493,65 @@ typedef struct LDKCVec_C2Tuple_ThirtyTwoBytesPublicKeyZZ { uintptr_t datalen; } LDKCVec_C2Tuple_ThirtyTwoBytesPublicKeyZZ; +/** + * An enum which can either contain a crate::c_types::Str or not + */ +typedef enum LDKCOption_StrZ_Tag { + /** + * When we're in this state, this COption_StrZ contains a crate::c_types::Str + */ + LDKCOption_StrZ_Some, + /** + * When we're in this state, this COption_StrZ contains nothing + */ + LDKCOption_StrZ_None, + /** + * Must be last for serialization purposes + */ + LDKCOption_StrZ_Sentinel, +} LDKCOption_StrZ_Tag; + +typedef struct LDKCOption_StrZ { + LDKCOption_StrZ_Tag tag; + union { + struct { + struct LDKStr some; + }; + }; +} LDKCOption_StrZ; + +/** + * The contents of CResult_NoneBolt12SemanticErrorZ + */ +typedef union LDKCResult_NoneBolt12SemanticErrorZPtr { + /** + * Note that this value is always NULL, as there are no contents in the OK variant + */ + void *result; + /** + * A pointer to the contents in the error state. + * Reading from this pointer when `result_ok` is set is undefined. + */ + enum LDKBolt12SemanticError *err; +} LDKCResult_NoneBolt12SemanticErrorZPtr; + +/** + * A CResult_NoneBolt12SemanticErrorZ represents the result of a fallible operation, + * containing a () on success and a crate::lightning::offers::parse::Bolt12SemanticError on failure. + * `result_ok` indicates the overall state, and the contents are provided via `contents`. + */ +typedef struct LDKCResult_NoneBolt12SemanticErrorZ { + /** + * The contents of this CResult_NoneBolt12SemanticErrorZ, accessible via either + * `err` or `result` depending on the state of `result_ok`. + */ + union LDKCResult_NoneBolt12SemanticErrorZPtr contents; + /** + * Whether this CResult_NoneBolt12SemanticErrorZ represents a success state. + */ + bool result_ok; +} LDKCResult_NoneBolt12SemanticErrorZ; + /** * The contents of CResult_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ */ @@ -8443,6 +8586,216 @@ typedef struct LDKCResult_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ { +/** + * An `InvoiceRequest` is a request for a [`Bolt12Invoice`] formulated from an [`Offer`]. + * + * An offer may provide choices such as quantity, amount, chain, features, etc. An invoice request + * specifies these such that its recipient can send an invoice for payment. + * + * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice + * [`Offer`]: crate::offers::offer::Offer + */ +typedef struct MUST_USE_STRUCT LDKInvoiceRequest { + /** + * A pointer to the opaque Rust object. + * Nearly everywhere, inner must be non-null, however in places where + * the Rust equivalent takes an Option, it may be set to null to indicate None. + */ + LDKnativeInvoiceRequest *inner; + /** + * Indicates that this is the only struct which contains the same pointer. + * Rust functions which take ownership of an object provided via an argument require + * this to be true and invalidate the object pointed to by inner. + */ + bool is_owned; +} LDKInvoiceRequest; + + + +/** + * A `Bolt12Invoice` is a payment request, typically corresponding to an [`Offer`] or a [`Refund`]. + * + * An invoice may be sent in response to an [`InvoiceRequest`] in the case of an offer or sent + * directly after scanning a refund. It includes all the information needed to pay a recipient. + * + * [`Offer`]: crate::offers::offer::Offer + * [`Refund`]: crate::offers::refund::Refund + * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest + */ +typedef struct MUST_USE_STRUCT LDKBolt12Invoice { + /** + * A pointer to the opaque Rust object. + * Nearly everywhere, inner must be non-null, however in places where + * the Rust equivalent takes an Option, it may be set to null to indicate None. + */ + LDKnativeBolt12Invoice *inner; + /** + * Indicates that this is the only struct which contains the same pointer. + * Rust functions which take ownership of an object provided via an argument require + * this to be true and invalidate the object pointed to by inner. + */ + bool is_owned; +} LDKBolt12Invoice; + + + +/** + * An error in response to an [`InvoiceRequest`] or an [`Bolt12Invoice`]. + * + * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest + * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice + */ +typedef struct MUST_USE_STRUCT LDKInvoiceError { + /** + * A pointer to the opaque Rust object. + * Nearly everywhere, inner must be non-null, however in places where + * the Rust equivalent takes an Option, it may be set to null to indicate None. + */ + LDKnativeInvoiceError *inner; + /** + * Indicates that this is the only struct which contains the same pointer. + * Rust functions which take ownership of an object provided via an argument require + * this to be true and invalidate the object pointed to by inner. + */ + bool is_owned; +} LDKInvoiceError; + +/** + * Possible BOLT 12 Offers messages sent and received via an [`OnionMessage`]. + * + * [`OnionMessage`]: crate::ln::msgs::OnionMessage + */ +typedef enum LDKOffersMessage_Tag { + /** + * A request for a [`Bolt12Invoice`] for a particular [`Offer`]. + * + * [`Offer`]: crate::offers::offer::Offer + */ + LDKOffersMessage_InvoiceRequest, + /** + * A [`Bolt12Invoice`] sent in response to an [`InvoiceRequest`] or a [`Refund`]. + * + * [`Refund`]: crate::offers::refund::Refund + */ + LDKOffersMessage_Invoice, + /** + * An error from handling an [`OffersMessage`]. + */ + LDKOffersMessage_InvoiceError, + /** + * Must be last for serialization purposes + */ + LDKOffersMessage_Sentinel, +} LDKOffersMessage_Tag; + +typedef struct MUST_USE_STRUCT LDKOffersMessage { + LDKOffersMessage_Tag tag; + union { + struct { + struct LDKInvoiceRequest invoice_request; + }; + struct { + struct LDKBolt12Invoice invoice; + }; + struct { + struct LDKInvoiceError invoice_error; + }; + }; +} LDKOffersMessage; + +/** + * An enum which can either contain a crate::lightning::onion_message::offers::OffersMessage or not + */ +typedef enum LDKCOption_OffersMessageZ_Tag { + /** + * When we're in this state, this COption_OffersMessageZ contains a crate::lightning::onion_message::offers::OffersMessage + */ + LDKCOption_OffersMessageZ_Some, + /** + * When we're in this state, this COption_OffersMessageZ contains nothing + */ + LDKCOption_OffersMessageZ_None, + /** + * Must be last for serialization purposes + */ + LDKCOption_OffersMessageZ_Sentinel, +} LDKCOption_OffersMessageZ_Tag; + +typedef struct LDKCOption_OffersMessageZ { + LDKCOption_OffersMessageZ_Tag tag; + union { + struct { + struct LDKOffersMessage some; + }; + }; +} LDKCOption_OffersMessageZ; + +/** + * The destination of an onion message. + */ +typedef enum LDKDestination_Tag { + /** + * We're sending this onion message to a node. + */ + LDKDestination_Node, + /** + * We're sending this onion message to a blinded path. + */ + LDKDestination_BlindedPath, + /** + * Must be last for serialization purposes + */ + LDKDestination_Sentinel, +} LDKDestination_Tag; + +typedef struct MUST_USE_STRUCT LDKDestination { + LDKDestination_Tag tag; + union { + struct { + struct LDKPublicKey node; + }; + struct { + struct LDKBlindedPath blinded_path; + }; + }; +} LDKDestination; + +/** + * A tuple of 3 elements. See the individual fields for the types contained. + */ +typedef struct LDKC3Tuple_OffersMessageDestinationBlindedPathZ { + /** + * The element at position 0 + */ + struct LDKOffersMessage a; + /** + * The element at position 1 + */ + struct LDKDestination b; + /** + * The element at position 2 + */ + struct LDKBlindedPath c; +} LDKC3Tuple_OffersMessageDestinationBlindedPathZ; + +/** + * A dynamically-allocated array of crate::c_types::derived::C3Tuple_OffersMessageDestinationBlindedPathZs of arbitrary size. + * This corresponds to std::vector in C++ + */ +typedef struct LDKCVec_C3Tuple_OffersMessageDestinationBlindedPathZZ { + /** + * The elements in the array. + * If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc(). + */ + struct LDKC3Tuple_OffersMessageDestinationBlindedPathZ *data; + /** + * The number of elements pointed to by `data`. + */ + uintptr_t datalen; +} LDKCVec_C3Tuple_OffersMessageDestinationBlindedPathZZ; + + + /** * Information needed for constructing an invoice route hint for this channel. */ @@ -10187,156 +10540,10 @@ typedef struct LDKCVec_C2Tuple_PublicKeyTypeZZ { uintptr_t datalen; } LDKCVec_C2Tuple_PublicKeyTypeZZ; - - -/** - * An `InvoiceRequest` is a request for a [`Bolt12Invoice`] formulated from an [`Offer`]. - * - * An offer may provide choices such as quantity, amount, chain, features, etc. An invoice request - * specifies these such that its recipient can send an invoice for payment. - * - * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice - * [`Offer`]: crate::offers::offer::Offer - */ -typedef struct MUST_USE_STRUCT LDKInvoiceRequest { - /** - * A pointer to the opaque Rust object. - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeInvoiceRequest *inner; - /** - * Indicates that this is the only struct which contains the same pointer. - * Rust functions which take ownership of an object provided via an argument require - * this to be true and invalidate the object pointed to by inner. - */ - bool is_owned; -} LDKInvoiceRequest; - - - -/** - * A `Bolt12Invoice` is a payment request, typically corresponding to an [`Offer`] or a [`Refund`]. - * - * An invoice may be sent in response to an [`InvoiceRequest`] in the case of an offer or sent - * directly after scanning a refund. It includes all the information needed to pay a recipient. - * - * [`Offer`]: crate::offers::offer::Offer - * [`Refund`]: crate::offers::refund::Refund - * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest - */ -typedef struct MUST_USE_STRUCT LDKBolt12Invoice { - /** - * A pointer to the opaque Rust object. - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeBolt12Invoice *inner; - /** - * Indicates that this is the only struct which contains the same pointer. - * Rust functions which take ownership of an object provided via an argument require - * this to be true and invalidate the object pointed to by inner. - */ - bool is_owned; -} LDKBolt12Invoice; - - - -/** - * An error in response to an [`InvoiceRequest`] or an [`Bolt12Invoice`]. - * - * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest - * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice - */ -typedef struct MUST_USE_STRUCT LDKInvoiceError { - /** - * A pointer to the opaque Rust object. - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeInvoiceError *inner; - /** - * Indicates that this is the only struct which contains the same pointer. - * Rust functions which take ownership of an object provided via an argument require - * this to be true and invalidate the object pointed to by inner. - */ - bool is_owned; -} LDKInvoiceError; - /** - * Possible BOLT 12 Offers messages sent and received via an [`OnionMessage`]. - * - * [`OnionMessage`]: crate::ln::msgs::OnionMessage + * The contents of an onion message. */ -typedef enum LDKOffersMessage_Tag { - /** - * A request for a [`Bolt12Invoice`] for a particular [`Offer`]. - * - * [`Offer`]: crate::offers::offer::Offer - */ - LDKOffersMessage_InvoiceRequest, - /** - * A [`Bolt12Invoice`] sent in response to an [`InvoiceRequest`] or a [`Refund`]. - * - * [`Refund`]: crate::offers::refund::Refund - */ - LDKOffersMessage_Invoice, - /** - * An error from handling an [`OffersMessage`]. - */ - LDKOffersMessage_InvoiceError, - /** - * Must be last for serialization purposes - */ - LDKOffersMessage_Sentinel, -} LDKOffersMessage_Tag; - -typedef struct MUST_USE_STRUCT LDKOffersMessage { - LDKOffersMessage_Tag tag; - union { - struct { - struct LDKInvoiceRequest invoice_request; - }; - struct { - struct LDKBolt12Invoice invoice; - }; - struct { - struct LDKInvoiceError invoice_error; - }; - }; -} LDKOffersMessage; - -/** - * An enum which can either contain a crate::lightning::onion_message::offers::OffersMessage or not - */ -typedef enum LDKCOption_OffersMessageZ_Tag { - /** - * When we're in this state, this COption_OffersMessageZ contains a crate::lightning::onion_message::offers::OffersMessage - */ - LDKCOption_OffersMessageZ_Some, - /** - * When we're in this state, this COption_OffersMessageZ contains nothing - */ - LDKCOption_OffersMessageZ_None, - /** - * Must be last for serialization purposes - */ - LDKCOption_OffersMessageZ_Sentinel, -} LDKCOption_OffersMessageZ_Tag; - -typedef struct LDKCOption_OffersMessageZ { - LDKCOption_OffersMessageZ_Tag tag; - union { - struct { - struct LDKOffersMessage some; - }; - }; -} LDKCOption_OffersMessageZ; - -/** - * The contents of a custom onion message. - */ -typedef struct LDKCustomOnionMessageContents { +typedef struct LDKOnionMessageContents { /** * An opaque pointer which is passed to your function implementations as an argument. * This has no meaning in the LDK, and can be NULL or any other value. @@ -10351,77 +10558,111 @@ typedef struct LDKCustomOnionMessageContents { */ struct LDKCVec_u8Z (*write)(const void *this_arg); /** - * Called, if set, after this CustomOnionMessageContents has been cloned into a duplicate object. - * The new CustomOnionMessageContents is provided, and should be mutated as needed to perform a + * Called, if set, after this OnionMessageContents has been cloned into a duplicate object. + * The new OnionMessageContents is provided, and should be mutated as needed to perform a * deep copy of the object pointed to by this_arg or avoid any double-freeing. */ - void (*cloned)(struct LDKCustomOnionMessageContents *NONNULL_PTR new_CustomOnionMessageContents); + void (*cloned)(struct LDKOnionMessageContents *NONNULL_PTR new_OnionMessageContents); /** * Frees any resources associated with this object given its this_arg pointer. * Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. */ void (*free)(void *this_arg); -} LDKCustomOnionMessageContents; +} LDKOnionMessageContents; /** - * An enum which can either contain a crate::lightning::onion_message::packet::CustomOnionMessageContents or not + * An enum which can either contain a crate::lightning::onion_message::packet::OnionMessageContents or not */ -typedef enum LDKCOption_CustomOnionMessageContentsZ_Tag { +typedef enum LDKCOption_OnionMessageContentsZ_Tag { /** - * When we're in this state, this COption_CustomOnionMessageContentsZ contains a crate::lightning::onion_message::packet::CustomOnionMessageContents + * When we're in this state, this COption_OnionMessageContentsZ contains a crate::lightning::onion_message::packet::OnionMessageContents */ - LDKCOption_CustomOnionMessageContentsZ_Some, + LDKCOption_OnionMessageContentsZ_Some, /** - * When we're in this state, this COption_CustomOnionMessageContentsZ contains nothing + * When we're in this state, this COption_OnionMessageContentsZ contains nothing */ - LDKCOption_CustomOnionMessageContentsZ_None, + LDKCOption_OnionMessageContentsZ_None, /** * Must be last for serialization purposes */ - LDKCOption_CustomOnionMessageContentsZ_Sentinel, -} LDKCOption_CustomOnionMessageContentsZ_Tag; + LDKCOption_OnionMessageContentsZ_Sentinel, +} LDKCOption_OnionMessageContentsZ_Tag; -typedef struct LDKCOption_CustomOnionMessageContentsZ { - LDKCOption_CustomOnionMessageContentsZ_Tag tag; +typedef struct LDKCOption_OnionMessageContentsZ { + LDKCOption_OnionMessageContentsZ_Tag tag; union { struct { - struct LDKCustomOnionMessageContents some; + struct LDKOnionMessageContents some; }; }; -} LDKCOption_CustomOnionMessageContentsZ; +} LDKCOption_OnionMessageContentsZ; /** - * The contents of CResult_COption_CustomOnionMessageContentsZDecodeErrorZ + * The contents of CResult_COption_OnionMessageContentsZDecodeErrorZ */ -typedef union LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZPtr { +typedef union LDKCResult_COption_OnionMessageContentsZDecodeErrorZPtr { /** * A pointer to the contents in the success state. * Reading from this pointer when `result_ok` is not set is undefined. */ - struct LDKCOption_CustomOnionMessageContentsZ *result; + struct LDKCOption_OnionMessageContentsZ *result; /** * A pointer to the contents in the error state. * Reading from this pointer when `result_ok` is set is undefined. */ struct LDKDecodeError *err; -} LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZPtr; +} LDKCResult_COption_OnionMessageContentsZDecodeErrorZPtr; /** - * A CResult_COption_CustomOnionMessageContentsZDecodeErrorZ represents the result of a fallible operation, - * containing a crate::c_types::derived::COption_CustomOnionMessageContentsZ on success and a crate::lightning::ln::msgs::DecodeError on failure. + * A CResult_COption_OnionMessageContentsZDecodeErrorZ represents the result of a fallible operation, + * containing a crate::c_types::derived::COption_OnionMessageContentsZ on success and a crate::lightning::ln::msgs::DecodeError on failure. * `result_ok` indicates the overall state, and the contents are provided via `contents`. */ -typedef struct LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ { +typedef struct LDKCResult_COption_OnionMessageContentsZDecodeErrorZ { /** - * The contents of this CResult_COption_CustomOnionMessageContentsZDecodeErrorZ, accessible via either + * The contents of this CResult_COption_OnionMessageContentsZDecodeErrorZ, accessible via either * `err` or `result` depending on the state of `result_ok`. */ - union LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZPtr contents; + union LDKCResult_COption_OnionMessageContentsZDecodeErrorZPtr contents; /** - * Whether this CResult_COption_CustomOnionMessageContentsZDecodeErrorZ represents a success state. + * Whether this CResult_COption_OnionMessageContentsZDecodeErrorZ represents a success state. */ bool result_ok; -} LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ; +} LDKCResult_COption_OnionMessageContentsZDecodeErrorZ; + +/** + * A tuple of 3 elements. See the individual fields for the types contained. + */ +typedef struct LDKC3Tuple_OnionMessageContentsDestinationBlindedPathZ { + /** + * The element at position 0 + */ + struct LDKOnionMessageContents a; + /** + * The element at position 1 + */ + struct LDKDestination b; + /** + * The element at position 2 + */ + struct LDKBlindedPath c; +} LDKC3Tuple_OnionMessageContentsDestinationBlindedPathZ; + +/** + * A dynamically-allocated array of crate::c_types::derived::C3Tuple_OnionMessageContentsDestinationBlindedPathZs of arbitrary size. + * This corresponds to std::vector in C++ + */ +typedef struct LDKCVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ { + /** + * The elements in the array. + * If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc(). + */ + struct LDKC3Tuple_OnionMessageContentsDestinationBlindedPathZ *data; + /** + * The number of elements pointed to by `data`. + */ + uintptr_t datalen; +} LDKCVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ; /** * An enum which can either contain a crate::lightning::ln::wire::Type or not @@ -14529,7 +14770,6 @@ typedef enum LDKBumpTransactionEvent_Tag { * * [`EcdsaChannelSigner`]: crate::sign::EcdsaChannelSigner * [`EcdsaChannelSigner::sign_holder_htlc_transaction`]: crate::sign::EcdsaChannelSigner::sign_holder_htlc_transaction - * [`HTLCDescriptor::tx_input_witness`]: HTLCDescriptor::tx_input_witness */ LDKBumpTransactionEvent_HTLCResolution, /** @@ -14681,6 +14921,17 @@ typedef enum LDKEvent_Tag { * [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds */ LDKEvent_PaymentClaimed, + /** + * Indicates a request for an invoice failed to yield a response in a reasonable amount of time + * or was explicitly abandoned by [`ChannelManager::abandon_payment`]. This may be for an + * [`InvoiceRequest`] sent for an [`Offer`] or for a [`Refund`] that hasn't been redeemed. + * + * [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment + * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest + * [`Offer`]: crate::offers::offer::Offer + * [`Refund`]: crate::offers::refund::Refund + */ + LDKEvent_InvoiceRequestFailed, /** * Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target * and we got back the payment preimage for it). @@ -15001,6 +15252,13 @@ typedef struct LDKEvent_LDKPaymentClaimed_Body { struct LDKCOption_u64Z sender_intended_total_msat; } LDKEvent_LDKPaymentClaimed_Body; +typedef struct LDKEvent_LDKInvoiceRequestFailed_Body { + /** + * The `payment_id` to have been associated with payment for the requested invoice. + */ + struct LDKThirtyTwoBytes payment_id; +} LDKEvent_LDKInvoiceRequestFailed_Body; + typedef struct LDKEvent_LDKPaymentSent_Body { /** * The `payment_id` passed to [`ChannelManager::send_payment`]. @@ -15441,6 +15699,7 @@ typedef struct MUST_USE_STRUCT LDKEvent { LDKEvent_LDKFundingGenerationReady_Body funding_generation_ready; LDKEvent_LDKPaymentClaimable_Body payment_claimable; LDKEvent_LDKPaymentClaimed_Body payment_claimed; + LDKEvent_LDKInvoiceRequestFailed_Body invoice_request_failed; LDKEvent_LDKPaymentSent_Body payment_sent; LDKEvent_LDKPaymentFailed_Body payment_failed; LDKEvent_LDKPaymentPathSuccessful_Body payment_path_successful; @@ -16713,7 +16972,7 @@ typedef struct LDKCResult_StrSecp256k1ErrorZ { /** - * A path for sending an [`msgs::OnionMessage`]. + * A path for sending an [`OnionMessage`]. */ typedef struct MUST_USE_STRUCT LDKOnionMessagePath { /** @@ -16792,8 +17051,8 @@ typedef enum LDKSendError_Tag { */ LDKSendError_TooBigPacket, /** - * The provided [`Destination`] was an invalid [`BlindedPath`], due to having fewer than two - * blinded hops. + * The provided [`Destination`] was an invalid [`BlindedPath`] due to not having any blinded + * hops. */ LDKSendError_TooFewBlindedHops, /** @@ -16869,6 +17128,116 @@ typedef struct LDKCResult_C2Tuple_PublicKeyOnionMessageZSendErrorZ { bool result_ok; } LDKCResult_C2Tuple_PublicKeyOnionMessageZSendErrorZ; +/** + * The contents of an [`OnionMessage`] as read from the wire. + * + * [`OnionMessage`]: crate::ln::msgs::OnionMessage + */ +typedef enum LDKParsedOnionMessageContents_Tag { + /** + * A message related to BOLT 12 Offers. + */ + LDKParsedOnionMessageContents_Offers, + /** + * A custom onion message specified by the user. + */ + LDKParsedOnionMessageContents_Custom, + /** + * Must be last for serialization purposes + */ + LDKParsedOnionMessageContents_Sentinel, +} LDKParsedOnionMessageContents_Tag; + +typedef struct MUST_USE_STRUCT LDKParsedOnionMessageContents { + LDKParsedOnionMessageContents_Tag tag; + union { + struct { + struct LDKOffersMessage offers; + }; + struct { + struct LDKOnionMessageContents custom; + }; + }; +} LDKParsedOnionMessageContents; + +/** + * A processed incoming onion message, containing either a Forward (another onion message) + * or a Receive payload with decrypted contents. + */ +typedef enum LDKPeeledOnion_Tag { + /** + * Forwarded onion, with the next node id and a new onion + */ + LDKPeeledOnion_Forward, + /** + * Received onion message, with decrypted contents, path_id, and reply path + */ + LDKPeeledOnion_Receive, + /** + * Must be last for serialization purposes + */ + LDKPeeledOnion_Sentinel, +} LDKPeeledOnion_Tag; + +typedef struct LDKPeeledOnion_LDKForward_Body { + struct LDKPublicKey _0; + struct LDKOnionMessage _1; +} LDKPeeledOnion_LDKForward_Body; + +typedef struct LDKPeeledOnion_LDKReceive_Body { + struct LDKParsedOnionMessageContents _0; + /** + * + * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None + */ + struct LDKThirtyTwoBytes _1; + /** + * + * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None + */ + struct LDKBlindedPath _2; +} LDKPeeledOnion_LDKReceive_Body; + +typedef struct MUST_USE_STRUCT LDKPeeledOnion { + LDKPeeledOnion_Tag tag; + union { + LDKPeeledOnion_LDKForward_Body forward; + LDKPeeledOnion_LDKReceive_Body receive; + }; +} LDKPeeledOnion; + +/** + * The contents of CResult_PeeledOnionNoneZ + */ +typedef union LDKCResult_PeeledOnionNoneZPtr { + /** + * A pointer to the contents in the success state. + * Reading from this pointer when `result_ok` is not set is undefined. + */ + struct LDKPeeledOnion *result; + /** + * Note that this value is always NULL, as there are no contents in the Err variant + */ + void *err; +} LDKCResult_PeeledOnionNoneZPtr; + +/** + * A CResult_PeeledOnionNoneZ represents the result of a fallible operation, + * containing a crate::lightning::onion_message::messenger::PeeledOnion on success and a () on failure. + * `result_ok` indicates the overall state, and the contents are provided via `contents`. + */ +typedef struct LDKCResult_PeeledOnionNoneZ { + /** + * The contents of this CResult_PeeledOnionNoneZ, accessible via either + * `err` or `result` depending on the state of `result_ok`. + */ + union LDKCResult_PeeledOnionNoneZPtr contents; + /** + * Whether this CResult_PeeledOnionNoneZ represents a success state. + */ + bool result_ok; +} LDKCResult_PeeledOnionNoneZ; + /** * The contents of CResult_NoneSendErrorZ */ @@ -18339,12 +18708,12 @@ typedef struct LDKChannelMessageHandler { */ struct LDKInitFeatures (*provided_init_features)(const void *this_arg, struct LDKPublicKey their_node_id); /** - * Gets the genesis hashes for this `ChannelMessageHandler` indicating which chains it supports. + * Gets the chain hashes for this `ChannelMessageHandler` indicating which chains it supports. * * If it's `None`, then no particular network chain hash compatibility will be enforced when * connecting to peers. */ - struct LDKCOption_CVec_ThirtyTwoBytesZZ (*get_genesis_hashes)(const void *this_arg); + struct LDKCOption_CVec_ThirtyTwoBytesZZ (*get_chain_hashes)(const void *this_arg); /** * Implementation of MessageSendEventsProvider for this object. */ @@ -18356,6 +18725,40 @@ typedef struct LDKChannelMessageHandler { void (*free)(void *this_arg); } LDKChannelMessageHandler; +/** + * A handler for an [`OnionMessage`] containing a BOLT 12 Offers message as its payload. + * + * [`OnionMessage`]: crate::ln::msgs::OnionMessage + */ +typedef struct LDKOffersMessageHandler { + /** + * An opaque pointer which is passed to your function implementations as an argument. + * This has no meaning in the LDK, and can be NULL or any other value. + */ + void *this_arg; + /** + * Handles the given message by either responding with an [`Bolt12Invoice`], sending a payment, + * or replying with an error. + * + * The returned [`OffersMessage`], if any, is enqueued to be sent by [`OnionMessenger`]. + * + * [`OnionMessenger`]: crate::onion_message::OnionMessenger + */ + struct LDKCOption_OffersMessageZ (*handle_message)(const void *this_arg, struct LDKOffersMessage message); + /** + * Releases any [`OffersMessage`]s that need to be sent. + * + * Typically, this is used for messages initiating a payment flow rather than in response to + * another message. The latter should use the return value of [`Self::handle_message`]. + */ + struct LDKCVec_C3Tuple_OffersMessageDestinationBlindedPathZZ (*release_pending_messages)(const void *this_arg); + /** + * Frees any resources associated with this object given its this_arg pointer. + * Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. + */ + void (*free)(void *this_arg); +} LDKOffersMessageHandler; + /** @@ -18572,29 +18975,7 @@ typedef struct LDKRoutingMessageHandler { } LDKRoutingMessageHandler; /** - * A trait indicating an object may generate onion messages to send - */ -typedef struct LDKOnionMessageProvider { - /** - * An opaque pointer which is passed to your function implementations as an argument. - * This has no meaning in the LDK, and can be NULL or any other value. - */ - void *this_arg; - /** - * Gets the next pending onion message for the peer with the given node id. - * - * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None - */ - struct LDKOnionMessage (*next_onion_message_for_peer)(const void *this_arg, struct LDKPublicKey peer_node_id); - /** - * Frees any resources associated with this object given its this_arg pointer. - * Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. - */ - void (*free)(void *this_arg); -} LDKOnionMessageProvider; - -/** - * A trait to describe an object that can receive onion messages. + * A handler for received [`OnionMessage`]s and for providing generated ones to send. */ typedef struct LDKOnionMessageHandler { /** @@ -18606,6 +18987,12 @@ typedef struct LDKOnionMessageHandler { * Handle an incoming `onion_message` message from the given peer. */ void (*handle_onion_message)(const void *this_arg, struct LDKPublicKey peer_node_id, const struct LDKOnionMessage *NONNULL_PTR msg); + /** + * Returns the next pending onion message for the peer with the given node id. + * + * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None + */ + struct LDKOnionMessage (*next_onion_message_for_peer)(const void *this_arg, struct LDKPublicKey peer_node_id); /** * Called when a connection is established with a peer. Can be used to track which peers * advertise onion message support and are online. @@ -18634,10 +19021,6 @@ typedef struct LDKOnionMessageHandler { * Note that this method is called before [`Self::peer_connected`]. */ struct LDKInitFeatures (*provided_init_features)(const void *this_arg, struct LDKPublicKey their_node_id); - /** - * Implementation of OnionMessageProvider for this object. - */ - struct LDKOnionMessageProvider OnionMessageProvider; /** * Frees any resources associated with this object given its this_arg pointer. * Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. @@ -18745,29 +19128,6 @@ typedef struct MUST_USE_STRUCT LDKIgnoringMessageHandler { bool is_owned; } LDKIgnoringMessageHandler; -/** - * A handler for an [`OnionMessage`] containing a BOLT 12 Offers message as its payload. - * - * [`OnionMessage`]: crate::ln::msgs::OnionMessage - */ -typedef struct LDKOffersMessageHandler { - /** - * An opaque pointer which is passed to your function implementations as an argument. - * This has no meaning in the LDK, and can be NULL or any other value. - */ - void *this_arg; - /** - * Handles the given message by either responding with an [`Bolt12Invoice`], sending a payment, - * or replying with an error. - */ - struct LDKCOption_OffersMessageZ (*handle_message)(const void *this_arg, struct LDKOffersMessage message); - /** - * Frees any resources associated with this object given its this_arg pointer. - * Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. - */ - void (*free)(void *this_arg); -} LDKOffersMessageHandler; - /** * Handler for custom onion messages. If you are using [`SimpleArcOnionMessenger`], * [`SimpleRefOnionMessenger`], or prefer to ignore inbound custom onion messages, @@ -18788,13 +19148,22 @@ typedef struct LDKCustomOnionMessageHandler { void *this_arg; /** * Called with the custom message that was received, returning a response to send, if any. + * + * The returned [`Self::CustomMessage`], if any, is enqueued to be sent by [`OnionMessenger`]. */ - struct LDKCOption_CustomOnionMessageContentsZ (*handle_custom_message)(const void *this_arg, struct LDKCustomOnionMessageContents msg); + struct LDKCOption_OnionMessageContentsZ (*handle_custom_message)(const void *this_arg, struct LDKOnionMessageContents msg); /** * Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the * message type is unknown. */ - struct LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ (*read_custom_message)(const void *this_arg, uint64_t message_type, struct LDKu8slice buffer); + struct LDKCResult_COption_OnionMessageContentsZDecodeErrorZ (*read_custom_message)(const void *this_arg, uint64_t message_type, struct LDKu8slice buffer); + /** + * Releases any [`Self::CustomMessage`]s that need to be sent. + * + * Typically, this is used for messages initiating a message flow rather than in response to + * another message. The latter should use the return value of [`Self::handle_custom_message`]. + */ + struct LDKCVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ (*release_pending_custom_messages)(const void *this_arg); /** * Frees any resources associated with this object given its this_arg pointer. * Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. @@ -19556,40 +19925,8 @@ typedef struct MUST_USE_STRUCT LDKPhantomKeysManager { bool is_owned; } LDKPhantomKeysManager; -/** - * The destination of an onion message. - */ -typedef enum LDKDestination_Tag { - /** - * We're sending this onion message to a node. - */ - LDKDestination_Node, - /** - * We're sending this onion message to a blinded path. - */ - LDKDestination_BlindedPath, - /** - * Must be last for serialization purposes - */ - LDKDestination_Sentinel, -} LDKDestination_Tag; - -typedef struct MUST_USE_STRUCT LDKDestination { - LDKDestination_Tag tag; - union { - struct { - struct LDKPublicKey node; - }; - struct { - struct LDKBlindedPath blinded_path; - }; - }; -} LDKDestination; - /** * A trait defining behavior for routing an [`OnionMessage`]. - * - * [`OnionMessage`]: msgs::OnionMessage */ typedef struct LDKMessageRouter { /** @@ -19599,8 +19936,6 @@ typedef struct LDKMessageRouter { void *this_arg; /** * Returns a route for sending an [`OnionMessage`] to the given [`Destination`]. - * - * [`OnionMessage`]: msgs::OnionMessage */ struct LDKCResult_OnionMessagePathNoneZ (*find_path)(const void *this_arg, struct LDKPublicKey sender, struct LDKCVec_PublicKeyZ peers, struct LDKDestination destination); /** @@ -19613,9 +19948,21 @@ typedef struct LDKMessageRouter { /** - * A sender, receiver and forwarder of onion messages. In upcoming releases, this object will be - * used to retrieve invoices and fulfill invoice requests from [offers]. Currently, only sending - * and receiving custom onion messages is supported. + * A sender, receiver and forwarder of [`OnionMessage`]s. + * + * # Handling Messages + * + * `OnionMessenger` implements [`OnionMessageHandler`], making it responsible for either forwarding + * messages to peers or delegating to the appropriate handler for the message type. Currently, the + * available handlers are: + * * [`OffersMessageHandler`], for responding to [`InvoiceRequest`]s and paying [`Bolt12Invoice`]s + * * [`CustomOnionMessageHandler`], for handling user-defined message types + * + * # Sending Messages + * + * [`OnionMessage`]s are sent initially using [`OnionMessenger::send_onion_message`]. When handling + * a message, the matched handler may return a response message which `OnionMessenger` will send + * on its behalf. * * # Example * @@ -19627,7 +19974,7 @@ typedef struct LDKMessageRouter { * # use lightning::sign::KeysManager; * # use lightning::ln::peer_handler::IgnoringMessageHandler; * # use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessenger, OnionMessagePath}; - * # use lightning::onion_message::packet::{CustomOnionMessageContents, OnionMessageContents}; + * # use lightning::onion_message::packet::OnionMessageContents; * # use lightning::util::logger::{Logger, Record}; * # use lightning::util::ser::{Writeable, Writer}; * # use lightning::io; @@ -19669,7 +20016,7 @@ typedef struct LDKMessageRouter { * \t\t// Write your custom onion message to `w` * \t} * } - * impl CustomOnionMessageContents for YourCustomMessage { + * impl OnionMessageContents for YourCustomMessage { * \tfn tlv_type(&self) -> u64 { * \t\t# let your_custom_message_type = 42; * \t\tyour_custom_message_type @@ -19681,8 +20028,7 @@ typedef struct LDKMessageRouter { * \tdestination: Destination::Node(destination_node_id), * }; * let reply_path = None; - * # let your_custom_message = YourCustomMessage {}; - * let message = OnionMessageContents::Custom(your_custom_message); + * # let message = YourCustomMessage {}; * onion_messenger.send_onion_message(path, message, reply_path); * * // Create a blinded path to yourself, for someone to send an onion message to. @@ -19696,13 +20042,12 @@ typedef struct LDKMessageRouter { * \tdestination: Destination::BlindedPath(blinded_path), * }; * let reply_path = None; - * # let your_custom_message = YourCustomMessage {}; - * let message = OnionMessageContents::Custom(your_custom_message); + * # let message = YourCustomMessage {}; * onion_messenger.send_onion_message(path, message, reply_path); * ``` * - * [offers]: - * [`OnionMessenger`]: crate::onion_message::OnionMessenger + * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest + * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice */ typedef struct MUST_USE_STRUCT LDKOnionMessenger { /** @@ -19722,7 +20067,7 @@ typedef struct MUST_USE_STRUCT LDKOnionMessenger { /** - * A [`MessageRouter`] that always fails. + * A [`MessageRouter`] that can only route to a directly connected [`Destination`]. */ typedef struct MUST_USE_STRUCT LDKDefaultMessageRouter { /** @@ -19739,37 +20084,6 @@ typedef struct MUST_USE_STRUCT LDKDefaultMessageRouter { bool is_owned; } LDKDefaultMessageRouter; -/** - * The contents of an onion message. In the context of offers, this would be the invoice, invoice - * request, or invoice error. - */ -typedef enum LDKOnionMessageContents_Tag { - /** - * A message related to BOLT 12 Offers. - */ - LDKOnionMessageContents_Offers, - /** - * A custom onion message specified by the user. - */ - LDKOnionMessageContents_Custom, - /** - * Must be last for serialization purposes - */ - LDKOnionMessageContents_Sentinel, -} LDKOnionMessageContents_Tag; - -typedef struct MUST_USE_STRUCT LDKOnionMessageContents { - LDKOnionMessageContents_Tag tag; - union { - struct { - struct LDKOffersMessage offers; - }; - struct { - struct LDKCustomOnionMessageContents custom; - }; - }; -} LDKOnionMessageContents; - /** @@ -20806,6 +21120,58 @@ void CResult_C2Tuple_CVec_u8ZusizeZNoneZ_free(struct LDKCResult_C2Tuple_CVec_u8Z */ struct LDKCResult_C2Tuple_CVec_u8ZusizeZNoneZ CResult_C2Tuple_CVec_u8ZusizeZNoneZ_clone(const struct LDKCResult_C2Tuple_CVec_u8ZusizeZNoneZ *NONNULL_PTR orig); +/** + * Creates a new CResult_ChannelDerivationParametersDecodeErrorZ in the success state. + */ +struct LDKCResult_ChannelDerivationParametersDecodeErrorZ CResult_ChannelDerivationParametersDecodeErrorZ_ok(struct LDKChannelDerivationParameters o); + +/** + * Creates a new CResult_ChannelDerivationParametersDecodeErrorZ in the error state. + */ +struct LDKCResult_ChannelDerivationParametersDecodeErrorZ CResult_ChannelDerivationParametersDecodeErrorZ_err(struct LDKDecodeError e); + +/** + * Checks if the given object is currently in the success state + */ +bool CResult_ChannelDerivationParametersDecodeErrorZ_is_ok(const struct LDKCResult_ChannelDerivationParametersDecodeErrorZ *NONNULL_PTR o); + +/** + * Frees any resources used by the CResult_ChannelDerivationParametersDecodeErrorZ. + */ +void CResult_ChannelDerivationParametersDecodeErrorZ_free(struct LDKCResult_ChannelDerivationParametersDecodeErrorZ _res); + +/** + * Creates a new CResult_ChannelDerivationParametersDecodeErrorZ which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. + */ +struct LDKCResult_ChannelDerivationParametersDecodeErrorZ CResult_ChannelDerivationParametersDecodeErrorZ_clone(const struct LDKCResult_ChannelDerivationParametersDecodeErrorZ *NONNULL_PTR orig); + +/** + * Creates a new CResult_HTLCDescriptorDecodeErrorZ in the success state. + */ +struct LDKCResult_HTLCDescriptorDecodeErrorZ CResult_HTLCDescriptorDecodeErrorZ_ok(struct LDKHTLCDescriptor o); + +/** + * Creates a new CResult_HTLCDescriptorDecodeErrorZ in the error state. + */ +struct LDKCResult_HTLCDescriptorDecodeErrorZ CResult_HTLCDescriptorDecodeErrorZ_err(struct LDKDecodeError e); + +/** + * Checks if the given object is currently in the success state + */ +bool CResult_HTLCDescriptorDecodeErrorZ_is_ok(const struct LDKCResult_HTLCDescriptorDecodeErrorZ *NONNULL_PTR o); + +/** + * Frees any resources used by the CResult_HTLCDescriptorDecodeErrorZ. + */ +void CResult_HTLCDescriptorDecodeErrorZ_free(struct LDKCResult_HTLCDescriptorDecodeErrorZ _res); + +/** + * Creates a new CResult_HTLCDescriptorDecodeErrorZ which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. + */ +struct LDKCResult_HTLCDescriptorDecodeErrorZ CResult_HTLCDescriptorDecodeErrorZ_clone(const struct LDKCResult_HTLCDescriptorDecodeErrorZ *NONNULL_PTR orig); + /** * Creates a new CResult_NoneNoneZ in the success state. */ @@ -22404,58 +22770,6 @@ void COption_CVec_SocketAddressZZ_free(struct LDKCOption_CVec_SocketAddressZZ _r */ struct LDKCOption_CVec_SocketAddressZZ COption_CVec_SocketAddressZZ_clone(const struct LDKCOption_CVec_SocketAddressZZ *NONNULL_PTR orig); -/** - * Creates a new CResult_ChannelDerivationParametersDecodeErrorZ in the success state. - */ -struct LDKCResult_ChannelDerivationParametersDecodeErrorZ CResult_ChannelDerivationParametersDecodeErrorZ_ok(struct LDKChannelDerivationParameters o); - -/** - * Creates a new CResult_ChannelDerivationParametersDecodeErrorZ in the error state. - */ -struct LDKCResult_ChannelDerivationParametersDecodeErrorZ CResult_ChannelDerivationParametersDecodeErrorZ_err(struct LDKDecodeError e); - -/** - * Checks if the given object is currently in the success state - */ -bool CResult_ChannelDerivationParametersDecodeErrorZ_is_ok(const struct LDKCResult_ChannelDerivationParametersDecodeErrorZ *NONNULL_PTR o); - -/** - * Frees any resources used by the CResult_ChannelDerivationParametersDecodeErrorZ. - */ -void CResult_ChannelDerivationParametersDecodeErrorZ_free(struct LDKCResult_ChannelDerivationParametersDecodeErrorZ _res); - -/** - * Creates a new CResult_ChannelDerivationParametersDecodeErrorZ which has the same data as `orig` - * but with all dynamically-allocated buffers duplicated in new buffers. - */ -struct LDKCResult_ChannelDerivationParametersDecodeErrorZ CResult_ChannelDerivationParametersDecodeErrorZ_clone(const struct LDKCResult_ChannelDerivationParametersDecodeErrorZ *NONNULL_PTR orig); - -/** - * Creates a new CResult_HTLCDescriptorDecodeErrorZ in the success state. - */ -struct LDKCResult_HTLCDescriptorDecodeErrorZ CResult_HTLCDescriptorDecodeErrorZ_ok(struct LDKHTLCDescriptor o); - -/** - * Creates a new CResult_HTLCDescriptorDecodeErrorZ in the error state. - */ -struct LDKCResult_HTLCDescriptorDecodeErrorZ CResult_HTLCDescriptorDecodeErrorZ_err(struct LDKDecodeError e); - -/** - * Checks if the given object is currently in the success state - */ -bool CResult_HTLCDescriptorDecodeErrorZ_is_ok(const struct LDKCResult_HTLCDescriptorDecodeErrorZ *NONNULL_PTR o); - -/** - * Frees any resources used by the CResult_HTLCDescriptorDecodeErrorZ. - */ -void CResult_HTLCDescriptorDecodeErrorZ_free(struct LDKCResult_HTLCDescriptorDecodeErrorZ _res); - -/** - * Creates a new CResult_HTLCDescriptorDecodeErrorZ which has the same data as `orig` - * but with all dynamically-allocated buffers duplicated in new buffers. - */ -struct LDKCResult_HTLCDescriptorDecodeErrorZ CResult_HTLCDescriptorDecodeErrorZ_clone(const struct LDKCResult_HTLCDescriptorDecodeErrorZ *NONNULL_PTR orig); - /** * Frees the buffer pointed to by `data` if `datalen` is non-0. */ @@ -22836,6 +23150,53 @@ void C2Tuple_ThirtyTwoBytesPublicKeyZ_free(struct LDKC2Tuple_ThirtyTwoBytesPubli */ void CVec_C2Tuple_ThirtyTwoBytesPublicKeyZZ_free(struct LDKCVec_C2Tuple_ThirtyTwoBytesPublicKeyZZ _res); +/** + * Constructs a new COption_StrZ containing a crate::c_types::Str + */ +struct LDKCOption_StrZ COption_StrZ_some(struct LDKStr o); + +/** + * Constructs a new COption_StrZ containing nothing + */ +struct LDKCOption_StrZ COption_StrZ_none(void); + +/** + * Frees any resources associated with the crate::c_types::Str, if we are in the Some state + */ +void COption_StrZ_free(struct LDKCOption_StrZ _res); + +/** + * Creates a new COption_StrZ which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. + */ +struct LDKCOption_StrZ COption_StrZ_clone(const struct LDKCOption_StrZ *NONNULL_PTR orig); + +/** + * Creates a new CResult_NoneBolt12SemanticErrorZ in the success state. + */ +struct LDKCResult_NoneBolt12SemanticErrorZ CResult_NoneBolt12SemanticErrorZ_ok(void); + +/** + * Creates a new CResult_NoneBolt12SemanticErrorZ in the error state. + */ +struct LDKCResult_NoneBolt12SemanticErrorZ CResult_NoneBolt12SemanticErrorZ_err(enum LDKBolt12SemanticError e); + +/** + * Checks if the given object is currently in the success state + */ +bool CResult_NoneBolt12SemanticErrorZ_is_ok(const struct LDKCResult_NoneBolt12SemanticErrorZ *NONNULL_PTR o); + +/** + * Frees any resources used by the CResult_NoneBolt12SemanticErrorZ. + */ +void CResult_NoneBolt12SemanticErrorZ_free(struct LDKCResult_NoneBolt12SemanticErrorZ _res); + +/** + * Creates a new CResult_NoneBolt12SemanticErrorZ which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. + */ +struct LDKCResult_NoneBolt12SemanticErrorZ CResult_NoneBolt12SemanticErrorZ_clone(const struct LDKCResult_NoneBolt12SemanticErrorZ *NONNULL_PTR orig); + /** * Creates a new CResult_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ in the success state. */ @@ -22862,6 +23223,48 @@ void CResult_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ_free(struct LDKCResult_C */ struct LDKCResult_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ CResult_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ_clone(const struct LDKCResult_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ *NONNULL_PTR orig); +/** + * Constructs a new COption_OffersMessageZ containing a crate::lightning::onion_message::offers::OffersMessage + */ +struct LDKCOption_OffersMessageZ COption_OffersMessageZ_some(struct LDKOffersMessage o); + +/** + * Constructs a new COption_OffersMessageZ containing nothing + */ +struct LDKCOption_OffersMessageZ COption_OffersMessageZ_none(void); + +/** + * Frees any resources associated with the crate::lightning::onion_message::offers::OffersMessage, if we are in the Some state + */ +void COption_OffersMessageZ_free(struct LDKCOption_OffersMessageZ _res); + +/** + * Creates a new COption_OffersMessageZ which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. + */ +struct LDKCOption_OffersMessageZ COption_OffersMessageZ_clone(const struct LDKCOption_OffersMessageZ *NONNULL_PTR orig); + +/** + * Creates a new tuple which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. + */ +struct LDKC3Tuple_OffersMessageDestinationBlindedPathZ C3Tuple_OffersMessageDestinationBlindedPathZ_clone(const struct LDKC3Tuple_OffersMessageDestinationBlindedPathZ *NONNULL_PTR orig); + +/** + * Creates a new C3Tuple_OffersMessageDestinationBlindedPathZ from the contained elements. + */ +struct LDKC3Tuple_OffersMessageDestinationBlindedPathZ C3Tuple_OffersMessageDestinationBlindedPathZ_new(struct LDKOffersMessage a, struct LDKDestination b, struct LDKBlindedPath c); + +/** + * Frees any resources used by the C3Tuple_OffersMessageDestinationBlindedPathZ. + */ +void C3Tuple_OffersMessageDestinationBlindedPathZ_free(struct LDKC3Tuple_OffersMessageDestinationBlindedPathZ _res); + +/** + * Frees the buffer pointed to by `data` if `datalen` is non-0. + */ +void CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ_free(struct LDKCVec_C3Tuple_OffersMessageDestinationBlindedPathZZ _res); + /** * Creates a new CResult_CounterpartyForwardingInfoDecodeErrorZ in the success state. */ @@ -23425,72 +23828,72 @@ void C2Tuple_PublicKeyTypeZ_free(struct LDKC2Tuple_PublicKeyTypeZ _res); void CVec_C2Tuple_PublicKeyTypeZZ_free(struct LDKCVec_C2Tuple_PublicKeyTypeZZ _res); /** - * Constructs a new COption_OffersMessageZ containing a crate::lightning::onion_message::offers::OffersMessage + * Constructs a new COption_OnionMessageContentsZ containing a crate::lightning::onion_message::packet::OnionMessageContents */ -struct LDKCOption_OffersMessageZ COption_OffersMessageZ_some(struct LDKOffersMessage o); +struct LDKCOption_OnionMessageContentsZ COption_OnionMessageContentsZ_some(struct LDKOnionMessageContents o); /** - * Constructs a new COption_OffersMessageZ containing nothing + * Constructs a new COption_OnionMessageContentsZ containing nothing */ -struct LDKCOption_OffersMessageZ COption_OffersMessageZ_none(void); +struct LDKCOption_OnionMessageContentsZ COption_OnionMessageContentsZ_none(void); /** - * Frees any resources associated with the crate::lightning::onion_message::offers::OffersMessage, if we are in the Some state + * Frees any resources associated with the crate::lightning::onion_message::packet::OnionMessageContents, if we are in the Some state */ -void COption_OffersMessageZ_free(struct LDKCOption_OffersMessageZ _res); +void COption_OnionMessageContentsZ_free(struct LDKCOption_OnionMessageContentsZ _res); /** - * Creates a new COption_OffersMessageZ which has the same data as `orig` + * Creates a new COption_OnionMessageContentsZ which has the same data as `orig` * but with all dynamically-allocated buffers duplicated in new buffers. */ -struct LDKCOption_OffersMessageZ COption_OffersMessageZ_clone(const struct LDKCOption_OffersMessageZ *NONNULL_PTR orig); +struct LDKCOption_OnionMessageContentsZ COption_OnionMessageContentsZ_clone(const struct LDKCOption_OnionMessageContentsZ *NONNULL_PTR orig); /** - * Constructs a new COption_CustomOnionMessageContentsZ containing a crate::lightning::onion_message::packet::CustomOnionMessageContents + * Creates a new CResult_COption_OnionMessageContentsZDecodeErrorZ in the success state. */ -struct LDKCOption_CustomOnionMessageContentsZ COption_CustomOnionMessageContentsZ_some(struct LDKCustomOnionMessageContents o); +struct LDKCResult_COption_OnionMessageContentsZDecodeErrorZ CResult_COption_OnionMessageContentsZDecodeErrorZ_ok(struct LDKCOption_OnionMessageContentsZ o); /** - * Constructs a new COption_CustomOnionMessageContentsZ containing nothing + * Creates a new CResult_COption_OnionMessageContentsZDecodeErrorZ in the error state. */ -struct LDKCOption_CustomOnionMessageContentsZ COption_CustomOnionMessageContentsZ_none(void); +struct LDKCResult_COption_OnionMessageContentsZDecodeErrorZ CResult_COption_OnionMessageContentsZDecodeErrorZ_err(struct LDKDecodeError e); /** - * Frees any resources associated with the crate::lightning::onion_message::packet::CustomOnionMessageContents, if we are in the Some state + * Checks if the given object is currently in the success state */ -void COption_CustomOnionMessageContentsZ_free(struct LDKCOption_CustomOnionMessageContentsZ _res); +bool CResult_COption_OnionMessageContentsZDecodeErrorZ_is_ok(const struct LDKCResult_COption_OnionMessageContentsZDecodeErrorZ *NONNULL_PTR o); /** - * Creates a new COption_CustomOnionMessageContentsZ which has the same data as `orig` - * but with all dynamically-allocated buffers duplicated in new buffers. + * Frees any resources used by the CResult_COption_OnionMessageContentsZDecodeErrorZ. */ -struct LDKCOption_CustomOnionMessageContentsZ COption_CustomOnionMessageContentsZ_clone(const struct LDKCOption_CustomOnionMessageContentsZ *NONNULL_PTR orig); +void CResult_COption_OnionMessageContentsZDecodeErrorZ_free(struct LDKCResult_COption_OnionMessageContentsZDecodeErrorZ _res); /** - * Creates a new CResult_COption_CustomOnionMessageContentsZDecodeErrorZ in the success state. + * Creates a new CResult_COption_OnionMessageContentsZDecodeErrorZ which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. */ -struct LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ CResult_COption_CustomOnionMessageContentsZDecodeErrorZ_ok(struct LDKCOption_CustomOnionMessageContentsZ o); +struct LDKCResult_COption_OnionMessageContentsZDecodeErrorZ CResult_COption_OnionMessageContentsZDecodeErrorZ_clone(const struct LDKCResult_COption_OnionMessageContentsZDecodeErrorZ *NONNULL_PTR orig); /** - * Creates a new CResult_COption_CustomOnionMessageContentsZDecodeErrorZ in the error state. + * Creates a new tuple which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. */ -struct LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ CResult_COption_CustomOnionMessageContentsZDecodeErrorZ_err(struct LDKDecodeError e); +struct LDKC3Tuple_OnionMessageContentsDestinationBlindedPathZ C3Tuple_OnionMessageContentsDestinationBlindedPathZ_clone(const struct LDKC3Tuple_OnionMessageContentsDestinationBlindedPathZ *NONNULL_PTR orig); /** - * Checks if the given object is currently in the success state + * Creates a new C3Tuple_OnionMessageContentsDestinationBlindedPathZ from the contained elements. */ -bool CResult_COption_CustomOnionMessageContentsZDecodeErrorZ_is_ok(const struct LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ *NONNULL_PTR o); +struct LDKC3Tuple_OnionMessageContentsDestinationBlindedPathZ C3Tuple_OnionMessageContentsDestinationBlindedPathZ_new(struct LDKOnionMessageContents a, struct LDKDestination b, struct LDKBlindedPath c); /** - * Frees any resources used by the CResult_COption_CustomOnionMessageContentsZDecodeErrorZ. + * Frees any resources used by the C3Tuple_OnionMessageContentsDestinationBlindedPathZ. */ -void CResult_COption_CustomOnionMessageContentsZDecodeErrorZ_free(struct LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ _res); +void C3Tuple_OnionMessageContentsDestinationBlindedPathZ_free(struct LDKC3Tuple_OnionMessageContentsDestinationBlindedPathZ _res); /** - * Creates a new CResult_COption_CustomOnionMessageContentsZDecodeErrorZ which has the same data as `orig` - * but with all dynamically-allocated buffers duplicated in new buffers. + * Frees the buffer pointed to by `data` if `datalen` is non-0. */ -struct LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ CResult_COption_CustomOnionMessageContentsZDecodeErrorZ_clone(const struct LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ *NONNULL_PTR orig); +void CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ_free(struct LDKCVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ _res); /** * Constructs a new COption_TypeZ containing a crate::lightning::ln::wire::Type @@ -26567,6 +26970,26 @@ bool CResult_C2Tuple_PublicKeyOnionMessageZSendErrorZ_is_ok(const struct LDKCRes */ void CResult_C2Tuple_PublicKeyOnionMessageZSendErrorZ_free(struct LDKCResult_C2Tuple_PublicKeyOnionMessageZSendErrorZ _res); +/** + * Creates a new CResult_PeeledOnionNoneZ in the success state. + */ +struct LDKCResult_PeeledOnionNoneZ CResult_PeeledOnionNoneZ_ok(struct LDKPeeledOnion o); + +/** + * Creates a new CResult_PeeledOnionNoneZ in the error state. + */ +struct LDKCResult_PeeledOnionNoneZ CResult_PeeledOnionNoneZ_err(void); + +/** + * Checks if the given object is currently in the success state + */ +bool CResult_PeeledOnionNoneZ_is_ok(const struct LDKCResult_PeeledOnionNoneZ *NONNULL_PTR o); + +/** + * Frees any resources used by the CResult_PeeledOnionNoneZ. + */ +void CResult_PeeledOnionNoneZ_free(struct LDKCResult_PeeledOnionNoneZ _res); + /** * Creates a new CResult_NoneSendErrorZ in the success state. */ @@ -28138,20 +28561,20 @@ void ChannelConfig_set_max_dust_htlc_exposure(struct LDKChannelConfig *NONNULL_P * funder/initiator. * * When we are the funder, because we have to pay the channel closing fee, we bound the - * acceptable fee by our [`Background`] and [`Normal`] fees, with the upper bound increased by + * acceptable fee by our [`ChannelCloseMinimum`] and [`NonAnchorChannelFee`] fees, with the upper bound increased by * this value. Because the on-chain fee we'd pay to force-close the channel is kept near our - * [`Normal`] feerate during normal operation, this value represents the additional fee we're + * [`NonAnchorChannelFee`] feerate during normal operation, this value represents the additional fee we're * willing to pay in order to avoid waiting for our counterparty's to_self_delay to reclaim our * funds. * * When we are not the funder, we require the closing transaction fee pay at least our - * [`Background`] fee estimate, but allow our counterparty to pay as much fee as they like. + * [`ChannelCloseMinimum`] fee estimate, but allow our counterparty to pay as much fee as they like. * Thus, this value is ignored when we are not the funder. * * Default value: 1000 satoshis. * - * [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal - * [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background + * [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee + * [`ChannelCloseMinimum`]: crate::chain::chaininterface::ConfirmationTarget::ChannelCloseMinimum */ uint64_t ChannelConfig_get_force_close_avoidance_max_fee_satoshis(const struct LDKChannelConfig *NONNULL_PTR this_ptr); @@ -28164,20 +28587,20 @@ uint64_t ChannelConfig_get_force_close_avoidance_max_fee_satoshis(const struct L * funder/initiator. * * When we are the funder, because we have to pay the channel closing fee, we bound the - * acceptable fee by our [`Background`] and [`Normal`] fees, with the upper bound increased by + * acceptable fee by our [`ChannelCloseMinimum`] and [`NonAnchorChannelFee`] fees, with the upper bound increased by * this value. Because the on-chain fee we'd pay to force-close the channel is kept near our - * [`Normal`] feerate during normal operation, this value represents the additional fee we're + * [`NonAnchorChannelFee`] feerate during normal operation, this value represents the additional fee we're * willing to pay in order to avoid waiting for our counterparty's to_self_delay to reclaim our * funds. * * When we are not the funder, we require the closing transaction fee pay at least our - * [`Background`] fee estimate, but allow our counterparty to pay as much fee as they like. + * [`ChannelCloseMinimum`] fee estimate, but allow our counterparty to pay as much fee as they like. * Thus, this value is ignored when we are not the funder. * * Default value: 1000 satoshis. * - * [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal - * [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background + * [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee + * [`ChannelCloseMinimum`]: crate::chain::chaininterface::ConfirmationTarget::ChannelCloseMinimum */ void ChannelConfig_set_force_close_avoidance_max_fee_satoshis(struct LDKChannelConfig *NONNULL_PTR this_ptr, uint64_t val); @@ -28667,24 +29090,39 @@ void BroadcasterInterface_free(struct LDKBroadcasterInterface this_ptr); enum LDKConfirmationTarget ConfirmationTarget_clone(const enum LDKConfirmationTarget *NONNULL_PTR orig); /** - * Utility method to constructs a new MempoolMinimum-variant ConfirmationTarget + * Utility method to constructs a new OnChainSweep-variant ConfirmationTarget + */ +enum LDKConfirmationTarget ConfirmationTarget_on_chain_sweep(void); + +/** + * Utility method to constructs a new MaxAllowedNonAnchorChannelRemoteFee-variant ConfirmationTarget + */ +enum LDKConfirmationTarget ConfirmationTarget_max_allowed_non_anchor_channel_remote_fee(void); + +/** + * Utility method to constructs a new MinAllowedAnchorChannelRemoteFee-variant ConfirmationTarget */ -enum LDKConfirmationTarget ConfirmationTarget_mempool_minimum(void); +enum LDKConfirmationTarget ConfirmationTarget_min_allowed_anchor_channel_remote_fee(void); /** - * Utility method to constructs a new Background-variant ConfirmationTarget + * Utility method to constructs a new MinAllowedNonAnchorChannelRemoteFee-variant ConfirmationTarget */ -enum LDKConfirmationTarget ConfirmationTarget_background(void); +enum LDKConfirmationTarget ConfirmationTarget_min_allowed_non_anchor_channel_remote_fee(void); /** - * Utility method to constructs a new Normal-variant ConfirmationTarget + * Utility method to constructs a new AnchorChannelFee-variant ConfirmationTarget */ -enum LDKConfirmationTarget ConfirmationTarget_normal(void); +enum LDKConfirmationTarget ConfirmationTarget_anchor_channel_fee(void); /** - * Utility method to constructs a new HighPriority-variant ConfirmationTarget + * Utility method to constructs a new NonAnchorChannelFee-variant ConfirmationTarget */ -enum LDKConfirmationTarget ConfirmationTarget_high_priority(void); +enum LDKConfirmationTarget ConfirmationTarget_non_anchor_channel_fee(void); + +/** + * Utility method to constructs a new ChannelCloseMinimum-variant ConfirmationTarget + */ +enum LDKConfirmationTarget ConfirmationTarget_channel_close_minimum(void); /** * Generates a non-cryptographic 64-bit hash of the ConfirmationTarget. @@ -30384,11 +30822,11 @@ MUST_USE_RES struct LDKCVec_RecentPaymentDetailsZ ChannelManager_list_recent_pay * will be accepted on the given channel, and after additional timeout/the closing of all * pending HTLCs, the channel will be closed on chain. * - * * If we are the channel initiator, we will pay between our [`Background`] and - * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee - * estimate. + * * If we are the channel initiator, we will pay between our [`ChannelCloseMinimum`] and + * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`NonAnchorChannelFee`] + * fee estimate. * * If our counterparty is the channel initiator, we will require a channel closing - * transaction feerate of at least our [`Background`] feerate or the feerate which + * transaction feerate of at least our [`ChannelCloseMinimum`] feerate or the feerate which * would appear on a force-closure transaction, whichever is lower. We will allow our * counterparty to pay as much fee as they'd like, however. * @@ -30400,8 +30838,8 @@ MUST_USE_RES struct LDKCVec_RecentPaymentDetailsZ ChannelManager_list_recent_pay * channel. * * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis - * [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background - * [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal + * [`ChannelCloseMinimum`]: crate::chain::chaininterface::ConfirmationTarget::ChannelCloseMinimum + * [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee * [`SendShutdown`]: crate::events::MessageSendEvent::SendShutdown */ MUST_USE_RES struct LDKCResult_NoneAPIErrorZ ChannelManager_close_channel(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*channel_id)[32], struct LDKPublicKey counterparty_node_id); @@ -30415,8 +30853,8 @@ MUST_USE_RES struct LDKCResult_NoneAPIErrorZ ChannelManager_close_channel(const * the channel being closed or not: * * If we are the channel initiator, we will pay at least this feerate on the closing * transaction. The upper-bound is set by - * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee - * estimate (or `target_feerate_sat_per_1000_weight`, if it is greater). + * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`NonAnchorChannelFee`] + * fee estimate (or `target_feerate_sat_per_1000_weight`, if it is greater). * * If our counterparty is the channel initiator, we will refuse to accept a channel closure * transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which * will appear on a force-closure transaction, whichever is lower). @@ -30434,8 +30872,7 @@ MUST_USE_RES struct LDKCResult_NoneAPIErrorZ ChannelManager_close_channel(const * channel. * * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis - * [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background - * [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal + * [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee * [`SendShutdown`]: crate::events::MessageSendEvent::SendShutdown * * Note that shutdown_script (or a relevant inner pointer) may be NULL or all-0s to represent None @@ -30547,10 +30984,20 @@ MUST_USE_RES struct LDKCResult_NoneRetryableSendFailureZ ChannelManager_send_pay * wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to * determine the ultimate status of a payment. * + * # Requested Invoices + * + * In the case of paying a [`Bolt12Invoice`] via [`ChannelManager::pay_for_offer`], abandoning + * the payment prior to receiving the invoice will result in an [`Event::InvoiceRequestFailed`] + * and prevent any attempts at paying it once received. The other events may only be generated + * once the invoice has been received. + * * # Restart Behavior * * If an [`Event::PaymentFailed`] is generated and we restart without first persisting the - * [`ChannelManager`], another [`Event::PaymentFailed`] may be generated. + * [`ChannelManager`], another [`Event::PaymentFailed`] may be generated; likewise for + * [`Event::InvoiceRequestFailed`]. + * + * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice */ void ChannelManager_abandon_payment(const struct LDKChannelManager *NONNULL_PTR this_arg, struct LDKThirtyTwoBytes payment_id); @@ -30773,6 +31220,10 @@ void ChannelManager_process_pending_htlc_forwards(const struct LDKChannelManager * with the current [`ChannelConfig`]. * * Removing peers which have disconnected but and no longer have any channels. * * Force-closing and removing channels which have not completed establishment in a timely manner. + * * Forgetting about stale outbound payments, either those that have already been fulfilled + * or those awaiting an invoice that hasn't been delivered in the necessary amount of time. + * The latter is determined using the system clock in `std` and the highest seen block time + * minus two hours in `no-std`. * * Note that this may cause reentrancy through [`chain::Watch::update_channel`] calls or feerate * estimate fetches. @@ -30895,6 +31346,79 @@ MUST_USE_RES struct LDKCResult_NoneAPIErrorZ ChannelManager_accept_inbound_chann */ MUST_USE_RES struct LDKCResult_NoneAPIErrorZ ChannelManager_accept_inbound_channel_from_trusted_peer_0conf(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*temporary_channel_id)[32], struct LDKPublicKey counterparty_node_id, struct LDKU128 user_channel_id); +/** + * Pays for an [`Offer`] using the given parameters by creating an [`InvoiceRequest`] and + * enqueuing it to be sent via an onion message. [`ChannelManager`] will pay the actual + * [`Bolt12Invoice`] once it is received. + * + * Uses [`InvoiceRequestBuilder`] such that the [`InvoiceRequest`] it builds is recognized by + * the [`ChannelManager`] when handling a [`Bolt12Invoice`] message in response to the request. + * The optional parameters are used in the builder, if `Some`: + * - `quantity` for [`InvoiceRequest::quantity`] which must be set if + * [`Offer::expects_quantity`] is `true`. + * - `amount_msats` if overpaying what is required for the given `quantity` is desired, and + * - `payer_note` for [`InvoiceRequest::payer_note`]. + * + * If `max_total_routing_fee_msat` is not specified, The default from + * [`RouteParameters::from_payment_params_and_value`] is applied. + * + * # Payment + * + * The provided `payment_id` is used to ensure that only one invoice is paid for the request + * when received. See [Avoiding Duplicate Payments] for other requirements once the payment has + * been sent. + * + * To revoke the request, use [`ChannelManager::abandon_payment`] prior to receiving the + * invoice. If abandoned, or an invoice isn't received in a reasonable amount of time, the + * payment will fail with an [`Event::InvoiceRequestFailed`]. + * + * # Privacy + * + * Uses a one-hop [`BlindedPath`] for the reply path with [`ChannelManager::get_our_node_id`] + * as the introduction node and a derived payer id for payer privacy. As such, currently, the + * node must be announced. Otherwise, there is no way to find a path to the introduction node + * in order to send the [`Bolt12Invoice`]. + * + * # Limitations + * + * Requires a direct connection to an introduction node in [`Offer::paths`] or to + * [`Offer::signing_pubkey`], if empty. A similar restriction applies to the responding + * [`Bolt12Invoice::payment_paths`]. + * + * # Errors + * + * Errors if a duplicate `payment_id` is provided given the caveats in the aforementioned link + * or if the provided parameters are invalid for the offer. + * + * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest + * [`InvoiceRequest::quantity`]: crate::offers::invoice_request::InvoiceRequest::quantity + * [`InvoiceRequest::payer_note`]: crate::offers::invoice_request::InvoiceRequest::payer_note + * [`InvoiceRequestBuilder`]: crate::offers::invoice_request::InvoiceRequestBuilder + * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice + * [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths + * [Avoiding Duplicate Payments]: #avoiding-duplicate-payments + */ +MUST_USE_RES struct LDKCResult_NoneBolt12SemanticErrorZ ChannelManager_pay_for_offer(const struct LDKChannelManager *NONNULL_PTR this_arg, const struct LDKOffer *NONNULL_PTR offer, struct LDKCOption_u64Z quantity, struct LDKCOption_u64Z amount_msats, struct LDKCOption_StrZ payer_note, struct LDKThirtyTwoBytes payment_id, struct LDKRetry retry_strategy, struct LDKCOption_u64Z max_total_routing_fee_msat); + +/** + * Creates a [`Bolt12Invoice`] for a [`Refund`] and enqueues it to be sent via an onion + * message. + * + * The resulting invoice uses a [`PaymentHash`] recognized by the [`ChannelManager`] and a + * [`BlindedPath`] containing the [`PaymentSecret`] needed to reconstruct the corresponding + * [`PaymentPreimage`]. + * + * # Limitations + * + * Requires a direct connection to an introduction node in [`Refund::paths`] or to + * [`Refund::payer_id`], if empty. This request is best effort; an invoice will be sent to each + * node meeting the aforementioned criteria, but there's no guarantee that they will be + * received and no retries will be made. + * + * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice + */ +MUST_USE_RES struct LDKCResult_NoneBolt12SemanticErrorZ ChannelManager_request_refund_payment(const struct LDKChannelManager *NONNULL_PTR this_arg, const struct LDKRefund *NONNULL_PTR refund); + /** * Gets a payment secret and payment hash for use in an invoice given to a third party wishing * to pay us. @@ -31068,25 +31592,25 @@ MUST_USE_RES bool ChannelManager_get_and_clear_needs_persistence(const struct LD MUST_USE_RES struct LDKBestBlock ChannelManager_current_best_block(const struct LDKChannelManager *NONNULL_PTR this_arg); /** - * Fetches the set of [`NodeFeatures`] flags which are provided by or required by + * Fetches the set of [`NodeFeatures`] flags that are provided by or required by * [`ChannelManager`]. */ MUST_USE_RES struct LDKNodeFeatures ChannelManager_node_features(const struct LDKChannelManager *NONNULL_PTR this_arg); /** - * Fetches the set of [`ChannelFeatures`] flags which are provided by or required by + * Fetches the set of [`ChannelFeatures`] flags that are provided by or required by * [`ChannelManager`]. */ MUST_USE_RES struct LDKChannelFeatures ChannelManager_channel_features(const struct LDKChannelManager *NONNULL_PTR this_arg); /** - * Fetches the set of [`ChannelTypeFeatures`] flags which are provided by or required by + * Fetches the set of [`ChannelTypeFeatures`] flags that are provided by or required by * [`ChannelManager`]. */ MUST_USE_RES struct LDKChannelTypeFeatures ChannelManager_channel_type_features(const struct LDKChannelManager *NONNULL_PTR this_arg); /** - * Fetches the set of [`InitFeatures`] flags which are provided by or required by + * Fetches the set of [`InitFeatures`] flags that are provided by or required by * [`ChannelManager`]. */ MUST_USE_RES struct LDKInitFeatures ChannelManager_init_features(const struct LDKChannelManager *NONNULL_PTR this_arg); @@ -31098,7 +31622,13 @@ MUST_USE_RES struct LDKInitFeatures ChannelManager_init_features(const struct LD struct LDKChannelMessageHandler ChannelManager_as_ChannelMessageHandler(const struct LDKChannelManager *NONNULL_PTR this_arg); /** - * Fetches the set of [`InitFeatures`] flags which are provided by or required by + * Constructs a new OffersMessageHandler which calls the relevant methods on this_arg. + * This copies the `inner` pointer in this_arg and thus the returned OffersMessageHandler must be freed before this_arg is + */ +struct LDKOffersMessageHandler ChannelManager_as_OffersMessageHandler(const struct LDKChannelManager *NONNULL_PTR this_arg); + +/** + * Fetches the set of [`InitFeatures`] flags that are provided by or required by * [`ChannelManager`]. */ struct LDKInitFeatures provided_init_features(const struct LDKUserConfig *NONNULL_PTR config); @@ -33999,6 +34529,11 @@ bool SocketAddressParseError_eq(const enum LDKSocketAddressParseError *NONNULL_P */ struct LDKCResult_SocketAddressSocketAddressParseErrorZ parse_onion_address(struct LDKStr host, uint16_t port); +/** + * Get the string representation of a SocketAddress object + */ +struct LDKStr SocketAddress_to_str(const struct LDKSocketAddress *NONNULL_PTR o); + /** * Read a SocketAddress object from a string */ @@ -35466,12 +36001,6 @@ struct LDKMessageSendEventsProvider IgnoringMessageHandler_as_MessageSendEventsP */ struct LDKRoutingMessageHandler IgnoringMessageHandler_as_RoutingMessageHandler(const struct LDKIgnoringMessageHandler *NONNULL_PTR this_arg); -/** - * Constructs a new OnionMessageProvider which calls the relevant methods on this_arg. - * This copies the `inner` pointer in this_arg and thus the returned OnionMessageProvider must be freed before this_arg is - */ -struct LDKOnionMessageProvider IgnoringMessageHandler_as_OnionMessageProvider(const struct LDKIgnoringMessageHandler *NONNULL_PTR this_arg); - /** * Constructs a new OnionMessageHandler which calls the relevant methods on this_arg. * This copies the `inner` pointer in this_arg and thus the returned OnionMessageHandler must be freed before this_arg is @@ -36767,6 +37296,11 @@ struct LDKCResult_CommitmentTransactionDecodeErrorZ CommitmentTransaction_read(s */ MUST_USE_RES uint64_t CommitmentTransaction_commitment_number(const struct LDKCommitmentTransaction *NONNULL_PTR this_arg); +/** + * The per commitment point used by the broadcaster. + */ +MUST_USE_RES struct LDKPublicKey CommitmentTransaction_per_commitment_point(const struct LDKCommitmentTransaction *NONNULL_PTR this_arg); + /** * The value to be sent to the broadcaster */ @@ -39643,6 +40177,11 @@ MUST_USE_RES struct LDKErroneousField ErroneousField_new(uint64_t tlv_fieldnum_a */ struct LDKErroneousField ErroneousField_clone(const struct LDKErroneousField *NONNULL_PTR orig); +/** + * Creates an [`InvoiceError`] with the given message. + */ +MUST_USE_RES struct LDKInvoiceError InvoiceError_from_string(struct LDKStr s); + /** * Serialize the InvoiceError object into a byte array which can be read by InvoiceError_read */ @@ -40176,6 +40715,11 @@ enum LDKBolt12SemanticError Bolt12SemanticError_missing_payer_metadata(void); */ enum LDKBolt12SemanticError Bolt12SemanticError_missing_payer_id(void); +/** + * Utility method to constructs a new DuplicatePaymentId-variant Bolt12SemanticError + */ +enum LDKBolt12SemanticError Bolt12SemanticError_duplicate_payment_id(void); + /** * Utility method to constructs a new MissingPaths-variant Bolt12SemanticError */ @@ -40496,15 +41040,17 @@ void P2PGossipSync_add_utxo_lookup(const struct LDKP2PGossipSync *NONNULL_PTR th /** * Handles any network updates originating from [`Event`]s. + * Note that this will skip applying any [`NetworkUpdate::ChannelUpdateMessage`] to avoid + * leaking possibly identifying information of the sender to the public network. * * [`Event`]: crate::events::Event */ void NetworkGraph_handle_network_update(const struct LDKNetworkGraph *NONNULL_PTR this_arg, const struct LDKNetworkUpdate *NONNULL_PTR network_update); /** - * Gets the genesis hash for this network graph. + * Gets the chain hash for this network graph. */ -MUST_USE_RES struct LDKThirtyTwoBytes NetworkGraph_get_genesis_hash(const struct LDKNetworkGraph *NONNULL_PTR this_arg); +MUST_USE_RES struct LDKThirtyTwoBytes NetworkGraph_get_chain_hash(const struct LDKNetworkGraph *NONNULL_PTR this_arg); /** * Verifies the signature of a [`NodeAnnouncement`]. @@ -41255,8 +41801,8 @@ void NetworkGraph_remove_stale_channels_and_tracking_with_time(const struct LDKN * For an already known (from announcement) channel, update info about one of the directions * of the channel. * - * You probably don't want to call this directly, instead relying on a P2PGossipSync's - * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept + * You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s + * [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept * routing messages from a source using a protocol other than the lightning P2P protocol. * * If built with `no-std`, any updates with a timestamp more than two weeks in the past or @@ -41274,6 +41820,16 @@ MUST_USE_RES struct LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel(c */ MUST_USE_RES struct LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel_unsigned(const struct LDKNetworkGraph *NONNULL_PTR this_arg, const struct LDKUnsignedChannelUpdate *NONNULL_PTR msg); +/** + * For an already known (from announcement) channel, verify the given [`ChannelUpdate`]. + * + * This checks whether the update currently is applicable by [`Self::update_channel`]. + * + * If built with `no-std`, any updates with a timestamp more than two weeks in the past or + * materially in the future will be rejected. + */ +MUST_USE_RES struct LDKCResult_NoneLightningErrorZ NetworkGraph_verify_channel_update(const struct LDKNetworkGraph *NONNULL_PTR this_arg, const struct LDKChannelUpdate *NONNULL_PTR msg); + /** * Returns information on a channel with the given id. * @@ -43263,6 +43819,221 @@ struct LDKCResult_SpendableOutputDescriptorDecodeErrorZ SpendableOutputDescripto */ MUST_USE_RES struct LDKCResult_C2Tuple_CVec_u8ZusizeZNoneZ SpendableOutputDescriptor_create_spendable_outputs_psbt(struct LDKCVec_SpendableOutputDescriptorZ descriptors, struct LDKCVec_TxOutZ outputs, struct LDKCVec_u8Z change_destination_script, uint32_t feerate_sat_per_1000_weight, struct LDKCOption_u32Z locktime); +/** + * Frees any resources used by the ChannelDerivationParameters, if is_owned is set and inner is non-NULL. + */ +void ChannelDerivationParameters_free(struct LDKChannelDerivationParameters this_obj); + +/** + * The value in satoshis of the channel we're attempting to spend the anchor output of. + */ +uint64_t ChannelDerivationParameters_get_value_satoshis(const struct LDKChannelDerivationParameters *NONNULL_PTR this_ptr); + +/** + * The value in satoshis of the channel we're attempting to spend the anchor output of. + */ +void ChannelDerivationParameters_set_value_satoshis(struct LDKChannelDerivationParameters *NONNULL_PTR this_ptr, uint64_t val); + +/** + * The unique identifier to re-derive the signer for the associated channel. + */ +const uint8_t (*ChannelDerivationParameters_get_keys_id(const struct LDKChannelDerivationParameters *NONNULL_PTR this_ptr))[32]; + +/** + * The unique identifier to re-derive the signer for the associated channel. + */ +void ChannelDerivationParameters_set_keys_id(struct LDKChannelDerivationParameters *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); + +/** + * The necessary channel parameters that need to be provided to the re-derived signer through + * [`ChannelSigner::provide_channel_parameters`]. + */ +struct LDKChannelTransactionParameters ChannelDerivationParameters_get_transaction_parameters(const struct LDKChannelDerivationParameters *NONNULL_PTR this_ptr); + +/** + * The necessary channel parameters that need to be provided to the re-derived signer through + * [`ChannelSigner::provide_channel_parameters`]. + */ +void ChannelDerivationParameters_set_transaction_parameters(struct LDKChannelDerivationParameters *NONNULL_PTR this_ptr, struct LDKChannelTransactionParameters val); + +/** + * Constructs a new ChannelDerivationParameters given each field + */ +MUST_USE_RES struct LDKChannelDerivationParameters ChannelDerivationParameters_new(uint64_t value_satoshis_arg, struct LDKThirtyTwoBytes keys_id_arg, struct LDKChannelTransactionParameters transaction_parameters_arg); + +/** + * Creates a copy of the ChannelDerivationParameters + */ +struct LDKChannelDerivationParameters ChannelDerivationParameters_clone(const struct LDKChannelDerivationParameters *NONNULL_PTR orig); + +/** + * Checks if two ChannelDerivationParameterss contain equal inner contents. + * This ignores pointers and is_owned flags and looks at the values in fields. + * Two objects with NULL inner values will be considered "equal" here. + */ +bool ChannelDerivationParameters_eq(const struct LDKChannelDerivationParameters *NONNULL_PTR a, const struct LDKChannelDerivationParameters *NONNULL_PTR b); + +/** + * Serialize the ChannelDerivationParameters object into a byte array which can be read by ChannelDerivationParameters_read + */ +struct LDKCVec_u8Z ChannelDerivationParameters_write(const struct LDKChannelDerivationParameters *NONNULL_PTR obj); + +/** + * Read a ChannelDerivationParameters from a byte array, created by ChannelDerivationParameters_write + */ +struct LDKCResult_ChannelDerivationParametersDecodeErrorZ ChannelDerivationParameters_read(struct LDKu8slice ser); + +/** + * Frees any resources used by the HTLCDescriptor, if is_owned is set and inner is non-NULL. + */ +void HTLCDescriptor_free(struct LDKHTLCDescriptor this_obj); + +/** + * The parameters required to derive the signer for the HTLC input. + */ +struct LDKChannelDerivationParameters HTLCDescriptor_get_channel_derivation_parameters(const struct LDKHTLCDescriptor *NONNULL_PTR this_ptr); + +/** + * The parameters required to derive the signer for the HTLC input. + */ +void HTLCDescriptor_set_channel_derivation_parameters(struct LDKHTLCDescriptor *NONNULL_PTR this_ptr, struct LDKChannelDerivationParameters val); + +/** + * The number of the commitment transaction in which the HTLC output lives. + */ +uint64_t HTLCDescriptor_get_per_commitment_number(const struct LDKHTLCDescriptor *NONNULL_PTR this_ptr); + +/** + * The number of the commitment transaction in which the HTLC output lives. + */ +void HTLCDescriptor_set_per_commitment_number(struct LDKHTLCDescriptor *NONNULL_PTR this_ptr, uint64_t val); + +/** + * The key tweak corresponding to the number of the commitment transaction in which the HTLC + * output lives. This tweak is applied to all the basepoints for both parties in the channel to + * arrive at unique keys per commitment. + * + * See for more info. + */ +struct LDKPublicKey HTLCDescriptor_get_per_commitment_point(const struct LDKHTLCDescriptor *NONNULL_PTR this_ptr); + +/** + * The key tweak corresponding to the number of the commitment transaction in which the HTLC + * output lives. This tweak is applied to all the basepoints for both parties in the channel to + * arrive at unique keys per commitment. + * + * See for more info. + */ +void HTLCDescriptor_set_per_commitment_point(struct LDKHTLCDescriptor *NONNULL_PTR this_ptr, struct LDKPublicKey val); + +/** + * The feerate to use on the HTLC claiming transaction. This is always `0` for HTLCs + * originating from a channel supporting anchor outputs, otherwise it is the channel's + * negotiated feerate at the time the commitment transaction was built. + */ +uint32_t HTLCDescriptor_get_feerate_per_kw(const struct LDKHTLCDescriptor *NONNULL_PTR this_ptr); + +/** + * The feerate to use on the HTLC claiming transaction. This is always `0` for HTLCs + * originating from a channel supporting anchor outputs, otherwise it is the channel's + * negotiated feerate at the time the commitment transaction was built. + */ +void HTLCDescriptor_set_feerate_per_kw(struct LDKHTLCDescriptor *NONNULL_PTR this_ptr, uint32_t val); + +/** + * The details of the HTLC as it appears in the commitment transaction. + */ +struct LDKHTLCOutputInCommitment HTLCDescriptor_get_htlc(const struct LDKHTLCDescriptor *NONNULL_PTR this_ptr); + +/** + * The details of the HTLC as it appears in the commitment transaction. + */ +void HTLCDescriptor_set_htlc(struct LDKHTLCDescriptor *NONNULL_PTR this_ptr, struct LDKHTLCOutputInCommitment val); + +/** + * The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be + * taken. + */ +struct LDKCOption_ThirtyTwoBytesZ HTLCDescriptor_get_preimage(const struct LDKHTLCDescriptor *NONNULL_PTR this_ptr); + +/** + * The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be + * taken. + */ +void HTLCDescriptor_set_preimage(struct LDKHTLCDescriptor *NONNULL_PTR this_ptr, struct LDKCOption_ThirtyTwoBytesZ val); + +/** + * The counterparty's signature required to spend the HTLC output. + */ +struct LDKECDSASignature HTLCDescriptor_get_counterparty_sig(const struct LDKHTLCDescriptor *NONNULL_PTR this_ptr); + +/** + * The counterparty's signature required to spend the HTLC output. + */ +void HTLCDescriptor_set_counterparty_sig(struct LDKHTLCDescriptor *NONNULL_PTR this_ptr, struct LDKECDSASignature val); + +/** + * Creates a copy of the HTLCDescriptor + */ +struct LDKHTLCDescriptor HTLCDescriptor_clone(const struct LDKHTLCDescriptor *NONNULL_PTR orig); + +/** + * Checks if two HTLCDescriptors contain equal inner contents. + * This ignores pointers and is_owned flags and looks at the values in fields. + * Two objects with NULL inner values will be considered "equal" here. + */ +bool HTLCDescriptor_eq(const struct LDKHTLCDescriptor *NONNULL_PTR a, const struct LDKHTLCDescriptor *NONNULL_PTR b); + +/** + * Serialize the HTLCDescriptor object into a byte array which can be read by HTLCDescriptor_read + */ +struct LDKCVec_u8Z HTLCDescriptor_write(const struct LDKHTLCDescriptor *NONNULL_PTR obj); + +/** + * Read a HTLCDescriptor from a byte array, created by HTLCDescriptor_write + */ +struct LDKCResult_HTLCDescriptorDecodeErrorZ HTLCDescriptor_read(struct LDKu8slice ser); + +/** + * Returns the outpoint of the HTLC output in the commitment transaction. This is the outpoint + * being spent by the HTLC input in the HTLC transaction. + */ +MUST_USE_RES struct LDKOutPoint HTLCDescriptor_outpoint(const struct LDKHTLCDescriptor *NONNULL_PTR this_arg); + +/** + * Returns the UTXO to be spent by the HTLC input, which can be obtained via + * [`Self::unsigned_tx_input`]. + */ +MUST_USE_RES struct LDKTxOut HTLCDescriptor_previous_utxo(const struct LDKHTLCDescriptor *NONNULL_PTR this_arg); + +/** + * Returns the unsigned transaction input spending the HTLC output in the commitment + * transaction. + */ +MUST_USE_RES struct LDKTxIn HTLCDescriptor_unsigned_tx_input(const struct LDKHTLCDescriptor *NONNULL_PTR this_arg); + +/** + * Returns the delayed output created as a result of spending the HTLC output in the commitment + * transaction. + */ +MUST_USE_RES struct LDKTxOut HTLCDescriptor_tx_output(const struct LDKHTLCDescriptor *NONNULL_PTR this_arg); + +/** + * Returns the witness script of the HTLC output in the commitment transaction. + */ +MUST_USE_RES struct LDKCVec_u8Z HTLCDescriptor_witness_script(const struct LDKHTLCDescriptor *NONNULL_PTR this_arg); + +/** + * Returns the fully signed witness required to spend the HTLC output in the commitment + * transaction. + */ +MUST_USE_RES struct LDKWitness HTLCDescriptor_tx_input_witness(const struct LDKHTLCDescriptor *NONNULL_PTR this_arg, struct LDKECDSASignature signature, struct LDKu8slice witness_script); + +/** + * Derives the channel signer required to sign the HTLC input. + */ +MUST_USE_RES struct LDKWriteableEcdsaChannelSigner HTLCDescriptor_derive_channel_signer(const struct LDKHTLCDescriptor *NONNULL_PTR this_arg, const struct LDKSignerProvider *NONNULL_PTR signer_provider); + /** * Calls the free function if one is set */ @@ -43811,12 +44582,42 @@ bool SendError_eq(const struct LDKSendError *NONNULL_PTR a, const struct LDKSend void CustomOnionMessageHandler_free(struct LDKCustomOnionMessageHandler this_ptr); /** - * Create an onion message with contents `message` to the destination of `path`. - * Returns (introduction_node_id, onion_msg) + * Frees any resources used by the PeeledOnion + */ +void PeeledOnion_free(struct LDKPeeledOnion this_ptr); + +/** + * Creates a copy of the PeeledOnion + */ +struct LDKPeeledOnion PeeledOnion_clone(const struct LDKPeeledOnion *NONNULL_PTR orig); + +/** + * Utility method to constructs a new Forward-variant PeeledOnion + */ +struct LDKPeeledOnion PeeledOnion_forward(struct LDKPublicKey a, struct LDKOnionMessage b); + +/** + * Utility method to constructs a new Receive-variant PeeledOnion + */ +struct LDKPeeledOnion PeeledOnion_receive(struct LDKParsedOnionMessageContents a, struct LDKThirtyTwoBytes b, struct LDKBlindedPath c); + +/** + * Creates an [`OnionMessage`] with the given `contents` for sending to the destination of + * `path`. + * + * Returns both the node id of the peer to send the message to and the message itself. * * Note that reply_path (or a relevant inner pointer) may be NULL or all-0s to represent None */ -struct LDKCResult_C2Tuple_PublicKeyOnionMessageZSendErrorZ create_onion_message(const struct LDKEntropySource *NONNULL_PTR entropy_source, const struct LDKNodeSigner *NONNULL_PTR node_signer, struct LDKOnionMessagePath path, struct LDKOnionMessageContents message, struct LDKBlindedPath reply_path); +struct LDKCResult_C2Tuple_PublicKeyOnionMessageZSendErrorZ create_onion_message(const struct LDKEntropySource *NONNULL_PTR entropy_source, const struct LDKNodeSigner *NONNULL_PTR node_signer, struct LDKOnionMessagePath path, struct LDKOnionMessageContents contents, struct LDKBlindedPath reply_path); + +/** + * Decode one layer of an incoming [`OnionMessage`]. + * + * Returns either the next layer of the onion for forwarding or the decrypted content for the + * receiver. + */ +struct LDKCResult_PeeledOnionNoneZ peel_onion_message(const struct LDKOnionMessage *NONNULL_PTR msg, struct LDKNodeSigner node_signer, struct LDKLogger logger, struct LDKCustomOnionMessageHandler custom_handler); /** * Constructs a new `OnionMessenger` to send, forward, and delegate received onion messages to @@ -43825,13 +44626,14 @@ struct LDKCResult_C2Tuple_PublicKeyOnionMessageZSendErrorZ create_onion_message( MUST_USE_RES struct LDKOnionMessenger OnionMessenger_new(struct LDKEntropySource entropy_source, struct LDKNodeSigner node_signer, struct LDKLogger logger, struct LDKMessageRouter message_router, struct LDKOffersMessageHandler offers_handler, struct LDKCustomOnionMessageHandler custom_handler); /** - * Send an onion message with contents `message` to the destination of `path`. + * Sends an [`OnionMessage`] with the given `contents` for sending to the destination of + * `path`. * * See [`OnionMessenger`] for example usage. * * Note that reply_path (or a relevant inner pointer) may be NULL or all-0s to represent None */ -MUST_USE_RES struct LDKCResult_NoneSendErrorZ OnionMessenger_send_onion_message(const struct LDKOnionMessenger *NONNULL_PTR this_arg, struct LDKOnionMessagePath path, struct LDKOnionMessageContents message, struct LDKBlindedPath reply_path); +MUST_USE_RES struct LDKCResult_NoneSendErrorZ OnionMessenger_send_onion_message(const struct LDKOnionMessenger *NONNULL_PTR this_arg, struct LDKOnionMessagePath path, struct LDKOnionMessageContents contents, struct LDKBlindedPath reply_path); /** * Constructs a new OnionMessageHandler which calls the relevant methods on this_arg. @@ -43839,12 +44641,6 @@ MUST_USE_RES struct LDKCResult_NoneSendErrorZ OnionMessenger_send_onion_message( */ struct LDKOnionMessageHandler OnionMessenger_as_OnionMessageHandler(const struct LDKOnionMessenger *NONNULL_PTR this_arg); -/** - * Constructs a new OnionMessageProvider which calls the relevant methods on this_arg. - * This copies the `inner` pointer in this_arg and thus the returned OnionMessageProvider must be freed before this_arg is - */ -struct LDKOnionMessageProvider OnionMessenger_as_OnionMessageProvider(const struct LDKOnionMessenger *NONNULL_PTR this_arg); - /** * Calls the free function if one is set */ @@ -43880,11 +44676,6 @@ struct LDKOffersMessage OffersMessage_invoice_error(struct LDKInvoiceError a); */ MUST_USE_RES bool OffersMessage_is_known_type(uint64_t tlv_type); -/** - * The TLV record type for the message as used in an `onionmsg_tlv` TLV stream. - */ -MUST_USE_RES uint64_t OffersMessage_tlv_type(const struct LDKOffersMessage *NONNULL_PTR this_arg); - /** * Serialize the OffersMessage object into a byte array which can be read by OffersMessage_read */ @@ -43965,34 +44756,45 @@ bool Packet_eq(const struct LDKPacket *NONNULL_PTR a, const struct LDKPacket *NO struct LDKCVec_u8Z Packet_write(const struct LDKPacket *NONNULL_PTR obj); /** - * Frees any resources used by the OnionMessageContents + * Frees any resources used by the ParsedOnionMessageContents */ -void OnionMessageContents_free(struct LDKOnionMessageContents this_ptr); +void ParsedOnionMessageContents_free(struct LDKParsedOnionMessageContents this_ptr); /** - * Creates a copy of the OnionMessageContents + * Creates a copy of the ParsedOnionMessageContents */ -struct LDKOnionMessageContents OnionMessageContents_clone(const struct LDKOnionMessageContents *NONNULL_PTR orig); +struct LDKParsedOnionMessageContents ParsedOnionMessageContents_clone(const struct LDKParsedOnionMessageContents *NONNULL_PTR orig); + +/** + * Utility method to constructs a new Offers-variant ParsedOnionMessageContents + */ +struct LDKParsedOnionMessageContents ParsedOnionMessageContents_offers(struct LDKOffersMessage a); /** - * Utility method to constructs a new Offers-variant OnionMessageContents + * Utility method to constructs a new Custom-variant ParsedOnionMessageContents */ -struct LDKOnionMessageContents OnionMessageContents_offers(struct LDKOffersMessage a); +struct LDKParsedOnionMessageContents ParsedOnionMessageContents_custom(struct LDKOnionMessageContents a); /** - * Utility method to constructs a new Custom-variant OnionMessageContents + * Constructs a new OnionMessageContents which calls the relevant methods on this_arg. + * This copies the `inner` pointer in this_arg and thus the returned OnionMessageContents must be freed before this_arg is */ -struct LDKOnionMessageContents OnionMessageContents_custom(struct LDKCustomOnionMessageContents a); +struct LDKOnionMessageContents ParsedOnionMessageContents_as_OnionMessageContents(const struct LDKParsedOnionMessageContents *NONNULL_PTR this_arg); /** - * Creates a copy of a CustomOnionMessageContents + * Serialize the ParsedOnionMessageContents object into a byte array which can be read by ParsedOnionMessageContents_read */ -struct LDKCustomOnionMessageContents CustomOnionMessageContents_clone(const struct LDKCustomOnionMessageContents *NONNULL_PTR orig); +struct LDKCVec_u8Z ParsedOnionMessageContents_write(const struct LDKParsedOnionMessageContents *NONNULL_PTR obj); + +/** + * Creates a copy of a OnionMessageContents + */ +struct LDKOnionMessageContents OnionMessageContents_clone(const struct LDKOnionMessageContents *NONNULL_PTR orig); /** * Calls the free function if one is set */ -void CustomOnionMessageContents_free(struct LDKCustomOnionMessageContents this_ptr); +void OnionMessageContents_free(struct LDKOnionMessageContents this_ptr); /** * Frees any resources used by the BlindedPath, if is_owned is set and inner is non-NULL. @@ -44114,11 +44916,16 @@ uint64_t BlindedHop_hash(const struct LDKBlindedHop *NONNULL_PTR o); */ bool BlindedHop_eq(const struct LDKBlindedHop *NONNULL_PTR a, const struct LDKBlindedHop *NONNULL_PTR b); +/** + * Create a one-hop blinded path for a message. + */ +MUST_USE_RES struct LDKCResult_BlindedPathNoneZ BlindedPath_one_hop_for_message(struct LDKPublicKey recipient_node_id, const struct LDKEntropySource *NONNULL_PTR entropy_source); + /** * Create a blinded path for an onion message, to be forwarded along `node_pks`. The last node * pubkey in `node_pks` will be the destination node. * - * Errors if less than two hops are provided or if `node_pk`(s) are invalid. + * Errors if no hops are provided or if `node_pk`(s) are invalid. */ MUST_USE_RES struct LDKCResult_BlindedPathNoneZ BlindedPath_new_for_message(struct LDKCVec_PublicKeyZ node_pks, const struct LDKEntropySource *NONNULL_PTR entropy_source); @@ -44343,14 +45150,12 @@ struct LDKPaymentRelay PaymentRelay_clone(const struct LDKPaymentRelay *NONNULL_ void PaymentConstraints_free(struct LDKPaymentConstraints this_obj); /** - * The maximum total CLTV delta that is acceptable when relaying a payment over this - * [`BlindedHop`]. + * The maximum total CLTV that is acceptable when relaying a payment over this [`BlindedHop`]. */ uint32_t PaymentConstraints_get_max_cltv_expiry(const struct LDKPaymentConstraints *NONNULL_PTR this_ptr); /** - * The maximum total CLTV delta that is acceptable when relaying a payment over this - * [`BlindedHop`]. + * The maximum total CLTV that is acceptable when relaying a payment over this [`BlindedHop`]. */ void PaymentConstraints_set_max_cltv_expiry(struct LDKPaymentConstraints *NONNULL_PTR this_ptr, uint32_t val); @@ -44777,6 +45582,11 @@ struct LDKEvent Event_payment_claimable(struct LDKPublicKey receiver_node_id, st */ struct LDKEvent Event_payment_claimed(struct LDKPublicKey receiver_node_id, struct LDKThirtyTwoBytes payment_hash, uint64_t amount_msat, struct LDKPaymentPurpose purpose, struct LDKCVec_ClaimedHTLCZ htlcs, struct LDKCOption_u64Z sender_intended_total_msat); +/** + * Utility method to constructs a new InvoiceRequestFailed-variant Event + */ +struct LDKEvent Event_invoice_request_failed(struct LDKThirtyTwoBytes payment_id); + /** * Utility method to constructs a new PaymentSent-variant Event */ @@ -45053,11 +45863,6 @@ struct LDKMessageSendEvent MessageSendEvent_send_gossip_timestamp_filter(struct */ void MessageSendEventsProvider_free(struct LDKMessageSendEventsProvider this_ptr); -/** - * Calls the free function if one is set - */ -void OnionMessageProvider_free(struct LDKOnionMessageProvider this_ptr); - /** * Calls the free function if one is set */ @@ -45068,74 +45873,6 @@ void EventsProvider_free(struct LDKEventsProvider this_ptr); */ void EventHandler_free(struct LDKEventHandler this_ptr); -/** - * Frees any resources used by the ChannelDerivationParameters, if is_owned is set and inner is non-NULL. - */ -void ChannelDerivationParameters_free(struct LDKChannelDerivationParameters this_obj); - -/** - * The value in satoshis of the channel we're attempting to spend the anchor output of. - */ -uint64_t ChannelDerivationParameters_get_value_satoshis(const struct LDKChannelDerivationParameters *NONNULL_PTR this_ptr); - -/** - * The value in satoshis of the channel we're attempting to spend the anchor output of. - */ -void ChannelDerivationParameters_set_value_satoshis(struct LDKChannelDerivationParameters *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The unique identifier to re-derive the signer for the associated channel. - */ -const uint8_t (*ChannelDerivationParameters_get_keys_id(const struct LDKChannelDerivationParameters *NONNULL_PTR this_ptr))[32]; - -/** - * The unique identifier to re-derive the signer for the associated channel. - */ -void ChannelDerivationParameters_set_keys_id(struct LDKChannelDerivationParameters *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The necessary channel parameters that need to be provided to the re-derived signer through - * [`ChannelSigner::provide_channel_parameters`]. - * - * [`ChannelSigner::provide_channel_parameters`]: crate::sign::ChannelSigner::provide_channel_parameters - */ -struct LDKChannelTransactionParameters ChannelDerivationParameters_get_transaction_parameters(const struct LDKChannelDerivationParameters *NONNULL_PTR this_ptr); - -/** - * The necessary channel parameters that need to be provided to the re-derived signer through - * [`ChannelSigner::provide_channel_parameters`]. - * - * [`ChannelSigner::provide_channel_parameters`]: crate::sign::ChannelSigner::provide_channel_parameters - */ -void ChannelDerivationParameters_set_transaction_parameters(struct LDKChannelDerivationParameters *NONNULL_PTR this_ptr, struct LDKChannelTransactionParameters val); - -/** - * Constructs a new ChannelDerivationParameters given each field - */ -MUST_USE_RES struct LDKChannelDerivationParameters ChannelDerivationParameters_new(uint64_t value_satoshis_arg, struct LDKThirtyTwoBytes keys_id_arg, struct LDKChannelTransactionParameters transaction_parameters_arg); - -/** - * Creates a copy of the ChannelDerivationParameters - */ -struct LDKChannelDerivationParameters ChannelDerivationParameters_clone(const struct LDKChannelDerivationParameters *NONNULL_PTR orig); - -/** - * Checks if two ChannelDerivationParameterss contain equal inner contents. - * This ignores pointers and is_owned flags and looks at the values in fields. - * Two objects with NULL inner values will be considered "equal" here. - */ -bool ChannelDerivationParameters_eq(const struct LDKChannelDerivationParameters *NONNULL_PTR a, const struct LDKChannelDerivationParameters *NONNULL_PTR b); - -/** - * Serialize the ChannelDerivationParameters object into a byte array which can be read by ChannelDerivationParameters_read - */ -struct LDKCVec_u8Z ChannelDerivationParameters_write(const struct LDKChannelDerivationParameters *NONNULL_PTR obj); - -/** - * Read a ChannelDerivationParameters from a byte array, created by ChannelDerivationParameters_write - */ -struct LDKCResult_ChannelDerivationParametersDecodeErrorZ ChannelDerivationParameters_read(struct LDKu8slice ser); - /** * Frees any resources used by the AnchorDescriptor, if is_owned is set and inner is non-NULL. */ @@ -45208,143 +45945,6 @@ MUST_USE_RES struct LDKWitness AnchorDescriptor_tx_input_witness(const struct LD */ MUST_USE_RES struct LDKWriteableEcdsaChannelSigner AnchorDescriptor_derive_channel_signer(const struct LDKAnchorDescriptor *NONNULL_PTR this_arg, const struct LDKSignerProvider *NONNULL_PTR signer_provider); -/** - * Frees any resources used by the HTLCDescriptor, if is_owned is set and inner is non-NULL. - */ -void HTLCDescriptor_free(struct LDKHTLCDescriptor this_obj); - -/** - * The parameters required to derive the signer for the HTLC input. - */ -struct LDKChannelDerivationParameters HTLCDescriptor_get_channel_derivation_parameters(const struct LDKHTLCDescriptor *NONNULL_PTR this_ptr); - -/** - * The parameters required to derive the signer for the HTLC input. - */ -void HTLCDescriptor_set_channel_derivation_parameters(struct LDKHTLCDescriptor *NONNULL_PTR this_ptr, struct LDKChannelDerivationParameters val); - -/** - * The number of the commitment transaction in which the HTLC output lives. - */ -uint64_t HTLCDescriptor_get_per_commitment_number(const struct LDKHTLCDescriptor *NONNULL_PTR this_ptr); - -/** - * The number of the commitment transaction in which the HTLC output lives. - */ -void HTLCDescriptor_set_per_commitment_number(struct LDKHTLCDescriptor *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The key tweak corresponding to the number of the commitment transaction in which the HTLC - * output lives. This tweak is applied to all the basepoints for both parties in the channel to - * arrive at unique keys per commitment. - * - * See for more info. - */ -struct LDKPublicKey HTLCDescriptor_get_per_commitment_point(const struct LDKHTLCDescriptor *NONNULL_PTR this_ptr); - -/** - * The key tweak corresponding to the number of the commitment transaction in which the HTLC - * output lives. This tweak is applied to all the basepoints for both parties in the channel to - * arrive at unique keys per commitment. - * - * See for more info. - */ -void HTLCDescriptor_set_per_commitment_point(struct LDKHTLCDescriptor *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * The details of the HTLC as it appears in the commitment transaction. - */ -struct LDKHTLCOutputInCommitment HTLCDescriptor_get_htlc(const struct LDKHTLCDescriptor *NONNULL_PTR this_ptr); - -/** - * The details of the HTLC as it appears in the commitment transaction. - */ -void HTLCDescriptor_set_htlc(struct LDKHTLCDescriptor *NONNULL_PTR this_ptr, struct LDKHTLCOutputInCommitment val); - -/** - * The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be - * taken. - */ -struct LDKCOption_ThirtyTwoBytesZ HTLCDescriptor_get_preimage(const struct LDKHTLCDescriptor *NONNULL_PTR this_ptr); - -/** - * The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be - * taken. - */ -void HTLCDescriptor_set_preimage(struct LDKHTLCDescriptor *NONNULL_PTR this_ptr, struct LDKCOption_ThirtyTwoBytesZ val); - -/** - * The counterparty's signature required to spend the HTLC output. - */ -struct LDKECDSASignature HTLCDescriptor_get_counterparty_sig(const struct LDKHTLCDescriptor *NONNULL_PTR this_ptr); - -/** - * The counterparty's signature required to spend the HTLC output. - */ -void HTLCDescriptor_set_counterparty_sig(struct LDKHTLCDescriptor *NONNULL_PTR this_ptr, struct LDKECDSASignature val); - -/** - * Creates a copy of the HTLCDescriptor - */ -struct LDKHTLCDescriptor HTLCDescriptor_clone(const struct LDKHTLCDescriptor *NONNULL_PTR orig); - -/** - * Checks if two HTLCDescriptors contain equal inner contents. - * This ignores pointers and is_owned flags and looks at the values in fields. - * Two objects with NULL inner values will be considered "equal" here. - */ -bool HTLCDescriptor_eq(const struct LDKHTLCDescriptor *NONNULL_PTR a, const struct LDKHTLCDescriptor *NONNULL_PTR b); - -/** - * Serialize the HTLCDescriptor object into a byte array which can be read by HTLCDescriptor_read - */ -struct LDKCVec_u8Z HTLCDescriptor_write(const struct LDKHTLCDescriptor *NONNULL_PTR obj); - -/** - * Read a HTLCDescriptor from a byte array, created by HTLCDescriptor_write - */ -struct LDKCResult_HTLCDescriptorDecodeErrorZ HTLCDescriptor_read(struct LDKu8slice ser); - -/** - * Returns the outpoint of the HTLC output in the commitment transaction. This is the outpoint - * being spent by the HTLC input in the HTLC transaction. - */ -MUST_USE_RES struct LDKOutPoint HTLCDescriptor_outpoint(const struct LDKHTLCDescriptor *NONNULL_PTR this_arg); - -/** - * Returns the UTXO to be spent by the HTLC input, which can be obtained via - * [`Self::unsigned_tx_input`]. - */ -MUST_USE_RES struct LDKTxOut HTLCDescriptor_previous_utxo(const struct LDKHTLCDescriptor *NONNULL_PTR this_arg); - -/** - * Returns the unsigned transaction input spending the HTLC output in the commitment - * transaction. - */ -MUST_USE_RES struct LDKTxIn HTLCDescriptor_unsigned_tx_input(const struct LDKHTLCDescriptor *NONNULL_PTR this_arg); - -/** - * Returns the delayed output created as a result of spending the HTLC output in the commitment - * transaction. - */ -MUST_USE_RES struct LDKTxOut HTLCDescriptor_tx_output(const struct LDKHTLCDescriptor *NONNULL_PTR this_arg); - -/** - * Returns the witness script of the HTLC output in the commitment transaction. - */ -MUST_USE_RES struct LDKCVec_u8Z HTLCDescriptor_witness_script(const struct LDKHTLCDescriptor *NONNULL_PTR this_arg); - -/** - * Returns the fully signed witness required to spend the HTLC output in the commitment - * transaction. - */ -MUST_USE_RES struct LDKWitness HTLCDescriptor_tx_input_witness(const struct LDKHTLCDescriptor *NONNULL_PTR this_arg, struct LDKECDSASignature signature, struct LDKu8slice witness_script); - -/** - * Derives the channel signer required to sign the HTLC input. - */ -MUST_USE_RES struct LDKWriteableEcdsaChannelSigner HTLCDescriptor_derive_channel_signer(const struct LDKHTLCDescriptor *NONNULL_PTR this_arg, const struct LDKSignerProvider *NONNULL_PTR signer_provider); - /** * Frees any resources used by the BumpTransactionEvent */ diff --git a/lightning-c-bindings/include/lightningpp.hpp b/lightning-c-bindings/include/lightningpp.hpp index 085eef7..30e5744 100644 --- a/lightning-c-bindings/include/lightningpp.hpp +++ b/lightning-c-bindings/include/lightningpp.hpp @@ -14,6 +14,8 @@ class BlindedPayInfo; class DelayedPaymentOutputDescriptor; class StaticPaymentOutputDescriptor; class SpendableOutputDescriptor; +class ChannelDerivationParameters; +class HTLCDescriptor; class ChannelSigner; class EcdsaChannelSigner; class WriteableEcdsaChannelSigner; @@ -84,9 +86,7 @@ class RoutingFees; class NodeAnnouncementInfo; class NodeAlias; class NodeInfo; -class ChannelDerivationParameters; class AnchorDescriptor; -class HTLCDescriptor; class BumpTransactionEvent; class Input; class Utxo; @@ -218,8 +218,8 @@ class BroadcasterInterface; class ConfirmationTarget; class FeeEstimator; class Packet; +class ParsedOnionMessageContents; class OnionMessageContents; -class CustomOnionMessageContents; class PaymentPurpose; class ClaimedHTLC; class PathFailure; @@ -229,7 +229,6 @@ class PaymentFailureReason; class Event; class MessageSendEvent; class MessageSendEventsProvider; -class OnionMessageProvider; class EventsProvider; class EventHandler; class Bolt11ParseError; @@ -278,6 +277,7 @@ class OnionMessagePath; class Destination; class SendError; class CustomOnionMessageHandler; +class PeeledOnion; class FilesystemStore; class BlindedPath; class BlindedHop; @@ -331,6 +331,7 @@ class CResult_ChannelFeaturesDecodeErrorZ; class CResult_ChannelReadyDecodeErrorZ; class CResult_UpdateFeeDecodeErrorZ; class CResult_NoneBolt11SemanticErrorZ; +class COption_OnionMessageContentsZ; class CResult_NoneRetryableSendFailureZ; class CResult_boolLightningErrorZ; class CResult_NodeIdDecodeErrorZ; @@ -347,7 +348,7 @@ class CVec_RouteHopZ; class CVec_C2Tuple_PublicKeyCOption_SocketAddressZZZ; class CResult_CVec_UtxoZNoneZ; class CResult_CVec_u8ZIOErrorZ; -class COption_CustomOnionMessageContentsZ; +class C3Tuple_OffersMessageDestinationBlindedPathZ; class CVec_ThirtyTwoBytesZ; class CResult_ChannelMonitorUpdateStatusNoneZ; class CResult_ClosingSignedDecodeErrorZ; @@ -359,6 +360,7 @@ class CResult_ReceiveTlvsDecodeErrorZ; class CResult_HTLCDescriptorDecodeErrorZ; class CVec_RecentPaymentDetailsZ; class CVec_RouteHintHopZ; +class CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ; class CResult_UntrustedStringDecodeErrorZ; class CVec_U5Z; class CResult_PaymentParametersDecodeErrorZ; @@ -379,7 +381,9 @@ class CResult_DelayedPaymentOutputDescriptorDecodeErrorZ; class CResult_InFlightHtlcsDecodeErrorZ; class CResult_COption_HTLCDestinationZDecodeErrorZ; class CResult_ThirtyTwoBytesNoneZ; +class C3Tuple_OnionMessageContentsDestinationBlindedPathZ; class C3Tuple_RawBolt11Invoice_u832Bolt11InvoiceSignatureZ; +class CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ; class CResult_BlindedHopDecodeErrorZ; class C2Tuple_ThirtyTwoBytesCOption_ThirtyTwoBytesZZ; class CResult_FixedPenaltyScorerDecodeErrorZ; @@ -444,6 +448,7 @@ class CVec_SpendableOutputDescriptorZ; class C2Tuple_OutPointCVec_u8ZZ; class COption_C2Tuple_u64u64ZZ; class CResult_ChannelAnnouncementDecodeErrorZ; +class CResult_PeeledOnionNoneZ; class CResult_HTLCUpdateDecodeErrorZ; class CResult_TxAddInputDecodeErrorZ; class CVec_OutPointZ; @@ -474,7 +479,7 @@ class COption_boolZ; class CVec_CVec_u8ZZ; class CResult_ProbabilisticScorerDecodeErrorZ; class CVec_C2Tuple_ThirtyTwoBytesPublicKeyZZ; -class CResult_COption_CustomOnionMessageContentsZDecodeErrorZ; +class COption_StrZ; class CResult_ShutdownScriptDecodeErrorZ; class C2Tuple_usizeTransactionZ; class CResult_NodeAnnouncementDecodeErrorZ; @@ -533,6 +538,7 @@ class CResult_HostnameDecodeErrorZ; class C2Tuple_u64u16Z; class COption_ThirtyTwoBytesZ; class CVec_u64Z; +class CResult_NoneBolt12SemanticErrorZ; class COption_SecretKeyZ; class CResult_ThirtyTwoBytesPaymentErrorZ; class COption_EventZ; @@ -576,11 +582,12 @@ class CResult_ChannelConfigDecodeErrorZ; class CVec_PrivateRouteZ; class COption_i64Z; class C2Tuple_ThirtyTwoBytesChannelManagerZ; -class CResult_ShutdownDecodeErrorZ; +class CResult_COption_OnionMessageContentsZDecodeErrorZ; class C2Tuple_u64CVec_u8ZZ; class CResult_OfferBolt12ParseErrorZ; class CResult_ThirtyTwoBytesRetryableSendFailureZ; class CVec_MonitorEventZ; +class CResult_ShutdownDecodeErrorZ; class CResult_BigSizeDecodeErrorZ; class CResult_TxOutUtxoLookupErrorZ; class CResult_BlindedPathNoneZ; @@ -799,6 +806,36 @@ public: const LDKSpendableOutputDescriptor* operator &() const { return &self; } const LDKSpendableOutputDescriptor* operator ->() const { return &self; } }; +class ChannelDerivationParameters { +private: + LDKChannelDerivationParameters self; +public: + ChannelDerivationParameters(const ChannelDerivationParameters&) = delete; + ChannelDerivationParameters(ChannelDerivationParameters&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelDerivationParameters)); } + ChannelDerivationParameters(LDKChannelDerivationParameters&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelDerivationParameters)); } + operator LDKChannelDerivationParameters() && { LDKChannelDerivationParameters res = self; memset(&self, 0, sizeof(LDKChannelDerivationParameters)); return res; } + ~ChannelDerivationParameters() { ChannelDerivationParameters_free(self); } + ChannelDerivationParameters& operator=(ChannelDerivationParameters&& o) { ChannelDerivationParameters_free(self); self = o.self; memset(&o, 0, sizeof(ChannelDerivationParameters)); return *this; } + LDKChannelDerivationParameters* operator &() { return &self; } + LDKChannelDerivationParameters* operator ->() { return &self; } + const LDKChannelDerivationParameters* operator &() const { return &self; } + const LDKChannelDerivationParameters* operator ->() const { return &self; } +}; +class HTLCDescriptor { +private: + LDKHTLCDescriptor self; +public: + HTLCDescriptor(const HTLCDescriptor&) = delete; + HTLCDescriptor(HTLCDescriptor&& o) : self(o.self) { memset(&o, 0, sizeof(HTLCDescriptor)); } + HTLCDescriptor(LDKHTLCDescriptor&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKHTLCDescriptor)); } + operator LDKHTLCDescriptor() && { LDKHTLCDescriptor res = self; memset(&self, 0, sizeof(LDKHTLCDescriptor)); return res; } + ~HTLCDescriptor() { HTLCDescriptor_free(self); } + HTLCDescriptor& operator=(HTLCDescriptor&& o) { HTLCDescriptor_free(self); self = o.self; memset(&o, 0, sizeof(HTLCDescriptor)); return *this; } + LDKHTLCDescriptor* operator &() { return &self; } + LDKHTLCDescriptor* operator ->() { return &self; } + const LDKHTLCDescriptor* operator &() const { return &self; } + const LDKHTLCDescriptor* operator ->() const { return &self; } +}; class ChannelSigner { private: LDKChannelSigner self; @@ -903,23 +940,17 @@ public: */ inline LDK::CResult_NoneNoneZ validate_counterparty_revocation(uint64_t idx, const uint8_t (*secret)[32]); /** - * Creates a signature for a holder's commitment transaction and its claiming HTLC transactions. + * Creates a signature for a holder's commitment transaction. * * This will be called * - with a non-revoked `commitment_tx`. * - with the latest `commitment_tx` when we initiate a force-close. - * - with the previous `commitment_tx`, just to get claiming HTLC - * signatures, if we are reacting to a [`ChannelMonitor`] - * [replica](https://github.com/lightningdevkit/rust-lightning/blob/main/GLOSSARY.md#monitor-replicas) - * that decided to broadcast before it had been updated to the latest `commitment_tx`. * * This may be called multiple times for the same transaction. * * An external signer implementation should check that the commitment has not been revoked. - * - * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor */ - inline LDK::CResult_C2Tuple_ECDSASignatureCVec_ECDSASignatureZZNoneZ sign_holder_commitment_and_htlcs(const struct LDKHolderCommitmentTransaction *NONNULL_PTR commitment_tx); + inline LDK::CResult_ECDSASignatureNoneZ sign_holder_commitment(const struct LDKHolderCommitmentTransaction *NONNULL_PTR commitment_tx); /** * Create a signature for the given input in a transaction spending an HTLC transaction output * or a commitment transaction `to_local` output when our counterparty broadcasts an old state. @@ -961,11 +992,14 @@ public: /** * Computes the signature for a commitment transaction's HTLC output used as an input within * `htlc_tx`, which spends the commitment transaction at index `input`. The signature returned - * must be be computed using [`EcdsaSighashType::All`]. Note that this should only be used to - * sign HTLC transactions from channels supporting anchor outputs after all additional - * inputs/outputs have been added to the transaction. + * must be be computed using [`EcdsaSighashType::All`]. + * + * Note that this may be called for HTLCs in the penultimate commitment transaction if a + * [`ChannelMonitor`] [replica](https://github.com/lightningdevkit/rust-lightning/blob/main/GLOSSARY.md#monitor-replicas) + * broadcasts it before receiving the update for the latest commitment transaction. * * [`EcdsaSighashType::All`]: bitcoin::blockdata::transaction::EcdsaSighashType::All + * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor */ inline LDK::CResult_ECDSASignatureNoneZ sign_holder_htlc_transaction(struct LDKTransaction htlc_tx, uintptr_t input, const struct LDKHTLCDescriptor *NONNULL_PTR htlc_descriptor); /** @@ -2363,21 +2397,6 @@ public: const LDKNodeInfo* operator &() const { return &self; } const LDKNodeInfo* operator ->() const { return &self; } }; -class ChannelDerivationParameters { -private: - LDKChannelDerivationParameters self; -public: - ChannelDerivationParameters(const ChannelDerivationParameters&) = delete; - ChannelDerivationParameters(ChannelDerivationParameters&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelDerivationParameters)); } - ChannelDerivationParameters(LDKChannelDerivationParameters&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelDerivationParameters)); } - operator LDKChannelDerivationParameters() && { LDKChannelDerivationParameters res = self; memset(&self, 0, sizeof(LDKChannelDerivationParameters)); return res; } - ~ChannelDerivationParameters() { ChannelDerivationParameters_free(self); } - ChannelDerivationParameters& operator=(ChannelDerivationParameters&& o) { ChannelDerivationParameters_free(self); self = o.self; memset(&o, 0, sizeof(ChannelDerivationParameters)); return *this; } - LDKChannelDerivationParameters* operator &() { return &self; } - LDKChannelDerivationParameters* operator ->() { return &self; } - const LDKChannelDerivationParameters* operator &() const { return &self; } - const LDKChannelDerivationParameters* operator ->() const { return &self; } -}; class AnchorDescriptor { private: LDKAnchorDescriptor self; @@ -2393,21 +2412,6 @@ public: const LDKAnchorDescriptor* operator &() const { return &self; } const LDKAnchorDescriptor* operator ->() const { return &self; } }; -class HTLCDescriptor { -private: - LDKHTLCDescriptor self; -public: - HTLCDescriptor(const HTLCDescriptor&) = delete; - HTLCDescriptor(HTLCDescriptor&& o) : self(o.self) { memset(&o, 0, sizeof(HTLCDescriptor)); } - HTLCDescriptor(LDKHTLCDescriptor&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKHTLCDescriptor)); } - operator LDKHTLCDescriptor() && { LDKHTLCDescriptor res = self; memset(&self, 0, sizeof(LDKHTLCDescriptor)); return res; } - ~HTLCDescriptor() { HTLCDescriptor_free(self); } - HTLCDescriptor& operator=(HTLCDescriptor&& o) { HTLCDescriptor_free(self); self = o.self; memset(&o, 0, sizeof(HTLCDescriptor)); return *this; } - LDKHTLCDescriptor* operator &() { return &self; } - LDKHTLCDescriptor* operator ->() { return &self; } - const LDKHTLCDescriptor* operator &() const { return &self; } - const LDKHTLCDescriptor* operator ->() const { return &self; } -}; class BumpTransactionEvent { private: LDKBumpTransactionEvent self; @@ -4199,12 +4203,12 @@ public: */ inline LDK::InitFeatures provided_init_features(struct LDKPublicKey their_node_id); /** - * Gets the genesis hashes for this `ChannelMessageHandler` indicating which chains it supports. + * Gets the chain hashes for this `ChannelMessageHandler` indicating which chains it supports. * * If it's `None`, then no particular network chain hash compatibility will be enforced when * connecting to peers. */ - inline LDK::COption_CVec_ThirtyTwoBytesZZ get_genesis_hashes(); + inline LDK::COption_CVec_ThirtyTwoBytesZZ get_chain_hashes(); }; class RoutingMessageHandler { private: @@ -4324,6 +4328,12 @@ public: * Handle an incoming `onion_message` message from the given peer. */ inline void handle_onion_message(struct LDKPublicKey peer_node_id, const struct LDKOnionMessage *NONNULL_PTR msg); + /** + * Returns the next pending onion message for the peer with the given node id. + * + * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None + */ + inline LDK::OnionMessage next_onion_message_for_peer(struct LDKPublicKey peer_node_id); /** * Called when a connection is established with a peer. Can be used to track which peers * advertise onion message support and are online. @@ -4467,8 +4477,19 @@ public: /** * Handles the given message by either responding with an [`Bolt12Invoice`], sending a payment, * or replying with an error. + * + * The returned [`OffersMessage`], if any, is enqueued to be sent by [`OnionMessenger`]. + * + * [`OnionMessenger`]: crate::onion_message::OnionMessenger */ inline LDK::COption_OffersMessageZ handle_message(struct LDKOffersMessage message); + /** + * Releases any [`OffersMessage`]s that need to be sent. + * + * Typically, this is used for messages initiating a payment flow rather than in response to + * another message. The latter should use the return value of [`Self::handle_message`]. + */ + inline LDK::CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ release_pending_messages(); }; class OffersMessage { private: @@ -4839,6 +4860,21 @@ public: const LDKPacket* operator &() const { return &self; } const LDKPacket* operator ->() const { return &self; } }; +class ParsedOnionMessageContents { +private: + LDKParsedOnionMessageContents self; +public: + ParsedOnionMessageContents(const ParsedOnionMessageContents&) = delete; + ParsedOnionMessageContents(ParsedOnionMessageContents&& o) : self(o.self) { memset(&o, 0, sizeof(ParsedOnionMessageContents)); } + ParsedOnionMessageContents(LDKParsedOnionMessageContents&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKParsedOnionMessageContents)); } + operator LDKParsedOnionMessageContents() && { LDKParsedOnionMessageContents res = self; memset(&self, 0, sizeof(LDKParsedOnionMessageContents)); return res; } + ~ParsedOnionMessageContents() { ParsedOnionMessageContents_free(self); } + ParsedOnionMessageContents& operator=(ParsedOnionMessageContents&& o) { ParsedOnionMessageContents_free(self); self = o.self; memset(&o, 0, sizeof(ParsedOnionMessageContents)); return *this; } + LDKParsedOnionMessageContents* operator &() { return &self; } + LDKParsedOnionMessageContents* operator ->() { return &self; } + const LDKParsedOnionMessageContents* operator &() const { return &self; } + const LDKParsedOnionMessageContents* operator ->() const { return &self; } +}; class OnionMessageContents { private: LDKOnionMessageContents self; @@ -4853,21 +4889,6 @@ public: LDKOnionMessageContents* operator ->() { return &self; } const LDKOnionMessageContents* operator &() const { return &self; } const LDKOnionMessageContents* operator ->() const { return &self; } -}; -class CustomOnionMessageContents { -private: - LDKCustomOnionMessageContents self; -public: - CustomOnionMessageContents(const CustomOnionMessageContents&) = delete; - CustomOnionMessageContents(CustomOnionMessageContents&& o) : self(o.self) { memset(&o, 0, sizeof(CustomOnionMessageContents)); } - CustomOnionMessageContents(LDKCustomOnionMessageContents&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCustomOnionMessageContents)); } - operator LDKCustomOnionMessageContents() && { LDKCustomOnionMessageContents res = self; memset(&self, 0, sizeof(LDKCustomOnionMessageContents)); return res; } - ~CustomOnionMessageContents() { CustomOnionMessageContents_free(self); } - CustomOnionMessageContents& operator=(CustomOnionMessageContents&& o) { CustomOnionMessageContents_free(self); self = o.self; memset(&o, 0, sizeof(CustomOnionMessageContents)); return *this; } - LDKCustomOnionMessageContents* operator &() { return &self; } - LDKCustomOnionMessageContents* operator ->() { return &self; } - const LDKCustomOnionMessageContents* operator &() const { return &self; } - const LDKCustomOnionMessageContents* operator ->() const { return &self; } /** * Returns the TLV type identifying the message contents. MUST be >= 64. */ @@ -5012,27 +5033,6 @@ public: */ inline LDK::CVec_MessageSendEventZ get_and_clear_pending_msg_events(); }; -class OnionMessageProvider { -private: - LDKOnionMessageProvider self; -public: - OnionMessageProvider(const OnionMessageProvider&) = delete; - OnionMessageProvider(OnionMessageProvider&& o) : self(o.self) { memset(&o, 0, sizeof(OnionMessageProvider)); } - OnionMessageProvider(LDKOnionMessageProvider&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKOnionMessageProvider)); } - operator LDKOnionMessageProvider() && { LDKOnionMessageProvider res = self; memset(&self, 0, sizeof(LDKOnionMessageProvider)); return res; } - ~OnionMessageProvider() { OnionMessageProvider_free(self); } - OnionMessageProvider& operator=(OnionMessageProvider&& o) { OnionMessageProvider_free(self); self = o.self; memset(&o, 0, sizeof(OnionMessageProvider)); return *this; } - LDKOnionMessageProvider* operator &() { return &self; } - LDKOnionMessageProvider* operator ->() { return &self; } - const LDKOnionMessageProvider* operator &() const { return &self; } - const LDKOnionMessageProvider* operator ->() const { return &self; } - /** - * Gets the next pending onion message for the peer with the given node id. - * - * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None - */ - inline LDK::OnionMessage next_onion_message_for_peer(struct LDKPublicKey peer_node_id); -}; class EventsProvider { private: LDKEventsProvider self; @@ -5656,12 +5656,12 @@ public: const LDKUtxoLookup* operator ->() const { return &self; } /** * Returns the transaction output of a funding transaction encoded by [`short_channel_id`]. - * Returns an error if `genesis_hash` is for a different chain or if such a transaction output - * is unknown. + * Returns an error if `chain_hash` is for a different chain or if such a transaction output is + * unknown. * * [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id */ - inline LDK::UtxoResult get_utxo(const uint8_t (*genesis_hash)[32], uint64_t short_channel_id); + inline LDK::UtxoResult get_utxo(const uint8_t (*chain_hash)[32], uint64_t short_channel_id); }; class UtxoFuture { private: @@ -5709,8 +5709,6 @@ public: const LDKMessageRouter* operator ->() const { return &self; } /** * Returns a route for sending an [`OnionMessage`] to the given [`Destination`]. - * - * [`OnionMessage`]: msgs::OnionMessage */ inline LDK::CResult_OnionMessagePathNoneZ find_path(struct LDKPublicKey sender, struct LDKCVec_PublicKeyZ peers, struct LDKDestination destination); }; @@ -5790,13 +5788,37 @@ public: const LDKCustomOnionMessageHandler* operator ->() const { return &self; } /** * Called with the custom message that was received, returning a response to send, if any. + * + * The returned [`Self::CustomMessage`], if any, is enqueued to be sent by [`OnionMessenger`]. */ - inline LDK::COption_CustomOnionMessageContentsZ handle_custom_message(struct LDKCustomOnionMessageContents msg); + inline LDK::COption_OnionMessageContentsZ handle_custom_message(struct LDKOnionMessageContents msg); /** * Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the * message type is unknown. */ - inline LDK::CResult_COption_CustomOnionMessageContentsZDecodeErrorZ read_custom_message(uint64_t message_type, struct LDKu8slice buffer); + inline LDK::CResult_COption_OnionMessageContentsZDecodeErrorZ read_custom_message(uint64_t message_type, struct LDKu8slice buffer); + /** + * Releases any [`Self::CustomMessage`]s that need to be sent. + * + * Typically, this is used for messages initiating a message flow rather than in response to + * another message. The latter should use the return value of [`Self::handle_custom_message`]. + */ + inline LDK::CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ release_pending_custom_messages(); +}; +class PeeledOnion { +private: + LDKPeeledOnion self; +public: + PeeledOnion(const PeeledOnion&) = delete; + PeeledOnion(PeeledOnion&& o) : self(o.self) { memset(&o, 0, sizeof(PeeledOnion)); } + PeeledOnion(LDKPeeledOnion&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKPeeledOnion)); } + operator LDKPeeledOnion() && { LDKPeeledOnion res = self; memset(&self, 0, sizeof(LDKPeeledOnion)); return res; } + ~PeeledOnion() { PeeledOnion_free(self); } + PeeledOnion& operator=(PeeledOnion&& o) { PeeledOnion_free(self); self = o.self; memset(&o, 0, sizeof(PeeledOnion)); return *this; } + LDKPeeledOnion* operator &() { return &self; } + LDKPeeledOnion* operator ->() { return &self; } + const LDKPeeledOnion* operator &() const { return &self; } + const LDKPeeledOnion* operator ->() const { return &self; } }; class FilesystemStore { private: @@ -6649,6 +6671,21 @@ public: const LDKCResult_NoneBolt11SemanticErrorZ* operator &() const { return &self; } const LDKCResult_NoneBolt11SemanticErrorZ* operator ->() const { return &self; } }; +class COption_OnionMessageContentsZ { +private: + LDKCOption_OnionMessageContentsZ self; +public: + COption_OnionMessageContentsZ(const COption_OnionMessageContentsZ&) = delete; + COption_OnionMessageContentsZ(COption_OnionMessageContentsZ&& o) : self(o.self) { memset(&o, 0, sizeof(COption_OnionMessageContentsZ)); } + COption_OnionMessageContentsZ(LDKCOption_OnionMessageContentsZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCOption_OnionMessageContentsZ)); } + operator LDKCOption_OnionMessageContentsZ() && { LDKCOption_OnionMessageContentsZ res = self; memset(&self, 0, sizeof(LDKCOption_OnionMessageContentsZ)); return res; } + ~COption_OnionMessageContentsZ() { COption_OnionMessageContentsZ_free(self); } + COption_OnionMessageContentsZ& operator=(COption_OnionMessageContentsZ&& o) { COption_OnionMessageContentsZ_free(self); self = o.self; memset(&o, 0, sizeof(COption_OnionMessageContentsZ)); return *this; } + LDKCOption_OnionMessageContentsZ* operator &() { return &self; } + LDKCOption_OnionMessageContentsZ* operator ->() { return &self; } + const LDKCOption_OnionMessageContentsZ* operator &() const { return &self; } + const LDKCOption_OnionMessageContentsZ* operator ->() const { return &self; } +}; class CResult_NoneRetryableSendFailureZ { private: LDKCResult_NoneRetryableSendFailureZ self; @@ -6889,20 +6926,20 @@ public: const LDKCResult_CVec_u8ZIOErrorZ* operator &() const { return &self; } const LDKCResult_CVec_u8ZIOErrorZ* operator ->() const { return &self; } }; -class COption_CustomOnionMessageContentsZ { +class C3Tuple_OffersMessageDestinationBlindedPathZ { private: - LDKCOption_CustomOnionMessageContentsZ self; + LDKC3Tuple_OffersMessageDestinationBlindedPathZ self; public: - COption_CustomOnionMessageContentsZ(const COption_CustomOnionMessageContentsZ&) = delete; - COption_CustomOnionMessageContentsZ(COption_CustomOnionMessageContentsZ&& o) : self(o.self) { memset(&o, 0, sizeof(COption_CustomOnionMessageContentsZ)); } - COption_CustomOnionMessageContentsZ(LDKCOption_CustomOnionMessageContentsZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCOption_CustomOnionMessageContentsZ)); } - operator LDKCOption_CustomOnionMessageContentsZ() && { LDKCOption_CustomOnionMessageContentsZ res = self; memset(&self, 0, sizeof(LDKCOption_CustomOnionMessageContentsZ)); return res; } - ~COption_CustomOnionMessageContentsZ() { COption_CustomOnionMessageContentsZ_free(self); } - COption_CustomOnionMessageContentsZ& operator=(COption_CustomOnionMessageContentsZ&& o) { COption_CustomOnionMessageContentsZ_free(self); self = o.self; memset(&o, 0, sizeof(COption_CustomOnionMessageContentsZ)); return *this; } - LDKCOption_CustomOnionMessageContentsZ* operator &() { return &self; } - LDKCOption_CustomOnionMessageContentsZ* operator ->() { return &self; } - const LDKCOption_CustomOnionMessageContentsZ* operator &() const { return &self; } - const LDKCOption_CustomOnionMessageContentsZ* operator ->() const { return &self; } + C3Tuple_OffersMessageDestinationBlindedPathZ(const C3Tuple_OffersMessageDestinationBlindedPathZ&) = delete; + C3Tuple_OffersMessageDestinationBlindedPathZ(C3Tuple_OffersMessageDestinationBlindedPathZ&& o) : self(o.self) { memset(&o, 0, sizeof(C3Tuple_OffersMessageDestinationBlindedPathZ)); } + C3Tuple_OffersMessageDestinationBlindedPathZ(LDKC3Tuple_OffersMessageDestinationBlindedPathZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKC3Tuple_OffersMessageDestinationBlindedPathZ)); } + operator LDKC3Tuple_OffersMessageDestinationBlindedPathZ() && { LDKC3Tuple_OffersMessageDestinationBlindedPathZ res = self; memset(&self, 0, sizeof(LDKC3Tuple_OffersMessageDestinationBlindedPathZ)); return res; } + ~C3Tuple_OffersMessageDestinationBlindedPathZ() { C3Tuple_OffersMessageDestinationBlindedPathZ_free(self); } + C3Tuple_OffersMessageDestinationBlindedPathZ& operator=(C3Tuple_OffersMessageDestinationBlindedPathZ&& o) { C3Tuple_OffersMessageDestinationBlindedPathZ_free(self); self = o.self; memset(&o, 0, sizeof(C3Tuple_OffersMessageDestinationBlindedPathZ)); return *this; } + LDKC3Tuple_OffersMessageDestinationBlindedPathZ* operator &() { return &self; } + LDKC3Tuple_OffersMessageDestinationBlindedPathZ* operator ->() { return &self; } + const LDKC3Tuple_OffersMessageDestinationBlindedPathZ* operator &() const { return &self; } + const LDKC3Tuple_OffersMessageDestinationBlindedPathZ* operator ->() const { return &self; } }; class CVec_ThirtyTwoBytesZ { private: @@ -7069,6 +7106,21 @@ public: const LDKCVec_RouteHintHopZ* operator &() const { return &self; } const LDKCVec_RouteHintHopZ* operator ->() const { return &self; } }; +class CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ { +private: + LDKCVec_C3Tuple_OffersMessageDestinationBlindedPathZZ self; +public: + CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ(const CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ&) = delete; + CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ(CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ)); } + CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ(LDKCVec_C3Tuple_OffersMessageDestinationBlindedPathZZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_C3Tuple_OffersMessageDestinationBlindedPathZZ)); } + operator LDKCVec_C3Tuple_OffersMessageDestinationBlindedPathZZ() && { LDKCVec_C3Tuple_OffersMessageDestinationBlindedPathZZ res = self; memset(&self, 0, sizeof(LDKCVec_C3Tuple_OffersMessageDestinationBlindedPathZZ)); return res; } + ~CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ() { CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ_free(self); } + CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ& operator=(CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ&& o) { CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ)); return *this; } + LDKCVec_C3Tuple_OffersMessageDestinationBlindedPathZZ* operator &() { return &self; } + LDKCVec_C3Tuple_OffersMessageDestinationBlindedPathZZ* operator ->() { return &self; } + const LDKCVec_C3Tuple_OffersMessageDestinationBlindedPathZZ* operator &() const { return &self; } + const LDKCVec_C3Tuple_OffersMessageDestinationBlindedPathZZ* operator ->() const { return &self; } +}; class CResult_UntrustedStringDecodeErrorZ { private: LDKCResult_UntrustedStringDecodeErrorZ self; @@ -7369,6 +7421,21 @@ public: const LDKCResult_ThirtyTwoBytesNoneZ* operator &() const { return &self; } const LDKCResult_ThirtyTwoBytesNoneZ* operator ->() const { return &self; } }; +class C3Tuple_OnionMessageContentsDestinationBlindedPathZ { +private: + LDKC3Tuple_OnionMessageContentsDestinationBlindedPathZ self; +public: + C3Tuple_OnionMessageContentsDestinationBlindedPathZ(const C3Tuple_OnionMessageContentsDestinationBlindedPathZ&) = delete; + C3Tuple_OnionMessageContentsDestinationBlindedPathZ(C3Tuple_OnionMessageContentsDestinationBlindedPathZ&& o) : self(o.self) { memset(&o, 0, sizeof(C3Tuple_OnionMessageContentsDestinationBlindedPathZ)); } + C3Tuple_OnionMessageContentsDestinationBlindedPathZ(LDKC3Tuple_OnionMessageContentsDestinationBlindedPathZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKC3Tuple_OnionMessageContentsDestinationBlindedPathZ)); } + operator LDKC3Tuple_OnionMessageContentsDestinationBlindedPathZ() && { LDKC3Tuple_OnionMessageContentsDestinationBlindedPathZ res = self; memset(&self, 0, sizeof(LDKC3Tuple_OnionMessageContentsDestinationBlindedPathZ)); return res; } + ~C3Tuple_OnionMessageContentsDestinationBlindedPathZ() { C3Tuple_OnionMessageContentsDestinationBlindedPathZ_free(self); } + C3Tuple_OnionMessageContentsDestinationBlindedPathZ& operator=(C3Tuple_OnionMessageContentsDestinationBlindedPathZ&& o) { C3Tuple_OnionMessageContentsDestinationBlindedPathZ_free(self); self = o.self; memset(&o, 0, sizeof(C3Tuple_OnionMessageContentsDestinationBlindedPathZ)); return *this; } + LDKC3Tuple_OnionMessageContentsDestinationBlindedPathZ* operator &() { return &self; } + LDKC3Tuple_OnionMessageContentsDestinationBlindedPathZ* operator ->() { return &self; } + const LDKC3Tuple_OnionMessageContentsDestinationBlindedPathZ* operator &() const { return &self; } + const LDKC3Tuple_OnionMessageContentsDestinationBlindedPathZ* operator ->() const { return &self; } +}; class C3Tuple_RawBolt11Invoice_u832Bolt11InvoiceSignatureZ { private: LDKC3Tuple_RawBolt11Invoice_u832Bolt11InvoiceSignatureZ self; @@ -7384,6 +7451,21 @@ public: const LDKC3Tuple_RawBolt11Invoice_u832Bolt11InvoiceSignatureZ* operator &() const { return &self; } const LDKC3Tuple_RawBolt11Invoice_u832Bolt11InvoiceSignatureZ* operator ->() const { return &self; } }; +class CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ { +private: + LDKCVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ self; +public: + CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ(const CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ&) = delete; + CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ(CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ)); } + CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ(LDKCVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ)); } + operator LDKCVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ() && { LDKCVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ res = self; memset(&self, 0, sizeof(LDKCVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ)); return res; } + ~CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ() { CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ_free(self); } + CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ& operator=(CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ&& o) { CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ)); return *this; } + LDKCVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ* operator &() { return &self; } + LDKCVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ* operator ->() { return &self; } + const LDKCVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ* operator &() const { return &self; } + const LDKCVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ* operator ->() const { return &self; } +}; class CResult_BlindedHopDecodeErrorZ { private: LDKCResult_BlindedHopDecodeErrorZ self; @@ -8344,6 +8426,21 @@ public: const LDKCResult_ChannelAnnouncementDecodeErrorZ* operator &() const { return &self; } const LDKCResult_ChannelAnnouncementDecodeErrorZ* operator ->() const { return &self; } }; +class CResult_PeeledOnionNoneZ { +private: + LDKCResult_PeeledOnionNoneZ self; +public: + CResult_PeeledOnionNoneZ(const CResult_PeeledOnionNoneZ&) = delete; + CResult_PeeledOnionNoneZ(CResult_PeeledOnionNoneZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_PeeledOnionNoneZ)); } + CResult_PeeledOnionNoneZ(LDKCResult_PeeledOnionNoneZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_PeeledOnionNoneZ)); } + operator LDKCResult_PeeledOnionNoneZ() && { LDKCResult_PeeledOnionNoneZ res = self; memset(&self, 0, sizeof(LDKCResult_PeeledOnionNoneZ)); return res; } + ~CResult_PeeledOnionNoneZ() { CResult_PeeledOnionNoneZ_free(self); } + CResult_PeeledOnionNoneZ& operator=(CResult_PeeledOnionNoneZ&& o) { CResult_PeeledOnionNoneZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_PeeledOnionNoneZ)); return *this; } + LDKCResult_PeeledOnionNoneZ* operator &() { return &self; } + LDKCResult_PeeledOnionNoneZ* operator ->() { return &self; } + const LDKCResult_PeeledOnionNoneZ* operator &() const { return &self; } + const LDKCResult_PeeledOnionNoneZ* operator ->() const { return &self; } +}; class CResult_HTLCUpdateDecodeErrorZ { private: LDKCResult_HTLCUpdateDecodeErrorZ self; @@ -8794,20 +8891,20 @@ public: const LDKCVec_C2Tuple_ThirtyTwoBytesPublicKeyZZ* operator &() const { return &self; } const LDKCVec_C2Tuple_ThirtyTwoBytesPublicKeyZZ* operator ->() const { return &self; } }; -class CResult_COption_CustomOnionMessageContentsZDecodeErrorZ { +class COption_StrZ { private: - LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ self; + LDKCOption_StrZ self; public: - CResult_COption_CustomOnionMessageContentsZDecodeErrorZ(const CResult_COption_CustomOnionMessageContentsZDecodeErrorZ&) = delete; - CResult_COption_CustomOnionMessageContentsZDecodeErrorZ(CResult_COption_CustomOnionMessageContentsZDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_COption_CustomOnionMessageContentsZDecodeErrorZ)); } - CResult_COption_CustomOnionMessageContentsZDecodeErrorZ(LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ)); } - operator LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ() && { LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ)); return res; } - ~CResult_COption_CustomOnionMessageContentsZDecodeErrorZ() { CResult_COption_CustomOnionMessageContentsZDecodeErrorZ_free(self); } - CResult_COption_CustomOnionMessageContentsZDecodeErrorZ& operator=(CResult_COption_CustomOnionMessageContentsZDecodeErrorZ&& o) { CResult_COption_CustomOnionMessageContentsZDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_COption_CustomOnionMessageContentsZDecodeErrorZ)); return *this; } - LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ* operator &() { return &self; } - LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ* operator ->() const { return &self; } + COption_StrZ(const COption_StrZ&) = delete; + COption_StrZ(COption_StrZ&& o) : self(o.self) { memset(&o, 0, sizeof(COption_StrZ)); } + COption_StrZ(LDKCOption_StrZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCOption_StrZ)); } + operator LDKCOption_StrZ() && { LDKCOption_StrZ res = self; memset(&self, 0, sizeof(LDKCOption_StrZ)); return res; } + ~COption_StrZ() { COption_StrZ_free(self); } + COption_StrZ& operator=(COption_StrZ&& o) { COption_StrZ_free(self); self = o.self; memset(&o, 0, sizeof(COption_StrZ)); return *this; } + LDKCOption_StrZ* operator &() { return &self; } + LDKCOption_StrZ* operator ->() { return &self; } + const LDKCOption_StrZ* operator &() const { return &self; } + const LDKCOption_StrZ* operator ->() const { return &self; } }; class CResult_ShutdownScriptDecodeErrorZ { private: @@ -9679,6 +9776,21 @@ public: const LDKCVec_u64Z* operator &() const { return &self; } const LDKCVec_u64Z* operator ->() const { return &self; } }; +class CResult_NoneBolt12SemanticErrorZ { +private: + LDKCResult_NoneBolt12SemanticErrorZ self; +public: + CResult_NoneBolt12SemanticErrorZ(const CResult_NoneBolt12SemanticErrorZ&) = delete; + CResult_NoneBolt12SemanticErrorZ(CResult_NoneBolt12SemanticErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NoneBolt12SemanticErrorZ)); } + CResult_NoneBolt12SemanticErrorZ(LDKCResult_NoneBolt12SemanticErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NoneBolt12SemanticErrorZ)); } + operator LDKCResult_NoneBolt12SemanticErrorZ() && { LDKCResult_NoneBolt12SemanticErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_NoneBolt12SemanticErrorZ)); return res; } + ~CResult_NoneBolt12SemanticErrorZ() { CResult_NoneBolt12SemanticErrorZ_free(self); } + CResult_NoneBolt12SemanticErrorZ& operator=(CResult_NoneBolt12SemanticErrorZ&& o) { CResult_NoneBolt12SemanticErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NoneBolt12SemanticErrorZ)); return *this; } + LDKCResult_NoneBolt12SemanticErrorZ* operator &() { return &self; } + LDKCResult_NoneBolt12SemanticErrorZ* operator ->() { return &self; } + const LDKCResult_NoneBolt12SemanticErrorZ* operator &() const { return &self; } + const LDKCResult_NoneBolt12SemanticErrorZ* operator ->() const { return &self; } +}; class COption_SecretKeyZ { private: LDKCOption_SecretKeyZ self; @@ -10324,20 +10436,20 @@ public: const LDKC2Tuple_ThirtyTwoBytesChannelManagerZ* operator &() const { return &self; } const LDKC2Tuple_ThirtyTwoBytesChannelManagerZ* operator ->() const { return &self; } }; -class CResult_ShutdownDecodeErrorZ { +class CResult_COption_OnionMessageContentsZDecodeErrorZ { private: - LDKCResult_ShutdownDecodeErrorZ self; + LDKCResult_COption_OnionMessageContentsZDecodeErrorZ self; public: - CResult_ShutdownDecodeErrorZ(const CResult_ShutdownDecodeErrorZ&) = delete; - CResult_ShutdownDecodeErrorZ(CResult_ShutdownDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ShutdownDecodeErrorZ)); } - CResult_ShutdownDecodeErrorZ(LDKCResult_ShutdownDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ShutdownDecodeErrorZ)); } - operator LDKCResult_ShutdownDecodeErrorZ() && { LDKCResult_ShutdownDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ShutdownDecodeErrorZ)); return res; } - ~CResult_ShutdownDecodeErrorZ() { CResult_ShutdownDecodeErrorZ_free(self); } - CResult_ShutdownDecodeErrorZ& operator=(CResult_ShutdownDecodeErrorZ&& o) { CResult_ShutdownDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_ShutdownDecodeErrorZ)); return *this; } - LDKCResult_ShutdownDecodeErrorZ* operator &() { return &self; } - LDKCResult_ShutdownDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_ShutdownDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_ShutdownDecodeErrorZ* operator ->() const { return &self; } + CResult_COption_OnionMessageContentsZDecodeErrorZ(const CResult_COption_OnionMessageContentsZDecodeErrorZ&) = delete; + CResult_COption_OnionMessageContentsZDecodeErrorZ(CResult_COption_OnionMessageContentsZDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_COption_OnionMessageContentsZDecodeErrorZ)); } + CResult_COption_OnionMessageContentsZDecodeErrorZ(LDKCResult_COption_OnionMessageContentsZDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_COption_OnionMessageContentsZDecodeErrorZ)); } + operator LDKCResult_COption_OnionMessageContentsZDecodeErrorZ() && { LDKCResult_COption_OnionMessageContentsZDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_COption_OnionMessageContentsZDecodeErrorZ)); return res; } + ~CResult_COption_OnionMessageContentsZDecodeErrorZ() { CResult_COption_OnionMessageContentsZDecodeErrorZ_free(self); } + CResult_COption_OnionMessageContentsZDecodeErrorZ& operator=(CResult_COption_OnionMessageContentsZDecodeErrorZ&& o) { CResult_COption_OnionMessageContentsZDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_COption_OnionMessageContentsZDecodeErrorZ)); return *this; } + LDKCResult_COption_OnionMessageContentsZDecodeErrorZ* operator &() { return &self; } + LDKCResult_COption_OnionMessageContentsZDecodeErrorZ* operator ->() { return &self; } + const LDKCResult_COption_OnionMessageContentsZDecodeErrorZ* operator &() const { return &self; } + const LDKCResult_COption_OnionMessageContentsZDecodeErrorZ* operator ->() const { return &self; } }; class C2Tuple_u64CVec_u8ZZ { private: @@ -10399,6 +10511,21 @@ public: const LDKCVec_MonitorEventZ* operator &() const { return &self; } const LDKCVec_MonitorEventZ* operator ->() const { return &self; } }; +class CResult_ShutdownDecodeErrorZ { +private: + LDKCResult_ShutdownDecodeErrorZ self; +public: + CResult_ShutdownDecodeErrorZ(const CResult_ShutdownDecodeErrorZ&) = delete; + CResult_ShutdownDecodeErrorZ(CResult_ShutdownDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ShutdownDecodeErrorZ)); } + CResult_ShutdownDecodeErrorZ(LDKCResult_ShutdownDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ShutdownDecodeErrorZ)); } + operator LDKCResult_ShutdownDecodeErrorZ() && { LDKCResult_ShutdownDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ShutdownDecodeErrorZ)); return res; } + ~CResult_ShutdownDecodeErrorZ() { CResult_ShutdownDecodeErrorZ_free(self); } + CResult_ShutdownDecodeErrorZ& operator=(CResult_ShutdownDecodeErrorZ&& o) { CResult_ShutdownDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_ShutdownDecodeErrorZ)); return *this; } + LDKCResult_ShutdownDecodeErrorZ* operator &() { return &self; } + LDKCResult_ShutdownDecodeErrorZ* operator ->() { return &self; } + const LDKCResult_ShutdownDecodeErrorZ* operator &() const { return &self; } + const LDKCResult_ShutdownDecodeErrorZ* operator ->() const { return &self; } +}; class CResult_BigSizeDecodeErrorZ { private: LDKCResult_BigSizeDecodeErrorZ self; @@ -10772,8 +10899,8 @@ inline LDK::CResult_NoneNoneZ EcdsaChannelSigner::validate_counterparty_revocati LDK::CResult_NoneNoneZ ret = (self.validate_counterparty_revocation)(self.this_arg, idx, secret); return ret; } -inline LDK::CResult_C2Tuple_ECDSASignatureCVec_ECDSASignatureZZNoneZ EcdsaChannelSigner::sign_holder_commitment_and_htlcs(const struct LDKHolderCommitmentTransaction *NONNULL_PTR commitment_tx) { - LDK::CResult_C2Tuple_ECDSASignatureCVec_ECDSASignatureZZNoneZ ret = (self.sign_holder_commitment_and_htlcs)(self.this_arg, commitment_tx); +inline LDK::CResult_ECDSASignatureNoneZ EcdsaChannelSigner::sign_holder_commitment(const struct LDKHolderCommitmentTransaction *NONNULL_PTR commitment_tx) { + LDK::CResult_ECDSASignatureNoneZ ret = (self.sign_holder_commitment)(self.this_arg, commitment_tx); return ret; } inline LDK::CResult_ECDSASignatureNoneZ EcdsaChannelSigner::sign_justice_revoked_output(struct LDKTransaction justice_tx, uintptr_t input, uint64_t amount, const uint8_t (*per_commitment_key)[32]) { @@ -11109,8 +11236,8 @@ inline LDK::InitFeatures ChannelMessageHandler::provided_init_features(struct LD LDK::InitFeatures ret = (self.provided_init_features)(self.this_arg, their_node_id); return ret; } -inline LDK::COption_CVec_ThirtyTwoBytesZZ ChannelMessageHandler::get_genesis_hashes() { - LDK::COption_CVec_ThirtyTwoBytesZZ ret = (self.get_genesis_hashes)(self.this_arg); +inline LDK::COption_CVec_ThirtyTwoBytesZZ ChannelMessageHandler::get_chain_hashes() { + LDK::COption_CVec_ThirtyTwoBytesZZ ret = (self.get_chain_hashes)(self.this_arg); return ret; } inline LDK::CResult_boolLightningErrorZ RoutingMessageHandler::handle_node_announcement(const struct LDKNodeAnnouncement *NONNULL_PTR msg) { @@ -11168,6 +11295,10 @@ inline LDK::InitFeatures RoutingMessageHandler::provided_init_features(struct LD inline void OnionMessageHandler::handle_onion_message(struct LDKPublicKey peer_node_id, const struct LDKOnionMessage *NONNULL_PTR msg) { (self.handle_onion_message)(self.this_arg, peer_node_id, msg); } +inline LDK::OnionMessage OnionMessageHandler::next_onion_message_for_peer(struct LDKPublicKey peer_node_id) { + LDK::OnionMessage ret = (self.next_onion_message_for_peer)(self.this_arg, peer_node_id); + return ret; +} inline LDK::CResult_NoneNoneZ OnionMessageHandler::peer_connected(struct LDKPublicKey their_node_id, const struct LDKInit *NONNULL_PTR init, bool inbound) { LDK::CResult_NoneNoneZ ret = (self.peer_connected)(self.this_arg, their_node_id, init, inbound); return ret; @@ -11193,6 +11324,10 @@ inline LDK::COption_OffersMessageZ OffersMessageHandler::handle_message(struct L LDK::COption_OffersMessageZ ret = (self.handle_message)(self.this_arg, message); return ret; } +inline LDK::CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ OffersMessageHandler::release_pending_messages() { + LDK::CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ ret = (self.release_pending_messages)(self.this_arg); + return ret; +} inline void BroadcasterInterface::broadcast_transactions(struct LDKCVec_TransactionZ txs) { (self.broadcast_transactions)(self.this_arg, txs); } @@ -11200,7 +11335,7 @@ inline uint32_t FeeEstimator::get_est_sat_per_1000_weight(enum LDKConfirmationTa uint32_t ret = (self.get_est_sat_per_1000_weight)(self.this_arg, confirmation_target); return ret; } -inline uint64_t CustomOnionMessageContents::tlv_type() { +inline uint64_t OnionMessageContents::tlv_type() { uint64_t ret = (self.tlv_type)(self.this_arg); return ret; } @@ -11208,10 +11343,6 @@ inline LDK::CVec_MessageSendEventZ MessageSendEventsProvider::get_and_clear_pend LDK::CVec_MessageSendEventZ ret = (self.get_and_clear_pending_msg_events)(self.this_arg); return ret; } -inline LDK::OnionMessage OnionMessageProvider::next_onion_message_for_peer(struct LDKPublicKey peer_node_id) { - LDK::OnionMessage ret = (self.next_onion_message_for_peer)(self.this_arg, peer_node_id); - return ret; -} inline void EventsProvider::process_pending_events(struct LDKEventHandler handler) { (self.process_pending_events)(self.this_arg, handler); } @@ -11230,20 +11361,24 @@ inline LDK::Str Type::debug_str() { LDK::Str ret = (self.debug_str)(self.this_arg); return ret; } -inline LDK::UtxoResult UtxoLookup::get_utxo(const uint8_t (*genesis_hash)[32], uint64_t short_channel_id) { - LDK::UtxoResult ret = (self.get_utxo)(self.this_arg, genesis_hash, short_channel_id); +inline LDK::UtxoResult UtxoLookup::get_utxo(const uint8_t (*chain_hash)[32], uint64_t short_channel_id) { + LDK::UtxoResult ret = (self.get_utxo)(self.this_arg, chain_hash, short_channel_id); return ret; } inline LDK::CResult_OnionMessagePathNoneZ MessageRouter::find_path(struct LDKPublicKey sender, struct LDKCVec_PublicKeyZ peers, struct LDKDestination destination) { LDK::CResult_OnionMessagePathNoneZ ret = (self.find_path)(self.this_arg, sender, peers, destination); return ret; } -inline LDK::COption_CustomOnionMessageContentsZ CustomOnionMessageHandler::handle_custom_message(struct LDKCustomOnionMessageContents msg) { - LDK::COption_CustomOnionMessageContentsZ ret = (self.handle_custom_message)(self.this_arg, msg); +inline LDK::COption_OnionMessageContentsZ CustomOnionMessageHandler::handle_custom_message(struct LDKOnionMessageContents msg) { + LDK::COption_OnionMessageContentsZ ret = (self.handle_custom_message)(self.this_arg, msg); + return ret; +} +inline LDK::CResult_COption_OnionMessageContentsZDecodeErrorZ CustomOnionMessageHandler::read_custom_message(uint64_t message_type, struct LDKu8slice buffer) { + LDK::CResult_COption_OnionMessageContentsZDecodeErrorZ ret = (self.read_custom_message)(self.this_arg, message_type, buffer); return ret; } -inline LDK::CResult_COption_CustomOnionMessageContentsZDecodeErrorZ CustomOnionMessageHandler::read_custom_message(uint64_t message_type, struct LDKu8slice buffer) { - LDK::CResult_COption_CustomOnionMessageContentsZDecodeErrorZ ret = (self.read_custom_message)(self.this_arg, message_type, buffer); +inline LDK::CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ CustomOnionMessageHandler::release_pending_custom_messages() { + LDK::CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ ret = (self.release_pending_custom_messages)(self.this_arg); return ret; } inline LDK::ChannelMonitorUpdateStatus Persist::persist_new_channel(struct LDKOutPoint channel_id, const struct LDKChannelMonitor *NONNULL_PTR data, struct LDKMonitorUpdateId update_id) { diff --git a/lightning-c-bindings/src/c_types/derived.rs b/lightning-c-bindings/src/c_types/derived.rs index 460823f..ff36cb6 100644 --- a/lightning-c-bindings/src/c_types/derived.rs +++ b/lightning-c-bindings/src/c_types/derived.rs @@ -1686,6 +1686,198 @@ impl Clone for CResult_C2Tuple_CVec_u8ZusizeZNoneZ { /// but with all dynamically-allocated buffers duplicated in new buffers. pub extern "C" fn CResult_C2Tuple_CVec_u8ZusizeZNoneZ_clone(orig: &CResult_C2Tuple_CVec_u8ZusizeZNoneZ) -> CResult_C2Tuple_CVec_u8ZusizeZNoneZ { Clone::clone(&orig) } #[repr(C)] +/// The contents of CResult_ChannelDerivationParametersDecodeErrorZ +pub union CResult_ChannelDerivationParametersDecodeErrorZPtr { + /// A pointer to the contents in the success state. + /// Reading from this pointer when `result_ok` is not set is undefined. + pub result: *mut crate::lightning::sign::ChannelDerivationParameters, + /// A pointer to the contents in the error state. + /// Reading from this pointer when `result_ok` is set is undefined. + pub err: *mut crate::lightning::ln::msgs::DecodeError, +} +#[repr(C)] +/// A CResult_ChannelDerivationParametersDecodeErrorZ represents the result of a fallible operation, +/// containing a crate::lightning::sign::ChannelDerivationParameters on success and a crate::lightning::ln::msgs::DecodeError on failure. +/// `result_ok` indicates the overall state, and the contents are provided via `contents`. +pub struct CResult_ChannelDerivationParametersDecodeErrorZ { + /// The contents of this CResult_ChannelDerivationParametersDecodeErrorZ, accessible via either + /// `err` or `result` depending on the state of `result_ok`. + pub contents: CResult_ChannelDerivationParametersDecodeErrorZPtr, + /// Whether this CResult_ChannelDerivationParametersDecodeErrorZ represents a success state. + pub result_ok: bool, +} +#[no_mangle] +/// Creates a new CResult_ChannelDerivationParametersDecodeErrorZ in the success state. +pub extern "C" fn CResult_ChannelDerivationParametersDecodeErrorZ_ok(o: crate::lightning::sign::ChannelDerivationParameters) -> CResult_ChannelDerivationParametersDecodeErrorZ { + CResult_ChannelDerivationParametersDecodeErrorZ { + contents: CResult_ChannelDerivationParametersDecodeErrorZPtr { + result: Box::into_raw(Box::new(o)), + }, + result_ok: true, + } +} +#[no_mangle] +/// Creates a new CResult_ChannelDerivationParametersDecodeErrorZ in the error state. +pub extern "C" fn CResult_ChannelDerivationParametersDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_ChannelDerivationParametersDecodeErrorZ { + CResult_ChannelDerivationParametersDecodeErrorZ { + contents: CResult_ChannelDerivationParametersDecodeErrorZPtr { + err: Box::into_raw(Box::new(e)), + }, + result_ok: false, + } +} +/// Checks if the given object is currently in the success state +#[no_mangle] +pub extern "C" fn CResult_ChannelDerivationParametersDecodeErrorZ_is_ok(o: &CResult_ChannelDerivationParametersDecodeErrorZ) -> bool { + o.result_ok +} +#[no_mangle] +/// Frees any resources used by the CResult_ChannelDerivationParametersDecodeErrorZ. +pub extern "C" fn CResult_ChannelDerivationParametersDecodeErrorZ_free(_res: CResult_ChannelDerivationParametersDecodeErrorZ) { } +impl Drop for CResult_ChannelDerivationParametersDecodeErrorZ { + fn drop(&mut self) { + if self.result_ok { + if unsafe { !(self.contents.result as *mut ()).is_null() } { + let _ = unsafe { Box::from_raw(self.contents.result) }; + } + } else { + if unsafe { !(self.contents.err as *mut ()).is_null() } { + let _ = unsafe { Box::from_raw(self.contents.err) }; + } + } + } +} +impl From> for CResult_ChannelDerivationParametersDecodeErrorZ { + fn from(mut o: crate::c_types::CResultTempl) -> Self { + let contents = if o.result_ok { + let result = unsafe { o.contents.result }; + unsafe { o.contents.result = core::ptr::null_mut() }; + CResult_ChannelDerivationParametersDecodeErrorZPtr { result } + } else { + let err = unsafe { o.contents.err }; + unsafe { o.contents.err = core::ptr::null_mut(); } + CResult_ChannelDerivationParametersDecodeErrorZPtr { err } + }; + Self { + contents, + result_ok: o.result_ok, + } + } +} +impl Clone for CResult_ChannelDerivationParametersDecodeErrorZ { + fn clone(&self) -> Self { + if self.result_ok { + Self { result_ok: true, contents: CResult_ChannelDerivationParametersDecodeErrorZPtr { + result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) + } } + } else { + Self { result_ok: false, contents: CResult_ChannelDerivationParametersDecodeErrorZPtr { + err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) + } } + } + } +} +#[no_mangle] +/// Creates a new CResult_ChannelDerivationParametersDecodeErrorZ which has the same data as `orig` +/// but with all dynamically-allocated buffers duplicated in new buffers. +pub extern "C" fn CResult_ChannelDerivationParametersDecodeErrorZ_clone(orig: &CResult_ChannelDerivationParametersDecodeErrorZ) -> CResult_ChannelDerivationParametersDecodeErrorZ { Clone::clone(&orig) } +#[repr(C)] +/// The contents of CResult_HTLCDescriptorDecodeErrorZ +pub union CResult_HTLCDescriptorDecodeErrorZPtr { + /// A pointer to the contents in the success state. + /// Reading from this pointer when `result_ok` is not set is undefined. + pub result: *mut crate::lightning::sign::HTLCDescriptor, + /// A pointer to the contents in the error state. + /// Reading from this pointer when `result_ok` is set is undefined. + pub err: *mut crate::lightning::ln::msgs::DecodeError, +} +#[repr(C)] +/// A CResult_HTLCDescriptorDecodeErrorZ represents the result of a fallible operation, +/// containing a crate::lightning::sign::HTLCDescriptor on success and a crate::lightning::ln::msgs::DecodeError on failure. +/// `result_ok` indicates the overall state, and the contents are provided via `contents`. +pub struct CResult_HTLCDescriptorDecodeErrorZ { + /// The contents of this CResult_HTLCDescriptorDecodeErrorZ, accessible via either + /// `err` or `result` depending on the state of `result_ok`. + pub contents: CResult_HTLCDescriptorDecodeErrorZPtr, + /// Whether this CResult_HTLCDescriptorDecodeErrorZ represents a success state. + pub result_ok: bool, +} +#[no_mangle] +/// Creates a new CResult_HTLCDescriptorDecodeErrorZ in the success state. +pub extern "C" fn CResult_HTLCDescriptorDecodeErrorZ_ok(o: crate::lightning::sign::HTLCDescriptor) -> CResult_HTLCDescriptorDecodeErrorZ { + CResult_HTLCDescriptorDecodeErrorZ { + contents: CResult_HTLCDescriptorDecodeErrorZPtr { + result: Box::into_raw(Box::new(o)), + }, + result_ok: true, + } +} +#[no_mangle] +/// Creates a new CResult_HTLCDescriptorDecodeErrorZ in the error state. +pub extern "C" fn CResult_HTLCDescriptorDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_HTLCDescriptorDecodeErrorZ { + CResult_HTLCDescriptorDecodeErrorZ { + contents: CResult_HTLCDescriptorDecodeErrorZPtr { + err: Box::into_raw(Box::new(e)), + }, + result_ok: false, + } +} +/// Checks if the given object is currently in the success state +#[no_mangle] +pub extern "C" fn CResult_HTLCDescriptorDecodeErrorZ_is_ok(o: &CResult_HTLCDescriptorDecodeErrorZ) -> bool { + o.result_ok +} +#[no_mangle] +/// Frees any resources used by the CResult_HTLCDescriptorDecodeErrorZ. +pub extern "C" fn CResult_HTLCDescriptorDecodeErrorZ_free(_res: CResult_HTLCDescriptorDecodeErrorZ) { } +impl Drop for CResult_HTLCDescriptorDecodeErrorZ { + fn drop(&mut self) { + if self.result_ok { + if unsafe { !(self.contents.result as *mut ()).is_null() } { + let _ = unsafe { Box::from_raw(self.contents.result) }; + } + } else { + if unsafe { !(self.contents.err as *mut ()).is_null() } { + let _ = unsafe { Box::from_raw(self.contents.err) }; + } + } + } +} +impl From> for CResult_HTLCDescriptorDecodeErrorZ { + fn from(mut o: crate::c_types::CResultTempl) -> Self { + let contents = if o.result_ok { + let result = unsafe { o.contents.result }; + unsafe { o.contents.result = core::ptr::null_mut() }; + CResult_HTLCDescriptorDecodeErrorZPtr { result } + } else { + let err = unsafe { o.contents.err }; + unsafe { o.contents.err = core::ptr::null_mut(); } + CResult_HTLCDescriptorDecodeErrorZPtr { err } + }; + Self { + contents, + result_ok: o.result_ok, + } + } +} +impl Clone for CResult_HTLCDescriptorDecodeErrorZ { + fn clone(&self) -> Self { + if self.result_ok { + Self { result_ok: true, contents: CResult_HTLCDescriptorDecodeErrorZPtr { + result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) + } } + } else { + Self { result_ok: false, contents: CResult_HTLCDescriptorDecodeErrorZPtr { + err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) + } } + } + } +} +#[no_mangle] +/// Creates a new CResult_HTLCDescriptorDecodeErrorZ which has the same data as `orig` +/// but with all dynamically-allocated buffers duplicated in new buffers. +pub extern "C" fn CResult_HTLCDescriptorDecodeErrorZ_clone(orig: &CResult_HTLCDescriptorDecodeErrorZ) -> CResult_HTLCDescriptorDecodeErrorZ { Clone::clone(&orig) } +#[repr(C)] /// The contents of CResult_NoneNoneZ pub union CResult_NoneNoneZPtr { /// Note that this value is always NULL, as there are no contents in the OK variant @@ -7544,198 +7736,6 @@ pub extern "C" fn COption_CVec_SocketAddressZZ_free(_res: COption_CVec_SocketAdd /// but with all dynamically-allocated buffers duplicated in new buffers. pub extern "C" fn COption_CVec_SocketAddressZZ_clone(orig: &COption_CVec_SocketAddressZZ) -> COption_CVec_SocketAddressZZ { Clone::clone(&orig) } #[repr(C)] -/// The contents of CResult_ChannelDerivationParametersDecodeErrorZ -pub union CResult_ChannelDerivationParametersDecodeErrorZPtr { - /// A pointer to the contents in the success state. - /// Reading from this pointer when `result_ok` is not set is undefined. - pub result: *mut crate::lightning::events::bump_transaction::ChannelDerivationParameters, - /// A pointer to the contents in the error state. - /// Reading from this pointer when `result_ok` is set is undefined. - pub err: *mut crate::lightning::ln::msgs::DecodeError, -} -#[repr(C)] -/// A CResult_ChannelDerivationParametersDecodeErrorZ represents the result of a fallible operation, -/// containing a crate::lightning::events::bump_transaction::ChannelDerivationParameters on success and a crate::lightning::ln::msgs::DecodeError on failure. -/// `result_ok` indicates the overall state, and the contents are provided via `contents`. -pub struct CResult_ChannelDerivationParametersDecodeErrorZ { - /// The contents of this CResult_ChannelDerivationParametersDecodeErrorZ, accessible via either - /// `err` or `result` depending on the state of `result_ok`. - pub contents: CResult_ChannelDerivationParametersDecodeErrorZPtr, - /// Whether this CResult_ChannelDerivationParametersDecodeErrorZ represents a success state. - pub result_ok: bool, -} -#[no_mangle] -/// Creates a new CResult_ChannelDerivationParametersDecodeErrorZ in the success state. -pub extern "C" fn CResult_ChannelDerivationParametersDecodeErrorZ_ok(o: crate::lightning::events::bump_transaction::ChannelDerivationParameters) -> CResult_ChannelDerivationParametersDecodeErrorZ { - CResult_ChannelDerivationParametersDecodeErrorZ { - contents: CResult_ChannelDerivationParametersDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -/// Creates a new CResult_ChannelDerivationParametersDecodeErrorZ in the error state. -pub extern "C" fn CResult_ChannelDerivationParametersDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_ChannelDerivationParametersDecodeErrorZ { - CResult_ChannelDerivationParametersDecodeErrorZ { - contents: CResult_ChannelDerivationParametersDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -/// Checks if the given object is currently in the success state -#[no_mangle] -pub extern "C" fn CResult_ChannelDerivationParametersDecodeErrorZ_is_ok(o: &CResult_ChannelDerivationParametersDecodeErrorZ) -> bool { - o.result_ok -} -#[no_mangle] -/// Frees any resources used by the CResult_ChannelDerivationParametersDecodeErrorZ. -pub extern "C" fn CResult_ChannelDerivationParametersDecodeErrorZ_free(_res: CResult_ChannelDerivationParametersDecodeErrorZ) { } -impl Drop for CResult_ChannelDerivationParametersDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_ChannelDerivationParametersDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = core::ptr::null_mut() }; - CResult_ChannelDerivationParametersDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = core::ptr::null_mut(); } - CResult_ChannelDerivationParametersDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_ChannelDerivationParametersDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_ChannelDerivationParametersDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_ChannelDerivationParametersDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -/// Creates a new CResult_ChannelDerivationParametersDecodeErrorZ which has the same data as `orig` -/// but with all dynamically-allocated buffers duplicated in new buffers. -pub extern "C" fn CResult_ChannelDerivationParametersDecodeErrorZ_clone(orig: &CResult_ChannelDerivationParametersDecodeErrorZ) -> CResult_ChannelDerivationParametersDecodeErrorZ { Clone::clone(&orig) } -#[repr(C)] -/// The contents of CResult_HTLCDescriptorDecodeErrorZ -pub union CResult_HTLCDescriptorDecodeErrorZPtr { - /// A pointer to the contents in the success state. - /// Reading from this pointer when `result_ok` is not set is undefined. - pub result: *mut crate::lightning::events::bump_transaction::HTLCDescriptor, - /// A pointer to the contents in the error state. - /// Reading from this pointer when `result_ok` is set is undefined. - pub err: *mut crate::lightning::ln::msgs::DecodeError, -} -#[repr(C)] -/// A CResult_HTLCDescriptorDecodeErrorZ represents the result of a fallible operation, -/// containing a crate::lightning::events::bump_transaction::HTLCDescriptor on success and a crate::lightning::ln::msgs::DecodeError on failure. -/// `result_ok` indicates the overall state, and the contents are provided via `contents`. -pub struct CResult_HTLCDescriptorDecodeErrorZ { - /// The contents of this CResult_HTLCDescriptorDecodeErrorZ, accessible via either - /// `err` or `result` depending on the state of `result_ok`. - pub contents: CResult_HTLCDescriptorDecodeErrorZPtr, - /// Whether this CResult_HTLCDescriptorDecodeErrorZ represents a success state. - pub result_ok: bool, -} -#[no_mangle] -/// Creates a new CResult_HTLCDescriptorDecodeErrorZ in the success state. -pub extern "C" fn CResult_HTLCDescriptorDecodeErrorZ_ok(o: crate::lightning::events::bump_transaction::HTLCDescriptor) -> CResult_HTLCDescriptorDecodeErrorZ { - CResult_HTLCDescriptorDecodeErrorZ { - contents: CResult_HTLCDescriptorDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -/// Creates a new CResult_HTLCDescriptorDecodeErrorZ in the error state. -pub extern "C" fn CResult_HTLCDescriptorDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_HTLCDescriptorDecodeErrorZ { - CResult_HTLCDescriptorDecodeErrorZ { - contents: CResult_HTLCDescriptorDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -/// Checks if the given object is currently in the success state -#[no_mangle] -pub extern "C" fn CResult_HTLCDescriptorDecodeErrorZ_is_ok(o: &CResult_HTLCDescriptorDecodeErrorZ) -> bool { - o.result_ok -} -#[no_mangle] -/// Frees any resources used by the CResult_HTLCDescriptorDecodeErrorZ. -pub extern "C" fn CResult_HTLCDescriptorDecodeErrorZ_free(_res: CResult_HTLCDescriptorDecodeErrorZ) { } -impl Drop for CResult_HTLCDescriptorDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_HTLCDescriptorDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = core::ptr::null_mut() }; - CResult_HTLCDescriptorDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = core::ptr::null_mut(); } - CResult_HTLCDescriptorDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_HTLCDescriptorDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_HTLCDescriptorDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_HTLCDescriptorDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -/// Creates a new CResult_HTLCDescriptorDecodeErrorZ which has the same data as `orig` -/// but with all dynamically-allocated buffers duplicated in new buffers. -pub extern "C" fn CResult_HTLCDescriptorDecodeErrorZ_clone(orig: &CResult_HTLCDescriptorDecodeErrorZ) -> CResult_HTLCDescriptorDecodeErrorZ { Clone::clone(&orig) } -#[repr(C)] /// A dynamically-allocated array of crate::lightning::ln::chan_utils::HTLCOutputInCommitments of arbitrary size. /// This corresponds to std::vector in C++ pub struct CVec_HTLCOutputInCommitmentZ { @@ -7782,29 +7782,29 @@ impl Clone for CVec_HTLCOutputInCommitmentZ { } } #[repr(C)] -/// A dynamically-allocated array of crate::lightning::events::bump_transaction::HTLCDescriptors of arbitrary size. +/// A dynamically-allocated array of crate::lightning::sign::HTLCDescriptors of arbitrary size. /// This corresponds to std::vector in C++ pub struct CVec_HTLCDescriptorZ { /// The elements in the array. /// If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc(). - pub data: *mut crate::lightning::events::bump_transaction::HTLCDescriptor, + pub data: *mut crate::lightning::sign::HTLCDescriptor, /// The number of elements pointed to by `data`. pub datalen: usize } impl CVec_HTLCDescriptorZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { + #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { if self.datalen == 0 { return Vec::new(); } let ret = unsafe { Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }.into(); self.data = core::ptr::null_mut(); self.datalen = 0; ret } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::lightning::events::bump_transaction::HTLCDescriptor] { + #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::lightning::sign::HTLCDescriptor] { unsafe { core::slice::from_raw_parts_mut(self.data, self.datalen) } } } -impl From> for CVec_HTLCDescriptorZ { - fn from(v: Vec) -> Self { +impl From> for CVec_HTLCDescriptorZ { + fn from(v: Vec) -> Self { let datalen = v.len(); let data = Box::into_raw(v.into_boxed_slice()); Self { datalen, data: unsafe { (*data).as_mut_ptr() } } @@ -9135,6 +9135,135 @@ impl Clone for CVec_C2Tuple_ThirtyTwoBytesPublicKeyZZ { } } #[repr(C)] +#[derive(Clone)] +/// An enum which can either contain a crate::c_types::Str or not +pub enum COption_StrZ { + /// When we're in this state, this COption_StrZ contains a crate::c_types::Str + Some(crate::c_types::Str), + /// When we're in this state, this COption_StrZ contains nothing + None +} +impl COption_StrZ { + #[allow(unused)] pub(crate) fn is_some(&self) -> bool { + if let Self::None = self { false } else { true } + } + #[allow(unused)] pub(crate) fn is_none(&self) -> bool { + !self.is_some() + } + #[allow(unused)] pub(crate) fn take(mut self) -> crate::c_types::Str { + if let Self::Some(v) = self { v } else { unreachable!() } + } +} +#[no_mangle] +/// Constructs a new COption_StrZ containing a crate::c_types::Str +pub extern "C" fn COption_StrZ_some(o: crate::c_types::Str) -> COption_StrZ { + COption_StrZ::Some(o) +} +#[no_mangle] +/// Constructs a new COption_StrZ containing nothing +pub extern "C" fn COption_StrZ_none() -> COption_StrZ { + COption_StrZ::None +} +#[no_mangle] +/// Frees any resources associated with the crate::c_types::Str, if we are in the Some state +pub extern "C" fn COption_StrZ_free(_res: COption_StrZ) { } +#[no_mangle] +/// Creates a new COption_StrZ which has the same data as `orig` +/// but with all dynamically-allocated buffers duplicated in new buffers. +pub extern "C" fn COption_StrZ_clone(orig: &COption_StrZ) -> COption_StrZ { Clone::clone(&orig) } +#[repr(C)] +/// The contents of CResult_NoneBolt12SemanticErrorZ +pub union CResult_NoneBolt12SemanticErrorZPtr { + /// Note that this value is always NULL, as there are no contents in the OK variant + pub result: *mut core::ffi::c_void, + /// A pointer to the contents in the error state. + /// Reading from this pointer when `result_ok` is set is undefined. + pub err: *mut crate::lightning::offers::parse::Bolt12SemanticError, +} +#[repr(C)] +/// A CResult_NoneBolt12SemanticErrorZ represents the result of a fallible operation, +/// containing a () on success and a crate::lightning::offers::parse::Bolt12SemanticError on failure. +/// `result_ok` indicates the overall state, and the contents are provided via `contents`. +pub struct CResult_NoneBolt12SemanticErrorZ { + /// The contents of this CResult_NoneBolt12SemanticErrorZ, accessible via either + /// `err` or `result` depending on the state of `result_ok`. + pub contents: CResult_NoneBolt12SemanticErrorZPtr, + /// Whether this CResult_NoneBolt12SemanticErrorZ represents a success state. + pub result_ok: bool, +} +#[no_mangle] +/// Creates a new CResult_NoneBolt12SemanticErrorZ in the success state. +pub extern "C" fn CResult_NoneBolt12SemanticErrorZ_ok() -> CResult_NoneBolt12SemanticErrorZ { + CResult_NoneBolt12SemanticErrorZ { + contents: CResult_NoneBolt12SemanticErrorZPtr { + result: core::ptr::null_mut(), + }, + result_ok: true, + } +} +#[no_mangle] +/// Creates a new CResult_NoneBolt12SemanticErrorZ in the error state. +pub extern "C" fn CResult_NoneBolt12SemanticErrorZ_err(e: crate::lightning::offers::parse::Bolt12SemanticError) -> CResult_NoneBolt12SemanticErrorZ { + CResult_NoneBolt12SemanticErrorZ { + contents: CResult_NoneBolt12SemanticErrorZPtr { + err: Box::into_raw(Box::new(e)), + }, + result_ok: false, + } +} +/// Checks if the given object is currently in the success state +#[no_mangle] +pub extern "C" fn CResult_NoneBolt12SemanticErrorZ_is_ok(o: &CResult_NoneBolt12SemanticErrorZ) -> bool { + o.result_ok +} +#[no_mangle] +/// Frees any resources used by the CResult_NoneBolt12SemanticErrorZ. +pub extern "C" fn CResult_NoneBolt12SemanticErrorZ_free(_res: CResult_NoneBolt12SemanticErrorZ) { } +impl Drop for CResult_NoneBolt12SemanticErrorZ { + fn drop(&mut self) { + if self.result_ok { + } else { + if unsafe { !(self.contents.err as *mut ()).is_null() } { + let _ = unsafe { Box::from_raw(self.contents.err) }; + } + } + } +} +impl From> for CResult_NoneBolt12SemanticErrorZ { + fn from(mut o: crate::c_types::CResultTempl<(), crate::lightning::offers::parse::Bolt12SemanticError>) -> Self { + let contents = if o.result_ok { + let _ = unsafe { Box::from_raw(o.contents.result) }; + o.contents.result = core::ptr::null_mut(); + CResult_NoneBolt12SemanticErrorZPtr { result: core::ptr::null_mut() } + } else { + let err = unsafe { o.contents.err }; + unsafe { o.contents.err = core::ptr::null_mut(); } + CResult_NoneBolt12SemanticErrorZPtr { err } + }; + Self { + contents, + result_ok: o.result_ok, + } + } +} +impl Clone for CResult_NoneBolt12SemanticErrorZ { + fn clone(&self) -> Self { + if self.result_ok { + Self { result_ok: true, contents: CResult_NoneBolt12SemanticErrorZPtr { + result: core::ptr::null_mut() + } } + } else { + Self { result_ok: false, contents: CResult_NoneBolt12SemanticErrorZPtr { + err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) + } } + } + } +} +#[no_mangle] +/// Creates a new CResult_NoneBolt12SemanticErrorZ which has the same data as `orig` +/// but with all dynamically-allocated buffers duplicated in new buffers. +pub extern "C" fn CResult_NoneBolt12SemanticErrorZ_clone(orig: &CResult_NoneBolt12SemanticErrorZ) -> CResult_NoneBolt12SemanticErrorZ { Clone::clone(&orig) } +#[repr(C)] /// The contents of CResult_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ pub union CResult_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZPtr { /// A pointer to the contents in the success state. @@ -9227,6 +9356,135 @@ impl Clone for CResult_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ { /// but with all dynamically-allocated buffers duplicated in new buffers. pub extern "C" fn CResult_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ_clone(orig: &CResult_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ) -> CResult_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ { Clone::clone(&orig) } #[repr(C)] +#[derive(Clone)] +/// An enum which can either contain a crate::lightning::onion_message::offers::OffersMessage or not +pub enum COption_OffersMessageZ { + /// When we're in this state, this COption_OffersMessageZ contains a crate::lightning::onion_message::offers::OffersMessage + Some(crate::lightning::onion_message::offers::OffersMessage), + /// When we're in this state, this COption_OffersMessageZ contains nothing + None +} +impl COption_OffersMessageZ { + #[allow(unused)] pub(crate) fn is_some(&self) -> bool { + if let Self::None = self { false } else { true } + } + #[allow(unused)] pub(crate) fn is_none(&self) -> bool { + !self.is_some() + } + #[allow(unused)] pub(crate) fn take(mut self) -> crate::lightning::onion_message::offers::OffersMessage { + if let Self::Some(v) = self { v } else { unreachable!() } + } +} +#[no_mangle] +/// Constructs a new COption_OffersMessageZ containing a crate::lightning::onion_message::offers::OffersMessage +pub extern "C" fn COption_OffersMessageZ_some(o: crate::lightning::onion_message::offers::OffersMessage) -> COption_OffersMessageZ { + COption_OffersMessageZ::Some(o) +} +#[no_mangle] +/// Constructs a new COption_OffersMessageZ containing nothing +pub extern "C" fn COption_OffersMessageZ_none() -> COption_OffersMessageZ { + COption_OffersMessageZ::None +} +#[no_mangle] +/// Frees any resources associated with the crate::lightning::onion_message::offers::OffersMessage, if we are in the Some state +pub extern "C" fn COption_OffersMessageZ_free(_res: COption_OffersMessageZ) { } +#[no_mangle] +/// Creates a new COption_OffersMessageZ which has the same data as `orig` +/// but with all dynamically-allocated buffers duplicated in new buffers. +pub extern "C" fn COption_OffersMessageZ_clone(orig: &COption_OffersMessageZ) -> COption_OffersMessageZ { Clone::clone(&orig) } +#[repr(C)] +/// A tuple of 3 elements. See the individual fields for the types contained. +pub struct C3Tuple_OffersMessageDestinationBlindedPathZ { + /// The element at position 0 + pub a: crate::lightning::onion_message::offers::OffersMessage, + /// The element at position 1 + pub b: crate::lightning::onion_message::messenger::Destination, + /// The element at position 2 + pub c: crate::lightning::blinded_path::BlindedPath, +} +impl From<(crate::lightning::onion_message::offers::OffersMessage, crate::lightning::onion_message::messenger::Destination, crate::lightning::blinded_path::BlindedPath)> for C3Tuple_OffersMessageDestinationBlindedPathZ { + fn from (tup: (crate::lightning::onion_message::offers::OffersMessage, crate::lightning::onion_message::messenger::Destination, crate::lightning::blinded_path::BlindedPath)) -> Self { + Self { + a: tup.0, + b: tup.1, + c: tup.2, + } + } +} +impl C3Tuple_OffersMessageDestinationBlindedPathZ { + #[allow(unused)] pub(crate) fn to_rust(mut self) -> (crate::lightning::onion_message::offers::OffersMessage, crate::lightning::onion_message::messenger::Destination, crate::lightning::blinded_path::BlindedPath) { + (self.a, self.b, self.c) + } +} +impl Clone for C3Tuple_OffersMessageDestinationBlindedPathZ { + fn clone(&self) -> Self { + Self { + a: Clone::clone(&self.a), + b: Clone::clone(&self.b), + c: Clone::clone(&self.c), + } + } +} +#[no_mangle] +/// Creates a new tuple which has the same data as `orig` +/// but with all dynamically-allocated buffers duplicated in new buffers. +pub extern "C" fn C3Tuple_OffersMessageDestinationBlindedPathZ_clone(orig: &C3Tuple_OffersMessageDestinationBlindedPathZ) -> C3Tuple_OffersMessageDestinationBlindedPathZ { Clone::clone(&orig) } +/// Creates a new C3Tuple_OffersMessageDestinationBlindedPathZ from the contained elements. +#[no_mangle] +pub extern "C" fn C3Tuple_OffersMessageDestinationBlindedPathZ_new(a: crate::lightning::onion_message::offers::OffersMessage, b: crate::lightning::onion_message::messenger::Destination, c: crate::lightning::blinded_path::BlindedPath) -> C3Tuple_OffersMessageDestinationBlindedPathZ { + C3Tuple_OffersMessageDestinationBlindedPathZ { a, b, c, } +} + +#[no_mangle] +/// Frees any resources used by the C3Tuple_OffersMessageDestinationBlindedPathZ. +pub extern "C" fn C3Tuple_OffersMessageDestinationBlindedPathZ_free(_res: C3Tuple_OffersMessageDestinationBlindedPathZ) { } +#[repr(C)] +/// A dynamically-allocated array of crate::c_types::derived::C3Tuple_OffersMessageDestinationBlindedPathZs of arbitrary size. +/// This corresponds to std::vector in C++ +pub struct CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ { + /// The elements in the array. + /// If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc(). + pub data: *mut crate::c_types::derived::C3Tuple_OffersMessageDestinationBlindedPathZ, + /// The number of elements pointed to by `data`. + pub datalen: usize +} +impl CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ { + #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { + if self.datalen == 0 { return Vec::new(); } + let ret = unsafe { Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }.into(); + self.data = core::ptr::null_mut(); + self.datalen = 0; + ret + } + #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::c_types::derived::C3Tuple_OffersMessageDestinationBlindedPathZ] { + unsafe { core::slice::from_raw_parts_mut(self.data, self.datalen) } + } +} +impl From> for CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ { + fn from(v: Vec) -> Self { + let datalen = v.len(); + let data = Box::into_raw(v.into_boxed_slice()); + Self { datalen, data: unsafe { (*data).as_mut_ptr() } } + } +} +#[no_mangle] +/// Frees the buffer pointed to by `data` if `datalen` is non-0. +pub extern "C" fn CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ_free(_res: CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ) { } +impl Drop for CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ { + fn drop(&mut self) { + if self.datalen == 0 { return; } + let _ = unsafe { Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }; + } +} +impl Clone for CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ { + fn clone(&self) -> Self { + let mut res = Vec::new(); + if self.datalen == 0 { return Self::from(res); } + res.extend_from_slice(unsafe { core::slice::from_raw_parts_mut(self.data, self.datalen) }); + Self::from(res) + } +} +#[repr(C)] /// The contents of CResult_CounterpartyForwardingInfoDecodeErrorZ pub union CResult_CounterpartyForwardingInfoDecodeErrorZPtr { /// A pointer to the contents in the success state. @@ -11308,114 +11566,77 @@ impl Clone for CVec_C2Tuple_PublicKeyTypeZZ { } #[repr(C)] #[derive(Clone)] -/// An enum which can either contain a crate::lightning::onion_message::offers::OffersMessage or not -pub enum COption_OffersMessageZ { - /// When we're in this state, this COption_OffersMessageZ contains a crate::lightning::onion_message::offers::OffersMessage - Some(crate::lightning::onion_message::offers::OffersMessage), - /// When we're in this state, this COption_OffersMessageZ contains nothing - None -} -impl COption_OffersMessageZ { - #[allow(unused)] pub(crate) fn is_some(&self) -> bool { - if let Self::None = self { false } else { true } - } - #[allow(unused)] pub(crate) fn is_none(&self) -> bool { - !self.is_some() - } - #[allow(unused)] pub(crate) fn take(mut self) -> crate::lightning::onion_message::offers::OffersMessage { - if let Self::Some(v) = self { v } else { unreachable!() } - } -} -#[no_mangle] -/// Constructs a new COption_OffersMessageZ containing a crate::lightning::onion_message::offers::OffersMessage -pub extern "C" fn COption_OffersMessageZ_some(o: crate::lightning::onion_message::offers::OffersMessage) -> COption_OffersMessageZ { - COption_OffersMessageZ::Some(o) -} -#[no_mangle] -/// Constructs a new COption_OffersMessageZ containing nothing -pub extern "C" fn COption_OffersMessageZ_none() -> COption_OffersMessageZ { - COption_OffersMessageZ::None -} -#[no_mangle] -/// Frees any resources associated with the crate::lightning::onion_message::offers::OffersMessage, if we are in the Some state -pub extern "C" fn COption_OffersMessageZ_free(_res: COption_OffersMessageZ) { } -#[no_mangle] -/// Creates a new COption_OffersMessageZ which has the same data as `orig` -/// but with all dynamically-allocated buffers duplicated in new buffers. -pub extern "C" fn COption_OffersMessageZ_clone(orig: &COption_OffersMessageZ) -> COption_OffersMessageZ { Clone::clone(&orig) } -#[repr(C)] -#[derive(Clone)] -/// An enum which can either contain a crate::lightning::onion_message::packet::CustomOnionMessageContents or not -pub enum COption_CustomOnionMessageContentsZ { - /// When we're in this state, this COption_CustomOnionMessageContentsZ contains a crate::lightning::onion_message::packet::CustomOnionMessageContents - Some(crate::lightning::onion_message::packet::CustomOnionMessageContents), - /// When we're in this state, this COption_CustomOnionMessageContentsZ contains nothing +/// An enum which can either contain a crate::lightning::onion_message::packet::OnionMessageContents or not +pub enum COption_OnionMessageContentsZ { + /// When we're in this state, this COption_OnionMessageContentsZ contains a crate::lightning::onion_message::packet::OnionMessageContents + Some(crate::lightning::onion_message::packet::OnionMessageContents), + /// When we're in this state, this COption_OnionMessageContentsZ contains nothing None } -impl COption_CustomOnionMessageContentsZ { +impl COption_OnionMessageContentsZ { #[allow(unused)] pub(crate) fn is_some(&self) -> bool { if let Self::None = self { false } else { true } } #[allow(unused)] pub(crate) fn is_none(&self) -> bool { !self.is_some() } - #[allow(unused)] pub(crate) fn take(mut self) -> crate::lightning::onion_message::packet::CustomOnionMessageContents { + #[allow(unused)] pub(crate) fn take(mut self) -> crate::lightning::onion_message::packet::OnionMessageContents { if let Self::Some(v) = self { v } else { unreachable!() } } } #[no_mangle] -/// Constructs a new COption_CustomOnionMessageContentsZ containing a crate::lightning::onion_message::packet::CustomOnionMessageContents -pub extern "C" fn COption_CustomOnionMessageContentsZ_some(o: crate::lightning::onion_message::packet::CustomOnionMessageContents) -> COption_CustomOnionMessageContentsZ { - COption_CustomOnionMessageContentsZ::Some(o) +/// Constructs a new COption_OnionMessageContentsZ containing a crate::lightning::onion_message::packet::OnionMessageContents +pub extern "C" fn COption_OnionMessageContentsZ_some(o: crate::lightning::onion_message::packet::OnionMessageContents) -> COption_OnionMessageContentsZ { + COption_OnionMessageContentsZ::Some(o) } #[no_mangle] -/// Constructs a new COption_CustomOnionMessageContentsZ containing nothing -pub extern "C" fn COption_CustomOnionMessageContentsZ_none() -> COption_CustomOnionMessageContentsZ { - COption_CustomOnionMessageContentsZ::None +/// Constructs a new COption_OnionMessageContentsZ containing nothing +pub extern "C" fn COption_OnionMessageContentsZ_none() -> COption_OnionMessageContentsZ { + COption_OnionMessageContentsZ::None } #[no_mangle] -/// Frees any resources associated with the crate::lightning::onion_message::packet::CustomOnionMessageContents, if we are in the Some state -pub extern "C" fn COption_CustomOnionMessageContentsZ_free(_res: COption_CustomOnionMessageContentsZ) { } +/// Frees any resources associated with the crate::lightning::onion_message::packet::OnionMessageContents, if we are in the Some state +pub extern "C" fn COption_OnionMessageContentsZ_free(_res: COption_OnionMessageContentsZ) { } #[no_mangle] -/// Creates a new COption_CustomOnionMessageContentsZ which has the same data as `orig` +/// Creates a new COption_OnionMessageContentsZ which has the same data as `orig` /// but with all dynamically-allocated buffers duplicated in new buffers. -pub extern "C" fn COption_CustomOnionMessageContentsZ_clone(orig: &COption_CustomOnionMessageContentsZ) -> COption_CustomOnionMessageContentsZ { Clone::clone(&orig) } +pub extern "C" fn COption_OnionMessageContentsZ_clone(orig: &COption_OnionMessageContentsZ) -> COption_OnionMessageContentsZ { Clone::clone(&orig) } #[repr(C)] -/// The contents of CResult_COption_CustomOnionMessageContentsZDecodeErrorZ -pub union CResult_COption_CustomOnionMessageContentsZDecodeErrorZPtr { +/// The contents of CResult_COption_OnionMessageContentsZDecodeErrorZ +pub union CResult_COption_OnionMessageContentsZDecodeErrorZPtr { /// A pointer to the contents in the success state. /// Reading from this pointer when `result_ok` is not set is undefined. - pub result: *mut crate::c_types::derived::COption_CustomOnionMessageContentsZ, + pub result: *mut crate::c_types::derived::COption_OnionMessageContentsZ, /// A pointer to the contents in the error state. /// Reading from this pointer when `result_ok` is set is undefined. pub err: *mut crate::lightning::ln::msgs::DecodeError, } #[repr(C)] -/// A CResult_COption_CustomOnionMessageContentsZDecodeErrorZ represents the result of a fallible operation, -/// containing a crate::c_types::derived::COption_CustomOnionMessageContentsZ on success and a crate::lightning::ln::msgs::DecodeError on failure. +/// A CResult_COption_OnionMessageContentsZDecodeErrorZ represents the result of a fallible operation, +/// containing a crate::c_types::derived::COption_OnionMessageContentsZ on success and a crate::lightning::ln::msgs::DecodeError on failure. /// `result_ok` indicates the overall state, and the contents are provided via `contents`. -pub struct CResult_COption_CustomOnionMessageContentsZDecodeErrorZ { - /// The contents of this CResult_COption_CustomOnionMessageContentsZDecodeErrorZ, accessible via either +pub struct CResult_COption_OnionMessageContentsZDecodeErrorZ { + /// The contents of this CResult_COption_OnionMessageContentsZDecodeErrorZ, accessible via either /// `err` or `result` depending on the state of `result_ok`. - pub contents: CResult_COption_CustomOnionMessageContentsZDecodeErrorZPtr, - /// Whether this CResult_COption_CustomOnionMessageContentsZDecodeErrorZ represents a success state. + pub contents: CResult_COption_OnionMessageContentsZDecodeErrorZPtr, + /// Whether this CResult_COption_OnionMessageContentsZDecodeErrorZ represents a success state. pub result_ok: bool, } #[no_mangle] -/// Creates a new CResult_COption_CustomOnionMessageContentsZDecodeErrorZ in the success state. -pub extern "C" fn CResult_COption_CustomOnionMessageContentsZDecodeErrorZ_ok(o: crate::c_types::derived::COption_CustomOnionMessageContentsZ) -> CResult_COption_CustomOnionMessageContentsZDecodeErrorZ { - CResult_COption_CustomOnionMessageContentsZDecodeErrorZ { - contents: CResult_COption_CustomOnionMessageContentsZDecodeErrorZPtr { +/// Creates a new CResult_COption_OnionMessageContentsZDecodeErrorZ in the success state. +pub extern "C" fn CResult_COption_OnionMessageContentsZDecodeErrorZ_ok(o: crate::c_types::derived::COption_OnionMessageContentsZ) -> CResult_COption_OnionMessageContentsZDecodeErrorZ { + CResult_COption_OnionMessageContentsZDecodeErrorZ { + contents: CResult_COption_OnionMessageContentsZDecodeErrorZPtr { result: Box::into_raw(Box::new(o)), }, result_ok: true, } } #[no_mangle] -/// Creates a new CResult_COption_CustomOnionMessageContentsZDecodeErrorZ in the error state. -pub extern "C" fn CResult_COption_CustomOnionMessageContentsZDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_COption_CustomOnionMessageContentsZDecodeErrorZ { - CResult_COption_CustomOnionMessageContentsZDecodeErrorZ { - contents: CResult_COption_CustomOnionMessageContentsZDecodeErrorZPtr { +/// Creates a new CResult_COption_OnionMessageContentsZDecodeErrorZ in the error state. +pub extern "C" fn CResult_COption_OnionMessageContentsZDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_COption_OnionMessageContentsZDecodeErrorZ { + CResult_COption_OnionMessageContentsZDecodeErrorZ { + contents: CResult_COption_OnionMessageContentsZDecodeErrorZPtr { err: Box::into_raw(Box::new(e)), }, result_ok: false, @@ -11423,13 +11644,13 @@ pub extern "C" fn CResult_COption_CustomOnionMessageContentsZDecodeErrorZ_err(e: } /// Checks if the given object is currently in the success state #[no_mangle] -pub extern "C" fn CResult_COption_CustomOnionMessageContentsZDecodeErrorZ_is_ok(o: &CResult_COption_CustomOnionMessageContentsZDecodeErrorZ) -> bool { +pub extern "C" fn CResult_COption_OnionMessageContentsZDecodeErrorZ_is_ok(o: &CResult_COption_OnionMessageContentsZDecodeErrorZ) -> bool { o.result_ok } #[no_mangle] -/// Frees any resources used by the CResult_COption_CustomOnionMessageContentsZDecodeErrorZ. -pub extern "C" fn CResult_COption_CustomOnionMessageContentsZDecodeErrorZ_free(_res: CResult_COption_CustomOnionMessageContentsZDecodeErrorZ) { } -impl Drop for CResult_COption_CustomOnionMessageContentsZDecodeErrorZ { +/// Frees any resources used by the CResult_COption_OnionMessageContentsZDecodeErrorZ. +pub extern "C" fn CResult_COption_OnionMessageContentsZDecodeErrorZ_free(_res: CResult_COption_OnionMessageContentsZDecodeErrorZ) { } +impl Drop for CResult_COption_OnionMessageContentsZDecodeErrorZ { fn drop(&mut self) { if self.result_ok { if unsafe { !(self.contents.result as *mut ()).is_null() } { @@ -11442,16 +11663,16 @@ impl Drop for CResult_COption_CustomOnionMessageContentsZDecodeErrorZ { } } } -impl From> for CResult_COption_CustomOnionMessageContentsZDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { +impl From> for CResult_COption_OnionMessageContentsZDecodeErrorZ { + fn from(mut o: crate::c_types::CResultTempl) -> Self { let contents = if o.result_ok { let result = unsafe { o.contents.result }; unsafe { o.contents.result = core::ptr::null_mut() }; - CResult_COption_CustomOnionMessageContentsZDecodeErrorZPtr { result } + CResult_COption_OnionMessageContentsZDecodeErrorZPtr { result } } else { let err = unsafe { o.contents.err }; unsafe { o.contents.err = core::ptr::null_mut(); } - CResult_COption_CustomOnionMessageContentsZDecodeErrorZPtr { err } + CResult_COption_OnionMessageContentsZDecodeErrorZPtr { err } }; Self { contents, @@ -11459,23 +11680,115 @@ impl From Self { if self.result_ok { - Self { result_ok: true, contents: CResult_COption_CustomOnionMessageContentsZDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) + Self { result_ok: true, contents: CResult_COption_OnionMessageContentsZDecodeErrorZPtr { + result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) } } } else { - Self { result_ok: false, contents: CResult_COption_CustomOnionMessageContentsZDecodeErrorZPtr { + Self { result_ok: false, contents: CResult_COption_OnionMessageContentsZDecodeErrorZPtr { err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) } } } } } #[no_mangle] -/// Creates a new CResult_COption_CustomOnionMessageContentsZDecodeErrorZ which has the same data as `orig` +/// Creates a new CResult_COption_OnionMessageContentsZDecodeErrorZ which has the same data as `orig` +/// but with all dynamically-allocated buffers duplicated in new buffers. +pub extern "C" fn CResult_COption_OnionMessageContentsZDecodeErrorZ_clone(orig: &CResult_COption_OnionMessageContentsZDecodeErrorZ) -> CResult_COption_OnionMessageContentsZDecodeErrorZ { Clone::clone(&orig) } +#[repr(C)] +/// A tuple of 3 elements. See the individual fields for the types contained. +pub struct C3Tuple_OnionMessageContentsDestinationBlindedPathZ { + /// The element at position 0 + pub a: crate::lightning::onion_message::packet::OnionMessageContents, + /// The element at position 1 + pub b: crate::lightning::onion_message::messenger::Destination, + /// The element at position 2 + pub c: crate::lightning::blinded_path::BlindedPath, +} +impl From<(crate::lightning::onion_message::packet::OnionMessageContents, crate::lightning::onion_message::messenger::Destination, crate::lightning::blinded_path::BlindedPath)> for C3Tuple_OnionMessageContentsDestinationBlindedPathZ { + fn from (tup: (crate::lightning::onion_message::packet::OnionMessageContents, crate::lightning::onion_message::messenger::Destination, crate::lightning::blinded_path::BlindedPath)) -> Self { + Self { + a: tup.0, + b: tup.1, + c: tup.2, + } + } +} +impl C3Tuple_OnionMessageContentsDestinationBlindedPathZ { + #[allow(unused)] pub(crate) fn to_rust(mut self) -> (crate::lightning::onion_message::packet::OnionMessageContents, crate::lightning::onion_message::messenger::Destination, crate::lightning::blinded_path::BlindedPath) { + (self.a, self.b, self.c) + } +} +impl Clone for C3Tuple_OnionMessageContentsDestinationBlindedPathZ { + fn clone(&self) -> Self { + Self { + a: Clone::clone(&self.a), + b: Clone::clone(&self.b), + c: Clone::clone(&self.c), + } + } +} +#[no_mangle] +/// Creates a new tuple which has the same data as `orig` /// but with all dynamically-allocated buffers duplicated in new buffers. -pub extern "C" fn CResult_COption_CustomOnionMessageContentsZDecodeErrorZ_clone(orig: &CResult_COption_CustomOnionMessageContentsZDecodeErrorZ) -> CResult_COption_CustomOnionMessageContentsZDecodeErrorZ { Clone::clone(&orig) } +pub extern "C" fn C3Tuple_OnionMessageContentsDestinationBlindedPathZ_clone(orig: &C3Tuple_OnionMessageContentsDestinationBlindedPathZ) -> C3Tuple_OnionMessageContentsDestinationBlindedPathZ { Clone::clone(&orig) } +/// Creates a new C3Tuple_OnionMessageContentsDestinationBlindedPathZ from the contained elements. +#[no_mangle] +pub extern "C" fn C3Tuple_OnionMessageContentsDestinationBlindedPathZ_new(a: crate::lightning::onion_message::packet::OnionMessageContents, b: crate::lightning::onion_message::messenger::Destination, c: crate::lightning::blinded_path::BlindedPath) -> C3Tuple_OnionMessageContentsDestinationBlindedPathZ { + C3Tuple_OnionMessageContentsDestinationBlindedPathZ { a, b, c, } +} + +#[no_mangle] +/// Frees any resources used by the C3Tuple_OnionMessageContentsDestinationBlindedPathZ. +pub extern "C" fn C3Tuple_OnionMessageContentsDestinationBlindedPathZ_free(_res: C3Tuple_OnionMessageContentsDestinationBlindedPathZ) { } +#[repr(C)] +/// A dynamically-allocated array of crate::c_types::derived::C3Tuple_OnionMessageContentsDestinationBlindedPathZs of arbitrary size. +/// This corresponds to std::vector in C++ +pub struct CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ { + /// The elements in the array. + /// If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc(). + pub data: *mut crate::c_types::derived::C3Tuple_OnionMessageContentsDestinationBlindedPathZ, + /// The number of elements pointed to by `data`. + pub datalen: usize +} +impl CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ { + #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { + if self.datalen == 0 { return Vec::new(); } + let ret = unsafe { Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }.into(); + self.data = core::ptr::null_mut(); + self.datalen = 0; + ret + } + #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::c_types::derived::C3Tuple_OnionMessageContentsDestinationBlindedPathZ] { + unsafe { core::slice::from_raw_parts_mut(self.data, self.datalen) } + } +} +impl From> for CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ { + fn from(v: Vec) -> Self { + let datalen = v.len(); + let data = Box::into_raw(v.into_boxed_slice()); + Self { datalen, data: unsafe { (*data).as_mut_ptr() } } + } +} +#[no_mangle] +/// Frees the buffer pointed to by `data` if `datalen` is non-0. +pub extern "C" fn CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ_free(_res: CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ) { } +impl Drop for CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ { + fn drop(&mut self) { + if self.datalen == 0 { return; } + let _ = unsafe { Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }; + } +} +impl Clone for CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ { + fn clone(&self) -> Self { + let mut res = Vec::new(); + if self.datalen == 0 { return Self::from(res); } + res.extend_from_slice(unsafe { core::slice::from_raw_parts_mut(self.data, self.datalen) }); + Self::from(res) + } +} #[repr(C)] #[derive(Clone)] /// An enum which can either contain a crate::lightning::ln::wire::Type or not @@ -22603,6 +22916,81 @@ impl From CResult_PeeledOnionNoneZ { + CResult_PeeledOnionNoneZ { + contents: CResult_PeeledOnionNoneZPtr { + result: Box::into_raw(Box::new(o)), + }, + result_ok: true, + } +} +#[no_mangle] +/// Creates a new CResult_PeeledOnionNoneZ in the error state. +pub extern "C" fn CResult_PeeledOnionNoneZ_err() -> CResult_PeeledOnionNoneZ { + CResult_PeeledOnionNoneZ { + contents: CResult_PeeledOnionNoneZPtr { + err: core::ptr::null_mut(), + }, + result_ok: false, + } +} +/// Checks if the given object is currently in the success state +#[no_mangle] +pub extern "C" fn CResult_PeeledOnionNoneZ_is_ok(o: &CResult_PeeledOnionNoneZ) -> bool { + o.result_ok +} +#[no_mangle] +/// Frees any resources used by the CResult_PeeledOnionNoneZ. +pub extern "C" fn CResult_PeeledOnionNoneZ_free(_res: CResult_PeeledOnionNoneZ) { } +impl Drop for CResult_PeeledOnionNoneZ { + fn drop(&mut self) { + if self.result_ok { + if unsafe { !(self.contents.result as *mut ()).is_null() } { + let _ = unsafe { Box::from_raw(self.contents.result) }; + } + } else { + } + } +} +impl From> for CResult_PeeledOnionNoneZ { + fn from(mut o: crate::c_types::CResultTempl) -> Self { + let contents = if o.result_ok { + let result = unsafe { o.contents.result }; + unsafe { o.contents.result = core::ptr::null_mut() }; + CResult_PeeledOnionNoneZPtr { result } + } else { + let _ = unsafe { Box::from_raw(o.contents.err) }; + o.contents.err = core::ptr::null_mut(); + CResult_PeeledOnionNoneZPtr { err: core::ptr::null_mut() } + }; + Self { + contents, + result_ok: o.result_ok, + } + } +} +#[repr(C)] /// The contents of CResult_NoneSendErrorZ pub union CResult_NoneSendErrorZPtr { /// Note that this value is always NULL, as there are no contents in the OK variant diff --git a/lightning-c-bindings/src/lightning/blinded_path/mod.rs b/lightning-c-bindings/src/lightning/blinded_path/mod.rs index 949321c..01351bf 100644 --- a/lightning-c-bindings/src/lightning/blinded_path/mod.rs +++ b/lightning-c-bindings/src/lightning/blinded_path/mod.rs @@ -166,7 +166,7 @@ impl Clone for BlindedPath { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn BlindedPath_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBlindedPath)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBlindedPath)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the BlindedPath @@ -293,7 +293,7 @@ impl Clone for BlindedHop { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn BlindedHop_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBlindedHop)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBlindedHop)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the BlindedHop @@ -319,10 +319,19 @@ pub extern "C" fn BlindedHop_eq(a: &BlindedHop, b: &BlindedHop) -> bool { if a.inner.is_null() || b.inner.is_null() { return false; } if a.get_native_ref() == b.get_native_ref() { true } else { false } } +/// Create a one-hop blinded path for a message. +#[must_use] +#[no_mangle] +pub extern "C" fn BlindedPath_one_hop_for_message(mut recipient_node_id: crate::c_types::PublicKey, entropy_source: &crate::lightning::sign::EntropySource) -> crate::c_types::derived::CResult_BlindedPathNoneZ { + let mut ret = lightning::blinded_path::BlindedPath::one_hop_for_message(recipient_node_id.into_rust(), entropy_source, secp256k1::global::SECP256K1); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() }; + local_ret +} + /// Create a blinded path for an onion message, to be forwarded along `node_pks`. The last node /// pubkey in `node_pks` will be the destination node. /// -/// Errors if less than two hops are provided or if `node_pk`(s) are invalid. +/// Errors if no hops are provided or if `node_pk`(s) are invalid. #[must_use] #[no_mangle] pub extern "C" fn BlindedPath_new_for_message(mut node_pks: crate::c_types::derived::CVec_PublicKeyZ, entropy_source: &crate::lightning::sign::EntropySource) -> crate::c_types::derived::CResult_BlindedPathNoneZ { @@ -346,7 +355,7 @@ pub extern "C" fn BlindedPath_one_hop_for_payment(mut payee_node_id: crate::c_ty pub extern "C" fn BlindedPath_write(obj: &crate::lightning::blinded_path::BlindedPath) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn BlindedPath_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBlindedPath) }) } @@ -362,7 +371,7 @@ pub extern "C" fn BlindedPath_read(ser: crate::c_types::u8slice) -> crate::c_typ pub extern "C" fn BlindedHop_write(obj: &crate::lightning::blinded_path::BlindedHop) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn BlindedHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBlindedHop) }) } diff --git a/lightning-c-bindings/src/lightning/blinded_path/payment.rs b/lightning-c-bindings/src/lightning/blinded_path/payment.rs index 8776618..e0b9d78 100644 --- a/lightning-c-bindings/src/lightning/blinded_path/payment.rs +++ b/lightning-c-bindings/src/lightning/blinded_path/payment.rs @@ -127,7 +127,7 @@ impl Clone for ForwardNode { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ForwardNode_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeForwardNode)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeForwardNode)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ForwardNode @@ -258,7 +258,7 @@ impl Clone for ForwardTlvs { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ForwardTlvs_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeForwardTlvs)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeForwardTlvs)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ForwardTlvs @@ -360,7 +360,7 @@ impl Clone for ReceiveTlvs { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ReceiveTlvs_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeReceiveTlvs)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeReceiveTlvs)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ReceiveTlvs @@ -477,7 +477,7 @@ impl Clone for PaymentRelay { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn PaymentRelay_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePaymentRelay)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePaymentRelay)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the PaymentRelay @@ -537,15 +537,13 @@ impl PaymentConstraints { ret } } -/// The maximum total CLTV delta that is acceptable when relaying a payment over this -/// [`BlindedHop`]. +/// The maximum total CLTV that is acceptable when relaying a payment over this [`BlindedHop`]. #[no_mangle] pub extern "C" fn PaymentConstraints_get_max_cltv_expiry(this_ptr: &PaymentConstraints) -> u32 { let mut inner_val = &mut this_ptr.get_native_mut_ref().max_cltv_expiry; *inner_val } -/// The maximum total CLTV delta that is acceptable when relaying a payment over this -/// [`BlindedHop`]. +/// The maximum total CLTV that is acceptable when relaying a payment over this [`BlindedHop`]. #[no_mangle] pub extern "C" fn PaymentConstraints_set_max_cltv_expiry(this_ptr: &mut PaymentConstraints, mut val: u32) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_cltv_expiry = val; @@ -584,7 +582,7 @@ impl Clone for PaymentConstraints { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn PaymentConstraints_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePaymentConstraints)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePaymentConstraints)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the PaymentConstraints @@ -596,7 +594,7 @@ pub extern "C" fn PaymentConstraints_clone(orig: &PaymentConstraints) -> Payment pub extern "C" fn ForwardTlvs_write(obj: &crate::lightning::blinded_path::payment::ForwardTlvs) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ForwardTlvs_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeForwardTlvs) }) } @@ -605,7 +603,7 @@ pub(crate) extern "C" fn ForwardTlvs_write_void(obj: *const c_void) -> crate::c_ pub extern "C" fn ReceiveTlvs_write(obj: &crate::lightning::blinded_path::payment::ReceiveTlvs) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ReceiveTlvs_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeReceiveTlvs) }) } @@ -621,7 +619,7 @@ pub extern "C" fn ReceiveTlvs_read(ser: crate::c_types::u8slice) -> crate::c_typ pub extern "C" fn PaymentRelay_write(obj: &crate::lightning::blinded_path::payment::PaymentRelay) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn PaymentRelay_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePaymentRelay) }) } @@ -637,7 +635,7 @@ pub extern "C" fn PaymentRelay_read(ser: crate::c_types::u8slice) -> crate::c_ty pub extern "C" fn PaymentConstraints_write(obj: &crate::lightning::blinded_path::payment::PaymentConstraints) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn PaymentConstraints_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePaymentConstraints) }) } diff --git a/lightning-c-bindings/src/lightning/chain/chaininterface.rs b/lightning-c-bindings/src/lightning/chain/chaininterface.rs index 0dc8d6c..47caccb 100644 --- a/lightning-c-bindings/src/lightning/chain/chaininterface.rs +++ b/lightning-c-bindings/src/lightning/chain/chaininterface.rs @@ -47,6 +47,7 @@ pub struct BroadcasterInterface { } unsafe impl Send for BroadcasterInterface {} unsafe impl Sync for BroadcasterInterface {} +#[allow(unused)] pub(crate) fn BroadcasterInterface_clone_fields(orig: &BroadcasterInterface) -> BroadcasterInterface { BroadcasterInterface { this_arg: orig.this_arg, @@ -92,21 +93,98 @@ impl Drop for BroadcasterInterface { #[must_use] #[repr(C)] pub enum ConfirmationTarget { - /// We'd like a transaction to confirm in the future, but don't want to commit most of the fees - /// required to do so yet. The remaining fees will come via a Child-Pays-For-Parent (CPFP) fee - /// bump of the transaction. + /// We have some funds available on chain which we need to spend prior to some expiry time at + /// which point our counterparty may be able to steal them. Generally we have in the high tens + /// to low hundreds of blocks to get our transaction on-chain, but we shouldn't risk too low a + /// fee - this should be a relatively high priority feerate. + OnChainSweep, + /// The highest feerate we will allow our channel counterparty to have in a non-anchor channel. /// - /// The feerate returned should be the absolute minimum feerate required to enter most node - /// mempools across the network. Note that if you are not able to obtain this feerate estimate, - /// you should likely use the furthest-out estimate allowed by your fee estimator. - MempoolMinimum, - /// We are happy with a transaction confirming slowly, at least within a day or so worth of - /// blocks. - Background, - /// We'd like a transaction to confirm without major delayed, i.e., within the next 12-24 blocks. - Normal, - /// We'd like a transaction to confirm in the next few blocks. - HighPriority, + /// This is the feerate on the transaction which we (or our counterparty) will broadcast in + /// order to close the channel unilaterally. Because our counterparty must ensure they can + /// always broadcast the latest state, this value being too low will cause immediate + /// force-closures. + /// + /// Allowing this value to be too high can allow our counterparty to burn our HTLC outputs to + /// dust, which can result in HTLCs failing or force-closures (when the dust HTLCs exceed + /// [`ChannelConfig::max_dust_htlc_exposure`]). + /// + /// Because most nodes use a feerate estimate which is based on a relatively high priority + /// transaction entering the current mempool, setting this to a small multiple of your current + /// high priority feerate estimate should suffice. + /// + /// [`ChannelConfig::max_dust_htlc_exposure`]: crate::util::config::ChannelConfig::max_dust_htlc_exposure + MaxAllowedNonAnchorChannelRemoteFee, + /// This is the lowest feerate we will allow our channel counterparty to have in an anchor + /// channel in order to close the channel if a channel party goes away. + /// + /// This needs to be sufficient to get into the mempool when the channel needs to + /// be force-closed. Setting too high may result in force-closures if our counterparty attempts + /// to use a lower feerate. Because this is for anchor channels, we can always bump the feerate + /// later; the feerate here only needs to be sufficient to enter the mempool. + /// + /// A good estimate is the expected mempool minimum at the time of force-closure. Obviously this + /// is not an estimate which is very easy to calculate because we do not know the future. Using + /// a simple long-term fee estimate or tracking of the mempool minimum is a good approach to + /// ensure you can always close the channel. A future change to Bitcoin's P2P network + /// (package relay) may obviate the need for this entirely. + MinAllowedAnchorChannelRemoteFee, + /// The lowest feerate we will allow our channel counterparty to have in a non-anchor channel. + /// + /// This is the feerate on the transaction which we (or our counterparty) will broadcast in + /// order to close the channel if a channel party goes away. Setting this value too high will + /// cause immediate force-closures in order to avoid having an unbroadcastable state. + /// + /// This feerate represents the fee we pick now, which must be sufficient to enter a block at an + /// arbitrary time in the future. Obviously this is not an estimate which is very easy to + /// calculate. This can leave channels subject to being unable to close if feerates rise, and in + /// general you should prefer anchor channels to ensure you can increase the feerate when the + /// transactions need broadcasting. + /// + /// Do note some fee estimators round up to the next full sat/vbyte (ie 250 sats per kw), + /// causing occasional issues with feerate disagreements between an initiator that wants a + /// feerate of 1.1 sat/vbyte and a receiver that wants 1.1 rounded up to 2. If your fee + /// estimator rounds subtracting 250 to your desired feerate here can help avoid this issue. + /// + /// [`ChannelConfig::max_dust_htlc_exposure`]: crate::util::config::ChannelConfig::max_dust_htlc_exposure + MinAllowedNonAnchorChannelRemoteFee, + /// This is the feerate on the transaction which we (or our counterparty) will broadcast in + /// order to close the channel if a channel party goes away. + /// + /// This needs to be sufficient to get into the mempool when the channel needs to + /// be force-closed. Setting too low may result in force-closures. Because this is for anchor + /// channels, it can be a low value as we can always bump the feerate later. + /// + /// A good estimate is the expected mempool minimum at the time of force-closure. Obviously this + /// is not an estimate which is very easy to calculate because we do not know the future. Using + /// a simple long-term fee estimate or tracking of the mempool minimum is a good approach to + /// ensure you can always close the channel. A future change to Bitcoin's P2P network + /// (package relay) may obviate the need for this entirely. + AnchorChannelFee, + /// Lightning is built around the ability to broadcast a transaction in the future to close our + /// channel and claim all pending funds. In order to do so, non-anchor channels are built with + /// transactions which we need to be able to broadcast at some point in the future. + /// + /// This feerate represents the fee we pick now, which must be sufficient to enter a block at an + /// arbitrary time in the future. Obviously this is not an estimate which is very easy to + /// calculate, so most lightning nodes use some relatively high-priority feerate using the + /// current mempool. This leaves channels subject to being unable to close if feerates rise, and + /// in general you should prefer anchor channels to ensure you can increase the feerate when the + /// transactions need broadcasting. + /// + /// Since this should represent the feerate of a channel close that does not need fee + /// bumping, this is also used as an upper bound for our attempted feerate when doing cooperative + /// closure of any channel. + NonAnchorChannelFee, + /// When cooperatively closing a channel, this is the minimum feerate we will accept. + /// Recommended at least within a day or so worth of blocks. + /// + /// This will also be used when initiating a cooperative close of a channel. When closing a + /// channel you can override this fee by using + /// [`ChannelManager::close_channel_with_feerate_and_script`]. + /// + /// [`ChannelManager::close_channel_with_feerate_and_script`]: crate::ln::channelmanager::ChannelManager::close_channel_with_feerate_and_script + ChannelCloseMinimum, } use lightning::chain::chaininterface::ConfirmationTarget as ConfirmationTargetImport; pub(crate) type nativeConfirmationTarget = ConfirmationTargetImport; @@ -115,37 +193,49 @@ impl ConfirmationTarget { #[allow(unused)] pub(crate) fn to_native(&self) -> nativeConfirmationTarget { match self { - ConfirmationTarget::MempoolMinimum => nativeConfirmationTarget::MempoolMinimum, - ConfirmationTarget::Background => nativeConfirmationTarget::Background, - ConfirmationTarget::Normal => nativeConfirmationTarget::Normal, - ConfirmationTarget::HighPriority => nativeConfirmationTarget::HighPriority, + ConfirmationTarget::OnChainSweep => nativeConfirmationTarget::OnChainSweep, + ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee => nativeConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee, + ConfirmationTarget::MinAllowedAnchorChannelRemoteFee => nativeConfirmationTarget::MinAllowedAnchorChannelRemoteFee, + ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee => nativeConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee, + ConfirmationTarget::AnchorChannelFee => nativeConfirmationTarget::AnchorChannelFee, + ConfirmationTarget::NonAnchorChannelFee => nativeConfirmationTarget::NonAnchorChannelFee, + ConfirmationTarget::ChannelCloseMinimum => nativeConfirmationTarget::ChannelCloseMinimum, } } #[allow(unused)] pub(crate) fn into_native(self) -> nativeConfirmationTarget { match self { - ConfirmationTarget::MempoolMinimum => nativeConfirmationTarget::MempoolMinimum, - ConfirmationTarget::Background => nativeConfirmationTarget::Background, - ConfirmationTarget::Normal => nativeConfirmationTarget::Normal, - ConfirmationTarget::HighPriority => nativeConfirmationTarget::HighPriority, + ConfirmationTarget::OnChainSweep => nativeConfirmationTarget::OnChainSweep, + ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee => nativeConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee, + ConfirmationTarget::MinAllowedAnchorChannelRemoteFee => nativeConfirmationTarget::MinAllowedAnchorChannelRemoteFee, + ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee => nativeConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee, + ConfirmationTarget::AnchorChannelFee => nativeConfirmationTarget::AnchorChannelFee, + ConfirmationTarget::NonAnchorChannelFee => nativeConfirmationTarget::NonAnchorChannelFee, + ConfirmationTarget::ChannelCloseMinimum => nativeConfirmationTarget::ChannelCloseMinimum, } } #[allow(unused)] pub(crate) fn from_native(native: &nativeConfirmationTarget) -> Self { match native { - nativeConfirmationTarget::MempoolMinimum => ConfirmationTarget::MempoolMinimum, - nativeConfirmationTarget::Background => ConfirmationTarget::Background, - nativeConfirmationTarget::Normal => ConfirmationTarget::Normal, - nativeConfirmationTarget::HighPriority => ConfirmationTarget::HighPriority, + nativeConfirmationTarget::OnChainSweep => ConfirmationTarget::OnChainSweep, + nativeConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee => ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee, + nativeConfirmationTarget::MinAllowedAnchorChannelRemoteFee => ConfirmationTarget::MinAllowedAnchorChannelRemoteFee, + nativeConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee => ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee, + nativeConfirmationTarget::AnchorChannelFee => ConfirmationTarget::AnchorChannelFee, + nativeConfirmationTarget::NonAnchorChannelFee => ConfirmationTarget::NonAnchorChannelFee, + nativeConfirmationTarget::ChannelCloseMinimum => ConfirmationTarget::ChannelCloseMinimum, } } #[allow(unused)] pub(crate) fn native_into(native: nativeConfirmationTarget) -> Self { match native { - nativeConfirmationTarget::MempoolMinimum => ConfirmationTarget::MempoolMinimum, - nativeConfirmationTarget::Background => ConfirmationTarget::Background, - nativeConfirmationTarget::Normal => ConfirmationTarget::Normal, - nativeConfirmationTarget::HighPriority => ConfirmationTarget::HighPriority, + nativeConfirmationTarget::OnChainSweep => ConfirmationTarget::OnChainSweep, + nativeConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee => ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee, + nativeConfirmationTarget::MinAllowedAnchorChannelRemoteFee => ConfirmationTarget::MinAllowedAnchorChannelRemoteFee, + nativeConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee => ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee, + nativeConfirmationTarget::AnchorChannelFee => ConfirmationTarget::AnchorChannelFee, + nativeConfirmationTarget::NonAnchorChannelFee => ConfirmationTarget::NonAnchorChannelFee, + nativeConfirmationTarget::ChannelCloseMinimum => ConfirmationTarget::ChannelCloseMinimum, } } } @@ -154,22 +244,44 @@ impl ConfirmationTarget { pub extern "C" fn ConfirmationTarget_clone(orig: &ConfirmationTarget) -> ConfirmationTarget { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ConfirmationTarget_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const ConfirmationTarget)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ConfirmationTarget_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut ConfirmationTarget) }; +} +#[no_mangle] +/// Utility method to constructs a new OnChainSweep-variant ConfirmationTarget +pub extern "C" fn ConfirmationTarget_on_chain_sweep() -> ConfirmationTarget { + ConfirmationTarget::OnChainSweep} +#[no_mangle] +/// Utility method to constructs a new MaxAllowedNonAnchorChannelRemoteFee-variant ConfirmationTarget +pub extern "C" fn ConfirmationTarget_max_allowed_non_anchor_channel_remote_fee() -> ConfirmationTarget { + ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee} +#[no_mangle] +/// Utility method to constructs a new MinAllowedAnchorChannelRemoteFee-variant ConfirmationTarget +pub extern "C" fn ConfirmationTarget_min_allowed_anchor_channel_remote_fee() -> ConfirmationTarget { + ConfirmationTarget::MinAllowedAnchorChannelRemoteFee} #[no_mangle] -/// Utility method to constructs a new MempoolMinimum-variant ConfirmationTarget -pub extern "C" fn ConfirmationTarget_mempool_minimum() -> ConfirmationTarget { - ConfirmationTarget::MempoolMinimum} +/// Utility method to constructs a new MinAllowedNonAnchorChannelRemoteFee-variant ConfirmationTarget +pub extern "C" fn ConfirmationTarget_min_allowed_non_anchor_channel_remote_fee() -> ConfirmationTarget { + ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee} #[no_mangle] -/// Utility method to constructs a new Background-variant ConfirmationTarget -pub extern "C" fn ConfirmationTarget_background() -> ConfirmationTarget { - ConfirmationTarget::Background} +/// Utility method to constructs a new AnchorChannelFee-variant ConfirmationTarget +pub extern "C" fn ConfirmationTarget_anchor_channel_fee() -> ConfirmationTarget { + ConfirmationTarget::AnchorChannelFee} #[no_mangle] -/// Utility method to constructs a new Normal-variant ConfirmationTarget -pub extern "C" fn ConfirmationTarget_normal() -> ConfirmationTarget { - ConfirmationTarget::Normal} +/// Utility method to constructs a new NonAnchorChannelFee-variant ConfirmationTarget +pub extern "C" fn ConfirmationTarget_non_anchor_channel_fee() -> ConfirmationTarget { + ConfirmationTarget::NonAnchorChannelFee} #[no_mangle] -/// Utility method to constructs a new HighPriority-variant ConfirmationTarget -pub extern "C" fn ConfirmationTarget_high_priority() -> ConfirmationTarget { - ConfirmationTarget::HighPriority} +/// Utility method to constructs a new ChannelCloseMinimum-variant ConfirmationTarget +pub extern "C" fn ConfirmationTarget_channel_close_minimum() -> ConfirmationTarget { + ConfirmationTarget::ChannelCloseMinimum} /// Generates a non-cryptographic 64-bit hash of the ConfirmationTarget. #[no_mangle] pub extern "C" fn ConfirmationTarget_hash(o: &ConfirmationTarget) -> u64 { @@ -215,6 +327,7 @@ pub struct FeeEstimator { } unsafe impl Send for FeeEstimator {} unsafe impl Sync for FeeEstimator {} +#[allow(unused)] pub(crate) fn FeeEstimator_clone_fields(orig: &FeeEstimator) -> FeeEstimator { FeeEstimator { this_arg: orig.this_arg, diff --git a/lightning-c-bindings/src/lightning/chain/chainmonitor.rs b/lightning-c-bindings/src/lightning/chain/chainmonitor.rs index a70ceb0..059cf40 100644 --- a/lightning-c-bindings/src/lightning/chain/chainmonitor.rs +++ b/lightning-c-bindings/src/lightning/chain/chainmonitor.rs @@ -106,7 +106,7 @@ impl Clone for MonitorUpdateId { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn MonitorUpdateId_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMonitorUpdateId)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeMonitorUpdateId)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the MonitorUpdateId @@ -250,6 +250,7 @@ pub struct Persist { } unsafe impl Send for Persist {} unsafe impl Sync for Persist {} +#[allow(unused)] pub(crate) fn Persist_clone_fields(orig: &Persist) -> Persist { Persist { this_arg: orig.this_arg, @@ -530,10 +531,10 @@ pub extern "C" fn ChainMonitor_rebroadcast_pending_claims(this_arg: &crate::ligh impl From for crate::lightning::chain::Listen { fn from(obj: nativeChainMonitor) -> Self { - let mut rust_obj = ChainMonitor { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::chain::chainmonitor::ChainMonitor { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = ChainMonitor_as_Listen(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(ChainMonitor_free_void); ret } @@ -564,10 +565,10 @@ extern "C" fn ChainMonitor_Listen_block_disconnected(this_arg: *const c_void, he impl From for crate::lightning::chain::Confirm { fn from(obj: nativeChainMonitor) -> Self { - let mut rust_obj = ChainMonitor { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::chain::chainmonitor::ChainMonitor { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = ChainMonitor_as_Confirm(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(ChainMonitor_free_void); ret } @@ -605,10 +606,10 @@ extern "C" fn ChainMonitor_Confirm_get_relevant_txids(this_arg: *const c_void) - impl From for crate::lightning::chain::Watch { fn from(obj: nativeChainMonitor) -> Self { - let mut rust_obj = ChainMonitor { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::chain::chainmonitor::ChainMonitor { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = ChainMonitor_as_Watch(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(ChainMonitor_free_void); ret } @@ -646,10 +647,10 @@ extern "C" fn ChainMonitor_Watch_release_pending_monitor_events(this_arg: *const impl From for crate::lightning::events::EventsProvider { fn from(obj: nativeChainMonitor) -> Self { - let mut rust_obj = ChainMonitor { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::chain::chainmonitor::ChainMonitor { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = ChainMonitor_as_EventsProvider(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(ChainMonitor_free_void); ret } diff --git a/lightning-c-bindings/src/lightning/chain/channelmonitor.rs b/lightning-c-bindings/src/lightning/chain/channelmonitor.rs index c15e5bb..c37e29e 100644 --- a/lightning-c-bindings/src/lightning/chain/channelmonitor.rs +++ b/lightning-c-bindings/src/lightning/chain/channelmonitor.rs @@ -136,7 +136,7 @@ impl Clone for ChannelMonitorUpdate { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelMonitorUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelMonitorUpdate)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelMonitorUpdate)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelMonitorUpdate @@ -168,7 +168,7 @@ pub static CLOSED_CHANNEL_UPDATE_ID: u64 = lightning::chain::channelmonitor::CLO pub extern "C" fn ChannelMonitorUpdate_write(obj: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelMonitorUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitorUpdate) }) } @@ -310,6 +310,16 @@ pub extern "C" fn MonitorEvent_free(this_ptr: MonitorEvent) { } pub extern "C" fn MonitorEvent_clone(orig: &MonitorEvent) -> MonitorEvent { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn MonitorEvent_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const MonitorEvent)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn MonitorEvent_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut MonitorEvent) }; +} #[no_mangle] /// Utility method to constructs a new HTLCEvent-variant MonitorEvent pub extern "C" fn MonitorEvent_htlcevent(a: crate::lightning::chain::channelmonitor::HTLCUpdate) -> MonitorEvent { @@ -339,6 +349,10 @@ pub extern "C" fn MonitorEvent_eq(a: &MonitorEvent, b: &MonitorEvent) -> bool { pub extern "C" fn MonitorEvent_write(obj: &crate::lightning::chain::channelmonitor::MonitorEvent) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) } +#[allow(unused)] +pub(crate) extern "C" fn MonitorEvent_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + MonitorEvent_write(unsafe { &*(obj as *const MonitorEvent) }) +} #[no_mangle] /// Read a MonitorEvent from a byte array, created by MonitorEvent_write pub extern "C" fn MonitorEvent_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_MonitorEventZDecodeErrorZ { @@ -411,7 +425,7 @@ impl Clone for HTLCUpdate { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn HTLCUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCUpdate)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeHTLCUpdate)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the HTLCUpdate @@ -432,7 +446,7 @@ pub extern "C" fn HTLCUpdate_eq(a: &HTLCUpdate, b: &HTLCUpdate) -> bool { pub extern "C" fn HTLCUpdate_write(obj: &crate::lightning::chain::channelmonitor::HTLCUpdate) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn HTLCUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCUpdate) }) } @@ -750,6 +764,16 @@ pub extern "C" fn Balance_free(this_ptr: Balance) { } pub extern "C" fn Balance_clone(orig: &Balance) -> Balance { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Balance_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Balance)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Balance_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut Balance) }; +} #[no_mangle] /// Utility method to constructs a new ClaimableOnChannelClose-variant Balance pub extern "C" fn Balance_claimable_on_channel_close(amount_satoshis: u64) -> Balance { @@ -892,7 +916,7 @@ impl Clone for ChannelMonitor { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelMonitor_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelMonitor)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelMonitor)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelMonitor @@ -904,7 +928,7 @@ pub extern "C" fn ChannelMonitor_clone(orig: &ChannelMonitor) -> ChannelMonitor pub extern "C" fn ChannelMonitor_write(obj: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelMonitor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitor) }) } diff --git a/lightning-c-bindings/src/lightning/chain/mod.rs b/lightning-c-bindings/src/lightning/chain/mod.rs index 592c6fd..4551b08 100644 --- a/lightning-c-bindings/src/lightning/chain/mod.rs +++ b/lightning-c-bindings/src/lightning/chain/mod.rs @@ -108,7 +108,7 @@ impl Clone for BestBlock { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn BestBlock_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBestBlock)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBestBlock)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the BestBlock @@ -186,6 +186,7 @@ pub struct Listen { } unsafe impl Send for Listen {} unsafe impl Sync for Listen {} +#[allow(unused)] pub(crate) fn Listen_clone_fields(orig: &Listen) -> Listen { Listen { this_arg: orig.this_arg, @@ -334,6 +335,7 @@ pub struct Confirm { } unsafe impl Send for Confirm {} unsafe impl Sync for Confirm {} +#[allow(unused)] pub(crate) fn Confirm_clone_fields(orig: &Confirm) -> Confirm { Confirm { this_arg: orig.this_arg, @@ -500,6 +502,16 @@ impl ChannelMonitorUpdateStatus { pub extern "C" fn ChannelMonitorUpdateStatus_clone(orig: &ChannelMonitorUpdateStatus) -> ChannelMonitorUpdateStatus { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ChannelMonitorUpdateStatus_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const ChannelMonitorUpdateStatus)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ChannelMonitorUpdateStatus_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut ChannelMonitorUpdateStatus) }; +} #[no_mangle] /// Utility method to constructs a new Completed-variant ChannelMonitorUpdateStatus pub extern "C" fn ChannelMonitorUpdateStatus_completed() -> ChannelMonitorUpdateStatus { @@ -581,6 +593,7 @@ pub struct Watch { } unsafe impl Send for Watch {} unsafe impl Sync for Watch {} +#[allow(unused)] pub(crate) fn Watch_clone_fields(orig: &Watch) -> Watch { Watch { this_arg: orig.this_arg, @@ -673,6 +686,7 @@ pub struct Filter { } unsafe impl Send for Filter {} unsafe impl Sync for Filter {} +#[allow(unused)] pub(crate) fn Filter_clone_fields(orig: &Filter) -> Filter { Filter { this_arg: orig.this_arg, @@ -834,7 +848,7 @@ impl Clone for WatchedOutput { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn WatchedOutput_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeWatchedOutput)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeWatchedOutput)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the WatchedOutput diff --git a/lightning-c-bindings/src/lightning/chain/transaction.rs b/lightning-c-bindings/src/lightning/chain/transaction.rs index 81b8ee1..c51bf6c 100644 --- a/lightning-c-bindings/src/lightning/chain/transaction.rs +++ b/lightning-c-bindings/src/lightning/chain/transaction.rs @@ -114,7 +114,7 @@ impl Clone for OutPoint { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn OutPoint_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeOutPoint)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeOutPoint)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the OutPoint @@ -153,7 +153,7 @@ pub extern "C" fn OutPoint_to_channel_id(this_arg: &crate::lightning::chain::tra pub extern "C" fn OutPoint_write(obj: &crate::lightning::chain::transaction::OutPoint) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn OutPoint_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeOutPoint) }) } diff --git a/lightning-c-bindings/src/lightning/events/bump_transaction.rs b/lightning-c-bindings/src/lightning/events/bump_transaction.rs index 22a6f47..9f72981 100644 --- a/lightning-c-bindings/src/lightning/events/bump_transaction.rs +++ b/lightning-c-bindings/src/lightning/events/bump_transaction.rs @@ -20,150 +20,6 @@ use crate::c_types::*; use alloc::{vec::Vec, boxed::Box}; -use lightning::events::bump_transaction::ChannelDerivationParameters as nativeChannelDerivationParametersImport; -pub(crate) type nativeChannelDerivationParameters = nativeChannelDerivationParametersImport; - -/// The parameters required to derive a channel signer via [`SignerProvider`]. -#[must_use] -#[repr(C)] -pub struct ChannelDerivationParameters { - /// A pointer to the opaque Rust object. - - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeChannelDerivationParameters, - /// Indicates that this is the only struct which contains the same pointer. - - /// Rust functions which take ownership of an object provided via an argument require - /// this to be true and invalidate the object pointed to by inner. - pub is_owned: bool, -} - -impl Drop for ChannelDerivationParameters { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeChannelDerivationParameters>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; - } - } -} -/// Frees any resources used by the ChannelDerivationParameters, if is_owned is set and inner is non-NULL. -#[no_mangle] -pub extern "C" fn ChannelDerivationParameters_free(this_obj: ChannelDerivationParameters) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ChannelDerivationParameters_free_void(this_ptr: *mut c_void) { - let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelDerivationParameters) }; -} -#[allow(unused)] -impl ChannelDerivationParameters { - pub(crate) fn get_native_ref(&self) -> &'static nativeChannelDerivationParameters { - unsafe { &*ObjOps::untweak_ptr(self.inner) } - } - pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelDerivationParameters { - unsafe { &mut *ObjOps::untweak_ptr(self.inner) } - } - /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy - pub(crate) fn take_inner(mut self) -> *mut nativeChannelDerivationParameters { - assert!(self.is_owned); - let ret = ObjOps::untweak_ptr(self.inner); - self.inner = core::ptr::null_mut(); - ret - } -} -/// The value in satoshis of the channel we're attempting to spend the anchor output of. -#[no_mangle] -pub extern "C" fn ChannelDerivationParameters_get_value_satoshis(this_ptr: &ChannelDerivationParameters) -> u64 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().value_satoshis; - *inner_val -} -/// The value in satoshis of the channel we're attempting to spend the anchor output of. -#[no_mangle] -pub extern "C" fn ChannelDerivationParameters_set_value_satoshis(this_ptr: &mut ChannelDerivationParameters, mut val: u64) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.value_satoshis = val; -} -/// The unique identifier to re-derive the signer for the associated channel. -#[no_mangle] -pub extern "C" fn ChannelDerivationParameters_get_keys_id(this_ptr: &ChannelDerivationParameters) -> *const [u8; 32] { - let mut inner_val = &mut this_ptr.get_native_mut_ref().keys_id; - inner_val -} -/// The unique identifier to re-derive the signer for the associated channel. -#[no_mangle] -pub extern "C" fn ChannelDerivationParameters_set_keys_id(this_ptr: &mut ChannelDerivationParameters, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.keys_id = val.data; -} -/// The necessary channel parameters that need to be provided to the re-derived signer through -/// [`ChannelSigner::provide_channel_parameters`]. -/// -/// [`ChannelSigner::provide_channel_parameters`]: crate::sign::ChannelSigner::provide_channel_parameters -#[no_mangle] -pub extern "C" fn ChannelDerivationParameters_get_transaction_parameters(this_ptr: &ChannelDerivationParameters) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters { - let mut inner_val = &mut this_ptr.get_native_mut_ref().transaction_parameters; - crate::lightning::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::chan_utils::ChannelTransactionParameters<>) as *mut _) }, is_owned: false } -} -/// The necessary channel parameters that need to be provided to the re-derived signer through -/// [`ChannelSigner::provide_channel_parameters`]. -/// -/// [`ChannelSigner::provide_channel_parameters`]: crate::sign::ChannelSigner::provide_channel_parameters -#[no_mangle] -pub extern "C" fn ChannelDerivationParameters_set_transaction_parameters(this_ptr: &mut ChannelDerivationParameters, mut val: crate::lightning::ln::chan_utils::ChannelTransactionParameters) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.transaction_parameters = *unsafe { Box::from_raw(val.take_inner()) }; -} -/// Constructs a new ChannelDerivationParameters given each field -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelDerivationParameters_new(mut value_satoshis_arg: u64, mut keys_id_arg: crate::c_types::ThirtyTwoBytes, mut transaction_parameters_arg: crate::lightning::ln::chan_utils::ChannelTransactionParameters) -> ChannelDerivationParameters { - ChannelDerivationParameters { inner: ObjOps::heap_alloc(nativeChannelDerivationParameters { - value_satoshis: value_satoshis_arg, - keys_id: keys_id_arg.data, - transaction_parameters: *unsafe { Box::from_raw(transaction_parameters_arg.take_inner()) }, - }), is_owned: true } -} -impl Clone for ChannelDerivationParameters { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeChannelDerivationParameters>::is_null(self.inner) { core::ptr::null_mut() } else { - ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ChannelDerivationParameters_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelDerivationParameters)).clone() })) as *mut c_void -} -#[no_mangle] -/// Creates a copy of the ChannelDerivationParameters -pub extern "C" fn ChannelDerivationParameters_clone(orig: &ChannelDerivationParameters) -> ChannelDerivationParameters { - orig.clone() -} -/// Checks if two ChannelDerivationParameterss contain equal inner contents. -/// This ignores pointers and is_owned flags and looks at the values in fields. -/// Two objects with NULL inner values will be considered "equal" here. -#[no_mangle] -pub extern "C" fn ChannelDerivationParameters_eq(a: &ChannelDerivationParameters, b: &ChannelDerivationParameters) -> bool { - if a.inner == b.inner { return true; } - if a.inner.is_null() || b.inner.is_null() { return false; } - if a.get_native_ref() == b.get_native_ref() { true } else { false } -} -#[no_mangle] -/// Serialize the ChannelDerivationParameters object into a byte array which can be read by ChannelDerivationParameters_read -pub extern "C" fn ChannelDerivationParameters_write(obj: &crate::lightning::events::bump_transaction::ChannelDerivationParameters) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) -} -#[no_mangle] -pub(crate) extern "C" fn ChannelDerivationParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelDerivationParameters) }) -} -#[no_mangle] -/// Read a ChannelDerivationParameters from a byte array, created by ChannelDerivationParameters_write -pub extern "C" fn ChannelDerivationParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelDerivationParametersDecodeErrorZ { - let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::events::bump_transaction::ChannelDerivationParameters { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; - local_res -} - use lightning::events::bump_transaction::AnchorDescriptor as nativeAnchorDescriptorImport; pub(crate) type nativeAnchorDescriptor = nativeAnchorDescriptorImport; @@ -216,13 +72,13 @@ impl AnchorDescriptor { } /// The parameters required to derive the signer for the anchor input. #[no_mangle] -pub extern "C" fn AnchorDescriptor_get_channel_derivation_parameters(this_ptr: &AnchorDescriptor) -> crate::lightning::events::bump_transaction::ChannelDerivationParameters { +pub extern "C" fn AnchorDescriptor_get_channel_derivation_parameters(this_ptr: &AnchorDescriptor) -> crate::lightning::sign::ChannelDerivationParameters { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_derivation_parameters; - crate::lightning::events::bump_transaction::ChannelDerivationParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::events::bump_transaction::ChannelDerivationParameters<>) as *mut _) }, is_owned: false } + crate::lightning::sign::ChannelDerivationParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::sign::ChannelDerivationParameters<>) as *mut _) }, is_owned: false } } /// The parameters required to derive the signer for the anchor input. #[no_mangle] -pub extern "C" fn AnchorDescriptor_set_channel_derivation_parameters(this_ptr: &mut AnchorDescriptor, mut val: crate::lightning::events::bump_transaction::ChannelDerivationParameters) { +pub extern "C" fn AnchorDescriptor_set_channel_derivation_parameters(this_ptr: &mut AnchorDescriptor, mut val: crate::lightning::sign::ChannelDerivationParameters) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_derivation_parameters = *unsafe { Box::from_raw(val.take_inner()) }; } /// The transaction input's outpoint corresponding to the commitment transaction's anchor @@ -241,7 +97,7 @@ pub extern "C" fn AnchorDescriptor_set_outpoint(this_ptr: &mut AnchorDescriptor, /// Constructs a new AnchorDescriptor given each field #[must_use] #[no_mangle] -pub extern "C" fn AnchorDescriptor_new(mut channel_derivation_parameters_arg: crate::lightning::events::bump_transaction::ChannelDerivationParameters, mut outpoint_arg: crate::lightning::chain::transaction::OutPoint) -> AnchorDescriptor { +pub extern "C" fn AnchorDescriptor_new(mut channel_derivation_parameters_arg: crate::lightning::sign::ChannelDerivationParameters, mut outpoint_arg: crate::lightning::chain::transaction::OutPoint) -> AnchorDescriptor { AnchorDescriptor { inner: ObjOps::heap_alloc(nativeAnchorDescriptor { channel_derivation_parameters: *unsafe { Box::from_raw(channel_derivation_parameters_arg.take_inner()) }, outpoint: crate::c_types::C_to_bitcoin_outpoint(outpoint_arg), @@ -259,7 +115,7 @@ impl Clone for AnchorDescriptor { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn AnchorDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeAnchorDescriptor)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeAnchorDescriptor)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the AnchorDescriptor @@ -318,240 +174,6 @@ pub extern "C" fn AnchorDescriptor_derive_channel_signer(this_arg: &crate::light Into::into(ret) } - -use lightning::events::bump_transaction::HTLCDescriptor as nativeHTLCDescriptorImport; -pub(crate) type nativeHTLCDescriptor = nativeHTLCDescriptorImport; - -/// A descriptor used to sign for a commitment transaction's HTLC output. -#[must_use] -#[repr(C)] -pub struct HTLCDescriptor { - /// A pointer to the opaque Rust object. - - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeHTLCDescriptor, - /// Indicates that this is the only struct which contains the same pointer. - - /// Rust functions which take ownership of an object provided via an argument require - /// this to be true and invalidate the object pointed to by inner. - pub is_owned: bool, -} - -impl Drop for HTLCDescriptor { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeHTLCDescriptor>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; - } - } -} -/// Frees any resources used by the HTLCDescriptor, if is_owned is set and inner is non-NULL. -#[no_mangle] -pub extern "C" fn HTLCDescriptor_free(this_obj: HTLCDescriptor) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn HTLCDescriptor_free_void(this_ptr: *mut c_void) { - let _ = unsafe { Box::from_raw(this_ptr as *mut nativeHTLCDescriptor) }; -} -#[allow(unused)] -impl HTLCDescriptor { - pub(crate) fn get_native_ref(&self) -> &'static nativeHTLCDescriptor { - unsafe { &*ObjOps::untweak_ptr(self.inner) } - } - pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHTLCDescriptor { - unsafe { &mut *ObjOps::untweak_ptr(self.inner) } - } - /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy - pub(crate) fn take_inner(mut self) -> *mut nativeHTLCDescriptor { - assert!(self.is_owned); - let ret = ObjOps::untweak_ptr(self.inner); - self.inner = core::ptr::null_mut(); - ret - } -} -/// The parameters required to derive the signer for the HTLC input. -#[no_mangle] -pub extern "C" fn HTLCDescriptor_get_channel_derivation_parameters(this_ptr: &HTLCDescriptor) -> crate::lightning::events::bump_transaction::ChannelDerivationParameters { - let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_derivation_parameters; - crate::lightning::events::bump_transaction::ChannelDerivationParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::events::bump_transaction::ChannelDerivationParameters<>) as *mut _) }, is_owned: false } -} -/// The parameters required to derive the signer for the HTLC input. -#[no_mangle] -pub extern "C" fn HTLCDescriptor_set_channel_derivation_parameters(this_ptr: &mut HTLCDescriptor, mut val: crate::lightning::events::bump_transaction::ChannelDerivationParameters) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_derivation_parameters = *unsafe { Box::from_raw(val.take_inner()) }; -} -/// The number of the commitment transaction in which the HTLC output lives. -#[no_mangle] -pub extern "C" fn HTLCDescriptor_get_per_commitment_number(this_ptr: &HTLCDescriptor) -> u64 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_number; - *inner_val -} -/// The number of the commitment transaction in which the HTLC output lives. -#[no_mangle] -pub extern "C" fn HTLCDescriptor_set_per_commitment_number(this_ptr: &mut HTLCDescriptor, mut val: u64) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_number = val; -} -/// The key tweak corresponding to the number of the commitment transaction in which the HTLC -/// output lives. This tweak is applied to all the basepoints for both parties in the channel to -/// arrive at unique keys per commitment. -/// -/// See for more info. -#[no_mangle] -pub extern "C" fn HTLCDescriptor_get_per_commitment_point(this_ptr: &HTLCDescriptor) -> crate::c_types::PublicKey { - let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_point; - crate::c_types::PublicKey::from_rust(&inner_val) -} -/// The key tweak corresponding to the number of the commitment transaction in which the HTLC -/// output lives. This tweak is applied to all the basepoints for both parties in the channel to -/// arrive at unique keys per commitment. -/// -/// See for more info. -#[no_mangle] -pub extern "C" fn HTLCDescriptor_set_per_commitment_point(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_point = val.into_rust(); -} -/// The details of the HTLC as it appears in the commitment transaction. -#[no_mangle] -pub extern "C" fn HTLCDescriptor_get_htlc(this_ptr: &HTLCDescriptor) -> crate::lightning::ln::chan_utils::HTLCOutputInCommitment { - let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc; - crate::lightning::ln::chan_utils::HTLCOutputInCommitment { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::chan_utils::HTLCOutputInCommitment<>) as *mut _) }, is_owned: false } -} -/// The details of the HTLC as it appears in the commitment transaction. -#[no_mangle] -pub extern "C" fn HTLCDescriptor_set_htlc(this_ptr: &mut HTLCDescriptor, mut val: crate::lightning::ln::chan_utils::HTLCOutputInCommitment) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc = *unsafe { Box::from_raw(val.take_inner()) }; -} -/// The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be -/// taken. -#[no_mangle] -pub extern "C" fn HTLCDescriptor_get_preimage(this_ptr: &HTLCDescriptor) -> crate::c_types::derived::COption_ThirtyTwoBytesZ { - let mut inner_val = &mut this_ptr.get_native_mut_ref().preimage; - let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_ThirtyTwoBytesZ::None } else { crate::c_types::derived::COption_ThirtyTwoBytesZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option is otherwise un-expressable. */ { crate::c_types::ThirtyTwoBytes { data: (*inner_val.as_ref().unwrap()).clone().0 } }) }; - local_inner_val -} -/// The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be -/// taken. -#[no_mangle] -pub extern "C" fn HTLCDescriptor_set_preimage(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::derived::COption_ThirtyTwoBytesZ) { - let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { ::lightning::ln::PaymentPreimage({ val_opt.take() }.data) }})} }; - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.preimage = local_val; -} -/// The counterparty's signature required to spend the HTLC output. -#[no_mangle] -pub extern "C" fn HTLCDescriptor_get_counterparty_sig(this_ptr: &HTLCDescriptor) -> crate::c_types::ECDSASignature { - let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty_sig; - crate::c_types::ECDSASignature::from_rust(&inner_val) -} -/// The counterparty's signature required to spend the HTLC output. -#[no_mangle] -pub extern "C" fn HTLCDescriptor_set_counterparty_sig(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::ECDSASignature) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty_sig = val.into_rust(); -} -impl Clone for HTLCDescriptor { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeHTLCDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else { - ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn HTLCDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCDescriptor)).clone() })) as *mut c_void -} -#[no_mangle] -/// Creates a copy of the HTLCDescriptor -pub extern "C" fn HTLCDescriptor_clone(orig: &HTLCDescriptor) -> HTLCDescriptor { - orig.clone() -} -/// Checks if two HTLCDescriptors contain equal inner contents. -/// This ignores pointers and is_owned flags and looks at the values in fields. -/// Two objects with NULL inner values will be considered "equal" here. -#[no_mangle] -pub extern "C" fn HTLCDescriptor_eq(a: &HTLCDescriptor, b: &HTLCDescriptor) -> bool { - if a.inner == b.inner { return true; } - if a.inner.is_null() || b.inner.is_null() { return false; } - if a.get_native_ref() == b.get_native_ref() { true } else { false } -} -#[no_mangle] -/// Serialize the HTLCDescriptor object into a byte array which can be read by HTLCDescriptor_read -pub extern "C" fn HTLCDescriptor_write(obj: &crate::lightning::events::bump_transaction::HTLCDescriptor) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) -} -#[no_mangle] -pub(crate) extern "C" fn HTLCDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCDescriptor) }) -} -#[no_mangle] -/// Read a HTLCDescriptor from a byte array, created by HTLCDescriptor_write -pub extern "C" fn HTLCDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCDescriptorDecodeErrorZ { - let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::events::bump_transaction::HTLCDescriptor { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; - local_res -} -/// Returns the outpoint of the HTLC output in the commitment transaction. This is the outpoint -/// being spent by the HTLC input in the HTLC transaction. -#[must_use] -#[no_mangle] -pub extern "C" fn HTLCDescriptor_outpoint(this_arg: &crate::lightning::events::bump_transaction::HTLCDescriptor) -> crate::lightning::chain::transaction::OutPoint { - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.outpoint(); - crate::c_types::bitcoin_to_C_outpoint(&ret) -} - -/// Returns the UTXO to be spent by the HTLC input, which can be obtained via -/// [`Self::unsigned_tx_input`]. -#[must_use] -#[no_mangle] -pub extern "C" fn HTLCDescriptor_previous_utxo(this_arg: &crate::lightning::events::bump_transaction::HTLCDescriptor) -> crate::c_types::TxOut { - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.previous_utxo(secp256k1::global::SECP256K1); - crate::c_types::TxOut::from_rust(&ret) -} - -/// Returns the unsigned transaction input spending the HTLC output in the commitment -/// transaction. -#[must_use] -#[no_mangle] -pub extern "C" fn HTLCDescriptor_unsigned_tx_input(this_arg: &crate::lightning::events::bump_transaction::HTLCDescriptor) -> crate::c_types::TxIn { - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.unsigned_tx_input(); - crate::c_types::TxIn::from_rust(&ret) -} - -/// Returns the delayed output created as a result of spending the HTLC output in the commitment -/// transaction. -#[must_use] -#[no_mangle] -pub extern "C" fn HTLCDescriptor_tx_output(this_arg: &crate::lightning::events::bump_transaction::HTLCDescriptor) -> crate::c_types::TxOut { - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.tx_output(secp256k1::global::SECP256K1); - crate::c_types::TxOut::from_rust(&ret) -} - -/// Returns the witness script of the HTLC output in the commitment transaction. -#[must_use] -#[no_mangle] -pub extern "C" fn HTLCDescriptor_witness_script(this_arg: &crate::lightning::events::bump_transaction::HTLCDescriptor) -> crate::c_types::derived::CVec_u8Z { - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.witness_script(secp256k1::global::SECP256K1); - ret.into_bytes().into() -} - -/// Returns the fully signed witness required to spend the HTLC output in the commitment -/// transaction. -#[must_use] -#[no_mangle] -pub extern "C" fn HTLCDescriptor_tx_input_witness(this_arg: &crate::lightning::events::bump_transaction::HTLCDescriptor, mut signature: crate::c_types::ECDSASignature, mut witness_script: crate::c_types::u8slice) -> crate::c_types::Witness { - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.tx_input_witness(&signature.into_rust(), &::bitcoin::blockdata::script::Script::from(Vec::from(witness_script.to_slice()))); - crate::c_types::Witness::from_bitcoin(&ret) -} - -/// Derives the channel signer required to sign the HTLC input. -#[must_use] -#[no_mangle] -pub extern "C" fn HTLCDescriptor_derive_channel_signer(this_arg: &crate::lightning::events::bump_transaction::HTLCDescriptor, signer_provider: &crate::lightning::sign::SignerProvider) -> crate::lightning::sign::WriteableEcdsaChannelSigner { - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_signer(signer_provider); - Into::into(ret) -} - /// Represents the different types of transactions, originating from LDK, to be bumped. #[derive(Clone)] #[must_use] @@ -649,7 +271,6 @@ pub enum BumpTransactionEvent { /// /// [`EcdsaChannelSigner`]: crate::sign::EcdsaChannelSigner /// [`EcdsaChannelSigner::sign_holder_htlc_transaction`]: crate::sign::EcdsaChannelSigner::sign_holder_htlc_transaction - /// [`HTLCDescriptor::tx_input_witness`]: HTLCDescriptor::tx_input_witness HTLCResolution { /// The unique identifier for the claim of the HTLCs in the confirmed commitment /// transaction. @@ -755,7 +376,7 @@ impl BumpTransactionEvent { let mut claim_id_nonref = Clone::clone(claim_id); let mut target_feerate_sat_per_1000_weight_nonref = Clone::clone(target_feerate_sat_per_1000_weight); let mut htlc_descriptors_nonref = Clone::clone(htlc_descriptors); - let mut local_htlc_descriptors_nonref = Vec::new(); for mut item in htlc_descriptors_nonref.drain(..) { local_htlc_descriptors_nonref.push( { crate::lightning::events::bump_transaction::HTLCDescriptor { inner: ObjOps::heap_alloc(item), is_owned: true } }); }; + let mut local_htlc_descriptors_nonref = Vec::new(); for mut item in htlc_descriptors_nonref.drain(..) { local_htlc_descriptors_nonref.push( { crate::lightning::sign::HTLCDescriptor { inner: ObjOps::heap_alloc(item), is_owned: true } }); }; let mut tx_lock_time_nonref = Clone::clone(tx_lock_time); BumpTransactionEvent::HTLCResolution { claim_id: crate::c_types::ThirtyTwoBytes { data: claim_id_nonref.0 }, @@ -781,7 +402,7 @@ impl BumpTransactionEvent { } }, nativeBumpTransactionEvent::HTLCResolution {mut claim_id, mut target_feerate_sat_per_1000_weight, mut htlc_descriptors, mut tx_lock_time, } => { - let mut local_htlc_descriptors = Vec::new(); for mut item in htlc_descriptors.drain(..) { local_htlc_descriptors.push( { crate::lightning::events::bump_transaction::HTLCDescriptor { inner: ObjOps::heap_alloc(item), is_owned: true } }); }; + let mut local_htlc_descriptors = Vec::new(); for mut item in htlc_descriptors.drain(..) { local_htlc_descriptors.push( { crate::lightning::sign::HTLCDescriptor { inner: ObjOps::heap_alloc(item), is_owned: true } }); }; BumpTransactionEvent::HTLCResolution { claim_id: crate::c_types::ThirtyTwoBytes { data: claim_id.0 }, target_feerate_sat_per_1000_weight: target_feerate_sat_per_1000_weight, @@ -800,6 +421,16 @@ pub extern "C" fn BumpTransactionEvent_free(this_ptr: BumpTransactionEvent) { } pub extern "C" fn BumpTransactionEvent_clone(orig: &BumpTransactionEvent) -> BumpTransactionEvent { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn BumpTransactionEvent_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const BumpTransactionEvent)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn BumpTransactionEvent_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut BumpTransactionEvent) }; +} #[no_mangle] /// Utility method to constructs a new ChannelClose-variant BumpTransactionEvent pub extern "C" fn BumpTransactionEvent_channel_close(claim_id: crate::c_types::ThirtyTwoBytes, package_target_feerate_sat_per_1000_weight: u32, commitment_tx: crate::c_types::Transaction, commitment_tx_fee_satoshis: u64, anchor_descriptor: crate::lightning::events::bump_transaction::AnchorDescriptor, pending_htlcs: crate::c_types::derived::CVec_HTLCOutputInCommitmentZ) -> BumpTransactionEvent { @@ -940,7 +571,7 @@ impl Clone for Input { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Input_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInput)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeInput)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Input @@ -1077,7 +708,7 @@ impl Clone for Utxo { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Utxo_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUtxo)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUtxo)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Utxo @@ -1220,7 +851,7 @@ impl Clone for CoinSelection { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn CoinSelection_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCoinSelection)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeCoinSelection)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the CoinSelection @@ -1272,6 +903,7 @@ pub struct CoinSelectionSource { } unsafe impl Send for CoinSelectionSource {} unsafe impl Sync for CoinSelectionSource {} +#[allow(unused)] pub(crate) fn CoinSelectionSource_clone_fields(orig: &CoinSelectionSource) -> CoinSelectionSource { CoinSelectionSource { this_arg: orig.this_arg, @@ -1342,6 +974,7 @@ pub struct WalletSource { } unsafe impl Send for WalletSource {} unsafe impl Sync for WalletSource {} +#[allow(unused)] pub(crate) fn WalletSource_clone_fields(orig: &WalletSource) -> WalletSource { WalletSource { this_arg: orig.this_arg, @@ -1458,10 +1091,10 @@ pub extern "C" fn Wallet_new(mut source: crate::lightning::events::bump_transact impl From for crate::lightning::events::bump_transaction::CoinSelectionSource { fn from(obj: nativeWallet) -> Self { - let mut rust_obj = Wallet { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::events::bump_transaction::Wallet { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = Wallet_as_CoinSelectionSource(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(Wallet_free_void); ret } diff --git a/lightning-c-bindings/src/lightning/events/mod.rs b/lightning-c-bindings/src/lightning/events/mod.rs index 7a85b83..a1e9b0a 100644 --- a/lightning-c-bindings/src/lightning/events/mod.rs +++ b/lightning-c-bindings/src/lightning/events/mod.rs @@ -142,6 +142,16 @@ pub extern "C" fn PaymentPurpose_free(this_ptr: PaymentPurpose) { } pub extern "C" fn PaymentPurpose_clone(orig: &PaymentPurpose) -> PaymentPurpose { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn PaymentPurpose_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const PaymentPurpose)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn PaymentPurpose_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut PaymentPurpose) }; +} #[no_mangle] /// Utility method to constructs a new InvoicePayment-variant PaymentPurpose pub extern "C" fn PaymentPurpose_invoice_payment(payment_preimage: crate::c_types::derived::COption_ThirtyTwoBytesZ, payment_secret: crate::c_types::ThirtyTwoBytes) -> PaymentPurpose { @@ -166,6 +176,10 @@ pub extern "C" fn PaymentPurpose_eq(a: &PaymentPurpose, b: &PaymentPurpose) -> b pub extern "C" fn PaymentPurpose_write(obj: &crate::lightning::events::PaymentPurpose) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) } +#[allow(unused)] +pub(crate) extern "C" fn PaymentPurpose_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + PaymentPurpose_write(unsafe { &*(obj as *const PaymentPurpose) }) +} #[no_mangle] /// Read a PaymentPurpose from a byte array, created by PaymentPurpose_write pub extern "C" fn PaymentPurpose_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PaymentPurposeDecodeErrorZ { @@ -315,7 +329,7 @@ impl Clone for ClaimedHTLC { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ClaimedHTLC_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeClaimedHTLC)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeClaimedHTLC)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ClaimedHTLC @@ -336,7 +350,7 @@ pub extern "C" fn ClaimedHTLC_eq(a: &ClaimedHTLC, b: &ClaimedHTLC) -> bool { pub extern "C" fn ClaimedHTLC_write(obj: &crate::lightning::events::ClaimedHTLC) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ClaimedHTLC_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeClaimedHTLC) }) } @@ -453,6 +467,16 @@ pub extern "C" fn PathFailure_free(this_ptr: PathFailure) { } pub extern "C" fn PathFailure_clone(orig: &PathFailure) -> PathFailure { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn PathFailure_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const PathFailure)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn PathFailure_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut PathFailure) }; +} #[no_mangle] /// Utility method to constructs a new InitialSend-variant PathFailure pub extern "C" fn PathFailure_initial_send(err: crate::lightning::util::errors::APIError) -> PathFailure { @@ -478,6 +502,10 @@ pub extern "C" fn PathFailure_eq(a: &PathFailure, b: &PathFailure) -> bool { pub extern "C" fn PathFailure_write(obj: &crate::lightning::events::PathFailure) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) } +#[allow(unused)] +pub(crate) extern "C" fn PathFailure_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + PathFailure_write(unsafe { &*(obj as *const PathFailure) }) +} #[no_mangle] /// Read a PathFailure from a byte array, created by PathFailure_write pub extern "C" fn PathFailure_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_PathFailureZDecodeErrorZ { @@ -655,6 +683,16 @@ pub extern "C" fn ClosureReason_free(this_ptr: ClosureReason) { } pub extern "C" fn ClosureReason_clone(orig: &ClosureReason) -> ClosureReason { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ClosureReason_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const ClosureReason)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ClosureReason_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut ClosureReason) }; +} #[no_mangle] /// Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason pub extern "C" fn ClosureReason_counterparty_force_closed(peer_msg: crate::lightning::util::string::UntrustedString) -> ClosureReason { @@ -712,6 +750,10 @@ pub extern "C" fn ClosureReason_eq(a: &ClosureReason, b: &ClosureReason) -> bool pub extern "C" fn ClosureReason_write(obj: &crate::lightning::events::ClosureReason) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) } +#[allow(unused)] +pub(crate) extern "C" fn ClosureReason_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + ClosureReason_write(unsafe { &*(obj as *const ClosureReason) }) +} #[no_mangle] /// Read a ClosureReason from a byte array, created by ClosureReason_write pub extern "C" fn ClosureReason_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_ClosureReasonZDecodeErrorZ { @@ -893,6 +935,16 @@ pub extern "C" fn HTLCDestination_free(this_ptr: HTLCDestination) { } pub extern "C" fn HTLCDestination_clone(orig: &HTLCDestination) -> HTLCDestination { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn HTLCDestination_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const HTLCDestination)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn HTLCDestination_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut HTLCDestination) }; +} #[no_mangle] /// Utility method to constructs a new NextHopChannel-variant HTLCDestination pub extern "C" fn HTLCDestination_next_hop_channel(node_id: crate::c_types::PublicKey, channel_id: crate::c_types::ThirtyTwoBytes) -> HTLCDestination { @@ -933,6 +985,10 @@ pub extern "C" fn HTLCDestination_eq(a: &HTLCDestination, b: &HTLCDestination) - pub extern "C" fn HTLCDestination_write(obj: &crate::lightning::events::HTLCDestination) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) } +#[allow(unused)] +pub(crate) extern "C" fn HTLCDestination_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + HTLCDestination_write(unsafe { &*(obj as *const HTLCDestination) }) +} #[no_mangle] /// Read a HTLCDestination from a byte array, created by HTLCDestination_write pub extern "C" fn HTLCDestination_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_HTLCDestinationZDecodeErrorZ { @@ -1023,6 +1079,16 @@ impl PaymentFailureReason { pub extern "C" fn PaymentFailureReason_clone(orig: &PaymentFailureReason) -> PaymentFailureReason { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn PaymentFailureReason_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const PaymentFailureReason)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn PaymentFailureReason_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut PaymentFailureReason) }; +} #[no_mangle] /// Utility method to constructs a new RecipientRejected-variant PaymentFailureReason pub extern "C" fn PaymentFailureReason_recipient_rejected() -> PaymentFailureReason { @@ -1058,6 +1124,10 @@ pub extern "C" fn PaymentFailureReason_eq(a: &PaymentFailureReason, b: &PaymentF pub extern "C" fn PaymentFailureReason_write(obj: &crate::lightning::events::PaymentFailureReason) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) } +#[allow(unused)] +pub(crate) extern "C" fn PaymentFailureReason_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + PaymentFailureReason_write(unsafe { &*(obj as *const PaymentFailureReason) }) +} #[no_mangle] /// Read a PaymentFailureReason from a byte array, created by PaymentFailureReason_write pub extern "C" fn PaymentFailureReason_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PaymentFailureReasonDecodeErrorZ { @@ -1237,6 +1307,18 @@ pub enum Event { /// serialized prior to LDK version 0.0.117. sender_intended_total_msat: crate::c_types::derived::COption_u64Z, }, + /// Indicates a request for an invoice failed to yield a response in a reasonable amount of time + /// or was explicitly abandoned by [`ChannelManager::abandon_payment`]. This may be for an + /// [`InvoiceRequest`] sent for an [`Offer`] or for a [`Refund`] that hasn't been redeemed. + /// + /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment + /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest + /// [`Offer`]: crate::offers::offer::Offer + /// [`Refund`]: crate::offers::refund::Refund + InvoiceRequestFailed { + /// The `payment_id` to have been associated with payment for the requested invoice. + payment_id: crate::c_types::ThirtyTwoBytes, + }, /// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target /// and we got back the payment preimage for it). /// @@ -1720,6 +1802,12 @@ impl Event { sender_intended_total_msat: local_sender_intended_total_msat_nonref, } }, + Event::InvoiceRequestFailed {ref payment_id, } => { + let mut payment_id_nonref = Clone::clone(payment_id); + nativeEvent::InvoiceRequestFailed { + payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data), + } + }, Event::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => { let mut payment_id_nonref = Clone::clone(payment_id); let mut local_payment_id_nonref = { /*payment_id_nonref*/ let payment_id_nonref_opt = payment_id_nonref; if payment_id_nonref_opt.is_none() { None } else { Some({ { ::lightning::ln::channelmanager::PaymentId({ payment_id_nonref_opt.take() }.data) }})} }; @@ -1969,6 +2057,11 @@ impl Event { sender_intended_total_msat: local_sender_intended_total_msat, } }, + Event::InvoiceRequestFailed {mut payment_id, } => { + nativeEvent::InvoiceRequestFailed { + payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data), + } + }, Event::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => { let mut local_payment_id = { /*payment_id*/ let payment_id_opt = payment_id; if payment_id_opt.is_none() { None } else { Some({ { ::lightning::ln::channelmanager::PaymentId({ payment_id_opt.take() }.data) }})} }; let mut local_fee_paid_msat = if fee_paid_msat.is_some() { Some( { fee_paid_msat.take() }) } else { None }; @@ -2178,6 +2271,12 @@ impl Event { sender_intended_total_msat: local_sender_intended_total_msat_nonref, } }, + nativeEvent::InvoiceRequestFailed {ref payment_id, } => { + let mut payment_id_nonref = Clone::clone(payment_id); + Event::InvoiceRequestFailed { + payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 }, + } + }, nativeEvent::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => { let mut payment_id_nonref = Clone::clone(payment_id); let mut local_payment_id_nonref = if payment_id_nonref.is_none() { crate::c_types::derived::COption_ThirtyTwoBytesZ::None } else { crate::c_types::derived::COption_ThirtyTwoBytesZ::Some( { crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.unwrap().0 } }) }; @@ -2427,6 +2526,11 @@ impl Event { sender_intended_total_msat: local_sender_intended_total_msat, } }, + nativeEvent::InvoiceRequestFailed {mut payment_id, } => { + Event::InvoiceRequestFailed { + payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 }, + } + }, nativeEvent::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => { let mut local_payment_id = if payment_id.is_none() { crate::c_types::derived::COption_ThirtyTwoBytesZ::None } else { crate::c_types::derived::COption_ThirtyTwoBytesZ::Some( { crate::c_types::ThirtyTwoBytes { data: payment_id.unwrap().0 } }) }; let mut local_fee_paid_msat = if fee_paid_msat.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { fee_paid_msat.unwrap() }) }; @@ -2582,6 +2686,16 @@ pub extern "C" fn Event_free(this_ptr: Event) { } pub extern "C" fn Event_clone(orig: &Event) -> Event { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Event_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Event)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Event_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut Event) }; +} #[no_mangle] /// Utility method to constructs a new FundingGenerationReady-variant Event pub extern "C" fn Event_funding_generation_ready(temporary_channel_id: crate::c_types::ThirtyTwoBytes, counterparty_node_id: crate::c_types::PublicKey, channel_value_satoshis: u64, output_script: crate::c_types::derived::CVec_u8Z, user_channel_id: crate::c_types::U128) -> Event { @@ -2621,6 +2735,13 @@ pub extern "C" fn Event_payment_claimed(receiver_node_id: crate::c_types::Public } } #[no_mangle] +/// Utility method to constructs a new InvoiceRequestFailed-variant Event +pub extern "C" fn Event_invoice_request_failed(payment_id: crate::c_types::ThirtyTwoBytes) -> Event { + Event::InvoiceRequestFailed { + payment_id, + } +} +#[no_mangle] /// Utility method to constructs a new PaymentSent-variant Event pub extern "C" fn Event_payment_sent(payment_id: crate::c_types::derived::COption_ThirtyTwoBytesZ, payment_preimage: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, fee_paid_msat: crate::c_types::derived::COption_u64Z) -> Event { Event::PaymentSent { @@ -2791,6 +2912,10 @@ pub extern "C" fn Event_eq(a: &Event, b: &Event) -> bool { pub extern "C" fn Event_write(obj: &crate::lightning::events::Event) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) } +#[allow(unused)] +pub(crate) extern "C" fn Event_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + Event_write(unsafe { &*(obj as *const Event) }) +} #[no_mangle] /// Read a Event from a byte array, created by Event_write pub extern "C" fn Event_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_EventZDecodeErrorZ { @@ -3977,6 +4102,16 @@ pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { } pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn MessageSendEvent_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const MessageSendEvent)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn MessageSendEvent_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut MessageSendEvent) }; +} #[no_mangle] /// Utility method to constructs a new SendAcceptChannel-variant MessageSendEvent pub extern "C" fn MessageSendEvent_send_accept_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AcceptChannel) -> MessageSendEvent { @@ -4247,6 +4382,7 @@ pub struct MessageSendEventsProvider { } unsafe impl Send for MessageSendEventsProvider {} unsafe impl Sync for MessageSendEventsProvider {} +#[allow(unused)] pub(crate) fn MessageSendEventsProvider_clone_fields(orig: &MessageSendEventsProvider) -> MessageSendEventsProvider { MessageSendEventsProvider { this_arg: orig.this_arg, @@ -4287,62 +4423,6 @@ impl Drop for MessageSendEventsProvider { } } } -/// A trait indicating an object may generate onion messages to send -#[repr(C)] -pub struct OnionMessageProvider { - /// An opaque pointer which is passed to your function implementations as an argument. - /// This has no meaning in the LDK, and can be NULL or any other value. - pub this_arg: *mut c_void, - /// Gets the next pending onion message for the peer with the given node id. - /// - /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None - pub next_onion_message_for_peer: extern "C" fn (this_arg: *const c_void, peer_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::msgs::OnionMessage, - /// Frees any resources associated with this object given its this_arg pointer. - /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. - pub free: Option, -} -unsafe impl Send for OnionMessageProvider {} -unsafe impl Sync for OnionMessageProvider {} -pub(crate) fn OnionMessageProvider_clone_fields(orig: &OnionMessageProvider) -> OnionMessageProvider { - OnionMessageProvider { - this_arg: orig.this_arg, - next_onion_message_for_peer: Clone::clone(&orig.next_onion_message_for_peer), - free: Clone::clone(&orig.free), - } -} - -use lightning::events::OnionMessageProvider as rustOnionMessageProvider; -impl rustOnionMessageProvider for OnionMessageProvider { - fn next_onion_message_for_peer(&self, mut peer_node_id: bitcoin::secp256k1::PublicKey) -> Option { - let mut ret = (self.next_onion_message_for_peer)(self.this_arg, crate::c_types::PublicKey::from_rust(&peer_node_id)); - let mut local_ret = if ret.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(ret.take_inner()) } }) }; - local_ret - } -} - -// We're essentially a pointer already, or at least a set of pointers, so allow us to be used -// directly as a Deref trait in higher-level structs: -impl core::ops::Deref for OnionMessageProvider { - type Target = Self; - fn deref(&self) -> &Self { - self - } -} -impl core::ops::DerefMut for OnionMessageProvider { - fn deref_mut(&mut self) -> &mut Self { - self - } -} -/// Calls the free function if one is set -#[no_mangle] -pub extern "C" fn OnionMessageProvider_free(this_ptr: OnionMessageProvider) { } -impl Drop for OnionMessageProvider { - fn drop(&mut self) { - if let Some(f) = self.free { - f(self.this_arg); - } - } -} /// A trait indicating an object may generate events. /// /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`]. @@ -4394,6 +4474,7 @@ pub struct EventsProvider { } unsafe impl Send for EventsProvider {} unsafe impl Sync for EventsProvider {} +#[allow(unused)] pub(crate) fn EventsProvider_clone_fields(orig: &EventsProvider) -> EventsProvider { EventsProvider { this_arg: orig.this_arg, @@ -4433,6 +4514,7 @@ pub struct EventHandler { } unsafe impl Send for EventHandler {} unsafe impl Sync for EventHandler {} +#[allow(unused)] pub(crate) fn EventHandler_clone_fields(orig: &EventHandler) -> EventHandler { EventHandler { this_arg: orig.this_arg, diff --git a/lightning-c-bindings/src/lightning/ln/chan_utils.rs b/lightning-c-bindings/src/lightning/ln/chan_utils.rs index 15f1135..5b57c01 100644 --- a/lightning-c-bindings/src/lightning/ln/chan_utils.rs +++ b/lightning-c-bindings/src/lightning/ln/chan_utils.rs @@ -130,6 +130,16 @@ impl HTLCClaim { pub extern "C" fn HTLCClaim_clone(orig: &HTLCClaim) -> HTLCClaim { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn HTLCClaim_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const HTLCClaim)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn HTLCClaim_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut HTLCClaim) }; +} #[no_mangle] /// Utility method to constructs a new OfferedTimeout-variant HTLCClaim pub extern "C" fn HTLCClaim_offered_timeout() -> HTLCClaim { @@ -246,7 +256,7 @@ impl Clone for CounterpartyCommitmentSecrets { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn CounterpartyCommitmentSecrets_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCounterpartyCommitmentSecrets)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeCounterpartyCommitmentSecrets)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the CounterpartyCommitmentSecrets @@ -297,7 +307,7 @@ pub extern "C" fn CounterpartyCommitmentSecrets_get_secret(this_arg: &crate::lig pub extern "C" fn CounterpartyCommitmentSecrets_write(obj: &crate::lightning::ln::chan_utils::CounterpartyCommitmentSecrets) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn CounterpartyCommitmentSecrets_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCounterpartyCommitmentSecrets) }) } @@ -507,7 +517,7 @@ impl Clone for TxCreationKeys { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TxCreationKeys_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxCreationKeys)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTxCreationKeys)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TxCreationKeys @@ -519,7 +529,7 @@ pub extern "C" fn TxCreationKeys_clone(orig: &TxCreationKeys) -> TxCreationKeys pub extern "C" fn TxCreationKeys_write(obj: &crate::lightning::ln::chan_utils::TxCreationKeys) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TxCreationKeys_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxCreationKeys) }) } @@ -678,7 +688,7 @@ impl Clone for ChannelPublicKeys { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelPublicKeys_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelPublicKeys)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelPublicKeys)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelPublicKeys @@ -709,7 +719,7 @@ pub extern "C" fn ChannelPublicKeys_eq(a: &ChannelPublicKeys, b: &ChannelPublicK pub extern "C" fn ChannelPublicKeys_write(obj: &crate::lightning::ln::chan_utils::ChannelPublicKeys) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelPublicKeys_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelPublicKeys) }) } @@ -904,7 +914,7 @@ impl Clone for HTLCOutputInCommitment { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn HTLCOutputInCommitment_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCOutputInCommitment)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeHTLCOutputInCommitment)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the HTLCOutputInCommitment @@ -925,7 +935,7 @@ pub extern "C" fn HTLCOutputInCommitment_eq(a: &HTLCOutputInCommitment, b: &HTLC pub extern "C" fn HTLCOutputInCommitment_write(obj: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn HTLCOutputInCommitment_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCOutputInCommitment) }) } @@ -1168,7 +1178,7 @@ impl Clone for ChannelTransactionParameters { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelTransactionParameters_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelTransactionParameters)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelTransactionParameters)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelTransactionParameters @@ -1288,7 +1298,7 @@ impl Clone for CounterpartyChannelTransactionParameters { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCounterpartyChannelTransactionParameters)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeCounterpartyChannelTransactionParameters)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the CounterpartyChannelTransactionParameters @@ -1349,7 +1359,7 @@ pub extern "C" fn ChannelTransactionParameters_as_counterparty_broadcastable(thi pub extern "C" fn CounterpartyChannelTransactionParameters_write(obj: &crate::lightning::ln::chan_utils::CounterpartyChannelTransactionParameters) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCounterpartyChannelTransactionParameters) }) } @@ -1365,7 +1375,7 @@ pub extern "C" fn CounterpartyChannelTransactionParameters_read(ser: crate::c_ty pub extern "C" fn ChannelTransactionParameters_write(obj: &crate::lightning::ln::chan_utils::ChannelTransactionParameters) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelTransactionParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelTransactionParameters) }) } @@ -1574,7 +1584,7 @@ impl Clone for HolderCommitmentTransaction { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn HolderCommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHolderCommitmentTransaction)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeHolderCommitmentTransaction)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the HolderCommitmentTransaction @@ -1586,7 +1596,7 @@ pub extern "C" fn HolderCommitmentTransaction_clone(orig: &HolderCommitmentTrans pub extern "C" fn HolderCommitmentTransaction_write(obj: &crate::lightning::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn HolderCommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHolderCommitmentTransaction) }) } @@ -1707,7 +1717,7 @@ impl Clone for BuiltCommitmentTransaction { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn BuiltCommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBuiltCommitmentTransaction)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBuiltCommitmentTransaction)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the BuiltCommitmentTransaction @@ -1719,7 +1729,7 @@ pub extern "C" fn BuiltCommitmentTransaction_clone(orig: &BuiltCommitmentTransac pub extern "C" fn BuiltCommitmentTransaction_write(obj: &crate::lightning::ln::chan_utils::BuiltCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn BuiltCommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBuiltCommitmentTransaction) }) } @@ -1823,7 +1833,7 @@ impl Clone for ClosingTransaction { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ClosingTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeClosingTransaction)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeClosingTransaction)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ClosingTransaction @@ -2067,7 +2077,7 @@ impl Clone for CommitmentTransaction { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn CommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCommitmentTransaction)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeCommitmentTransaction)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the CommitmentTransaction @@ -2079,7 +2089,7 @@ pub extern "C" fn CommitmentTransaction_clone(orig: &CommitmentTransaction) -> C pub extern "C" fn CommitmentTransaction_write(obj: &crate::lightning::ln::chan_utils::CommitmentTransaction) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn CommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCommitmentTransaction) }) } @@ -2098,6 +2108,14 @@ pub extern "C" fn CommitmentTransaction_commitment_number(this_arg: &crate::ligh ret } +/// The per commitment point used by the broadcaster. +#[must_use] +#[no_mangle] +pub extern "C" fn CommitmentTransaction_per_commitment_point(this_arg: &crate::lightning::ln::chan_utils::CommitmentTransaction) -> crate::c_types::PublicKey { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.per_commitment_point(); + crate::c_types::PublicKey::from_rust(&ret) +} + /// The value to be sent to the broadcaster #[must_use] #[no_mangle] diff --git a/lightning-c-bindings/src/lightning/ln/channelmanager.rs b/lightning-c-bindings/src/lightning/ln/channelmanager.rs index 54ec0d5..19642ac 100644 --- a/lightning-c-bindings/src/lightning/ln/channelmanager.rs +++ b/lightning-c-bindings/src/lightning/ln/channelmanager.rs @@ -123,6 +123,16 @@ pub extern "C" fn FailureCode_free(this_ptr: FailureCode) { } pub extern "C" fn FailureCode_clone(orig: &FailureCode) -> FailureCode { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn FailureCode_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const FailureCode)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn FailureCode_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut FailureCode) }; +} #[no_mangle] /// Utility method to constructs a new TemporaryNodeFailure-variant FailureCode pub extern "C" fn FailureCode_temporary_node_failure() -> FailureCode { @@ -346,7 +356,7 @@ impl Clone for ChainParameters { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChainParameters_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChainParameters)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChainParameters)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChainParameters @@ -487,7 +497,7 @@ impl Clone for CounterpartyForwardingInfo { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn CounterpartyForwardingInfo_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCounterpartyForwardingInfo)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeCounterpartyForwardingInfo)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the CounterpartyForwardingInfo @@ -674,7 +684,7 @@ impl Clone for ChannelCounterparty { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelCounterparty_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelCounterparty)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelCounterparty)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelCounterparty @@ -1381,7 +1391,7 @@ impl Clone for ChannelDetails { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelDetails_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelDetails)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelDetails)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelDetails @@ -1489,6 +1499,16 @@ impl ChannelShutdownState { pub extern "C" fn ChannelShutdownState_clone(orig: &ChannelShutdownState) -> ChannelShutdownState { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ChannelShutdownState_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const ChannelShutdownState)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ChannelShutdownState_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut ChannelShutdownState) }; +} #[no_mangle] /// Utility method to constructs a new NotShuttingDown-variant ChannelShutdownState pub extern "C" fn ChannelShutdownState_not_shutting_down() -> ChannelShutdownState { @@ -1710,6 +1730,16 @@ pub extern "C" fn RecentPaymentDetails_free(this_ptr: RecentPaymentDetails) { } pub extern "C" fn RecentPaymentDetails_clone(orig: &RecentPaymentDetails) -> RecentPaymentDetails { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn RecentPaymentDetails_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const RecentPaymentDetails)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn RecentPaymentDetails_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut RecentPaymentDetails) }; +} #[no_mangle] /// Utility method to constructs a new AwaitingInvoice-variant RecentPaymentDetails pub extern "C" fn RecentPaymentDetails_awaiting_invoice(payment_id: crate::c_types::ThirtyTwoBytes) -> RecentPaymentDetails { @@ -1855,7 +1885,7 @@ impl Clone for PhantomRouteHints { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn PhantomRouteHints_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePhantomRouteHints)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePhantomRouteHints)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the PhantomRouteHints @@ -1987,11 +2017,11 @@ pub extern "C" fn ChannelManager_list_recent_payments(this_arg: &crate::lightnin /// will be accepted on the given channel, and after additional timeout/the closing of all /// pending HTLCs, the channel will be closed on chain. /// -/// * If we are the channel initiator, we will pay between our [`Background`] and -/// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee -/// estimate. +/// * If we are the channel initiator, we will pay between our [`ChannelCloseMinimum`] and +/// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`NonAnchorChannelFee`] +/// fee estimate. /// * If our counterparty is the channel initiator, we will require a channel closing -/// transaction feerate of at least our [`Background`] feerate or the feerate which +/// transaction feerate of at least our [`ChannelCloseMinimum`] feerate or the feerate which /// would appear on a force-closure transaction, whichever is lower. We will allow our /// counterparty to pay as much fee as they'd like, however. /// @@ -2003,8 +2033,8 @@ pub extern "C" fn ChannelManager_list_recent_payments(this_arg: &crate::lightnin /// channel. /// /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis -/// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background -/// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal +/// [`ChannelCloseMinimum`]: crate::chain::chaininterface::ConfirmationTarget::ChannelCloseMinimum +/// [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee /// [`SendShutdown`]: crate::events::MessageSendEvent::SendShutdown #[must_use] #[no_mangle] @@ -2022,8 +2052,8 @@ pub extern "C" fn ChannelManager_close_channel(this_arg: &crate::lightning::ln:: /// the channel being closed or not: /// * If we are the channel initiator, we will pay at least this feerate on the closing /// transaction. The upper-bound is set by -/// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee -/// estimate (or `target_feerate_sat_per_1000_weight`, if it is greater). +/// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`NonAnchorChannelFee`] +/// fee estimate (or `target_feerate_sat_per_1000_weight`, if it is greater). /// * If our counterparty is the channel initiator, we will refuse to accept a channel closure /// transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which /// will appear on a force-closure transaction, whichever is lower). @@ -2041,8 +2071,7 @@ pub extern "C" fn ChannelManager_close_channel(this_arg: &crate::lightning::ln:: /// channel. /// /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis -/// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background -/// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal +/// [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee /// [`SendShutdown`]: crate::events::MessageSendEvent::SendShutdown /// /// Note that shutdown_script (or a relevant inner pointer) may be NULL or all-0s to represent None @@ -2178,10 +2207,20 @@ pub extern "C" fn ChannelManager_send_payment(this_arg: &crate::lightning::ln::c /// wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to /// determine the ultimate status of a payment. /// +/// # Requested Invoices +/// +/// In the case of paying a [`Bolt12Invoice`] via [`ChannelManager::pay_for_offer`], abandoning +/// the payment prior to receiving the invoice will result in an [`Event::InvoiceRequestFailed`] +/// and prevent any attempts at paying it once received. The other events may only be generated +/// once the invoice has been received. +/// /// # Restart Behavior /// /// If an [`Event::PaymentFailed`] is generated and we restart without first persisting the -/// [`ChannelManager`], another [`Event::PaymentFailed`] may be generated. +/// [`ChannelManager`], another [`Event::PaymentFailed`] may be generated; likewise for +/// [`Event::InvoiceRequestFailed`]. +/// +/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice #[no_mangle] pub extern "C" fn ChannelManager_abandon_payment(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_id: crate::c_types::ThirtyTwoBytes) { unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.abandon_payment(::lightning::ln::channelmanager::PaymentId(payment_id.data)) @@ -2457,6 +2496,10 @@ pub extern "C" fn ChannelManager_process_pending_htlc_forwards(this_arg: &crate: /// with the current [`ChannelConfig`]. /// * Removing peers which have disconnected but and no longer have any channels. /// * Force-closing and removing channels which have not completed establishment in a timely manner. +/// * Forgetting about stale outbound payments, either those that have already been fulfilled +/// or those awaiting an invoice that hasn't been delivered in the necessary amount of time. +/// The latter is determined using the system clock in `std` and the highest seen block time +/// minus two hours in `no-std`. /// /// Note that this may cause reentrancy through [`chain::Watch::update_channel`] calls or feerate /// estimate fetches. @@ -2596,6 +2639,91 @@ pub extern "C" fn ChannelManager_accept_inbound_channel_from_trusted_peer_0conf( local_ret } +/// Pays for an [`Offer`] using the given parameters by creating an [`InvoiceRequest`] and +/// enqueuing it to be sent via an onion message. [`ChannelManager`] will pay the actual +/// [`Bolt12Invoice`] once it is received. +/// +/// Uses [`InvoiceRequestBuilder`] such that the [`InvoiceRequest`] it builds is recognized by +/// the [`ChannelManager`] when handling a [`Bolt12Invoice`] message in response to the request. +/// The optional parameters are used in the builder, if `Some`: +/// - `quantity` for [`InvoiceRequest::quantity`] which must be set if +/// [`Offer::expects_quantity`] is `true`. +/// - `amount_msats` if overpaying what is required for the given `quantity` is desired, and +/// - `payer_note` for [`InvoiceRequest::payer_note`]. +/// +/// If `max_total_routing_fee_msat` is not specified, The default from +/// [`RouteParameters::from_payment_params_and_value`] is applied. +/// +/// # Payment +/// +/// The provided `payment_id` is used to ensure that only one invoice is paid for the request +/// when received. See [Avoiding Duplicate Payments] for other requirements once the payment has +/// been sent. +/// +/// To revoke the request, use [`ChannelManager::abandon_payment`] prior to receiving the +/// invoice. If abandoned, or an invoice isn't received in a reasonable amount of time, the +/// payment will fail with an [`Event::InvoiceRequestFailed`]. +/// +/// # Privacy +/// +/// Uses a one-hop [`BlindedPath`] for the reply path with [`ChannelManager::get_our_node_id`] +/// as the introduction node and a derived payer id for payer privacy. As such, currently, the +/// node must be announced. Otherwise, there is no way to find a path to the introduction node +/// in order to send the [`Bolt12Invoice`]. +/// +/// # Limitations +/// +/// Requires a direct connection to an introduction node in [`Offer::paths`] or to +/// [`Offer::signing_pubkey`], if empty. A similar restriction applies to the responding +/// [`Bolt12Invoice::payment_paths`]. +/// +/// # Errors +/// +/// Errors if a duplicate `payment_id` is provided given the caveats in the aforementioned link +/// or if the provided parameters are invalid for the offer. +/// +/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest +/// [`InvoiceRequest::quantity`]: crate::offers::invoice_request::InvoiceRequest::quantity +/// [`InvoiceRequest::payer_note`]: crate::offers::invoice_request::InvoiceRequest::payer_note +/// [`InvoiceRequestBuilder`]: crate::offers::invoice_request::InvoiceRequestBuilder +/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice +/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths +/// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments +#[must_use] +#[no_mangle] +pub extern "C" fn ChannelManager_pay_for_offer(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, offer: &crate::lightning::offers::offer::Offer, mut quantity: crate::c_types::derived::COption_u64Z, mut amount_msats: crate::c_types::derived::COption_u64Z, mut payer_note: crate::c_types::derived::COption_StrZ, mut payment_id: crate::c_types::ThirtyTwoBytes, mut retry_strategy: crate::lightning::ln::outbound_payment::Retry, mut max_total_routing_fee_msat: crate::c_types::derived::COption_u64Z) -> crate::c_types::derived::CResult_NoneBolt12SemanticErrorZ { + let mut local_quantity = if quantity.is_some() { Some( { quantity.take() }) } else { None }; + let mut local_amount_msats = if amount_msats.is_some() { Some( { amount_msats.take() }) } else { None }; + let mut local_payer_note = { /*payer_note*/ let payer_note_opt = payer_note; if payer_note_opt.is_none() { None } else { Some({ { { payer_note_opt.take() }.into_string() }})} }; + let mut local_max_total_routing_fee_msat = if max_total_routing_fee_msat.is_some() { Some( { max_total_routing_fee_msat.take() }) } else { None }; + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.pay_for_offer(offer.get_native_ref(), local_quantity, local_amount_msats, local_payer_note, ::lightning::ln::channelmanager::PaymentId(payment_id.data), retry_strategy.into_native(), local_max_total_routing_fee_msat); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::offers::parse::Bolt12SemanticError::native_into(e) }).into() }; + local_ret +} + +/// Creates a [`Bolt12Invoice`] for a [`Refund`] and enqueues it to be sent via an onion +/// message. +/// +/// The resulting invoice uses a [`PaymentHash`] recognized by the [`ChannelManager`] and a +/// [`BlindedPath`] containing the [`PaymentSecret`] needed to reconstruct the corresponding +/// [`PaymentPreimage`]. +/// +/// # Limitations +/// +/// Requires a direct connection to an introduction node in [`Refund::paths`] or to +/// [`Refund::payer_id`], if empty. This request is best effort; an invoice will be sent to each +/// node meeting the aforementioned criteria, but there's no guarantee that they will be +/// received and no retries will be made. +/// +/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice +#[must_use] +#[no_mangle] +pub extern "C" fn ChannelManager_request_refund_payment(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, refund: &crate::lightning::offers::refund::Refund) -> crate::c_types::derived::CResult_NoneBolt12SemanticErrorZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.request_refund_payment(refund.get_native_ref()); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::offers::parse::Bolt12SemanticError::native_into(e) }).into() }; + local_ret +} + /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing /// to pay us. /// @@ -2751,10 +2879,10 @@ pub extern "C" fn ChannelManager_compute_inflight_htlcs(this_arg: &crate::lightn impl From for crate::lightning::events::MessageSendEventsProvider { fn from(obj: nativeChannelManager) -> Self { - let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = ChannelManager_as_MessageSendEventsProvider(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(ChannelManager_free_void); ret } @@ -2779,10 +2907,10 @@ extern "C" fn ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg impl From for crate::lightning::events::EventsProvider { fn from(obj: nativeChannelManager) -> Self { - let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = ChannelManager_as_EventsProvider(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(ChannelManager_free_void); ret } @@ -2804,10 +2932,10 @@ extern "C" fn ChannelManager_EventsProvider_process_pending_events(this_arg: *co impl From for crate::lightning::chain::Listen { fn from(obj: nativeChannelManager) -> Self { - let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = ChannelManager_as_Listen(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(ChannelManager_free_void); ret } @@ -2838,10 +2966,10 @@ extern "C" fn ChannelManager_Listen_block_disconnected(this_arg: *const c_void, impl From for crate::lightning::chain::Confirm { fn from(obj: nativeChannelManager) -> Self { - let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = ChannelManager_as_Confirm(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(ChannelManager_free_void); ret } @@ -2909,7 +3037,7 @@ pub extern "C" fn ChannelManager_current_best_block(this_arg: &crate::lightning: crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true } } -/// Fetches the set of [`NodeFeatures`] flags which are provided by or required by +/// Fetches the set of [`NodeFeatures`] flags that are provided by or required by /// [`ChannelManager`]. #[must_use] #[no_mangle] @@ -2918,7 +3046,7 @@ pub extern "C" fn ChannelManager_node_features(this_arg: &crate::lightning::ln:: crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true } } -/// Fetches the set of [`ChannelFeatures`] flags which are provided by or required by +/// Fetches the set of [`ChannelFeatures`] flags that are provided by or required by /// [`ChannelManager`]. #[must_use] #[no_mangle] @@ -2927,7 +3055,7 @@ pub extern "C" fn ChannelManager_channel_features(this_arg: &crate::lightning::l crate::lightning::ln::features::ChannelFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true } } -/// Fetches the set of [`ChannelTypeFeatures`] flags which are provided by or required by +/// Fetches the set of [`ChannelTypeFeatures`] flags that are provided by or required by /// [`ChannelManager`]. #[must_use] #[no_mangle] @@ -2936,7 +3064,7 @@ pub extern "C" fn ChannelManager_channel_type_features(this_arg: &crate::lightni crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true } } -/// Fetches the set of [`InitFeatures`] flags which are provided by or required by +/// Fetches the set of [`InitFeatures`] flags that are provided by or required by /// [`ChannelManager`]. #[must_use] #[no_mangle] @@ -2947,10 +3075,10 @@ pub extern "C" fn ChannelManager_init_features(this_arg: &crate::lightning::ln:: impl From for crate::lightning::ln::msgs::ChannelMessageHandler { fn from(obj: nativeChannelManager) -> Self { - let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = ChannelManager_as_ChannelMessageHandler(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(ChannelManager_free_void); ret } @@ -2995,7 +3123,7 @@ pub extern "C" fn ChannelManager_as_ChannelMessageHandler(this_arg: &ChannelMana handle_error: ChannelManager_ChannelMessageHandler_handle_error, provided_node_features: ChannelManager_ChannelMessageHandler_provided_node_features, provided_init_features: ChannelManager_ChannelMessageHandler_provided_init_features, - get_genesis_hashes: ChannelManager_ChannelMessageHandler_get_genesis_hashes, + get_chain_hashes: ChannelManager_ChannelMessageHandler_get_chain_hashes, MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider { this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, free: None, @@ -3111,13 +3239,48 @@ extern "C" fn ChannelManager_ChannelMessageHandler_provided_init_features(this_a crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true } } #[must_use] -extern "C" fn ChannelManager_ChannelMessageHandler_get_genesis_hashes(this_arg: *const c_void) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ { - let mut ret = >::get_genesis_hashes(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, ); +extern "C" fn ChannelManager_ChannelMessageHandler_get_chain_hashes(this_arg: *const c_void) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ { + let mut ret = >::get_chain_hashes(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, ); let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::None } else { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::Some( { let mut local_ret_0 = Vec::new(); for mut item in ret.unwrap().drain(..) { local_ret_0.push( { crate::c_types::ThirtyTwoBytes { data: item.to_bytes() } }); }; local_ret_0.into() }) }; local_ret } -/// Fetches the set of [`InitFeatures`] flags which are provided by or required by +impl From for crate::lightning::onion_message::offers::OffersMessageHandler { + fn from(obj: nativeChannelManager) -> Self { + let rust_obj = crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let mut ret = ChannelManager_as_OffersMessageHandler(&rust_obj); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); + ret.free = Some(ChannelManager_free_void); + ret + } +} +/// Constructs a new OffersMessageHandler which calls the relevant methods on this_arg. +/// This copies the `inner` pointer in this_arg and thus the returned OffersMessageHandler must be freed before this_arg is +#[no_mangle] +pub extern "C" fn ChannelManager_as_OffersMessageHandler(this_arg: &ChannelManager) -> crate::lightning::onion_message::offers::OffersMessageHandler { + crate::lightning::onion_message::offers::OffersMessageHandler { + this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, + free: None, + handle_message: ChannelManager_OffersMessageHandler_handle_message, + release_pending_messages: ChannelManager_OffersMessageHandler_release_pending_messages, + } +} + +#[must_use] +extern "C" fn ChannelManager_OffersMessageHandler_handle_message(this_arg: *const c_void, mut message: crate::lightning::onion_message::offers::OffersMessage) -> crate::c_types::derived::COption_OffersMessageZ { + let mut ret = >::handle_message(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, message.into_native()); + let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_OffersMessageZ::None } else { crate::c_types::derived::COption_OffersMessageZ::Some( { crate::lightning::onion_message::offers::OffersMessage::native_into(ret.unwrap()) }) }; + local_ret +} +#[must_use] +extern "C" fn ChannelManager_OffersMessageHandler_release_pending_messages(this_arg: *const c_void) -> crate::c_types::derived::CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ { + let mut ret = >::release_pending_messages(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, ); + let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item; let mut local_orig_ret_0_2 = crate::lightning::blinded_path::BlindedPath { inner: if orig_ret_0_2.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((orig_ret_0_2.unwrap())) } }, is_owned: true }; let mut local_ret_0 = (crate::lightning::onion_message::offers::OffersMessage::native_into(orig_ret_0_0), crate::lightning::onion_message::messenger::Destination::native_into(orig_ret_0_1), local_orig_ret_0_2).into(); local_ret_0 }); }; + local_ret.into() +} + +/// Fetches the set of [`InitFeatures`] flags that are provided by or required by /// [`ChannelManager`]. #[no_mangle] pub extern "C" fn provided_init_features(config: &crate::lightning::util::config::UserConfig) -> crate::lightning::ln::features::InitFeatures { @@ -3130,7 +3293,7 @@ pub extern "C" fn provided_init_features(config: &crate::lightning::util::config pub extern "C" fn CounterpartyForwardingInfo_write(obj: &crate::lightning::ln::channelmanager::CounterpartyForwardingInfo) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn CounterpartyForwardingInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCounterpartyForwardingInfo) }) } @@ -3146,7 +3309,7 @@ pub extern "C" fn CounterpartyForwardingInfo_read(ser: crate::c_types::u8slice) pub extern "C" fn ChannelCounterparty_write(obj: &crate::lightning::ln::channelmanager::ChannelCounterparty) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelCounterparty_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelCounterparty) }) } @@ -3162,7 +3325,7 @@ pub extern "C" fn ChannelCounterparty_read(ser: crate::c_types::u8slice) -> crat pub extern "C" fn ChannelDetails_write(obj: &crate::lightning::ln::channelmanager::ChannelDetails) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelDetails_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelDetails) }) } @@ -3178,7 +3341,7 @@ pub extern "C" fn ChannelDetails_read(ser: crate::c_types::u8slice) -> crate::c_ pub extern "C" fn PhantomRouteHints_write(obj: &crate::lightning::ln::channelmanager::PhantomRouteHints) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn PhantomRouteHints_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePhantomRouteHints) }) } @@ -3194,7 +3357,7 @@ pub extern "C" fn PhantomRouteHints_read(ser: crate::c_types::u8slice) -> crate: pub extern "C" fn ChannelManager_write(obj: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelManager_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelManager) }) } @@ -3203,6 +3366,10 @@ pub(crate) extern "C" fn ChannelManager_write_void(obj: *const c_void) -> crate: pub extern "C" fn ChannelShutdownState_write(obj: &crate::lightning::ln::channelmanager::ChannelShutdownState) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) } +#[allow(unused)] +pub(crate) extern "C" fn ChannelShutdownState_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + ChannelShutdownState_write(unsafe { &*(obj as *const ChannelShutdownState) }) +} #[no_mangle] /// Read a ChannelShutdownState from a byte array, created by ChannelShutdownState_write pub extern "C" fn ChannelShutdownState_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelShutdownStateDecodeErrorZ { diff --git a/lightning-c-bindings/src/lightning/ln/features.rs b/lightning-c-bindings/src/lightning/ln/features.rs index f3f46a7..ff4e66d 100644 --- a/lightning-c-bindings/src/lightning/ln/features.rs +++ b/lightning-c-bindings/src/lightning/ln/features.rs @@ -1438,7 +1438,7 @@ impl Clone for InitFeatures { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn InitFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInitFeatures)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeInitFeatures)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the InitFeatures @@ -1457,7 +1457,7 @@ impl Clone for NodeFeatures { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn NodeFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeFeatures)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeNodeFeatures)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the NodeFeatures @@ -1476,7 +1476,7 @@ impl Clone for ChannelFeatures { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelFeatures)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelFeatures)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelFeatures @@ -1495,7 +1495,7 @@ impl Clone for Bolt11InvoiceFeatures { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Bolt11InvoiceFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBolt11InvoiceFeatures)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBolt11InvoiceFeatures)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Bolt11InvoiceFeatures @@ -1514,7 +1514,7 @@ impl Clone for OfferFeatures { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn OfferFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeOfferFeatures)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeOfferFeatures)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the OfferFeatures @@ -1533,7 +1533,7 @@ impl Clone for InvoiceRequestFeatures { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn InvoiceRequestFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceRequestFeatures)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeInvoiceRequestFeatures)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the InvoiceRequestFeatures @@ -1552,7 +1552,7 @@ impl Clone for Bolt12InvoiceFeatures { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Bolt12InvoiceFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBolt12InvoiceFeatures)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBolt12InvoiceFeatures)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Bolt12InvoiceFeatures @@ -1571,7 +1571,7 @@ impl Clone for BlindedHopFeatures { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn BlindedHopFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBlindedHopFeatures)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBlindedHopFeatures)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the BlindedHopFeatures @@ -1590,7 +1590,7 @@ impl Clone for ChannelTypeFeatures { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelTypeFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelTypeFeatures)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelTypeFeatures)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelTypeFeatures @@ -2835,7 +2835,7 @@ pub extern "C" fn ChannelTypeFeatures_set_optional_custom_bit(this_arg: &mut cra pub extern "C" fn InitFeatures_write(obj: &crate::lightning::ln::features::InitFeatures) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn InitFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInitFeatures) }) } @@ -2851,7 +2851,7 @@ pub extern "C" fn InitFeatures_read(ser: crate::c_types::u8slice) -> crate::c_ty pub extern "C" fn ChannelFeatures_write(obj: &crate::lightning::ln::features::ChannelFeatures) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelFeatures) }) } @@ -2867,7 +2867,7 @@ pub extern "C" fn ChannelFeatures_read(ser: crate::c_types::u8slice) -> crate::c pub extern "C" fn NodeFeatures_write(obj: &crate::lightning::ln::features::NodeFeatures) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn NodeFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeFeatures) }) } @@ -2883,7 +2883,7 @@ pub extern "C" fn NodeFeatures_read(ser: crate::c_types::u8slice) -> crate::c_ty pub extern "C" fn Bolt11InvoiceFeatures_write(obj: &crate::lightning::ln::features::Bolt11InvoiceFeatures) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn Bolt11InvoiceFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBolt11InvoiceFeatures) }) } @@ -2899,7 +2899,7 @@ pub extern "C" fn Bolt11InvoiceFeatures_read(ser: crate::c_types::u8slice) -> cr pub extern "C" fn Bolt12InvoiceFeatures_write(obj: &crate::lightning::ln::features::Bolt12InvoiceFeatures) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn Bolt12InvoiceFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBolt12InvoiceFeatures) }) } @@ -2915,7 +2915,7 @@ pub extern "C" fn Bolt12InvoiceFeatures_read(ser: crate::c_types::u8slice) -> cr pub extern "C" fn BlindedHopFeatures_write(obj: &crate::lightning::ln::features::BlindedHopFeatures) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn BlindedHopFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBlindedHopFeatures) }) } @@ -2931,7 +2931,7 @@ pub extern "C" fn BlindedHopFeatures_read(ser: crate::c_types::u8slice) -> crate pub extern "C" fn ChannelTypeFeatures_write(obj: &crate::lightning::ln::features::ChannelTypeFeatures) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelTypeFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelTypeFeatures) }) } diff --git a/lightning-c-bindings/src/lightning/ln/msgs.rs b/lightning-c-bindings/src/lightning/ln/msgs.rs index dbc2397..a28511b 100644 --- a/lightning-c-bindings/src/lightning/ln/msgs.rs +++ b/lightning-c-bindings/src/lightning/ln/msgs.rs @@ -138,6 +138,16 @@ pub extern "C" fn DecodeError_free(this_ptr: DecodeError) { } pub extern "C" fn DecodeError_clone(orig: &DecodeError) -> DecodeError { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn DecodeError_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const DecodeError)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn DecodeError_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut DecodeError) }; +} #[no_mangle] /// Utility method to constructs a new UnknownVersion-variant DecodeError pub extern "C" fn DecodeError_unknown_version() -> DecodeError { @@ -303,7 +313,7 @@ impl Clone for Init { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Init_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInit)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeInit)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Init @@ -429,7 +439,7 @@ impl Clone for ErrorMessage { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ErrorMessage_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeErrorMessage)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeErrorMessage)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ErrorMessage @@ -553,7 +563,7 @@ impl Clone for WarningMessage { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn WarningMessage_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeWarningMessage)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeWarningMessage)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the WarningMessage @@ -669,7 +679,7 @@ impl Clone for Ping { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Ping_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePing)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePing)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Ping @@ -773,7 +783,7 @@ impl Clone for Pong { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Pong_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePong)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePong)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Pong @@ -848,12 +858,12 @@ impl OpenChannel { #[no_mangle] pub extern "C" fn OpenChannel_get_chain_hash(this_ptr: &OpenChannel) -> *const [u8; 32] { let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_hash; - inner_val.as_inner() + inner_val.as_bytes() } /// The genesis hash of the blockchain where the channel is to be opened #[no_mangle] pub extern "C" fn OpenChannel_set_chain_hash(this_ptr: &mut OpenChannel, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::blockdata::constants::ChainHash::from(&val.data[..]); } /// A temporary channel ID, until the funding outpoint is announced #[no_mangle] @@ -1091,7 +1101,7 @@ pub extern "C" fn OpenChannel_new(mut chain_hash_arg: crate::c_types::ThirtyTwoB let mut local_shutdown_scriptpubkey_arg = { /*shutdown_scriptpubkey_arg*/ let shutdown_scriptpubkey_arg_opt = shutdown_scriptpubkey_arg; if shutdown_scriptpubkey_arg_opt.is_none() { None } else { Some({ { ::bitcoin::blockdata::script::Script::from({ shutdown_scriptpubkey_arg_opt.take() }.into_rust()) }})} }; let mut local_channel_type_arg = if channel_type_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(channel_type_arg.take_inner()) } }) }; OpenChannel { inner: ObjOps::heap_alloc(nativeOpenChannel { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), + chain_hash: ::bitcoin::blockdata::constants::ChainHash::from(&chain_hash_arg.data[..]), temporary_channel_id: ::lightning::ln::ChannelId(temporary_channel_id_arg.data), funding_satoshis: funding_satoshis_arg, push_msat: push_msat_arg, @@ -1125,7 +1135,7 @@ impl Clone for OpenChannel { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn OpenChannel_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeOpenChannel)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeOpenChannel)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the OpenChannel @@ -1199,12 +1209,12 @@ impl OpenChannelV2 { #[no_mangle] pub extern "C" fn OpenChannelV2_get_chain_hash(this_ptr: &OpenChannelV2) -> *const [u8; 32] { let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_hash; - inner_val.as_inner() + inner_val.as_bytes() } /// The genesis hash of the blockchain where the channel is to be opened #[no_mangle] pub extern "C" fn OpenChannelV2_set_chain_hash(this_ptr: &mut OpenChannelV2, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::blockdata::constants::ChainHash::from(&val.data[..]); } /// A temporary channel ID derived using a zeroed out value for the channel acceptor's revocation basepoint #[no_mangle] @@ -1469,7 +1479,7 @@ pub extern "C" fn OpenChannelV2_new(mut chain_hash_arg: crate::c_types::ThirtyTw let mut local_channel_type_arg = if channel_type_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(channel_type_arg.take_inner()) } }) }; let mut local_require_confirmed_inputs_arg = if require_confirmed_inputs_arg.is_some() { Some( { () /*require_confirmed_inputs_arg.take()*/ }) } else { None }; OpenChannelV2 { inner: ObjOps::heap_alloc(nativeOpenChannelV2 { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), + chain_hash: ::bitcoin::blockdata::constants::ChainHash::from(&chain_hash_arg.data[..]), temporary_channel_id: ::lightning::ln::ChannelId(temporary_channel_id_arg.data), funding_feerate_sat_per_1000_weight: funding_feerate_sat_per_1000_weight_arg, commitment_feerate_sat_per_1000_weight: commitment_feerate_sat_per_1000_weight_arg, @@ -1505,7 +1515,7 @@ impl Clone for OpenChannelV2 { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn OpenChannelV2_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeOpenChannelV2)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeOpenChannelV2)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the OpenChannelV2 @@ -1807,7 +1817,7 @@ impl Clone for AcceptChannel { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn AcceptChannel_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeAcceptChannel)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeAcceptChannel)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the AcceptChannel @@ -2143,7 +2153,7 @@ impl Clone for AcceptChannelV2 { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn AcceptChannelV2_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeAcceptChannelV2)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeAcceptChannelV2)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the AcceptChannelV2 @@ -2281,7 +2291,7 @@ impl Clone for FundingCreated { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn FundingCreated_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeFundingCreated)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeFundingCreated)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the FundingCreated @@ -2395,7 +2405,7 @@ impl Clone for FundingSigned { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn FundingSigned_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeFundingSigned)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeFundingSigned)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the FundingSigned @@ -2528,7 +2538,7 @@ impl Clone for ChannelReady { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelReady_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelReady)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelReady)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelReady @@ -2679,7 +2689,7 @@ impl Clone for TxAddInput { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TxAddInput_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxAddInput)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTxAddInput)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TxAddInput @@ -2816,7 +2826,7 @@ impl Clone for TxAddOutput { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TxAddOutput_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxAddOutput)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTxAddOutput)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TxAddOutput @@ -2927,7 +2937,7 @@ impl Clone for TxRemoveInput { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TxRemoveInput_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxRemoveInput)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTxRemoveInput)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TxRemoveInput @@ -3038,7 +3048,7 @@ impl Clone for TxRemoveOutput { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TxRemoveOutput_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxRemoveOutput)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTxRemoveOutput)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TxRemoveOutput @@ -3138,7 +3148,7 @@ impl Clone for TxComplete { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TxComplete_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxComplete)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTxComplete)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TxComplete @@ -3267,7 +3277,7 @@ impl Clone for TxSignatures { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TxSignatures_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxSignatures)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTxSignatures)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TxSignatures @@ -3408,7 +3418,7 @@ impl Clone for TxInitRbf { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TxInitRbf_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxInitRbf)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTxInitRbf)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TxInitRbf @@ -3525,7 +3535,7 @@ impl Clone for TxAckRbf { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TxAckRbf_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxAckRbf)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTxAckRbf)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TxAckRbf @@ -3641,7 +3651,7 @@ impl Clone for TxAbort { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TxAbort_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxAbort)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTxAbort)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TxAbort @@ -3757,7 +3767,7 @@ impl Clone for Shutdown { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Shutdown_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeShutdown)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeShutdown)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Shutdown @@ -3874,7 +3884,7 @@ impl Clone for ClosingSignedFeeRange { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ClosingSignedFeeRange_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeClosingSignedFeeRange)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeClosingSignedFeeRange)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ClosingSignedFeeRange @@ -4021,7 +4031,7 @@ impl Clone for ClosingSigned { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ClosingSigned_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeClosingSigned)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeClosingSigned)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ClosingSigned @@ -4176,7 +4186,7 @@ impl Clone for UpdateAddHTLC { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UpdateAddHTLC_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUpdateAddHTLC)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUpdateAddHTLC)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the UpdateAddHTLC @@ -4287,7 +4297,7 @@ impl Clone for OnionMessage { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn OnionMessage_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeOnionMessage)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeOnionMessage)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the OnionMessage @@ -4411,7 +4421,7 @@ impl Clone for UpdateFulfillHTLC { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UpdateFulfillHTLC_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUpdateFulfillHTLC)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUpdateFulfillHTLC)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the UpdateFulfillHTLC @@ -4514,7 +4524,7 @@ impl Clone for UpdateFailHTLC { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UpdateFailHTLC_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUpdateFailHTLC)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUpdateFailHTLC)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the UpdateFailHTLC @@ -4628,7 +4638,7 @@ impl Clone for UpdateFailMalformedHTLC { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UpdateFailMalformedHTLC_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUpdateFailMalformedHTLC)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUpdateFailMalformedHTLC)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the UpdateFailMalformedHTLC @@ -4757,7 +4767,7 @@ impl Clone for CommitmentSigned { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn CommitmentSigned_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCommitmentSigned)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeCommitmentSigned)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the CommitmentSigned @@ -4881,7 +4891,7 @@ impl Clone for RevokeAndACK { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn RevokeAndACK_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRevokeAndACK)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRevokeAndACK)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the RevokeAndACK @@ -4993,7 +5003,7 @@ impl Clone for UpdateFee { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UpdateFee_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUpdateFee)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUpdateFee)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the UpdateFee @@ -5158,7 +5168,7 @@ impl Clone for ChannelReestablish { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelReestablish_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelReestablish)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelReestablish)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelReestablish @@ -5294,7 +5304,7 @@ impl Clone for AnnouncementSignatures { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn AnnouncementSignatures_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeAnnouncementSignatures)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeAnnouncementSignatures)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the AnnouncementSignatures @@ -5536,6 +5546,16 @@ pub extern "C" fn SocketAddress_free(this_ptr: SocketAddress) { } pub extern "C" fn SocketAddress_clone(orig: &SocketAddress) -> SocketAddress { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn SocketAddress_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const SocketAddress)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn SocketAddress_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut SocketAddress) }; +} #[no_mangle] /// Utility method to constructs a new TcpIpV4-variant SocketAddress pub extern "C" fn SocketAddress_tcp_ip_v4(addr: crate::c_types::FourBytes, port: u16) -> SocketAddress { @@ -5586,6 +5606,10 @@ pub extern "C" fn SocketAddress_eq(a: &SocketAddress, b: &SocketAddress) -> bool pub extern "C" fn SocketAddress_write(obj: &crate::lightning::ln::msgs::SocketAddress) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) } +#[allow(unused)] +pub(crate) extern "C" fn SocketAddress_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + SocketAddress_write(unsafe { &*(obj as *const SocketAddress) }) +} #[no_mangle] /// Read a SocketAddress from a byte array, created by SocketAddress_write pub extern "C" fn SocketAddress_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SocketAddressDecodeErrorZ { @@ -5653,6 +5677,16 @@ impl SocketAddressParseError { pub extern "C" fn SocketAddressParseError_clone(orig: &SocketAddressParseError) -> SocketAddressParseError { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn SocketAddressParseError_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const SocketAddressParseError)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn SocketAddressParseError_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut SocketAddressParseError) }; +} #[no_mangle] /// Utility method to constructs a new SocketAddrParse-variant SocketAddressParseError pub extern "C" fn SocketAddressParseError_socket_addr_parse() -> SocketAddressParseError { @@ -5685,6 +5719,11 @@ pub extern "C" fn parse_onion_address(mut host: crate::c_types::Str, mut port: u local_ret } +#[no_mangle] +/// Get the string representation of a SocketAddress object +pub extern "C" fn SocketAddress_to_str(o: &crate::lightning::ln::msgs::SocketAddress) -> Str { + alloc::format!("{}", &o.to_native()).into() +} #[no_mangle] /// Read a SocketAddress object from a string pub extern "C" fn SocketAddress_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SocketAddressSocketAddressParseErrorZ { @@ -5815,6 +5854,16 @@ pub extern "C" fn UnsignedGossipMessage_free(this_ptr: UnsignedGossipMessage) { pub extern "C" fn UnsignedGossipMessage_clone(orig: &UnsignedGossipMessage) -> UnsignedGossipMessage { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn UnsignedGossipMessage_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const UnsignedGossipMessage)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn UnsignedGossipMessage_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut UnsignedGossipMessage) }; +} #[no_mangle] /// Utility method to constructs a new ChannelAnnouncement-variant UnsignedGossipMessage pub extern "C" fn UnsignedGossipMessage_channel_announcement(a: crate::lightning::ln::msgs::UnsignedChannelAnnouncement) -> UnsignedGossipMessage { @@ -5835,6 +5884,10 @@ pub extern "C" fn UnsignedGossipMessage_node_announcement(a: crate::lightning::l pub extern "C" fn UnsignedGossipMessage_write(obj: &crate::lightning::ln::msgs::UnsignedGossipMessage) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) } +#[allow(unused)] +pub(crate) extern "C" fn UnsignedGossipMessage_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + UnsignedGossipMessage_write(unsafe { &*(obj as *const UnsignedGossipMessage) }) +} use lightning::ln::msgs::UnsignedNodeAnnouncement as nativeUnsignedNodeAnnouncementImport; pub(crate) type nativeUnsignedNodeAnnouncement = nativeUnsignedNodeAnnouncementImport; @@ -5976,7 +6029,7 @@ impl Clone for UnsignedNodeAnnouncement { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UnsignedNodeAnnouncement_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUnsignedNodeAnnouncement)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUnsignedNodeAnnouncement)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the UnsignedNodeAnnouncement @@ -6088,7 +6141,7 @@ impl Clone for NodeAnnouncement { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn NodeAnnouncement_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncement)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeNodeAnnouncement)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the NodeAnnouncement @@ -6172,12 +6225,12 @@ pub extern "C" fn UnsignedChannelAnnouncement_set_features(this_ptr: &mut Unsign #[no_mangle] pub extern "C" fn UnsignedChannelAnnouncement_get_chain_hash(this_ptr: &UnsignedChannelAnnouncement) -> *const [u8; 32] { let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_hash; - inner_val.as_inner() + inner_val.as_bytes() } /// The genesis hash of the blockchain where the channel is to be opened #[no_mangle] pub extern "C" fn UnsignedChannelAnnouncement_set_chain_hash(this_ptr: &mut UnsignedChannelAnnouncement, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::blockdata::constants::ChainHash::from(&val.data[..]); } /// The short channel ID #[no_mangle] @@ -6262,7 +6315,7 @@ pub extern "C" fn UnsignedChannelAnnouncement_new(mut features_arg: crate::light let mut local_excess_data_arg = Vec::new(); for mut item in excess_data_arg.into_rust().drain(..) { local_excess_data_arg.push( { item }); }; UnsignedChannelAnnouncement { inner: ObjOps::heap_alloc(nativeUnsignedChannelAnnouncement { features: *unsafe { Box::from_raw(features_arg.take_inner()) }, - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), + chain_hash: ::bitcoin::blockdata::constants::ChainHash::from(&chain_hash_arg.data[..]), short_channel_id: short_channel_id_arg, node_id_1: *unsafe { Box::from_raw(node_id_1_arg.take_inner()) }, node_id_2: *unsafe { Box::from_raw(node_id_2_arg.take_inner()) }, @@ -6283,7 +6336,7 @@ impl Clone for UnsignedChannelAnnouncement { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UnsignedChannelAnnouncement_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUnsignedChannelAnnouncement)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUnsignedChannelAnnouncement)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the UnsignedChannelAnnouncement @@ -6431,7 +6484,7 @@ impl Clone for ChannelAnnouncement { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelAnnouncement_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelAnnouncement)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelAnnouncement)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelAnnouncement @@ -6504,12 +6557,12 @@ impl UnsignedChannelUpdate { #[no_mangle] pub extern "C" fn UnsignedChannelUpdate_get_chain_hash(this_ptr: &UnsignedChannelUpdate) -> *const [u8; 32] { let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_hash; - inner_val.as_inner() + inner_val.as_bytes() } /// The genesis hash of the blockchain where the channel is to be opened #[no_mangle] pub extern "C" fn UnsignedChannelUpdate_set_chain_hash(this_ptr: &mut UnsignedChannelUpdate, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::blockdata::constants::ChainHash::from(&val.data[..]); } /// The short channel ID #[no_mangle] @@ -6644,7 +6697,7 @@ pub extern "C" fn UnsignedChannelUpdate_set_excess_data(this_ptr: &mut UnsignedC pub extern "C" fn UnsignedChannelUpdate_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut short_channel_id_arg: u64, mut timestamp_arg: u32, mut flags_arg: u8, mut cltv_expiry_delta_arg: u16, mut htlc_minimum_msat_arg: u64, mut htlc_maximum_msat_arg: u64, mut fee_base_msat_arg: u32, mut fee_proportional_millionths_arg: u32, mut excess_data_arg: crate::c_types::derived::CVec_u8Z) -> UnsignedChannelUpdate { let mut local_excess_data_arg = Vec::new(); for mut item in excess_data_arg.into_rust().drain(..) { local_excess_data_arg.push( { item }); }; UnsignedChannelUpdate { inner: ObjOps::heap_alloc(nativeUnsignedChannelUpdate { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), + chain_hash: ::bitcoin::blockdata::constants::ChainHash::from(&chain_hash_arg.data[..]), short_channel_id: short_channel_id_arg, timestamp: timestamp_arg, flags: flags_arg, @@ -6668,7 +6721,7 @@ impl Clone for UnsignedChannelUpdate { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UnsignedChannelUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUnsignedChannelUpdate)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUnsignedChannelUpdate)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the UnsignedChannelUpdate @@ -6780,7 +6833,7 @@ impl Clone for ChannelUpdate { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelUpdate)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelUpdate)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelUpdate @@ -6856,12 +6909,12 @@ impl QueryChannelRange { #[no_mangle] pub extern "C" fn QueryChannelRange_get_chain_hash(this_ptr: &QueryChannelRange) -> *const [u8; 32] { let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_hash; - inner_val.as_inner() + inner_val.as_bytes() } /// The genesis hash of the blockchain being queried #[no_mangle] pub extern "C" fn QueryChannelRange_set_chain_hash(this_ptr: &mut QueryChannelRange, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::blockdata::constants::ChainHash::from(&val.data[..]); } /// The height of the first block for the channel UTXOs being queried #[no_mangle] @@ -6890,7 +6943,7 @@ pub extern "C" fn QueryChannelRange_set_number_of_blocks(this_ptr: &mut QueryCha #[no_mangle] pub extern "C" fn QueryChannelRange_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut first_blocknum_arg: u32, mut number_of_blocks_arg: u32) -> QueryChannelRange { QueryChannelRange { inner: ObjOps::heap_alloc(nativeQueryChannelRange { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), + chain_hash: ::bitcoin::blockdata::constants::ChainHash::from(&chain_hash_arg.data[..]), first_blocknum: first_blocknum_arg, number_of_blocks: number_of_blocks_arg, }), is_owned: true } @@ -6907,7 +6960,7 @@ impl Clone for QueryChannelRange { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn QueryChannelRange_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeQueryChannelRange)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeQueryChannelRange)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the QueryChannelRange @@ -6988,12 +7041,12 @@ impl ReplyChannelRange { #[no_mangle] pub extern "C" fn ReplyChannelRange_get_chain_hash(this_ptr: &ReplyChannelRange) -> *const [u8; 32] { let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_hash; - inner_val.as_inner() + inner_val.as_bytes() } /// The genesis hash of the blockchain being queried #[no_mangle] pub extern "C" fn ReplyChannelRange_set_chain_hash(this_ptr: &mut ReplyChannelRange, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::blockdata::constants::ChainHash::from(&val.data[..]); } /// The height of the first block in the range of the reply #[no_mangle] @@ -7049,7 +7102,7 @@ pub extern "C" fn ReplyChannelRange_set_short_channel_ids(this_ptr: &mut ReplyCh pub extern "C" fn ReplyChannelRange_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut first_blocknum_arg: u32, mut number_of_blocks_arg: u32, mut sync_complete_arg: bool, mut short_channel_ids_arg: crate::c_types::derived::CVec_u64Z) -> ReplyChannelRange { let mut local_short_channel_ids_arg = Vec::new(); for mut item in short_channel_ids_arg.into_rust().drain(..) { local_short_channel_ids_arg.push( { item }); }; ReplyChannelRange { inner: ObjOps::heap_alloc(nativeReplyChannelRange { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), + chain_hash: ::bitcoin::blockdata::constants::ChainHash::from(&chain_hash_arg.data[..]), first_blocknum: first_blocknum_arg, number_of_blocks: number_of_blocks_arg, sync_complete: sync_complete_arg, @@ -7068,7 +7121,7 @@ impl Clone for ReplyChannelRange { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ReplyChannelRange_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeReplyChannelRange)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeReplyChannelRange)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ReplyChannelRange @@ -7149,12 +7202,12 @@ impl QueryShortChannelIds { #[no_mangle] pub extern "C" fn QueryShortChannelIds_get_chain_hash(this_ptr: &QueryShortChannelIds) -> *const [u8; 32] { let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_hash; - inner_val.as_inner() + inner_val.as_bytes() } /// The genesis hash of the blockchain being queried #[no_mangle] pub extern "C" fn QueryShortChannelIds_set_chain_hash(this_ptr: &mut QueryShortChannelIds, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::blockdata::constants::ChainHash::from(&val.data[..]); } /// The short_channel_ids that are being queried /// @@ -7177,7 +7230,7 @@ pub extern "C" fn QueryShortChannelIds_set_short_channel_ids(this_ptr: &mut Quer pub extern "C" fn QueryShortChannelIds_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut short_channel_ids_arg: crate::c_types::derived::CVec_u64Z) -> QueryShortChannelIds { let mut local_short_channel_ids_arg = Vec::new(); for mut item in short_channel_ids_arg.into_rust().drain(..) { local_short_channel_ids_arg.push( { item }); }; QueryShortChannelIds { inner: ObjOps::heap_alloc(nativeQueryShortChannelIds { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), + chain_hash: ::bitcoin::blockdata::constants::ChainHash::from(&chain_hash_arg.data[..]), short_channel_ids: local_short_channel_ids_arg, }), is_owned: true } } @@ -7193,7 +7246,7 @@ impl Clone for QueryShortChannelIds { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn QueryShortChannelIds_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeQueryShortChannelIds)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeQueryShortChannelIds)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the QueryShortChannelIds @@ -7269,12 +7322,12 @@ impl ReplyShortChannelIdsEnd { #[no_mangle] pub extern "C" fn ReplyShortChannelIdsEnd_get_chain_hash(this_ptr: &ReplyShortChannelIdsEnd) -> *const [u8; 32] { let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_hash; - inner_val.as_inner() + inner_val.as_bytes() } /// The genesis hash of the blockchain that was queried #[no_mangle] pub extern "C" fn ReplyShortChannelIdsEnd_set_chain_hash(this_ptr: &mut ReplyShortChannelIdsEnd, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::blockdata::constants::ChainHash::from(&val.data[..]); } /// Indicates if the query recipient maintains up-to-date channel /// information for the `chain_hash` @@ -7294,7 +7347,7 @@ pub extern "C" fn ReplyShortChannelIdsEnd_set_full_information(this_ptr: &mut Re #[no_mangle] pub extern "C" fn ReplyShortChannelIdsEnd_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut full_information_arg: bool) -> ReplyShortChannelIdsEnd { ReplyShortChannelIdsEnd { inner: ObjOps::heap_alloc(nativeReplyShortChannelIdsEnd { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), + chain_hash: ::bitcoin::blockdata::constants::ChainHash::from(&chain_hash_arg.data[..]), full_information: full_information_arg, }), is_owned: true } } @@ -7310,7 +7363,7 @@ impl Clone for ReplyShortChannelIdsEnd { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ReplyShortChannelIdsEnd_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeReplyShortChannelIdsEnd)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeReplyShortChannelIdsEnd)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ReplyShortChannelIdsEnd @@ -7385,12 +7438,12 @@ impl GossipTimestampFilter { #[no_mangle] pub extern "C" fn GossipTimestampFilter_get_chain_hash(this_ptr: &GossipTimestampFilter) -> *const [u8; 32] { let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_hash; - inner_val.as_inner() + inner_val.as_bytes() } /// The genesis hash of the blockchain for channel and node information #[no_mangle] pub extern "C" fn GossipTimestampFilter_set_chain_hash(this_ptr: &mut GossipTimestampFilter, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::blockdata::constants::ChainHash::from(&val.data[..]); } /// The starting unix timestamp #[no_mangle] @@ -7419,7 +7472,7 @@ pub extern "C" fn GossipTimestampFilter_set_timestamp_range(this_ptr: &mut Gossi #[no_mangle] pub extern "C" fn GossipTimestampFilter_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut first_timestamp_arg: u32, mut timestamp_range_arg: u32) -> GossipTimestampFilter { GossipTimestampFilter { inner: ObjOps::heap_alloc(nativeGossipTimestampFilter { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), + chain_hash: ::bitcoin::blockdata::constants::ChainHash::from(&chain_hash_arg.data[..]), first_timestamp: first_timestamp_arg, timestamp_range: timestamp_range_arg, }), is_owned: true } @@ -7436,7 +7489,7 @@ impl Clone for GossipTimestampFilter { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn GossipTimestampFilter_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeGossipTimestampFilter)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeGossipTimestampFilter)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the GossipTimestampFilter @@ -7655,6 +7708,16 @@ pub extern "C" fn ErrorAction_free(this_ptr: ErrorAction) { } pub extern "C" fn ErrorAction_clone(orig: &ErrorAction) -> ErrorAction { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ErrorAction_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const ErrorAction)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ErrorAction_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut ErrorAction) }; +} #[no_mangle] /// Utility method to constructs a new DisconnectPeer-variant ErrorAction pub extern "C" fn ErrorAction_disconnect_peer(msg: crate::lightning::ln::msgs::ErrorMessage) -> ErrorAction { @@ -7791,7 +7854,7 @@ impl Clone for LightningError { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn LightningError_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeLightningError)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeLightningError)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the LightningError @@ -7962,7 +8025,7 @@ impl Clone for CommitmentUpdate { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn CommitmentUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCommitmentUpdate)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeCommitmentUpdate)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the CommitmentUpdate @@ -8063,11 +8126,11 @@ pub struct ChannelMessageHandler { /// /// Note that this method is called before [`Self::peer_connected`]. pub provided_init_features: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures, - /// Gets the genesis hashes for this `ChannelMessageHandler` indicating which chains it supports. + /// Gets the chain hashes for this `ChannelMessageHandler` indicating which chains it supports. /// /// If it's `None`, then no particular network chain hash compatibility will be enforced when /// connecting to peers. - pub get_genesis_hashes: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ, + pub get_chain_hashes: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ, /// Implementation of MessageSendEventsProvider for this object. pub MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider, /// Frees any resources associated with this object given its this_arg pointer. @@ -8076,6 +8139,7 @@ pub struct ChannelMessageHandler { } unsafe impl Send for ChannelMessageHandler {} unsafe impl Sync for ChannelMessageHandler {} +#[allow(unused)] pub(crate) fn ChannelMessageHandler_clone_fields(orig: &ChannelMessageHandler) -> ChannelMessageHandler { ChannelMessageHandler { this_arg: orig.this_arg, @@ -8112,7 +8176,7 @@ pub(crate) fn ChannelMessageHandler_clone_fields(orig: &ChannelMessageHandler) - handle_error: Clone::clone(&orig.handle_error), provided_node_features: Clone::clone(&orig.provided_node_features), provided_init_features: Clone::clone(&orig.provided_init_features), - get_genesis_hashes: Clone::clone(&orig.get_genesis_hashes), + get_chain_hashes: Clone::clone(&orig.get_chain_hashes), MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider_clone_fields(&orig.MessageSendEventsProvider), free: Clone::clone(&orig.free), } @@ -8230,8 +8294,8 @@ impl rustChannelMessageHandler for ChannelMessageHandler { let mut ret = (self.provided_init_features)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id)); *unsafe { Box::from_raw(ret.take_inner()) } } - fn get_genesis_hashes(&self) -> Option> { - let mut ret = (self.get_genesis_hashes)(self.this_arg); + fn get_chain_hashes(&self) -> Option> { + let mut ret = (self.get_chain_hashes)(self.this_arg); let mut local_ret = { /*ret*/ let ret_opt = ret; if ret_opt.is_none() { None } else { Some({ { let mut local_ret_0 = Vec::new(); for mut item in { ret_opt.take() }.into_rust().drain(..) { local_ret_0.push( { ::bitcoin::blockdata::constants::ChainHash::from(&item.data[..]) }); }; local_ret_0 }})} }; local_ret } @@ -8339,6 +8403,7 @@ pub struct RoutingMessageHandler { } unsafe impl Send for RoutingMessageHandler {} unsafe impl Sync for RoutingMessageHandler {} +#[allow(unused)] pub(crate) fn RoutingMessageHandler_clone_fields(orig: &RoutingMessageHandler) -> RoutingMessageHandler { RoutingMessageHandler { this_arg: orig.this_arg, @@ -8457,7 +8522,7 @@ impl Drop for RoutingMessageHandler { } } } -/// A trait to describe an object that can receive onion messages. +/// A handler for received [`OnionMessage`]s and for providing generated ones to send. #[repr(C)] pub struct OnionMessageHandler { /// An opaque pointer which is passed to your function implementations as an argument. @@ -8465,6 +8530,10 @@ pub struct OnionMessageHandler { pub this_arg: *mut c_void, /// Handle an incoming `onion_message` message from the given peer. pub handle_onion_message: extern "C" fn (this_arg: *const c_void, peer_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::OnionMessage), + /// Returns the next pending onion message for the peer with the given node id. + /// + /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None + pub next_onion_message_for_peer: extern "C" fn (this_arg: *const c_void, peer_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::msgs::OnionMessage, /// Called when a connection is established with a peer. Can be used to track which peers /// advertise onion message support and are online. /// @@ -8485,39 +8554,36 @@ pub struct OnionMessageHandler { /// /// Note that this method is called before [`Self::peer_connected`]. pub provided_init_features: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures, - /// Implementation of OnionMessageProvider for this object. - pub OnionMessageProvider: crate::lightning::events::OnionMessageProvider, /// Frees any resources associated with this object given its this_arg pointer. /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. pub free: Option, } unsafe impl Send for OnionMessageHandler {} unsafe impl Sync for OnionMessageHandler {} +#[allow(unused)] pub(crate) fn OnionMessageHandler_clone_fields(orig: &OnionMessageHandler) -> OnionMessageHandler { OnionMessageHandler { this_arg: orig.this_arg, handle_onion_message: Clone::clone(&orig.handle_onion_message), + next_onion_message_for_peer: Clone::clone(&orig.next_onion_message_for_peer), peer_connected: Clone::clone(&orig.peer_connected), peer_disconnected: Clone::clone(&orig.peer_disconnected), provided_node_features: Clone::clone(&orig.provided_node_features), provided_init_features: Clone::clone(&orig.provided_init_features), - OnionMessageProvider: crate::lightning::events::OnionMessageProvider_clone_fields(&orig.OnionMessageProvider), free: Clone::clone(&orig.free), } } -impl lightning::events::OnionMessageProvider for OnionMessageHandler { - fn next_onion_message_for_peer(&self, mut peer_node_id: bitcoin::secp256k1::PublicKey) -> Option { - let mut ret = (self.OnionMessageProvider.next_onion_message_for_peer)(self.OnionMessageProvider.this_arg, crate::c_types::PublicKey::from_rust(&peer_node_id)); - let mut local_ret = if ret.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(ret.take_inner()) } }) }; - local_ret - } -} use lightning::ln::msgs::OnionMessageHandler as rustOnionMessageHandler; impl rustOnionMessageHandler for OnionMessageHandler { fn handle_onion_message(&self, mut peer_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::OnionMessage) { (self.handle_onion_message)(self.this_arg, crate::c_types::PublicKey::from_rust(&peer_node_id), &crate::lightning::ln::msgs::OnionMessage { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::OnionMessage<>) as *mut _) }, is_owned: false }) } + fn next_onion_message_for_peer(&self, mut peer_node_id: bitcoin::secp256k1::PublicKey) -> Option { + let mut ret = (self.next_onion_message_for_peer)(self.this_arg, crate::c_types::PublicKey::from_rust(&peer_node_id)); + let mut local_ret = if ret.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(ret.take_inner()) } }) }; + local_ret + } fn peer_connected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut init: &lightning::ln::msgs::Init, mut inbound: bool) -> Result<(), ()> { let mut ret = (self.peer_connected)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::Init { inner: unsafe { ObjOps::nonnull_ptr_to_inner((init as *const lightning::ln::msgs::Init<>) as *mut _) }, is_owned: false }, inbound); let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; @@ -8576,7 +8642,7 @@ use alloc::{vec::Vec, boxed::Box}; pub extern "C" fn AcceptChannel_write(obj: &crate::lightning::ln::msgs::AcceptChannel) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn AcceptChannel_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeAcceptChannel) }) } @@ -8592,7 +8658,7 @@ pub extern "C" fn AcceptChannel_read(ser: crate::c_types::u8slice) -> crate::c_t pub extern "C" fn AcceptChannelV2_write(obj: &crate::lightning::ln::msgs::AcceptChannelV2) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn AcceptChannelV2_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeAcceptChannelV2) }) } @@ -8608,7 +8674,7 @@ pub extern "C" fn AcceptChannelV2_read(ser: crate::c_types::u8slice) -> crate::c pub extern "C" fn TxAddInput_write(obj: &crate::lightning::ln::msgs::TxAddInput) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TxAddInput_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxAddInput) }) } @@ -8624,7 +8690,7 @@ pub extern "C" fn TxAddInput_read(ser: crate::c_types::u8slice) -> crate::c_type pub extern "C" fn TxAddOutput_write(obj: &crate::lightning::ln::msgs::TxAddOutput) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TxAddOutput_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxAddOutput) }) } @@ -8640,7 +8706,7 @@ pub extern "C" fn TxAddOutput_read(ser: crate::c_types::u8slice) -> crate::c_typ pub extern "C" fn TxRemoveInput_write(obj: &crate::lightning::ln::msgs::TxRemoveInput) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TxRemoveInput_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxRemoveInput) }) } @@ -8656,7 +8722,7 @@ pub extern "C" fn TxRemoveInput_read(ser: crate::c_types::u8slice) -> crate::c_t pub extern "C" fn TxRemoveOutput_write(obj: &crate::lightning::ln::msgs::TxRemoveOutput) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TxRemoveOutput_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxRemoveOutput) }) } @@ -8672,7 +8738,7 @@ pub extern "C" fn TxRemoveOutput_read(ser: crate::c_types::u8slice) -> crate::c_ pub extern "C" fn TxComplete_write(obj: &crate::lightning::ln::msgs::TxComplete) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TxComplete_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxComplete) }) } @@ -8688,7 +8754,7 @@ pub extern "C" fn TxComplete_read(ser: crate::c_types::u8slice) -> crate::c_type pub extern "C" fn TxSignatures_write(obj: &crate::lightning::ln::msgs::TxSignatures) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TxSignatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxSignatures) }) } @@ -8704,7 +8770,7 @@ pub extern "C" fn TxSignatures_read(ser: crate::c_types::u8slice) -> crate::c_ty pub extern "C" fn TxInitRbf_write(obj: &crate::lightning::ln::msgs::TxInitRbf) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TxInitRbf_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxInitRbf) }) } @@ -8720,7 +8786,7 @@ pub extern "C" fn TxInitRbf_read(ser: crate::c_types::u8slice) -> crate::c_types pub extern "C" fn TxAckRbf_write(obj: &crate::lightning::ln::msgs::TxAckRbf) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TxAckRbf_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxAckRbf) }) } @@ -8736,7 +8802,7 @@ pub extern "C" fn TxAckRbf_read(ser: crate::c_types::u8slice) -> crate::c_types: pub extern "C" fn TxAbort_write(obj: &crate::lightning::ln::msgs::TxAbort) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TxAbort_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxAbort) }) } @@ -8752,7 +8818,7 @@ pub extern "C" fn TxAbort_read(ser: crate::c_types::u8slice) -> crate::c_types:: pub extern "C" fn AnnouncementSignatures_write(obj: &crate::lightning::ln::msgs::AnnouncementSignatures) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn AnnouncementSignatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeAnnouncementSignatures) }) } @@ -8768,7 +8834,7 @@ pub extern "C" fn AnnouncementSignatures_read(ser: crate::c_types::u8slice) -> c pub extern "C" fn ChannelReestablish_write(obj: &crate::lightning::ln::msgs::ChannelReestablish) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelReestablish_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelReestablish) }) } @@ -8784,7 +8850,7 @@ pub extern "C" fn ChannelReestablish_read(ser: crate::c_types::u8slice) -> crate pub extern "C" fn ClosingSigned_write(obj: &crate::lightning::ln::msgs::ClosingSigned) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ClosingSigned_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeClosingSigned) }) } @@ -8800,7 +8866,7 @@ pub extern "C" fn ClosingSigned_read(ser: crate::c_types::u8slice) -> crate::c_t pub extern "C" fn ClosingSignedFeeRange_write(obj: &crate::lightning::ln::msgs::ClosingSignedFeeRange) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ClosingSignedFeeRange_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeClosingSignedFeeRange) }) } @@ -8816,7 +8882,7 @@ pub extern "C" fn ClosingSignedFeeRange_read(ser: crate::c_types::u8slice) -> cr pub extern "C" fn CommitmentSigned_write(obj: &crate::lightning::ln::msgs::CommitmentSigned) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn CommitmentSigned_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCommitmentSigned) }) } @@ -8832,7 +8898,7 @@ pub extern "C" fn CommitmentSigned_read(ser: crate::c_types::u8slice) -> crate:: pub extern "C" fn FundingCreated_write(obj: &crate::lightning::ln::msgs::FundingCreated) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn FundingCreated_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeFundingCreated) }) } @@ -8848,7 +8914,7 @@ pub extern "C" fn FundingCreated_read(ser: crate::c_types::u8slice) -> crate::c_ pub extern "C" fn FundingSigned_write(obj: &crate::lightning::ln::msgs::FundingSigned) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn FundingSigned_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeFundingSigned) }) } @@ -8864,7 +8930,7 @@ pub extern "C" fn FundingSigned_read(ser: crate::c_types::u8slice) -> crate::c_t pub extern "C" fn ChannelReady_write(obj: &crate::lightning::ln::msgs::ChannelReady) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelReady_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelReady) }) } @@ -8880,7 +8946,7 @@ pub extern "C" fn ChannelReady_read(ser: crate::c_types::u8slice) -> crate::c_ty pub extern "C" fn Init_write(obj: &crate::lightning::ln::msgs::Init) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn Init_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInit) }) } @@ -8896,7 +8962,7 @@ pub extern "C" fn Init_read(ser: crate::c_types::u8slice) -> crate::c_types::der pub extern "C" fn OpenChannel_write(obj: &crate::lightning::ln::msgs::OpenChannel) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn OpenChannel_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeOpenChannel) }) } @@ -8912,7 +8978,7 @@ pub extern "C" fn OpenChannel_read(ser: crate::c_types::u8slice) -> crate::c_typ pub extern "C" fn OpenChannelV2_write(obj: &crate::lightning::ln::msgs::OpenChannelV2) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn OpenChannelV2_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeOpenChannelV2) }) } @@ -8928,7 +8994,7 @@ pub extern "C" fn OpenChannelV2_read(ser: crate::c_types::u8slice) -> crate::c_t pub extern "C" fn RevokeAndACK_write(obj: &crate::lightning::ln::msgs::RevokeAndACK) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn RevokeAndACK_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRevokeAndACK) }) } @@ -8944,7 +9010,7 @@ pub extern "C" fn RevokeAndACK_read(ser: crate::c_types::u8slice) -> crate::c_ty pub extern "C" fn Shutdown_write(obj: &crate::lightning::ln::msgs::Shutdown) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn Shutdown_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeShutdown) }) } @@ -8960,7 +9026,7 @@ pub extern "C" fn Shutdown_read(ser: crate::c_types::u8slice) -> crate::c_types: pub extern "C" fn UpdateFailHTLC_write(obj: &crate::lightning::ln::msgs::UpdateFailHTLC) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn UpdateFailHTLC_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUpdateFailHTLC) }) } @@ -8976,7 +9042,7 @@ pub extern "C" fn UpdateFailHTLC_read(ser: crate::c_types::u8slice) -> crate::c_ pub extern "C" fn UpdateFailMalformedHTLC_write(obj: &crate::lightning::ln::msgs::UpdateFailMalformedHTLC) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn UpdateFailMalformedHTLC_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUpdateFailMalformedHTLC) }) } @@ -8992,7 +9058,7 @@ pub extern "C" fn UpdateFailMalformedHTLC_read(ser: crate::c_types::u8slice) -> pub extern "C" fn UpdateFee_write(obj: &crate::lightning::ln::msgs::UpdateFee) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn UpdateFee_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUpdateFee) }) } @@ -9008,7 +9074,7 @@ pub extern "C" fn UpdateFee_read(ser: crate::c_types::u8slice) -> crate::c_types pub extern "C" fn UpdateFulfillHTLC_write(obj: &crate::lightning::ln::msgs::UpdateFulfillHTLC) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn UpdateFulfillHTLC_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUpdateFulfillHTLC) }) } @@ -9024,7 +9090,7 @@ pub extern "C" fn UpdateFulfillHTLC_read(ser: crate::c_types::u8slice) -> crate: pub extern "C" fn UpdateAddHTLC_write(obj: &crate::lightning::ln::msgs::UpdateAddHTLC) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn UpdateAddHTLC_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUpdateAddHTLC) }) } @@ -9047,7 +9113,7 @@ pub extern "C" fn OnionMessage_read(ser: crate::c_types::u8slice) -> crate::c_ty pub extern "C" fn OnionMessage_write(obj: &crate::lightning::ln::msgs::OnionMessage) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn OnionMessage_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeOnionMessage) }) } @@ -9056,7 +9122,7 @@ pub(crate) extern "C" fn OnionMessage_write_void(obj: *const c_void) -> crate::c pub extern "C" fn Ping_write(obj: &crate::lightning::ln::msgs::Ping) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn Ping_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePing) }) } @@ -9072,7 +9138,7 @@ pub extern "C" fn Ping_read(ser: crate::c_types::u8slice) -> crate::c_types::der pub extern "C" fn Pong_write(obj: &crate::lightning::ln::msgs::Pong) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn Pong_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePong) }) } @@ -9088,7 +9154,7 @@ pub extern "C" fn Pong_read(ser: crate::c_types::u8slice) -> crate::c_types::der pub extern "C" fn UnsignedChannelAnnouncement_write(obj: &crate::lightning::ln::msgs::UnsignedChannelAnnouncement) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn UnsignedChannelAnnouncement_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUnsignedChannelAnnouncement) }) } @@ -9104,7 +9170,7 @@ pub extern "C" fn UnsignedChannelAnnouncement_read(ser: crate::c_types::u8slice) pub extern "C" fn ChannelAnnouncement_write(obj: &crate::lightning::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelAnnouncement_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelAnnouncement) }) } @@ -9120,7 +9186,7 @@ pub extern "C" fn ChannelAnnouncement_read(ser: crate::c_types::u8slice) -> crat pub extern "C" fn UnsignedChannelUpdate_write(obj: &crate::lightning::ln::msgs::UnsignedChannelUpdate) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn UnsignedChannelUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUnsignedChannelUpdate) }) } @@ -9136,7 +9202,7 @@ pub extern "C" fn UnsignedChannelUpdate_read(ser: crate::c_types::u8slice) -> cr pub extern "C" fn ChannelUpdate_write(obj: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelUpdate) }) } @@ -9152,7 +9218,7 @@ pub extern "C" fn ChannelUpdate_read(ser: crate::c_types::u8slice) -> crate::c_t pub extern "C" fn ErrorMessage_write(obj: &crate::lightning::ln::msgs::ErrorMessage) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ErrorMessage_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeErrorMessage) }) } @@ -9168,7 +9234,7 @@ pub extern "C" fn ErrorMessage_read(ser: crate::c_types::u8slice) -> crate::c_ty pub extern "C" fn WarningMessage_write(obj: &crate::lightning::ln::msgs::WarningMessage) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn WarningMessage_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeWarningMessage) }) } @@ -9184,7 +9250,7 @@ pub extern "C" fn WarningMessage_read(ser: crate::c_types::u8slice) -> crate::c_ pub extern "C" fn UnsignedNodeAnnouncement_write(obj: &crate::lightning::ln::msgs::UnsignedNodeAnnouncement) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn UnsignedNodeAnnouncement_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUnsignedNodeAnnouncement) }) } @@ -9200,7 +9266,7 @@ pub extern "C" fn UnsignedNodeAnnouncement_read(ser: crate::c_types::u8slice) -> pub extern "C" fn NodeAnnouncement_write(obj: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn NodeAnnouncement_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncement) }) } @@ -9223,7 +9289,7 @@ pub extern "C" fn QueryShortChannelIds_read(ser: crate::c_types::u8slice) -> cra pub extern "C" fn QueryShortChannelIds_write(obj: &crate::lightning::ln::msgs::QueryShortChannelIds) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn QueryShortChannelIds_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeQueryShortChannelIds) }) } @@ -9232,7 +9298,7 @@ pub(crate) extern "C" fn QueryShortChannelIds_write_void(obj: *const c_void) -> pub extern "C" fn ReplyShortChannelIdsEnd_write(obj: &crate::lightning::ln::msgs::ReplyShortChannelIdsEnd) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ReplyShortChannelIdsEnd_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeReplyShortChannelIdsEnd) }) } @@ -9258,7 +9324,7 @@ pub extern "C" fn QueryChannelRange_end_blocknum(this_arg: &crate::lightning::ln pub extern "C" fn QueryChannelRange_write(obj: &crate::lightning::ln::msgs::QueryChannelRange) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn QueryChannelRange_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeQueryChannelRange) }) } @@ -9281,7 +9347,7 @@ pub extern "C" fn ReplyChannelRange_read(ser: crate::c_types::u8slice) -> crate: pub extern "C" fn ReplyChannelRange_write(obj: &crate::lightning::ln::msgs::ReplyChannelRange) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ReplyChannelRange_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeReplyChannelRange) }) } @@ -9290,7 +9356,7 @@ pub(crate) extern "C" fn ReplyChannelRange_write_void(obj: *const c_void) -> cra pub extern "C" fn GossipTimestampFilter_write(obj: &crate::lightning::ln::msgs::GossipTimestampFilter) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn GossipTimestampFilter_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeGossipTimestampFilter) }) } diff --git a/lightning-c-bindings/src/lightning/ln/outbound_payment.rs b/lightning-c-bindings/src/lightning/ln/outbound_payment.rs index 946122e..80ab003 100644 --- a/lightning-c-bindings/src/lightning/ln/outbound_payment.rs +++ b/lightning-c-bindings/src/lightning/ln/outbound_payment.rs @@ -113,6 +113,16 @@ pub extern "C" fn Retry_free(this_ptr: Retry) { } pub extern "C" fn Retry_clone(orig: &Retry) -> Retry { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Retry_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Retry)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Retry_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut Retry) }; +} #[no_mangle] /// Utility method to constructs a new Attempts-variant Retry pub extern "C" fn Retry_attempts(a: u32) -> Retry { @@ -143,6 +153,10 @@ pub extern "C" fn Retry_hash(o: &Retry) -> u64 { pub extern "C" fn Retry_write(obj: &crate::lightning::ln::outbound_payment::Retry) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) } +#[allow(unused)] +pub(crate) extern "C" fn Retry_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + Retry_write(unsafe { &*(obj as *const Retry) }) +} #[no_mangle] /// Read a Retry from a byte array, created by Retry_write pub extern "C" fn Retry_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RetryDecodeErrorZ { @@ -217,6 +231,16 @@ impl RetryableSendFailure { pub extern "C" fn RetryableSendFailure_clone(orig: &RetryableSendFailure) -> RetryableSendFailure { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn RetryableSendFailure_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const RetryableSendFailure)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn RetryableSendFailure_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut RetryableSendFailure) }; +} #[no_mangle] /// Utility method to constructs a new PaymentExpired-variant RetryableSendFailure pub extern "C" fn RetryableSendFailure_payment_expired() -> RetryableSendFailure { @@ -464,6 +488,16 @@ pub extern "C" fn PaymentSendFailure_free(this_ptr: PaymentSendFailure) { } pub extern "C" fn PaymentSendFailure_clone(orig: &PaymentSendFailure) -> PaymentSendFailure { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn PaymentSendFailure_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const PaymentSendFailure)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn PaymentSendFailure_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut PaymentSendFailure) }; +} #[no_mangle] /// Utility method to constructs a new ParameterError-variant PaymentSendFailure pub extern "C" fn PaymentSendFailure_parameter_error(a: crate::lightning::util::errors::APIError) -> PaymentSendFailure { @@ -571,6 +605,16 @@ pub extern "C" fn ProbeSendFailure_free(this_ptr: ProbeSendFailure) { } pub extern "C" fn ProbeSendFailure_clone(orig: &ProbeSendFailure) -> ProbeSendFailure { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ProbeSendFailure_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const ProbeSendFailure)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ProbeSendFailure_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut ProbeSendFailure) }; +} #[no_mangle] /// Utility method to constructs a new RouteNotFound-variant ProbeSendFailure pub extern "C" fn ProbeSendFailure_route_not_found() -> ProbeSendFailure { @@ -722,7 +766,7 @@ impl Clone for RecipientOnionFields { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn RecipientOnionFields_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRecipientOnionFields)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRecipientOnionFields)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the RecipientOnionFields @@ -743,7 +787,7 @@ pub extern "C" fn RecipientOnionFields_eq(a: &RecipientOnionFields, b: &Recipien pub extern "C" fn RecipientOnionFields_write(obj: &crate::lightning::ln::outbound_payment::RecipientOnionFields) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn RecipientOnionFields_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRecipientOnionFields) }) } diff --git a/lightning-c-bindings/src/lightning/ln/peer_handler.rs b/lightning-c-bindings/src/lightning/ln/peer_handler.rs index d349f6f..7c2354e 100644 --- a/lightning-c-bindings/src/lightning/ln/peer_handler.rs +++ b/lightning-c-bindings/src/lightning/ln/peer_handler.rs @@ -64,6 +64,7 @@ pub struct CustomMessageHandler { } unsafe impl Send for CustomMessageHandler {} unsafe impl Sync for CustomMessageHandler {} +#[allow(unused)] pub(crate) fn CustomMessageHandler_clone_fields(orig: &CustomMessageHandler) -> CustomMessageHandler { CustomMessageHandler { this_arg: orig.this_arg, @@ -190,10 +191,10 @@ pub extern "C" fn IgnoringMessageHandler_new() -> IgnoringMessageHandler { } impl From for crate::lightning::events::MessageSendEventsProvider { fn from(obj: nativeIgnoringMessageHandler) -> Self { - let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = IgnoringMessageHandler_as_MessageSendEventsProvider(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(IgnoringMessageHandler_free_void); ret } @@ -218,10 +219,10 @@ extern "C" fn IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pen impl From for crate::lightning::ln::msgs::RoutingMessageHandler { fn from(obj: nativeIgnoringMessageHandler) -> Self { - let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = IgnoringMessageHandler_as_RoutingMessageHandler(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(IgnoringMessageHandler_free_void); ret } @@ -331,40 +332,12 @@ extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_provided_init_feature crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true } } -impl From for crate::lightning::events::OnionMessageProvider { - fn from(obj: nativeIgnoringMessageHandler) -> Self { - let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true }; - let mut ret = IgnoringMessageHandler_as_OnionMessageProvider(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); - ret.free = Some(IgnoringMessageHandler_free_void); - ret - } -} -/// Constructs a new OnionMessageProvider which calls the relevant methods on this_arg. -/// This copies the `inner` pointer in this_arg and thus the returned OnionMessageProvider must be freed before this_arg is -#[no_mangle] -pub extern "C" fn IgnoringMessageHandler_as_OnionMessageProvider(this_arg: &IgnoringMessageHandler) -> crate::lightning::events::OnionMessageProvider { - crate::lightning::events::OnionMessageProvider { - this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, - free: None, - next_onion_message_for_peer: IgnoringMessageHandler_OnionMessageProvider_next_onion_message_for_peer, - } -} - -#[must_use] -extern "C" fn IgnoringMessageHandler_OnionMessageProvider_next_onion_message_for_peer(this_arg: *const c_void, mut peer_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::msgs::OnionMessage { - let mut ret = >::next_onion_message_for_peer(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, peer_node_id.into_rust()); - let mut local_ret = crate::lightning::ln::msgs::OnionMessage { inner: if ret.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true }; - local_ret -} - impl From for crate::lightning::ln::msgs::OnionMessageHandler { fn from(obj: nativeIgnoringMessageHandler) -> Self { - let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = IgnoringMessageHandler_as_OnionMessageHandler(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(IgnoringMessageHandler_free_void); ret } @@ -377,15 +350,11 @@ pub extern "C" fn IgnoringMessageHandler_as_OnionMessageHandler(this_arg: &Ignor this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, free: None, handle_onion_message: IgnoringMessageHandler_OnionMessageHandler_handle_onion_message, + next_onion_message_for_peer: IgnoringMessageHandler_OnionMessageHandler_next_onion_message_for_peer, peer_connected: IgnoringMessageHandler_OnionMessageHandler_peer_connected, peer_disconnected: IgnoringMessageHandler_OnionMessageHandler_peer_disconnected, provided_node_features: IgnoringMessageHandler_OnionMessageHandler_provided_node_features, provided_init_features: IgnoringMessageHandler_OnionMessageHandler_provided_init_features, - OnionMessageProvider: crate::lightning::events::OnionMessageProvider { - this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, - free: None, - next_onion_message_for_peer: IgnoringMessageHandler_OnionMessageProvider_next_onion_message_for_peer, - }, } } @@ -393,6 +362,12 @@ extern "C" fn IgnoringMessageHandler_OnionMessageHandler_handle_onion_message(th >::handle_onion_message(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &peer_node_id.into_rust(), msg.get_native_ref()) } #[must_use] +extern "C" fn IgnoringMessageHandler_OnionMessageHandler_next_onion_message_for_peer(this_arg: *const c_void, mut peer_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::msgs::OnionMessage { + let mut ret = >::next_onion_message_for_peer(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, peer_node_id.into_rust()); + let mut local_ret = crate::lightning::ln::msgs::OnionMessage { inner: if ret.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true }; + local_ret +} +#[must_use] extern "C" fn IgnoringMessageHandler_OnionMessageHandler_peer_connected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, init: &crate::lightning::ln::msgs::Init, mut inbound: bool) -> crate::c_types::derived::CResult_NoneNoneZ { let mut ret = >::peer_connected(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust(), init.get_native_ref(), inbound); let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() }; @@ -414,10 +389,10 @@ extern "C" fn IgnoringMessageHandler_OnionMessageHandler_provided_init_features( impl From for crate::lightning::onion_message::offers::OffersMessageHandler { fn from(obj: nativeIgnoringMessageHandler) -> Self { - let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = IgnoringMessageHandler_as_OffersMessageHandler(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(IgnoringMessageHandler_free_void); ret } @@ -430,6 +405,7 @@ pub extern "C" fn IgnoringMessageHandler_as_OffersMessageHandler(this_arg: &Igno this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, free: None, handle_message: IgnoringMessageHandler_OffersMessageHandler_handle_message, + release_pending_messages: IgnoringMessageHandler_OffersMessageHandler_release_pending_messages, } } @@ -439,13 +415,19 @@ extern "C" fn IgnoringMessageHandler_OffersMessageHandler_handle_message(this_ar let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_OffersMessageZ::None } else { crate::c_types::derived::COption_OffersMessageZ::Some( { crate::lightning::onion_message::offers::OffersMessage::native_into(ret.unwrap()) }) }; local_ret } +#[must_use] +extern "C" fn IgnoringMessageHandler_OffersMessageHandler_release_pending_messages(this_arg: *const c_void) -> crate::c_types::derived::CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ { + let mut ret = >::release_pending_messages(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, ); + let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item; let mut local_orig_ret_0_2 = crate::lightning::blinded_path::BlindedPath { inner: if orig_ret_0_2.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((orig_ret_0_2.unwrap())) } }, is_owned: true }; let mut local_ret_0 = (crate::lightning::onion_message::offers::OffersMessage::native_into(orig_ret_0_0), crate::lightning::onion_message::messenger::Destination::native_into(orig_ret_0_1), local_orig_ret_0_2).into(); local_ret_0 }); }; + local_ret.into() +} impl From for crate::lightning::onion_message::messenger::CustomOnionMessageHandler { fn from(obj: nativeIgnoringMessageHandler) -> Self { - let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = IgnoringMessageHandler_as_CustomOnionMessageHandler(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(IgnoringMessageHandler_free_void); ret } @@ -459,21 +441,28 @@ pub extern "C" fn IgnoringMessageHandler_as_CustomOnionMessageHandler(this_arg: free: None, handle_custom_message: IgnoringMessageHandler_CustomOnionMessageHandler_handle_custom_message, read_custom_message: IgnoringMessageHandler_CustomOnionMessageHandler_read_custom_message, + release_pending_custom_messages: IgnoringMessageHandler_CustomOnionMessageHandler_release_pending_custom_messages, } } #[must_use] -extern "C" fn IgnoringMessageHandler_CustomOnionMessageHandler_handle_custom_message(this_arg: *const c_void, mut msg: crate::lightning::onion_message::packet::CustomOnionMessageContents) -> crate::c_types::derived::COption_CustomOnionMessageContentsZ { +extern "C" fn IgnoringMessageHandler_CustomOnionMessageHandler_handle_custom_message(this_arg: *const c_void, mut msg: crate::lightning::onion_message::packet::OnionMessageContents) -> crate::c_types::derived::COption_OnionMessageContentsZ { unreachable!(); } #[must_use] -extern "C" fn IgnoringMessageHandler_CustomOnionMessageHandler_read_custom_message(this_arg: *const c_void, mut message_type: u64, mut buffer: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_CustomOnionMessageContentsZDecodeErrorZ { +extern "C" fn IgnoringMessageHandler_CustomOnionMessageHandler_read_custom_message(this_arg: *const c_void, mut message_type: u64, mut buffer: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_OnionMessageContentsZDecodeErrorZ { let mut ret = >::read_custom_message(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, message_type, &mut buffer.to_reader()); - let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = if o.is_none() { crate::c_types::derived::COption_CustomOnionMessageContentsZ::None } else { crate::c_types::derived::COption_CustomOnionMessageContentsZ::Some( { Into::into(o.unwrap()) }) }; local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = if o.is_none() { crate::c_types::derived::COption_OnionMessageContentsZ::None } else { crate::c_types::derived::COption_OnionMessageContentsZ::Some( { Into::into(o.unwrap()) }) }; local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_ret } +#[must_use] +extern "C" fn IgnoringMessageHandler_CustomOnionMessageHandler_release_pending_custom_messages(this_arg: *const c_void) -> crate::c_types::derived::CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ { + let mut ret = >::release_pending_custom_messages(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, ); + let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item; let mut local_orig_ret_0_2 = crate::lightning::blinded_path::BlindedPath { inner: if orig_ret_0_2.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((orig_ret_0_2.unwrap())) } }, is_owned: true }; let mut local_ret_0 = (Into::into(orig_ret_0_0), crate::lightning::onion_message::messenger::Destination::native_into(orig_ret_0_1), local_orig_ret_0_2).into(); local_ret_0 }); }; + local_ret.into() +} -impl From for crate::lightning::onion_message::packet::CustomOnionMessageContents { +impl From for crate::lightning::onion_message::packet::OnionMessageContents { fn from(obj: nativeInfallible) -> Self { unreachable!(); } @@ -485,10 +474,10 @@ impl From for crate::lightning::ln::wire::Type { } impl From for crate::lightning::ln::wire::CustomMessageReader { fn from(obj: nativeIgnoringMessageHandler) -> Self { - let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = IgnoringMessageHandler_as_CustomMessageReader(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(IgnoringMessageHandler_free_void); ret } @@ -513,10 +502,10 @@ extern "C" fn IgnoringMessageHandler_CustomMessageReader_read(this_arg: *const c impl From for crate::lightning::ln::peer_handler::CustomMessageHandler { fn from(obj: nativeIgnoringMessageHandler) -> Self { - let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = IgnoringMessageHandler_as_CustomMessageHandler(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(IgnoringMessageHandler_free_void); ret } @@ -623,10 +612,10 @@ pub extern "C" fn ErroringMessageHandler_new() -> crate::lightning::ln::peer_han impl From for crate::lightning::events::MessageSendEventsProvider { fn from(obj: nativeErroringMessageHandler) -> Self { - let mut rust_obj = ErroringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::ln::peer_handler::ErroringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = ErroringMessageHandler_as_MessageSendEventsProvider(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(ErroringMessageHandler_free_void); ret } @@ -651,10 +640,10 @@ extern "C" fn ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pen impl From for crate::lightning::ln::msgs::ChannelMessageHandler { fn from(obj: nativeErroringMessageHandler) -> Self { - let mut rust_obj = ErroringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::ln::peer_handler::ErroringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = ErroringMessageHandler_as_ChannelMessageHandler(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(ErroringMessageHandler_free_void); ret } @@ -699,7 +688,7 @@ pub extern "C" fn ErroringMessageHandler_as_ChannelMessageHandler(this_arg: &Err handle_error: ErroringMessageHandler_ChannelMessageHandler_handle_error, provided_node_features: ErroringMessageHandler_ChannelMessageHandler_provided_node_features, provided_init_features: ErroringMessageHandler_ChannelMessageHandler_provided_init_features, - get_genesis_hashes: ErroringMessageHandler_ChannelMessageHandler_get_genesis_hashes, + get_chain_hashes: ErroringMessageHandler_ChannelMessageHandler_get_chain_hashes, MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider { this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, free: None, @@ -815,8 +804,8 @@ extern "C" fn ErroringMessageHandler_ChannelMessageHandler_provided_init_feature crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true } } #[must_use] -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_get_genesis_hashes(this_arg: *const c_void) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ { - let mut ret = >::get_genesis_hashes(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, ); +extern "C" fn ErroringMessageHandler_ChannelMessageHandler_get_chain_hashes(this_arg: *const c_void) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ { + let mut ret = >::get_chain_hashes(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, ); let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::None } else { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::Some( { let mut local_ret_0 = Vec::new(); for mut item in ret.unwrap().drain(..) { local_ret_0.push( { crate::c_types::ThirtyTwoBytes { data: item.to_bytes() } }); }; local_ret_0.into() }) }; local_ret } @@ -1002,6 +991,7 @@ pub struct SocketDescriptor { } unsafe impl Send for SocketDescriptor {} unsafe impl Sync for SocketDescriptor {} +#[allow(unused)] pub(crate) fn SocketDescriptor_clone_fields(orig: &SocketDescriptor) -> SocketDescriptor { SocketDescriptor { this_arg: orig.this_arg, @@ -1140,7 +1130,7 @@ impl Clone for PeerHandleError { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn PeerHandleError_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePeerHandleError)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePeerHandleError)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the PeerHandleError diff --git a/lightning-c-bindings/src/lightning/ln/script.rs b/lightning-c-bindings/src/lightning/ln/script.rs index e0e2e7f..cb56f36 100644 --- a/lightning-c-bindings/src/lightning/ln/script.rs +++ b/lightning-c-bindings/src/lightning/ln/script.rs @@ -82,7 +82,7 @@ impl Clone for ShutdownScript { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ShutdownScript_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeShutdownScript)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeShutdownScript)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ShutdownScript @@ -184,7 +184,7 @@ impl Clone for InvalidShutdownScript { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn InvalidShutdownScript_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvalidShutdownScript)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeInvalidShutdownScript)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the InvalidShutdownScript @@ -196,7 +196,7 @@ pub extern "C" fn InvalidShutdownScript_clone(orig: &InvalidShutdownScript) -> I pub extern "C" fn ShutdownScript_write(obj: &crate::lightning::ln::script::ShutdownScript) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ShutdownScript_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeShutdownScript) }) } diff --git a/lightning-c-bindings/src/lightning/ln/wire.rs b/lightning-c-bindings/src/lightning/ln/wire.rs index 9fa946d..39a696a 100644 --- a/lightning-c-bindings/src/lightning/ln/wire.rs +++ b/lightning-c-bindings/src/lightning/ln/wire.rs @@ -38,6 +38,7 @@ pub struct CustomMessageReader { } unsafe impl Send for CustomMessageReader {} unsafe impl Sync for CustomMessageReader {} +#[allow(unused)] pub(crate) fn CustomMessageReader_clone_fields(orig: &CustomMessageReader) -> CustomMessageReader { CustomMessageReader { this_arg: orig.this_arg, @@ -115,6 +116,7 @@ pub struct Type { } unsafe impl Send for Type {} unsafe impl Sync for Type {} +#[allow(unused)] pub(crate) fn Type_clone_fields(orig: &Type) -> Type { Type { this_arg: orig.this_arg, diff --git a/lightning-c-bindings/src/lightning/offers/invoice.rs b/lightning-c-bindings/src/lightning/offers/invoice.rs index 2385fd4..330a7ab 100644 --- a/lightning-c-bindings/src/lightning/offers/invoice.rs +++ b/lightning-c-bindings/src/lightning/offers/invoice.rs @@ -233,7 +233,7 @@ impl Clone for Bolt12Invoice { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Bolt12Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBolt12Invoice)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBolt12Invoice)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Bolt12Invoice @@ -787,7 +787,7 @@ pub extern "C" fn Bolt12Invoice_verify(this_arg: &crate::lightning::offers::invo pub extern "C" fn UnsignedBolt12Invoice_write(obj: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn UnsignedBolt12Invoice_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUnsignedBolt12Invoice) }) } @@ -796,7 +796,7 @@ pub(crate) extern "C" fn UnsignedBolt12Invoice_write_void(obj: *const c_void) -> pub extern "C" fn Bolt12Invoice_write(obj: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn Bolt12Invoice_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBolt12Invoice) }) } @@ -956,7 +956,7 @@ impl Clone for BlindedPayInfo { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn BlindedPayInfo_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBlindedPayInfo)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBlindedPayInfo)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the BlindedPayInfo @@ -987,7 +987,7 @@ pub extern "C" fn BlindedPayInfo_eq(a: &BlindedPayInfo, b: &BlindedPayInfo) -> b pub extern "C" fn BlindedPayInfo_write(obj: &crate::lightning::offers::invoice::BlindedPayInfo) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn BlindedPayInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBlindedPayInfo) }) } diff --git a/lightning-c-bindings/src/lightning/offers/invoice_error.rs b/lightning-c-bindings/src/lightning/offers/invoice_error.rs index 069ad78..acf381e 100644 --- a/lightning-c-bindings/src/lightning/offers/invoice_error.rs +++ b/lightning-c-bindings/src/lightning/offers/invoice_error.rs @@ -129,7 +129,7 @@ impl Clone for InvoiceError { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn InvoiceError_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceError)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeInvoiceError)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the InvoiceError @@ -238,19 +238,27 @@ impl Clone for ErroneousField { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ErroneousField_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeErroneousField)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeErroneousField)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ErroneousField pub extern "C" fn ErroneousField_clone(orig: &ErroneousField) -> ErroneousField { orig.clone() } +/// Creates an [`InvoiceError`] with the given message. +#[must_use] +#[no_mangle] +pub extern "C" fn InvoiceError_from_string(mut s: crate::c_types::Str) -> crate::lightning::offers::invoice_error::InvoiceError { + let mut ret = lightning::offers::invoice_error::InvoiceError::from_string(s.into_string()); + crate::lightning::offers::invoice_error::InvoiceError { inner: ObjOps::heap_alloc(ret), is_owned: true } +} + #[no_mangle] /// Serialize the InvoiceError object into a byte array which can be read by InvoiceError_read pub extern "C" fn InvoiceError_write(obj: &crate::lightning::offers::invoice_error::InvoiceError) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn InvoiceError_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInvoiceError) }) } diff --git a/lightning-c-bindings/src/lightning/offers/invoice_request.rs b/lightning-c-bindings/src/lightning/offers/invoice_request.rs index b856337..fcf9be2 100644 --- a/lightning-c-bindings/src/lightning/offers/invoice_request.rs +++ b/lightning-c-bindings/src/lightning/offers/invoice_request.rs @@ -195,7 +195,7 @@ impl Clone for InvoiceRequest { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn InvoiceRequest_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceRequest)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeInvoiceRequest)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the InvoiceRequest @@ -293,7 +293,7 @@ impl Clone for VerifiedInvoiceRequest { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn VerifiedInvoiceRequest_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeVerifiedInvoiceRequest)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeVerifiedInvoiceRequest)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the VerifiedInvoiceRequest @@ -829,7 +829,7 @@ pub extern "C" fn VerifiedInvoiceRequest_payer_note(this_arg: &crate::lightning: pub extern "C" fn UnsignedInvoiceRequest_write(obj: &crate::lightning::offers::invoice_request::UnsignedInvoiceRequest) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn UnsignedInvoiceRequest_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUnsignedInvoiceRequest) }) } @@ -838,7 +838,7 @@ pub(crate) extern "C" fn UnsignedInvoiceRequest_write_void(obj: *const c_void) - pub extern "C" fn InvoiceRequest_write(obj: &crate::lightning::offers::invoice_request::InvoiceRequest) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn InvoiceRequest_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInvoiceRequest) }) } diff --git a/lightning-c-bindings/src/lightning/offers/offer.rs b/lightning-c-bindings/src/lightning/offers/offer.rs index c4f0c06..f9691b4 100644 --- a/lightning-c-bindings/src/lightning/offers/offer.rs +++ b/lightning-c-bindings/src/lightning/offers/offer.rs @@ -12,6 +12,8 @@ //! published as a QR code to be scanned by a customer. The customer uses the offer to request an //! invoice from the merchant to be paid. //! +//! # Example +//! //! ``` //! extern crate bitcoin; //! extern crate core; @@ -64,6 +66,14 @@ //! # Ok(()) //! # } //! ``` +//! +//! # Note +//! +//! If constructing an [`Offer`] for use with a [`ChannelManager`], use +//! [`ChannelManager::create_offer_builder`] instead of [`OfferBuilder::new`]. +//! +//! [`ChannelManager`]: crate::ln::channelmanager::ChannelManager +//! [`ChannelManager::create_offer_builder`]: crate::ln::channelmanager::ChannelManager::create_offer_builder use alloc::str::FromStr; use alloc::string::String; @@ -149,7 +159,7 @@ impl Clone for Offer { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Offer_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeOffer)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeOffer)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Offer @@ -293,7 +303,7 @@ pub extern "C" fn Offer_expects_quantity(this_arg: &crate::lightning::offers::of pub extern "C" fn Offer_write(obj: &crate::lightning::offers::offer::Offer) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn Offer_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeOffer) }) } @@ -361,7 +371,7 @@ impl Clone for Amount { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Amount_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeAmount)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeAmount)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Amount @@ -431,7 +441,7 @@ impl Clone for Quantity { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Quantity_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeQuantity)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeQuantity)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Quantity diff --git a/lightning-c-bindings/src/lightning/offers/parse.rs b/lightning-c-bindings/src/lightning/offers/parse.rs index 22ab654..fc84acd 100644 --- a/lightning-c-bindings/src/lightning/offers/parse.rs +++ b/lightning-c-bindings/src/lightning/offers/parse.rs @@ -92,7 +92,7 @@ impl Clone for Bolt12ParseError { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Bolt12ParseError_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBolt12ParseError)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBolt12ParseError)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Bolt12ParseError @@ -146,6 +146,8 @@ pub enum Bolt12SemanticError { MissingPayerMetadata, /// A payer id was expected but was missing. MissingPayerId, + /// The payment id for a refund or request is already in use. + DuplicatePaymentId, /// Blinded paths were expected but were missing. MissingPaths, /// The blinded payinfo given does not match the number of blinded path hops. @@ -185,6 +187,7 @@ impl Bolt12SemanticError { Bolt12SemanticError::UnexpectedMetadata => nativeBolt12SemanticError::UnexpectedMetadata, Bolt12SemanticError::MissingPayerMetadata => nativeBolt12SemanticError::MissingPayerMetadata, Bolt12SemanticError::MissingPayerId => nativeBolt12SemanticError::MissingPayerId, + Bolt12SemanticError::DuplicatePaymentId => nativeBolt12SemanticError::DuplicatePaymentId, Bolt12SemanticError::MissingPaths => nativeBolt12SemanticError::MissingPaths, Bolt12SemanticError::InvalidPayInfo => nativeBolt12SemanticError::InvalidPayInfo, Bolt12SemanticError::MissingCreationTime => nativeBolt12SemanticError::MissingCreationTime, @@ -216,6 +219,7 @@ impl Bolt12SemanticError { Bolt12SemanticError::UnexpectedMetadata => nativeBolt12SemanticError::UnexpectedMetadata, Bolt12SemanticError::MissingPayerMetadata => nativeBolt12SemanticError::MissingPayerMetadata, Bolt12SemanticError::MissingPayerId => nativeBolt12SemanticError::MissingPayerId, + Bolt12SemanticError::DuplicatePaymentId => nativeBolt12SemanticError::DuplicatePaymentId, Bolt12SemanticError::MissingPaths => nativeBolt12SemanticError::MissingPaths, Bolt12SemanticError::InvalidPayInfo => nativeBolt12SemanticError::InvalidPayInfo, Bolt12SemanticError::MissingCreationTime => nativeBolt12SemanticError::MissingCreationTime, @@ -247,6 +251,7 @@ impl Bolt12SemanticError { nativeBolt12SemanticError::UnexpectedMetadata => Bolt12SemanticError::UnexpectedMetadata, nativeBolt12SemanticError::MissingPayerMetadata => Bolt12SemanticError::MissingPayerMetadata, nativeBolt12SemanticError::MissingPayerId => Bolt12SemanticError::MissingPayerId, + nativeBolt12SemanticError::DuplicatePaymentId => Bolt12SemanticError::DuplicatePaymentId, nativeBolt12SemanticError::MissingPaths => Bolt12SemanticError::MissingPaths, nativeBolt12SemanticError::InvalidPayInfo => Bolt12SemanticError::InvalidPayInfo, nativeBolt12SemanticError::MissingCreationTime => Bolt12SemanticError::MissingCreationTime, @@ -278,6 +283,7 @@ impl Bolt12SemanticError { nativeBolt12SemanticError::UnexpectedMetadata => Bolt12SemanticError::UnexpectedMetadata, nativeBolt12SemanticError::MissingPayerMetadata => Bolt12SemanticError::MissingPayerMetadata, nativeBolt12SemanticError::MissingPayerId => Bolt12SemanticError::MissingPayerId, + nativeBolt12SemanticError::DuplicatePaymentId => Bolt12SemanticError::DuplicatePaymentId, nativeBolt12SemanticError::MissingPaths => Bolt12SemanticError::MissingPaths, nativeBolt12SemanticError::InvalidPayInfo => Bolt12SemanticError::InvalidPayInfo, nativeBolt12SemanticError::MissingCreationTime => Bolt12SemanticError::MissingCreationTime, @@ -291,6 +297,16 @@ impl Bolt12SemanticError { pub extern "C" fn Bolt12SemanticError_clone(orig: &Bolt12SemanticError) -> Bolt12SemanticError { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Bolt12SemanticError_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Bolt12SemanticError)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Bolt12SemanticError_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut Bolt12SemanticError) }; +} #[no_mangle] /// Utility method to constructs a new AlreadyExpired-variant Bolt12SemanticError pub extern "C" fn Bolt12SemanticError_already_expired() -> Bolt12SemanticError { @@ -376,6 +392,10 @@ pub extern "C" fn Bolt12SemanticError_missing_payer_metadata() -> Bolt12Semantic pub extern "C" fn Bolt12SemanticError_missing_payer_id() -> Bolt12SemanticError { Bolt12SemanticError::MissingPayerId} #[no_mangle] +/// Utility method to constructs a new DuplicatePaymentId-variant Bolt12SemanticError +pub extern "C" fn Bolt12SemanticError_duplicate_payment_id() -> Bolt12SemanticError { + Bolt12SemanticError::DuplicatePaymentId} +#[no_mangle] /// Utility method to constructs a new MissingPaths-variant Bolt12SemanticError pub extern "C" fn Bolt12SemanticError_missing_paths() -> Bolt12SemanticError { Bolt12SemanticError::MissingPaths} diff --git a/lightning-c-bindings/src/lightning/offers/refund.rs b/lightning-c-bindings/src/lightning/offers/refund.rs index b7ec076..7fcfc66 100644 --- a/lightning-c-bindings/src/lightning/offers/refund.rs +++ b/lightning-c-bindings/src/lightning/offers/refund.rs @@ -17,6 +17,8 @@ //! [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest //! [`Offer`]: crate::offers::offer::Offer //! +//! # Example +//! //! ``` //! extern crate bitcoin; //! extern crate core; @@ -69,6 +71,14 @@ //! # Ok(()) //! # } //! ``` +//! +//! # Note +//! +//! If constructing a [`Refund`] for use with a [`ChannelManager`], use +//! [`ChannelManager::create_refund_builder`] instead of [`RefundBuilder::new`]. +//! +//! [`ChannelManager`]: crate::ln::channelmanager::ChannelManager +//! [`ChannelManager::create_refund_builder`]: crate::ln::channelmanager::ChannelManager::create_refund_builder use alloc::str::FromStr; use alloc::string::String; @@ -149,7 +159,7 @@ impl Clone for Refund { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Refund_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRefund)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRefund)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Refund @@ -280,7 +290,7 @@ pub extern "C" fn Refund_payer_note(this_arg: &crate::lightning::offers::refund: pub extern "C" fn Refund_write(obj: &crate::lightning::offers::refund::Refund) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn Refund_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRefund) }) } diff --git a/lightning-c-bindings/src/lightning/onion_message/messenger.rs b/lightning-c-bindings/src/lightning/onion_message/messenger.rs index 4a0e600..5ef9665 100644 --- a/lightning-c-bindings/src/lightning/onion_message/messenger.rs +++ b/lightning-c-bindings/src/lightning/onion_message/messenger.rs @@ -22,9 +22,21 @@ use alloc::{vec::Vec, boxed::Box}; use lightning::onion_message::messenger::OnionMessenger as nativeOnionMessengerImport; pub(crate) type nativeOnionMessenger = nativeOnionMessengerImport; -/// A sender, receiver and forwarder of onion messages. In upcoming releases, this object will be -/// used to retrieve invoices and fulfill invoice requests from [offers]. Currently, only sending -/// and receiving custom onion messages is supported. +/// A sender, receiver and forwarder of [`OnionMessage`]s. +/// +/// # Handling Messages +/// +/// `OnionMessenger` implements [`OnionMessageHandler`], making it responsible for either forwarding +/// messages to peers or delegating to the appropriate handler for the message type. Currently, the +/// available handlers are: +/// * [`OffersMessageHandler`], for responding to [`InvoiceRequest`]s and paying [`Bolt12Invoice`]s +/// * [`CustomOnionMessageHandler`], for handling user-defined message types +/// +/// # Sending Messages +/// +/// [`OnionMessage`]s are sent initially using [`OnionMessenger::send_onion_message`]. When handling +/// a message, the matched handler may return a response message which `OnionMessenger` will send +/// on its behalf. /// /// # Example /// @@ -36,7 +48,7 @@ pub(crate) type nativeOnionMessenger = nativeOnionMessengerImport u64 { /// \t\t# let your_custom_message_type = 42; /// \t\tyour_custom_message_type @@ -90,8 +102,7 @@ pub(crate) type nativeOnionMessenger = nativeOnionMessengerImport -/// [`OnionMessenger`]: crate::onion_message::OnionMessenger +/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest +/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice #[must_use] #[repr(C)] pub struct OnionMessenger { @@ -159,16 +169,12 @@ impl OnionMessenger { } } /// A trait defining behavior for routing an [`OnionMessage`]. -/// -/// [`OnionMessage`]: msgs::OnionMessage #[repr(C)] pub struct MessageRouter { /// An opaque pointer which is passed to your function implementations as an argument. /// This has no meaning in the LDK, and can be NULL or any other value. pub this_arg: *mut c_void, /// Returns a route for sending an [`OnionMessage`] to the given [`Destination`]. - /// - /// [`OnionMessage`]: msgs::OnionMessage pub find_path: extern "C" fn (this_arg: *const c_void, sender: crate::c_types::PublicKey, peers: crate::c_types::derived::CVec_PublicKeyZ, destination: crate::lightning::onion_message::messenger::Destination) -> crate::c_types::derived::CResult_OnionMessagePathNoneZ, /// Frees any resources associated with this object given its this_arg pointer. /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. @@ -176,6 +182,7 @@ pub struct MessageRouter { } unsafe impl Send for MessageRouter {} unsafe impl Sync for MessageRouter {} +#[allow(unused)] pub(crate) fn MessageRouter_clone_fields(orig: &MessageRouter) -> MessageRouter { MessageRouter { this_arg: orig.this_arg, @@ -221,7 +228,7 @@ impl Drop for MessageRouter { use lightning::onion_message::messenger::DefaultMessageRouter as nativeDefaultMessageRouterImport; pub(crate) type nativeDefaultMessageRouter = nativeDefaultMessageRouterImport; -/// A [`MessageRouter`] that always fails. +/// A [`MessageRouter`] that can only route to a directly connected [`Destination`]. #[must_use] #[repr(C)] pub struct DefaultMessageRouter { @@ -276,10 +283,10 @@ pub extern "C" fn DefaultMessageRouter_new() -> DefaultMessageRouter { } impl From for crate::lightning::onion_message::messenger::MessageRouter { fn from(obj: nativeDefaultMessageRouter) -> Self { - let mut rust_obj = DefaultMessageRouter { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::onion_message::messenger::DefaultMessageRouter { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = DefaultMessageRouter_as_MessageRouter(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(DefaultMessageRouter_free_void); ret } @@ -307,7 +314,7 @@ extern "C" fn DefaultMessageRouter_MessageRouter_find_path(this_arg: *const c_vo use lightning::onion_message::messenger::OnionMessagePath as nativeOnionMessagePathImport; pub(crate) type nativeOnionMessagePath = nativeOnionMessagePathImport; -/// A path for sending an [`msgs::OnionMessage`]. +/// A path for sending an [`OnionMessage`]. #[must_use] #[repr(C)] pub struct OnionMessagePath { @@ -402,7 +409,7 @@ impl Clone for OnionMessagePath { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn OnionMessagePath_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeOnionMessagePath)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeOnionMessagePath)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the OnionMessagePath @@ -498,6 +505,16 @@ pub extern "C" fn Destination_free(this_ptr: Destination) { } pub extern "C" fn Destination_clone(orig: &Destination) -> Destination { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Destination_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Destination)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Destination_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut Destination) }; +} #[no_mangle] /// Utility method to constructs a new Node-variant Destination pub extern "C" fn Destination_node(a: crate::c_types::PublicKey) -> Destination { @@ -521,8 +538,8 @@ pub enum SendError { /// Because implementations such as Eclair will drop onion messages where the message packet /// exceeds 32834 bytes, we refuse to send messages where the packet exceeds this size. TooBigPacket, - /// The provided [`Destination`] was an invalid [`BlindedPath`], due to having fewer than two - /// blinded hops. + /// The provided [`Destination`] was an invalid [`BlindedPath`] due to not having any blinded + /// hops. TooFewBlindedHops, /// Our next-hop peer was offline or does not support onion message forwarding. InvalidFirstHop, @@ -623,6 +640,16 @@ pub extern "C" fn SendError_free(this_ptr: SendError) { } pub extern "C" fn SendError_clone(orig: &SendError) -> SendError { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn SendError_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const SendError)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn SendError_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut SendError) }; +} #[no_mangle] /// Utility method to constructs a new Secp256k1-variant SendError pub extern "C" fn SendError_secp256k1(a: crate::c_types::Secp256k1Error) -> SendError { @@ -678,38 +705,52 @@ pub struct CustomOnionMessageHandler { /// This has no meaning in the LDK, and can be NULL or any other value. pub this_arg: *mut c_void, /// Called with the custom message that was received, returning a response to send, if any. - pub handle_custom_message: extern "C" fn (this_arg: *const c_void, msg: crate::lightning::onion_message::packet::CustomOnionMessageContents) -> crate::c_types::derived::COption_CustomOnionMessageContentsZ, + /// + /// The returned [`Self::CustomMessage`], if any, is enqueued to be sent by [`OnionMessenger`]. + pub handle_custom_message: extern "C" fn (this_arg: *const c_void, msg: crate::lightning::onion_message::packet::OnionMessageContents) -> crate::c_types::derived::COption_OnionMessageContentsZ, /// Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the /// message type is unknown. - pub read_custom_message: extern "C" fn (this_arg: *const c_void, message_type: u64, buffer: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_CustomOnionMessageContentsZDecodeErrorZ, + pub read_custom_message: extern "C" fn (this_arg: *const c_void, message_type: u64, buffer: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_OnionMessageContentsZDecodeErrorZ, + /// Releases any [`Self::CustomMessage`]s that need to be sent. + /// + /// Typically, this is used for messages initiating a message flow rather than in response to + /// another message. The latter should use the return value of [`Self::handle_custom_message`]. + pub release_pending_custom_messages: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ, /// Frees any resources associated with this object given its this_arg pointer. /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. pub free: Option, } unsafe impl Send for CustomOnionMessageHandler {} unsafe impl Sync for CustomOnionMessageHandler {} +#[allow(unused)] pub(crate) fn CustomOnionMessageHandler_clone_fields(orig: &CustomOnionMessageHandler) -> CustomOnionMessageHandler { CustomOnionMessageHandler { this_arg: orig.this_arg, handle_custom_message: Clone::clone(&orig.handle_custom_message), read_custom_message: Clone::clone(&orig.read_custom_message), + release_pending_custom_messages: Clone::clone(&orig.release_pending_custom_messages), free: Clone::clone(&orig.free), } } use lightning::onion_message::messenger::CustomOnionMessageHandler as rustCustomOnionMessageHandler; impl rustCustomOnionMessageHandler for CustomOnionMessageHandler { - type CustomMessage = crate::lightning::onion_message::packet::CustomOnionMessageContents; - fn handle_custom_message(&self, mut msg: crate::lightning::onion_message::packet::CustomOnionMessageContents) -> Option { + type CustomMessage = crate::lightning::onion_message::packet::OnionMessageContents; + fn handle_custom_message(&self, mut msg: crate::lightning::onion_message::packet::OnionMessageContents) -> Option { let mut ret = (self.handle_custom_message)(self.this_arg, Into::into(msg)); let mut local_ret = { /*ret*/ let ret_opt = ret; if ret_opt.is_none() { None } else { Some({ { { ret_opt.take() } }})} }; local_ret } - fn read_custom_message(&self, mut message_type: u64, mut buffer: &mut R) -> Result, lightning::ln::msgs::DecodeError> { + fn read_custom_message(&self, mut message_type: u64, mut buffer: &mut R) -> Result, lightning::ln::msgs::DecodeError> { let mut ret = (self.read_custom_message)(self.this_arg, message_type, crate::c_types::u8slice::from_vec(&crate::c_types::reader_to_vec(buffer))); let mut local_ret = match ret.result_ok { true => Ok( { let mut local_ret_0 = { /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ let ret_0_opt = (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }); if ret_0_opt.is_none() { None } else { Some({ { { ret_0_opt.take() } }})} }; local_ret_0 }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })}; local_ret } + fn release_pending_custom_messages(&self) -> Vec<(crate::lightning::onion_message::packet::OnionMessageContents, lightning::onion_message::messenger::Destination, Option)> { + let mut ret = (self.release_pending_custom_messages)(self.this_arg); + let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item.to_rust(); let mut local_orig_ret_0_2 = if orig_ret_0_2.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(orig_ret_0_2.take_inner()) } }) }; let mut local_ret_0 = (orig_ret_0_0, orig_ret_0_1.into_native(), local_orig_ret_0_2); local_ret_0 }); }; + local_ret + } } // We're essentially a pointer already, or at least a set of pointers, so allow us to be used @@ -735,18 +776,174 @@ impl Drop for CustomOnionMessageHandler { } } } -/// Create an onion message with contents `message` to the destination of `path`. -/// Returns (introduction_node_id, onion_msg) +/// A processed incoming onion message, containing either a Forward (another onion message) +/// or a Receive payload with decrypted contents. +#[derive(Clone)] +#[must_use] +#[repr(C)] +pub enum PeeledOnion { + /// Forwarded onion, with the next node id and a new onion + Forward( + crate::c_types::PublicKey, + crate::lightning::ln::msgs::OnionMessage), + /// Received onion message, with decrypted contents, path_id, and reply path + Receive( + crate::lightning::onion_message::packet::ParsedOnionMessageContents, + /// + /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None + crate::c_types::ThirtyTwoBytes, + /// + /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None + crate::lightning::blinded_path::BlindedPath), +} +use lightning::onion_message::messenger::PeeledOnion as PeeledOnionImport; +pub(crate) type nativePeeledOnion = PeeledOnionImport; + +impl PeeledOnion { + #[allow(unused)] + pub(crate) fn to_native(&self) -> nativePeeledOnion { + match self { + PeeledOnion::Forward (ref a, ref b, ) => { + let mut a_nonref = Clone::clone(a); + let mut b_nonref = Clone::clone(b); + nativePeeledOnion::Forward ( + a_nonref.into_rust(), + *unsafe { Box::from_raw(b_nonref.take_inner()) }, + ) + }, + PeeledOnion::Receive (ref a, ref b, ref c, ) => { + let mut a_nonref = Clone::clone(a); + let mut b_nonref = Clone::clone(b); + let mut local_b_nonref = if b_nonref.data == [0; 32] { None } else { Some( { b_nonref.data }) }; + let mut c_nonref = Clone::clone(c); + let mut local_c_nonref = if c_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(c_nonref.take_inner()) } }) }; + nativePeeledOnion::Receive ( + a_nonref.into_native(), + local_b_nonref, + local_c_nonref, + ) + }, + } + } + #[allow(unused)] + pub(crate) fn into_native(self) -> nativePeeledOnion { + match self { + PeeledOnion::Forward (mut a, mut b, ) => { + nativePeeledOnion::Forward ( + a.into_rust(), + *unsafe { Box::from_raw(b.take_inner()) }, + ) + }, + PeeledOnion::Receive (mut a, mut b, mut c, ) => { + let mut local_b = if b.data == [0; 32] { None } else { Some( { b.data }) }; + let mut local_c = if c.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(c.take_inner()) } }) }; + nativePeeledOnion::Receive ( + a.into_native(), + local_b, + local_c, + ) + }, + } + } + #[allow(unused)] + pub(crate) fn from_native(native: &nativePeeledOnion) -> Self { + match native { + nativePeeledOnion::Forward (ref a, ref b, ) => { + let mut a_nonref = Clone::clone(a); + let mut b_nonref = Clone::clone(b); + PeeledOnion::Forward ( + crate::c_types::PublicKey::from_rust(&a_nonref), + crate::lightning::ln::msgs::OnionMessage { inner: ObjOps::heap_alloc(b_nonref), is_owned: true }, + ) + }, + nativePeeledOnion::Receive (ref a, ref b, ref c, ) => { + let mut a_nonref = Clone::clone(a); + let mut b_nonref = Clone::clone(b); + let mut local_b_nonref = if b_nonref.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (b_nonref.unwrap()) } } }; + let mut c_nonref = Clone::clone(c); + let mut local_c_nonref = crate::lightning::blinded_path::BlindedPath { inner: if c_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((c_nonref.unwrap())) } }, is_owned: true }; + PeeledOnion::Receive ( + crate::lightning::onion_message::packet::ParsedOnionMessageContents::native_into(a_nonref), + local_b_nonref, + local_c_nonref, + ) + }, + } + } + #[allow(unused)] + pub(crate) fn native_into(native: nativePeeledOnion) -> Self { + match native { + nativePeeledOnion::Forward (mut a, mut b, ) => { + PeeledOnion::Forward ( + crate::c_types::PublicKey::from_rust(&a), + crate::lightning::ln::msgs::OnionMessage { inner: ObjOps::heap_alloc(b), is_owned: true }, + ) + }, + nativePeeledOnion::Receive (mut a, mut b, mut c, ) => { + let mut local_b = if b.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (b.unwrap()) } } }; + let mut local_c = crate::lightning::blinded_path::BlindedPath { inner: if c.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((c.unwrap())) } }, is_owned: true }; + PeeledOnion::Receive ( + crate::lightning::onion_message::packet::ParsedOnionMessageContents::native_into(a), + local_b, + local_c, + ) + }, + } + } +} +/// Frees any resources used by the PeeledOnion +#[no_mangle] +pub extern "C" fn PeeledOnion_free(this_ptr: PeeledOnion) { } +/// Creates a copy of the PeeledOnion +#[no_mangle] +pub extern "C" fn PeeledOnion_clone(orig: &PeeledOnion) -> PeeledOnion { + orig.clone() +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn PeeledOnion_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const PeeledOnion)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn PeeledOnion_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut PeeledOnion) }; +} +#[no_mangle] +/// Utility method to constructs a new Forward-variant PeeledOnion +pub extern "C" fn PeeledOnion_forward(a: crate::c_types::PublicKey,b: crate::lightning::ln::msgs::OnionMessage) -> PeeledOnion { + PeeledOnion::Forward(a, b, ) +} +#[no_mangle] +/// Utility method to constructs a new Receive-variant PeeledOnion +pub extern "C" fn PeeledOnion_receive(a: crate::lightning::onion_message::packet::ParsedOnionMessageContents,b: crate::c_types::ThirtyTwoBytes,c: crate::lightning::blinded_path::BlindedPath) -> PeeledOnion { + PeeledOnion::Receive(a, b, c, ) +} +/// Creates an [`OnionMessage`] with the given `contents` for sending to the destination of +/// `path`. +/// +/// Returns both the node id of the peer to send the message to and the message itself. /// /// Note that reply_path (or a relevant inner pointer) may be NULL or all-0s to represent None #[no_mangle] -pub extern "C" fn create_onion_message(entropy_source: &crate::lightning::sign::EntropySource, node_signer: &crate::lightning::sign::NodeSigner, mut path: crate::lightning::onion_message::messenger::OnionMessagePath, mut message: crate::lightning::onion_message::packet::OnionMessageContents, mut reply_path: crate::lightning::blinded_path::BlindedPath) -> crate::c_types::derived::CResult_C2Tuple_PublicKeyOnionMessageZSendErrorZ { +pub extern "C" fn create_onion_message(entropy_source: &crate::lightning::sign::EntropySource, node_signer: &crate::lightning::sign::NodeSigner, mut path: crate::lightning::onion_message::messenger::OnionMessagePath, mut contents: crate::lightning::onion_message::packet::OnionMessageContents, mut reply_path: crate::lightning::blinded_path::BlindedPath) -> crate::c_types::derived::CResult_C2Tuple_PublicKeyOnionMessageZSendErrorZ { let mut local_reply_path = if reply_path.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(reply_path.take_inner()) } }) }; - let mut ret = lightning::onion_message::messenger::create_onion_message::(entropy_source, node_signer, secp256k1::global::SECP256K1, *unsafe { Box::from_raw(path.take_inner()) }, message.into_native(), local_reply_path); + let mut ret = lightning::onion_message::messenger::create_onion_message::(entropy_source, node_signer, secp256k1::global::SECP256K1, *unsafe { Box::from_raw(path.take_inner()) }, contents, local_reply_path); let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_ret_0 = (crate::c_types::PublicKey::from_rust(&orig_ret_0_0), crate::lightning::ln::msgs::OnionMessage { inner: ObjOps::heap_alloc(orig_ret_0_1), is_owned: true }).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::onion_message::messenger::SendError::native_into(e) }).into() }; local_ret } +/// Decode one layer of an incoming [`OnionMessage`]. +/// +/// Returns either the next layer of the onion for forwarding or the decrypted content for the +/// receiver. +#[no_mangle] +pub extern "C" fn peel_onion_message(msg: &crate::lightning::ln::msgs::OnionMessage, mut node_signer: crate::lightning::sign::NodeSigner, mut logger: crate::lightning::util::logger::Logger, mut custom_handler: crate::lightning::onion_message::messenger::CustomOnionMessageHandler) -> crate::c_types::derived::CResult_PeeledOnionNoneZ { + let mut ret = lightning::onion_message::messenger::peel_onion_message::(msg.get_native_ref(), secp256k1::global::SECP256K1, node_signer, logger, custom_handler); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::onion_message::messenger::PeeledOnion::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() }; + local_ret +} + /// Constructs a new `OnionMessenger` to send, forward, and delegate received onion messages to /// their respective handlers. #[must_use] @@ -756,26 +953,27 @@ pub extern "C" fn OnionMessenger_new(mut entropy_source: crate::lightning::sign: crate::lightning::onion_message::messenger::OnionMessenger { inner: ObjOps::heap_alloc(ret), is_owned: true } } -/// Send an onion message with contents `message` to the destination of `path`. +/// Sends an [`OnionMessage`] with the given `contents` for sending to the destination of +/// `path`. /// /// See [`OnionMessenger`] for example usage. /// /// Note that reply_path (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] -pub extern "C" fn OnionMessenger_send_onion_message(this_arg: &crate::lightning::onion_message::messenger::OnionMessenger, mut path: crate::lightning::onion_message::messenger::OnionMessagePath, mut message: crate::lightning::onion_message::packet::OnionMessageContents, mut reply_path: crate::lightning::blinded_path::BlindedPath) -> crate::c_types::derived::CResult_NoneSendErrorZ { +pub extern "C" fn OnionMessenger_send_onion_message(this_arg: &crate::lightning::onion_message::messenger::OnionMessenger, mut path: crate::lightning::onion_message::messenger::OnionMessagePath, mut contents: crate::lightning::onion_message::packet::OnionMessageContents, mut reply_path: crate::lightning::blinded_path::BlindedPath) -> crate::c_types::derived::CResult_NoneSendErrorZ { let mut local_reply_path = if reply_path.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(reply_path.take_inner()) } }) }; - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_onion_message(*unsafe { Box::from_raw(path.take_inner()) }, message.into_native(), local_reply_path); + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_onion_message(*unsafe { Box::from_raw(path.take_inner()) }, contents, local_reply_path); let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::onion_message::messenger::SendError::native_into(e) }).into() }; local_ret } impl From for crate::lightning::ln::msgs::OnionMessageHandler { fn from(obj: nativeOnionMessenger) -> Self { - let mut rust_obj = OnionMessenger { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::onion_message::messenger::OnionMessenger { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = OnionMessenger_as_OnionMessageHandler(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(OnionMessenger_free_void); ret } @@ -788,15 +986,11 @@ pub extern "C" fn OnionMessenger_as_OnionMessageHandler(this_arg: &OnionMessenge this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, free: None, handle_onion_message: OnionMessenger_OnionMessageHandler_handle_onion_message, + next_onion_message_for_peer: OnionMessenger_OnionMessageHandler_next_onion_message_for_peer, peer_connected: OnionMessenger_OnionMessageHandler_peer_connected, peer_disconnected: OnionMessenger_OnionMessageHandler_peer_disconnected, provided_node_features: OnionMessenger_OnionMessageHandler_provided_node_features, provided_init_features: OnionMessenger_OnionMessageHandler_provided_init_features, - OnionMessageProvider: crate::lightning::events::OnionMessageProvider { - this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, - free: None, - next_onion_message_for_peer: OnionMessenger_OnionMessageProvider_next_onion_message_for_peer, - }, } } @@ -804,6 +998,12 @@ extern "C" fn OnionMessenger_OnionMessageHandler_handle_onion_message(this_arg: >::handle_onion_message(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, &peer_node_id.into_rust(), msg.get_native_ref()) } #[must_use] +extern "C" fn OnionMessenger_OnionMessageHandler_next_onion_message_for_peer(this_arg: *const c_void, mut peer_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::msgs::OnionMessage { + let mut ret = >::next_onion_message_for_peer(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, peer_node_id.into_rust()); + let mut local_ret = crate::lightning::ln::msgs::OnionMessage { inner: if ret.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true }; + local_ret +} +#[must_use] extern "C" fn OnionMessenger_OnionMessageHandler_peer_connected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, init: &crate::lightning::ln::msgs::Init, mut inbound: bool) -> crate::c_types::derived::CResult_NoneNoneZ { let mut ret = >::peer_connected(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, &their_node_id.into_rust(), init.get_native_ref(), inbound); let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() }; @@ -823,31 +1023,3 @@ extern "C" fn OnionMessenger_OnionMessageHandler_provided_init_features(this_arg crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true } } -impl From for crate::lightning::events::OnionMessageProvider { - fn from(obj: nativeOnionMessenger) -> Self { - let mut rust_obj = OnionMessenger { inner: ObjOps::heap_alloc(obj), is_owned: true }; - let mut ret = OnionMessenger_as_OnionMessageProvider(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); - ret.free = Some(OnionMessenger_free_void); - ret - } -} -/// Constructs a new OnionMessageProvider which calls the relevant methods on this_arg. -/// This copies the `inner` pointer in this_arg and thus the returned OnionMessageProvider must be freed before this_arg is -#[no_mangle] -pub extern "C" fn OnionMessenger_as_OnionMessageProvider(this_arg: &OnionMessenger) -> crate::lightning::events::OnionMessageProvider { - crate::lightning::events::OnionMessageProvider { - this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, - free: None, - next_onion_message_for_peer: OnionMessenger_OnionMessageProvider_next_onion_message_for_peer, - } -} - -#[must_use] -extern "C" fn OnionMessenger_OnionMessageProvider_next_onion_message_for_peer(this_arg: *const c_void, mut peer_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::msgs::OnionMessage { - let mut ret = >::next_onion_message_for_peer(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, peer_node_id.into_rust()); - let mut local_ret = crate::lightning::ln::msgs::OnionMessage { inner: if ret.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true }; - local_ret -} - diff --git a/lightning-c-bindings/src/lightning/onion_message/offers.rs b/lightning-c-bindings/src/lightning/onion_message/offers.rs index ae1f1a6..294d832 100644 --- a/lightning-c-bindings/src/lightning/onion_message/offers.rs +++ b/lightning-c-bindings/src/lightning/onion_message/offers.rs @@ -27,17 +27,28 @@ pub struct OffersMessageHandler { pub this_arg: *mut c_void, /// Handles the given message by either responding with an [`Bolt12Invoice`], sending a payment, /// or replying with an error. + /// + /// The returned [`OffersMessage`], if any, is enqueued to be sent by [`OnionMessenger`]. + /// + /// [`OnionMessenger`]: crate::onion_message::OnionMessenger pub handle_message: extern "C" fn (this_arg: *const c_void, message: crate::lightning::onion_message::offers::OffersMessage) -> crate::c_types::derived::COption_OffersMessageZ, + /// Releases any [`OffersMessage`]s that need to be sent. + /// + /// Typically, this is used for messages initiating a payment flow rather than in response to + /// another message. The latter should use the return value of [`Self::handle_message`]. + pub release_pending_messages: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ, /// Frees any resources associated with this object given its this_arg pointer. /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. pub free: Option, } unsafe impl Send for OffersMessageHandler {} unsafe impl Sync for OffersMessageHandler {} +#[allow(unused)] pub(crate) fn OffersMessageHandler_clone_fields(orig: &OffersMessageHandler) -> OffersMessageHandler { OffersMessageHandler { this_arg: orig.this_arg, handle_message: Clone::clone(&orig.handle_message), + release_pending_messages: Clone::clone(&orig.release_pending_messages), free: Clone::clone(&orig.free), } } @@ -49,6 +60,11 @@ impl rustOffersMessageHandler for OffersMessageHandler { let mut local_ret = { /*ret*/ let ret_opt = ret; if ret_opt.is_none() { None } else { Some({ { { ret_opt.take() }.into_native() }})} }; local_ret } + fn release_pending_messages(&self) -> Vec<(lightning::onion_message::offers::OffersMessage, lightning::onion_message::messenger::Destination, Option)> { + let mut ret = (self.release_pending_messages)(self.this_arg); + let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item.to_rust(); let mut local_orig_ret_0_2 = if orig_ret_0_2.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(orig_ret_0_2.take_inner()) } }) }; let mut local_ret_0 = (orig_ret_0_0.into_native(), orig_ret_0_1.into_native(), local_orig_ret_0_2); local_ret_0 }); }; + local_ret + } } // We're essentially a pointer already, or at least a set of pointers, so allow us to be used @@ -194,6 +210,16 @@ pub extern "C" fn OffersMessage_free(this_ptr: OffersMessage) { } pub extern "C" fn OffersMessage_clone(orig: &OffersMessage) -> OffersMessage { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn OffersMessage_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const OffersMessage)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn OffersMessage_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut OffersMessage) }; +} #[no_mangle] /// Utility method to constructs a new InvoiceRequest-variant OffersMessage pub extern "C" fn OffersMessage_invoice_request(a: crate::lightning::offers::invoice_request::InvoiceRequest) -> OffersMessage { @@ -217,19 +243,15 @@ pub extern "C" fn OffersMessage_is_known_type(mut tlv_type: u64) -> bool { ret } -/// The TLV record type for the message as used in an `onionmsg_tlv` TLV stream. -#[must_use] -#[no_mangle] -pub extern "C" fn OffersMessage_tlv_type(this_arg: &crate::lightning::onion_message::offers::OffersMessage) -> u64 { - let mut ret = this_arg.to_native().tlv_type(); - ret -} - #[no_mangle] /// Serialize the OffersMessage object into a byte array which can be read by OffersMessage_read pub extern "C" fn OffersMessage_write(obj: &crate::lightning::onion_message::offers::OffersMessage) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) } +#[allow(unused)] +pub(crate) extern "C" fn OffersMessage_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + OffersMessage_write(unsafe { &*(obj as *const OffersMessage) }) +} #[no_mangle] /// Read a OffersMessage from a byte array, created by OffersMessage_write pub extern "C" fn OffersMessage_read(ser: crate::c_types::u8slice, arg_a: u64, arg_b: &crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_OffersMessageDecodeErrorZ { diff --git a/lightning-c-bindings/src/lightning/onion_message/packet.rs b/lightning-c-bindings/src/lightning/onion_message/packet.rs index 94d6d65..37e3855 100644 --- a/lightning-c-bindings/src/lightning/onion_message/packet.rs +++ b/lightning-c-bindings/src/lightning/onion_message/packet.rs @@ -140,7 +140,7 @@ impl Clone for Packet { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Packet_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePacket)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePacket)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Packet @@ -161,113 +161,166 @@ pub extern "C" fn Packet_eq(a: &Packet, b: &Packet) -> bool { pub extern "C" fn Packet_write(obj: &crate::lightning::onion_message::packet::Packet) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn Packet_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePacket) }) } -/// The contents of an onion message. In the context of offers, this would be the invoice, invoice -/// request, or invoice error. +/// The contents of an [`OnionMessage`] as read from the wire. +/// +/// [`OnionMessage`]: crate::ln::msgs::OnionMessage #[derive(Clone)] #[must_use] #[repr(C)] -pub enum OnionMessageContents { +pub enum ParsedOnionMessageContents { /// A message related to BOLT 12 Offers. Offers( crate::lightning::onion_message::offers::OffersMessage), /// A custom onion message specified by the user. Custom( - crate::lightning::onion_message::packet::CustomOnionMessageContents), + crate::lightning::onion_message::packet::OnionMessageContents), } -use lightning::onion_message::packet::OnionMessageContents as OnionMessageContentsImport; -pub(crate) type nativeOnionMessageContents = OnionMessageContentsImport; +use lightning::onion_message::packet::ParsedOnionMessageContents as ParsedOnionMessageContentsImport; +pub(crate) type nativeParsedOnionMessageContents = ParsedOnionMessageContentsImport; -impl OnionMessageContents { +impl ParsedOnionMessageContents { #[allow(unused)] - pub(crate) fn to_native(&self) -> nativeOnionMessageContents { + pub(crate) fn to_native(&self) -> nativeParsedOnionMessageContents { match self { - OnionMessageContents::Offers (ref a, ) => { + ParsedOnionMessageContents::Offers (ref a, ) => { let mut a_nonref = Clone::clone(a); - nativeOnionMessageContents::Offers ( + nativeParsedOnionMessageContents::Offers ( a_nonref.into_native(), ) }, - OnionMessageContents::Custom (ref a, ) => { + ParsedOnionMessageContents::Custom (ref a, ) => { let mut a_nonref = Clone::clone(a); - nativeOnionMessageContents::Custom ( + nativeParsedOnionMessageContents::Custom ( a_nonref, ) }, } } #[allow(unused)] - pub(crate) fn into_native(self) -> nativeOnionMessageContents { + pub(crate) fn into_native(self) -> nativeParsedOnionMessageContents { match self { - OnionMessageContents::Offers (mut a, ) => { - nativeOnionMessageContents::Offers ( + ParsedOnionMessageContents::Offers (mut a, ) => { + nativeParsedOnionMessageContents::Offers ( a.into_native(), ) }, - OnionMessageContents::Custom (mut a, ) => { - nativeOnionMessageContents::Custom ( + ParsedOnionMessageContents::Custom (mut a, ) => { + nativeParsedOnionMessageContents::Custom ( a, ) }, } } #[allow(unused)] - pub(crate) fn from_native(native: &nativeOnionMessageContents) -> Self { + pub(crate) fn from_native(native: &nativeParsedOnionMessageContents) -> Self { match native { - nativeOnionMessageContents::Offers (ref a, ) => { + nativeParsedOnionMessageContents::Offers (ref a, ) => { let mut a_nonref = Clone::clone(a); - OnionMessageContents::Offers ( + ParsedOnionMessageContents::Offers ( crate::lightning::onion_message::offers::OffersMessage::native_into(a_nonref), ) }, - nativeOnionMessageContents::Custom (ref a, ) => { + nativeParsedOnionMessageContents::Custom (ref a, ) => { let mut a_nonref = Clone::clone(a); - OnionMessageContents::Custom ( + ParsedOnionMessageContents::Custom ( Into::into(a_nonref), ) }, } } #[allow(unused)] - pub(crate) fn native_into(native: nativeOnionMessageContents) -> Self { + pub(crate) fn native_into(native: nativeParsedOnionMessageContents) -> Self { match native { - nativeOnionMessageContents::Offers (mut a, ) => { - OnionMessageContents::Offers ( + nativeParsedOnionMessageContents::Offers (mut a, ) => { + ParsedOnionMessageContents::Offers ( crate::lightning::onion_message::offers::OffersMessage::native_into(a), ) }, - nativeOnionMessageContents::Custom (mut a, ) => { - OnionMessageContents::Custom ( + nativeParsedOnionMessageContents::Custom (mut a, ) => { + ParsedOnionMessageContents::Custom ( Into::into(a), ) }, } } } -/// Frees any resources used by the OnionMessageContents +/// Frees any resources used by the ParsedOnionMessageContents #[no_mangle] -pub extern "C" fn OnionMessageContents_free(this_ptr: OnionMessageContents) { } -/// Creates a copy of the OnionMessageContents +pub extern "C" fn ParsedOnionMessageContents_free(this_ptr: ParsedOnionMessageContents) { } +/// Creates a copy of the ParsedOnionMessageContents #[no_mangle] -pub extern "C" fn OnionMessageContents_clone(orig: &OnionMessageContents) -> OnionMessageContents { +pub extern "C" fn ParsedOnionMessageContents_clone(orig: &ParsedOnionMessageContents) -> ParsedOnionMessageContents { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ParsedOnionMessageContents_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const ParsedOnionMessageContents)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ParsedOnionMessageContents_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut ParsedOnionMessageContents) }; +} +#[no_mangle] +/// Utility method to constructs a new Offers-variant ParsedOnionMessageContents +pub extern "C" fn ParsedOnionMessageContents_offers(a: crate::lightning::onion_message::offers::OffersMessage) -> ParsedOnionMessageContents { + ParsedOnionMessageContents::Offers(a, ) +} +#[no_mangle] +/// Utility method to constructs a new Custom-variant ParsedOnionMessageContents +pub extern "C" fn ParsedOnionMessageContents_custom(a: crate::lightning::onion_message::packet::OnionMessageContents) -> ParsedOnionMessageContents { + ParsedOnionMessageContents::Custom(a, ) +} +impl From for crate::lightning::onion_message::packet::OnionMessageContents { + fn from(obj: nativeParsedOnionMessageContents) -> Self { + let rust_obj = crate::lightning::onion_message::packet::ParsedOnionMessageContents::native_into(obj); + let mut ret = ParsedOnionMessageContents_as_OnionMessageContents(&rust_obj); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); + ret.free = Some(ParsedOnionMessageContents_free_void); + ret + } +} +/// Constructs a new OnionMessageContents which calls the relevant methods on this_arg. +/// This copies the `inner` pointer in this_arg and thus the returned OnionMessageContents must be freed before this_arg is #[no_mangle] -/// Utility method to constructs a new Offers-variant OnionMessageContents -pub extern "C" fn OnionMessageContents_offers(a: crate::lightning::onion_message::offers::OffersMessage) -> OnionMessageContents { - OnionMessageContents::Offers(a, ) +pub extern "C" fn ParsedOnionMessageContents_as_OnionMessageContents(this_arg: &ParsedOnionMessageContents) -> crate::lightning::onion_message::packet::OnionMessageContents { + crate::lightning::onion_message::packet::OnionMessageContents { + this_arg: unsafe { ObjOps::untweak_ptr(this_arg as *const ParsedOnionMessageContents as *mut ParsedOnionMessageContents) as *mut c_void }, + free: None, + tlv_type: ParsedOnionMessageContents_OnionMessageContents_tlv_type, + write: ParsedOnionMessageContents_write_void, + cloned: Some(OnionMessageContents_ParsedOnionMessageContents_cloned), + } +} + +#[must_use] +extern "C" fn ParsedOnionMessageContents_OnionMessageContents_tlv_type(this_arg: *const c_void) -> u64 { + let mut ret = >::tlv_type(unsafe { &mut *(this_arg as *mut nativeParsedOnionMessageContents) }, ); + ret } +extern "C" fn OnionMessageContents_ParsedOnionMessageContents_cloned(new_obj: &mut crate::lightning::onion_message::packet::OnionMessageContents) { + new_obj.this_arg = ParsedOnionMessageContents_clone_void(new_obj.this_arg); + new_obj.free = Some(ParsedOnionMessageContents_free_void); +} + #[no_mangle] -/// Utility method to constructs a new Custom-variant OnionMessageContents -pub extern "C" fn OnionMessageContents_custom(a: crate::lightning::onion_message::packet::CustomOnionMessageContents) -> OnionMessageContents { - OnionMessageContents::Custom(a, ) +/// Serialize the ParsedOnionMessageContents object into a byte array which can be read by ParsedOnionMessageContents_read +pub extern "C" fn ParsedOnionMessageContents_write(obj: &crate::lightning::onion_message::packet::ParsedOnionMessageContents) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) +} +#[allow(unused)] +pub(crate) extern "C" fn ParsedOnionMessageContents_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + ParsedOnionMessageContents_write(unsafe { &*(obj as *const ParsedOnionMessageContents) }) } -/// The contents of a custom onion message. +/// The contents of an onion message. #[repr(C)] -pub struct CustomOnionMessageContents { +pub struct OnionMessageContents { /// An opaque pointer which is passed to your function implementations as an argument. /// This has no meaning in the LDK, and can be NULL or any other value. pub this_arg: *mut c_void, @@ -275,18 +328,19 @@ pub struct CustomOnionMessageContents { pub tlv_type: extern "C" fn (this_arg: *const c_void) -> u64, /// Serialize the object into a byte array pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z, - /// Called, if set, after this CustomOnionMessageContents has been cloned into a duplicate object. - /// The new CustomOnionMessageContents is provided, and should be mutated as needed to perform a + /// Called, if set, after this OnionMessageContents has been cloned into a duplicate object. + /// The new OnionMessageContents is provided, and should be mutated as needed to perform a /// deep copy of the object pointed to by this_arg or avoid any double-freeing. - pub cloned: Option, + pub cloned: Option, /// Frees any resources associated with this object given its this_arg pointer. /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. pub free: Option, } -unsafe impl Send for CustomOnionMessageContents {} -unsafe impl Sync for CustomOnionMessageContents {} -pub(crate) fn CustomOnionMessageContents_clone_fields(orig: &CustomOnionMessageContents) -> CustomOnionMessageContents { - CustomOnionMessageContents { +unsafe impl Send for OnionMessageContents {} +unsafe impl Sync for OnionMessageContents {} +#[allow(unused)] +pub(crate) fn OnionMessageContents_clone_fields(orig: &OnionMessageContents) -> OnionMessageContents { + OnionMessageContents { this_arg: orig.this_arg, tlv_type: Clone::clone(&orig.tlv_type), write: Clone::clone(&orig.write), @@ -294,27 +348,27 @@ pub(crate) fn CustomOnionMessageContents_clone_fields(orig: &CustomOnionMessageC free: Clone::clone(&orig.free), } } -impl lightning::util::ser::Writeable for CustomOnionMessageContents { +impl lightning::util::ser::Writeable for OnionMessageContents { fn write(&self, w: &mut W) -> Result<(), crate::c_types::io::Error> { let vec = (self.write)(self.this_arg); w.write_all(vec.as_slice()) } } #[no_mangle] -/// Creates a copy of a CustomOnionMessageContents -pub extern "C" fn CustomOnionMessageContents_clone(orig: &CustomOnionMessageContents) -> CustomOnionMessageContents { - let mut res = CustomOnionMessageContents_clone_fields(orig); +/// Creates a copy of a OnionMessageContents +pub extern "C" fn OnionMessageContents_clone(orig: &OnionMessageContents) -> OnionMessageContents { + let mut res = OnionMessageContents_clone_fields(orig); if let Some(f) = orig.cloned { (f)(&mut res) }; res } -impl Clone for CustomOnionMessageContents { +impl Clone for OnionMessageContents { fn clone(&self) -> Self { - CustomOnionMessageContents_clone(self) + OnionMessageContents_clone(self) } } -use lightning::onion_message::packet::CustomOnionMessageContents as rustCustomOnionMessageContents; -impl rustCustomOnionMessageContents for CustomOnionMessageContents { +use lightning::onion_message::packet::OnionMessageContents as rustOnionMessageContents; +impl rustOnionMessageContents for OnionMessageContents { fn tlv_type(&self) -> u64 { let mut ret = (self.tlv_type)(self.this_arg); ret @@ -323,21 +377,21 @@ impl rustCustomOnionMessageContents for CustomOnionMessageContents { // We're essentially a pointer already, or at least a set of pointers, so allow us to be used // directly as a Deref trait in higher-level structs: -impl core::ops::Deref for CustomOnionMessageContents { +impl core::ops::Deref for OnionMessageContents { type Target = Self; fn deref(&self) -> &Self { self } } -impl core::ops::DerefMut for CustomOnionMessageContents { +impl core::ops::DerefMut for OnionMessageContents { fn deref_mut(&mut self) -> &mut Self { self } } /// Calls the free function if one is set #[no_mangle] -pub extern "C" fn CustomOnionMessageContents_free(this_ptr: CustomOnionMessageContents) { } -impl Drop for CustomOnionMessageContents { +pub extern "C" fn OnionMessageContents_free(this_ptr: OnionMessageContents) { } +impl Drop for OnionMessageContents { fn drop(&mut self) { if let Some(f) = self.free { f(self.this_arg); diff --git a/lightning-c-bindings/src/lightning/routing/gossip.rs b/lightning-c-bindings/src/lightning/routing/gossip.rs index bef0af5..e86caa4 100644 --- a/lightning-c-bindings/src/lightning/routing/gossip.rs +++ b/lightning-c-bindings/src/lightning/routing/gossip.rs @@ -80,7 +80,7 @@ impl Clone for NodeId { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn NodeId_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeId)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeNodeId)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the NodeId @@ -128,7 +128,7 @@ pub extern "C" fn NodeId_hash(o: &NodeId) -> u64 { pub extern "C" fn NodeId_write(obj: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn NodeId_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeId) }) } @@ -385,6 +385,16 @@ pub extern "C" fn NetworkUpdate_free(this_ptr: NetworkUpdate) { } pub extern "C" fn NetworkUpdate_clone(orig: &NetworkUpdate) -> NetworkUpdate { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn NetworkUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const NetworkUpdate)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn NetworkUpdate_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut NetworkUpdate) }; +} #[no_mangle] /// Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate pub extern "C" fn NetworkUpdate_channel_update_message(msg: crate::lightning::ln::msgs::ChannelUpdate) -> NetworkUpdate { @@ -419,6 +429,10 @@ pub extern "C" fn NetworkUpdate_eq(a: &NetworkUpdate, b: &NetworkUpdate) -> bool pub extern "C" fn NetworkUpdate_write(obj: &crate::lightning::routing::gossip::NetworkUpdate) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) } +#[allow(unused)] +pub(crate) extern "C" fn NetworkUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + NetworkUpdate_write(unsafe { &*(obj as *const NetworkUpdate) }) +} #[no_mangle] /// Read a NetworkUpdate from a byte array, created by NetworkUpdate_write pub extern "C" fn NetworkUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_NetworkUpdateZDecodeErrorZ { @@ -503,6 +517,8 @@ pub extern "C" fn P2PGossipSync_add_utxo_lookup(this_arg: &crate::lightning::rou } /// Handles any network updates originating from [`Event`]s. +/// Note that this will skip applying any [`NetworkUpdate::ChannelUpdateMessage`] to avoid +/// leaking possibly identifying information of the sender to the public network. /// /// [`Event`]: crate::events::Event #[no_mangle] @@ -510,12 +526,12 @@ pub extern "C" fn NetworkGraph_handle_network_update(this_arg: &crate::lightning unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.handle_network_update(&network_update.to_native()) } -/// Gets the genesis hash for this network graph. +/// Gets the chain hash for this network graph. #[must_use] #[no_mangle] -pub extern "C" fn NetworkGraph_get_genesis_hash(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::ThirtyTwoBytes { - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_genesis_hash(); - crate::c_types::ThirtyTwoBytes { data: ret.into_inner() } +pub extern "C" fn NetworkGraph_get_chain_hash(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::ThirtyTwoBytes { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_chain_hash(); + crate::c_types::ThirtyTwoBytes { data: ret.to_bytes() } } /// Verifies the signature of a [`NodeAnnouncement`]. @@ -540,10 +556,10 @@ pub extern "C" fn verify_channel_announcement(msg: &crate::lightning::ln::msgs:: impl From for crate::lightning::ln::msgs::RoutingMessageHandler { fn from(obj: nativeP2PGossipSync) -> Self { - let mut rust_obj = P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::routing::gossip::P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = P2PGossipSync_as_RoutingMessageHandler(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(P2PGossipSync_free_void); ret } @@ -655,10 +671,10 @@ extern "C" fn P2PGossipSync_RoutingMessageHandler_provided_init_features(this_ar impl From for crate::lightning::events::MessageSendEventsProvider { fn from(obj: nativeP2PGossipSync) -> Self { - let mut rust_obj = P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::routing::gossip::P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = P2PGossipSync_as_MessageSendEventsProvider(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(P2PGossipSync_free_void); ret } @@ -852,7 +868,7 @@ impl Clone for ChannelUpdateInfo { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelUpdateInfo_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelUpdateInfo)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelUpdateInfo)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelUpdateInfo @@ -873,7 +889,7 @@ pub extern "C" fn ChannelUpdateInfo_eq(a: &ChannelUpdateInfo, b: &ChannelUpdateI pub extern "C" fn ChannelUpdateInfo_write(obj: &crate::lightning::routing::gossip::ChannelUpdateInfo) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelUpdateInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelUpdateInfo) }) } @@ -1051,7 +1067,7 @@ impl Clone for ChannelInfo { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelInfo)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelInfo)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelInfo @@ -1083,7 +1099,7 @@ pub extern "C" fn ChannelInfo_get_directional_info(this_arg: &crate::lightning:: pub extern "C" fn ChannelInfo_write(obj: &crate::lightning::routing::gossip::ChannelInfo) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) }) } @@ -1158,7 +1174,7 @@ impl Clone for DirectedChannelInfo { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn DirectedChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectedChannelInfo)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeDirectedChannelInfo)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the DirectedChannelInfo @@ -1367,6 +1383,16 @@ pub extern "C" fn EffectiveCapacity_free(this_ptr: EffectiveCapacity) { } pub extern "C" fn EffectiveCapacity_clone(orig: &EffectiveCapacity) -> EffectiveCapacity { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn EffectiveCapacity_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const EffectiveCapacity)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn EffectiveCapacity_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut EffectiveCapacity) }; +} #[no_mangle] /// Utility method to constructs a new ExactLiquidity-variant EffectiveCapacity pub extern "C" fn EffectiveCapacity_exact_liquidity(liquidity_msat: u64) -> EffectiveCapacity { @@ -1522,7 +1548,7 @@ impl Clone for RoutingFees { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRoutingFees)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the RoutingFees @@ -1544,7 +1570,7 @@ pub extern "C" fn RoutingFees_hash(o: &RoutingFees) -> u64 { pub extern "C" fn RoutingFees_write(obj: &crate::lightning::routing::gossip::RoutingFees) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) }) } @@ -1706,7 +1732,7 @@ impl Clone for NodeAnnouncementInfo { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeNodeAnnouncementInfo)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the NodeAnnouncementInfo @@ -1736,7 +1762,7 @@ pub extern "C" fn NodeAnnouncementInfo_addresses(this_arg: &crate::lightning::ro pub extern "C" fn NodeAnnouncementInfo_write(obj: &crate::lightning::routing::gossip::NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) }) } @@ -1830,7 +1856,7 @@ impl Clone for NodeAlias { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn NodeAlias_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAlias)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeNodeAlias)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the NodeAlias @@ -1851,7 +1877,7 @@ pub extern "C" fn NodeAlias_eq(a: &NodeAlias, b: &NodeAlias) -> bool { pub extern "C" fn NodeAlias_write(obj: &crate::lightning::routing::gossip::NodeAlias) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn NodeAlias_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAlias) }) } @@ -1974,7 +2000,7 @@ impl Clone for NodeInfo { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeNodeInfo)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the NodeInfo @@ -1995,7 +2021,7 @@ pub extern "C" fn NodeInfo_eq(a: &NodeInfo, b: &NodeInfo) -> bool { pub extern "C" fn NodeInfo_write(obj: &crate::lightning::routing::gossip::NodeInfo) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) }) } @@ -2011,7 +2037,7 @@ pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types: pub extern "C" fn NetworkGraph_write(obj: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) }) } @@ -2200,8 +2226,8 @@ pub extern "C" fn NetworkGraph_remove_stale_channels_and_tracking_with_time(this /// For an already known (from announcement) channel, update info about one of the directions /// of the channel. /// -/// You probably don't want to call this directly, instead relying on a P2PGossipSync's -/// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept +/// You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s +/// [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept /// routing messages from a source using a protocol other than the lightning P2P protocol. /// /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or @@ -2228,6 +2254,20 @@ pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &crate::lightni local_ret } +/// For an already known (from announcement) channel, verify the given [`ChannelUpdate`]. +/// +/// This checks whether the update currently is applicable by [`Self::update_channel`]. +/// +/// If built with `no-std`, any updates with a timestamp more than two weeks in the past or +/// materially in the future will be rejected. +#[must_use] +#[no_mangle] +pub extern "C" fn NetworkGraph_verify_channel_update(this_arg: &crate::lightning::routing::gossip::NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.verify_channel_update(msg.get_native_ref()); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + local_ret +} + /// Returns information on a channel with the given id. /// /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None diff --git a/lightning-c-bindings/src/lightning/routing/router.rs b/lightning-c-bindings/src/lightning/routing/router.rs index 4594db3..47b8336 100644 --- a/lightning-c-bindings/src/lightning/routing/router.rs +++ b/lightning-c-bindings/src/lightning/routing/router.rs @@ -78,10 +78,10 @@ pub extern "C" fn DefaultRouter_new(network_graph: &crate::lightning::routing::g impl From for crate::lightning::routing::router::Router { fn from(obj: nativeDefaultRouter) -> Self { - let mut rust_obj = DefaultRouter { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::routing::router::DefaultRouter { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = DefaultRouter_as_Router(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(DefaultRouter_free_void); ret } @@ -142,6 +142,7 @@ pub struct Router { } unsafe impl Send for Router {} unsafe impl Sync for Router {} +#[allow(unused)] pub(crate) fn Router_clone_fields(orig: &Router) -> Router { Router { this_arg: orig.this_arg, @@ -256,10 +257,10 @@ pub extern "C" fn ScorerAccountingForInFlightHtlcs_new(mut scorer: crate::lightn impl From for crate::lightning::routing::scoring::ScoreLookUp { fn from(obj: nativeScorerAccountingForInFlightHtlcs) -> Self { - let mut rust_obj = ScorerAccountingForInFlightHtlcs { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::routing::router::ScorerAccountingForInFlightHtlcs { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = ScorerAccountingForInFlightHtlcs_as_ScoreLookUp(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(ScorerAccountingForInFlightHtlcs_free_void); ret } @@ -345,7 +346,7 @@ impl Clone for InFlightHtlcs { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn InFlightHtlcs_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInFlightHtlcs)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeInFlightHtlcs)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the InFlightHtlcs @@ -388,7 +389,7 @@ pub extern "C" fn InFlightHtlcs_used_liquidity_msat(this_arg: &crate::lightning: pub extern "C" fn InFlightHtlcs_write(obj: &crate::lightning::routing::router::InFlightHtlcs) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn InFlightHtlcs_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInFlightHtlcs) }) } @@ -592,7 +593,7 @@ impl Clone for RouteHop { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn RouteHop_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHop)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRouteHop)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the RouteHop @@ -623,7 +624,7 @@ pub extern "C" fn RouteHop_eq(a: &RouteHop, b: &RouteHop) -> bool { pub extern "C" fn RouteHop_write(obj: &crate::lightning::routing::router::RouteHop) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn RouteHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHop) }) } @@ -768,7 +769,7 @@ impl Clone for BlindedTail { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn BlindedTail_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBlindedTail)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBlindedTail)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the BlindedTail @@ -799,7 +800,7 @@ pub extern "C" fn BlindedTail_eq(a: &BlindedTail, b: &BlindedTail) -> bool { pub extern "C" fn BlindedTail_write(obj: &crate::lightning::routing::router::BlindedTail) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn BlindedTail_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBlindedTail) }) } @@ -917,7 +918,7 @@ impl Clone for Path { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Path_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePath)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePath)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Path @@ -1087,7 +1088,7 @@ impl Clone for Route { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Route_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoute)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRoute)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Route @@ -1145,7 +1146,7 @@ pub extern "C" fn Route_get_total_amount(this_arg: &crate::lightning::routing::r pub extern "C" fn Route_write(obj: &crate::lightning::routing::router::Route) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn Route_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoute) }) } @@ -1277,7 +1278,7 @@ impl Clone for RouteParameters { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn RouteParameters_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteParameters)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRouteParameters)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the RouteParameters @@ -1318,7 +1319,7 @@ pub extern "C" fn RouteParameters_from_payment_params_and_value(mut payment_para pub extern "C" fn RouteParameters_write(obj: &crate::lightning::routing::router::RouteParameters) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn RouteParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteParameters) }) } @@ -1519,7 +1520,7 @@ impl Clone for PaymentParameters { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn PaymentParameters_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePaymentParameters)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePaymentParameters)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the PaymentParameters @@ -1550,7 +1551,7 @@ pub extern "C" fn PaymentParameters_eq(a: &PaymentParameters, b: &PaymentParamet pub extern "C" fn PaymentParameters_write(obj: &crate::lightning::routing::router::PaymentParameters) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn PaymentParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePaymentParameters) }) } @@ -1766,6 +1767,16 @@ pub extern "C" fn Payee_free(this_ptr: Payee) { } pub extern "C" fn Payee_clone(orig: &Payee) -> Payee { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Payee_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Payee)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Payee_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut Payee) }; +} #[no_mangle] /// Utility method to constructs a new Blinded-variant Payee pub extern "C" fn Payee_blinded(route_hints: crate::c_types::derived::CVec_C2Tuple_BlindedPayInfoBlindedPathZZ, features: crate::lightning::ln::features::Bolt12InvoiceFeatures) -> Payee { @@ -1882,7 +1893,7 @@ impl Clone for RouteHint { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHint)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRouteHint)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the RouteHint @@ -1913,7 +1924,7 @@ pub extern "C" fn RouteHint_eq(a: &RouteHint, b: &RouteHint) -> bool { pub extern "C" fn RouteHint_write(obj: &crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn RouteHint_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHint) }) } @@ -2072,7 +2083,7 @@ impl Clone for RouteHintHop { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn RouteHintHop_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHintHop)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRouteHintHop)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the RouteHintHop @@ -2103,7 +2114,7 @@ pub extern "C" fn RouteHintHop_eq(a: &RouteHintHop, b: &RouteHintHop) -> bool { pub extern "C" fn RouteHintHop_write(obj: &crate::lightning::routing::router::RouteHintHop) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn RouteHintHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHintHop) }) } diff --git a/lightning-c-bindings/src/lightning/routing/scoring.rs b/lightning-c-bindings/src/lightning/routing/scoring.rs index 8060fbf..3ebead9 100644 --- a/lightning-c-bindings/src/lightning/routing/scoring.rs +++ b/lightning-c-bindings/src/lightning/routing/scoring.rs @@ -89,6 +89,7 @@ pub struct ScoreLookUp { } unsafe impl Send for ScoreLookUp {} unsafe impl Sync for ScoreLookUp {} +#[allow(unused)] pub(crate) fn ScoreLookUp_clone_fields(orig: &ScoreLookUp) -> ScoreLookUp { ScoreLookUp { this_arg: orig.this_arg, @@ -148,6 +149,7 @@ pub struct ScoreUpdate { } unsafe impl Send for ScoreUpdate {} unsafe impl Sync for ScoreUpdate {} +#[allow(unused)] pub(crate) fn ScoreUpdate_clone_fields(orig: &ScoreUpdate) -> ScoreUpdate { ScoreUpdate { this_arg: orig.this_arg, @@ -221,6 +223,7 @@ pub struct Score { } unsafe impl Send for Score {} unsafe impl Sync for Score {} +#[allow(unused)] pub(crate) fn Score_clone_fields(orig: &Score) -> Score { Score { this_arg: orig.this_arg, @@ -307,6 +310,7 @@ pub struct LockableScore { } unsafe impl Send for LockableScore {} unsafe impl Sync for LockableScore {} +#[allow(unused)] pub(crate) fn LockableScore_clone_fields(orig: &LockableScore) -> LockableScore { LockableScore { this_arg: orig.this_arg, @@ -374,6 +378,7 @@ pub struct WriteableScore { } unsafe impl Send for WriteableScore {} unsafe impl Sync for WriteableScore {} +#[allow(unused)] pub(crate) fn WriteableScore_clone_fields(orig: &WriteableScore) -> WriteableScore { WriteableScore { this_arg: orig.this_arg, @@ -483,10 +488,10 @@ impl MultiThreadedLockableScore { } impl From for crate::lightning::routing::scoring::LockableScore { fn from(obj: nativeMultiThreadedLockableScore) -> Self { - let mut rust_obj = MultiThreadedLockableScore { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::routing::scoring::MultiThreadedLockableScore { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = MultiThreadedLockableScore_as_LockableScore(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(MultiThreadedLockableScore_free_void); ret } @@ -519,16 +524,16 @@ extern "C" fn MultiThreadedLockableScore_LockableScore_write_lock(this_arg: *con pub extern "C" fn MultiThreadedLockableScore_write(obj: &crate::lightning::routing::scoring::MultiThreadedLockableScore) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn MultiThreadedLockableScore_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeMultiThreadedLockableScore) }) } impl From for crate::lightning::routing::scoring::WriteableScore { fn from(obj: nativeMultiThreadedLockableScore) -> Self { - let mut rust_obj = MultiThreadedLockableScore { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::routing::scoring::MultiThreadedLockableScore { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = MultiThreadedLockableScore_as_WriteableScore(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(MultiThreadedLockableScore_free_void); ret } @@ -663,10 +668,10 @@ impl MultiThreadedScoreLockWrite { } impl From for crate::lightning::routing::scoring::ScoreLookUp { fn from(obj: nativeMultiThreadedScoreLockRead) -> Self { - let mut rust_obj = MultiThreadedScoreLockRead { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::routing::scoring::MultiThreadedScoreLockRead { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = MultiThreadedScoreLockRead_as_ScoreLookUp(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(MultiThreadedScoreLockRead_free_void); ret } @@ -693,16 +698,16 @@ extern "C" fn MultiThreadedScoreLockRead_ScoreLookUp_channel_penalty_msat(this_a pub extern "C" fn MultiThreadedScoreLockWrite_write(obj: &crate::lightning::routing::scoring::MultiThreadedScoreLockWrite) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn MultiThreadedScoreLockWrite_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeMultiThreadedScoreLockWrite) }) } impl From for crate::lightning::routing::scoring::ScoreUpdate { fn from(obj: nativeMultiThreadedScoreLockWrite) -> Self { - let mut rust_obj = MultiThreadedScoreLockWrite { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::routing::scoring::MultiThreadedScoreLockWrite { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = MultiThreadedScoreLockWrite_as_ScoreUpdate(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(MultiThreadedScoreLockWrite_free_void); ret } @@ -842,7 +847,7 @@ impl Clone for ChannelUsage { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelUsage_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelUsage)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelUsage)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelUsage @@ -912,7 +917,7 @@ impl Clone for FixedPenaltyScorer { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn FixedPenaltyScorer_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeFixedPenaltyScorer)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeFixedPenaltyScorer)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the FixedPenaltyScorer @@ -929,10 +934,10 @@ pub extern "C" fn FixedPenaltyScorer_with_penalty(mut penalty_msat: u64) -> crat impl From for crate::lightning::routing::scoring::ScoreLookUp { fn from(obj: nativeFixedPenaltyScorer) -> Self { - let mut rust_obj = FixedPenaltyScorer { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::routing::scoring::FixedPenaltyScorer { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = FixedPenaltyScorer_as_ScoreLookUp(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(FixedPenaltyScorer_free_void); ret } @@ -956,10 +961,10 @@ extern "C" fn FixedPenaltyScorer_ScoreLookUp_channel_penalty_msat(this_arg: *con impl From for crate::lightning::routing::scoring::ScoreUpdate { fn from(obj: nativeFixedPenaltyScorer) -> Self { - let mut rust_obj = FixedPenaltyScorer { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::routing::scoring::FixedPenaltyScorer { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = FixedPenaltyScorer_as_ScoreUpdate(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(FixedPenaltyScorer_free_void); ret } @@ -996,7 +1001,7 @@ extern "C" fn FixedPenaltyScorer_ScoreUpdate_probe_successful(this_arg: *mut c_v pub extern "C" fn FixedPenaltyScorer_write(obj: &crate::lightning::routing::scoring::FixedPenaltyScorer) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn FixedPenaltyScorer_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeFixedPenaltyScorer) }) } @@ -1502,7 +1507,7 @@ impl Clone for ProbabilisticScoringFeeParameters { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ProbabilisticScoringFeeParameters_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeProbabilisticScoringFeeParameters)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeProbabilisticScoringFeeParameters)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ProbabilisticScoringFeeParameters @@ -1708,7 +1713,7 @@ impl Clone for ProbabilisticScoringDecayParameters { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ProbabilisticScoringDecayParameters_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeProbabilisticScoringDecayParameters)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeProbabilisticScoringDecayParameters)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ProbabilisticScoringDecayParameters @@ -1800,10 +1805,10 @@ pub extern "C" fn ProbabilisticScorer_historical_estimated_payment_success_proba impl From for crate::lightning::routing::scoring::ScoreLookUp { fn from(obj: nativeProbabilisticScorer) -> Self { - let mut rust_obj = ProbabilisticScorer { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::routing::scoring::ProbabilisticScorer { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = ProbabilisticScorer_as_ScoreLookUp(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(ProbabilisticScorer_free_void); ret } @@ -1827,10 +1832,10 @@ extern "C" fn ProbabilisticScorer_ScoreLookUp_channel_penalty_msat(this_arg: *co impl From for crate::lightning::routing::scoring::ScoreUpdate { fn from(obj: nativeProbabilisticScorer) -> Self { - let mut rust_obj = ProbabilisticScorer { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::routing::scoring::ProbabilisticScorer { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = ProbabilisticScorer_as_ScoreUpdate(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(ProbabilisticScorer_free_void); ret } @@ -1864,10 +1869,10 @@ extern "C" fn ProbabilisticScorer_ScoreUpdate_probe_successful(this_arg: *mut c_ impl From for crate::lightning::routing::scoring::Score { fn from(obj: nativeProbabilisticScorer) -> Self { - let mut rust_obj = ProbabilisticScorer { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::routing::scoring::ProbabilisticScorer { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = ProbabilisticScorer_as_Score(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(ProbabilisticScorer_free_void); ret } @@ -1926,7 +1931,7 @@ use alloc::{vec::Vec, boxed::Box}; pub extern "C" fn ProbabilisticScorer_write(obj: &crate::lightning::routing::scoring::ProbabilisticScorer) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ProbabilisticScorer_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeProbabilisticScorer) }) } diff --git a/lightning-c-bindings/src/lightning/routing/utxo.rs b/lightning-c-bindings/src/lightning/routing/utxo.rs index 187badd..6ebae6c 100644 --- a/lightning-c-bindings/src/lightning/routing/utxo.rs +++ b/lightning-c-bindings/src/lightning/routing/utxo.rs @@ -69,6 +69,16 @@ impl UtxoLookupError { pub extern "C" fn UtxoLookupError_clone(orig: &UtxoLookupError) -> UtxoLookupError { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn UtxoLookupError_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const UtxoLookupError)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn UtxoLookupError_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut UtxoLookupError) }; +} #[no_mangle] /// Utility method to constructs a new UnknownChain-variant UtxoLookupError pub extern "C" fn UtxoLookupError_unknown_chain() -> UtxoLookupError { @@ -179,6 +189,16 @@ pub extern "C" fn UtxoResult_free(this_ptr: UtxoResult) { } pub extern "C" fn UtxoResult_clone(orig: &UtxoResult) -> UtxoResult { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn UtxoResult_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const UtxoResult)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn UtxoResult_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut UtxoResult) }; +} #[no_mangle] /// Utility method to constructs a new Sync-variant UtxoResult pub extern "C" fn UtxoResult_sync(a: crate::c_types::derived::CResult_TxOutUtxoLookupErrorZ) -> UtxoResult { @@ -196,17 +216,18 @@ pub struct UtxoLookup { /// This has no meaning in the LDK, and can be NULL or any other value. pub this_arg: *mut c_void, /// Returns the transaction output of a funding transaction encoded by [`short_channel_id`]. - /// Returns an error if `genesis_hash` is for a different chain or if such a transaction output - /// is unknown. + /// Returns an error if `chain_hash` is for a different chain or if such a transaction output is + /// unknown. /// /// [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id - pub get_utxo: extern "C" fn (this_arg: *const c_void, genesis_hash: *const [u8; 32], short_channel_id: u64) -> crate::lightning::routing::utxo::UtxoResult, + pub get_utxo: extern "C" fn (this_arg: *const c_void, chain_hash: *const [u8; 32], short_channel_id: u64) -> crate::lightning::routing::utxo::UtxoResult, /// Frees any resources associated with this object given its this_arg pointer. /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. pub free: Option, } unsafe impl Send for UtxoLookup {} unsafe impl Sync for UtxoLookup {} +#[allow(unused)] pub(crate) fn UtxoLookup_clone_fields(orig: &UtxoLookup) -> UtxoLookup { UtxoLookup { this_arg: orig.this_arg, @@ -217,8 +238,8 @@ pub(crate) fn UtxoLookup_clone_fields(orig: &UtxoLookup) -> UtxoLookup { use lightning::routing::utxo::UtxoLookup as rustUtxoLookup; impl rustUtxoLookup for UtxoLookup { - fn get_utxo(&self, mut genesis_hash: &bitcoin::BlockHash, mut short_channel_id: u64) -> lightning::routing::utxo::UtxoResult { - let mut ret = (self.get_utxo)(self.this_arg, genesis_hash.as_inner(), short_channel_id); + fn get_utxo(&self, mut chain_hash: &bitcoin::blockdata::constants::ChainHash, mut short_channel_id: u64) -> lightning::routing::utxo::UtxoResult { + let mut ret = (self.get_utxo)(self.this_arg, chain_hash.as_bytes(), short_channel_id); ret.into_native() } } @@ -311,7 +332,7 @@ impl Clone for UtxoFuture { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UtxoFuture_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUtxoFuture)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUtxoFuture)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the UtxoFuture diff --git a/lightning-c-bindings/src/lightning/sign.rs b/lightning-c-bindings/src/lightning/sign.rs index ded5264..4ef5cce 100644 --- a/lightning-c-bindings/src/lightning/sign.rs +++ b/lightning-c-bindings/src/lightning/sign.rs @@ -194,7 +194,7 @@ impl Clone for DelayedPaymentOutputDescriptor { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDelayedPaymentOutputDescriptor)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeDelayedPaymentOutputDescriptor)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the DelayedPaymentOutputDescriptor @@ -225,7 +225,7 @@ pub extern "C" fn DelayedPaymentOutputDescriptor_eq(a: &DelayedPaymentOutputDesc pub extern "C" fn DelayedPaymentOutputDescriptor_write(obj: &crate::lightning::sign::DelayedPaymentOutputDescriptor) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDelayedPaymentOutputDescriptor) }) } @@ -385,7 +385,7 @@ impl Clone for StaticPaymentOutputDescriptor { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn StaticPaymentOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeStaticPaymentOutputDescriptor)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeStaticPaymentOutputDescriptor)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the StaticPaymentOutputDescriptor @@ -438,7 +438,7 @@ pub extern "C" fn StaticPaymentOutputDescriptor_max_witness_length(this_arg: &cr pub extern "C" fn StaticPaymentOutputDescriptor_write(obj: &crate::lightning::sign::StaticPaymentOutputDescriptor) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn StaticPaymentOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeStaticPaymentOutputDescriptor) }) } @@ -641,6 +641,16 @@ pub extern "C" fn SpendableOutputDescriptor_free(this_ptr: SpendableOutputDescri pub extern "C" fn SpendableOutputDescriptor_clone(orig: &SpendableOutputDescriptor) -> SpendableOutputDescriptor { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn SpendableOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const SpendableOutputDescriptor)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn SpendableOutputDescriptor_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut SpendableOutputDescriptor) }; +} #[no_mangle] /// Utility method to constructs a new StaticOutput-variant SpendableOutputDescriptor pub extern "C" fn SpendableOutputDescriptor_static_output(outpoint: crate::lightning::chain::transaction::OutPoint, output: crate::c_types::TxOut) -> SpendableOutputDescriptor { @@ -679,6 +689,10 @@ pub extern "C" fn SpendableOutputDescriptor_eq(a: &SpendableOutputDescriptor, b: pub extern "C" fn SpendableOutputDescriptor_write(obj: &crate::lightning::sign::SpendableOutputDescriptor) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) } +#[allow(unused)] +pub(crate) extern "C" fn SpendableOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + SpendableOutputDescriptor_write(unsafe { &*(obj as *const SpendableOutputDescriptor) }) +} #[no_mangle] /// Read a SpendableOutputDescriptor from a byte array, created by SpendableOutputDescriptor_write pub extern "C" fn SpendableOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SpendableOutputDescriptorDecodeErrorZ { @@ -713,6 +727,395 @@ pub extern "C" fn SpendableOutputDescriptor_create_spendable_outputs_psbt(mut de local_ret } + +use lightning::sign::ChannelDerivationParameters as nativeChannelDerivationParametersImport; +pub(crate) type nativeChannelDerivationParameters = nativeChannelDerivationParametersImport; + +/// The parameters required to derive a channel signer via [`SignerProvider`]. +#[must_use] +#[repr(C)] +pub struct ChannelDerivationParameters { + /// A pointer to the opaque Rust object. + + /// Nearly everywhere, inner must be non-null, however in places where + /// the Rust equivalent takes an Option, it may be set to null to indicate None. + pub inner: *mut nativeChannelDerivationParameters, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. + pub is_owned: bool, +} + +impl Drop for ChannelDerivationParameters { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeChannelDerivationParameters>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the ChannelDerivationParameters, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn ChannelDerivationParameters_free(this_obj: ChannelDerivationParameters) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ChannelDerivationParameters_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelDerivationParameters) }; +} +#[allow(unused)] +impl ChannelDerivationParameters { + pub(crate) fn get_native_ref(&self) -> &'static nativeChannelDerivationParameters { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelDerivationParameters { + unsafe { &mut *ObjOps::untweak_ptr(self.inner) } + } + /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy + pub(crate) fn take_inner(mut self) -> *mut nativeChannelDerivationParameters { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = core::ptr::null_mut(); + ret + } +} +/// The value in satoshis of the channel we're attempting to spend the anchor output of. +#[no_mangle] +pub extern "C" fn ChannelDerivationParameters_get_value_satoshis(this_ptr: &ChannelDerivationParameters) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().value_satoshis; + *inner_val +} +/// The value in satoshis of the channel we're attempting to spend the anchor output of. +#[no_mangle] +pub extern "C" fn ChannelDerivationParameters_set_value_satoshis(this_ptr: &mut ChannelDerivationParameters, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.value_satoshis = val; +} +/// The unique identifier to re-derive the signer for the associated channel. +#[no_mangle] +pub extern "C" fn ChannelDerivationParameters_get_keys_id(this_ptr: &ChannelDerivationParameters) -> *const [u8; 32] { + let mut inner_val = &mut this_ptr.get_native_mut_ref().keys_id; + inner_val +} +/// The unique identifier to re-derive the signer for the associated channel. +#[no_mangle] +pub extern "C" fn ChannelDerivationParameters_set_keys_id(this_ptr: &mut ChannelDerivationParameters, mut val: crate::c_types::ThirtyTwoBytes) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.keys_id = val.data; +} +/// The necessary channel parameters that need to be provided to the re-derived signer through +/// [`ChannelSigner::provide_channel_parameters`]. +#[no_mangle] +pub extern "C" fn ChannelDerivationParameters_get_transaction_parameters(this_ptr: &ChannelDerivationParameters) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters { + let mut inner_val = &mut this_ptr.get_native_mut_ref().transaction_parameters; + crate::lightning::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::chan_utils::ChannelTransactionParameters<>) as *mut _) }, is_owned: false } +} +/// The necessary channel parameters that need to be provided to the re-derived signer through +/// [`ChannelSigner::provide_channel_parameters`]. +#[no_mangle] +pub extern "C" fn ChannelDerivationParameters_set_transaction_parameters(this_ptr: &mut ChannelDerivationParameters, mut val: crate::lightning::ln::chan_utils::ChannelTransactionParameters) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.transaction_parameters = *unsafe { Box::from_raw(val.take_inner()) }; +} +/// Constructs a new ChannelDerivationParameters given each field +#[must_use] +#[no_mangle] +pub extern "C" fn ChannelDerivationParameters_new(mut value_satoshis_arg: u64, mut keys_id_arg: crate::c_types::ThirtyTwoBytes, mut transaction_parameters_arg: crate::lightning::ln::chan_utils::ChannelTransactionParameters) -> ChannelDerivationParameters { + ChannelDerivationParameters { inner: ObjOps::heap_alloc(nativeChannelDerivationParameters { + value_satoshis: value_satoshis_arg, + keys_id: keys_id_arg.data, + transaction_parameters: *unsafe { Box::from_raw(transaction_parameters_arg.take_inner()) }, + }), is_owned: true } +} +impl Clone for ChannelDerivationParameters { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeChannelDerivationParameters>::is_null(self.inner) { core::ptr::null_mut() } else { + ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ChannelDerivationParameters_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelDerivationParameters)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the ChannelDerivationParameters +pub extern "C" fn ChannelDerivationParameters_clone(orig: &ChannelDerivationParameters) -> ChannelDerivationParameters { + orig.clone() +} +/// Checks if two ChannelDerivationParameterss contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn ChannelDerivationParameters_eq(a: &ChannelDerivationParameters, b: &ChannelDerivationParameters) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} +#[no_mangle] +/// Serialize the ChannelDerivationParameters object into a byte array which can be read by ChannelDerivationParameters_read +pub extern "C" fn ChannelDerivationParameters_write(obj: &crate::lightning::sign::ChannelDerivationParameters) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[allow(unused)] +pub(crate) extern "C" fn ChannelDerivationParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelDerivationParameters) }) +} +#[no_mangle] +/// Read a ChannelDerivationParameters from a byte array, created by ChannelDerivationParameters_write +pub extern "C" fn ChannelDerivationParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelDerivationParametersDecodeErrorZ { + let res: Result = crate::c_types::deserialize_obj(ser); + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::sign::ChannelDerivationParameters { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; + local_res +} + +use lightning::sign::HTLCDescriptor as nativeHTLCDescriptorImport; +pub(crate) type nativeHTLCDescriptor = nativeHTLCDescriptorImport; + +/// A descriptor used to sign for a commitment transaction's HTLC output. +#[must_use] +#[repr(C)] +pub struct HTLCDescriptor { + /// A pointer to the opaque Rust object. + + /// Nearly everywhere, inner must be non-null, however in places where + /// the Rust equivalent takes an Option, it may be set to null to indicate None. + pub inner: *mut nativeHTLCDescriptor, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. + pub is_owned: bool, +} + +impl Drop for HTLCDescriptor { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeHTLCDescriptor>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the HTLCDescriptor, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn HTLCDescriptor_free(this_obj: HTLCDescriptor) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn HTLCDescriptor_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeHTLCDescriptor) }; +} +#[allow(unused)] +impl HTLCDescriptor { + pub(crate) fn get_native_ref(&self) -> &'static nativeHTLCDescriptor { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHTLCDescriptor { + unsafe { &mut *ObjOps::untweak_ptr(self.inner) } + } + /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy + pub(crate) fn take_inner(mut self) -> *mut nativeHTLCDescriptor { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = core::ptr::null_mut(); + ret + } +} +/// The parameters required to derive the signer for the HTLC input. +#[no_mangle] +pub extern "C" fn HTLCDescriptor_get_channel_derivation_parameters(this_ptr: &HTLCDescriptor) -> crate::lightning::sign::ChannelDerivationParameters { + let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_derivation_parameters; + crate::lightning::sign::ChannelDerivationParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::sign::ChannelDerivationParameters<>) as *mut _) }, is_owned: false } +} +/// The parameters required to derive the signer for the HTLC input. +#[no_mangle] +pub extern "C" fn HTLCDescriptor_set_channel_derivation_parameters(this_ptr: &mut HTLCDescriptor, mut val: crate::lightning::sign::ChannelDerivationParameters) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_derivation_parameters = *unsafe { Box::from_raw(val.take_inner()) }; +} +/// The number of the commitment transaction in which the HTLC output lives. +#[no_mangle] +pub extern "C" fn HTLCDescriptor_get_per_commitment_number(this_ptr: &HTLCDescriptor) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_number; + *inner_val +} +/// The number of the commitment transaction in which the HTLC output lives. +#[no_mangle] +pub extern "C" fn HTLCDescriptor_set_per_commitment_number(this_ptr: &mut HTLCDescriptor, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_number = val; +} +/// The key tweak corresponding to the number of the commitment transaction in which the HTLC +/// output lives. This tweak is applied to all the basepoints for both parties in the channel to +/// arrive at unique keys per commitment. +/// +/// See for more info. +#[no_mangle] +pub extern "C" fn HTLCDescriptor_get_per_commitment_point(this_ptr: &HTLCDescriptor) -> crate::c_types::PublicKey { + let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_point; + crate::c_types::PublicKey::from_rust(&inner_val) +} +/// The key tweak corresponding to the number of the commitment transaction in which the HTLC +/// output lives. This tweak is applied to all the basepoints for both parties in the channel to +/// arrive at unique keys per commitment. +/// +/// See for more info. +#[no_mangle] +pub extern "C" fn HTLCDescriptor_set_per_commitment_point(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::PublicKey) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_point = val.into_rust(); +} +/// The feerate to use on the HTLC claiming transaction. This is always `0` for HTLCs +/// originating from a channel supporting anchor outputs, otherwise it is the channel's +/// negotiated feerate at the time the commitment transaction was built. +#[no_mangle] +pub extern "C" fn HTLCDescriptor_get_feerate_per_kw(this_ptr: &HTLCDescriptor) -> u32 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().feerate_per_kw; + *inner_val +} +/// The feerate to use on the HTLC claiming transaction. This is always `0` for HTLCs +/// originating from a channel supporting anchor outputs, otherwise it is the channel's +/// negotiated feerate at the time the commitment transaction was built. +#[no_mangle] +pub extern "C" fn HTLCDescriptor_set_feerate_per_kw(this_ptr: &mut HTLCDescriptor, mut val: u32) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.feerate_per_kw = val; +} +/// The details of the HTLC as it appears in the commitment transaction. +#[no_mangle] +pub extern "C" fn HTLCDescriptor_get_htlc(this_ptr: &HTLCDescriptor) -> crate::lightning::ln::chan_utils::HTLCOutputInCommitment { + let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc; + crate::lightning::ln::chan_utils::HTLCOutputInCommitment { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::chan_utils::HTLCOutputInCommitment<>) as *mut _) }, is_owned: false } +} +/// The details of the HTLC as it appears in the commitment transaction. +#[no_mangle] +pub extern "C" fn HTLCDescriptor_set_htlc(this_ptr: &mut HTLCDescriptor, mut val: crate::lightning::ln::chan_utils::HTLCOutputInCommitment) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc = *unsafe { Box::from_raw(val.take_inner()) }; +} +/// The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be +/// taken. +#[no_mangle] +pub extern "C" fn HTLCDescriptor_get_preimage(this_ptr: &HTLCDescriptor) -> crate::c_types::derived::COption_ThirtyTwoBytesZ { + let mut inner_val = &mut this_ptr.get_native_mut_ref().preimage; + let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_ThirtyTwoBytesZ::None } else { crate::c_types::derived::COption_ThirtyTwoBytesZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option is otherwise un-expressable. */ { crate::c_types::ThirtyTwoBytes { data: (*inner_val.as_ref().unwrap()).clone().0 } }) }; + local_inner_val +} +/// The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be +/// taken. +#[no_mangle] +pub extern "C" fn HTLCDescriptor_set_preimage(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::derived::COption_ThirtyTwoBytesZ) { + let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { ::lightning::ln::PaymentPreimage({ val_opt.take() }.data) }})} }; + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.preimage = local_val; +} +/// The counterparty's signature required to spend the HTLC output. +#[no_mangle] +pub extern "C" fn HTLCDescriptor_get_counterparty_sig(this_ptr: &HTLCDescriptor) -> crate::c_types::ECDSASignature { + let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty_sig; + crate::c_types::ECDSASignature::from_rust(&inner_val) +} +/// The counterparty's signature required to spend the HTLC output. +#[no_mangle] +pub extern "C" fn HTLCDescriptor_set_counterparty_sig(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::ECDSASignature) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty_sig = val.into_rust(); +} +impl Clone for HTLCDescriptor { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeHTLCDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else { + ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn HTLCDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeHTLCDescriptor)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the HTLCDescriptor +pub extern "C" fn HTLCDescriptor_clone(orig: &HTLCDescriptor) -> HTLCDescriptor { + orig.clone() +} +/// Checks if two HTLCDescriptors contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn HTLCDescriptor_eq(a: &HTLCDescriptor, b: &HTLCDescriptor) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} +#[no_mangle] +/// Serialize the HTLCDescriptor object into a byte array which can be read by HTLCDescriptor_read +pub extern "C" fn HTLCDescriptor_write(obj: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[allow(unused)] +pub(crate) extern "C" fn HTLCDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCDescriptor) }) +} +#[no_mangle] +/// Read a HTLCDescriptor from a byte array, created by HTLCDescriptor_write +pub extern "C" fn HTLCDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCDescriptorDecodeErrorZ { + let res: Result = crate::c_types::deserialize_obj(ser); + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::sign::HTLCDescriptor { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; + local_res +} +/// Returns the outpoint of the HTLC output in the commitment transaction. This is the outpoint +/// being spent by the HTLC input in the HTLC transaction. +#[must_use] +#[no_mangle] +pub extern "C" fn HTLCDescriptor_outpoint(this_arg: &crate::lightning::sign::HTLCDescriptor) -> crate::lightning::chain::transaction::OutPoint { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.outpoint(); + crate::c_types::bitcoin_to_C_outpoint(&ret) +} + +/// Returns the UTXO to be spent by the HTLC input, which can be obtained via +/// [`Self::unsigned_tx_input`]. +#[must_use] +#[no_mangle] +pub extern "C" fn HTLCDescriptor_previous_utxo(this_arg: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::TxOut { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.previous_utxo(secp256k1::global::SECP256K1); + crate::c_types::TxOut::from_rust(&ret) +} + +/// Returns the unsigned transaction input spending the HTLC output in the commitment +/// transaction. +#[must_use] +#[no_mangle] +pub extern "C" fn HTLCDescriptor_unsigned_tx_input(this_arg: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::TxIn { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.unsigned_tx_input(); + crate::c_types::TxIn::from_rust(&ret) +} + +/// Returns the delayed output created as a result of spending the HTLC output in the commitment +/// transaction. +#[must_use] +#[no_mangle] +pub extern "C" fn HTLCDescriptor_tx_output(this_arg: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::TxOut { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.tx_output(secp256k1::global::SECP256K1); + crate::c_types::TxOut::from_rust(&ret) +} + +/// Returns the witness script of the HTLC output in the commitment transaction. +#[must_use] +#[no_mangle] +pub extern "C" fn HTLCDescriptor_witness_script(this_arg: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::derived::CVec_u8Z { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.witness_script(secp256k1::global::SECP256K1); + ret.into_bytes().into() +} + +/// Returns the fully signed witness required to spend the HTLC output in the commitment +/// transaction. +#[must_use] +#[no_mangle] +pub extern "C" fn HTLCDescriptor_tx_input_witness(this_arg: &crate::lightning::sign::HTLCDescriptor, mut signature: crate::c_types::ECDSASignature, mut witness_script: crate::c_types::u8slice) -> crate::c_types::Witness { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.tx_input_witness(&signature.into_rust(), &::bitcoin::blockdata::script::Script::from(Vec::from(witness_script.to_slice()))); + crate::c_types::Witness::from_bitcoin(&ret) +} + +/// Derives the channel signer required to sign the HTLC input. +#[must_use] +#[no_mangle] +pub extern "C" fn HTLCDescriptor_derive_channel_signer(this_arg: &crate::lightning::sign::HTLCDescriptor, signer_provider: &crate::lightning::sign::SignerProvider) -> crate::lightning::sign::WriteableEcdsaChannelSigner { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_signer(signer_provider); + Into::into(ret) +} + /// A trait to handle Lightning channel key material without concretizing the channel type or /// the signature mechanism. #[repr(C)] @@ -773,6 +1176,7 @@ pub struct ChannelSigner { } unsafe impl Send for ChannelSigner {} unsafe impl Sync for ChannelSigner {} +#[allow(unused)] pub(crate) fn ChannelSigner_clone_fields(orig: &ChannelSigner) -> ChannelSigner { ChannelSigner { this_arg: orig.this_arg, @@ -872,22 +1276,16 @@ pub struct EcdsaChannelSigner { /// This is required in order for the signer to make sure that the state has moved /// forward and it is safe to sign the next counterparty commitment. pub validate_counterparty_revocation: extern "C" fn (this_arg: *const c_void, idx: u64, secret: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneNoneZ, - /// Creates a signature for a holder's commitment transaction and its claiming HTLC transactions. + /// Creates a signature for a holder's commitment transaction. /// /// This will be called /// - with a non-revoked `commitment_tx`. /// - with the latest `commitment_tx` when we initiate a force-close. - /// - with the previous `commitment_tx`, just to get claiming HTLC - /// signatures, if we are reacting to a [`ChannelMonitor`] - /// [replica](https://github.com/lightningdevkit/rust-lightning/blob/main/GLOSSARY.md#monitor-replicas) - /// that decided to broadcast before it had been updated to the latest `commitment_tx`. /// /// This may be called multiple times for the same transaction. /// /// An external signer implementation should check that the commitment has not been revoked. - /// - /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor - pub sign_holder_commitment_and_htlcs: extern "C" fn (this_arg: *const c_void, commitment_tx: &crate::lightning::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_C2Tuple_ECDSASignatureCVec_ECDSASignatureZZNoneZ, + pub sign_holder_commitment: extern "C" fn (this_arg: *const c_void, commitment_tx: &crate::lightning::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ, /// Create a signature for the given input in a transaction spending an HTLC transaction output /// or a commitment transaction `to_local` output when our counterparty broadcasts an old state. /// @@ -924,12 +1322,15 @@ pub struct EcdsaChannelSigner { pub sign_justice_revoked_htlc: extern "C" fn (this_arg: *const c_void, justice_tx: crate::c_types::Transaction, input: usize, amount: u64, per_commitment_key: *const [u8; 32], htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ, /// Computes the signature for a commitment transaction's HTLC output used as an input within /// `htlc_tx`, which spends the commitment transaction at index `input`. The signature returned - /// must be be computed using [`EcdsaSighashType::All`]. Note that this should only be used to - /// sign HTLC transactions from channels supporting anchor outputs after all additional - /// inputs/outputs have been added to the transaction. + /// must be be computed using [`EcdsaSighashType::All`]. + /// + /// Note that this may be called for HTLCs in the penultimate commitment transaction if a + /// [`ChannelMonitor`] [replica](https://github.com/lightningdevkit/rust-lightning/blob/main/GLOSSARY.md#monitor-replicas) + /// broadcasts it before receiving the update for the latest commitment transaction. /// /// [`EcdsaSighashType::All`]: bitcoin::blockdata::transaction::EcdsaSighashType::All - pub sign_holder_htlc_transaction: extern "C" fn (this_arg: *const c_void, htlc_tx: crate::c_types::Transaction, input: usize, htlc_descriptor: &crate::lightning::events::bump_transaction::HTLCDescriptor) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ, + /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor + pub sign_holder_htlc_transaction: extern "C" fn (this_arg: *const c_void, htlc_tx: crate::c_types::Transaction, input: usize, htlc_descriptor: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ, /// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment /// transaction, either offered or received. /// @@ -974,12 +1375,13 @@ pub struct EcdsaChannelSigner { } unsafe impl Send for EcdsaChannelSigner {} unsafe impl Sync for EcdsaChannelSigner {} +#[allow(unused)] pub(crate) fn EcdsaChannelSigner_clone_fields(orig: &EcdsaChannelSigner) -> EcdsaChannelSigner { EcdsaChannelSigner { this_arg: orig.this_arg, sign_counterparty_commitment: Clone::clone(&orig.sign_counterparty_commitment), validate_counterparty_revocation: Clone::clone(&orig.validate_counterparty_revocation), - sign_holder_commitment_and_htlcs: Clone::clone(&orig.sign_holder_commitment_and_htlcs), + sign_holder_commitment: Clone::clone(&orig.sign_holder_commitment), sign_justice_revoked_output: Clone::clone(&orig.sign_justice_revoked_output), sign_justice_revoked_htlc: Clone::clone(&orig.sign_justice_revoked_htlc), sign_holder_htlc_transaction: Clone::clone(&orig.sign_holder_htlc_transaction), @@ -1034,9 +1436,9 @@ impl rustEcdsaChannelSigner for EcdsaChannelSigner { let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; local_ret } - fn sign_holder_commitment_and_htlcs(&self, mut commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result<(bitcoin::secp256k1::ecdsa::Signature, Vec), ()> { - let mut ret = (self.sign_holder_commitment_and_htlcs)(self.this_arg, &crate::lightning::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((commitment_tx as *const lightning::ln::chan_utils::HolderCommitmentTransaction<>) as *mut _) }, is_owned: false }); - let mut local_ret = match ret.result_ok { true => Ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).to_rust(); let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.into_rust().drain(..) { local_orig_ret_0_1.push( { item.into_rust() }); }; let mut local_ret_0 = (orig_ret_0_0.into_rust(), local_orig_ret_0_1); local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; + fn sign_holder_commitment(&self, mut commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result { + let mut ret = (self.sign_holder_commitment)(self.this_arg, &crate::lightning::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((commitment_tx as *const lightning::ln::chan_utils::HolderCommitmentTransaction<>) as *mut _) }, is_owned: false }); + let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; local_ret } fn sign_justice_revoked_output(&self, mut justice_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut amount: u64, mut per_commitment_key: &bitcoin::secp256k1::SecretKey, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result { @@ -1049,8 +1451,8 @@ impl rustEcdsaChannelSigner for EcdsaChannelSigner { let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; local_ret } - fn sign_holder_htlc_transaction(&self, mut htlc_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut htlc_descriptor: &lightning::events::bump_transaction::HTLCDescriptor, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result { - let mut ret = (self.sign_holder_htlc_transaction)(self.this_arg, crate::c_types::Transaction::from_bitcoin(htlc_tx), input, &crate::lightning::events::bump_transaction::HTLCDescriptor { inner: unsafe { ObjOps::nonnull_ptr_to_inner((htlc_descriptor as *const lightning::events::bump_transaction::HTLCDescriptor<>) as *mut _) }, is_owned: false }); + fn sign_holder_htlc_transaction(&self, mut htlc_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut htlc_descriptor: &lightning::sign::HTLCDescriptor, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result { + let mut ret = (self.sign_holder_htlc_transaction)(self.this_arg, crate::c_types::Transaction::from_bitcoin(htlc_tx), input, &crate::lightning::sign::HTLCDescriptor { inner: unsafe { ObjOps::nonnull_ptr_to_inner((htlc_descriptor as *const lightning::sign::HTLCDescriptor<>) as *mut _) }, is_owned: false }); let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; local_ret } @@ -1125,6 +1527,7 @@ pub struct WriteableEcdsaChannelSigner { } unsafe impl Send for WriteableEcdsaChannelSigner {} unsafe impl Sync for WriteableEcdsaChannelSigner {} +#[allow(unused)] pub(crate) fn WriteableEcdsaChannelSigner_clone_fields(orig: &WriteableEcdsaChannelSigner) -> WriteableEcdsaChannelSigner { WriteableEcdsaChannelSigner { this_arg: orig.this_arg, @@ -1146,9 +1549,9 @@ impl lightning::sign::EcdsaChannelSigner for WriteableEcdsaChannelSigner { let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; local_ret } - fn sign_holder_commitment_and_htlcs(&self, mut commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result<(bitcoin::secp256k1::ecdsa::Signature, Vec), ()> { - let mut ret = (self.EcdsaChannelSigner.sign_holder_commitment_and_htlcs)(self.EcdsaChannelSigner.this_arg, &crate::lightning::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((commitment_tx as *const lightning::ln::chan_utils::HolderCommitmentTransaction<>) as *mut _) }, is_owned: false }); - let mut local_ret = match ret.result_ok { true => Ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).to_rust(); let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.into_rust().drain(..) { local_orig_ret_0_1.push( { item.into_rust() }); }; let mut local_ret_0 = (orig_ret_0_0.into_rust(), local_orig_ret_0_1); local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; + fn sign_holder_commitment(&self, mut commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result { + let mut ret = (self.EcdsaChannelSigner.sign_holder_commitment)(self.EcdsaChannelSigner.this_arg, &crate::lightning::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((commitment_tx as *const lightning::ln::chan_utils::HolderCommitmentTransaction<>) as *mut _) }, is_owned: false }); + let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; local_ret } fn sign_justice_revoked_output(&self, mut justice_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut amount: u64, mut per_commitment_key: &bitcoin::secp256k1::SecretKey, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result { @@ -1161,8 +1564,8 @@ impl lightning::sign::EcdsaChannelSigner for WriteableEcdsaChannelSigner { let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; local_ret } - fn sign_holder_htlc_transaction(&self, mut htlc_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut htlc_descriptor: &lightning::events::bump_transaction::HTLCDescriptor, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result { - let mut ret = (self.EcdsaChannelSigner.sign_holder_htlc_transaction)(self.EcdsaChannelSigner.this_arg, crate::c_types::Transaction::from_bitcoin(htlc_tx), input, &crate::lightning::events::bump_transaction::HTLCDescriptor { inner: unsafe { ObjOps::nonnull_ptr_to_inner((htlc_descriptor as *const lightning::events::bump_transaction::HTLCDescriptor<>) as *mut _) }, is_owned: false }); + fn sign_holder_htlc_transaction(&self, mut htlc_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut htlc_descriptor: &lightning::sign::HTLCDescriptor, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result { + let mut ret = (self.EcdsaChannelSigner.sign_holder_htlc_transaction)(self.EcdsaChannelSigner.this_arg, crate::c_types::Transaction::from_bitcoin(htlc_tx), input, &crate::lightning::sign::HTLCDescriptor { inner: unsafe { ObjOps::nonnull_ptr_to_inner((htlc_descriptor as *const lightning::sign::HTLCDescriptor<>) as *mut _) }, is_owned: false }); let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; local_ret } @@ -1316,6 +1719,16 @@ impl Recipient { pub extern "C" fn Recipient_clone(orig: &Recipient) -> Recipient { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Recipient_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Recipient)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Recipient_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut Recipient) }; +} #[no_mangle] /// Utility method to constructs a new Node-variant Recipient pub extern "C" fn Recipient_node() -> Recipient { @@ -1339,6 +1752,7 @@ pub struct EntropySource { } unsafe impl Send for EntropySource {} unsafe impl Sync for EntropySource {} +#[allow(unused)] pub(crate) fn EntropySource_clone_fields(orig: &EntropySource) -> EntropySource { EntropySource { this_arg: orig.this_arg, @@ -1459,6 +1873,7 @@ pub struct NodeSigner { } unsafe impl Send for NodeSigner {} unsafe impl Sync for NodeSigner {} +#[allow(unused)] pub(crate) fn NodeSigner_clone_fields(orig: &NodeSigner) -> NodeSigner { NodeSigner { this_arg: orig.this_arg, @@ -1593,6 +2008,7 @@ pub struct SignerProvider { } unsafe impl Send for SignerProvider {} unsafe impl Sync for SignerProvider {} +#[allow(unused)] pub(crate) fn SignerProvider_clone_fields(orig: &SignerProvider) -> SignerProvider { SignerProvider { this_arg: orig.this_arg, @@ -1791,7 +2207,7 @@ impl Clone for InMemorySigner { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn InMemorySigner_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInMemorySigner)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeInMemorySigner)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the InMemorySigner @@ -1940,10 +2356,10 @@ pub extern "C" fn InMemorySigner_sign_dynamic_p2wsh_input(this_arg: &crate::ligh impl From for crate::lightning::sign::EntropySource { fn from(obj: nativeInMemorySigner) -> Self { - let mut rust_obj = InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = InMemorySigner_as_EntropySource(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(InMemorySigner_free_void); ret } @@ -1967,10 +2383,10 @@ extern "C" fn InMemorySigner_EntropySource_get_secure_random_bytes(this_arg: *co impl From for crate::lightning::sign::ChannelSigner { fn from(obj: nativeInMemorySigner) -> Self { - let mut rust_obj = InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = InMemorySigner_as_ChannelSigner(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(InMemorySigner_free_void); ret } @@ -2033,10 +2449,10 @@ extern "C" fn InMemorySigner_ChannelSigner_provide_channel_parameters(this_arg: impl From for crate::lightning::sign::EcdsaChannelSigner { fn from(obj: nativeInMemorySigner) -> Self { - let mut rust_obj = InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = InMemorySigner_as_EcdsaChannelSigner(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(InMemorySigner_free_void); ret } @@ -2050,7 +2466,7 @@ pub extern "C" fn InMemorySigner_as_EcdsaChannelSigner(this_arg: &InMemorySigner free: None, sign_counterparty_commitment: InMemorySigner_EcdsaChannelSigner_sign_counterparty_commitment, validate_counterparty_revocation: InMemorySigner_EcdsaChannelSigner_validate_counterparty_revocation, - sign_holder_commitment_and_htlcs: InMemorySigner_EcdsaChannelSigner_sign_holder_commitment_and_htlcs, + sign_holder_commitment: InMemorySigner_EcdsaChannelSigner_sign_holder_commitment, sign_justice_revoked_output: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_output, sign_justice_revoked_htlc: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_htlc, sign_holder_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_holder_htlc_transaction, @@ -2087,9 +2503,9 @@ extern "C" fn InMemorySigner_EcdsaChannelSigner_validate_counterparty_revocation local_ret } #[must_use] -extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_holder_commitment_and_htlcs(this_arg: *const c_void, commitment_tx: &crate::lightning::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_C2Tuple_ECDSASignatureCVec_ECDSASignatureZZNoneZ { - let mut ret = >::sign_holder_commitment_and_htlcs(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, commitment_tx.get_native_ref(), secp256k1::global::SECP256K1); - let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { crate::c_types::ECDSASignature::from_rust(&item) }); }; let mut local_ret_0 = (crate::c_types::ECDSASignature::from_rust(&orig_ret_0_0), local_orig_ret_0_1.into()).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() }; +extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_holder_commitment(this_arg: *const c_void, commitment_tx: &crate::lightning::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ { + let mut ret = >::sign_holder_commitment(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, commitment_tx.get_native_ref(), secp256k1::global::SECP256K1); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() }; local_ret } #[must_use] @@ -2105,7 +2521,7 @@ extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_htlc(this_a local_ret } #[must_use] -extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_holder_htlc_transaction(this_arg: *const c_void, mut htlc_tx: crate::c_types::Transaction, mut input: usize, htlc_descriptor: &crate::lightning::events::bump_transaction::HTLCDescriptor) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ { +extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_holder_htlc_transaction(this_arg: *const c_void, mut htlc_tx: crate::c_types::Transaction, mut input: usize, htlc_descriptor: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ { let mut ret = >::sign_holder_htlc_transaction(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, &htlc_tx.into_bitcoin(), input, htlc_descriptor.get_native_ref(), secp256k1::global::SECP256K1); let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() }; local_ret @@ -2137,10 +2553,10 @@ extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_channel_announcement_with_f impl From for crate::lightning::sign::WriteableEcdsaChannelSigner { fn from(obj: nativeInMemorySigner) -> Self { - let mut rust_obj = InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = InMemorySigner_as_WriteableEcdsaChannelSigner(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(InMemorySigner_free_void); ret } @@ -2157,7 +2573,7 @@ pub extern "C" fn InMemorySigner_as_WriteableEcdsaChannelSigner(this_arg: &InMem free: None, sign_counterparty_commitment: InMemorySigner_EcdsaChannelSigner_sign_counterparty_commitment, validate_counterparty_revocation: InMemorySigner_EcdsaChannelSigner_validate_counterparty_revocation, - sign_holder_commitment_and_htlcs: InMemorySigner_EcdsaChannelSigner_sign_holder_commitment_and_htlcs, + sign_holder_commitment: InMemorySigner_EcdsaChannelSigner_sign_holder_commitment, sign_justice_revoked_output: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_output, sign_justice_revoked_htlc: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_htlc, sign_holder_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_holder_htlc_transaction, @@ -2197,7 +2613,7 @@ extern "C" fn WriteableEcdsaChannelSigner_InMemorySigner_cloned(new_obj: &mut cr pub extern "C" fn InMemorySigner_write(obj: &crate::lightning::sign::InMemorySigner) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn InMemorySigner_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInMemorySigner) }) } @@ -2359,10 +2775,10 @@ pub extern "C" fn KeysManager_spend_spendable_outputs(this_arg: &crate::lightnin impl From for crate::lightning::sign::EntropySource { fn from(obj: nativeKeysManager) -> Self { - let mut rust_obj = KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::sign::KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = KeysManager_as_EntropySource(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(KeysManager_free_void); ret } @@ -2386,10 +2802,10 @@ extern "C" fn KeysManager_EntropySource_get_secure_random_bytes(this_arg: *const impl From for crate::lightning::sign::NodeSigner { fn from(obj: nativeKeysManager) -> Self { - let mut rust_obj = KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::sign::KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = KeysManager_as_NodeSigner(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(KeysManager_free_void); ret } @@ -2457,10 +2873,10 @@ extern "C" fn KeysManager_NodeSigner_sign_gossip_message(this_arg: *const c_void impl From for crate::lightning::sign::SignerProvider { fn from(obj: nativeKeysManager) -> Self { - let mut rust_obj = KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::sign::KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = KeysManager_as_SignerProvider(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(KeysManager_free_void); ret } @@ -2576,10 +2992,10 @@ impl PhantomKeysManager { } impl From for crate::lightning::sign::EntropySource { fn from(obj: nativePhantomKeysManager) -> Self { - let mut rust_obj = PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::sign::PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = PhantomKeysManager_as_EntropySource(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(PhantomKeysManager_free_void); ret } @@ -2603,10 +3019,10 @@ extern "C" fn PhantomKeysManager_EntropySource_get_secure_random_bytes(this_arg: impl From for crate::lightning::sign::NodeSigner { fn from(obj: nativePhantomKeysManager) -> Self { - let mut rust_obj = PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::sign::PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = PhantomKeysManager_as_NodeSigner(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(PhantomKeysManager_free_void); ret } @@ -2674,10 +3090,10 @@ extern "C" fn PhantomKeysManager_NodeSigner_sign_gossip_message(this_arg: *const impl From for crate::lightning::sign::SignerProvider { fn from(obj: nativePhantomKeysManager) -> Self { - let mut rust_obj = PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::sign::PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = PhantomKeysManager_as_SignerProvider(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(PhantomKeysManager_free_void); ret } diff --git a/lightning-c-bindings/src/lightning/util/config.rs b/lightning-c-bindings/src/lightning/util/config.rs index c4eb473..e83fb2b 100644 --- a/lightning-c-bindings/src/lightning/util/config.rs +++ b/lightning-c-bindings/src/lightning/util/config.rs @@ -514,7 +514,7 @@ impl Clone for ChannelHandshakeConfig { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelHandshakeConfig_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeConfig)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelHandshakeConfig)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelHandshakeConfig @@ -833,7 +833,7 @@ impl Clone for ChannelHandshakeLimits { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelHandshakeLimits_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeLimits)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelHandshakeLimits)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelHandshakeLimits @@ -970,6 +970,16 @@ pub extern "C" fn MaxDustHTLCExposure_free(this_ptr: MaxDustHTLCExposure) { } pub extern "C" fn MaxDustHTLCExposure_clone(orig: &MaxDustHTLCExposure) -> MaxDustHTLCExposure { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn MaxDustHTLCExposure_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const MaxDustHTLCExposure)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn MaxDustHTLCExposure_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut MaxDustHTLCExposure) }; +} #[no_mangle] /// Utility method to constructs a new FixedLimitMsat-variant MaxDustHTLCExposure pub extern "C" fn MaxDustHTLCExposure_fixed_limit_msat(a: u64) -> MaxDustHTLCExposure { @@ -991,6 +1001,10 @@ pub extern "C" fn MaxDustHTLCExposure_eq(a: &MaxDustHTLCExposure, b: &MaxDustHTL pub extern "C" fn MaxDustHTLCExposure_write(obj: &crate::lightning::util::config::MaxDustHTLCExposure) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) } +#[allow(unused)] +pub(crate) extern "C" fn MaxDustHTLCExposure_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + MaxDustHTLCExposure_write(unsafe { &*(obj as *const MaxDustHTLCExposure) }) +} #[no_mangle] /// Read a MaxDustHTLCExposure from a byte array, created by MaxDustHTLCExposure_write pub extern "C" fn MaxDustHTLCExposure_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_MaxDustHTLCExposureDecodeErrorZ { @@ -1210,20 +1224,20 @@ pub extern "C" fn ChannelConfig_set_max_dust_htlc_exposure(this_ptr: &mut Channe /// funder/initiator. /// /// When we are the funder, because we have to pay the channel closing fee, we bound the -/// acceptable fee by our [`Background`] and [`Normal`] fees, with the upper bound increased by +/// acceptable fee by our [`ChannelCloseMinimum`] and [`NonAnchorChannelFee`] fees, with the upper bound increased by /// this value. Because the on-chain fee we'd pay to force-close the channel is kept near our -/// [`Normal`] feerate during normal operation, this value represents the additional fee we're +/// [`NonAnchorChannelFee`] feerate during normal operation, this value represents the additional fee we're /// willing to pay in order to avoid waiting for our counterparty's to_self_delay to reclaim our /// funds. /// /// When we are not the funder, we require the closing transaction fee pay at least our -/// [`Background`] fee estimate, but allow our counterparty to pay as much fee as they like. +/// [`ChannelCloseMinimum`] fee estimate, but allow our counterparty to pay as much fee as they like. /// Thus, this value is ignored when we are not the funder. /// /// Default value: 1000 satoshis. /// -/// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal -/// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background +/// [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee +/// [`ChannelCloseMinimum`]: crate::chain::chaininterface::ConfirmationTarget::ChannelCloseMinimum #[no_mangle] pub extern "C" fn ChannelConfig_get_force_close_avoidance_max_fee_satoshis(this_ptr: &ChannelConfig) -> u64 { let mut inner_val = &mut this_ptr.get_native_mut_ref().force_close_avoidance_max_fee_satoshis; @@ -1237,20 +1251,20 @@ pub extern "C" fn ChannelConfig_get_force_close_avoidance_max_fee_satoshis(this_ /// funder/initiator. /// /// When we are the funder, because we have to pay the channel closing fee, we bound the -/// acceptable fee by our [`Background`] and [`Normal`] fees, with the upper bound increased by +/// acceptable fee by our [`ChannelCloseMinimum`] and [`NonAnchorChannelFee`] fees, with the upper bound increased by /// this value. Because the on-chain fee we'd pay to force-close the channel is kept near our -/// [`Normal`] feerate during normal operation, this value represents the additional fee we're +/// [`NonAnchorChannelFee`] feerate during normal operation, this value represents the additional fee we're /// willing to pay in order to avoid waiting for our counterparty's to_self_delay to reclaim our /// funds. /// /// When we are not the funder, we require the closing transaction fee pay at least our -/// [`Background`] fee estimate, but allow our counterparty to pay as much fee as they like. +/// [`ChannelCloseMinimum`] fee estimate, but allow our counterparty to pay as much fee as they like. /// Thus, this value is ignored when we are not the funder. /// /// Default value: 1000 satoshis. /// -/// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal -/// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background +/// [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee +/// [`ChannelCloseMinimum`]: crate::chain::chaininterface::ConfirmationTarget::ChannelCloseMinimum #[no_mangle] pub extern "C" fn ChannelConfig_set_force_close_avoidance_max_fee_satoshis(this_ptr: &mut ChannelConfig, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.force_close_avoidance_max_fee_satoshis = val; @@ -1347,7 +1361,7 @@ impl Clone for ChannelConfig { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelConfig_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelConfig)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelConfig)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelConfig @@ -1380,7 +1394,7 @@ pub extern "C" fn ChannelConfig_default() -> ChannelConfig { pub extern "C" fn ChannelConfig_write(obj: &crate::lightning::util::config::ChannelConfig) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelConfig_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelConfig) }) } @@ -1783,7 +1797,7 @@ impl Clone for UserConfig { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UserConfig_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUserConfig)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUserConfig)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the UserConfig diff --git a/lightning-c-bindings/src/lightning/util/errors.rs b/lightning-c-bindings/src/lightning/util/errors.rs index 43755de..08929c1 100644 --- a/lightning-c-bindings/src/lightning/util/errors.rs +++ b/lightning-c-bindings/src/lightning/util/errors.rs @@ -226,6 +226,16 @@ pub extern "C" fn APIError_free(this_ptr: APIError) { } pub extern "C" fn APIError_clone(orig: &APIError) -> APIError { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn APIError_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const APIError)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn APIError_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut APIError) }; +} #[no_mangle] /// Utility method to constructs a new APIMisuseError-variant APIError pub extern "C" fn APIError_apimisuse_error(err: crate::c_types::Str) -> APIError { @@ -277,6 +287,10 @@ pub extern "C" fn APIError_eq(a: &APIError, b: &APIError) -> bool { pub extern "C" fn APIError_write(obj: &crate::lightning::util::errors::APIError) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) } +#[allow(unused)] +pub(crate) extern "C" fn APIError_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + APIError_write(unsafe { &*(obj as *const APIError) }) +} #[no_mangle] /// Read a APIError from a byte array, created by APIError_write pub extern "C" fn APIError_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_APIErrorZDecodeErrorZ { diff --git a/lightning-c-bindings/src/lightning/util/logger.rs b/lightning-c-bindings/src/lightning/util/logger.rs index 452da10..645fafa 100644 --- a/lightning-c-bindings/src/lightning/util/logger.rs +++ b/lightning-c-bindings/src/lightning/util/logger.rs @@ -94,6 +94,16 @@ impl Level { pub extern "C" fn Level_clone(orig: &Level) -> Level { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Level_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Level)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Level_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut Level) }; +} #[no_mangle] /// Utility method to constructs a new Gossip-variant Level pub extern "C" fn Level_gossip() -> Level { @@ -260,7 +270,7 @@ impl Clone for Record { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Record_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRecord)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRecord)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Record @@ -281,6 +291,7 @@ pub struct Logger { } unsafe impl Send for Logger {} unsafe impl Sync for Logger {} +#[allow(unused)] pub(crate) fn Logger_clone_fields(orig: &Logger) -> Logger { Logger { this_arg: orig.this_arg, diff --git a/lightning-c-bindings/src/lightning/util/persist.rs b/lightning-c-bindings/src/lightning/util/persist.rs index 953ffe8..f962c98 100644 --- a/lightning-c-bindings/src/lightning/util/persist.rs +++ b/lightning-c-bindings/src/lightning/util/persist.rs @@ -90,6 +90,7 @@ pub struct KVStore { } unsafe impl Send for KVStore {} unsafe impl Sync for KVStore {} +#[allow(unused)] pub(crate) fn KVStore_clone_fields(orig: &KVStore) -> KVStore { KVStore { this_arg: orig.this_arg, @@ -167,6 +168,7 @@ pub struct Persister { } unsafe impl Send for Persister {} unsafe impl Sync for Persister {} +#[allow(unused)] pub(crate) fn Persister_clone_fields(orig: &Persister) -> Persister { Persister { this_arg: orig.this_arg, @@ -436,10 +438,10 @@ pub extern "C" fn MonitorUpdatingPersister_cleanup_stale_updates(this_arg: &crat impl From for crate::lightning::chain::chainmonitor::Persist { fn from(obj: nativeMonitorUpdatingPersister) -> Self { - let mut rust_obj = MonitorUpdatingPersister { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::util::persist::MonitorUpdatingPersister { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = MonitorUpdatingPersister_as_Persist(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(MonitorUpdatingPersister_free_void); ret } diff --git a/lightning-c-bindings/src/lightning/util/ser.rs b/lightning-c-bindings/src/lightning/util/ser.rs index 663a172..eab63e5 100644 --- a/lightning-c-bindings/src/lightning/util/ser.rs +++ b/lightning-c-bindings/src/lightning/util/ser.rs @@ -111,7 +111,7 @@ impl Clone for BigSize { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn BigSize_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBigSize)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBigSize)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the BigSize @@ -142,7 +142,7 @@ pub extern "C" fn BigSize_eq(a: &BigSize, b: &BigSize) -> bool { pub extern "C" fn BigSize_write(obj: &crate::lightning::util::ser::BigSize) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn BigSize_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBigSize) }) } @@ -222,7 +222,7 @@ impl Clone for Hostname { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Hostname_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHostname)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeHostname)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Hostname @@ -251,7 +251,7 @@ pub extern "C" fn Hostname_len(this_arg: &crate::lightning::util::ser::Hostname) pub extern "C" fn Hostname_write(obj: &crate::lightning::util::ser::Hostname) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn Hostname_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHostname) }) } @@ -328,7 +328,7 @@ impl Clone for TransactionU16LenLimited { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TransactionU16LenLimited_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTransactionU16LenLimited)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTransactionU16LenLimited)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TransactionU16LenLimited @@ -367,7 +367,7 @@ pub extern "C" fn TransactionU16LenLimited_into_transaction(mut this_arg: crate: pub extern "C" fn TransactionU16LenLimited_write(obj: &crate::lightning::util::ser::TransactionU16LenLimited) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TransactionU16LenLimited_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTransactionU16LenLimited) }) } diff --git a/lightning-c-bindings/src/lightning/util/string.rs b/lightning-c-bindings/src/lightning/util/string.rs index 5b720c2..90d3a06 100644 --- a/lightning-c-bindings/src/lightning/util/string.rs +++ b/lightning-c-bindings/src/lightning/util/string.rs @@ -97,7 +97,7 @@ impl Clone for UntrustedString { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UntrustedString_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUntrustedString)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUntrustedString)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the UntrustedString @@ -118,7 +118,7 @@ pub extern "C" fn UntrustedString_eq(a: &UntrustedString, b: &UntrustedString) - pub extern "C" fn UntrustedString_write(obj: &crate::lightning::util::string::UntrustedString) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn UntrustedString_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUntrustedString) }) } diff --git a/lightning-c-bindings/src/lightning/util/wakers.rs b/lightning-c-bindings/src/lightning/util/wakers.rs index 9ff48bd..bf85828 100644 --- a/lightning-c-bindings/src/lightning/util/wakers.rs +++ b/lightning-c-bindings/src/lightning/util/wakers.rs @@ -42,6 +42,7 @@ pub struct FutureCallback { } unsafe impl Send for FutureCallback {} unsafe impl Sync for FutureCallback {} +#[allow(unused)] pub(crate) fn FutureCallback_clone_fields(orig: &FutureCallback) -> FutureCallback { FutureCallback { this_arg: orig.this_arg, @@ -145,7 +146,7 @@ impl Clone for Future { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Future_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeFuture)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeFuture)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Future diff --git a/lightning-c-bindings/src/lightning_background_processor.rs b/lightning-c-bindings/src/lightning_background_processor.rs index 9d0dfe0..eb8c0f1 100644 --- a/lightning-c-bindings/src/lightning_background_processor.rs +++ b/lightning-c-bindings/src/lightning_background_processor.rs @@ -151,6 +151,11 @@ impl GossipSync { /// Frees any resources used by the GossipSync #[no_mangle] pub extern "C" fn GossipSync_free(this_ptr: GossipSync) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn GossipSync_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut GossipSync) }; +} #[no_mangle] /// Utility method to constructs a new P2P-variant GossipSync pub extern "C" fn GossipSync_p2_p(a: &crate::lightning::routing::gossip::P2PGossipSync) -> GossipSync { diff --git a/lightning-c-bindings/src/lightning_invoice/mod.rs b/lightning-c-bindings/src/lightning_invoice/mod.rs index 34025a2..931505a 100644 --- a/lightning-c-bindings/src/lightning_invoice/mod.rs +++ b/lightning-c-bindings/src/lightning_invoice/mod.rs @@ -406,6 +406,16 @@ pub extern "C" fn Bolt11ParseError_free(this_ptr: Bolt11ParseError) { } pub extern "C" fn Bolt11ParseError_clone(orig: &Bolt11ParseError) -> Bolt11ParseError { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Bolt11ParseError_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Bolt11ParseError)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Bolt11ParseError_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut Bolt11ParseError) }; +} #[no_mangle] /// Utility method to constructs a new Bech32Error-variant Bolt11ParseError pub extern "C" fn Bolt11ParseError_bech32_error(a: crate::c_types::Bech32Error) -> Bolt11ParseError { @@ -580,6 +590,16 @@ pub extern "C" fn ParseOrSemanticError_free(this_ptr: ParseOrSemanticError) { } pub extern "C" fn ParseOrSemanticError_clone(orig: &ParseOrSemanticError) -> ParseOrSemanticError { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ParseOrSemanticError_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const ParseOrSemanticError)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ParseOrSemanticError_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut ParseOrSemanticError) }; +} #[no_mangle] /// Utility method to constructs a new ParseError-variant ParseOrSemanticError pub extern "C" fn ParseOrSemanticError_parse_error(a: crate::lightning_invoice::Bolt11ParseError) -> ParseOrSemanticError { @@ -697,7 +717,7 @@ impl Clone for Bolt11Invoice { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Bolt11Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBolt11Invoice)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBolt11Invoice)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Bolt11Invoice @@ -790,7 +810,7 @@ impl Clone for SignedRawBolt11Invoice { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn SignedRawBolt11Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawBolt11Invoice)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeSignedRawBolt11Invoice)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the SignedRawBolt11Invoice @@ -894,7 +914,7 @@ impl Clone for RawBolt11Invoice { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn RawBolt11Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawBolt11Invoice)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRawBolt11Invoice)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the RawBolt11Invoice @@ -994,7 +1014,7 @@ impl Clone for RawDataPart { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRawDataPart)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the RawDataPart @@ -1088,7 +1108,7 @@ impl Clone for PositiveTimestamp { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePositiveTimestamp)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the PositiveTimestamp @@ -1165,6 +1185,16 @@ impl SiPrefix { pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn SiPrefix_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const SiPrefix)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn SiPrefix_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut SiPrefix) }; +} #[no_mangle] /// Utility method to constructs a new Milli-variant SiPrefix pub extern "C" fn SiPrefix_milli() -> SiPrefix { @@ -1271,6 +1301,16 @@ impl Currency { pub extern "C" fn Currency_clone(orig: &Currency) -> Currency { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Currency_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Currency)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Currency_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut Currency) }; +} #[no_mangle] /// Utility method to constructs a new Bitcoin-variant Currency pub extern "C" fn Currency_bitcoin() -> Currency { @@ -1369,7 +1409,7 @@ impl Clone for Sha256 { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeSha256)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Sha256 @@ -1470,7 +1510,7 @@ impl Clone for Description { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeDescription)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Description @@ -1576,7 +1616,7 @@ impl Clone for PayeePubKey { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePayeePubKey)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the PayeePubKey @@ -1666,7 +1706,7 @@ impl Clone for ExpiryTime { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeExpiryTime)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ExpiryTime @@ -1772,7 +1812,7 @@ impl Clone for MinFinalCltvExpiryDelta { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn MinFinalCltvExpiryDelta_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiryDelta)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeMinFinalCltvExpiryDelta)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the MinFinalCltvExpiryDelta @@ -1921,6 +1961,16 @@ pub extern "C" fn Fallback_free(this_ptr: Fallback) { } pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Fallback_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Fallback)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Fallback_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut Fallback) }; +} #[no_mangle] /// Utility method to constructs a new SegWitProgram-variant Fallback pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::WitnessVersion, program: crate::c_types::derived::CVec_u8Z) -> Fallback { @@ -2017,7 +2067,7 @@ impl Clone for Bolt11InvoiceSignature { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Bolt11InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBolt11InvoiceSignature)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBolt11InvoiceSignature)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Bolt11InvoiceSignature @@ -2110,7 +2160,7 @@ impl Clone for PrivateRoute { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePrivateRoute)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePrivateRoute)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the PrivateRoute @@ -2745,6 +2795,16 @@ impl CreationError { pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn CreationError_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const CreationError)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn CreationError_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut CreationError) }; +} #[no_mangle] /// Utility method to constructs a new DescriptionTooLong-variant CreationError pub extern "C" fn CreationError_description_too_long() -> CreationError { @@ -2878,6 +2938,16 @@ impl Bolt11SemanticError { pub extern "C" fn Bolt11SemanticError_clone(orig: &Bolt11SemanticError) -> Bolt11SemanticError { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Bolt11SemanticError_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Bolt11SemanticError)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Bolt11SemanticError_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut Bolt11SemanticError) }; +} #[no_mangle] /// Utility method to constructs a new NoPaymentHash-variant Bolt11SemanticError pub extern "C" fn Bolt11SemanticError_no_payment_hash() -> Bolt11SemanticError { @@ -3010,6 +3080,16 @@ pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { } pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn SignOrCreationError_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const SignOrCreationError)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn SignOrCreationError_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut SignOrCreationError) }; +} #[no_mangle] /// Utility method to constructs a new SignError-variant SignOrCreationError pub extern "C" fn SignOrCreationError_sign_error() -> SignOrCreationError { diff --git a/lightning-c-bindings/src/lightning_invoice/payment.rs b/lightning-c-bindings/src/lightning_invoice/payment.rs index e94f0da..593a683 100644 --- a/lightning-c-bindings/src/lightning_invoice/payment.rs +++ b/lightning-c-bindings/src/lightning_invoice/payment.rs @@ -194,6 +194,16 @@ pub extern "C" fn PaymentError_free(this_ptr: PaymentError) { } pub extern "C" fn PaymentError_clone(orig: &PaymentError) -> PaymentError { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn PaymentError_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const PaymentError)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn PaymentError_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut PaymentError) }; +} #[no_mangle] /// Utility method to constructs a new Invoice-variant PaymentError pub extern "C" fn PaymentError_invoice(a: crate::c_types::Str) -> PaymentError { @@ -299,6 +309,16 @@ pub extern "C" fn ProbingError_free(this_ptr: ProbingError) { } pub extern "C" fn ProbingError_clone(orig: &ProbingError) -> ProbingError { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ProbingError_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const ProbingError)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ProbingError_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut ProbingError) }; +} #[no_mangle] /// Utility method to constructs a new Invoice-variant ProbingError pub extern "C" fn ProbingError_invoice(a: crate::c_types::Str) -> ProbingError { diff --git a/lightning-c-bindings/src/lightning_persister/fs_store.rs b/lightning-c-bindings/src/lightning_persister/fs_store.rs index a53f6e6..073d9d9 100644 --- a/lightning-c-bindings/src/lightning_persister/fs_store.rs +++ b/lightning-c-bindings/src/lightning_persister/fs_store.rs @@ -86,10 +86,10 @@ pub extern "C" fn FilesystemStore_get_data_dir(this_arg: &crate::lightning_persi impl From for crate::lightning::util::persist::KVStore { fn from(obj: nativeFilesystemStore) -> Self { - let mut rust_obj = FilesystemStore { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning_persister::fs_store::FilesystemStore { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = FilesystemStore_as_KVStore(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(FilesystemStore_free_void); ret } diff --git a/lightning-c-bindings/src/lightning_rapid_gossip_sync/error.rs b/lightning-c-bindings/src/lightning_rapid_gossip_sync/error.rs index 4a76839..4b1b6ff 100644 --- a/lightning-c-bindings/src/lightning_rapid_gossip_sync/error.rs +++ b/lightning-c-bindings/src/lightning_rapid_gossip_sync/error.rs @@ -108,6 +108,16 @@ pub extern "C" fn GraphSyncError_free(this_ptr: GraphSyncError) { } pub extern "C" fn GraphSyncError_clone(orig: &GraphSyncError) -> GraphSyncError { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn GraphSyncError_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const GraphSyncError)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn GraphSyncError_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut GraphSyncError) }; +} #[no_mangle] /// Utility method to constructs a new DecodeError-variant GraphSyncError pub extern "C" fn GraphSyncError_decode_error(a: crate::lightning::ln::msgs::DecodeError) -> GraphSyncError { -- 2.39.5