From: Matt Corallo Date: Sat, 16 Oct 2021 22:22:11 +0000 (+0000) Subject: Update auto-generated bindings X-Git-Tag: v0.0.102.0^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=7428d63475aee8fa920405fd14eda47113337798;p=ldk-c-bindings Update auto-generated bindings --- diff --git a/lightning-c-bindings/include/ldk_rust_types.h b/lightning-c-bindings/include/ldk_rust_types.h index 9c2fc19..497d259 100644 --- a/lightning-c-bindings/include/ldk_rust_types.h +++ b/lightning-c-bindings/include/ldk_rust_types.h @@ -60,6 +60,8 @@ struct nativeChannelFeaturesOpaque; typedef struct nativeChannelFeaturesOpaque LDKnativeChannelFeatures; struct nativeInvoiceFeaturesOpaque; typedef struct nativeInvoiceFeaturesOpaque LDKnativeInvoiceFeatures; +struct nativeScorerOpaque; +typedef struct nativeScorerOpaque LDKnativeScorer; struct nativeDelayedPaymentOutputDescriptorOpaque; typedef struct nativeDelayedPaymentOutputDescriptorOpaque LDKnativeDelayedPaymentOutputDescriptor; struct nativeStaticPaymentOutputDescriptorOpaque; @@ -71,6 +73,8 @@ struct nativeKeysManagerOpaque; typedef struct nativeKeysManagerOpaque LDKnativeKeysManager; struct nativeFilesystemPersisterOpaque; typedef struct nativeFilesystemPersisterOpaque LDKnativeFilesystemPersister; +struct nativePaymentIdOpaque; +typedef struct nativePaymentIdOpaque LDKnativePaymentId; struct nativeChannelManagerOpaque; typedef struct nativeChannelManagerOpaque LDKnativeChannelManager; struct nativeChainParametersOpaque; @@ -135,6 +139,8 @@ struct nativePeerHandleErrorOpaque; typedef struct nativePeerHandleErrorOpaque LDKnativePeerHandleError; struct nativePeerManagerOpaque; typedef struct nativePeerManagerOpaque LDKnativePeerManager; +struct nativeNodeIdOpaque; +typedef struct nativeNodeIdOpaque LDKnativeNodeId; struct nativeNetworkGraphOpaque; typedef struct nativeNetworkGraphOpaque LDKnativeNetworkGraph; struct nativeReadOnlyNetworkGraphOpaque; @@ -223,5 +229,7 @@ struct nativeLightningErrorOpaque; typedef struct nativeLightningErrorOpaque LDKnativeLightningError; struct nativeCommitmentUpdateOpaque; typedef struct nativeCommitmentUpdateOpaque LDKnativeCommitmentUpdate; +struct nativeLockedChannelMonitorOpaque; +typedef struct nativeLockedChannelMonitorOpaque LDKnativeLockedChannelMonitor; struct nativeChainMonitorOpaque; typedef struct nativeChainMonitorOpaque LDKnativeChainMonitor; diff --git a/lightning-c-bindings/include/lightning.h b/lightning-c-bindings/include/lightning.h index dad0072..17abdfd 100644 --- a/lightning-c-bindings/include/lightning.h +++ b/lightning-c-bindings/include/lightning.h @@ -1788,7 +1788,7 @@ typedef union LDKCResult_NoneChannelMonitorUpdateErrZPtr { /** * A CResult_NoneChannelMonitorUpdateErrZ represents the result of a fallible operation, - * containing a () on success and a crate::lightning::chain::channelmonitor::ChannelMonitorUpdateErr on failure. + * containing a () on success and a crate::lightning::chain::ChannelMonitorUpdateErr on failure. * `result_ok` indicates the overall state, and the contents are provided via `contents`. */ typedef struct LDKCResult_NoneChannelMonitorUpdateErrZ { @@ -3951,6 +3951,59 @@ typedef struct LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ { bool result_ok; } LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ; + + +/** + * A payment identifier used to uniquely identify a payment to LDK. + */ +typedef struct MUST_USE_STRUCT LDKPaymentId { + /** + * 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. + */ + LDKnativePaymentId *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; +} LDKPaymentId; + +/** + * The contents of CResult_PaymentIdDecodeErrorZ + */ +typedef union LDKCResult_PaymentIdDecodeErrorZPtr { + /** + * A pointer to the contents in the success state. + * Reading from this pointer when `result_ok` is not set is undefined. + */ + struct LDKPaymentId *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_PaymentIdDecodeErrorZPtr; + +/** + * A CResult_PaymentIdDecodeErrorZ represents the result of a fallible operation, + * containing a crate::lightning::ln::channelmanager::PaymentId 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_PaymentIdDecodeErrorZ { + /** + * The contents of this CResult_PaymentIdDecodeErrorZ, accessible via either + * `err` or `result` depending on the state of `result_ok`. + */ + union LDKCResult_PaymentIdDecodeErrorZPtr contents; + /** + * Whether this CResult_PaymentIdDecodeErrorZ represents a success state. + */ + bool result_ok; +} LDKCResult_PaymentIdDecodeErrorZ; + /** * An enum which can either contain a u16 or not */ @@ -4141,6 +4194,39 @@ typedef struct LDKCVec_APIErrorZ { uintptr_t datalen; } LDKCVec_APIErrorZ; +/** + * The contents of CResult__u832APIErrorZ + */ +typedef union LDKCResult__u832APIErrorZPtr { + /** + * A pointer to the contents in the success state. + * Reading from this pointer when `result_ok` is not set is undefined. + */ + struct LDKThirtyTwoBytes *result; + /** + * A pointer to the contents in the error state. + * Reading from this pointer when `result_ok` is set is undefined. + */ + struct LDKAPIError *err; +} LDKCResult__u832APIErrorZPtr; + +/** + * A CResult__u832APIErrorZ represents the result of a fallible operation, + * containing a crate::c_types::ThirtyTwoBytes on success and a crate::lightning::util::errors::APIError on failure. + * `result_ok` indicates the overall state, and the contents are provided via `contents`. + */ +typedef struct LDKCResult__u832APIErrorZ { + /** + * The contents of this CResult__u832APIErrorZ, accessible via either + * `err` or `result` depending on the state of `result_ok`. + */ + union LDKCResult__u832APIErrorZPtr contents; + /** + * Whether this CResult__u832APIErrorZ represents a success state. + */ + bool result_ok; +} LDKCResult__u832APIErrorZ; + /** * If a payment fails to send, it can be in one of several states. This enum is returned as the * Err() type describing which state the payment is in, see the description of individual enum @@ -4208,6 +4294,39 @@ typedef struct MUST_USE_STRUCT LDKPaymentSendFailure { }; } LDKPaymentSendFailure; +/** + * The contents of CResult_PaymentIdPaymentSendFailureZ + */ +typedef union LDKCResult_PaymentIdPaymentSendFailureZPtr { + /** + * A pointer to the contents in the success state. + * Reading from this pointer when `result_ok` is not set is undefined. + */ + struct LDKPaymentId *result; + /** + * A pointer to the contents in the error state. + * Reading from this pointer when `result_ok` is set is undefined. + */ + struct LDKPaymentSendFailure *err; +} LDKCResult_PaymentIdPaymentSendFailureZPtr; + +/** + * A CResult_PaymentIdPaymentSendFailureZ represents the result of a fallible operation, + * containing a crate::lightning::ln::channelmanager::PaymentId on success and a crate::lightning::ln::channelmanager::PaymentSendFailure on failure. + * `result_ok` indicates the overall state, and the contents are provided via `contents`. + */ +typedef struct LDKCResult_PaymentIdPaymentSendFailureZ { + /** + * The contents of this CResult_PaymentIdPaymentSendFailureZ, accessible via either + * `err` or `result` depending on the state of `result_ok`. + */ + union LDKCResult_PaymentIdPaymentSendFailureZPtr contents; + /** + * Whether this CResult_PaymentIdPaymentSendFailureZ represents a success state. + */ + bool result_ok; +} LDKCResult_PaymentIdPaymentSendFailureZ; + /** * The contents of CResult_NonePaymentSendFailureZ */ @@ -4241,37 +4360,51 @@ typedef struct LDKCResult_NonePaymentSendFailureZ { } LDKCResult_NonePaymentSendFailureZ; /** - * The contents of CResult_PaymentHashPaymentSendFailureZ + * A tuple of 2 elements. See the individual fields for the types contained. + */ +typedef struct LDKC2Tuple_PaymentHashPaymentIdZ { + /** + * The element at position 0 + */ + struct LDKThirtyTwoBytes a; + /** + * The element at position 1 + */ + struct LDKPaymentId b; +} LDKC2Tuple_PaymentHashPaymentIdZ; + +/** + * The contents of CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ */ -typedef union LDKCResult_PaymentHashPaymentSendFailureZPtr { +typedef union LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZPtr { /** * A pointer to the contents in the success state. * Reading from this pointer when `result_ok` is not set is undefined. */ - struct LDKThirtyTwoBytes *result; + struct LDKC2Tuple_PaymentHashPaymentIdZ *result; /** * A pointer to the contents in the error state. * Reading from this pointer when `result_ok` is set is undefined. */ struct LDKPaymentSendFailure *err; -} LDKCResult_PaymentHashPaymentSendFailureZPtr; +} LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZPtr; /** - * A CResult_PaymentHashPaymentSendFailureZ represents the result of a fallible operation, - * containing a crate::c_types::ThirtyTwoBytes on success and a crate::lightning::ln::channelmanager::PaymentSendFailure on failure. + * A CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ represents the result of a fallible operation, + * containing a crate::c_types::derived::C2Tuple_PaymentHashPaymentIdZ on success and a crate::lightning::ln::channelmanager::PaymentSendFailure on failure. * `result_ok` indicates the overall state, and the contents are provided via `contents`. */ -typedef struct LDKCResult_PaymentHashPaymentSendFailureZ { +typedef struct LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ { /** - * The contents of this CResult_PaymentHashPaymentSendFailureZ, accessible via either + * The contents of this CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ, accessible via either * `err` or `result` depending on the state of `result_ok`. */ - union LDKCResult_PaymentHashPaymentSendFailureZPtr contents; + union LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZPtr contents; /** - * Whether this CResult_PaymentHashPaymentSendFailureZ represents a success state. + * Whether this CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ represents a success state. */ bool result_ok; -} LDKCResult_PaymentHashPaymentSendFailureZ; +} LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ; /** * A 4-byte byte array. @@ -4512,9 +4645,7 @@ typedef struct MUST_USE_STRUCT LDKChannelMonitorUpdate { * funds in the channel. See [`ChannelMonitorUpdateErr`] for more details about how to handle * multiple instances. * - * [`ChannelMonitor`]: channelmonitor::ChannelMonitor - * [`ChannelMonitorUpdateErr`]: channelmonitor::ChannelMonitorUpdateErr - * [`PermanentFailure`]: channelmonitor::ChannelMonitorUpdateErr::PermanentFailure + * [`PermanentFailure`]: ChannelMonitorUpdateErr::PermanentFailure */ typedef struct LDKWatch { /** @@ -4529,6 +4660,9 @@ typedef struct LDKWatch { * with any spends of outputs returned by [`get_outputs_to_watch`]. In practice, this means * calling [`block_connected`] and [`block_disconnected`] on the monitor. * + * Note: this interface MUST error with `ChannelMonitorUpdateErr::PermanentFailure` if + * the given `funding_txo` has previously been registered via `watch_channel`. + * * [`get_outputs_to_watch`]: channelmonitor::ChannelMonitor::get_outputs_to_watch * [`block_connected`]: channelmonitor::ChannelMonitor::block_connected * [`block_disconnected`]: channelmonitor::ChannelMonitor::block_disconnected @@ -4541,7 +4675,6 @@ typedef struct LDKWatch { * [`ChannelMonitorUpdateErr`] for invariants around returning an error. * * [`update_monitor`]: channelmonitor::ChannelMonitor::update_monitor - * [`ChannelMonitorUpdateErr`]: channelmonitor::ChannelMonitorUpdateErr */ struct LDKCResult_NoneChannelMonitorUpdateErrZ (*update_channel)(const void *this_arg, struct LDKOutPoint funding_txo, struct LDKChannelMonitorUpdate update); /** @@ -5951,15 +6084,16 @@ typedef enum LDKEvent_Tag { LDKEvent_FundingGenerationReady, /** * Indicates we've received money! Just gotta dig out that payment preimage and feed it to - * ChannelManager::claim_funds to get it.... - * Note that if the preimage is not known or the amount paid is incorrect, you should call - * ChannelManager::fail_htlc_backwards to free up resources for this HTLC and avoid + * [`ChannelManager::claim_funds`] to get it.... + * Note that if the preimage is not known, you should call + * [`ChannelManager::fail_htlc_backwards`] to free up resources for this HTLC and avoid * network congestion. - * The amount paid should be considered 'incorrect' when it is less than or more than twice - * the amount expected. - * If you fail to call either ChannelManager::claim_funds or - * ChannelManager::fail_htlc_backwards within the HTLC's timeout, the HTLC will be + * If you fail to call either [`ChannelManager::claim_funds`] or + * [`ChannelManager::fail_htlc_backwards`] within the HTLC's timeout, the HTLC will be * automatically failed. + * + * [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds + * [`ChannelManager::fail_htlc_backwards`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards */ LDKEvent_PaymentReceived, /** @@ -5997,6 +6131,11 @@ typedef enum LDKEvent_Tag { * Used to indicate that a channel with the given `channel_id` is in the process of closure. */ LDKEvent_ChannelClosed, + /** + * Used to indicate to the user that they can abandon the funding transaction and recycle the + * inputs for another purpose. + */ + LDKEvent_DiscardFunding, /** * Must be last for serialization purposes */ @@ -6018,7 +6157,10 @@ typedef struct LDKEvent_LDKFundingGenerationReady_Body { */ struct LDKCVec_u8Z output_script; /** - * The value passed in to ChannelManager::create_channel + * The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or 0 for + * an inbound channel. + * + * [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel */ uint64_t user_channel_id; } LDKEvent_LDKFundingGenerationReady_Body; @@ -6029,9 +6171,7 @@ typedef struct LDKEvent_LDKPaymentReceived_Body { */ struct LDKThirtyTwoBytes payment_hash; /** - * The value, in thousandths of a satoshi, that this payment is for. Note that you must - * compare this to the expected value before accepting the payment (as otherwise you are - * providing proof-of-payment for less than the value you expected!). + * The value, in thousandths of a satoshi, that this payment is for. */ uint64_t amt; /** @@ -6048,6 +6188,12 @@ typedef struct LDKEvent_LDKPaymentSent_Body { * store it somehow! */ struct LDKThirtyTwoBytes payment_preimage; + /** + * The hash which was given to [`ChannelManager::send_payment`]. + * + * [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + */ + struct LDKThirtyTwoBytes payment_hash; } LDKEvent_LDKPaymentSent_Body; typedef struct LDKEvent_LDKPaymentPathFailed_Body { @@ -6082,6 +6228,13 @@ typedef struct LDKEvent_LDKPaymentPathFailed_Body { * The payment path that failed. */ struct LDKCVec_RouteHopZ path; + /** + * The channel responsible for the failed payment path. + * + * If this is `Some`, then the corresponding channel should be avoided when the payment is + * retried. May be `None` for older [`Event`] serializations. + */ + struct LDKCOption_u64Z short_channel_id; } LDKEvent_LDKPaymentPathFailed_Body; typedef struct LDKEvent_LDKPendingHTLCsForwardable_Body { @@ -6131,12 +6284,31 @@ typedef struct LDKEvent_LDKChannelClosed_Body { * resolving the channel are likely still awaiting confirmation. */ struct LDKThirtyTwoBytes channel_id; + /** + * The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or 0 for + * an inbound channel. This will always be zero for objects serialized with LDK versions + * prior to 0.0.102. + * + * [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel + */ + uint64_t user_channel_id; /** * The reason the channel was closed. */ struct LDKClosureReason reason; } LDKEvent_LDKChannelClosed_Body; +typedef struct LDKEvent_LDKDiscardFunding_Body { + /** + * The channel_id of the channel which has been closed. + */ + struct LDKThirtyTwoBytes channel_id; + /** + * The full transaction received from the user + */ + struct LDKTransaction transaction; +} LDKEvent_LDKDiscardFunding_Body; + typedef struct MUST_USE_STRUCT LDKEvent { LDKEvent_Tag tag; union { @@ -6148,6 +6320,7 @@ typedef struct MUST_USE_STRUCT LDKEvent { LDKEvent_LDKSpendableOutputs_Body spendable_outputs; LDKEvent_LDKPaymentForwarded_Body payment_forwarded; LDKEvent_LDKChannelClosed_Body channel_closed; + LDKEvent_LDKDiscardFunding_Body discard_funding; }; } LDKEvent; @@ -6670,6 +6843,59 @@ typedef struct LDKCResult_boolPeerHandleErrorZ { bool result_ok; } LDKCResult_boolPeerHandleErrorZ; + + +/** + * Represents the compressed public key of a node + */ +typedef struct MUST_USE_STRUCT LDKNodeId { + /** + * 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. + */ + LDKnativeNodeId *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; +} LDKNodeId; + +/** + * The contents of CResult_NodeIdDecodeErrorZ + */ +typedef union LDKCResult_NodeIdDecodeErrorZPtr { + /** + * A pointer to the contents in the success state. + * Reading from this pointer when `result_ok` is not set is undefined. + */ + struct LDKNodeId *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_NodeIdDecodeErrorZPtr; + +/** + * A CResult_NodeIdDecodeErrorZ represents the result of a fallible operation, + * containing a crate::lightning::routing::network_graph::NodeId 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_NodeIdDecodeErrorZ { + /** + * The contents of this CResult_NodeIdDecodeErrorZ, accessible via either + * `err` or `result` depending on the state of `result_ok`. + */ + union LDKCResult_NodeIdDecodeErrorZPtr contents; + /** + * Whether this CResult_NodeIdDecodeErrorZ represents a success state. + */ + bool result_ok; +} LDKCResult_NodeIdDecodeErrorZ; + /** * The `Access` trait defines behavior for accessing chain data and state, such as blocks and * UTXOs. @@ -7058,6 +7284,33 @@ typedef struct LDKCResult_NetworkGraphDecodeErrorZ { bool result_ok; } LDKCResult_NetworkGraphDecodeErrorZ; +/** + * An enum which can either contain a crate::c_types::derived::CVec_NetAddressZ or not + */ +typedef enum LDKCOption_CVec_NetAddressZZ_Tag { + /** + * When we're in this state, this COption_CVec_NetAddressZZ contains a crate::c_types::derived::CVec_NetAddressZ + */ + LDKCOption_CVec_NetAddressZZ_Some, + /** + * When we're in this state, this COption_CVec_NetAddressZZ contains nothing + */ + LDKCOption_CVec_NetAddressZZ_None, + /** + * Must be last for serialization purposes + */ + LDKCOption_CVec_NetAddressZZ_Sentinel, +} LDKCOption_CVec_NetAddressZZ_Tag; + +typedef struct LDKCOption_CVec_NetAddressZZ { + LDKCOption_CVec_NetAddressZZ_Tag tag; + union { + struct { + struct LDKCVec_NetAddressZ some; + }; + }; +} LDKCOption_CVec_NetAddressZZ; + /** * The contents of CResult_NetAddressu8Z */ @@ -8673,7 +8926,7 @@ typedef struct MUST_USE_STRUCT LDKWatchedOutput { * processed later. Then, in order to block until the data has been processed, any [`Watch`] * invocation that has called the `Filter` must return [`TemporaryFailure`]. * - * [`TemporaryFailure`]: channelmonitor::ChannelMonitorUpdateErr::TemporaryFailure + * [`TemporaryFailure`]: ChannelMonitorUpdateErr::TemporaryFailure * [BIP 157]: https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki * [BIP 158]: https://github.com/bitcoin/bips/blob/master/bip-0158.mediawiki */ @@ -8734,6 +8987,77 @@ typedef struct LDKCOption_FilterZ { }; } LDKCOption_FilterZ; + + +/** + * A read-only reference to a current ChannelMonitor. + * + * Note that this holds a mutex in [`ChainMonitor`] and may block other events until it is + * released. + */ +typedef struct MUST_USE_STRUCT LDKLockedChannelMonitor { + /** + * 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. + */ + LDKnativeLockedChannelMonitor *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; +} LDKLockedChannelMonitor; + +/** + * The contents of CResult_LockedChannelMonitorNoneZ + */ +typedef union LDKCResult_LockedChannelMonitorNoneZPtr { + /** + * A pointer to the contents in the success state. + * Reading from this pointer when `result_ok` is not set is undefined. + */ + struct LDKLockedChannelMonitor *result; + /** + * Note that this value is always NULL, as there are no contents in the Err variant + */ + void *err; +} LDKCResult_LockedChannelMonitorNoneZPtr; + +/** + * A CResult_LockedChannelMonitorNoneZ represents the result of a fallible operation, + * containing a crate::lightning::chain::chainmonitor::LockedChannelMonitor on success and a () on failure. + * `result_ok` indicates the overall state, and the contents are provided via `contents`. + */ +typedef struct LDKCResult_LockedChannelMonitorNoneZ { + /** + * The contents of this CResult_LockedChannelMonitorNoneZ, accessible via either + * `err` or `result` depending on the state of `result_ok`. + */ + union LDKCResult_LockedChannelMonitorNoneZPtr contents; + /** + * Whether this CResult_LockedChannelMonitorNoneZ represents a success state. + */ + bool result_ok; +} LDKCResult_LockedChannelMonitorNoneZ; + +/** + * A dynamically-allocated array of crate::lightning::chain::transaction::OutPoints of arbitrary size. + * This corresponds to std::vector in C++ + */ +typedef struct LDKCVec_OutPointZ { + /** + * The elements in the array. + * If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc(). + */ + struct LDKOutPoint *data; + /** + * The number of elements pointed to by `data`. + */ + uintptr_t datalen; +} LDKCVec_OutPointZ; + /** * A trait indicating an object may generate message send events */ @@ -9072,8 +9396,10 @@ typedef struct LDKPersist { * stored channel data). Note that you **must** persist every new monitor to * disk. See the `Persist` trait documentation for more details. * - * See [`ChannelMonitor::write`] for writing out a `ChannelMonitor`, + * See [`Writeable::write`] on [`ChannelMonitor`] for writing out a `ChannelMonitor` * and [`ChannelMonitorUpdateErr`] for requirements when returning errors. + * + * [`Writeable::write`]: crate::util::ser::Writeable::write */ struct LDKCResult_NoneChannelMonitorUpdateErrZ (*persist_new_channel)(const void *this_arg, struct LDKOutPoint id, const struct LDKChannelMonitor *NONNULL_PTR data); /** @@ -9096,9 +9422,11 @@ typedef struct LDKPersist { * them in batches. The size of each monitor grows `O(number of state updates)` * whereas updates are small and `O(1)`. * - * See [`ChannelMonitor::write`] for writing out a `ChannelMonitor`, - * [`ChannelMonitorUpdate::write`] for writing out an update, and + * See [`Writeable::write`] on [`ChannelMonitor`] for writing out a `ChannelMonitor`, + * [`Writeable::write`] on [`ChannelMonitorUpdate`] for writing out an update, and * [`ChannelMonitorUpdateErr`] for requirements when returning errors. + * + * [`Writeable::write`]: crate::util::ser::Writeable::write */ struct LDKCResult_NoneChannelMonitorUpdateErrZ (*update_persisted_channel)(const void *this_arg, struct LDKOutPoint id, const struct LDKChannelMonitorUpdate *NONNULL_PTR update, const struct LDKChannelMonitor *NONNULL_PTR data); /** @@ -9744,25 +10072,27 @@ typedef struct MUST_USE_STRUCT LDKDirectedChannelTransactionParameters { bool is_owned; } LDKDirectedChannelTransactionParameters; - - /** - * A channel descriptor for a hop along a payment path. + * An interface used to score payment channels for path finding. + * + *\tScoring is in terms of fees willing to be paid in order to avoid routing through a channel. */ -typedef struct MUST_USE_STRUCT LDKRouteHintHop { +typedef struct LDKScore { /** - * 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. + * 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. */ - LDKnativeRouteHintHop *inner; + void *this_arg; /** - * 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. + * Returns the fee in msats willing to be paid to avoid routing through the given channel. */ - bool is_owned; -} LDKRouteHintHop; + uint64_t (*channel_penalty_msat)(const void *this_arg, 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. + */ + void (*free)(void *this_arg); +} LDKScore; @@ -9814,15 +10144,62 @@ typedef struct MUST_USE_STRUCT LDKNetGraphMsgHandler { /** - * FilesystemPersister persists channel data on disk, where each channel's - * data is stored in a file named after its funding outpoint. - * - * Warning: this module does the best it can with calls to persist data, but it - * can only guarantee that the data is passed to the drive. It is up to the - * drive manufacturers to do the actual persistence properly, which they often - * don't (especially on consumer-grade hardware). Therefore, it is up to the - * user to validate their entire storage stack, to ensure the writes are - * persistent. + * A channel descriptor for a hop along a payment path. + */ +typedef struct MUST_USE_STRUCT LDKRouteHintHop { + /** + * 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. + */ + LDKnativeRouteHintHop *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; +} LDKRouteHintHop; + + + +/** + * [`routing::Score`] implementation that provides reasonable default behavior. + * + * Used to apply a fixed penalty to each channel, thus avoiding long paths when shorter paths with + * slightly higher fees are available. + * + * See [module-level documentation] for usage. + * + * [module-level documentation]: crate::routing::scorer + */ +typedef struct MUST_USE_STRUCT LDKScorer { + /** + * 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. + */ + LDKnativeScorer *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; +} LDKScorer; + + + +/** + * FilesystemPersister persists channel data on disk, where each channel's + * data is stored in a file named after its funding outpoint. + * + * Warning: this module does the best it can with calls to persist data, but it + * can only guarantee that the data is passed to the drive. It is up to the + * drive manufacturers to do the actual persistence properly, which they often + * don't (especially on consumer-grade hardware). Therefore, it is up to the + * user to validate their entire storage stack, to ensure the writes are + * persistent. * Corollary: especially when dealing with larger amounts of money, it is best * practice to have multiple channel data backups and not rely only on one * FilesystemPersister. @@ -11026,6 +11403,27 @@ struct LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ CResult_CVec_C2Tu */ void CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ_free(struct LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ _res); +/** + * Creates a new CResult_PaymentIdDecodeErrorZ in the success state. + */ +struct LDKCResult_PaymentIdDecodeErrorZ CResult_PaymentIdDecodeErrorZ_ok(struct LDKPaymentId o); + +/** + * Creates a new CResult_PaymentIdDecodeErrorZ in the error state. + */ +struct LDKCResult_PaymentIdDecodeErrorZ CResult_PaymentIdDecodeErrorZ_err(struct LDKDecodeError e); + +/** + * Frees any resources used by the CResult_PaymentIdDecodeErrorZ. + */ +void CResult_PaymentIdDecodeErrorZ_free(struct LDKCResult_PaymentIdDecodeErrorZ _res); + +/** + * Creates a new CResult_PaymentIdDecodeErrorZ which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. + */ +struct LDKCResult_PaymentIdDecodeErrorZ CResult_PaymentIdDecodeErrorZ_clone(const struct LDKCResult_PaymentIdDecodeErrorZ *NONNULL_PTR orig); + /** * Constructs a new COption_u16Z containing a u16 */ @@ -11078,6 +11476,48 @@ void CVec_CResult_NoneAPIErrorZZ_free(struct LDKCVec_CResult_NoneAPIErrorZZ _res */ void CVec_APIErrorZ_free(struct LDKCVec_APIErrorZ _res); +/** + * Creates a new CResult__u832APIErrorZ in the success state. + */ +struct LDKCResult__u832APIErrorZ CResult__u832APIErrorZ_ok(struct LDKThirtyTwoBytes o); + +/** + * Creates a new CResult__u832APIErrorZ in the error state. + */ +struct LDKCResult__u832APIErrorZ CResult__u832APIErrorZ_err(struct LDKAPIError e); + +/** + * Frees any resources used by the CResult__u832APIErrorZ. + */ +void CResult__u832APIErrorZ_free(struct LDKCResult__u832APIErrorZ _res); + +/** + * Creates a new CResult__u832APIErrorZ which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. + */ +struct LDKCResult__u832APIErrorZ CResult__u832APIErrorZ_clone(const struct LDKCResult__u832APIErrorZ *NONNULL_PTR orig); + +/** + * Creates a new CResult_PaymentIdPaymentSendFailureZ in the success state. + */ +struct LDKCResult_PaymentIdPaymentSendFailureZ CResult_PaymentIdPaymentSendFailureZ_ok(struct LDKPaymentId o); + +/** + * Creates a new CResult_PaymentIdPaymentSendFailureZ in the error state. + */ +struct LDKCResult_PaymentIdPaymentSendFailureZ CResult_PaymentIdPaymentSendFailureZ_err(struct LDKPaymentSendFailure e); + +/** + * Frees any resources used by the CResult_PaymentIdPaymentSendFailureZ. + */ +void CResult_PaymentIdPaymentSendFailureZ_free(struct LDKCResult_PaymentIdPaymentSendFailureZ _res); + +/** + * Creates a new CResult_PaymentIdPaymentSendFailureZ which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. + */ +struct LDKCResult_PaymentIdPaymentSendFailureZ CResult_PaymentIdPaymentSendFailureZ_clone(const struct LDKCResult_PaymentIdPaymentSendFailureZ *NONNULL_PTR orig); + /** * Creates a new CResult_NonePaymentSendFailureZ in the success state. */ @@ -11100,25 +11540,41 @@ void CResult_NonePaymentSendFailureZ_free(struct LDKCResult_NonePaymentSendFailu struct LDKCResult_NonePaymentSendFailureZ CResult_NonePaymentSendFailureZ_clone(const struct LDKCResult_NonePaymentSendFailureZ *NONNULL_PTR orig); /** - * Creates a new CResult_PaymentHashPaymentSendFailureZ in the success state. + * Creates a new tuple which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. + */ +struct LDKC2Tuple_PaymentHashPaymentIdZ C2Tuple_PaymentHashPaymentIdZ_clone(const struct LDKC2Tuple_PaymentHashPaymentIdZ *NONNULL_PTR orig); + +/** + * Creates a new C2Tuple_PaymentHashPaymentIdZ from the contained elements. + */ +struct LDKC2Tuple_PaymentHashPaymentIdZ C2Tuple_PaymentHashPaymentIdZ_new(struct LDKThirtyTwoBytes a, struct LDKPaymentId b); + +/** + * Frees any resources used by the C2Tuple_PaymentHashPaymentIdZ. + */ +void C2Tuple_PaymentHashPaymentIdZ_free(struct LDKC2Tuple_PaymentHashPaymentIdZ _res); + +/** + * Creates a new CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ in the success state. */ -struct LDKCResult_PaymentHashPaymentSendFailureZ CResult_PaymentHashPaymentSendFailureZ_ok(struct LDKThirtyTwoBytes o); +struct LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ_ok(struct LDKC2Tuple_PaymentHashPaymentIdZ o); /** - * Creates a new CResult_PaymentHashPaymentSendFailureZ in the error state. + * Creates a new CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ in the error state. */ -struct LDKCResult_PaymentHashPaymentSendFailureZ CResult_PaymentHashPaymentSendFailureZ_err(struct LDKPaymentSendFailure e); +struct LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ_err(struct LDKPaymentSendFailure e); /** - * Frees any resources used by the CResult_PaymentHashPaymentSendFailureZ. + * Frees any resources used by the CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ. */ -void CResult_PaymentHashPaymentSendFailureZ_free(struct LDKCResult_PaymentHashPaymentSendFailureZ _res); +void CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ_free(struct LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ _res); /** - * Creates a new CResult_PaymentHashPaymentSendFailureZ which has the same data as `orig` + * Creates a new CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ which has the same data as `orig` * but with all dynamically-allocated buffers duplicated in new buffers. */ -struct LDKCResult_PaymentHashPaymentSendFailureZ CResult_PaymentHashPaymentSendFailureZ_clone(const struct LDKCResult_PaymentHashPaymentSendFailureZ *NONNULL_PTR orig); +struct LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ_clone(const struct LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ *NONNULL_PTR orig); /** * Frees the buffer pointed to by `data` if `datalen` is non-0. @@ -11854,6 +12310,27 @@ void CResult_boolPeerHandleErrorZ_free(struct LDKCResult_boolPeerHandleErrorZ _r */ struct LDKCResult_boolPeerHandleErrorZ CResult_boolPeerHandleErrorZ_clone(const struct LDKCResult_boolPeerHandleErrorZ *NONNULL_PTR orig); +/** + * Creates a new CResult_NodeIdDecodeErrorZ in the success state. + */ +struct LDKCResult_NodeIdDecodeErrorZ CResult_NodeIdDecodeErrorZ_ok(struct LDKNodeId o); + +/** + * Creates a new CResult_NodeIdDecodeErrorZ in the error state. + */ +struct LDKCResult_NodeIdDecodeErrorZ CResult_NodeIdDecodeErrorZ_err(struct LDKDecodeError e); + +/** + * Frees any resources used by the CResult_NodeIdDecodeErrorZ. + */ +void CResult_NodeIdDecodeErrorZ_free(struct LDKCResult_NodeIdDecodeErrorZ _res); + +/** + * Creates a new CResult_NodeIdDecodeErrorZ which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. + */ +struct LDKCResult_NodeIdDecodeErrorZ CResult_NodeIdDecodeErrorZ_clone(const struct LDKCResult_NodeIdDecodeErrorZ *NONNULL_PTR orig); + /** * Constructs a new COption_AccessZ containing a crate::lightning::chain::Access */ @@ -12000,6 +12477,27 @@ void CResult_NetworkGraphDecodeErrorZ_free(struct LDKCResult_NetworkGraphDecodeE */ struct LDKCResult_NetworkGraphDecodeErrorZ CResult_NetworkGraphDecodeErrorZ_clone(const struct LDKCResult_NetworkGraphDecodeErrorZ *NONNULL_PTR orig); +/** + * Constructs a new COption_CVec_NetAddressZZ containing a crate::c_types::derived::CVec_NetAddressZ + */ +struct LDKCOption_CVec_NetAddressZZ COption_CVec_NetAddressZZ_some(struct LDKCVec_NetAddressZ o); + +/** + * Constructs a new COption_CVec_NetAddressZZ containing nothing + */ +struct LDKCOption_CVec_NetAddressZZ COption_CVec_NetAddressZZ_none(void); + +/** + * Frees any resources associated with the crate::c_types::derived::CVec_NetAddressZ, if we are in the Some state + */ +void COption_CVec_NetAddressZZ_free(struct LDKCOption_CVec_NetAddressZZ _res); + +/** + * Creates a new COption_CVec_NetAddressZZ which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. + */ +struct LDKCOption_CVec_NetAddressZZ COption_CVec_NetAddressZZ_clone(const struct LDKCOption_CVec_NetAddressZZ *NONNULL_PTR orig); + /** * Creates a new CResult_NetAddressu8Z in the success state. */ @@ -12791,6 +13289,26 @@ struct LDKCOption_FilterZ COption_FilterZ_none(void); */ void COption_FilterZ_free(struct LDKCOption_FilterZ _res); +/** + * Creates a new CResult_LockedChannelMonitorNoneZ in the success state. + */ +struct LDKCResult_LockedChannelMonitorNoneZ CResult_LockedChannelMonitorNoneZ_ok(struct LDKLockedChannelMonitor o); + +/** + * Creates a new CResult_LockedChannelMonitorNoneZ in the error state. + */ +struct LDKCResult_LockedChannelMonitorNoneZ CResult_LockedChannelMonitorNoneZ_err(void); + +/** + * Frees any resources used by the CResult_LockedChannelMonitorNoneZ. + */ +void CResult_LockedChannelMonitorNoneZ_free(struct LDKCResult_LockedChannelMonitorNoneZ _res); + +/** + * Frees the buffer pointed to by `data` if `datalen` is non-0. + */ +void CVec_OutPointZ_free(struct LDKCVec_OutPointZ _res); + /** * Frees any resources used by the PaymentPurpose */ @@ -12884,12 +13402,12 @@ struct LDKEvent Event_payment_received(struct LDKThirtyTwoBytes payment_hash, ui /** * Utility method to constructs a new PaymentSent-variant Event */ -struct LDKEvent Event_payment_sent(struct LDKThirtyTwoBytes payment_preimage); +struct LDKEvent Event_payment_sent(struct LDKThirtyTwoBytes payment_preimage, struct LDKThirtyTwoBytes payment_hash); /** * Utility method to constructs a new PaymentPathFailed-variant Event */ -struct LDKEvent Event_payment_path_failed(struct LDKThirtyTwoBytes payment_hash, bool rejected_by_dest, struct LDKCOption_NetworkUpdateZ network_update, bool all_paths_failed, struct LDKCVec_RouteHopZ path); +struct LDKEvent Event_payment_path_failed(struct LDKThirtyTwoBytes payment_hash, bool rejected_by_dest, struct LDKCOption_NetworkUpdateZ network_update, bool all_paths_failed, struct LDKCVec_RouteHopZ path, struct LDKCOption_u64Z short_channel_id); /** * Utility method to constructs a new PendingHTLCsForwardable-variant Event @@ -12909,7 +13427,12 @@ struct LDKEvent Event_payment_forwarded(struct LDKCOption_u64Z fee_earned_msat, /** * Utility method to constructs a new ChannelClosed-variant Event */ -struct LDKEvent Event_channel_closed(struct LDKThirtyTwoBytes channel_id, struct LDKClosureReason reason); +struct LDKEvent Event_channel_closed(struct LDKThirtyTwoBytes channel_id, uint64_t user_channel_id, struct LDKClosureReason reason); + +/** + * Utility method to constructs a new DiscardFunding-variant Event + */ +struct LDKEvent Event_discard_funding(struct LDKThirtyTwoBytes channel_id, struct LDKTransaction transaction); /** * Serialize the Event object into a byte array which can be read by Event_read @@ -13840,6 +14363,21 @@ void Listen_free(struct LDKListen this_ptr); */ void Confirm_free(struct LDKConfirm this_ptr); +/** + * Creates a copy of the ChannelMonitorUpdateErr + */ +enum LDKChannelMonitorUpdateErr ChannelMonitorUpdateErr_clone(const enum LDKChannelMonitorUpdateErr *NONNULL_PTR orig); + +/** + * Utility method to constructs a new TemporaryFailure-variant ChannelMonitorUpdateErr + */ +enum LDKChannelMonitorUpdateErr ChannelMonitorUpdateErr_temporary_failure(void); + +/** + * Utility method to constructs a new PermanentFailure-variant ChannelMonitorUpdateErr + */ +enum LDKChannelMonitorUpdateErr ChannelMonitorUpdateErr_permanent_failure(void); + /** * Calls the free function if one is set */ @@ -13940,6 +14478,16 @@ bool ConfirmationTarget_eq(const enum LDKConfirmationTarget *NONNULL_PTR a, cons */ void FeeEstimator_free(struct LDKFeeEstimator this_ptr); +/** + * Calls the free function if one is set + */ +void Persist_free(struct LDKPersist this_ptr); + +/** + * Frees any resources used by the LockedChannelMonitor, if is_owned is set and inner is non-NULL. + */ +void LockedChannelMonitor_free(struct LDKLockedChannelMonitor this_obj); + /** * Frees any resources used by the ChainMonitor, if is_owned is set and inner is non-NULL. */ @@ -13969,6 +14517,23 @@ MUST_USE_RES struct LDKChainMonitor ChainMonitor_new(struct LDKCOption_FilterZ c */ MUST_USE_RES struct LDKCVec_BalanceZ ChainMonitor_get_claimable_balances(const struct LDKChainMonitor *NONNULL_PTR this_arg, struct LDKCVec_ChannelDetailsZ ignored_channels); +/** + * Gets the [`LockedChannelMonitor`] for a given funding outpoint, returning an `Err` if no + * such [`ChannelMonitor`] is currently being monitored for. + * + * Note that the result holds a mutex over our monitor set, and should not be held + * indefinitely. + */ +MUST_USE_RES struct LDKCResult_LockedChannelMonitorNoneZ ChainMonitor_get_monitor(const struct LDKChainMonitor *NONNULL_PTR this_arg, struct LDKOutPoint funding_txo); + +/** + * Lists the funding outpoint of each [`ChannelMonitor`] being monitored. + * + * Note that [`ChannelMonitor`]s are not removed when a channel is closed as they are always + * monitoring for on-chain state resolutions. + */ +MUST_USE_RES struct LDKCVec_OutPointZ ChainMonitor_list_monitors(const struct LDKChainMonitor *NONNULL_PTR this_arg); + /** * Constructs a new Listen which calls the relevant methods on this_arg. * This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is @@ -14043,21 +14608,6 @@ struct LDKCVec_u8Z ChannelMonitorUpdate_write(const struct LDKChannelMonitorUpda */ struct LDKCResult_ChannelMonitorUpdateDecodeErrorZ ChannelMonitorUpdate_read(struct LDKu8slice ser); -/** - * Creates a copy of the ChannelMonitorUpdateErr - */ -enum LDKChannelMonitorUpdateErr ChannelMonitorUpdateErr_clone(const enum LDKChannelMonitorUpdateErr *NONNULL_PTR orig); - -/** - * Utility method to constructs a new TemporaryFailure-variant ChannelMonitorUpdateErr - */ -enum LDKChannelMonitorUpdateErr ChannelMonitorUpdateErr_temporary_failure(void); - -/** - * Utility method to constructs a new PermanentFailure-variant ChannelMonitorUpdateErr - */ -enum LDKChannelMonitorUpdateErr ChannelMonitorUpdateErr_permanent_failure(void); - /** * Frees any resources used by the MonitorUpdateError, if is_owned is set and inner is non-NULL. */ @@ -14297,11 +14847,6 @@ MUST_USE_RES struct LDKBestBlock ChannelMonitor_current_best_block(const struct */ MUST_USE_RES struct LDKCVec_BalanceZ ChannelMonitor_get_claimable_balances(const struct LDKChannelMonitor *NONNULL_PTR this_arg); -/** - * Calls the free function if one is set - */ -void Persist_free(struct LDKPersist this_ptr); - /** * Read a C2Tuple_BlockHashChannelMonitorZ from a byte array, created by C2Tuple_BlockHashChannelMonitorZ_write */ @@ -14802,6 +15347,38 @@ MUST_USE_RES struct LDKCResult_TransactionNoneZ KeysManager_spend_spendable_outp */ struct LDKKeysInterface KeysManager_as_KeysInterface(const struct LDKKeysManager *NONNULL_PTR this_arg); +/** + * Frees any resources used by the PaymentId, if is_owned is set and inner is non-NULL. + */ +void PaymentId_free(struct LDKPaymentId this_obj); + +/** + * Checks if two PaymentIds contain equal inner contents. + */ +uint64_t PaymentId_hash(const struct LDKPaymentId *NONNULL_PTR o); + +/** + * Creates a copy of the PaymentId + */ +struct LDKPaymentId PaymentId_clone(const struct LDKPaymentId *NONNULL_PTR orig); + +/** + * Checks if two PaymentIds 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 PaymentId_eq(const struct LDKPaymentId *NONNULL_PTR a, const struct LDKPaymentId *NONNULL_PTR b); + +/** + * Serialize the PaymentId object into a byte array which can be read by PaymentId_read + */ +struct LDKCVec_u8Z PaymentId_write(const struct LDKPaymentId *NONNULL_PTR obj); + +/** + * Read a PaymentId from a byte array, created by PaymentId_write + */ +struct LDKCResult_PaymentIdDecodeErrorZ PaymentId_read(struct LDKu8slice ser); + /** * Frees any resources used by the ChannelManager, if is_owned is set and inner is non-NULL. */ @@ -15074,14 +15651,14 @@ struct LDKCOption_u64Z ChannelDetails_get_unspendable_punishment_reserve(const s void ChannelDetails_set_unspendable_punishment_reserve(struct LDKChannelDetails *NONNULL_PTR this_ptr, struct LDKCOption_u64Z val); /** - * The user_id passed in to create_channel, or 0 if the channel was inbound. + * The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound. */ -uint64_t ChannelDetails_get_user_id(const struct LDKChannelDetails *NONNULL_PTR this_ptr); +uint64_t ChannelDetails_get_user_channel_id(const struct LDKChannelDetails *NONNULL_PTR this_ptr); /** - * The user_id passed in to create_channel, or 0 if the channel was inbound. + * The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound. */ -void ChannelDetails_set_user_id(struct LDKChannelDetails *NONNULL_PTR this_ptr, uint64_t val); +void ChannelDetails_set_user_channel_id(struct LDKChannelDetails *NONNULL_PTR this_ptr, uint64_t val); /** * The available outbound capacity for sending HTLCs to the remote peer. This does not include @@ -15246,7 +15823,7 @@ void ChannelDetails_set_is_public(struct LDKChannelDetails *NONNULL_PTR this_ptr /** * Constructs a new ChannelDetails given each field */ -MUST_USE_RES struct LDKChannelDetails ChannelDetails_new(struct LDKThirtyTwoBytes channel_id_arg, struct LDKChannelCounterparty counterparty_arg, struct LDKOutPoint funding_txo_arg, struct LDKCOption_u64Z short_channel_id_arg, uint64_t channel_value_satoshis_arg, struct LDKCOption_u64Z unspendable_punishment_reserve_arg, uint64_t user_id_arg, uint64_t outbound_capacity_msat_arg, uint64_t inbound_capacity_msat_arg, struct LDKCOption_u32Z confirmations_required_arg, struct LDKCOption_u16Z force_close_spend_delay_arg, bool is_outbound_arg, bool is_funding_locked_arg, bool is_usable_arg, bool is_public_arg); +MUST_USE_RES struct LDKChannelDetails ChannelDetails_new(struct LDKThirtyTwoBytes channel_id_arg, struct LDKChannelCounterparty counterparty_arg, struct LDKOutPoint funding_txo_arg, struct LDKCOption_u64Z short_channel_id_arg, uint64_t channel_value_satoshis_arg, struct LDKCOption_u64Z unspendable_punishment_reserve_arg, uint64_t user_channel_id_arg, uint64_t outbound_capacity_msat_arg, uint64_t inbound_capacity_msat_arg, struct LDKCOption_u32Z confirmations_required_arg, struct LDKCOption_u16Z force_close_spend_delay_arg, bool is_outbound_arg, bool is_funding_locked_arg, bool is_usable_arg, bool is_public_arg); /** * Creates a copy of the ChannelDetails @@ -15307,25 +15884,34 @@ MUST_USE_RES struct LDKUserConfig ChannelManager_get_current_default_configurati /** * Creates a new outbound channel to the given remote node and with the given value. * - * user_id will be provided back as user_channel_id in FundingGenerationReady events to allow - * tracking of which events correspond with which create_channel call. Note that the - * user_channel_id defaults to 0 for inbound channels, so you may wish to avoid using 0 for - * user_id here. user_id has no meaning inside of LDK, it is simply copied to events and - * otherwise ignored. - * - * If successful, will generate a SendOpenChannel message event, so you should probably poll - * PeerManager::process_events afterwards. + * `user_channel_id` will be provided back as in + * [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events + * correspond with which `create_channel` call. Note that the `user_channel_id` defaults to 0 + * for inbound channels, so you may wish to avoid using 0 for `user_channel_id` here. + * `user_channel_id` has no meaning inside of LDK, it is simply copied to events and otherwise + * ignored. * - * Raises APIError::APIMisuseError when channel_value_satoshis > 2**24 or push_msat is - * greater than channel_value_satoshis * 1k or channel_value_satoshis is < 1000. + * Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is + * greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`. * * Note that we do not check if you are currently connected to the given peer. If no * connection is available, the outbound `open_channel` message may fail to send, resulting in - * the channel eventually being silently forgotten. + * the channel eventually being silently forgotten (dropped on reload). + * + * Returns the new Channel's temporary `channel_id`. This ID will appear as + * [`Event::FundingGenerationReady::temporary_channel_id`] and in + * [`ChannelDetails::channel_id`] until after + * [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for + * one derived from the funding transaction's TXID. If the counterparty rejects the channel + * immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`]. + * + * [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id + * [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id + * [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id * * Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None */ -MUST_USE_RES struct LDKCResult_NoneAPIErrorZ ChannelManager_create_channel(const struct LDKChannelManager *NONNULL_PTR this_arg, struct LDKPublicKey their_network_key, uint64_t channel_value_satoshis, uint64_t push_msat, uint64_t user_id, struct LDKUserConfig override_config); +MUST_USE_RES struct LDKCResult__u832APIErrorZ ChannelManager_create_channel(const struct LDKChannelManager *NONNULL_PTR this_arg, struct LDKPublicKey their_network_key, uint64_t channel_value_satoshis, uint64_t push_msat, uint64_t user_channel_id, struct LDKUserConfig override_config); /** * Gets the list of open channels, in random order. See ChannelDetail field documentation for @@ -15442,7 +16028,19 @@ void ChannelManager_force_close_all_channels(const struct LDKChannelManager *NON * * Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None */ -MUST_USE_RES struct LDKCResult_NonePaymentSendFailureZ ChannelManager_send_payment(const struct LDKChannelManager *NONNULL_PTR this_arg, const struct LDKRoute *NONNULL_PTR route, struct LDKThirtyTwoBytes payment_hash, struct LDKThirtyTwoBytes payment_secret); +MUST_USE_RES struct LDKCResult_PaymentIdPaymentSendFailureZ ChannelManager_send_payment(const struct LDKChannelManager *NONNULL_PTR this_arg, const struct LDKRoute *NONNULL_PTR route, struct LDKThirtyTwoBytes payment_hash, struct LDKThirtyTwoBytes payment_secret); + +/** + * Retries a payment along the given [`Route`]. + * + * Errors returned are a superset of those returned from [`send_payment`], so see + * [`send_payment`] documentation for more details on errors. This method will also error if the + * retry amount puts the payment more than 10% over the payment's total amount, or if the payment + * for the given `payment_id` cannot be found (likely due to timeout or success). + * + * [`send_payment`]: [`ChannelManager::send_payment`] + */ +MUST_USE_RES struct LDKCResult_NonePaymentSendFailureZ ChannelManager_retry_payment(const struct LDKChannelManager *NONNULL_PTR this_arg, const struct LDKRoute *NONNULL_PTR route, struct LDKPaymentId payment_id); /** * Send a spontaneous payment, which is a payment that does not require the recipient to have @@ -15462,7 +16060,7 @@ MUST_USE_RES struct LDKCResult_NonePaymentSendFailureZ ChannelManager_send_payme * * Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None */ -MUST_USE_RES struct LDKCResult_PaymentHashPaymentSendFailureZ ChannelManager_send_spontaneous_payment(const struct LDKChannelManager *NONNULL_PTR this_arg, const struct LDKRoute *NONNULL_PTR route, struct LDKThirtyTwoBytes payment_preimage); +MUST_USE_RES struct LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ ChannelManager_send_spontaneous_payment(const struct LDKChannelManager *NONNULL_PTR this_arg, const struct LDKRoute *NONNULL_PTR route, struct LDKThirtyTwoBytes payment_preimage); /** * Call this upon creation of a funding transaction for the given channel. @@ -19492,599 +20090,318 @@ void CustomMessageReader_free(struct LDKCustomMessageReader this_ptr); void Type_free(struct LDKType this_ptr); /** - * Frees any resources used by the RouteHop, if is_owned is set and inner is non-NULL. + * Calls the free function if one is set */ -void RouteHop_free(struct LDKRouteHop this_obj); +void Score_free(struct LDKScore this_ptr); /** - * The node_id of the node at this hop. + * Frees any resources used by the NodeId, if is_owned is set and inner is non-NULL. */ -struct LDKPublicKey RouteHop_get_pubkey(const struct LDKRouteHop *NONNULL_PTR this_ptr); +void NodeId_free(struct LDKNodeId this_obj); /** - * The node_id of the node at this hop. + * Creates a copy of the NodeId */ -void RouteHop_set_pubkey(struct LDKRouteHop *NONNULL_PTR this_ptr, struct LDKPublicKey val); +struct LDKNodeId NodeId_clone(const struct LDKNodeId *NONNULL_PTR orig); /** - * The node_announcement features of the node at this hop. For the last hop, these may be - * amended to match the features present in the invoice this node generated. + * Create a new NodeId from a public key */ -struct LDKNodeFeatures RouteHop_get_node_features(const struct LDKRouteHop *NONNULL_PTR this_ptr); +MUST_USE_RES struct LDKNodeId NodeId_from_pubkey(struct LDKPublicKey pubkey); /** - * The node_announcement features of the node at this hop. For the last hop, these may be - * amended to match the features present in the invoice this node generated. + * Get the public key slice from this NodeId */ -void RouteHop_set_node_features(struct LDKRouteHop *NONNULL_PTR this_ptr, struct LDKNodeFeatures val); +MUST_USE_RES struct LDKu8slice NodeId_as_slice(const struct LDKNodeId *NONNULL_PTR this_arg); /** - * The channel that should be used from the previous hop to reach this node. + * Checks if two NodeIds contain equal inner contents. */ -uint64_t RouteHop_get_short_channel_id(const struct LDKRouteHop *NONNULL_PTR this_ptr); +uint64_t NodeId_hash(const struct LDKNodeId *NONNULL_PTR o); /** - * The channel that should be used from the previous hop to reach this node. + * Serialize the NodeId object into a byte array which can be read by NodeId_read */ -void RouteHop_set_short_channel_id(struct LDKRouteHop *NONNULL_PTR this_ptr, uint64_t val); +struct LDKCVec_u8Z NodeId_write(const struct LDKNodeId *NONNULL_PTR obj); /** - * The channel_announcement features of the channel that should be used from the previous hop - * to reach this node. + * Read a NodeId from a byte array, created by NodeId_write */ -struct LDKChannelFeatures RouteHop_get_channel_features(const struct LDKRouteHop *NONNULL_PTR this_ptr); +struct LDKCResult_NodeIdDecodeErrorZ NodeId_read(struct LDKu8slice ser); /** - * The channel_announcement features of the channel that should be used from the previous hop - * to reach this node. + * Frees any resources used by the NetworkGraph, if is_owned is set and inner is non-NULL. */ -void RouteHop_set_channel_features(struct LDKRouteHop *NONNULL_PTR this_ptr, struct LDKChannelFeatures val); +void NetworkGraph_free(struct LDKNetworkGraph this_obj); /** - * The fee taken on this hop (for paying for the use of the *next* channel in the path). - * For the last hop, this should be the full value of the payment (might be more than - * requested if we had to match htlc_minimum_msat). + * Creates a copy of the NetworkGraph */ -uint64_t RouteHop_get_fee_msat(const struct LDKRouteHop *NONNULL_PTR this_ptr); +struct LDKNetworkGraph NetworkGraph_clone(const struct LDKNetworkGraph *NONNULL_PTR orig); /** - * The fee taken on this hop (for paying for the use of the *next* channel in the path). - * For the last hop, this should be the full value of the payment (might be more than - * requested if we had to match htlc_minimum_msat). + * Frees any resources used by the ReadOnlyNetworkGraph, if is_owned is set and inner is non-NULL. */ -void RouteHop_set_fee_msat(struct LDKRouteHop *NONNULL_PTR this_ptr, uint64_t val); +void ReadOnlyNetworkGraph_free(struct LDKReadOnlyNetworkGraph this_obj); /** - * The CLTV delta added for this hop. For the last hop, this should be the full CLTV value - * expected at the destination, in excess of the current block height. + * Frees any resources used by the NetworkUpdate */ -uint32_t RouteHop_get_cltv_expiry_delta(const struct LDKRouteHop *NONNULL_PTR this_ptr); +void NetworkUpdate_free(struct LDKNetworkUpdate this_ptr); /** - * The CLTV delta added for this hop. For the last hop, this should be the full CLTV value - * expected at the destination, in excess of the current block height. + * Creates a copy of the NetworkUpdate */ -void RouteHop_set_cltv_expiry_delta(struct LDKRouteHop *NONNULL_PTR this_ptr, uint32_t val); +struct LDKNetworkUpdate NetworkUpdate_clone(const struct LDKNetworkUpdate *NONNULL_PTR orig); /** - * Constructs a new RouteHop given each field + * Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate */ -MUST_USE_RES struct LDKRouteHop RouteHop_new(struct LDKPublicKey pubkey_arg, struct LDKNodeFeatures node_features_arg, uint64_t short_channel_id_arg, struct LDKChannelFeatures channel_features_arg, uint64_t fee_msat_arg, uint32_t cltv_expiry_delta_arg); +struct LDKNetworkUpdate NetworkUpdate_channel_update_message(struct LDKChannelUpdate msg); /** - * Creates a copy of the RouteHop + * Utility method to constructs a new ChannelClosed-variant NetworkUpdate */ -struct LDKRouteHop RouteHop_clone(const struct LDKRouteHop *NONNULL_PTR orig); +struct LDKNetworkUpdate NetworkUpdate_channel_closed(uint64_t short_channel_id, bool is_permanent); /** - * Checks if two RouteHops contain equal inner contents. + * Utility method to constructs a new NodeFailure-variant NetworkUpdate */ -uint64_t RouteHop_hash(const struct LDKRouteHop *NONNULL_PTR o); +struct LDKNetworkUpdate NetworkUpdate_node_failure(struct LDKPublicKey node_id, bool is_permanent); /** - * Checks if two RouteHops 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. + * Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read */ -bool RouteHop_eq(const struct LDKRouteHop *NONNULL_PTR a, const struct LDKRouteHop *NONNULL_PTR b); +struct LDKCVec_u8Z NetworkUpdate_write(const struct LDKNetworkUpdate *NONNULL_PTR obj); /** - * Serialize the RouteHop object into a byte array which can be read by RouteHop_read + * Constructs a new EventHandler which calls the relevant methods on this_arg. + * This copies the `inner` pointer in this_arg and thus the returned EventHandler must be freed before this_arg is */ -struct LDKCVec_u8Z RouteHop_write(const struct LDKRouteHop *NONNULL_PTR obj); +struct LDKEventHandler NetGraphMsgHandler_as_EventHandler(const struct LDKNetGraphMsgHandler *NONNULL_PTR this_arg); /** - * Read a RouteHop from a byte array, created by RouteHop_write + * Frees any resources used by the NetGraphMsgHandler, if is_owned is set and inner is non-NULL. */ -struct LDKCResult_RouteHopDecodeErrorZ RouteHop_read(struct LDKu8slice ser); +void NetGraphMsgHandler_free(struct LDKNetGraphMsgHandler this_obj); /** - * Frees any resources used by the Route, if is_owned is set and inner is non-NULL. + * Representation of the payment channel network */ -void Route_free(struct LDKRoute this_obj); +struct LDKNetworkGraph NetGraphMsgHandler_get_network_graph(const struct LDKNetGraphMsgHandler *NONNULL_PTR this_ptr); /** - * The list of routes taken for a single (potentially-)multi-part payment. The pubkey of the - * last RouteHop in each path must be the same. - * Each entry represents a list of hops, NOT INCLUDING our own, where the last hop is the - * destination. Thus, this must always be at least length one. While the maximum length of any - * given path is variable, keeping the length of any path to less than 20 should currently - * ensure it is viable. + * Representation of the payment channel network */ -struct LDKCVec_CVec_RouteHopZZ Route_get_paths(const struct LDKRoute *NONNULL_PTR this_ptr); +void NetGraphMsgHandler_set_network_graph(struct LDKNetGraphMsgHandler *NONNULL_PTR this_ptr, struct LDKNetworkGraph val); /** - * The list of routes taken for a single (potentially-)multi-part payment. The pubkey of the - * last RouteHop in each path must be the same. - * Each entry represents a list of hops, NOT INCLUDING our own, where the last hop is the - * destination. Thus, this must always be at least length one. While the maximum length of any - * given path is variable, keeping the length of any path to less than 20 should currently - * ensure it is viable. + * Creates a new tracker of the actual state of the network of channels and nodes, + * assuming an existing Network Graph. + * Chain monitor is used to make sure announced channels exist on-chain, + * channel data is correct, and that the announcement is signed with + * channel owners' keys. */ -void Route_set_paths(struct LDKRoute *NONNULL_PTR this_ptr, struct LDKCVec_CVec_RouteHopZZ val); +MUST_USE_RES struct LDKNetGraphMsgHandler NetGraphMsgHandler_new(struct LDKNetworkGraph network_graph, struct LDKCOption_AccessZ chain_access, struct LDKLogger logger); /** - * Constructs a new Route given each field + * Adds a provider used to check new announcements. Does not affect + * existing announcements unless they are updated. + * Add, update or remove the provider would replace the current one. */ -MUST_USE_RES struct LDKRoute Route_new(struct LDKCVec_CVec_RouteHopZZ paths_arg); +void NetGraphMsgHandler_add_chain_access(struct LDKNetGraphMsgHandler *NONNULL_PTR this_arg, struct LDKCOption_AccessZ chain_access); /** - * Creates a copy of the Route + * Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg. + * This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is */ -struct LDKRoute Route_clone(const struct LDKRoute *NONNULL_PTR orig); +struct LDKRoutingMessageHandler NetGraphMsgHandler_as_RoutingMessageHandler(const struct LDKNetGraphMsgHandler *NONNULL_PTR this_arg); /** - * Checks if two Routes contain equal inner contents. + * Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg. + * This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is */ -uint64_t Route_hash(const struct LDKRoute *NONNULL_PTR o); +struct LDKMessageSendEventsProvider NetGraphMsgHandler_as_MessageSendEventsProvider(const struct LDKNetGraphMsgHandler *NONNULL_PTR this_arg); /** - * Checks if two Routes 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. + * Frees any resources used by the DirectionalChannelInfo, if is_owned is set and inner is non-NULL. */ -bool Route_eq(const struct LDKRoute *NONNULL_PTR a, const struct LDKRoute *NONNULL_PTR b); +void DirectionalChannelInfo_free(struct LDKDirectionalChannelInfo this_obj); /** - * Returns the total amount of fees paid on this [`Route`]. - * - * This doesn't include any extra payment made to the recipient, which can happen in excess of - * the amount passed to [`get_route`]'s `final_value_msat`. + * When the last update to the channel direction was issued. + * Value is opaque, as set in the announcement. */ -MUST_USE_RES uint64_t Route_get_total_fees(const struct LDKRoute *NONNULL_PTR this_arg); +uint32_t DirectionalChannelInfo_get_last_update(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr); /** - * Returns the total amount paid on this [`Route`], excluding the fees. + * When the last update to the channel direction was issued. + * Value is opaque, as set in the announcement. */ -MUST_USE_RES uint64_t Route_get_total_amount(const struct LDKRoute *NONNULL_PTR this_arg); +void DirectionalChannelInfo_set_last_update(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, uint32_t val); /** - * Serialize the Route object into a byte array which can be read by Route_read + * Whether the channel can be currently used for payments (in this one direction). */ -struct LDKCVec_u8Z Route_write(const struct LDKRoute *NONNULL_PTR obj); +bool DirectionalChannelInfo_get_enabled(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr); /** - * Read a Route from a byte array, created by Route_write + * Whether the channel can be currently used for payments (in this one direction). */ -struct LDKCResult_RouteDecodeErrorZ Route_read(struct LDKu8slice ser); +void DirectionalChannelInfo_set_enabled(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, bool val); /** - * Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL. + * The difference in CLTV values that you must have when routing through this channel. */ -void RouteHint_free(struct LDKRouteHint this_obj); +uint16_t DirectionalChannelInfo_get_cltv_expiry_delta(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr); /** - * Creates a copy of the RouteHint + * The difference in CLTV values that you must have when routing through this channel. */ -struct LDKRouteHint RouteHint_clone(const struct LDKRouteHint *NONNULL_PTR orig); +void DirectionalChannelInfo_set_cltv_expiry_delta(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, uint16_t val); /** - * Checks if two RouteHints contain equal inner contents. + * The minimum value, which must be relayed to the next hop via the channel */ -uint64_t RouteHint_hash(const struct LDKRouteHint *NONNULL_PTR o); +uint64_t DirectionalChannelInfo_get_htlc_minimum_msat(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr); /** - * Checks if two RouteHints 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. + * The minimum value, which must be relayed to the next hop via the channel */ -bool RouteHint_eq(const struct LDKRouteHint *NONNULL_PTR a, const struct LDKRouteHint *NONNULL_PTR b); +void DirectionalChannelInfo_set_htlc_minimum_msat(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, uint64_t val); /** - * Frees any resources used by the RouteHintHop, if is_owned is set and inner is non-NULL. + * The maximum value which may be relayed to the next hop via the channel. */ -void RouteHintHop_free(struct LDKRouteHintHop this_obj); +struct LDKCOption_u64Z DirectionalChannelInfo_get_htlc_maximum_msat(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr); /** - * The node_id of the non-target end of the route + * The maximum value which may be relayed to the next hop via the channel. */ -struct LDKPublicKey RouteHintHop_get_src_node_id(const struct LDKRouteHintHop *NONNULL_PTR this_ptr); +void DirectionalChannelInfo_set_htlc_maximum_msat(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, struct LDKCOption_u64Z val); /** - * The node_id of the non-target end of the route + * Fees charged when the channel is used for routing */ -void RouteHintHop_set_src_node_id(struct LDKRouteHintHop *NONNULL_PTR this_ptr, struct LDKPublicKey val); +struct LDKRoutingFees DirectionalChannelInfo_get_fees(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr); /** - * The short_channel_id of this channel + * Fees charged when the channel is used for routing */ -uint64_t RouteHintHop_get_short_channel_id(const struct LDKRouteHintHop *NONNULL_PTR this_ptr); +void DirectionalChannelInfo_set_fees(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, struct LDKRoutingFees val); /** - * The short_channel_id of this channel + * Most recent update for the channel received from the network + * Mostly redundant with the data we store in fields explicitly. + * Everything else is useful only for sending out for initial routing sync. + * Not stored if contains excess data to prevent DoS. + * + * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None */ -void RouteHintHop_set_short_channel_id(struct LDKRouteHintHop *NONNULL_PTR this_ptr, uint64_t val); +struct LDKChannelUpdate DirectionalChannelInfo_get_last_update_message(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr); /** - * The fees which must be paid to use this channel + * Most recent update for the channel received from the network + * Mostly redundant with the data we store in fields explicitly. + * Everything else is useful only for sending out for initial routing sync. + * Not stored if contains excess data to prevent DoS. + * + * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None */ -struct LDKRoutingFees RouteHintHop_get_fees(const struct LDKRouteHintHop *NONNULL_PTR this_ptr); +void DirectionalChannelInfo_set_last_update_message(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, struct LDKChannelUpdate val); /** - * The fees which must be paid to use this channel + * Constructs a new DirectionalChannelInfo given each field */ -void RouteHintHop_set_fees(struct LDKRouteHintHop *NONNULL_PTR this_ptr, struct LDKRoutingFees val); +MUST_USE_RES struct LDKDirectionalChannelInfo DirectionalChannelInfo_new(uint32_t last_update_arg, bool enabled_arg, uint16_t cltv_expiry_delta_arg, uint64_t htlc_minimum_msat_arg, struct LDKCOption_u64Z htlc_maximum_msat_arg, struct LDKRoutingFees fees_arg, struct LDKChannelUpdate last_update_message_arg); /** - * The difference in CLTV values between this node and the next node. + * Creates a copy of the DirectionalChannelInfo */ -uint16_t RouteHintHop_get_cltv_expiry_delta(const struct LDKRouteHintHop *NONNULL_PTR this_ptr); +struct LDKDirectionalChannelInfo DirectionalChannelInfo_clone(const struct LDKDirectionalChannelInfo *NONNULL_PTR orig); /** - * The difference in CLTV values between this node and the next node. + * Serialize the DirectionalChannelInfo object into a byte array which can be read by DirectionalChannelInfo_read */ -void RouteHintHop_set_cltv_expiry_delta(struct LDKRouteHintHop *NONNULL_PTR this_ptr, uint16_t val); +struct LDKCVec_u8Z DirectionalChannelInfo_write(const struct LDKDirectionalChannelInfo *NONNULL_PTR obj); /** - * The minimum value, in msat, which must be relayed to the next hop. + * Read a DirectionalChannelInfo from a byte array, created by DirectionalChannelInfo_write */ -struct LDKCOption_u64Z RouteHintHop_get_htlc_minimum_msat(const struct LDKRouteHintHop *NONNULL_PTR this_ptr); +struct LDKCResult_DirectionalChannelInfoDecodeErrorZ DirectionalChannelInfo_read(struct LDKu8slice ser); /** - * The minimum value, in msat, which must be relayed to the next hop. + * Frees any resources used by the ChannelInfo, if is_owned is set and inner is non-NULL. */ -void RouteHintHop_set_htlc_minimum_msat(struct LDKRouteHintHop *NONNULL_PTR this_ptr, struct LDKCOption_u64Z val); +void ChannelInfo_free(struct LDKChannelInfo this_obj); /** - * The maximum value in msat available for routing with a single HTLC. + * Protocol features of a channel communicated during its announcement */ -struct LDKCOption_u64Z RouteHintHop_get_htlc_maximum_msat(const struct LDKRouteHintHop *NONNULL_PTR this_ptr); +struct LDKChannelFeatures ChannelInfo_get_features(const struct LDKChannelInfo *NONNULL_PTR this_ptr); /** - * The maximum value in msat available for routing with a single HTLC. + * Protocol features of a channel communicated during its announcement */ -void RouteHintHop_set_htlc_maximum_msat(struct LDKRouteHintHop *NONNULL_PTR this_ptr, struct LDKCOption_u64Z val); +void ChannelInfo_set_features(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKChannelFeatures val); /** - * Constructs a new RouteHintHop given each field + * Source node of the first direction of a channel */ -MUST_USE_RES struct LDKRouteHintHop RouteHintHop_new(struct LDKPublicKey src_node_id_arg, uint64_t short_channel_id_arg, struct LDKRoutingFees fees_arg, uint16_t cltv_expiry_delta_arg, struct LDKCOption_u64Z htlc_minimum_msat_arg, struct LDKCOption_u64Z htlc_maximum_msat_arg); +struct LDKNodeId ChannelInfo_get_node_one(const struct LDKChannelInfo *NONNULL_PTR this_ptr); /** - * Creates a copy of the RouteHintHop + * Source node of the first direction of a channel */ -struct LDKRouteHintHop RouteHintHop_clone(const struct LDKRouteHintHop *NONNULL_PTR orig); +void ChannelInfo_set_node_one(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKNodeId val); /** - * Checks if two RouteHintHops contain equal inner contents. + * Details about the first direction of a channel + * + * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None */ -uint64_t RouteHintHop_hash(const struct LDKRouteHintHop *NONNULL_PTR o); +struct LDKDirectionalChannelInfo ChannelInfo_get_one_to_two(const struct LDKChannelInfo *NONNULL_PTR this_ptr); /** - * Checks if two RouteHintHops 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. + * Details about the first direction of a channel + * + * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None */ -bool RouteHintHop_eq(const struct LDKRouteHintHop *NONNULL_PTR a, const struct LDKRouteHintHop *NONNULL_PTR b); +void ChannelInfo_set_one_to_two(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKDirectionalChannelInfo val); /** - * Gets a keysend route from us (payer) to the given target node (payee). This is needed because - * keysend payments do not have an invoice from which to pull the payee's supported features, which - * makes it tricky to otherwise supply the `payee_features` parameter of `get_route`. - * - * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None + * Source node of the second direction of a channel */ -struct LDKCResult_RouteLightningErrorZ get_keysend_route(struct LDKPublicKey our_node_id, const struct LDKNetworkGraph *NONNULL_PTR network, struct LDKPublicKey payee, struct LDKCVec_ChannelDetailsZ *first_hops, struct LDKCVec_RouteHintZ last_hops, uint64_t final_value_msat, uint32_t final_cltv, struct LDKLogger logger); +struct LDKNodeId ChannelInfo_get_node_two(const struct LDKChannelInfo *NONNULL_PTR this_ptr); /** - * Gets a route from us (payer) to the given target node (payee). - * - * If the payee provided features in their invoice, they should be provided via payee_features. - * Without this, MPP will only be used if the payee's features are available in the network graph. - * - * Private routing paths between a public node and the target may be included in `last_hops`. - * Currently, only the last hop in each path is considered. - * - * If some channels aren't announced, it may be useful to fill in a first_hops with the - * results from a local ChannelManager::list_usable_channels() call. If it is filled in, our - * view of our local channels (from net_graph_msg_handler) will be ignored, and only those - * in first_hops will be used. - * - * Panics if first_hops contains channels without short_channel_ids - * (ChannelManager::list_usable_channels will never include such channels). - * - * The fees on channels from us to next-hops are ignored (as they are assumed to all be - * equal), however the enabled/disabled bit on such channels as well as the - * htlc_minimum_msat/htlc_maximum_msat *are* checked as they may change based on the receiving node. - * - * Note that payee_features (or a relevant inner pointer) may be NULL or all-0s to represent None - * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None + * Source node of the second direction of a channel */ -struct LDKCResult_RouteLightningErrorZ get_route(struct LDKPublicKey our_node_id, const struct LDKNetworkGraph *NONNULL_PTR network, struct LDKPublicKey payee, struct LDKInvoiceFeatures payee_features, struct LDKCVec_ChannelDetailsZ *first_hops, struct LDKCVec_RouteHintZ last_hops, uint64_t final_value_msat, uint32_t final_cltv, struct LDKLogger logger); +void ChannelInfo_set_node_two(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKNodeId val); /** - * Frees any resources used by the NetworkGraph, if is_owned is set and inner is non-NULL. + * Details about the second direction of a channel + * + * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None */ -void NetworkGraph_free(struct LDKNetworkGraph this_obj); +struct LDKDirectionalChannelInfo ChannelInfo_get_two_to_one(const struct LDKChannelInfo *NONNULL_PTR this_ptr); /** - * Creates a copy of the NetworkGraph + * Details about the second direction of a channel + * + * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None */ -struct LDKNetworkGraph NetworkGraph_clone(const struct LDKNetworkGraph *NONNULL_PTR orig); +void ChannelInfo_set_two_to_one(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKDirectionalChannelInfo val); /** - * Frees any resources used by the ReadOnlyNetworkGraph, if is_owned is set and inner is non-NULL. + * The channel capacity as seen on-chain, if chain lookup is available. */ -void ReadOnlyNetworkGraph_free(struct LDKReadOnlyNetworkGraph this_obj); +struct LDKCOption_u64Z ChannelInfo_get_capacity_sats(const struct LDKChannelInfo *NONNULL_PTR this_ptr); /** - * Frees any resources used by the NetworkUpdate + * The channel capacity as seen on-chain, if chain lookup is available. */ -void NetworkUpdate_free(struct LDKNetworkUpdate this_ptr); - -/** - * Creates a copy of the NetworkUpdate - */ -struct LDKNetworkUpdate NetworkUpdate_clone(const struct LDKNetworkUpdate *NONNULL_PTR orig); - -/** - * Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate - */ -struct LDKNetworkUpdate NetworkUpdate_channel_update_message(struct LDKChannelUpdate msg); - -/** - * Utility method to constructs a new ChannelClosed-variant NetworkUpdate - */ -struct LDKNetworkUpdate NetworkUpdate_channel_closed(uint64_t short_channel_id, bool is_permanent); - -/** - * Utility method to constructs a new NodeFailure-variant NetworkUpdate - */ -struct LDKNetworkUpdate NetworkUpdate_node_failure(struct LDKPublicKey node_id, bool is_permanent); - -/** - * Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read - */ -struct LDKCVec_u8Z NetworkUpdate_write(const struct LDKNetworkUpdate *NONNULL_PTR obj); - -/** - * Constructs a new EventHandler which calls the relevant methods on this_arg. - * This copies the `inner` pointer in this_arg and thus the returned EventHandler must be freed before this_arg is - */ -struct LDKEventHandler NetGraphMsgHandler_as_EventHandler(const struct LDKNetGraphMsgHandler *NONNULL_PTR this_arg); - -/** - * Frees any resources used by the NetGraphMsgHandler, if is_owned is set and inner is non-NULL. - */ -void NetGraphMsgHandler_free(struct LDKNetGraphMsgHandler this_obj); - -/** - * Representation of the payment channel network - */ -struct LDKNetworkGraph NetGraphMsgHandler_get_network_graph(const struct LDKNetGraphMsgHandler *NONNULL_PTR this_ptr); - -/** - * Representation of the payment channel network - */ -void NetGraphMsgHandler_set_network_graph(struct LDKNetGraphMsgHandler *NONNULL_PTR this_ptr, struct LDKNetworkGraph val); - -/** - * Creates a new tracker of the actual state of the network of channels and nodes, - * assuming an existing Network Graph. - * Chain monitor is used to make sure announced channels exist on-chain, - * channel data is correct, and that the announcement is signed with - * channel owners' keys. - */ -MUST_USE_RES struct LDKNetGraphMsgHandler NetGraphMsgHandler_new(struct LDKNetworkGraph network_graph, struct LDKCOption_AccessZ chain_access, struct LDKLogger logger); - -/** - * Adds a provider used to check new announcements. Does not affect - * existing announcements unless they are updated. - * Add, update or remove the provider would replace the current one. - */ -void NetGraphMsgHandler_add_chain_access(struct LDKNetGraphMsgHandler *NONNULL_PTR this_arg, struct LDKCOption_AccessZ chain_access); - -/** - * Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg. - * This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is - */ -struct LDKRoutingMessageHandler NetGraphMsgHandler_as_RoutingMessageHandler(const struct LDKNetGraphMsgHandler *NONNULL_PTR this_arg); - -/** - * Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg. - * This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is - */ -struct LDKMessageSendEventsProvider NetGraphMsgHandler_as_MessageSendEventsProvider(const struct LDKNetGraphMsgHandler *NONNULL_PTR this_arg); - -/** - * Frees any resources used by the DirectionalChannelInfo, if is_owned is set and inner is non-NULL. - */ -void DirectionalChannelInfo_free(struct LDKDirectionalChannelInfo this_obj); - -/** - * When the last update to the channel direction was issued. - * Value is opaque, as set in the announcement. - */ -uint32_t DirectionalChannelInfo_get_last_update(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr); - -/** - * When the last update to the channel direction was issued. - * Value is opaque, as set in the announcement. - */ -void DirectionalChannelInfo_set_last_update(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, uint32_t val); - -/** - * Whether the channel can be currently used for payments (in this one direction). - */ -bool DirectionalChannelInfo_get_enabled(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr); - -/** - * Whether the channel can be currently used for payments (in this one direction). - */ -void DirectionalChannelInfo_set_enabled(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, bool val); - -/** - * The difference in CLTV values that you must have when routing through this channel. - */ -uint16_t DirectionalChannelInfo_get_cltv_expiry_delta(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr); - -/** - * The difference in CLTV values that you must have when routing through this channel. - */ -void DirectionalChannelInfo_set_cltv_expiry_delta(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, uint16_t val); - -/** - * The minimum value, which must be relayed to the next hop via the channel - */ -uint64_t DirectionalChannelInfo_get_htlc_minimum_msat(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr); - -/** - * The minimum value, which must be relayed to the next hop via the channel - */ -void DirectionalChannelInfo_set_htlc_minimum_msat(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The maximum value which may be relayed to the next hop via the channel. - */ -struct LDKCOption_u64Z DirectionalChannelInfo_get_htlc_maximum_msat(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr); - -/** - * The maximum value which may be relayed to the next hop via the channel. - */ -void DirectionalChannelInfo_set_htlc_maximum_msat(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, struct LDKCOption_u64Z val); - -/** - * Fees charged when the channel is used for routing - */ -struct LDKRoutingFees DirectionalChannelInfo_get_fees(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr); - -/** - * Fees charged when the channel is used for routing - */ -void DirectionalChannelInfo_set_fees(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, struct LDKRoutingFees val); - -/** - * Most recent update for the channel received from the network - * Mostly redundant with the data we store in fields explicitly. - * Everything else is useful only for sending out for initial routing sync. - * Not stored if contains excess data to prevent DoS. - * - * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None - */ -struct LDKChannelUpdate DirectionalChannelInfo_get_last_update_message(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr); - -/** - * Most recent update for the channel received from the network - * Mostly redundant with the data we store in fields explicitly. - * Everything else is useful only for sending out for initial routing sync. - * Not stored if contains excess data to prevent DoS. - * - * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None - */ -void DirectionalChannelInfo_set_last_update_message(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, struct LDKChannelUpdate val); - -/** - * Constructs a new DirectionalChannelInfo given each field - */ -MUST_USE_RES struct LDKDirectionalChannelInfo DirectionalChannelInfo_new(uint32_t last_update_arg, bool enabled_arg, uint16_t cltv_expiry_delta_arg, uint64_t htlc_minimum_msat_arg, struct LDKCOption_u64Z htlc_maximum_msat_arg, struct LDKRoutingFees fees_arg, struct LDKChannelUpdate last_update_message_arg); - -/** - * Creates a copy of the DirectionalChannelInfo - */ -struct LDKDirectionalChannelInfo DirectionalChannelInfo_clone(const struct LDKDirectionalChannelInfo *NONNULL_PTR orig); - -/** - * Serialize the DirectionalChannelInfo object into a byte array which can be read by DirectionalChannelInfo_read - */ -struct LDKCVec_u8Z DirectionalChannelInfo_write(const struct LDKDirectionalChannelInfo *NONNULL_PTR obj); - -/** - * Read a DirectionalChannelInfo from a byte array, created by DirectionalChannelInfo_write - */ -struct LDKCResult_DirectionalChannelInfoDecodeErrorZ DirectionalChannelInfo_read(struct LDKu8slice ser); - -/** - * Frees any resources used by the ChannelInfo, if is_owned is set and inner is non-NULL. - */ -void ChannelInfo_free(struct LDKChannelInfo this_obj); - -/** - * Protocol features of a channel communicated during its announcement - */ -struct LDKChannelFeatures ChannelInfo_get_features(const struct LDKChannelInfo *NONNULL_PTR this_ptr); - -/** - * Protocol features of a channel communicated during its announcement - */ -void ChannelInfo_set_features(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKChannelFeatures val); - -/** - * Source node of the first direction of a channel - */ -struct LDKPublicKey ChannelInfo_get_node_one(const struct LDKChannelInfo *NONNULL_PTR this_ptr); - -/** - * Source node of the first direction of a channel - */ -void ChannelInfo_set_node_one(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * Details about the first direction of a channel - * - * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None - */ -struct LDKDirectionalChannelInfo ChannelInfo_get_one_to_two(const struct LDKChannelInfo *NONNULL_PTR this_ptr); - -/** - * Details about the first direction of a channel - * - * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None - */ -void ChannelInfo_set_one_to_two(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKDirectionalChannelInfo val); - -/** - * Source node of the second direction of a channel - */ -struct LDKPublicKey ChannelInfo_get_node_two(const struct LDKChannelInfo *NONNULL_PTR this_ptr); - -/** - * Source node of the second direction of a channel - */ -void ChannelInfo_set_node_two(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * Details about the second direction of a channel - * - * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None - */ -struct LDKDirectionalChannelInfo ChannelInfo_get_two_to_one(const struct LDKChannelInfo *NONNULL_PTR this_ptr); - -/** - * Details about the second direction of a channel - * - * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None - */ -void ChannelInfo_set_two_to_one(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKDirectionalChannelInfo val); - -/** - * The channel capacity as seen on-chain, if chain lookup is available. - */ -struct LDKCOption_u64Z ChannelInfo_get_capacity_sats(const struct LDKChannelInfo *NONNULL_PTR this_ptr); - -/** - * The channel capacity as seen on-chain, if chain lookup is available. - */ -void ChannelInfo_set_capacity_sats(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKCOption_u64Z val); +void ChannelInfo_set_capacity_sats(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKCOption_u64Z val); /** * An initial announcement of the channel @@ -20109,7 +20426,7 @@ void ChannelInfo_set_announcement_message(struct LDKChannelInfo *NONNULL_PTR thi /** * Constructs a new ChannelInfo given each field */ -MUST_USE_RES struct LDKChannelInfo ChannelInfo_new(struct LDKChannelFeatures features_arg, struct LDKPublicKey node_one_arg, struct LDKDirectionalChannelInfo one_to_two_arg, struct LDKPublicKey node_two_arg, struct LDKDirectionalChannelInfo two_to_one_arg, struct LDKCOption_u64Z capacity_sats_arg, struct LDKChannelAnnouncement announcement_message_arg); +MUST_USE_RES struct LDKChannelInfo ChannelInfo_new(struct LDKChannelFeatures features_arg, struct LDKNodeId node_one_arg, struct LDKDirectionalChannelInfo one_to_two_arg, struct LDKNodeId node_two_arg, struct LDKDirectionalChannelInfo two_to_one_arg, struct LDKCOption_u64Z capacity_sats_arg, struct LDKChannelAnnouncement announcement_message_arg); /** * Creates a copy of the ChannelInfo @@ -20437,6 +20754,355 @@ 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); +/** + * Get network addresses by node id. + * Returns None if the requested node is completely unknown, + * or if node announcement for the node was never received. + */ +MUST_USE_RES struct LDKCOption_CVec_NetAddressZZ ReadOnlyNetworkGraph_get_addresses(const struct LDKReadOnlyNetworkGraph *NONNULL_PTR this_arg, struct LDKPublicKey pubkey); + +/** + * Frees any resources used by the RouteHop, if is_owned is set and inner is non-NULL. + */ +void RouteHop_free(struct LDKRouteHop this_obj); + +/** + * The node_id of the node at this hop. + */ +struct LDKPublicKey RouteHop_get_pubkey(const struct LDKRouteHop *NONNULL_PTR this_ptr); + +/** + * The node_id of the node at this hop. + */ +void RouteHop_set_pubkey(struct LDKRouteHop *NONNULL_PTR this_ptr, struct LDKPublicKey val); + +/** + * The node_announcement features of the node at this hop. For the last hop, these may be + * amended to match the features present in the invoice this node generated. + */ +struct LDKNodeFeatures RouteHop_get_node_features(const struct LDKRouteHop *NONNULL_PTR this_ptr); + +/** + * The node_announcement features of the node at this hop. For the last hop, these may be + * amended to match the features present in the invoice this node generated. + */ +void RouteHop_set_node_features(struct LDKRouteHop *NONNULL_PTR this_ptr, struct LDKNodeFeatures val); + +/** + * The channel that should be used from the previous hop to reach this node. + */ +uint64_t RouteHop_get_short_channel_id(const struct LDKRouteHop *NONNULL_PTR this_ptr); + +/** + * The channel that should be used from the previous hop to reach this node. + */ +void RouteHop_set_short_channel_id(struct LDKRouteHop *NONNULL_PTR this_ptr, uint64_t val); + +/** + * The channel_announcement features of the channel that should be used from the previous hop + * to reach this node. + */ +struct LDKChannelFeatures RouteHop_get_channel_features(const struct LDKRouteHop *NONNULL_PTR this_ptr); + +/** + * The channel_announcement features of the channel that should be used from the previous hop + * to reach this node. + */ +void RouteHop_set_channel_features(struct LDKRouteHop *NONNULL_PTR this_ptr, struct LDKChannelFeatures val); + +/** + * The fee taken on this hop (for paying for the use of the *next* channel in the path). + * For the last hop, this should be the full value of the payment (might be more than + * requested if we had to match htlc_minimum_msat). + */ +uint64_t RouteHop_get_fee_msat(const struct LDKRouteHop *NONNULL_PTR this_ptr); + +/** + * The fee taken on this hop (for paying for the use of the *next* channel in the path). + * For the last hop, this should be the full value of the payment (might be more than + * requested if we had to match htlc_minimum_msat). + */ +void RouteHop_set_fee_msat(struct LDKRouteHop *NONNULL_PTR this_ptr, uint64_t val); + +/** + * The CLTV delta added for this hop. For the last hop, this should be the full CLTV value + * expected at the destination, in excess of the current block height. + */ +uint32_t RouteHop_get_cltv_expiry_delta(const struct LDKRouteHop *NONNULL_PTR this_ptr); + +/** + * The CLTV delta added for this hop. For the last hop, this should be the full CLTV value + * expected at the destination, in excess of the current block height. + */ +void RouteHop_set_cltv_expiry_delta(struct LDKRouteHop *NONNULL_PTR this_ptr, uint32_t val); + +/** + * Constructs a new RouteHop given each field + */ +MUST_USE_RES struct LDKRouteHop RouteHop_new(struct LDKPublicKey pubkey_arg, struct LDKNodeFeatures node_features_arg, uint64_t short_channel_id_arg, struct LDKChannelFeatures channel_features_arg, uint64_t fee_msat_arg, uint32_t cltv_expiry_delta_arg); + +/** + * Creates a copy of the RouteHop + */ +struct LDKRouteHop RouteHop_clone(const struct LDKRouteHop *NONNULL_PTR orig); + +/** + * Checks if two RouteHops contain equal inner contents. + */ +uint64_t RouteHop_hash(const struct LDKRouteHop *NONNULL_PTR o); + +/** + * Checks if two RouteHops 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 RouteHop_eq(const struct LDKRouteHop *NONNULL_PTR a, const struct LDKRouteHop *NONNULL_PTR b); + +/** + * Serialize the RouteHop object into a byte array which can be read by RouteHop_read + */ +struct LDKCVec_u8Z RouteHop_write(const struct LDKRouteHop *NONNULL_PTR obj); + +/** + * Read a RouteHop from a byte array, created by RouteHop_write + */ +struct LDKCResult_RouteHopDecodeErrorZ RouteHop_read(struct LDKu8slice ser); + +/** + * Frees any resources used by the Route, if is_owned is set and inner is non-NULL. + */ +void Route_free(struct LDKRoute this_obj); + +/** + * The list of routes taken for a single (potentially-)multi-part payment. The pubkey of the + * last RouteHop in each path must be the same. + * Each entry represents a list of hops, NOT INCLUDING our own, where the last hop is the + * destination. Thus, this must always be at least length one. While the maximum length of any + * given path is variable, keeping the length of any path to less than 20 should currently + * ensure it is viable. + */ +struct LDKCVec_CVec_RouteHopZZ Route_get_paths(const struct LDKRoute *NONNULL_PTR this_ptr); + +/** + * The list of routes taken for a single (potentially-)multi-part payment. The pubkey of the + * last RouteHop in each path must be the same. + * Each entry represents a list of hops, NOT INCLUDING our own, where the last hop is the + * destination. Thus, this must always be at least length one. While the maximum length of any + * given path is variable, keeping the length of any path to less than 20 should currently + * ensure it is viable. + */ +void Route_set_paths(struct LDKRoute *NONNULL_PTR this_ptr, struct LDKCVec_CVec_RouteHopZZ val); + +/** + * Constructs a new Route given each field + */ +MUST_USE_RES struct LDKRoute Route_new(struct LDKCVec_CVec_RouteHopZZ paths_arg); + +/** + * Creates a copy of the Route + */ +struct LDKRoute Route_clone(const struct LDKRoute *NONNULL_PTR orig); + +/** + * Checks if two Routes contain equal inner contents. + */ +uint64_t Route_hash(const struct LDKRoute *NONNULL_PTR o); + +/** + * Checks if two Routes 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 Route_eq(const struct LDKRoute *NONNULL_PTR a, const struct LDKRoute *NONNULL_PTR b); + +/** + * Returns the total amount of fees paid on this [`Route`]. + * + * This doesn't include any extra payment made to the recipient, which can happen in excess of + * the amount passed to [`get_route`]'s `final_value_msat`. + */ +MUST_USE_RES uint64_t Route_get_total_fees(const struct LDKRoute *NONNULL_PTR this_arg); + +/** + * Returns the total amount paid on this [`Route`], excluding the fees. + */ +MUST_USE_RES uint64_t Route_get_total_amount(const struct LDKRoute *NONNULL_PTR this_arg); + +/** + * Serialize the Route object into a byte array which can be read by Route_read + */ +struct LDKCVec_u8Z Route_write(const struct LDKRoute *NONNULL_PTR obj); + +/** + * Read a Route from a byte array, created by Route_write + */ +struct LDKCResult_RouteDecodeErrorZ Route_read(struct LDKu8slice ser); + +/** + * Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL. + */ +void RouteHint_free(struct LDKRouteHint this_obj); + +/** + * Creates a copy of the RouteHint + */ +struct LDKRouteHint RouteHint_clone(const struct LDKRouteHint *NONNULL_PTR orig); + +/** + * Checks if two RouteHints contain equal inner contents. + */ +uint64_t RouteHint_hash(const struct LDKRouteHint *NONNULL_PTR o); + +/** + * Checks if two RouteHints 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 RouteHint_eq(const struct LDKRouteHint *NONNULL_PTR a, const struct LDKRouteHint *NONNULL_PTR b); + +/** + * Frees any resources used by the RouteHintHop, if is_owned is set and inner is non-NULL. + */ +void RouteHintHop_free(struct LDKRouteHintHop this_obj); + +/** + * The node_id of the non-target end of the route + */ +struct LDKPublicKey RouteHintHop_get_src_node_id(const struct LDKRouteHintHop *NONNULL_PTR this_ptr); + +/** + * The node_id of the non-target end of the route + */ +void RouteHintHop_set_src_node_id(struct LDKRouteHintHop *NONNULL_PTR this_ptr, struct LDKPublicKey val); + +/** + * The short_channel_id of this channel + */ +uint64_t RouteHintHop_get_short_channel_id(const struct LDKRouteHintHop *NONNULL_PTR this_ptr); + +/** + * The short_channel_id of this channel + */ +void RouteHintHop_set_short_channel_id(struct LDKRouteHintHop *NONNULL_PTR this_ptr, uint64_t val); + +/** + * The fees which must be paid to use this channel + */ +struct LDKRoutingFees RouteHintHop_get_fees(const struct LDKRouteHintHop *NONNULL_PTR this_ptr); + +/** + * The fees which must be paid to use this channel + */ +void RouteHintHop_set_fees(struct LDKRouteHintHop *NONNULL_PTR this_ptr, struct LDKRoutingFees val); + +/** + * The difference in CLTV values between this node and the next node. + */ +uint16_t RouteHintHop_get_cltv_expiry_delta(const struct LDKRouteHintHop *NONNULL_PTR this_ptr); + +/** + * The difference in CLTV values between this node and the next node. + */ +void RouteHintHop_set_cltv_expiry_delta(struct LDKRouteHintHop *NONNULL_PTR this_ptr, uint16_t val); + +/** + * The minimum value, in msat, which must be relayed to the next hop. + */ +struct LDKCOption_u64Z RouteHintHop_get_htlc_minimum_msat(const struct LDKRouteHintHop *NONNULL_PTR this_ptr); + +/** + * The minimum value, in msat, which must be relayed to the next hop. + */ +void RouteHintHop_set_htlc_minimum_msat(struct LDKRouteHintHop *NONNULL_PTR this_ptr, struct LDKCOption_u64Z val); + +/** + * The maximum value in msat available for routing with a single HTLC. + */ +struct LDKCOption_u64Z RouteHintHop_get_htlc_maximum_msat(const struct LDKRouteHintHop *NONNULL_PTR this_ptr); + +/** + * The maximum value in msat available for routing with a single HTLC. + */ +void RouteHintHop_set_htlc_maximum_msat(struct LDKRouteHintHop *NONNULL_PTR this_ptr, struct LDKCOption_u64Z val); + +/** + * Constructs a new RouteHintHop given each field + */ +MUST_USE_RES struct LDKRouteHintHop RouteHintHop_new(struct LDKPublicKey src_node_id_arg, uint64_t short_channel_id_arg, struct LDKRoutingFees fees_arg, uint16_t cltv_expiry_delta_arg, struct LDKCOption_u64Z htlc_minimum_msat_arg, struct LDKCOption_u64Z htlc_maximum_msat_arg); + +/** + * Creates a copy of the RouteHintHop + */ +struct LDKRouteHintHop RouteHintHop_clone(const struct LDKRouteHintHop *NONNULL_PTR orig); + +/** + * Checks if two RouteHintHops contain equal inner contents. + */ +uint64_t RouteHintHop_hash(const struct LDKRouteHintHop *NONNULL_PTR o); + +/** + * Checks if two RouteHintHops 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 RouteHintHop_eq(const struct LDKRouteHintHop *NONNULL_PTR a, const struct LDKRouteHintHop *NONNULL_PTR b); + +/** + * Gets a keysend route from us (payer) to the given target node (payee). This is needed because + * keysend payments do not have an invoice from which to pull the payee's supported features, which + * makes it tricky to otherwise supply the `payee_features` parameter of `get_route`. + * + * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None + */ +struct LDKCResult_RouteLightningErrorZ get_keysend_route(struct LDKPublicKey our_node_pubkey, const struct LDKNetworkGraph *NONNULL_PTR network, struct LDKPublicKey payee, struct LDKCVec_ChannelDetailsZ *first_hops, struct LDKCVec_RouteHintZ last_hops, uint64_t final_value_msat, uint32_t final_cltv, struct LDKLogger logger, const struct LDKScore *NONNULL_PTR scorer); + +/** + * Gets a route from us (payer) to the given target node (payee). + * + * If the payee provided features in their invoice, they should be provided via payee_features. + * Without this, MPP will only be used if the payee's features are available in the network graph. + * + * Private routing paths between a public node and the target may be included in `last_hops`. + * Currently, only the last hop in each path is considered. + * + * If some channels aren't announced, it may be useful to fill in a first_hops with the + * results from a local ChannelManager::list_usable_channels() call. If it is filled in, our + * view of our local channels (from net_graph_msg_handler) will be ignored, and only those + * in first_hops will be used. + * + * Panics if first_hops contains channels without short_channel_ids + * (ChannelManager::list_usable_channels will never include such channels). + * + * The fees on channels from us to next-hops are ignored (as they are assumed to all be + * equal), however the enabled/disabled bit on such channels as well as the + * htlc_minimum_msat/htlc_maximum_msat *are* checked as they may change based on the receiving node. + * + * Note that payee_features (or a relevant inner pointer) may be NULL or all-0s to represent None + * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None + */ +struct LDKCResult_RouteLightningErrorZ get_route(struct LDKPublicKey our_node_pubkey, const struct LDKNetworkGraph *NONNULL_PTR network, struct LDKPublicKey payee, struct LDKInvoiceFeatures payee_features, struct LDKCVec_ChannelDetailsZ *first_hops, struct LDKCVec_RouteHintZ last_hops, uint64_t final_value_msat, uint32_t final_cltv, struct LDKLogger logger, const struct LDKScore *NONNULL_PTR scorer); + +/** + * Frees any resources used by the Scorer, if is_owned is set and inner is non-NULL. + */ +void Scorer_free(struct LDKScorer this_obj); + +/** + * Creates a new scorer using `base_penalty_msat` as the channel penalty. + */ +MUST_USE_RES struct LDKScorer Scorer_new(uint64_t base_penalty_msat); + +/** + * Creates a "default" Scorer. See struct and individual field documentaiton for details on which values are used. + */ +MUST_USE_RES struct LDKScorer Scorer_default(void); + +/** + * Constructs a new Score which calls the relevant methods on this_arg. + * This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is + */ +struct LDKScore Scorer_as_Score(const struct LDKScorer *NONNULL_PTR this_arg); + /** * Frees any resources used by the FilesystemPersister, if is_owned is set and inner is non-NULL. */ diff --git a/lightning-c-bindings/include/lightningpp.hpp b/lightning-c-bindings/include/lightningpp.hpp index 1301b65..d05c71c 100644 --- a/lightning-c-bindings/include/lightningpp.hpp +++ b/lightning-c-bindings/include/lightningpp.hpp @@ -30,6 +30,7 @@ class AccessError; class Access; class Listen; class Confirm; +class ChannelMonitorUpdateErr; class Watch; class Filter; class WatchedOutput; @@ -40,10 +41,12 @@ class MessageSendEvent; class MessageSendEventsProvider; class EventsProvider; class EventHandler; +class Score; class InitFeatures; class NodeFeatures; class ChannelFeatures; class InvoiceFeatures; +class Scorer; class DelayedPaymentOutputDescriptor; class StaticPaymentOutputDescriptor; class SpendableOutputDescriptor; @@ -53,6 +56,7 @@ class KeysInterface; class InMemorySigner; class KeysManager; class FilesystemPersister; +class PaymentId; class ChannelManager; class ChainParameters; class CounterpartyForwardingInfo; @@ -87,13 +91,11 @@ class CreationError; class SemanticError; class SignOrCreationError; class ChannelMonitorUpdate; -class ChannelMonitorUpdateErr; class MonitorUpdateError; class MonitorEvent; class HTLCUpdate; class Balance; class ChannelMonitor; -class Persist; class CustomMessageHandler; class IgnoringMessageHandler; class ErroringMessageHandler; @@ -101,6 +103,7 @@ class MessageHandler; class SocketDescriptor; class PeerHandleError; class PeerManager; +class NodeId; class NetworkGraph; class ReadOnlyNetworkGraph; class NetworkUpdate; @@ -152,8 +155,11 @@ class ChannelMessageHandler; class RoutingMessageHandler; class Level; class Logger; +class Persist; +class LockedChannelMonitor; class ChainMonitor; class CVec_SpendableOutputDescriptorZ; +class CResult_LockedChannelMonitorNoneZ; class CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ; class CVec_C2Tuple_TxidCVec_C2Tuple_u32ScriptZZZZ; class CResult_HTLCUpdateDecodeErrorZ; @@ -162,6 +168,7 @@ class CVec_C2Tuple_u32TxOutZZ; class CResult_ChannelInfoDecodeErrorZ; class CResult_FundingCreatedDecodeErrorZ; class CResult_ChannelAnnouncementDecodeErrorZ; +class CVec_OutPointZ; class CResult_PositiveTimestampCreationErrorZ; class CResult_CVec_u8ZPeerHandleErrorZ; class CResult_InvoiceFeaturesDecodeErrorZ; @@ -181,8 +188,8 @@ class CResult_GossipTimestampFilterDecodeErrorZ; class COption_u32Z; class CResult_InitFeaturesDecodeErrorZ; class CResult_StaticPaymentOutputDescriptorDecodeErrorZ; +class CResult_PaymentIdPaymentSendFailureZ; class CResult_InvoiceSignOrCreationErrorZ; -class COption_FilterZ; class CResult_CommitmentTransactionDecodeErrorZ; class COption_C2Tuple_usizeTransactionZZ; class CResult_TransactionNoneZ; @@ -190,6 +197,7 @@ class CResult_SignedRawInvoiceNoneZ; class CResult_ExpiryTimeCreationErrorZ; class CResult_ClosingSignedFeeRangeDecodeErrorZ; class CResult_PingDecodeErrorZ; +class COption_FilterZ; class CVec_TransactionOutputsZ; class CResult_ErrorMessageDecodeErrorZ; class CResult_OpenChannelDecodeErrorZ; @@ -211,13 +219,14 @@ class CResult_HTLCOutputInCommitmentDecodeErrorZ; class CResult_boolLightningErrorZ; class CResult_TxCreationKeysErrorZ; class C2Tuple_BlockHashChannelMonitorZ; -class CResult_FundingSignedDecodeErrorZ; +class CResult_NodeIdDecodeErrorZ; class CResult_ShutdownScriptInvalidShutdownScriptZ; class CResult_RecoverableSignatureNoneZ; class CResult_NodeAnnouncementInfoDecodeErrorZ; class CResult_NetAddressu8Z; class C3Tuple_RawInvoice_u832InvoiceSignatureZ; class CVec_UpdateFailMalformedHTLCZ; +class CResult_FundingSignedDecodeErrorZ; class CResult_NetworkGraphDecodeErrorZ; class CVec_RouteHopZ; class CVec_C2Tuple_BlockHashChannelMonitorZZ; @@ -237,6 +246,7 @@ class CVec_ChannelDetailsZ; class CResult_SignDecodeErrorZ; class CVec_MessageSendEventZ; class C2Tuple_OutPointScriptZ; +class CResult_PaymentIdDecodeErrorZ; class CResult_UpdateFailMalformedHTLCDecodeErrorZ; class CVec_NodeAnnouncementZ; class CResult_UnsignedChannelAnnouncementDecodeErrorZ; @@ -255,16 +265,20 @@ class CVec_SignatureZ; class CVec_u64Z; class CResult_PongDecodeErrorZ; class CResult_DelayedPaymentOutputDescriptorDecodeErrorZ; +class C2Tuple_PaymentHashPaymentIdZ; class CResult_StringErrorZ; class CResult_NoneErrorZ; class C2Tuple_TxidCVec_C2Tuple_u32ScriptZZZ; +class CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ; class CVec_RouteHintZ; class COption_u16Z; class CVec_CVec_RouteHopZZ; class CResult_TrustedCommitmentTransactionNoneZ; class CResult_NoneLightningErrorZ; class CResult_NonePeerHandleErrorZ; +class COption_CVec_NetAddressZZ; class CResult_CVec_SignatureZNoneZ; +class CResult__u832APIErrorZ; class CResult_DescriptionCreationErrorZ; class CVec_C2Tuple_PublicKeyTypeZZ; class CResult_RoutingFeesDecodeErrorZ; @@ -293,7 +307,6 @@ class CResult_NoneSemanticErrorZ; class CVec_MonitorEventZ; class CVec_C2Tuple_u32ScriptZZ; class CResult_NoneChannelMonitorUpdateErrZ; -class CResult_PaymentHashPaymentSendFailureZ; class CResult_SiPrefixNoneZ; class CResult_PublicKeyErrorZ; class C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ; @@ -839,6 +852,20 @@ public: */ inline LDK::CVec_TxidZ get_relevant_txids(); }; +class ChannelMonitorUpdateErr { +private: + LDKChannelMonitorUpdateErr self; +public: + ChannelMonitorUpdateErr(const ChannelMonitorUpdateErr&) = delete; + ChannelMonitorUpdateErr(ChannelMonitorUpdateErr&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelMonitorUpdateErr)); } + ChannelMonitorUpdateErr(LDKChannelMonitorUpdateErr&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelMonitorUpdateErr)); } + operator LDKChannelMonitorUpdateErr() && { LDKChannelMonitorUpdateErr res = self; memset(&self, 0, sizeof(LDKChannelMonitorUpdateErr)); return res; } + ChannelMonitorUpdateErr& operator=(ChannelMonitorUpdateErr&& o) { self = o.self; memset(&o, 0, sizeof(ChannelMonitorUpdateErr)); return *this; } + LDKChannelMonitorUpdateErr* operator &() { return &self; } + LDKChannelMonitorUpdateErr* operator ->() { return &self; } + const LDKChannelMonitorUpdateErr* operator &() const { return &self; } + const LDKChannelMonitorUpdateErr* operator ->() const { return &self; } +}; class Watch { private: LDKWatch self; @@ -860,6 +887,9 @@ public: * with any spends of outputs returned by [`get_outputs_to_watch`]. In practice, this means * calling [`block_connected`] and [`block_disconnected`] on the monitor. * + * Note: this interface MUST error with `ChannelMonitorUpdateErr::PermanentFailure` if + * the given `funding_txo` has previously been registered via `watch_channel`. + * * [`get_outputs_to_watch`]: channelmonitor::ChannelMonitor::get_outputs_to_watch * [`block_connected`]: channelmonitor::ChannelMonitor::block_connected * [`block_disconnected`]: channelmonitor::ChannelMonitor::block_disconnected @@ -872,7 +902,6 @@ public: * [`ChannelMonitorUpdateErr`] for invariants around returning an error. * * [`update_monitor`]: channelmonitor::ChannelMonitor::update_monitor - * [`ChannelMonitorUpdateErr`]: channelmonitor::ChannelMonitorUpdateErr */ inline LDK::CResult_NoneChannelMonitorUpdateErrZ update_channel(struct LDKOutPoint funding_txo, struct LDKChannelMonitorUpdate update); /** @@ -1052,6 +1081,25 @@ public: */ inline void handle_event(const struct LDKEvent *NONNULL_PTR event); }; +class Score { +private: + LDKScore self; +public: + Score(const Score&) = delete; + Score(Score&& o) : self(o.self) { memset(&o, 0, sizeof(Score)); } + Score(LDKScore&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKScore)); } + operator LDKScore() && { LDKScore res = self; memset(&self, 0, sizeof(LDKScore)); return res; } + ~Score() { Score_free(self); } + Score& operator=(Score&& o) { Score_free(self); self = o.self; memset(&o, 0, sizeof(Score)); return *this; } + LDKScore* operator &() { return &self; } + LDKScore* operator ->() { return &self; } + const LDKScore* operator &() const { return &self; } + const LDKScore* operator ->() const { return &self; } + /** + * Returns the fee in msats willing to be paid to avoid routing through the given channel. + */ + inline uint64_t channel_penalty_msat(uint64_t short_channel_id); +}; class InitFeatures { private: LDKInitFeatures self; @@ -1112,6 +1160,21 @@ public: const LDKInvoiceFeatures* operator &() const { return &self; } const LDKInvoiceFeatures* operator ->() const { return &self; } }; +class Scorer { +private: + LDKScorer self; +public: + Scorer(const Scorer&) = delete; + Scorer(Scorer&& o) : self(o.self) { memset(&o, 0, sizeof(Scorer)); } + Scorer(LDKScorer&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKScorer)); } + operator LDKScorer() && { LDKScorer res = self; memset(&self, 0, sizeof(LDKScorer)); return res; } + ~Scorer() { Scorer_free(self); } + Scorer& operator=(Scorer&& o) { Scorer_free(self); self = o.self; memset(&o, 0, sizeof(Scorer)); return *this; } + LDKScorer* operator &() { return &self; } + LDKScorer* operator ->() { return &self; } + const LDKScorer* operator &() const { return &self; } + const LDKScorer* operator ->() const { return &self; } +}; class DelayedPaymentOutputDescriptor { private: LDKDelayedPaymentOutputDescriptor self; @@ -1446,6 +1509,21 @@ public: const LDKFilesystemPersister* operator &() const { return &self; } const LDKFilesystemPersister* operator ->() const { return &self; } }; +class PaymentId { +private: + LDKPaymentId self; +public: + PaymentId(const PaymentId&) = delete; + PaymentId(PaymentId&& o) : self(o.self) { memset(&o, 0, sizeof(PaymentId)); } + PaymentId(LDKPaymentId&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKPaymentId)); } + operator LDKPaymentId() && { LDKPaymentId res = self; memset(&self, 0, sizeof(LDKPaymentId)); return res; } + ~PaymentId() { PaymentId_free(self); } + PaymentId& operator=(PaymentId&& o) { PaymentId_free(self); self = o.self; memset(&o, 0, sizeof(PaymentId)); return *this; } + LDKPaymentId* operator &() { return &self; } + LDKPaymentId* operator ->() { return &self; } + const LDKPaymentId* operator &() const { return &self; } + const LDKPaymentId* operator ->() const { return &self; } +}; class ChannelManager { private: LDKChannelManager self; @@ -1967,20 +2045,6 @@ public: const LDKChannelMonitorUpdate* operator &() const { return &self; } const LDKChannelMonitorUpdate* operator ->() const { return &self; } }; -class ChannelMonitorUpdateErr { -private: - LDKChannelMonitorUpdateErr self; -public: - ChannelMonitorUpdateErr(const ChannelMonitorUpdateErr&) = delete; - ChannelMonitorUpdateErr(ChannelMonitorUpdateErr&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelMonitorUpdateErr)); } - ChannelMonitorUpdateErr(LDKChannelMonitorUpdateErr&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelMonitorUpdateErr)); } - operator LDKChannelMonitorUpdateErr() && { LDKChannelMonitorUpdateErr res = self; memset(&self, 0, sizeof(LDKChannelMonitorUpdateErr)); return res; } - ChannelMonitorUpdateErr& operator=(ChannelMonitorUpdateErr&& o) { self = o.self; memset(&o, 0, sizeof(ChannelMonitorUpdateErr)); return *this; } - LDKChannelMonitorUpdateErr* operator &() { return &self; } - LDKChannelMonitorUpdateErr* operator ->() { return &self; } - const LDKChannelMonitorUpdateErr* operator &() const { return &self; } - const LDKChannelMonitorUpdateErr* operator ->() const { return &self; } -}; class MonitorUpdateError { private: LDKMonitorUpdateError self; @@ -2056,57 +2120,6 @@ public: const LDKChannelMonitor* operator &() const { return &self; } const LDKChannelMonitor* operator ->() const { return &self; } }; -class Persist { -private: - LDKPersist self; -public: - Persist(const Persist&) = delete; - Persist(Persist&& o) : self(o.self) { memset(&o, 0, sizeof(Persist)); } - Persist(LDKPersist&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKPersist)); } - operator LDKPersist() && { LDKPersist res = self; memset(&self, 0, sizeof(LDKPersist)); return res; } - ~Persist() { Persist_free(self); } - Persist& operator=(Persist&& o) { Persist_free(self); self = o.self; memset(&o, 0, sizeof(Persist)); return *this; } - LDKPersist* operator &() { return &self; } - LDKPersist* operator ->() { return &self; } - const LDKPersist* operator &() const { return &self; } - const LDKPersist* operator ->() const { return &self; } - /** - * Persist a new channel's data. The data can be stored any way you want, but - * the identifier provided by Rust-Lightning is the channel's outpoint (and - * it is up to you to maintain a correct mapping between the outpoint and the - * stored channel data). Note that you **must** persist every new monitor to - * disk. See the `Persist` trait documentation for more details. - * - * See [`ChannelMonitor::write`] for writing out a `ChannelMonitor`, - * and [`ChannelMonitorUpdateErr`] for requirements when returning errors. - */ - inline LDK::CResult_NoneChannelMonitorUpdateErrZ persist_new_channel(struct LDKOutPoint id, const struct LDKChannelMonitor *NONNULL_PTR data); - /** - * Update one channel's data. The provided `ChannelMonitor` has already - * applied the given update. - * - * Note that on every update, you **must** persist either the - * `ChannelMonitorUpdate` or the updated monitor itself to disk/backups. See - * the `Persist` trait documentation for more details. - * - * If an implementer chooses to persist the updates only, they need to make - * sure that all the updates are applied to the `ChannelMonitors` *before* - * the set of channel monitors is given to the `ChannelManager` - * deserialization routine. See [`ChannelMonitor::update_monitor`] for - * applying a monitor update to a monitor. If full `ChannelMonitors` are - * persisted, then there is no need to persist individual updates. - * - * Note that there could be a performance tradeoff between persisting complete - * channel monitors on every update vs. persisting only updates and applying - * them in batches. The size of each monitor grows `O(number of state updates)` - * whereas updates are small and `O(1)`. - * - * See [`ChannelMonitor::write`] for writing out a `ChannelMonitor`, - * [`ChannelMonitorUpdate::write`] for writing out an update, and - * [`ChannelMonitorUpdateErr`] for requirements when returning errors. - */ - inline LDK::CResult_NoneChannelMonitorUpdateErrZ update_persisted_channel(struct LDKOutPoint id, const struct LDKChannelMonitorUpdate *NONNULL_PTR update, const struct LDKChannelMonitor *NONNULL_PTR data); -}; class CustomMessageHandler { private: LDKCustomMessageHandler self; @@ -2258,6 +2271,21 @@ public: const LDKPeerManager* operator &() const { return &self; } const LDKPeerManager* operator ->() const { return &self; } }; +class NodeId { +private: + LDKNodeId self; +public: + NodeId(const NodeId&) = delete; + NodeId(NodeId&& o) : self(o.self) { memset(&o, 0, sizeof(NodeId)); } + NodeId(LDKNodeId&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKNodeId)); } + operator LDKNodeId() && { LDKNodeId res = self; memset(&self, 0, sizeof(LDKNodeId)); return res; } + ~NodeId() { NodeId_free(self); } + NodeId& operator=(NodeId&& o) { NodeId_free(self); self = o.self; memset(&o, 0, sizeof(NodeId)); return *this; } + LDKNodeId* operator &() { return &self; } + LDKNodeId* operator ->() { return &self; } + const LDKNodeId* operator &() const { return &self; } + const LDKNodeId* operator ->() const { return &self; } +}; class NetworkGraph { private: LDKNetworkGraph self; @@ -3168,6 +3196,76 @@ public: */ inline void log(const char *record); }; +class Persist { +private: + LDKPersist self; +public: + Persist(const Persist&) = delete; + Persist(Persist&& o) : self(o.self) { memset(&o, 0, sizeof(Persist)); } + Persist(LDKPersist&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKPersist)); } + operator LDKPersist() && { LDKPersist res = self; memset(&self, 0, sizeof(LDKPersist)); return res; } + ~Persist() { Persist_free(self); } + Persist& operator=(Persist&& o) { Persist_free(self); self = o.self; memset(&o, 0, sizeof(Persist)); return *this; } + LDKPersist* operator &() { return &self; } + LDKPersist* operator ->() { return &self; } + const LDKPersist* operator &() const { return &self; } + const LDKPersist* operator ->() const { return &self; } + /** + * Persist a new channel's data. The data can be stored any way you want, but + * the identifier provided by Rust-Lightning is the channel's outpoint (and + * it is up to you to maintain a correct mapping between the outpoint and the + * stored channel data). Note that you **must** persist every new monitor to + * disk. See the `Persist` trait documentation for more details. + * + * See [`Writeable::write`] on [`ChannelMonitor`] for writing out a `ChannelMonitor` + * and [`ChannelMonitorUpdateErr`] for requirements when returning errors. + * + * [`Writeable::write`]: crate::util::ser::Writeable::write + */ + inline LDK::CResult_NoneChannelMonitorUpdateErrZ persist_new_channel(struct LDKOutPoint id, const struct LDKChannelMonitor *NONNULL_PTR data); + /** + * Update one channel's data. The provided `ChannelMonitor` has already + * applied the given update. + * + * Note that on every update, you **must** persist either the + * `ChannelMonitorUpdate` or the updated monitor itself to disk/backups. See + * the `Persist` trait documentation for more details. + * + * If an implementer chooses to persist the updates only, they need to make + * sure that all the updates are applied to the `ChannelMonitors` *before* + * the set of channel monitors is given to the `ChannelManager` + * deserialization routine. See [`ChannelMonitor::update_monitor`] for + * applying a monitor update to a monitor. If full `ChannelMonitors` are + * persisted, then there is no need to persist individual updates. + * + * Note that there could be a performance tradeoff between persisting complete + * channel monitors on every update vs. persisting only updates and applying + * them in batches. The size of each monitor grows `O(number of state updates)` + * whereas updates are small and `O(1)`. + * + * See [`Writeable::write`] on [`ChannelMonitor`] for writing out a `ChannelMonitor`, + * [`Writeable::write`] on [`ChannelMonitorUpdate`] for writing out an update, and + * [`ChannelMonitorUpdateErr`] for requirements when returning errors. + * + * [`Writeable::write`]: crate::util::ser::Writeable::write + */ + inline LDK::CResult_NoneChannelMonitorUpdateErrZ update_persisted_channel(struct LDKOutPoint id, const struct LDKChannelMonitorUpdate *NONNULL_PTR update, const struct LDKChannelMonitor *NONNULL_PTR data); +}; +class LockedChannelMonitor { +private: + LDKLockedChannelMonitor self; +public: + LockedChannelMonitor(const LockedChannelMonitor&) = delete; + LockedChannelMonitor(LockedChannelMonitor&& o) : self(o.self) { memset(&o, 0, sizeof(LockedChannelMonitor)); } + LockedChannelMonitor(LDKLockedChannelMonitor&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKLockedChannelMonitor)); } + operator LDKLockedChannelMonitor() && { LDKLockedChannelMonitor res = self; memset(&self, 0, sizeof(LDKLockedChannelMonitor)); return res; } + ~LockedChannelMonitor() { LockedChannelMonitor_free(self); } + LockedChannelMonitor& operator=(LockedChannelMonitor&& o) { LockedChannelMonitor_free(self); self = o.self; memset(&o, 0, sizeof(LockedChannelMonitor)); return *this; } + LDKLockedChannelMonitor* operator &() { return &self; } + LDKLockedChannelMonitor* operator ->() { return &self; } + const LDKLockedChannelMonitor* operator &() const { return &self; } + const LDKLockedChannelMonitor* operator ->() const { return &self; } +}; class ChainMonitor { private: LDKChainMonitor self; @@ -3198,6 +3296,21 @@ public: const LDKCVec_SpendableOutputDescriptorZ* operator &() const { return &self; } const LDKCVec_SpendableOutputDescriptorZ* operator ->() const { return &self; } }; +class CResult_LockedChannelMonitorNoneZ { +private: + LDKCResult_LockedChannelMonitorNoneZ self; +public: + CResult_LockedChannelMonitorNoneZ(const CResult_LockedChannelMonitorNoneZ&) = delete; + CResult_LockedChannelMonitorNoneZ(CResult_LockedChannelMonitorNoneZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_LockedChannelMonitorNoneZ)); } + CResult_LockedChannelMonitorNoneZ(LDKCResult_LockedChannelMonitorNoneZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_LockedChannelMonitorNoneZ)); } + operator LDKCResult_LockedChannelMonitorNoneZ() && { LDKCResult_LockedChannelMonitorNoneZ res = self; memset(&self, 0, sizeof(LDKCResult_LockedChannelMonitorNoneZ)); return res; } + ~CResult_LockedChannelMonitorNoneZ() { CResult_LockedChannelMonitorNoneZ_free(self); } + CResult_LockedChannelMonitorNoneZ& operator=(CResult_LockedChannelMonitorNoneZ&& o) { CResult_LockedChannelMonitorNoneZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_LockedChannelMonitorNoneZ)); return *this; } + LDKCResult_LockedChannelMonitorNoneZ* operator &() { return &self; } + LDKCResult_LockedChannelMonitorNoneZ* operator ->() { return &self; } + const LDKCResult_LockedChannelMonitorNoneZ* operator &() const { return &self; } + const LDKCResult_LockedChannelMonitorNoneZ* operator ->() const { return &self; } +}; class CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ { private: LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ self; @@ -3318,6 +3431,21 @@ public: const LDKCResult_ChannelAnnouncementDecodeErrorZ* operator &() const { return &self; } const LDKCResult_ChannelAnnouncementDecodeErrorZ* operator ->() const { return &self; } }; +class CVec_OutPointZ { +private: + LDKCVec_OutPointZ self; +public: + CVec_OutPointZ(const CVec_OutPointZ&) = delete; + CVec_OutPointZ(CVec_OutPointZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_OutPointZ)); } + CVec_OutPointZ(LDKCVec_OutPointZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_OutPointZ)); } + operator LDKCVec_OutPointZ() && { LDKCVec_OutPointZ res = self; memset(&self, 0, sizeof(LDKCVec_OutPointZ)); return res; } + ~CVec_OutPointZ() { CVec_OutPointZ_free(self); } + CVec_OutPointZ& operator=(CVec_OutPointZ&& o) { CVec_OutPointZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_OutPointZ)); return *this; } + LDKCVec_OutPointZ* operator &() { return &self; } + LDKCVec_OutPointZ* operator ->() { return &self; } + const LDKCVec_OutPointZ* operator &() const { return &self; } + const LDKCVec_OutPointZ* operator ->() const { return &self; } +}; class CResult_PositiveTimestampCreationErrorZ { private: LDKCResult_PositiveTimestampCreationErrorZ self; @@ -3603,6 +3731,21 @@ public: const LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ* operator &() const { return &self; } const LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ* operator ->() const { return &self; } }; +class CResult_PaymentIdPaymentSendFailureZ { +private: + LDKCResult_PaymentIdPaymentSendFailureZ self; +public: + CResult_PaymentIdPaymentSendFailureZ(const CResult_PaymentIdPaymentSendFailureZ&) = delete; + CResult_PaymentIdPaymentSendFailureZ(CResult_PaymentIdPaymentSendFailureZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_PaymentIdPaymentSendFailureZ)); } + CResult_PaymentIdPaymentSendFailureZ(LDKCResult_PaymentIdPaymentSendFailureZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_PaymentIdPaymentSendFailureZ)); } + operator LDKCResult_PaymentIdPaymentSendFailureZ() && { LDKCResult_PaymentIdPaymentSendFailureZ res = self; memset(&self, 0, sizeof(LDKCResult_PaymentIdPaymentSendFailureZ)); return res; } + ~CResult_PaymentIdPaymentSendFailureZ() { CResult_PaymentIdPaymentSendFailureZ_free(self); } + CResult_PaymentIdPaymentSendFailureZ& operator=(CResult_PaymentIdPaymentSendFailureZ&& o) { CResult_PaymentIdPaymentSendFailureZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_PaymentIdPaymentSendFailureZ)); return *this; } + LDKCResult_PaymentIdPaymentSendFailureZ* operator &() { return &self; } + LDKCResult_PaymentIdPaymentSendFailureZ* operator ->() { return &self; } + const LDKCResult_PaymentIdPaymentSendFailureZ* operator &() const { return &self; } + const LDKCResult_PaymentIdPaymentSendFailureZ* operator ->() const { return &self; } +}; class CResult_InvoiceSignOrCreationErrorZ { private: LDKCResult_InvoiceSignOrCreationErrorZ self; @@ -3618,21 +3761,6 @@ public: const LDKCResult_InvoiceSignOrCreationErrorZ* operator &() const { return &self; } const LDKCResult_InvoiceSignOrCreationErrorZ* operator ->() const { return &self; } }; -class COption_FilterZ { -private: - LDKCOption_FilterZ self; -public: - COption_FilterZ(const COption_FilterZ&) = delete; - COption_FilterZ(COption_FilterZ&& o) : self(o.self) { memset(&o, 0, sizeof(COption_FilterZ)); } - COption_FilterZ(LDKCOption_FilterZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCOption_FilterZ)); } - operator LDKCOption_FilterZ() && { LDKCOption_FilterZ res = self; memset(&self, 0, sizeof(LDKCOption_FilterZ)); return res; } - ~COption_FilterZ() { COption_FilterZ_free(self); } - COption_FilterZ& operator=(COption_FilterZ&& o) { COption_FilterZ_free(self); self = o.self; memset(&o, 0, sizeof(COption_FilterZ)); return *this; } - LDKCOption_FilterZ* operator &() { return &self; } - LDKCOption_FilterZ* operator ->() { return &self; } - const LDKCOption_FilterZ* operator &() const { return &self; } - const LDKCOption_FilterZ* operator ->() const { return &self; } -}; class CResult_CommitmentTransactionDecodeErrorZ { private: LDKCResult_CommitmentTransactionDecodeErrorZ self; @@ -3738,6 +3866,21 @@ public: const LDKCResult_PingDecodeErrorZ* operator &() const { return &self; } const LDKCResult_PingDecodeErrorZ* operator ->() const { return &self; } }; +class COption_FilterZ { +private: + LDKCOption_FilterZ self; +public: + COption_FilterZ(const COption_FilterZ&) = delete; + COption_FilterZ(COption_FilterZ&& o) : self(o.self) { memset(&o, 0, sizeof(COption_FilterZ)); } + COption_FilterZ(LDKCOption_FilterZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCOption_FilterZ)); } + operator LDKCOption_FilterZ() && { LDKCOption_FilterZ res = self; memset(&self, 0, sizeof(LDKCOption_FilterZ)); return res; } + ~COption_FilterZ() { COption_FilterZ_free(self); } + COption_FilterZ& operator=(COption_FilterZ&& o) { COption_FilterZ_free(self); self = o.self; memset(&o, 0, sizeof(COption_FilterZ)); return *this; } + LDKCOption_FilterZ* operator &() { return &self; } + LDKCOption_FilterZ* operator ->() { return &self; } + const LDKCOption_FilterZ* operator &() const { return &self; } + const LDKCOption_FilterZ* operator ->() const { return &self; } +}; class CVec_TransactionOutputsZ { private: LDKCVec_TransactionOutputsZ self; @@ -4053,20 +4196,20 @@ public: const LDKC2Tuple_BlockHashChannelMonitorZ* operator &() const { return &self; } const LDKC2Tuple_BlockHashChannelMonitorZ* operator ->() const { return &self; } }; -class CResult_FundingSignedDecodeErrorZ { +class CResult_NodeIdDecodeErrorZ { private: - LDKCResult_FundingSignedDecodeErrorZ self; + LDKCResult_NodeIdDecodeErrorZ self; public: - CResult_FundingSignedDecodeErrorZ(const CResult_FundingSignedDecodeErrorZ&) = delete; - CResult_FundingSignedDecodeErrorZ(CResult_FundingSignedDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_FundingSignedDecodeErrorZ)); } - CResult_FundingSignedDecodeErrorZ(LDKCResult_FundingSignedDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_FundingSignedDecodeErrorZ)); } - operator LDKCResult_FundingSignedDecodeErrorZ() && { LDKCResult_FundingSignedDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_FundingSignedDecodeErrorZ)); return res; } - ~CResult_FundingSignedDecodeErrorZ() { CResult_FundingSignedDecodeErrorZ_free(self); } - CResult_FundingSignedDecodeErrorZ& operator=(CResult_FundingSignedDecodeErrorZ&& o) { CResult_FundingSignedDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_FundingSignedDecodeErrorZ)); return *this; } - LDKCResult_FundingSignedDecodeErrorZ* operator &() { return &self; } - LDKCResult_FundingSignedDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_FundingSignedDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_FundingSignedDecodeErrorZ* operator ->() const { return &self; } + CResult_NodeIdDecodeErrorZ(const CResult_NodeIdDecodeErrorZ&) = delete; + CResult_NodeIdDecodeErrorZ(CResult_NodeIdDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NodeIdDecodeErrorZ)); } + CResult_NodeIdDecodeErrorZ(LDKCResult_NodeIdDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NodeIdDecodeErrorZ)); } + operator LDKCResult_NodeIdDecodeErrorZ() && { LDKCResult_NodeIdDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_NodeIdDecodeErrorZ)); return res; } + ~CResult_NodeIdDecodeErrorZ() { CResult_NodeIdDecodeErrorZ_free(self); } + CResult_NodeIdDecodeErrorZ& operator=(CResult_NodeIdDecodeErrorZ&& o) { CResult_NodeIdDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NodeIdDecodeErrorZ)); return *this; } + LDKCResult_NodeIdDecodeErrorZ* operator &() { return &self; } + LDKCResult_NodeIdDecodeErrorZ* operator ->() { return &self; } + const LDKCResult_NodeIdDecodeErrorZ* operator &() const { return &self; } + const LDKCResult_NodeIdDecodeErrorZ* operator ->() const { return &self; } }; class CResult_ShutdownScriptInvalidShutdownScriptZ { private: @@ -4158,6 +4301,21 @@ public: const LDKCVec_UpdateFailMalformedHTLCZ* operator &() const { return &self; } const LDKCVec_UpdateFailMalformedHTLCZ* operator ->() const { return &self; } }; +class CResult_FundingSignedDecodeErrorZ { +private: + LDKCResult_FundingSignedDecodeErrorZ self; +public: + CResult_FundingSignedDecodeErrorZ(const CResult_FundingSignedDecodeErrorZ&) = delete; + CResult_FundingSignedDecodeErrorZ(CResult_FundingSignedDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_FundingSignedDecodeErrorZ)); } + CResult_FundingSignedDecodeErrorZ(LDKCResult_FundingSignedDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_FundingSignedDecodeErrorZ)); } + operator LDKCResult_FundingSignedDecodeErrorZ() && { LDKCResult_FundingSignedDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_FundingSignedDecodeErrorZ)); return res; } + ~CResult_FundingSignedDecodeErrorZ() { CResult_FundingSignedDecodeErrorZ_free(self); } + CResult_FundingSignedDecodeErrorZ& operator=(CResult_FundingSignedDecodeErrorZ&& o) { CResult_FundingSignedDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_FundingSignedDecodeErrorZ)); return *this; } + LDKCResult_FundingSignedDecodeErrorZ* operator &() { return &self; } + LDKCResult_FundingSignedDecodeErrorZ* operator ->() { return &self; } + const LDKCResult_FundingSignedDecodeErrorZ* operator &() const { return &self; } + const LDKCResult_FundingSignedDecodeErrorZ* operator ->() const { return &self; } +}; class CResult_NetworkGraphDecodeErrorZ { private: LDKCResult_NetworkGraphDecodeErrorZ self; @@ -4443,6 +4601,21 @@ public: const LDKC2Tuple_OutPointScriptZ* operator &() const { return &self; } const LDKC2Tuple_OutPointScriptZ* operator ->() const { return &self; } }; +class CResult_PaymentIdDecodeErrorZ { +private: + LDKCResult_PaymentIdDecodeErrorZ self; +public: + CResult_PaymentIdDecodeErrorZ(const CResult_PaymentIdDecodeErrorZ&) = delete; + CResult_PaymentIdDecodeErrorZ(CResult_PaymentIdDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_PaymentIdDecodeErrorZ)); } + CResult_PaymentIdDecodeErrorZ(LDKCResult_PaymentIdDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_PaymentIdDecodeErrorZ)); } + operator LDKCResult_PaymentIdDecodeErrorZ() && { LDKCResult_PaymentIdDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_PaymentIdDecodeErrorZ)); return res; } + ~CResult_PaymentIdDecodeErrorZ() { CResult_PaymentIdDecodeErrorZ_free(self); } + CResult_PaymentIdDecodeErrorZ& operator=(CResult_PaymentIdDecodeErrorZ&& o) { CResult_PaymentIdDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_PaymentIdDecodeErrorZ)); return *this; } + LDKCResult_PaymentIdDecodeErrorZ* operator &() { return &self; } + LDKCResult_PaymentIdDecodeErrorZ* operator ->() { return &self; } + const LDKCResult_PaymentIdDecodeErrorZ* operator &() const { return &self; } + const LDKCResult_PaymentIdDecodeErrorZ* operator ->() const { return &self; } +}; class CResult_UpdateFailMalformedHTLCDecodeErrorZ { private: LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ self; @@ -4713,6 +4886,21 @@ public: const LDKCResult_DelayedPaymentOutputDescriptorDecodeErrorZ* operator &() const { return &self; } const LDKCResult_DelayedPaymentOutputDescriptorDecodeErrorZ* operator ->() const { return &self; } }; +class C2Tuple_PaymentHashPaymentIdZ { +private: + LDKC2Tuple_PaymentHashPaymentIdZ self; +public: + C2Tuple_PaymentHashPaymentIdZ(const C2Tuple_PaymentHashPaymentIdZ&) = delete; + C2Tuple_PaymentHashPaymentIdZ(C2Tuple_PaymentHashPaymentIdZ&& o) : self(o.self) { memset(&o, 0, sizeof(C2Tuple_PaymentHashPaymentIdZ)); } + C2Tuple_PaymentHashPaymentIdZ(LDKC2Tuple_PaymentHashPaymentIdZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKC2Tuple_PaymentHashPaymentIdZ)); } + operator LDKC2Tuple_PaymentHashPaymentIdZ() && { LDKC2Tuple_PaymentHashPaymentIdZ res = self; memset(&self, 0, sizeof(LDKC2Tuple_PaymentHashPaymentIdZ)); return res; } + ~C2Tuple_PaymentHashPaymentIdZ() { C2Tuple_PaymentHashPaymentIdZ_free(self); } + C2Tuple_PaymentHashPaymentIdZ& operator=(C2Tuple_PaymentHashPaymentIdZ&& o) { C2Tuple_PaymentHashPaymentIdZ_free(self); self = o.self; memset(&o, 0, sizeof(C2Tuple_PaymentHashPaymentIdZ)); return *this; } + LDKC2Tuple_PaymentHashPaymentIdZ* operator &() { return &self; } + LDKC2Tuple_PaymentHashPaymentIdZ* operator ->() { return &self; } + const LDKC2Tuple_PaymentHashPaymentIdZ* operator &() const { return &self; } + const LDKC2Tuple_PaymentHashPaymentIdZ* operator ->() const { return &self; } +}; class CResult_StringErrorZ { private: LDKCResult_StringErrorZ self; @@ -4758,6 +4946,21 @@ public: const LDKC2Tuple_TxidCVec_C2Tuple_u32ScriptZZZ* operator &() const { return &self; } const LDKC2Tuple_TxidCVec_C2Tuple_u32ScriptZZZ* operator ->() const { return &self; } }; +class CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ { +private: + LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ self; +public: + CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ(const CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ&) = delete; + CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ(CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ)); } + CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ(LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ)); } + operator LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ() && { LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ res = self; memset(&self, 0, sizeof(LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ)); return res; } + ~CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ() { CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ_free(self); } + CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ& operator=(CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ&& o) { CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ)); return *this; } + LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ* operator &() { return &self; } + LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ* operator ->() { return &self; } + const LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ* operator &() const { return &self; } + const LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ* operator ->() const { return &self; } +}; class CVec_RouteHintZ { private: LDKCVec_RouteHintZ self; @@ -4848,6 +5051,21 @@ public: const LDKCResult_NonePeerHandleErrorZ* operator &() const { return &self; } const LDKCResult_NonePeerHandleErrorZ* operator ->() const { return &self; } }; +class COption_CVec_NetAddressZZ { +private: + LDKCOption_CVec_NetAddressZZ self; +public: + COption_CVec_NetAddressZZ(const COption_CVec_NetAddressZZ&) = delete; + COption_CVec_NetAddressZZ(COption_CVec_NetAddressZZ&& o) : self(o.self) { memset(&o, 0, sizeof(COption_CVec_NetAddressZZ)); } + COption_CVec_NetAddressZZ(LDKCOption_CVec_NetAddressZZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCOption_CVec_NetAddressZZ)); } + operator LDKCOption_CVec_NetAddressZZ() && { LDKCOption_CVec_NetAddressZZ res = self; memset(&self, 0, sizeof(LDKCOption_CVec_NetAddressZZ)); return res; } + ~COption_CVec_NetAddressZZ() { COption_CVec_NetAddressZZ_free(self); } + COption_CVec_NetAddressZZ& operator=(COption_CVec_NetAddressZZ&& o) { COption_CVec_NetAddressZZ_free(self); self = o.self; memset(&o, 0, sizeof(COption_CVec_NetAddressZZ)); return *this; } + LDKCOption_CVec_NetAddressZZ* operator &() { return &self; } + LDKCOption_CVec_NetAddressZZ* operator ->() { return &self; } + const LDKCOption_CVec_NetAddressZZ* operator &() const { return &self; } + const LDKCOption_CVec_NetAddressZZ* operator ->() const { return &self; } +}; class CResult_CVec_SignatureZNoneZ { private: LDKCResult_CVec_SignatureZNoneZ self; @@ -4863,6 +5081,21 @@ public: const LDKCResult_CVec_SignatureZNoneZ* operator &() const { return &self; } const LDKCResult_CVec_SignatureZNoneZ* operator ->() const { return &self; } }; +class CResult__u832APIErrorZ { +private: + LDKCResult__u832APIErrorZ self; +public: + CResult__u832APIErrorZ(const CResult__u832APIErrorZ&) = delete; + CResult__u832APIErrorZ(CResult__u832APIErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult__u832APIErrorZ)); } + CResult__u832APIErrorZ(LDKCResult__u832APIErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult__u832APIErrorZ)); } + operator LDKCResult__u832APIErrorZ() && { LDKCResult__u832APIErrorZ res = self; memset(&self, 0, sizeof(LDKCResult__u832APIErrorZ)); return res; } + ~CResult__u832APIErrorZ() { CResult__u832APIErrorZ_free(self); } + CResult__u832APIErrorZ& operator=(CResult__u832APIErrorZ&& o) { CResult__u832APIErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult__u832APIErrorZ)); return *this; } + LDKCResult__u832APIErrorZ* operator &() { return &self; } + LDKCResult__u832APIErrorZ* operator ->() { return &self; } + const LDKCResult__u832APIErrorZ* operator &() const { return &self; } + const LDKCResult__u832APIErrorZ* operator ->() const { return &self; } +}; class CResult_DescriptionCreationErrorZ { private: LDKCResult_DescriptionCreationErrorZ self; @@ -5283,21 +5516,6 @@ public: const LDKCResult_NoneChannelMonitorUpdateErrZ* operator &() const { return &self; } const LDKCResult_NoneChannelMonitorUpdateErrZ* operator ->() const { return &self; } }; -class CResult_PaymentHashPaymentSendFailureZ { -private: - LDKCResult_PaymentHashPaymentSendFailureZ self; -public: - CResult_PaymentHashPaymentSendFailureZ(const CResult_PaymentHashPaymentSendFailureZ&) = delete; - CResult_PaymentHashPaymentSendFailureZ(CResult_PaymentHashPaymentSendFailureZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_PaymentHashPaymentSendFailureZ)); } - CResult_PaymentHashPaymentSendFailureZ(LDKCResult_PaymentHashPaymentSendFailureZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_PaymentHashPaymentSendFailureZ)); } - operator LDKCResult_PaymentHashPaymentSendFailureZ() && { LDKCResult_PaymentHashPaymentSendFailureZ res = self; memset(&self, 0, sizeof(LDKCResult_PaymentHashPaymentSendFailureZ)); return res; } - ~CResult_PaymentHashPaymentSendFailureZ() { CResult_PaymentHashPaymentSendFailureZ_free(self); } - CResult_PaymentHashPaymentSendFailureZ& operator=(CResult_PaymentHashPaymentSendFailureZ&& o) { CResult_PaymentHashPaymentSendFailureZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_PaymentHashPaymentSendFailureZ)); return *this; } - LDKCResult_PaymentHashPaymentSendFailureZ* operator &() { return &self; } - LDKCResult_PaymentHashPaymentSendFailureZ* operator ->() { return &self; } - const LDKCResult_PaymentHashPaymentSendFailureZ* operator &() const { return &self; } - const LDKCResult_PaymentHashPaymentSendFailureZ* operator ->() const { return &self; } -}; class CResult_SiPrefixNoneZ { private: LDKCResult_SiPrefixNoneZ self; @@ -5707,6 +5925,10 @@ inline void EventsProvider::process_pending_events(struct LDKEventHandler handle inline void EventHandler::handle_event(const struct LDKEvent *NONNULL_PTR event) { (self.handle_event)(self.this_arg, event); } +inline uint64_t Score::channel_penalty_msat(uint64_t short_channel_id) { + uint64_t ret = (self.channel_penalty_msat)(self.this_arg, short_channel_id); + return ret; +} inline LDKPublicKey BaseSign::get_per_commitment_point(uint64_t idx) { LDKPublicKey ret = (self.get_per_commitment_point)(self.this_arg, idx); return ret; @@ -5798,14 +6020,6 @@ inline LDK::Str Type::debug_str() { LDK::Str ret = (self.debug_str)(self.this_arg); return ret; } -inline LDK::CResult_NoneChannelMonitorUpdateErrZ Persist::persist_new_channel(struct LDKOutPoint id, const struct LDKChannelMonitor *NONNULL_PTR data) { - LDK::CResult_NoneChannelMonitorUpdateErrZ ret = (self.persist_new_channel)(self.this_arg, id, data); - return ret; -} -inline LDK::CResult_NoneChannelMonitorUpdateErrZ Persist::update_persisted_channel(struct LDKOutPoint id, const struct LDKChannelMonitorUpdate *NONNULL_PTR update, const struct LDKChannelMonitor *NONNULL_PTR data) { - LDK::CResult_NoneChannelMonitorUpdateErrZ ret = (self.update_persisted_channel)(self.this_arg, id, update, data); - return ret; -} inline LDK::CResult_NoneLightningErrorZ CustomMessageHandler::handle_custom_message(struct LDKType msg, struct LDKPublicKey sender_node_id) { LDK::CResult_NoneLightningErrorZ ret = (self.handle_custom_message)(self.this_arg, msg, sender_node_id); return ret; @@ -5931,4 +6145,12 @@ inline LDK::CResult_NoneLightningErrorZ RoutingMessageHandler::handle_query_shor inline void Logger::log(const char *record) { (self.log)(self.this_arg, record); } +inline LDK::CResult_NoneChannelMonitorUpdateErrZ Persist::persist_new_channel(struct LDKOutPoint id, const struct LDKChannelMonitor *NONNULL_PTR data) { + LDK::CResult_NoneChannelMonitorUpdateErrZ ret = (self.persist_new_channel)(self.this_arg, id, data); + return ret; +} +inline LDK::CResult_NoneChannelMonitorUpdateErrZ Persist::update_persisted_channel(struct LDKOutPoint id, const struct LDKChannelMonitorUpdate *NONNULL_PTR update, const struct LDKChannelMonitor *NONNULL_PTR data) { + LDK::CResult_NoneChannelMonitorUpdateErrZ ret = (self.update_persisted_channel)(self.this_arg, id, update, data); + return ret; +} } diff --git a/lightning-c-bindings/src/c_types/derived.rs b/lightning-c-bindings/src/c_types/derived.rs index 2afa5c2..61b8bff 100644 --- a/lightning-c-bindings/src/c_types/derived.rs +++ b/lightning-c-bindings/src/c_types/derived.rs @@ -2270,11 +2270,11 @@ pub union CResult_NoneChannelMonitorUpdateErrZPtr { pub result: *mut std::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::chain::channelmonitor::ChannelMonitorUpdateErr, + pub err: *mut crate::lightning::chain::ChannelMonitorUpdateErr, } #[repr(C)] /// A CResult_NoneChannelMonitorUpdateErrZ represents the result of a fallible operation, -/// containing a () on success and a crate::lightning::chain::channelmonitor::ChannelMonitorUpdateErr on failure. +/// containing a () on success and a crate::lightning::chain::ChannelMonitorUpdateErr on failure. /// `result_ok` indicates the overall state, and the contents are provided via `contents`. pub struct CResult_NoneChannelMonitorUpdateErrZ { /// The contents of this CResult_NoneChannelMonitorUpdateErrZ, accessible via either @@ -2295,7 +2295,7 @@ pub extern "C" fn CResult_NoneChannelMonitorUpdateErrZ_ok() -> CResult_NoneChann } #[no_mangle] /// Creates a new CResult_NoneChannelMonitorUpdateErrZ in the error state. -pub extern "C" fn CResult_NoneChannelMonitorUpdateErrZ_err(e: crate::lightning::chain::channelmonitor::ChannelMonitorUpdateErr) -> CResult_NoneChannelMonitorUpdateErrZ { +pub extern "C" fn CResult_NoneChannelMonitorUpdateErrZ_err(e: crate::lightning::chain::ChannelMonitorUpdateErr) -> CResult_NoneChannelMonitorUpdateErrZ { CResult_NoneChannelMonitorUpdateErrZ { contents: CResult_NoneChannelMonitorUpdateErrZPtr { err: Box::into_raw(Box::new(e)), @@ -2316,8 +2316,8 @@ impl Drop for CResult_NoneChannelMonitorUpdateErrZ { } } } -impl From> for CResult_NoneChannelMonitorUpdateErrZ { - fn from(mut o: crate::c_types::CResultTempl<(), crate::lightning::chain::channelmonitor::ChannelMonitorUpdateErr>) -> Self { +impl From> for CResult_NoneChannelMonitorUpdateErrZ { + fn from(mut o: crate::c_types::CResultTempl<(), crate::lightning::chain::ChannelMonitorUpdateErr>) -> Self { let contents = if o.result_ok { let _ = unsafe { Box::from_raw(o.contents.result) }; o.contents.result = std::ptr::null_mut(); @@ -2341,7 +2341,7 @@ impl Clone for CResult_NoneChannelMonitorUpdateErrZ { } } } else { Self { result_ok: false, contents: CResult_NoneChannelMonitorUpdateErrZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) + err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) } } } } @@ -4154,6 +4154,97 @@ impl From CResult_PaymentIdDecodeErrorZ { + CResult_PaymentIdDecodeErrorZ { + contents: CResult_PaymentIdDecodeErrorZPtr { + result: Box::into_raw(Box::new(o)), + }, + result_ok: true, + } +} +#[no_mangle] +/// Creates a new CResult_PaymentIdDecodeErrorZ in the error state. +pub extern "C" fn CResult_PaymentIdDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_PaymentIdDecodeErrorZ { + CResult_PaymentIdDecodeErrorZ { + contents: CResult_PaymentIdDecodeErrorZPtr { + err: Box::into_raw(Box::new(e)), + }, + result_ok: false, + } +} +#[no_mangle] +/// Frees any resources used by the CResult_PaymentIdDecodeErrorZ. +pub extern "C" fn CResult_PaymentIdDecodeErrorZ_free(_res: CResult_PaymentIdDecodeErrorZ) { } +impl Drop for CResult_PaymentIdDecodeErrorZ { + 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_PaymentIdDecodeErrorZ { + 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 = std::ptr::null_mut() }; + CResult_PaymentIdDecodeErrorZPtr { result } + } else { + let err = unsafe { o.contents.err }; + unsafe { o.contents.err = std::ptr::null_mut(); } + CResult_PaymentIdDecodeErrorZPtr { err } + }; + Self { + contents, + result_ok: o.result_ok, + } + } +} +impl Clone for CResult_PaymentIdDecodeErrorZ { + fn clone(&self) -> Self { + if self.result_ok { + Self { result_ok: true, contents: CResult_PaymentIdDecodeErrorZPtr { + result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) + } } + } else { + Self { result_ok: false, contents: CResult_PaymentIdDecodeErrorZPtr { + err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) + } } + } + } +} +#[no_mangle] +/// Creates a new CResult_PaymentIdDecodeErrorZ which has the same data as `orig` +/// but with all dynamically-allocated buffers duplicated in new buffers. +pub extern "C" fn CResult_PaymentIdDecodeErrorZ_clone(orig: &CResult_PaymentIdDecodeErrorZ) -> CResult_PaymentIdDecodeErrorZ { Clone::clone(&orig) } +#[repr(C)] #[derive(Clone)] /// An enum which can either contain a u16 or not pub enum COption_u16Z { @@ -4370,6 +4461,188 @@ impl Clone for CVec_APIErrorZ { } } #[repr(C)] +/// The contents of CResult__u832APIErrorZ +pub union CResult__u832APIErrorZPtr { + /// 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::ThirtyTwoBytes, + /// 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::util::errors::APIError, +} +#[repr(C)] +/// A CResult__u832APIErrorZ represents the result of a fallible operation, +/// containing a crate::c_types::ThirtyTwoBytes on success and a crate::lightning::util::errors::APIError on failure. +/// `result_ok` indicates the overall state, and the contents are provided via `contents`. +pub struct CResult__u832APIErrorZ { + /// The contents of this CResult__u832APIErrorZ, accessible via either + /// `err` or `result` depending on the state of `result_ok`. + pub contents: CResult__u832APIErrorZPtr, + /// Whether this CResult__u832APIErrorZ represents a success state. + pub result_ok: bool, +} +#[no_mangle] +/// Creates a new CResult__u832APIErrorZ in the success state. +pub extern "C" fn CResult__u832APIErrorZ_ok(o: crate::c_types::ThirtyTwoBytes) -> CResult__u832APIErrorZ { + CResult__u832APIErrorZ { + contents: CResult__u832APIErrorZPtr { + result: Box::into_raw(Box::new(o)), + }, + result_ok: true, + } +} +#[no_mangle] +/// Creates a new CResult__u832APIErrorZ in the error state. +pub extern "C" fn CResult__u832APIErrorZ_err(e: crate::lightning::util::errors::APIError) -> CResult__u832APIErrorZ { + CResult__u832APIErrorZ { + contents: CResult__u832APIErrorZPtr { + err: Box::into_raw(Box::new(e)), + }, + result_ok: false, + } +} +#[no_mangle] +/// Frees any resources used by the CResult__u832APIErrorZ. +pub extern "C" fn CResult__u832APIErrorZ_free(_res: CResult__u832APIErrorZ) { } +impl Drop for CResult__u832APIErrorZ { + 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__u832APIErrorZ { + 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 = std::ptr::null_mut() }; + CResult__u832APIErrorZPtr { result } + } else { + let err = unsafe { o.contents.err }; + unsafe { o.contents.err = std::ptr::null_mut(); } + CResult__u832APIErrorZPtr { err } + }; + Self { + contents, + result_ok: o.result_ok, + } + } +} +impl Clone for CResult__u832APIErrorZ { + fn clone(&self) -> Self { + if self.result_ok { + Self { result_ok: true, contents: CResult__u832APIErrorZPtr { + result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) + } } + } else { + Self { result_ok: false, contents: CResult__u832APIErrorZPtr { + err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) + } } + } + } +} +#[no_mangle] +/// Creates a new CResult__u832APIErrorZ which has the same data as `orig` +/// but with all dynamically-allocated buffers duplicated in new buffers. +pub extern "C" fn CResult__u832APIErrorZ_clone(orig: &CResult__u832APIErrorZ) -> CResult__u832APIErrorZ { Clone::clone(&orig) } +#[repr(C)] +/// The contents of CResult_PaymentIdPaymentSendFailureZ +pub union CResult_PaymentIdPaymentSendFailureZPtr { + /// 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::ln::channelmanager::PaymentId, + /// 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::channelmanager::PaymentSendFailure, +} +#[repr(C)] +/// A CResult_PaymentIdPaymentSendFailureZ represents the result of a fallible operation, +/// containing a crate::lightning::ln::channelmanager::PaymentId on success and a crate::lightning::ln::channelmanager::PaymentSendFailure on failure. +/// `result_ok` indicates the overall state, and the contents are provided via `contents`. +pub struct CResult_PaymentIdPaymentSendFailureZ { + /// The contents of this CResult_PaymentIdPaymentSendFailureZ, accessible via either + /// `err` or `result` depending on the state of `result_ok`. + pub contents: CResult_PaymentIdPaymentSendFailureZPtr, + /// Whether this CResult_PaymentIdPaymentSendFailureZ represents a success state. + pub result_ok: bool, +} +#[no_mangle] +/// Creates a new CResult_PaymentIdPaymentSendFailureZ in the success state. +pub extern "C" fn CResult_PaymentIdPaymentSendFailureZ_ok(o: crate::lightning::ln::channelmanager::PaymentId) -> CResult_PaymentIdPaymentSendFailureZ { + CResult_PaymentIdPaymentSendFailureZ { + contents: CResult_PaymentIdPaymentSendFailureZPtr { + result: Box::into_raw(Box::new(o)), + }, + result_ok: true, + } +} +#[no_mangle] +/// Creates a new CResult_PaymentIdPaymentSendFailureZ in the error state. +pub extern "C" fn CResult_PaymentIdPaymentSendFailureZ_err(e: crate::lightning::ln::channelmanager::PaymentSendFailure) -> CResult_PaymentIdPaymentSendFailureZ { + CResult_PaymentIdPaymentSendFailureZ { + contents: CResult_PaymentIdPaymentSendFailureZPtr { + err: Box::into_raw(Box::new(e)), + }, + result_ok: false, + } +} +#[no_mangle] +/// Frees any resources used by the CResult_PaymentIdPaymentSendFailureZ. +pub extern "C" fn CResult_PaymentIdPaymentSendFailureZ_free(_res: CResult_PaymentIdPaymentSendFailureZ) { } +impl Drop for CResult_PaymentIdPaymentSendFailureZ { + 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_PaymentIdPaymentSendFailureZ { + 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 = std::ptr::null_mut() }; + CResult_PaymentIdPaymentSendFailureZPtr { result } + } else { + let err = unsafe { o.contents.err }; + unsafe { o.contents.err = std::ptr::null_mut(); } + CResult_PaymentIdPaymentSendFailureZPtr { err } + }; + Self { + contents, + result_ok: o.result_ok, + } + } +} +impl Clone for CResult_PaymentIdPaymentSendFailureZ { + fn clone(&self) -> Self { + if self.result_ok { + Self { result_ok: true, contents: CResult_PaymentIdPaymentSendFailureZPtr { + result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) + } } + } else { + Self { result_ok: false, contents: CResult_PaymentIdPaymentSendFailureZPtr { + err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) + } } + } + } +} +#[no_mangle] +/// Creates a new CResult_PaymentIdPaymentSendFailureZ which has the same data as `orig` +/// but with all dynamically-allocated buffers duplicated in new buffers. +pub extern "C" fn CResult_PaymentIdPaymentSendFailureZ_clone(orig: &CResult_PaymentIdPaymentSendFailureZ) -> CResult_PaymentIdPaymentSendFailureZ { Clone::clone(&orig) } +#[repr(C)] /// The contents of CResult_NonePaymentSendFailureZ pub union CResult_NonePaymentSendFailureZPtr { /// Note that this value is always NULL, as there are no contents in the OK variant @@ -4457,50 +4730,92 @@ impl Clone for CResult_NonePaymentSendFailureZ { /// but with all dynamically-allocated buffers duplicated in new buffers. pub extern "C" fn CResult_NonePaymentSendFailureZ_clone(orig: &CResult_NonePaymentSendFailureZ) -> CResult_NonePaymentSendFailureZ { Clone::clone(&orig) } #[repr(C)] -/// The contents of CResult_PaymentHashPaymentSendFailureZ -pub union CResult_PaymentHashPaymentSendFailureZPtr { +/// A tuple of 2 elements. See the individual fields for the types contained. +pub struct C2Tuple_PaymentHashPaymentIdZ { + /// The element at position 0 + pub a: crate::c_types::ThirtyTwoBytes, + /// The element at position 1 + pub b: crate::lightning::ln::channelmanager::PaymentId, +} +impl From<(crate::c_types::ThirtyTwoBytes, crate::lightning::ln::channelmanager::PaymentId)> for C2Tuple_PaymentHashPaymentIdZ { + fn from (tup: (crate::c_types::ThirtyTwoBytes, crate::lightning::ln::channelmanager::PaymentId)) -> Self { + Self { + a: tup.0, + b: tup.1, + } + } +} +impl C2Tuple_PaymentHashPaymentIdZ { + #[allow(unused)] pub(crate) fn to_rust(mut self) -> (crate::c_types::ThirtyTwoBytes, crate::lightning::ln::channelmanager::PaymentId) { + (self.a, self.b) + } +} +impl Clone for C2Tuple_PaymentHashPaymentIdZ { + fn clone(&self) -> Self { + Self { + a: Clone::clone(&self.a), + b: Clone::clone(&self.b), + } + } +} +#[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 C2Tuple_PaymentHashPaymentIdZ_clone(orig: &C2Tuple_PaymentHashPaymentIdZ) -> C2Tuple_PaymentHashPaymentIdZ { Clone::clone(&orig) } +/// Creates a new C2Tuple_PaymentHashPaymentIdZ from the contained elements. +#[no_mangle] +pub extern "C" fn C2Tuple_PaymentHashPaymentIdZ_new(a: crate::c_types::ThirtyTwoBytes, b: crate::lightning::ln::channelmanager::PaymentId) -> C2Tuple_PaymentHashPaymentIdZ { + C2Tuple_PaymentHashPaymentIdZ { a, b, } +} + +#[no_mangle] +/// Frees any resources used by the C2Tuple_PaymentHashPaymentIdZ. +pub extern "C" fn C2Tuple_PaymentHashPaymentIdZ_free(_res: C2Tuple_PaymentHashPaymentIdZ) { } +#[repr(C)] +/// The contents of CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ +pub union CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZPtr { /// 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::ThirtyTwoBytes, + pub result: *mut crate::c_types::derived::C2Tuple_PaymentHashPaymentIdZ, /// 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::channelmanager::PaymentSendFailure, } #[repr(C)] -/// A CResult_PaymentHashPaymentSendFailureZ represents the result of a fallible operation, -/// containing a crate::c_types::ThirtyTwoBytes on success and a crate::lightning::ln::channelmanager::PaymentSendFailure on failure. +/// A CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ represents the result of a fallible operation, +/// containing a crate::c_types::derived::C2Tuple_PaymentHashPaymentIdZ on success and a crate::lightning::ln::channelmanager::PaymentSendFailure on failure. /// `result_ok` indicates the overall state, and the contents are provided via `contents`. -pub struct CResult_PaymentHashPaymentSendFailureZ { - /// The contents of this CResult_PaymentHashPaymentSendFailureZ, accessible via either +pub struct CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ { + /// The contents of this CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ, accessible via either /// `err` or `result` depending on the state of `result_ok`. - pub contents: CResult_PaymentHashPaymentSendFailureZPtr, - /// Whether this CResult_PaymentHashPaymentSendFailureZ represents a success state. + pub contents: CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZPtr, + /// Whether this CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ represents a success state. pub result_ok: bool, } #[no_mangle] -/// Creates a new CResult_PaymentHashPaymentSendFailureZ in the success state. -pub extern "C" fn CResult_PaymentHashPaymentSendFailureZ_ok(o: crate::c_types::ThirtyTwoBytes) -> CResult_PaymentHashPaymentSendFailureZ { - CResult_PaymentHashPaymentSendFailureZ { - contents: CResult_PaymentHashPaymentSendFailureZPtr { +/// Creates a new CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ in the success state. +pub extern "C" fn CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ_ok(o: crate::c_types::derived::C2Tuple_PaymentHashPaymentIdZ) -> CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ { + CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ { + contents: CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZPtr { result: Box::into_raw(Box::new(o)), }, result_ok: true, } } #[no_mangle] -/// Creates a new CResult_PaymentHashPaymentSendFailureZ in the error state. -pub extern "C" fn CResult_PaymentHashPaymentSendFailureZ_err(e: crate::lightning::ln::channelmanager::PaymentSendFailure) -> CResult_PaymentHashPaymentSendFailureZ { - CResult_PaymentHashPaymentSendFailureZ { - contents: CResult_PaymentHashPaymentSendFailureZPtr { +/// Creates a new CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ in the error state. +pub extern "C" fn CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ_err(e: crate::lightning::ln::channelmanager::PaymentSendFailure) -> CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ { + CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ { + contents: CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZPtr { err: Box::into_raw(Box::new(e)), }, result_ok: false, } } #[no_mangle] -/// Frees any resources used by the CResult_PaymentHashPaymentSendFailureZ. -pub extern "C" fn CResult_PaymentHashPaymentSendFailureZ_free(_res: CResult_PaymentHashPaymentSendFailureZ) { } -impl Drop for CResult_PaymentHashPaymentSendFailureZ { +/// Frees any resources used by the CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ. +pub extern "C" fn CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ_free(_res: CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ) { } +impl Drop for CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ { fn drop(&mut self) { if self.result_ok { if unsafe { !(self.contents.result as *mut ()).is_null() } { @@ -4513,16 +4828,16 @@ impl Drop for CResult_PaymentHashPaymentSendFailureZ { } } } -impl From> for CResult_PaymentHashPaymentSendFailureZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { +impl From> for CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ { + 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 = std::ptr::null_mut() }; - CResult_PaymentHashPaymentSendFailureZPtr { result } + CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZPtr { result } } else { let err = unsafe { o.contents.err }; unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_PaymentHashPaymentSendFailureZPtr { err } + CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZPtr { err } }; Self { contents, @@ -4530,23 +4845,23 @@ impl From Self { if self.result_ok { - Self { result_ok: true, contents: CResult_PaymentHashPaymentSendFailureZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) + Self { result_ok: true, contents: CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZPtr { + result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) } } } else { - Self { result_ok: false, contents: CResult_PaymentHashPaymentSendFailureZPtr { + Self { result_ok: false, contents: CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZPtr { err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) } } } } } #[no_mangle] -/// Creates a new CResult_PaymentHashPaymentSendFailureZ which has the same data as `orig` +/// Creates a new CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ which has the same data as `orig` /// but with all dynamically-allocated buffers duplicated in new buffers. -pub extern "C" fn CResult_PaymentHashPaymentSendFailureZ_clone(orig: &CResult_PaymentHashPaymentSendFailureZ) -> CResult_PaymentHashPaymentSendFailureZ { Clone::clone(&orig) } +pub extern "C" fn CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ_clone(orig: &CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ) -> CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ { Clone::clone(&orig) } #[repr(C)] /// A dynamically-allocated array of crate::lightning::ln::msgs::NetAddresss of arbitrary size. /// This corresponds to std::vector in C++ @@ -7791,6 +8106,97 @@ impl Clone for CResult_boolPeerHandleErrorZ { /// but with all dynamically-allocated buffers duplicated in new buffers. pub extern "C" fn CResult_boolPeerHandleErrorZ_clone(orig: &CResult_boolPeerHandleErrorZ) -> CResult_boolPeerHandleErrorZ { Clone::clone(&orig) } #[repr(C)] +/// The contents of CResult_NodeIdDecodeErrorZ +pub union CResult_NodeIdDecodeErrorZPtr { + /// 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::routing::network_graph::NodeId, + /// 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_NodeIdDecodeErrorZ represents the result of a fallible operation, +/// containing a crate::lightning::routing::network_graph::NodeId 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_NodeIdDecodeErrorZ { + /// The contents of this CResult_NodeIdDecodeErrorZ, accessible via either + /// `err` or `result` depending on the state of `result_ok`. + pub contents: CResult_NodeIdDecodeErrorZPtr, + /// Whether this CResult_NodeIdDecodeErrorZ represents a success state. + pub result_ok: bool, +} +#[no_mangle] +/// Creates a new CResult_NodeIdDecodeErrorZ in the success state. +pub extern "C" fn CResult_NodeIdDecodeErrorZ_ok(o: crate::lightning::routing::network_graph::NodeId) -> CResult_NodeIdDecodeErrorZ { + CResult_NodeIdDecodeErrorZ { + contents: CResult_NodeIdDecodeErrorZPtr { + result: Box::into_raw(Box::new(o)), + }, + result_ok: true, + } +} +#[no_mangle] +/// Creates a new CResult_NodeIdDecodeErrorZ in the error state. +pub extern "C" fn CResult_NodeIdDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_NodeIdDecodeErrorZ { + CResult_NodeIdDecodeErrorZ { + contents: CResult_NodeIdDecodeErrorZPtr { + err: Box::into_raw(Box::new(e)), + }, + result_ok: false, + } +} +#[no_mangle] +/// Frees any resources used by the CResult_NodeIdDecodeErrorZ. +pub extern "C" fn CResult_NodeIdDecodeErrorZ_free(_res: CResult_NodeIdDecodeErrorZ) { } +impl Drop for CResult_NodeIdDecodeErrorZ { + 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_NodeIdDecodeErrorZ { + 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 = std::ptr::null_mut() }; + CResult_NodeIdDecodeErrorZPtr { result } + } else { + let err = unsafe { o.contents.err }; + unsafe { o.contents.err = std::ptr::null_mut(); } + CResult_NodeIdDecodeErrorZPtr { err } + }; + Self { + contents, + result_ok: o.result_ok, + } + } +} +impl Clone for CResult_NodeIdDecodeErrorZ { + fn clone(&self) -> Self { + if self.result_ok { + Self { result_ok: true, contents: CResult_NodeIdDecodeErrorZPtr { + result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) + } } + } else { + Self { result_ok: false, contents: CResult_NodeIdDecodeErrorZPtr { + err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) + } } + } + } +} +#[no_mangle] +/// Creates a new CResult_NodeIdDecodeErrorZ which has the same data as `orig` +/// but with all dynamically-allocated buffers duplicated in new buffers. +pub extern "C" fn CResult_NodeIdDecodeErrorZ_clone(orig: &CResult_NodeIdDecodeErrorZ) -> CResult_NodeIdDecodeErrorZ { Clone::clone(&orig) } +#[repr(C)] /// An enum which can either contain a crate::lightning::chain::Access or not pub enum COption_AccessZ { /// When we're in this state, this COption_AccessZ contains a crate::lightning::chain::Access @@ -8415,6 +8821,43 @@ impl Clone for CResult_NetworkGraphDecodeErrorZ { /// but with all dynamically-allocated buffers duplicated in new buffers. pub extern "C" fn CResult_NetworkGraphDecodeErrorZ_clone(orig: &CResult_NetworkGraphDecodeErrorZ) -> CResult_NetworkGraphDecodeErrorZ { Clone::clone(&orig) } #[repr(C)] +#[derive(Clone)] +/// An enum which can either contain a crate::c_types::derived::CVec_NetAddressZ or not +pub enum COption_CVec_NetAddressZZ { + /// When we're in this state, this COption_CVec_NetAddressZZ contains a crate::c_types::derived::CVec_NetAddressZ + Some(crate::c_types::derived::CVec_NetAddressZ), + /// When we're in this state, this COption_CVec_NetAddressZZ contains nothing + None +} +impl COption_CVec_NetAddressZZ { + #[allow(unused)] pub(crate) fn is_some(&self) -> bool { + if let Self::Some(_) = self { true } else { false } + } + #[allow(unused)] pub(crate) fn is_none(&self) -> bool { + !self.is_some() + } + #[allow(unused)] pub(crate) fn take(mut self) -> crate::c_types::derived::CVec_NetAddressZ { + if let Self::Some(v) = self { v } else { unreachable!() } + } +} +#[no_mangle] +/// Constructs a new COption_CVec_NetAddressZZ containing a crate::c_types::derived::CVec_NetAddressZ +pub extern "C" fn COption_CVec_NetAddressZZ_some(o: crate::c_types::derived::CVec_NetAddressZ) -> COption_CVec_NetAddressZZ { + COption_CVec_NetAddressZZ::Some(o) +} +#[no_mangle] +/// Constructs a new COption_CVec_NetAddressZZ containing nothing +pub extern "C" fn COption_CVec_NetAddressZZ_none() -> COption_CVec_NetAddressZZ { + COption_CVec_NetAddressZZ::None +} +#[no_mangle] +/// Frees any resources associated with the crate::c_types::derived::CVec_NetAddressZ, if we are in the Some state +pub extern "C" fn COption_CVec_NetAddressZZ_free(_res: COption_CVec_NetAddressZZ) { } +#[no_mangle] +/// Creates a new COption_CVec_NetAddressZZ which has the same data as `orig` +/// but with all dynamically-allocated buffers duplicated in new buffers. +pub extern "C" fn COption_CVec_NetAddressZZ_clone(orig: &COption_CVec_NetAddressZZ) -> COption_CVec_NetAddressZZ { Clone::clone(&orig) } +#[repr(C)] /// The contents of CResult_NetAddressu8Z pub union CResult_NetAddressu8ZPtr { /// A pointer to the contents in the success state. @@ -11906,3 +12349,119 @@ pub extern "C" fn COption_FilterZ_none() -> COption_FilterZ { #[no_mangle] /// Frees any resources associated with the crate::lightning::chain::Filter, if we are in the Some state pub extern "C" fn COption_FilterZ_free(_res: COption_FilterZ) { } +#[repr(C)] +/// The contents of CResult_LockedChannelMonitorNoneZ +pub union CResult_LockedChannelMonitorNoneZPtr { + /// 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::chain::chainmonitor::LockedChannelMonitor, + /// Note that this value is always NULL, as there are no contents in the Err variant + pub err: *mut std::ffi::c_void, +} +#[repr(C)] +/// A CResult_LockedChannelMonitorNoneZ represents the result of a fallible operation, +/// containing a crate::lightning::chain::chainmonitor::LockedChannelMonitor on success and a () on failure. +/// `result_ok` indicates the overall state, and the contents are provided via `contents`. +pub struct CResult_LockedChannelMonitorNoneZ { + /// The contents of this CResult_LockedChannelMonitorNoneZ, accessible via either + /// `err` or `result` depending on the state of `result_ok`. + pub contents: CResult_LockedChannelMonitorNoneZPtr, + /// Whether this CResult_LockedChannelMonitorNoneZ represents a success state. + pub result_ok: bool, +} +#[no_mangle] +/// Creates a new CResult_LockedChannelMonitorNoneZ in the success state. +pub extern "C" fn CResult_LockedChannelMonitorNoneZ_ok(o: crate::lightning::chain::chainmonitor::LockedChannelMonitor) -> CResult_LockedChannelMonitorNoneZ { + CResult_LockedChannelMonitorNoneZ { + contents: CResult_LockedChannelMonitorNoneZPtr { + result: Box::into_raw(Box::new(o)), + }, + result_ok: true, + } +} +#[no_mangle] +/// Creates a new CResult_LockedChannelMonitorNoneZ in the error state. +pub extern "C" fn CResult_LockedChannelMonitorNoneZ_err() -> CResult_LockedChannelMonitorNoneZ { + CResult_LockedChannelMonitorNoneZ { + contents: CResult_LockedChannelMonitorNoneZPtr { + err: std::ptr::null_mut(), + }, + result_ok: false, + } +} +#[no_mangle] +/// Frees any resources used by the CResult_LockedChannelMonitorNoneZ. +pub extern "C" fn CResult_LockedChannelMonitorNoneZ_free(_res: CResult_LockedChannelMonitorNoneZ) { } +impl Drop for CResult_LockedChannelMonitorNoneZ { + 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_LockedChannelMonitorNoneZ { + 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 = std::ptr::null_mut() }; + CResult_LockedChannelMonitorNoneZPtr { result } + } else { + let _ = unsafe { Box::from_raw(o.contents.err) }; + o.contents.err = std::ptr::null_mut(); + CResult_LockedChannelMonitorNoneZPtr { err: std::ptr::null_mut() } + }; + Self { + contents, + result_ok: o.result_ok, + } + } +} +#[repr(C)] +/// A dynamically-allocated array of crate::lightning::chain::transaction::OutPoints of arbitrary size. +/// This corresponds to std::vector in C++ +pub struct CVec_OutPointZ { + /// 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::chain::transaction::OutPoint, + /// The number of elements pointed to by `data`. + pub datalen: usize +} +impl CVec_OutPointZ { + #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { + if self.datalen == 0 { return Vec::new(); } + let ret = unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }.into(); + self.data = std::ptr::null_mut(); + self.datalen = 0; + ret + } + #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::lightning::chain::transaction::OutPoint] { + unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } + } +} +impl From> for CVec_OutPointZ { + 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_OutPointZ_free(_res: CVec_OutPointZ) { } +impl Drop for CVec_OutPointZ { + fn drop(&mut self) { + if self.datalen == 0 { return; } + unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; + } +} +impl Clone for CVec_OutPointZ { + fn clone(&self) -> Self { + let mut res = Vec::new(); + if self.datalen == 0 { return Self::from(res); } + res.extend_from_slice(unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) }); + Self::from(res) + } +} diff --git a/lightning-c-bindings/src/lightning/chain/chainmonitor.rs b/lightning-c-bindings/src/lightning/chain/chainmonitor.rs index 0899794..5c37216 100644 --- a/lightning-c-bindings/src/lightning/chain/chainmonitor.rs +++ b/lightning-c-bindings/src/lightning/chain/chainmonitor.rs @@ -28,9 +28,165 @@ use core::convert::Infallible; use bitcoin::hashes::Hash; use crate::c_types::*; +/// `Persist` defines behavior for persisting channel monitors: this could mean +/// writing once to disk, and/or uploading to one or more backup services. +/// +/// Note that for every new monitor, you **must** persist the new `ChannelMonitor` +/// to disk/backups. And, on every update, you **must** persist either the +/// `ChannelMonitorUpdate` or the updated monitor itself. Otherwise, there is risk +/// of situations such as revoking a transaction, then crashing before this +/// revocation can be persisted, then unintentionally broadcasting a revoked +/// transaction and losing money. This is a risk because previous channel states +/// are toxic, so it's important that whatever channel state is persisted is +/// kept up-to-date. +#[repr(C)] +pub struct Persist { + /// 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, + /// Persist a new channel's data. The data can be stored any way you want, but + /// the identifier provided by Rust-Lightning is the channel's outpoint (and + /// it is up to you to maintain a correct mapping between the outpoint and the + /// stored channel data). Note that you **must** persist every new monitor to + /// disk. See the `Persist` trait documentation for more details. + /// + /// See [`Writeable::write`] on [`ChannelMonitor`] for writing out a `ChannelMonitor` + /// and [`ChannelMonitorUpdateErr`] for requirements when returning errors. + /// + /// [`Writeable::write`]: crate::util::ser::Writeable::write + #[must_use] + pub persist_new_channel: extern "C" fn (this_arg: *const c_void, id: crate::lightning::chain::transaction::OutPoint, data: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ, + /// Update one channel's data. The provided `ChannelMonitor` has already + /// applied the given update. + /// + /// Note that on every update, you **must** persist either the + /// `ChannelMonitorUpdate` or the updated monitor itself to disk/backups. See + /// the `Persist` trait documentation for more details. + /// + /// If an implementer chooses to persist the updates only, they need to make + /// sure that all the updates are applied to the `ChannelMonitors` *before* + /// the set of channel monitors is given to the `ChannelManager` + /// deserialization routine. See [`ChannelMonitor::update_monitor`] for + /// applying a monitor update to a monitor. If full `ChannelMonitors` are + /// persisted, then there is no need to persist individual updates. + /// + /// Note that there could be a performance tradeoff between persisting complete + /// channel monitors on every update vs. persisting only updates and applying + /// them in batches. The size of each monitor grows `O(number of state updates)` + /// whereas updates are small and `O(1)`. + /// + /// See [`Writeable::write`] on [`ChannelMonitor`] for writing out a `ChannelMonitor`, + /// [`Writeable::write`] on [`ChannelMonitorUpdate`] for writing out an update, and + /// [`ChannelMonitorUpdateErr`] for requirements when returning errors. + /// + /// [`Writeable::write`]: crate::util::ser::Writeable::write + #[must_use] + pub update_persisted_channel: extern "C" fn (this_arg: *const c_void, id: crate::lightning::chain::transaction::OutPoint, update: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate, data: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ, + /// 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 Persist {} +unsafe impl Sync for Persist {} +#[no_mangle] +pub(crate) extern "C" fn Persist_clone_fields(orig: &Persist) -> Persist { + Persist { + this_arg: orig.this_arg, + persist_new_channel: Clone::clone(&orig.persist_new_channel), + update_persisted_channel: Clone::clone(&orig.update_persisted_channel), + free: Clone::clone(&orig.free), + } +} + +use lightning::chain::chainmonitor::Persist as rustPersist; +impl rustPersist for Persist { + fn persist_new_channel(&self, mut id: lightning::chain::transaction::OutPoint, mut data: &lightning::chain::channelmonitor::ChannelMonitor) -> Result<(), lightning::chain::ChannelMonitorUpdateErr> { + let mut ret = (self.persist_new_channel)(self.this_arg, crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(id), is_owned: true }, &crate::lightning::chain::channelmonitor::ChannelMonitor { inner: unsafe { ObjOps::nonnull_ptr_to_inner((data as *const _) 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)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })}; + local_ret + } + fn update_persisted_channel(&self, mut id: lightning::chain::transaction::OutPoint, mut update: &lightning::chain::channelmonitor::ChannelMonitorUpdate, mut data: &lightning::chain::channelmonitor::ChannelMonitor) -> Result<(), lightning::chain::ChannelMonitorUpdateErr> { + let mut ret = (self.update_persisted_channel)(self.this_arg, crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(id), is_owned: true }, &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate { inner: unsafe { ObjOps::nonnull_ptr_to_inner((update as *const _) as *mut _) }, is_owned: false }, &crate::lightning::chain::channelmonitor::ChannelMonitor { inner: unsafe { ObjOps::nonnull_ptr_to_inner((data as *const _) 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)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })}; + 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 std::ops::Deref for Persist { + type Target = Self; + fn deref(&self) -> &Self { + self + } +} +/// Calls the free function if one is set +#[no_mangle] +pub extern "C" fn Persist_free(this_ptr: Persist) { } +impl Drop for Persist { + fn drop(&mut self) { + if let Some(f) = self.free { + f(self.this_arg); + } + } +} + +use lightning::chain::chainmonitor::LockedChannelMonitor as nativeLockedChannelMonitorImport; +type nativeLockedChannelMonitor = nativeLockedChannelMonitorImport<'static, crate::lightning::chain::keysinterface::Sign>; + +/// A read-only reference to a current ChannelMonitor. +/// +/// Note that this holds a mutex in [`ChainMonitor`] and may block other events until it is +/// released. +#[must_use] +#[repr(C)] +pub struct LockedChannelMonitor { + /// 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 nativeLockedChannelMonitor, + /// 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 LockedChannelMonitor { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeLockedChannelMonitor>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the LockedChannelMonitor, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn LockedChannelMonitor_free(this_obj: LockedChannelMonitor) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn LockedChannelMonitor_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeLockedChannelMonitor); } +} +#[allow(unused)] +impl LockedChannelMonitor { + pub(crate) fn get_native_ref(&self) -> &'static nativeLockedChannelMonitor { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeLockedChannelMonitor { + 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 nativeLockedChannelMonitor { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = std::ptr::null_mut(); + ret + } +} use lightning::chain::chainmonitor::ChainMonitor as nativeChainMonitorImport; -type nativeChainMonitor = nativeChainMonitorImport; +type nativeChainMonitor = nativeChainMonitorImport; /// An implementation of [`chain::Watch`] for monitoring channels. /// @@ -96,7 +252,7 @@ impl ChainMonitor { /// transactions relevant to the watched channels. #[must_use] #[no_mangle] -pub extern "C" fn ChainMonitor_new(mut chain_source: crate::c_types::derived::COption_FilterZ, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut logger: crate::lightning::util::logger::Logger, mut feeest: crate::lightning::chain::chaininterface::FeeEstimator, mut persister: crate::lightning::chain::channelmonitor::Persist) -> ChainMonitor { +pub extern "C" fn ChainMonitor_new(mut chain_source: crate::c_types::derived::COption_FilterZ, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut logger: crate::lightning::util::logger::Logger, mut feeest: crate::lightning::chain::chaininterface::FeeEstimator, mut persister: crate::lightning::chain::chainmonitor::Persist) -> ChainMonitor { let mut local_chain_source = { /* chain_source*/ let chain_source_opt = chain_source; { } if chain_source_opt.is_none() { None } else { Some({ chain_source_opt.take() }) } }; let mut ret = lightning::chain::chainmonitor::ChainMonitor::new(local_chain_source, broadcaster, logger, feeest, persister); ChainMonitor { inner: ObjOps::heap_alloc(ret), is_owned: true } @@ -120,6 +276,31 @@ pub extern "C" fn ChainMonitor_get_claimable_balances(this_arg: &ChainMonitor, m local_ret.into() } +/// Gets the [`LockedChannelMonitor`] for a given funding outpoint, returning an `Err` if no +/// such [`ChannelMonitor`] is currently being monitored for. +/// +/// Note that the result holds a mutex over our monitor set, and should not be held +/// indefinitely. +#[must_use] +#[no_mangle] +pub extern "C" fn ChainMonitor_get_monitor(this_arg: &ChainMonitor, mut funding_txo: crate::lightning::chain::transaction::OutPoint) -> crate::c_types::derived::CResult_LockedChannelMonitorNoneZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_monitor(*unsafe { Box::from_raw(funding_txo.take_inner()) }); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::chainmonitor::LockedChannelMonitor { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() }; + local_ret +} + +/// Lists the funding outpoint of each [`ChannelMonitor`] being monitored. +/// +/// Note that [`ChannelMonitor`]s are not removed when a channel is closed as they are always +/// monitoring for on-chain state resolutions. +#[must_use] +#[no_mangle] +pub extern "C" fn ChainMonitor_list_monitors(this_arg: &ChainMonitor) -> crate::c_types::derived::CVec_OutPointZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_monitors(); + let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(item), is_owned: true } }); }; + local_ret.into() +} + 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 }; @@ -216,13 +397,13 @@ pub extern "C" fn ChainMonitor_as_Watch(this_arg: &ChainMonitor) -> crate::light #[must_use] extern "C" fn ChainMonitor_Watch_watch_channel(this_arg: *const c_void, mut funding_outpoint: crate::lightning::chain::transaction::OutPoint, mut monitor: crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ { let mut ret = >::watch_channel(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, *unsafe { Box::from_raw(funding_outpoint.take_inner()) }, *unsafe { Box::from_raw(monitor.take_inner()) }); - 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::chain::channelmonitor::ChannelMonitorUpdateErr::native_into(e) }).into() }; + 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::chain::ChannelMonitorUpdateErr::native_into(e) }).into() }; local_ret } #[must_use] extern "C" fn ChainMonitor_Watch_update_channel(this_arg: *const c_void, mut funding_txo: crate::lightning::chain::transaction::OutPoint, mut update: crate::lightning::chain::channelmonitor::ChannelMonitorUpdate) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ { let mut ret = >::update_channel(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, *unsafe { Box::from_raw(funding_txo.take_inner()) }, *unsafe { Box::from_raw(update.take_inner()) }); - 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::chain::channelmonitor::ChannelMonitorUpdateErr::native_into(e) }).into() }; + 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::chain::ChannelMonitorUpdateErr::native_into(e) }).into() }; local_ret } #[must_use] diff --git a/lightning-c-bindings/src/lightning/chain/channelmonitor.rs b/lightning-c-bindings/src/lightning/chain/channelmonitor.rs index e446535..31c4f9e 100644 --- a/lightning-c-bindings/src/lightning/chain/channelmonitor.rs +++ b/lightning-c-bindings/src/lightning/chain/channelmonitor.rs @@ -153,112 +153,6 @@ pub extern "C" fn ChannelMonitorUpdate_read(ser: crate::c_types::u8slice) -> cra let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::channelmonitor::ChannelMonitorUpdate { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; local_res } -/// An error enum representing a failure to persist a channel monitor update. -#[must_use] -#[derive(Clone)] -#[repr(C)] -pub enum ChannelMonitorUpdateErr { - /// Used to indicate a temporary failure (eg connection to a watchtower or remote backup of - /// our state failed, but is expected to succeed at some point in the future). - /// - /// Such a failure will \"freeze\" a channel, preventing us from revoking old states or - /// submitting new commitment transactions to the counterparty. Once the update(s) which failed - /// have been successfully applied, ChannelManager::channel_monitor_updated can be used to - /// restore the channel to an operational state. - /// - /// Note that a given ChannelManager will *never* re-generate a given ChannelMonitorUpdate. If - /// you return a TemporaryFailure you must ensure that it is written to disk safely before - /// writing out the latest ChannelManager state. - /// - /// Even when a channel has been \"frozen\" updates to the ChannelMonitor can continue to occur - /// (eg if an inbound HTLC which we forwarded was claimed upstream resulting in us attempting - /// to claim it on this channel) and those updates must be applied wherever they can be. At - /// least one such updated ChannelMonitor must be persisted otherwise PermanentFailure should - /// be returned to get things on-chain ASAP using only the in-memory copy. Obviously updates to - /// the channel which would invalidate previous ChannelMonitors are not made when a channel has - /// been \"frozen\". - /// - /// Note that even if updates made after TemporaryFailure succeed you must still call - /// channel_monitor_updated to ensure you have the latest monitor and re-enable normal channel - /// operation. - /// - /// Note that the update being processed here will not be replayed for you when you call - /// ChannelManager::channel_monitor_updated, so you must store the update itself along - /// with the persisted ChannelMonitor on your own local disk prior to returning a - /// TemporaryFailure. You may, of course, employ a journaling approach, storing only the - /// ChannelMonitorUpdate on disk without updating the monitor itself, replaying the journal at - /// reload-time. - /// - /// For deployments where a copy of ChannelMonitors and other local state are backed up in a - /// remote location (with local copies persisted immediately), it is anticipated that all - /// updates will return TemporaryFailure until the remote copies could be updated. - TemporaryFailure, - /// Used to indicate no further channel monitor updates will be allowed (eg we've moved on to a - /// different watchtower and cannot update with all watchtowers that were previously informed - /// of this channel). - /// - /// At reception of this error, ChannelManager will force-close the channel and return at - /// least a final ChannelMonitorUpdate::ChannelForceClosed which must be delivered to at - /// least one ChannelMonitor copy. Revocation secret MUST NOT be released and offchain channel - /// update must be rejected. - /// - /// This failure may also signal a failure to update the local persisted copy of one of - /// the channel monitor instance. - /// - /// Note that even when you fail a holder commitment transaction update, you must store the - /// update to ensure you can claim from it in case of a duplicate copy of this ChannelMonitor - /// broadcasts it (e.g distributed channel-monitor deployment) - /// - /// In case of distributed watchtowers deployment, the new version must be written to disk, as - /// state may have been stored but rejected due to a block forcing a commitment broadcast. This - /// storage is used to claim outputs of rejected state confirmed onchain by another watchtower, - /// lagging behind on block processing. - PermanentFailure, -} -use lightning::chain::channelmonitor::ChannelMonitorUpdateErr as nativeChannelMonitorUpdateErr; -impl ChannelMonitorUpdateErr { - #[allow(unused)] - pub(crate) fn to_native(&self) -> nativeChannelMonitorUpdateErr { - match self { - ChannelMonitorUpdateErr::TemporaryFailure => nativeChannelMonitorUpdateErr::TemporaryFailure, - ChannelMonitorUpdateErr::PermanentFailure => nativeChannelMonitorUpdateErr::PermanentFailure, - } - } - #[allow(unused)] - pub(crate) fn into_native(self) -> nativeChannelMonitorUpdateErr { - match self { - ChannelMonitorUpdateErr::TemporaryFailure => nativeChannelMonitorUpdateErr::TemporaryFailure, - ChannelMonitorUpdateErr::PermanentFailure => nativeChannelMonitorUpdateErr::PermanentFailure, - } - } - #[allow(unused)] - pub(crate) fn from_native(native: &nativeChannelMonitorUpdateErr) -> Self { - match native { - nativeChannelMonitorUpdateErr::TemporaryFailure => ChannelMonitorUpdateErr::TemporaryFailure, - nativeChannelMonitorUpdateErr::PermanentFailure => ChannelMonitorUpdateErr::PermanentFailure, - } - } - #[allow(unused)] - pub(crate) fn native_into(native: nativeChannelMonitorUpdateErr) -> Self { - match native { - nativeChannelMonitorUpdateErr::TemporaryFailure => ChannelMonitorUpdateErr::TemporaryFailure, - nativeChannelMonitorUpdateErr::PermanentFailure => ChannelMonitorUpdateErr::PermanentFailure, - } - } -} -/// Creates a copy of the ChannelMonitorUpdateErr -#[no_mangle] -pub extern "C" fn ChannelMonitorUpdateErr_clone(orig: &ChannelMonitorUpdateErr) -> ChannelMonitorUpdateErr { - orig.clone() -} -#[no_mangle] -/// Utility method to constructs a new TemporaryFailure-variant ChannelMonitorUpdateErr -pub extern "C" fn ChannelMonitorUpdateErr_temporary_failure() -> ChannelMonitorUpdateErr { - ChannelMonitorUpdateErr::TemporaryFailure} -#[no_mangle] -/// Utility method to constructs a new PermanentFailure-variant ChannelMonitorUpdateErr -pub extern "C" fn ChannelMonitorUpdateErr_permanent_failure() -> ChannelMonitorUpdateErr { - ChannelMonitorUpdateErr::PermanentFailure} use lightning::chain::channelmonitor::MonitorUpdateError as nativeMonitorUpdateErrorImport; type nativeMonitorUpdateError = nativeMonitorUpdateErrorImport; @@ -1026,104 +920,6 @@ pub extern "C" fn ChannelMonitor_get_claimable_balances(this_arg: &ChannelMonito local_ret.into() } -/// `Persist` defines behavior for persisting channel monitors: this could mean -/// writing once to disk, and/or uploading to one or more backup services. -/// -/// Note that for every new monitor, you **must** persist the new `ChannelMonitor` -/// to disk/backups. And, on every update, you **must** persist either the -/// `ChannelMonitorUpdate` or the updated monitor itself. Otherwise, there is risk -/// of situations such as revoking a transaction, then crashing before this -/// revocation can be persisted, then unintentionally broadcasting a revoked -/// transaction and losing money. This is a risk because previous channel states -/// are toxic, so it's important that whatever channel state is persisted is -/// kept up-to-date. -#[repr(C)] -pub struct Persist { - /// 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, - /// Persist a new channel's data. The data can be stored any way you want, but - /// the identifier provided by Rust-Lightning is the channel's outpoint (and - /// it is up to you to maintain a correct mapping between the outpoint and the - /// stored channel data). Note that you **must** persist every new monitor to - /// disk. See the `Persist` trait documentation for more details. - /// - /// See [`ChannelMonitor::write`] for writing out a `ChannelMonitor`, - /// and [`ChannelMonitorUpdateErr`] for requirements when returning errors. - #[must_use] - pub persist_new_channel: extern "C" fn (this_arg: *const c_void, id: crate::lightning::chain::transaction::OutPoint, data: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ, - /// Update one channel's data. The provided `ChannelMonitor` has already - /// applied the given update. - /// - /// Note that on every update, you **must** persist either the - /// `ChannelMonitorUpdate` or the updated monitor itself to disk/backups. See - /// the `Persist` trait documentation for more details. - /// - /// If an implementer chooses to persist the updates only, they need to make - /// sure that all the updates are applied to the `ChannelMonitors` *before* - /// the set of channel monitors is given to the `ChannelManager` - /// deserialization routine. See [`ChannelMonitor::update_monitor`] for - /// applying a monitor update to a monitor. If full `ChannelMonitors` are - /// persisted, then there is no need to persist individual updates. - /// - /// Note that there could be a performance tradeoff between persisting complete - /// channel monitors on every update vs. persisting only updates and applying - /// them in batches. The size of each monitor grows `O(number of state updates)` - /// whereas updates are small and `O(1)`. - /// - /// See [`ChannelMonitor::write`] for writing out a `ChannelMonitor`, - /// [`ChannelMonitorUpdate::write`] for writing out an update, and - /// [`ChannelMonitorUpdateErr`] for requirements when returning errors. - #[must_use] - pub update_persisted_channel: extern "C" fn (this_arg: *const c_void, id: crate::lightning::chain::transaction::OutPoint, update: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate, data: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ, - /// 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 Persist {} -unsafe impl Sync for Persist {} -#[no_mangle] -pub(crate) extern "C" fn Persist_clone_fields(orig: &Persist) -> Persist { - Persist { - this_arg: orig.this_arg, - persist_new_channel: Clone::clone(&orig.persist_new_channel), - update_persisted_channel: Clone::clone(&orig.update_persisted_channel), - free: Clone::clone(&orig.free), - } -} - -use lightning::chain::channelmonitor::Persist as rustPersist; -impl rustPersist for Persist { - fn persist_new_channel(&self, mut id: lightning::chain::transaction::OutPoint, mut data: &lightning::chain::channelmonitor::ChannelMonitor) -> Result<(), lightning::chain::channelmonitor::ChannelMonitorUpdateErr> { - let mut ret = (self.persist_new_channel)(self.this_arg, crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(id), is_owned: true }, &crate::lightning::chain::channelmonitor::ChannelMonitor { inner: unsafe { ObjOps::nonnull_ptr_to_inner((data as *const _) 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)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })}; - local_ret - } - fn update_persisted_channel(&self, mut id: lightning::chain::transaction::OutPoint, mut update: &lightning::chain::channelmonitor::ChannelMonitorUpdate, mut data: &lightning::chain::channelmonitor::ChannelMonitor) -> Result<(), lightning::chain::channelmonitor::ChannelMonitorUpdateErr> { - let mut ret = (self.update_persisted_channel)(self.this_arg, crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(id), is_owned: true }, &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate { inner: unsafe { ObjOps::nonnull_ptr_to_inner((update as *const _) as *mut _) }, is_owned: false }, &crate::lightning::chain::channelmonitor::ChannelMonitor { inner: unsafe { ObjOps::nonnull_ptr_to_inner((data as *const _) 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)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })}; - 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 std::ops::Deref for Persist { - type Target = Self; - fn deref(&self) -> &Self { - self - } -} -/// Calls the free function if one is set -#[no_mangle] -pub extern "C" fn Persist_free(this_ptr: Persist) { } -impl Drop for Persist { - fn drop(&mut self) { - if let Some(f) = self.free { - f(self.this_arg); - } - } -} #[no_mangle] /// Read a C2Tuple_BlockHashChannelMonitorZ from a byte array, created by C2Tuple_BlockHashChannelMonitorZ_write pub extern "C" fn C2Tuple_BlockHashChannelMonitorZ_read(ser: crate::c_types::u8slice, arg: &crate::lightning::chain::keysinterface::KeysInterface) -> crate::c_types::derived::CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ { diff --git a/lightning-c-bindings/src/lightning/chain/mod.rs b/lightning-c-bindings/src/lightning/chain/mod.rs index 78f4b2e..bfed80c 100644 --- a/lightning-c-bindings/src/lightning/chain/mod.rs +++ b/lightning-c-bindings/src/lightning/chain/mod.rs @@ -449,6 +449,112 @@ impl Drop for Confirm { } } } +/// An error enum representing a failure to persist a channel monitor update. +#[must_use] +#[derive(Clone)] +#[repr(C)] +pub enum ChannelMonitorUpdateErr { + /// Used to indicate a temporary failure (eg connection to a watchtower or remote backup of + /// our state failed, but is expected to succeed at some point in the future). + /// + /// Such a failure will \"freeze\" a channel, preventing us from revoking old states or + /// submitting new commitment transactions to the counterparty. Once the update(s) which failed + /// have been successfully applied, ChannelManager::channel_monitor_updated can be used to + /// restore the channel to an operational state. + /// + /// Note that a given ChannelManager will *never* re-generate a given ChannelMonitorUpdate. If + /// you return a TemporaryFailure you must ensure that it is written to disk safely before + /// writing out the latest ChannelManager state. + /// + /// Even when a channel has been \"frozen\" updates to the ChannelMonitor can continue to occur + /// (eg if an inbound HTLC which we forwarded was claimed upstream resulting in us attempting + /// to claim it on this channel) and those updates must be applied wherever they can be. At + /// least one such updated ChannelMonitor must be persisted otherwise PermanentFailure should + /// be returned to get things on-chain ASAP using only the in-memory copy. Obviously updates to + /// the channel which would invalidate previous ChannelMonitors are not made when a channel has + /// been \"frozen\". + /// + /// Note that even if updates made after TemporaryFailure succeed you must still call + /// channel_monitor_updated to ensure you have the latest monitor and re-enable normal channel + /// operation. + /// + /// Note that the update being processed here will not be replayed for you when you call + /// ChannelManager::channel_monitor_updated, so you must store the update itself along + /// with the persisted ChannelMonitor on your own local disk prior to returning a + /// TemporaryFailure. You may, of course, employ a journaling approach, storing only the + /// ChannelMonitorUpdate on disk without updating the monitor itself, replaying the journal at + /// reload-time. + /// + /// For deployments where a copy of ChannelMonitors and other local state are backed up in a + /// remote location (with local copies persisted immediately), it is anticipated that all + /// updates will return TemporaryFailure until the remote copies could be updated. + TemporaryFailure, + /// Used to indicate no further channel monitor updates will be allowed (eg we've moved on to a + /// different watchtower and cannot update with all watchtowers that were previously informed + /// of this channel). + /// + /// At reception of this error, ChannelManager will force-close the channel and return at + /// least a final ChannelMonitorUpdate::ChannelForceClosed which must be delivered to at + /// least one ChannelMonitor copy. Revocation secret MUST NOT be released and offchain channel + /// update must be rejected. + /// + /// This failure may also signal a failure to update the local persisted copy of one of + /// the channel monitor instance. + /// + /// Note that even when you fail a holder commitment transaction update, you must store the + /// update to ensure you can claim from it in case of a duplicate copy of this ChannelMonitor + /// broadcasts it (e.g distributed channel-monitor deployment) + /// + /// In case of distributed watchtowers deployment, the new version must be written to disk, as + /// state may have been stored but rejected due to a block forcing a commitment broadcast. This + /// storage is used to claim outputs of rejected state confirmed onchain by another watchtower, + /// lagging behind on block processing. + PermanentFailure, +} +use lightning::chain::ChannelMonitorUpdateErr as nativeChannelMonitorUpdateErr; +impl ChannelMonitorUpdateErr { + #[allow(unused)] + pub(crate) fn to_native(&self) -> nativeChannelMonitorUpdateErr { + match self { + ChannelMonitorUpdateErr::TemporaryFailure => nativeChannelMonitorUpdateErr::TemporaryFailure, + ChannelMonitorUpdateErr::PermanentFailure => nativeChannelMonitorUpdateErr::PermanentFailure, + } + } + #[allow(unused)] + pub(crate) fn into_native(self) -> nativeChannelMonitorUpdateErr { + match self { + ChannelMonitorUpdateErr::TemporaryFailure => nativeChannelMonitorUpdateErr::TemporaryFailure, + ChannelMonitorUpdateErr::PermanentFailure => nativeChannelMonitorUpdateErr::PermanentFailure, + } + } + #[allow(unused)] + pub(crate) fn from_native(native: &nativeChannelMonitorUpdateErr) -> Self { + match native { + nativeChannelMonitorUpdateErr::TemporaryFailure => ChannelMonitorUpdateErr::TemporaryFailure, + nativeChannelMonitorUpdateErr::PermanentFailure => ChannelMonitorUpdateErr::PermanentFailure, + } + } + #[allow(unused)] + pub(crate) fn native_into(native: nativeChannelMonitorUpdateErr) -> Self { + match native { + nativeChannelMonitorUpdateErr::TemporaryFailure => ChannelMonitorUpdateErr::TemporaryFailure, + nativeChannelMonitorUpdateErr::PermanentFailure => ChannelMonitorUpdateErr::PermanentFailure, + } + } +} +/// Creates a copy of the ChannelMonitorUpdateErr +#[no_mangle] +pub extern "C" fn ChannelMonitorUpdateErr_clone(orig: &ChannelMonitorUpdateErr) -> ChannelMonitorUpdateErr { + orig.clone() +} +#[no_mangle] +/// Utility method to constructs a new TemporaryFailure-variant ChannelMonitorUpdateErr +pub extern "C" fn ChannelMonitorUpdateErr_temporary_failure() -> ChannelMonitorUpdateErr { + ChannelMonitorUpdateErr::TemporaryFailure} +#[no_mangle] +/// Utility method to constructs a new PermanentFailure-variant ChannelMonitorUpdateErr +pub extern "C" fn ChannelMonitorUpdateErr_permanent_failure() -> ChannelMonitorUpdateErr { + ChannelMonitorUpdateErr::PermanentFailure} /// The `Watch` trait defines behavior for watching on-chain activity pertaining to channels as /// blocks are connected and disconnected. /// @@ -467,9 +573,7 @@ impl Drop for Confirm { /// funds in the channel. See [`ChannelMonitorUpdateErr`] for more details about how to handle /// multiple instances. /// -/// [`ChannelMonitor`]: channelmonitor::ChannelMonitor -/// [`ChannelMonitorUpdateErr`]: channelmonitor::ChannelMonitorUpdateErr -/// [`PermanentFailure`]: channelmonitor::ChannelMonitorUpdateErr::PermanentFailure +/// [`PermanentFailure`]: ChannelMonitorUpdateErr::PermanentFailure #[repr(C)] pub struct Watch { /// An opaque pointer which is passed to your function implementations as an argument. @@ -481,6 +585,9 @@ pub struct Watch { /// with any spends of outputs returned by [`get_outputs_to_watch`]. In practice, this means /// calling [`block_connected`] and [`block_disconnected`] on the monitor. /// + /// Note: this interface MUST error with `ChannelMonitorUpdateErr::PermanentFailure` if + /// the given `funding_txo` has previously been registered via `watch_channel`. + /// /// [`get_outputs_to_watch`]: channelmonitor::ChannelMonitor::get_outputs_to_watch /// [`block_connected`]: channelmonitor::ChannelMonitor::block_connected /// [`block_disconnected`]: channelmonitor::ChannelMonitor::block_disconnected @@ -492,7 +599,6 @@ pub struct Watch { /// [`ChannelMonitorUpdateErr`] for invariants around returning an error. /// /// [`update_monitor`]: channelmonitor::ChannelMonitor::update_monitor - /// [`ChannelMonitorUpdateErr`]: channelmonitor::ChannelMonitorUpdateErr #[must_use] pub update_channel: extern "C" fn (this_arg: *const c_void, funding_txo: crate::lightning::chain::transaction::OutPoint, update: crate::lightning::chain::channelmonitor::ChannelMonitorUpdate) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ, /// Returns any monitor events since the last call. Subsequent calls must only return new @@ -518,12 +624,12 @@ pub(crate) extern "C" fn Watch_clone_fields(orig: &Watch) -> Watch { use lightning::chain::Watch as rustWatch; impl rustWatch for Watch { - fn watch_channel(&self, mut funding_txo: lightning::chain::transaction::OutPoint, mut monitor: lightning::chain::channelmonitor::ChannelMonitor) -> Result<(), lightning::chain::channelmonitor::ChannelMonitorUpdateErr> { + fn watch_channel(&self, mut funding_txo: lightning::chain::transaction::OutPoint, mut monitor: lightning::chain::channelmonitor::ChannelMonitor) -> Result<(), lightning::chain::ChannelMonitorUpdateErr> { let mut ret = (self.watch_channel)(self.this_arg, crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo), is_owned: true }, crate::lightning::chain::channelmonitor::ChannelMonitor { inner: ObjOps::heap_alloc(monitor), is_owned: true }); 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)) }).into_native() })}; local_ret } - fn update_channel(&self, mut funding_txo: lightning::chain::transaction::OutPoint, mut update: lightning::chain::channelmonitor::ChannelMonitorUpdate) -> Result<(), lightning::chain::channelmonitor::ChannelMonitorUpdateErr> { + fn update_channel(&self, mut funding_txo: lightning::chain::transaction::OutPoint, mut update: lightning::chain::channelmonitor::ChannelMonitorUpdate) -> Result<(), lightning::chain::ChannelMonitorUpdateErr> { let mut ret = (self.update_channel)(self.this_arg, crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo), is_owned: true }, crate::lightning::chain::channelmonitor::ChannelMonitorUpdate { inner: ObjOps::heap_alloc(update), is_owned: true }); 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)) }).into_native() })}; local_ret @@ -570,7 +676,7 @@ impl Drop for Watch { /// processed later. Then, in order to block until the data has been processed, any [`Watch`] /// invocation that has called the `Filter` must return [`TemporaryFailure`]. /// -/// [`TemporaryFailure`]: channelmonitor::ChannelMonitorUpdateErr::TemporaryFailure +/// [`TemporaryFailure`]: ChannelMonitorUpdateErr::TemporaryFailure /// [BIP 157]: https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki /// [BIP 158]: https://github.com/bitcoin/bips/blob/master/bip-0158.mediawiki #[repr(C)] diff --git a/lightning-c-bindings/src/lightning/ln/channelmanager.rs b/lightning-c-bindings/src/lightning/ln/channelmanager.rs index 8ebf7fd..871d9e5 100644 --- a/lightning-c-bindings/src/lightning/ln/channelmanager.rs +++ b/lightning-c-bindings/src/lightning/ln/channelmanager.rs @@ -24,6 +24,111 @@ use bitcoin::hashes::Hash; use crate::c_types::*; +use lightning::ln::channelmanager::PaymentId as nativePaymentIdImport; +type nativePaymentId = nativePaymentIdImport; + +/// A payment identifier used to uniquely identify a payment to LDK. +#[must_use] +#[repr(C)] +pub struct PaymentId { + /// 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 nativePaymentId, + /// 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 PaymentId { + fn drop(&mut self) { + if self.is_owned && !<*mut nativePaymentId>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the PaymentId, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn PaymentId_free(this_obj: PaymentId) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn PaymentId_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativePaymentId); } +} +#[allow(unused)] +impl PaymentId { + pub(crate) fn get_native_ref(&self) -> &'static nativePaymentId { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePaymentId { + 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 nativePaymentId { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = std::ptr::null_mut(); + ret + } +} +/// Checks if two PaymentIds contain equal inner contents. +#[no_mangle] +pub extern "C" fn PaymentId_hash(o: &PaymentId) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + std::hash::Hash::hash(o.get_native_ref(), &mut hasher); + std::hash::Hasher::finish(&hasher) +} +impl Clone for PaymentId { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativePaymentId>::is_null(self.inner) { std::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 PaymentId_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePaymentId)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the PaymentId +pub extern "C" fn PaymentId_clone(orig: &PaymentId) -> PaymentId { + orig.clone() +} +/// Checks if two PaymentIds 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 PaymentId_eq(a: &PaymentId, b: &PaymentId) -> 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 PaymentId object into a byte array which can be read by PaymentId_read +pub extern "C" fn PaymentId_write(obj: &PaymentId) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[no_mangle] +pub(crate) extern "C" fn PaymentId_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePaymentId) }) +} +#[no_mangle] +/// Read a PaymentId from a byte array, created by PaymentId_write +pub extern "C" fn PaymentId_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PaymentIdDecodeErrorZ { + let res = crate::c_types::deserialize_obj(ser); + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channelmanager::PaymentId { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + local_res +} + use lightning::ln::channelmanager::ChannelManager as nativeChannelManagerImport; type nativeChannelManager = nativeChannelManagerImport; @@ -669,16 +774,16 @@ pub extern "C" fn ChannelDetails_set_unspendable_punishment_reserve(this_ptr: &m let mut local_val = if val.is_some() { Some( { val.take() }) } else { None }; unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = local_val; } -/// The user_id passed in to create_channel, or 0 if the channel was inbound. +/// The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound. #[no_mangle] -pub extern "C" fn ChannelDetails_get_user_id(this_ptr: &ChannelDetails) -> u64 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().user_id; +pub extern "C" fn ChannelDetails_get_user_channel_id(this_ptr: &ChannelDetails) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().user_channel_id; *inner_val } -/// The user_id passed in to create_channel, or 0 if the channel was inbound. +/// The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound. #[no_mangle] -pub extern "C" fn ChannelDetails_set_user_id(this_ptr: &mut ChannelDetails, mut val: u64) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.user_id = val; +pub extern "C" fn ChannelDetails_set_user_channel_id(this_ptr: &mut ChannelDetails, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.user_channel_id = val; } /// The available outbound capacity for sending HTLCs to the remote peer. This does not include /// any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not @@ -855,7 +960,7 @@ pub extern "C" fn ChannelDetails_set_is_public(this_ptr: &mut ChannelDetails, mu /// Constructs a new ChannelDetails given each field #[must_use] #[no_mangle] -pub extern "C" fn ChannelDetails_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut counterparty_arg: crate::lightning::ln::channelmanager::ChannelCounterparty, mut funding_txo_arg: crate::lightning::chain::transaction::OutPoint, mut short_channel_id_arg: crate::c_types::derived::COption_u64Z, mut channel_value_satoshis_arg: u64, mut unspendable_punishment_reserve_arg: crate::c_types::derived::COption_u64Z, mut user_id_arg: u64, mut outbound_capacity_msat_arg: u64, mut inbound_capacity_msat_arg: u64, mut confirmations_required_arg: crate::c_types::derived::COption_u32Z, mut force_close_spend_delay_arg: crate::c_types::derived::COption_u16Z, mut is_outbound_arg: bool, mut is_funding_locked_arg: bool, mut is_usable_arg: bool, mut is_public_arg: bool) -> ChannelDetails { +pub extern "C" fn ChannelDetails_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut counterparty_arg: crate::lightning::ln::channelmanager::ChannelCounterparty, mut funding_txo_arg: crate::lightning::chain::transaction::OutPoint, mut short_channel_id_arg: crate::c_types::derived::COption_u64Z, mut channel_value_satoshis_arg: u64, mut unspendable_punishment_reserve_arg: crate::c_types::derived::COption_u64Z, mut user_channel_id_arg: u64, mut outbound_capacity_msat_arg: u64, mut inbound_capacity_msat_arg: u64, mut confirmations_required_arg: crate::c_types::derived::COption_u32Z, mut force_close_spend_delay_arg: crate::c_types::derived::COption_u16Z, mut is_outbound_arg: bool, mut is_funding_locked_arg: bool, mut is_usable_arg: bool, mut is_public_arg: bool) -> ChannelDetails { let mut local_funding_txo_arg = if funding_txo_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(funding_txo_arg.take_inner()) } }) }; let mut local_short_channel_id_arg = if short_channel_id_arg.is_some() { Some( { short_channel_id_arg.take() }) } else { None }; let mut local_unspendable_punishment_reserve_arg = if unspendable_punishment_reserve_arg.is_some() { Some( { unspendable_punishment_reserve_arg.take() }) } else { None }; @@ -868,7 +973,7 @@ pub extern "C" fn ChannelDetails_new(mut channel_id_arg: crate::c_types::ThirtyT short_channel_id: local_short_channel_id_arg, channel_value_satoshis: channel_value_satoshis_arg, unspendable_punishment_reserve: local_unspendable_punishment_reserve_arg, - user_id: user_id_arg, + user_channel_id: user_channel_id_arg, outbound_capacity_msat: outbound_capacity_msat_arg, inbound_capacity_msat: inbound_capacity_msat_arg, confirmations_required: local_confirmations_required_arg, @@ -1115,29 +1220,38 @@ pub extern "C" fn ChannelManager_get_current_default_configuration(this_arg: &Ch /// Creates a new outbound channel to the given remote node and with the given value. /// -/// user_id will be provided back as user_channel_id in FundingGenerationReady events to allow -/// tracking of which events correspond with which create_channel call. Note that the -/// user_channel_id defaults to 0 for inbound channels, so you may wish to avoid using 0 for -/// user_id here. user_id has no meaning inside of LDK, it is simply copied to events and -/// otherwise ignored. +/// `user_channel_id` will be provided back as in +/// [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events +/// correspond with which `create_channel` call. Note that the `user_channel_id` defaults to 0 +/// for inbound channels, so you may wish to avoid using 0 for `user_channel_id` here. +/// `user_channel_id` has no meaning inside of LDK, it is simply copied to events and otherwise +/// ignored. /// -/// If successful, will generate a SendOpenChannel message event, so you should probably poll -/// PeerManager::process_events afterwards. -/// -/// Raises APIError::APIMisuseError when channel_value_satoshis > 2**24 or push_msat is -/// greater than channel_value_satoshis * 1k or channel_value_satoshis is < 1000. +/// Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is +/// greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`. /// /// Note that we do not check if you are currently connected to the given peer. If no /// connection is available, the outbound `open_channel` message may fail to send, resulting in -/// the channel eventually being silently forgotten. +/// the channel eventually being silently forgotten (dropped on reload). +/// +/// Returns the new Channel's temporary `channel_id`. This ID will appear as +/// [`Event::FundingGenerationReady::temporary_channel_id`] and in +/// [`ChannelDetails::channel_id`] until after +/// [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for +/// one derived from the funding transaction's TXID. If the counterparty rejects the channel +/// immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`]. +/// +/// [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id +/// [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id +/// [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id /// /// Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] -pub extern "C" fn ChannelManager_create_channel(this_arg: &ChannelManager, mut their_network_key: crate::c_types::PublicKey, mut channel_value_satoshis: u64, mut push_msat: u64, mut user_id: u64, mut override_config: crate::lightning::util::config::UserConfig) -> crate::c_types::derived::CResult_NoneAPIErrorZ { +pub extern "C" fn ChannelManager_create_channel(this_arg: &ChannelManager, mut their_network_key: crate::c_types::PublicKey, mut channel_value_satoshis: u64, mut push_msat: u64, mut user_channel_id: u64, mut override_config: crate::lightning::util::config::UserConfig) -> crate::c_types::derived::CResult__u832APIErrorZ { let mut local_override_config = if override_config.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(override_config.take_inner()) } }) }; - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_channel(their_network_key.into_rust(), channel_value_satoshis, push_msat, user_id, local_override_config); - 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::util::errors::APIError::native_into(e) }).into() }; + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_channel(their_network_key.into_rust(), channel_value_satoshis, push_msat, user_channel_id, local_override_config); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ThirtyTwoBytes { data: o } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() }; local_ret } @@ -1277,9 +1391,25 @@ pub extern "C" fn ChannelManager_force_close_all_channels(this_arg: &ChannelMana /// Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] -pub extern "C" fn ChannelManager_send_payment(this_arg: &ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut payment_secret: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_NonePaymentSendFailureZ { +pub extern "C" fn ChannelManager_send_payment(this_arg: &ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut payment_secret: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_PaymentIdPaymentSendFailureZ { let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentSecret(payment_secret.data) }) }; let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_payment(route.get_native_ref(), ::lightning::ln::PaymentHash(payment_hash.data), &local_payment_secret); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channelmanager::PaymentId { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::channelmanager::PaymentSendFailure::native_into(e) }).into() }; + local_ret +} + +/// Retries a payment along the given [`Route`]. +/// +/// Errors returned are a superset of those returned from [`send_payment`], so see +/// [`send_payment`] documentation for more details on errors. This method will also error if the +/// retry amount puts the payment more than 10% over the payment's total amount, or if the payment +/// for the given `payment_id` cannot be found (likely due to timeout or success). +/// +/// [`send_payment`]: [`ChannelManager::send_payment`] +#[must_use] +#[no_mangle] +pub extern "C" fn ChannelManager_retry_payment(this_arg: &ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_id: crate::lightning::ln::channelmanager::PaymentId) -> crate::c_types::derived::CResult_NonePaymentSendFailureZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.retry_payment(route.get_native_ref(), *unsafe { Box::from_raw(payment_id.take_inner()) }); 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::channelmanager::PaymentSendFailure::native_into(e) }).into() }; local_ret } @@ -1302,10 +1432,10 @@ pub extern "C" fn ChannelManager_send_payment(this_arg: &ChannelManager, route: /// Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] -pub extern "C" fn ChannelManager_send_spontaneous_payment(this_arg: &ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_preimage: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_PaymentHashPaymentSendFailureZ { +pub extern "C" fn ChannelManager_send_spontaneous_payment(this_arg: &ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_preimage: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ { let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) }; let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_spontaneous_payment(route.get_native_ref(), local_payment_preimage); - let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ThirtyTwoBytes { data: o.0 } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::channelmanager::PaymentSendFailure::native_into(e) }).into() }; + 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::ThirtyTwoBytes { data: orig_ret_0_0.0 }, crate::lightning::ln::channelmanager::PaymentId { 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::ln::channelmanager::PaymentSendFailure::native_into(e) }).into() }; local_ret } diff --git a/lightning-c-bindings/src/lightning/routing/mod.rs b/lightning-c-bindings/src/lightning/routing/mod.rs index 1cc1bfb..8508d5d 100644 --- a/lightning-c-bindings/src/lightning/routing/mod.rs +++ b/lightning-c-bindings/src/lightning/routing/mod.rs @@ -14,5 +14,58 @@ use core::convert::Infallible; use bitcoin::hashes::Hash; use crate::c_types::*; -pub mod router; pub mod network_graph; +pub mod router; +pub mod scorer; +/// An interface used to score payment channels for path finding. +/// +///\tScoring is in terms of fees willing to be paid in order to avoid routing through a channel. +#[repr(C)] +pub struct Score { + /// 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 the fee in msats willing to be paid to avoid routing through the given channel. + #[must_use] + pub channel_penalty_msat: extern "C" fn (this_arg: *const c_void, short_channel_id: u64) -> u64, + /// 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 Score {} +unsafe impl Sync for Score {} +#[no_mangle] +pub(crate) extern "C" fn Score_clone_fields(orig: &Score) -> Score { + Score { + this_arg: orig.this_arg, + channel_penalty_msat: Clone::clone(&orig.channel_penalty_msat), + free: Clone::clone(&orig.free), + } +} + +use lightning::routing::Score as rustScore; +impl rustScore for Score { + fn channel_penalty_msat(&self, mut short_channel_id: u64) -> u64 { + let mut ret = (self.channel_penalty_msat)(self.this_arg, short_channel_id); + 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 std::ops::Deref for Score { + type Target = Self; + fn deref(&self) -> &Self { + self + } +} +/// Calls the free function if one is set +#[no_mangle] +pub extern "C" fn Score_free(this_ptr: Score) { } +impl Drop for Score { + fn drop(&mut self) { + if let Some(f) = self.free { + f(self.this_arg); + } + } +} diff --git a/lightning-c-bindings/src/lightning/routing/network_graph.rs b/lightning-c-bindings/src/lightning/routing/network_graph.rs index 5aece81..425a000 100644 --- a/lightning-c-bindings/src/lightning/routing/network_graph.rs +++ b/lightning-c-bindings/src/lightning/routing/network_graph.rs @@ -15,6 +15,119 @@ use bitcoin::hashes::Hash; use crate::c_types::*; +use lightning::routing::network_graph::NodeId as nativeNodeIdImport; +type nativeNodeId = nativeNodeIdImport; + +/// Represents the compressed public key of a node +#[must_use] +#[repr(C)] +pub struct NodeId { + /// 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 nativeNodeId, + /// 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 NodeId { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeNodeId>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the NodeId, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn NodeId_free(this_obj: NodeId) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn NodeId_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeId); } +} +#[allow(unused)] +impl NodeId { + pub(crate) fn get_native_ref(&self) -> &'static nativeNodeId { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeId { + 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 nativeNodeId { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = std::ptr::null_mut(); + ret + } +} +impl Clone for NodeId { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeNodeId>::is_null(self.inner) { std::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 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 +} +#[no_mangle] +/// Creates a copy of the NodeId +pub extern "C" fn NodeId_clone(orig: &NodeId) -> NodeId { + orig.clone() +} +/// Create a new NodeId from a public key +#[must_use] +#[no_mangle] +pub extern "C" fn NodeId_from_pubkey(mut pubkey: crate::c_types::PublicKey) -> NodeId { + let mut ret = lightning::routing::network_graph::NodeId::from_pubkey(&pubkey.into_rust()); + NodeId { inner: ObjOps::heap_alloc(ret), is_owned: true } +} + +/// Get the public key slice from this NodeId +#[must_use] +#[no_mangle] +pub extern "C" fn NodeId_as_slice(this_arg: &NodeId) -> crate::c_types::u8slice { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_slice(); + let mut local_ret = crate::c_types::u8slice::from_slice(ret); + local_ret +} + +/// Checks if two NodeIds contain equal inner contents. +#[no_mangle] +pub extern "C" fn NodeId_hash(o: &NodeId) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + std::hash::Hash::hash(o.get_native_ref(), &mut hasher); + std::hash::Hasher::finish(&hasher) +} +#[no_mangle] +/// Serialize the NodeId object into a byte array which can be read by NodeId_read +pub extern "C" fn NodeId_write(obj: &NodeId) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[no_mangle] +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) }) +} +#[no_mangle] +/// Read a NodeId from a byte array, created by NodeId_write +pub extern "C" fn NodeId_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeIdDecodeErrorZ { + let res = crate::c_types::deserialize_obj(ser); + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::NodeId { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + local_res +} + use lightning::routing::network_graph::NetworkGraph as nativeNetworkGraphImport; type nativeNetworkGraph = nativeNetworkGraphImport; @@ -804,14 +917,14 @@ pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: } /// Source node of the first direction of a channel #[no_mangle] -pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey { +pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::NodeId { let mut inner_val = &mut this_ptr.get_native_mut_ref().node_one; - crate::c_types::PublicKey::from_rust(&inner_val) + crate::lightning::routing::network_graph::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false } } /// Source node of the first direction of a channel #[no_mangle] -pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_one = val.into_rust(); +pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::NodeId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_one = *unsafe { Box::from_raw(val.take_inner()) }; } /// Details about the first direction of a channel /// @@ -832,14 +945,14 @@ pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val } /// Source node of the second direction of a channel #[no_mangle] -pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey { +pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::NodeId { let mut inner_val = &mut this_ptr.get_native_mut_ref().node_two; - crate::c_types::PublicKey::from_rust(&inner_val) + crate::lightning::routing::network_graph::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false } } /// Source node of the second direction of a channel #[no_mangle] -pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_two = val.into_rust(); +pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::NodeId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_two = *unsafe { Box::from_raw(val.take_inner()) }; } /// Details about the second direction of a channel /// @@ -897,16 +1010,16 @@ pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInf /// Constructs a new ChannelInfo given each field #[must_use] #[no_mangle] -pub extern "C" fn ChannelInfo_new(mut features_arg: crate::lightning::ln::features::ChannelFeatures, mut node_one_arg: crate::c_types::PublicKey, mut one_to_two_arg: crate::lightning::routing::network_graph::DirectionalChannelInfo, mut node_two_arg: crate::c_types::PublicKey, mut two_to_one_arg: crate::lightning::routing::network_graph::DirectionalChannelInfo, mut capacity_sats_arg: crate::c_types::derived::COption_u64Z, mut announcement_message_arg: crate::lightning::ln::msgs::ChannelAnnouncement) -> ChannelInfo { +pub extern "C" fn ChannelInfo_new(mut features_arg: crate::lightning::ln::features::ChannelFeatures, mut node_one_arg: crate::lightning::routing::network_graph::NodeId, mut one_to_two_arg: crate::lightning::routing::network_graph::DirectionalChannelInfo, mut node_two_arg: crate::lightning::routing::network_graph::NodeId, mut two_to_one_arg: crate::lightning::routing::network_graph::DirectionalChannelInfo, mut capacity_sats_arg: crate::c_types::derived::COption_u64Z, mut announcement_message_arg: crate::lightning::ln::msgs::ChannelAnnouncement) -> ChannelInfo { let mut local_one_to_two_arg = if one_to_two_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(one_to_two_arg.take_inner()) } }) }; let mut local_two_to_one_arg = if two_to_one_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(two_to_one_arg.take_inner()) } }) }; let mut local_capacity_sats_arg = if capacity_sats_arg.is_some() { Some( { capacity_sats_arg.take() }) } else { None }; let mut local_announcement_message_arg = if announcement_message_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(announcement_message_arg.take_inner()) } }) }; ChannelInfo { inner: ObjOps::heap_alloc(nativeChannelInfo { features: *unsafe { Box::from_raw(features_arg.take_inner()) }, - node_one: node_one_arg.into_rust(), + node_one: *unsafe { Box::from_raw(node_one_arg.take_inner()) }, one_to_two: local_one_to_two_arg, - node_two: node_two_arg.into_rust(), + node_two: *unsafe { Box::from_raw(node_two_arg.take_inner()) }, two_to_one: local_two_to_one_arg, capacity_sats: local_capacity_sats_arg, announcement_message: local_announcement_message_arg, @@ -1542,3 +1655,14 @@ pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &NetworkGraph, local_ret } +/// Get network addresses by node id. +/// Returns None if the requested node is completely unknown, +/// or if node announcement for the node was never received. +#[must_use] +#[no_mangle] +pub extern "C" fn ReadOnlyNetworkGraph_get_addresses(this_arg: &ReadOnlyNetworkGraph, mut pubkey: crate::c_types::PublicKey) -> crate::c_types::derived::COption_CVec_NetAddressZZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_addresses(&pubkey.into_rust()); + let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_NetAddressZZ::None } else { crate::c_types::derived::COption_CVec_NetAddressZZ::Some( { let mut local_ret_0 = Vec::new(); for mut item in ret.unwrap().drain(..) { local_ret_0.push( { crate::lightning::ln::msgs::NetAddress::native_into(item) }); }; local_ret_0.into() }) }; + local_ret +} + diff --git a/lightning-c-bindings/src/lightning/routing/router.rs b/lightning-c-bindings/src/lightning/routing/router.rs index ef58e57..5b5368d 100644 --- a/lightning-c-bindings/src/lightning/routing/router.rs +++ b/lightning-c-bindings/src/lightning/routing/router.rs @@ -637,10 +637,10 @@ pub extern "C" fn RouteHintHop_eq(a: &RouteHintHop, b: &RouteHintHop) -> bool { /// /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None #[no_mangle] -pub extern "C" fn get_keysend_route(mut our_node_id: crate::c_types::PublicKey, network: &crate::lightning::routing::network_graph::NetworkGraph, mut payee: crate::c_types::PublicKey, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut last_hops: crate::c_types::derived::CVec_RouteHintZ, mut final_value_msat: u64, mut final_cltv: u32, mut logger: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_RouteLightningErrorZ { +pub extern "C" fn get_keysend_route(mut our_node_pubkey: crate::c_types::PublicKey, network: &crate::lightning::routing::network_graph::NetworkGraph, mut payee: crate::c_types::PublicKey, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut last_hops: crate::c_types::derived::CVec_RouteHintZ, mut final_value_msat: u64, mut final_cltv: u32, mut logger: crate::lightning::util::logger::Logger, scorer: &crate::lightning::routing::Score) -> crate::c_types::derived::CResult_RouteLightningErrorZ { let mut local_first_hops_base = if first_hops == std::ptr::null_mut() { None } else { Some( { let mut local_first_hops_0 = Vec::new(); for mut item in unsafe { &mut *first_hops }.as_slice().iter() { local_first_hops_0.push( { item.get_native_ref() }); }; local_first_hops_0 }) }; let mut local_first_hops = local_first_hops_base.as_ref().map(|a| &a[..]); let mut local_last_hops = Vec::new(); for mut item in last_hops.as_slice().iter() { local_last_hops.push( { item.get_native_ref() }); }; - let mut ret = lightning::routing::router::get_keysend_route(&our_node_id.into_rust(), network.get_native_ref(), &payee.into_rust(), local_first_hops, &local_last_hops[..], final_value_msat, final_cltv, logger); + let mut ret = lightning::routing::router::get_keysend_route(&our_node_pubkey.into_rust(), network.get_native_ref(), &payee.into_rust(), local_first_hops, &local_last_hops[..], final_value_msat, final_cltv, logger, scorer); let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::Route { inner: ObjOps::heap_alloc(o), is_owned: true } }).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 } @@ -668,11 +668,11 @@ pub extern "C" fn get_keysend_route(mut our_node_id: crate::c_types::PublicKey, /// Note that payee_features (or a relevant inner pointer) may be NULL or all-0s to represent None /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None #[no_mangle] -pub extern "C" fn get_route(mut our_node_id: crate::c_types::PublicKey, network: &crate::lightning::routing::network_graph::NetworkGraph, mut payee: crate::c_types::PublicKey, mut payee_features: crate::lightning::ln::features::InvoiceFeatures, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut last_hops: crate::c_types::derived::CVec_RouteHintZ, mut final_value_msat: u64, mut final_cltv: u32, mut logger: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_RouteLightningErrorZ { +pub extern "C" fn get_route(mut our_node_pubkey: crate::c_types::PublicKey, network: &crate::lightning::routing::network_graph::NetworkGraph, mut payee: crate::c_types::PublicKey, mut payee_features: crate::lightning::ln::features::InvoiceFeatures, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut last_hops: crate::c_types::derived::CVec_RouteHintZ, mut final_value_msat: u64, mut final_cltv: u32, mut logger: crate::lightning::util::logger::Logger, scorer: &crate::lightning::routing::Score) -> crate::c_types::derived::CResult_RouteLightningErrorZ { let mut local_payee_features = if payee_features.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(payee_features.take_inner()) } }) }; let mut local_first_hops_base = if first_hops == std::ptr::null_mut() { None } else { Some( { let mut local_first_hops_0 = Vec::new(); for mut item in unsafe { &mut *first_hops }.as_slice().iter() { local_first_hops_0.push( { item.get_native_ref() }); }; local_first_hops_0 }) }; let mut local_first_hops = local_first_hops_base.as_ref().map(|a| &a[..]); let mut local_last_hops = Vec::new(); for mut item in last_hops.as_slice().iter() { local_last_hops.push( { item.get_native_ref() }); }; - let mut ret = lightning::routing::router::get_route(&our_node_id.into_rust(), network.get_native_ref(), &payee.into_rust(), local_payee_features, local_first_hops, &local_last_hops[..], final_value_msat, final_cltv, logger); + let mut ret = lightning::routing::router::get_route(&our_node_pubkey.into_rust(), network.get_native_ref(), &payee.into_rust(), local_payee_features, local_first_hops, &local_last_hops[..], final_value_msat, final_cltv, logger, scorer); let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::Route { inner: ObjOps::heap_alloc(o), is_owned: true } }).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 } diff --git a/lightning-c-bindings/src/lightning/routing/scorer.rs b/lightning-c-bindings/src/lightning/routing/scorer.rs new file mode 100644 index 0000000..a25a489 --- /dev/null +++ b/lightning-c-bindings/src/lightning/routing/scorer.rs @@ -0,0 +1,148 @@ +// This file is Copyright its original authors, visible in version control +// history and in the source files from which this was generated. +// +// This file is licensed under the license available in the LICENSE or LICENSE.md +// file in the root of this repository or, if no such file exists, the same +// license as that which applies to the original source files from which this +// source was automatically generated. + +//! Utilities for scoring payment channels. +//! +//! [`Scorer`] may be given to [`get_route`] to score payment channels during path finding when a +//! custom [`routing::Score`] implementation is not needed. +//! +//! # Example +//! +//! ``` +//! # extern crate secp256k1; +//! # +//! # use lightning::routing::network_graph::NetworkGraph; +//! # use lightning::routing::router::get_route; +//! # use lightning::routing::scorer::Scorer; +//! # use lightning::util::logger::{Logger, Record}; +//! # use secp256k1::key::PublicKey; +//! # +//! # struct FakeLogger {}; +//! # impl Logger for FakeLogger { +//! # fn log(&self, record: &Record) { unimplemented!() } +//! # } +//! # fn find_scored_route(payer: PublicKey, payee: PublicKey, network_graph: NetworkGraph) { +//! # let logger = FakeLogger {}; +//! # +//! // Use the default channel penalty. +//! let scorer = Scorer::default(); +//! +//! // Or use a custom channel penalty. +//! let scorer = Scorer::new(1_000); +//! +//! let route = get_route(&payer, &network_graph, &payee, None, None, &vec![], 1_000, 42, &logger, &scorer); +//! # } +//! ``` +//! +//! [`get_route`]: crate::routing::router::get_route + +use std::str::FromStr; +use std::ffi::c_void; +use core::convert::Infallible; +use bitcoin::hashes::Hash; +use crate::c_types::*; + + +use lightning::routing::scorer::Scorer as nativeScorerImport; +type nativeScorer = nativeScorerImport; + +/// [`routing::Score`] implementation that provides reasonable default behavior. +/// +/// Used to apply a fixed penalty to each channel, thus avoiding long paths when shorter paths with +/// slightly higher fees are available. +/// +/// See [module-level documentation] for usage. +/// +/// [module-level documentation]: crate::routing::scorer +#[must_use] +#[repr(C)] +pub struct Scorer { + /// 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 nativeScorer, + /// 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 Scorer { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeScorer>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the Scorer, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn Scorer_free(this_obj: Scorer) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn Scorer_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeScorer); } +} +#[allow(unused)] +impl Scorer { + pub(crate) fn get_native_ref(&self) -> &'static nativeScorer { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeScorer { + 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 nativeScorer { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = std::ptr::null_mut(); + ret + } +} +/// Creates a new scorer using `base_penalty_msat` as the channel penalty. +#[must_use] +#[no_mangle] +pub extern "C" fn Scorer_new(mut base_penalty_msat: u64) -> Scorer { + let mut ret = lightning::routing::scorer::Scorer::new(base_penalty_msat); + Scorer { inner: ObjOps::heap_alloc(ret), is_owned: true } +} + +/// Creates a "default" Scorer. See struct and individual field documentaiton for details on which values are used. +#[must_use] +#[no_mangle] +pub extern "C" fn Scorer_default() -> Scorer { + Scorer { inner: ObjOps::heap_alloc(Default::default()), is_owned: true } +} +impl From for crate::lightning::routing::Score { + fn from(obj: nativeScorer) -> Self { + let mut rust_obj = Scorer { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let mut ret = Scorer_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 = std::ptr::null_mut(); + ret.free = Some(Scorer_free_void); + ret + } +} +/// Constructs a new Score which calls the relevant methods on this_arg. +/// This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is +#[no_mangle] +pub extern "C" fn Scorer_as_Score(this_arg: &Scorer) -> crate::lightning::routing::Score { + crate::lightning::routing::Score { + this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, + free: None, + channel_penalty_msat: Scorer_Score_channel_penalty_msat, + } +} + +#[must_use] +extern "C" fn Scorer_Score_channel_penalty_msat(this_arg: *const c_void, mut _short_channel_id: u64) -> u64 { + let mut ret = >::channel_penalty_msat(unsafe { &mut *(this_arg as *mut nativeScorer) }, _short_channel_id); + ret +} + diff --git a/lightning-c-bindings/src/lightning/util/events.rs b/lightning-c-bindings/src/lightning/util/events.rs index 55541a5..47f4465 100644 --- a/lightning-c-bindings/src/lightning/util/events.rs +++ b/lightning-c-bindings/src/lightning/util/events.rs @@ -365,25 +365,27 @@ pub enum Event { channel_value_satoshis: u64, /// The script which should be used in the transaction output. output_script: crate::c_types::derived::CVec_u8Z, - /// The value passed in to ChannelManager::create_channel + /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or 0 for + /// an inbound channel. + /// + /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel user_channel_id: u64, }, /// Indicates we've received money! Just gotta dig out that payment preimage and feed it to - /// ChannelManager::claim_funds to get it.... - /// Note that if the preimage is not known or the amount paid is incorrect, you should call - /// ChannelManager::fail_htlc_backwards to free up resources for this HTLC and avoid + /// [`ChannelManager::claim_funds`] to get it.... + /// Note that if the preimage is not known, you should call + /// [`ChannelManager::fail_htlc_backwards`] to free up resources for this HTLC and avoid /// network congestion. - /// The amount paid should be considered 'incorrect' when it is less than or more than twice - /// the amount expected. - /// If you fail to call either ChannelManager::claim_funds or - /// ChannelManager::fail_htlc_backwards within the HTLC's timeout, the HTLC will be + /// If you fail to call either [`ChannelManager::claim_funds`] or + /// [`ChannelManager::fail_htlc_backwards`] within the HTLC's timeout, the HTLC will be /// automatically failed. + /// + /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds + /// [`ChannelManager::fail_htlc_backwards`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards PaymentReceived { /// The hash for which the preimage should be handed to the ChannelManager. payment_hash: crate::c_types::ThirtyTwoBytes, - /// The value, in thousandths of a satoshi, that this payment is for. Note that you must - /// compare this to the expected value before accepting the payment (as otherwise you are - /// providing proof-of-payment for less than the value you expected!). + /// The value, in thousandths of a satoshi, that this payment is for. amt: u64, /// Information for claiming this received payment, based on whether the purpose of the /// payment is to pay an invoice or to send a spontaneous payment. @@ -399,6 +401,10 @@ pub enum Event { /// Note that this serves as a payment receipt, if you wish to have such a thing, you must /// store it somehow! payment_preimage: crate::c_types::ThirtyTwoBytes, + /// The hash which was given to [`ChannelManager::send_payment`]. + /// + /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + payment_hash: crate::c_types::ThirtyTwoBytes, }, /// Indicates an outbound payment we made failed. Probably some intermediary node dropped /// something. You may wish to retry with a different route. @@ -424,6 +430,11 @@ pub enum Event { all_paths_failed: bool, /// The payment path that failed. path: crate::c_types::derived::CVec_RouteHopZ, + /// The channel responsible for the failed payment path. + /// + /// If this is `Some`, then the corresponding channel should be avoided when the payment is + /// retried. May be `None` for older [`Event`] serializations. + short_channel_id: crate::c_types::derived::COption_u64Z, }, /// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a /// time in the future. @@ -469,9 +480,23 @@ pub enum Event { /// The channel_id of the channel which has been closed. Note that on-chain transactions /// resolving the channel are likely still awaiting confirmation. channel_id: crate::c_types::ThirtyTwoBytes, + /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or 0 for + /// an inbound channel. This will always be zero for objects serialized with LDK versions + /// prior to 0.0.102. + /// + /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel + user_channel_id: u64, /// The reason the channel was closed. reason: crate::lightning::util::events::ClosureReason, }, + /// Used to indicate to the user that they can abandon the funding transaction and recycle the + /// inputs for another purpose. + DiscardFunding { + /// The channel_id of the channel which has been closed. + channel_id: crate::c_types::ThirtyTwoBytes, + /// The full transaction received from the user + transaction: crate::c_types::Transaction, + }, } use lightning::util::events::Event as nativeEvent; impl Event { @@ -500,13 +525,15 @@ impl Event { purpose: purpose_nonref.into_native(), } }, - Event::PaymentSent {ref payment_preimage, } => { + Event::PaymentSent {ref payment_preimage, ref payment_hash, } => { let mut payment_preimage_nonref = (*payment_preimage).clone(); + let mut payment_hash_nonref = (*payment_hash).clone(); nativeEvent::PaymentSent { payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data), + payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data), } }, - Event::PaymentPathFailed {ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, ref path, } => { + Event::PaymentPathFailed {ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, ref path, ref short_channel_id, } => { let mut payment_hash_nonref = (*payment_hash).clone(); let mut rejected_by_dest_nonref = (*rejected_by_dest).clone(); let mut network_update_nonref = (*network_update).clone(); @@ -514,12 +541,15 @@ impl Event { let mut all_paths_failed_nonref = (*all_paths_failed).clone(); let mut path_nonref = (*path).clone(); let mut local_path_nonref = Vec::new(); for mut item in path_nonref.into_rust().drain(..) { local_path_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; + let mut short_channel_id_nonref = (*short_channel_id).clone(); + let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_some() { Some( { short_channel_id_nonref.take() }) } else { None }; nativeEvent::PaymentPathFailed { payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data), rejected_by_dest: rejected_by_dest_nonref, network_update: local_network_update_nonref, all_paths_failed: all_paths_failed_nonref, path: local_path_nonref, + short_channel_id: local_short_channel_id_nonref, } }, Event::PendingHTLCsForwardable {ref time_forwardable, } => { @@ -544,14 +574,24 @@ impl Event { claim_from_onchain_tx: claim_from_onchain_tx_nonref, } }, - Event::ChannelClosed {ref channel_id, ref reason, } => { + Event::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => { let mut channel_id_nonref = (*channel_id).clone(); + let mut user_channel_id_nonref = (*user_channel_id).clone(); let mut reason_nonref = (*reason).clone(); nativeEvent::ChannelClosed { channel_id: channel_id_nonref.data, + user_channel_id: user_channel_id_nonref, reason: reason_nonref.into_native(), } }, + Event::DiscardFunding {ref channel_id, ref transaction, } => { + let mut channel_id_nonref = (*channel_id).clone(); + let mut transaction_nonref = (*transaction).clone(); + nativeEvent::DiscardFunding { + channel_id: channel_id_nonref.data, + transaction: transaction_nonref.into_bitcoin(), + } + }, } } #[allow(unused)] @@ -572,20 +612,23 @@ impl Event { purpose: purpose.into_native(), } }, - Event::PaymentSent {mut payment_preimage, } => { + Event::PaymentSent {mut payment_preimage, mut payment_hash, } => { nativeEvent::PaymentSent { payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data), + payment_hash: ::lightning::ln::PaymentHash(payment_hash.data), } }, - Event::PaymentPathFailed {mut payment_hash, mut rejected_by_dest, mut network_update, mut all_paths_failed, mut path, } => { + Event::PaymentPathFailed {mut payment_hash, mut rejected_by_dest, mut network_update, mut all_paths_failed, mut path, mut short_channel_id, } => { let mut local_network_update = { /* network_update*/ let network_update_opt = network_update; { } if network_update_opt.is_none() { None } else { Some({ network_update_opt.take().into_native() }) } }; let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; + let mut local_short_channel_id = if short_channel_id.is_some() { Some( { short_channel_id.take() }) } else { None }; nativeEvent::PaymentPathFailed { payment_hash: ::lightning::ln::PaymentHash(payment_hash.data), rejected_by_dest: rejected_by_dest, network_update: local_network_update, all_paths_failed: all_paths_failed, path: local_path, + short_channel_id: local_short_channel_id, } }, Event::PendingHTLCsForwardable {mut time_forwardable, } => { @@ -606,12 +649,19 @@ impl Event { claim_from_onchain_tx: claim_from_onchain_tx, } }, - Event::ChannelClosed {mut channel_id, mut reason, } => { + Event::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => { nativeEvent::ChannelClosed { channel_id: channel_id.data, + user_channel_id: user_channel_id, reason: reason.into_native(), } }, + Event::DiscardFunding {mut channel_id, mut transaction, } => { + nativeEvent::DiscardFunding { + channel_id: channel_id.data, + transaction: transaction.into_bitcoin(), + } + }, } } #[allow(unused)] @@ -639,13 +689,15 @@ impl Event { purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose_nonref), } }, - nativeEvent::PaymentSent {ref payment_preimage, } => { + nativeEvent::PaymentSent {ref payment_preimage, ref payment_hash, } => { let mut payment_preimage_nonref = (*payment_preimage).clone(); + let mut payment_hash_nonref = (*payment_hash).clone(); Event::PaymentSent { payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 }, + payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 }, } }, - nativeEvent::PaymentPathFailed {ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, ref path, } => { + nativeEvent::PaymentPathFailed {ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, ref path, ref short_channel_id, } => { let mut payment_hash_nonref = (*payment_hash).clone(); let mut rejected_by_dest_nonref = (*rejected_by_dest).clone(); let mut network_update_nonref = (*network_update).clone(); @@ -653,12 +705,15 @@ impl Event { let mut all_paths_failed_nonref = (*all_paths_failed).clone(); let mut path_nonref = (*path).clone(); let mut local_path_nonref = Vec::new(); for mut item in path_nonref.drain(..) { local_path_nonref.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); }; + let mut short_channel_id_nonref = (*short_channel_id).clone(); + let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { short_channel_id_nonref.unwrap() }) }; Event::PaymentPathFailed { payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 }, rejected_by_dest: rejected_by_dest_nonref, network_update: local_network_update_nonref, all_paths_failed: all_paths_failed_nonref, path: local_path_nonref.into(), + short_channel_id: local_short_channel_id_nonref, } }, nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => { @@ -683,14 +738,24 @@ impl Event { claim_from_onchain_tx: claim_from_onchain_tx_nonref, } }, - nativeEvent::ChannelClosed {ref channel_id, ref reason, } => { + nativeEvent::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => { let mut channel_id_nonref = (*channel_id).clone(); + let mut user_channel_id_nonref = (*user_channel_id).clone(); let mut reason_nonref = (*reason).clone(); Event::ChannelClosed { channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref }, + user_channel_id: user_channel_id_nonref, reason: crate::lightning::util::events::ClosureReason::native_into(reason_nonref), } }, + nativeEvent::DiscardFunding {ref channel_id, ref transaction, } => { + let mut channel_id_nonref = (*channel_id).clone(); + let mut transaction_nonref = (*transaction).clone(); + Event::DiscardFunding { + channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref }, + transaction: crate::c_types::Transaction::from_bitcoin(&transaction_nonref), + } + }, } } #[allow(unused)] @@ -711,20 +776,23 @@ impl Event { purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose), } }, - nativeEvent::PaymentSent {mut payment_preimage, } => { + nativeEvent::PaymentSent {mut payment_preimage, mut payment_hash, } => { Event::PaymentSent { payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 }, + payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 }, } }, - nativeEvent::PaymentPathFailed {mut payment_hash, mut rejected_by_dest, mut network_update, mut all_paths_failed, mut path, } => { + nativeEvent::PaymentPathFailed {mut payment_hash, mut rejected_by_dest, mut network_update, mut all_paths_failed, mut path, mut short_channel_id, } => { let mut local_network_update = if network_update.is_none() { crate::c_types::derived::COption_NetworkUpdateZ::None } else { crate::c_types::derived::COption_NetworkUpdateZ::Some( { crate::lightning::routing::network_graph::NetworkUpdate::native_into(network_update.unwrap()) }) }; let mut local_path = Vec::new(); for mut item in path.drain(..) { local_path.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); }; + let mut local_short_channel_id = if short_channel_id.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { short_channel_id.unwrap() }) }; Event::PaymentPathFailed { payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 }, rejected_by_dest: rejected_by_dest, network_update: local_network_update, all_paths_failed: all_paths_failed, path: local_path.into(), + short_channel_id: local_short_channel_id, } }, nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => { @@ -745,12 +813,19 @@ impl Event { claim_from_onchain_tx: claim_from_onchain_tx, } }, - nativeEvent::ChannelClosed {mut channel_id, mut reason, } => { + nativeEvent::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => { Event::ChannelClosed { channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id }, + user_channel_id: user_channel_id, reason: crate::lightning::util::events::ClosureReason::native_into(reason), } }, + nativeEvent::DiscardFunding {mut channel_id, mut transaction, } => { + Event::DiscardFunding { + channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id }, + transaction: crate::c_types::Transaction::from_bitcoin(&transaction), + } + }, } } } @@ -783,20 +858,22 @@ pub extern "C" fn Event_payment_received(payment_hash: crate::c_types::ThirtyTwo } #[no_mangle] /// Utility method to constructs a new PaymentSent-variant Event -pub extern "C" fn Event_payment_sent(payment_preimage: crate::c_types::ThirtyTwoBytes) -> Event { +pub extern "C" fn Event_payment_sent(payment_preimage: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes) -> Event { Event::PaymentSent { payment_preimage, + payment_hash, } } #[no_mangle] /// Utility method to constructs a new PaymentPathFailed-variant Event -pub extern "C" fn Event_payment_path_failed(payment_hash: crate::c_types::ThirtyTwoBytes, rejected_by_dest: bool, network_update: crate::c_types::derived::COption_NetworkUpdateZ, all_paths_failed: bool, path: crate::c_types::derived::CVec_RouteHopZ) -> Event { +pub extern "C" fn Event_payment_path_failed(payment_hash: crate::c_types::ThirtyTwoBytes, rejected_by_dest: bool, network_update: crate::c_types::derived::COption_NetworkUpdateZ, all_paths_failed: bool, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: crate::c_types::derived::COption_u64Z) -> Event { Event::PaymentPathFailed { payment_hash, rejected_by_dest, network_update, all_paths_failed, path, + short_channel_id, } } #[no_mangle] @@ -823,13 +900,22 @@ pub extern "C" fn Event_payment_forwarded(fee_earned_msat: crate::c_types::deriv } #[no_mangle] /// Utility method to constructs a new ChannelClosed-variant Event -pub extern "C" fn Event_channel_closed(channel_id: crate::c_types::ThirtyTwoBytes, reason: crate::lightning::util::events::ClosureReason) -> Event { +pub extern "C" fn Event_channel_closed(channel_id: crate::c_types::ThirtyTwoBytes, user_channel_id: u64, reason: crate::lightning::util::events::ClosureReason) -> Event { Event::ChannelClosed { channel_id, + user_channel_id, reason, } } #[no_mangle] +/// Utility method to constructs a new DiscardFunding-variant Event +pub extern "C" fn Event_discard_funding(channel_id: crate::c_types::ThirtyTwoBytes, transaction: crate::c_types::Transaction) -> Event { + Event::DiscardFunding { + channel_id, + transaction, + } +} +#[no_mangle] /// Serialize the Event object into a byte array which can be read by Event_read pub extern "C" fn Event_write(obj: &Event) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) diff --git a/lightning-c-bindings/src/lightning_persister.rs b/lightning-c-bindings/src/lightning_persister.rs index a93e915..c0cd08a 100644 --- a/lightning-c-bindings/src/lightning_persister.rs +++ b/lightning-c-bindings/src/lightning_persister.rs @@ -121,7 +121,7 @@ pub extern "C" fn FilesystemPersister_read_channelmonitors(this_arg: &Filesystem local_ret } -impl From for crate::lightning::chain::channelmonitor::Persist { +impl From for crate::lightning::chain::chainmonitor::Persist { fn from(obj: nativeFilesystemPersister) -> Self { let mut rust_obj = FilesystemPersister { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = FilesystemPersister_as_Persist(&rust_obj); @@ -134,8 +134,8 @@ impl From for crate::lightning::chain::channelmonitor /// Constructs a new Persist which calls the relevant methods on this_arg. /// This copies the `inner` pointer in this_arg and thus the returned Persist must be freed before this_arg is #[no_mangle] -pub extern "C" fn FilesystemPersister_as_Persist(this_arg: &FilesystemPersister) -> crate::lightning::chain::channelmonitor::Persist { - crate::lightning::chain::channelmonitor::Persist { +pub extern "C" fn FilesystemPersister_as_Persist(this_arg: &FilesystemPersister) -> crate::lightning::chain::chainmonitor::Persist { + crate::lightning::chain::chainmonitor::Persist { this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, free: None, persist_new_channel: FilesystemPersister_Persist_persist_new_channel, @@ -145,14 +145,14 @@ pub extern "C" fn FilesystemPersister_as_Persist(this_arg: &FilesystemPersister) #[must_use] extern "C" fn FilesystemPersister_Persist_persist_new_channel(this_arg: *const c_void, mut funding_txo: crate::lightning::chain::transaction::OutPoint, monitor: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ { - let mut ret = >::persist_new_channel(unsafe { &mut *(this_arg as *mut nativeFilesystemPersister) }, *unsafe { Box::from_raw(funding_txo.take_inner()) }, monitor.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::chain::channelmonitor::ChannelMonitorUpdateErr::native_into(e) }).into() }; + let mut ret = >::persist_new_channel(unsafe { &mut *(this_arg as *mut nativeFilesystemPersister) }, *unsafe { Box::from_raw(funding_txo.take_inner()) }, monitor.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::chain::ChannelMonitorUpdateErr::native_into(e) }).into() }; local_ret } #[must_use] extern "C" fn FilesystemPersister_Persist_update_persisted_channel(this_arg: *const c_void, mut funding_txo: crate::lightning::chain::transaction::OutPoint, _update: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate, monitor: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ { - let mut ret = >::update_persisted_channel(unsafe { &mut *(this_arg as *mut nativeFilesystemPersister) }, *unsafe { Box::from_raw(funding_txo.take_inner()) }, _update.get_native_ref(), monitor.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::chain::channelmonitor::ChannelMonitorUpdateErr::native_into(e) }).into() }; + let mut ret = >::update_persisted_channel(unsafe { &mut *(this_arg as *mut nativeFilesystemPersister) }, *unsafe { Box::from_raw(funding_txo.take_inner()) }, _update.get_native_ref(), monitor.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::chain::ChannelMonitorUpdateErr::native_into(e) }).into() }; local_ret }