From 23b946be5cf633afdba94e12fd71380cafdf49be Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sat, 18 Dec 2021 03:31:43 +0000 Subject: [PATCH] Update auto-generated bindings --- lightning-c-bindings/include/ldk_rust_types.h | 16 +- lightning-c-bindings/include/lightning.h | 1538 ++++++++++++----- lightning-c-bindings/include/lightningpp.hpp | 656 ++++--- lightning-c-bindings/src/c_types/derived.rs | 917 +++++++--- .../src/lightning/chain/chaininterface.rs | 10 +- .../src/lightning/chain/channelmonitor.rs | 95 +- .../src/lightning/chain/keysinterface.rs | 25 + .../src/lightning/ln/chan_utils.rs | 96 +- .../src/lightning/ln/channelmanager.rs | 187 +- .../src/lightning/ln/features.rs | 171 +- lightning-c-bindings/src/lightning/ln/msgs.rs | 92 +- .../src/lightning/ln/script.rs | 19 + .../src/lightning/routing/mod.rs | 146 +- .../src/lightning/routing/network_graph.rs | 39 +- .../src/lightning/routing/router.rs | 2 +- .../src/lightning/routing/scorer.rs | 331 ---- .../src/lightning/routing/scoring.rs | 598 +++++++ .../src/lightning/util/config.rs | 16 +- .../src/lightning/util/events.rs | 216 ++- .../src/lightning/util/logger.rs | 10 + .../src/lightning_background_processor.rs | 4 +- .../src/lightning_invoice/mod.rs | 10 + .../src/lightning_invoice/payment.rs | 96 +- .../src/lightning_invoice/utils.rs | 15 +- 24 files changed, 3625 insertions(+), 1680 deletions(-) delete mode 100644 lightning-c-bindings/src/lightning/routing/scorer.rs create mode 100644 lightning-c-bindings/src/lightning/routing/scoring.rs diff --git a/lightning-c-bindings/include/ldk_rust_types.h b/lightning-c-bindings/include/ldk_rust_types.h index bbd06e6..7ef9dd9 100644 --- a/lightning-c-bindings/include/ldk_rust_types.h +++ b/lightning-c-bindings/include/ldk_rust_types.h @@ -56,8 +56,12 @@ struct nativeBestBlockOpaque; typedef struct nativeBestBlockOpaque LDKnativeBestBlock; struct nativeWatchedOutputOpaque; typedef struct nativeWatchedOutputOpaque LDKnativeWatchedOutput; -struct nativeLockableScoreOpaque; -typedef struct nativeLockableScoreOpaque LDKnativeLockableScore; +struct nativeMultiThreadedLockableScoreOpaque; +typedef struct nativeMultiThreadedLockableScoreOpaque LDKnativeMultiThreadedLockableScore; +struct nativeScorerOpaque; +typedef struct nativeScorerOpaque LDKnativeScorer; +struct nativeScoringParametersOpaque; +typedef struct nativeScoringParametersOpaque LDKnativeScoringParameters; struct nativeInitFeaturesOpaque; typedef struct nativeInitFeaturesOpaque LDKnativeInitFeatures; struct nativeNodeFeaturesOpaque; @@ -66,10 +70,8 @@ struct nativeChannelFeaturesOpaque; typedef struct nativeChannelFeaturesOpaque LDKnativeChannelFeatures; struct nativeInvoiceFeaturesOpaque; typedef struct nativeInvoiceFeaturesOpaque LDKnativeInvoiceFeatures; -struct nativeScorerOpaque; -typedef struct nativeScorerOpaque LDKnativeScorer; -struct nativeScoringParametersOpaque; -typedef struct nativeScoringParametersOpaque LDKnativeScoringParameters; +struct nativeChannelTypeFeaturesOpaque; +typedef struct nativeChannelTypeFeaturesOpaque LDKnativeChannelTypeFeatures; struct nativeDelayedPaymentOutputDescriptorOpaque; typedef struct nativeDelayedPaymentOutputDescriptorOpaque LDKnativeDelayedPaymentOutputDescriptor; struct nativeStaticPaymentOutputDescriptorOpaque; @@ -133,8 +135,6 @@ struct nativePrivateRouteOpaque; typedef struct nativePrivateRouteOpaque LDKnativePrivateRoute; struct nativeChannelMonitorUpdateOpaque; typedef struct nativeChannelMonitorUpdateOpaque LDKnativeChannelMonitorUpdate; -struct nativeMonitorUpdateErrorOpaque; -typedef struct nativeMonitorUpdateErrorOpaque LDKnativeMonitorUpdateError; struct nativeHTLCUpdateOpaque; typedef struct nativeHTLCUpdateOpaque LDKnativeHTLCUpdate; struct nativeChannelMonitorOpaque; diff --git a/lightning-c-bindings/include/lightning.h b/lightning-c-bindings/include/lightning.h index 090c0ee..7c5d88d 100644 --- a/lightning-c-bindings/include/lightning.h +++ b/lightning-c-bindings/include/lightning.h @@ -28,6 +28,24 @@ typedef enum LDKAccessError { LDKAccessError_Sentinel, } LDKAccessError; +/** + * An enum which can either contain a or not + */ +typedef enum LDKCOption_NoneZ { + /** + * When we're in this state, this COption_NoneZ contains a + */ + LDKCOption_NoneZ_Some, + /** + * When we're in this state, this COption_NoneZ contains nothing + */ + LDKCOption_NoneZ_None, + /** + * Must be last for serialization purposes + */ + LDKCOption_NoneZ_Sentinel, +} LDKCOption_NoneZ; + /** * An error enum representing a failure to persist a channel monitor update. */ @@ -145,6 +163,10 @@ typedef enum LDKCreationError { * The supplied expiry time could cause an overflow if added to a `PositiveTimestamp` */ LDKCreationError_ExpiryTimeOutOfBounds, + /** + * The supplied millisatoshi amount was greater than the total bitcoin supply. + */ + LDKCreationError_InvalidAmount, /** * Must be last for serialization purposes */ @@ -213,6 +235,10 @@ typedef enum LDKIOError { * An enum representing the available verbosity levels of the logger. */ typedef enum LDKLevel { + /** + * Designates extremely verbose information, including gossip-induced messages + */ + LDKLevel_Gossip, /** * Designates very low priority, often extremely verbose, information */ @@ -2199,6 +2225,10 @@ typedef enum LDKClosureReason_Tag { * a copy of our own `ChannelMonitor`. */ LDKClosureReason_CommitmentTxConfirmed, + /** + * The funding transaction failed to confirm in a timely manner on an inbound channel. + */ + LDKClosureReason_FundingTimedOut, /** * Closure generated from processing an event, likely a HTLC forward/relay/reception. */ @@ -2613,17 +2643,6 @@ typedef struct LDKPaymentPurpose_LDKInvoicePayment_Body { * [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash */ struct LDKThirtyTwoBytes payment_secret; - /** - * This is the `user_payment_id` which was provided to - * [`ChannelManager::create_inbound_payment_for_hash`] or - * [`ChannelManager::create_inbound_payment`]. It has no meaning inside of LDK and is - * simply copied here. It may be used to correlate PaymentReceived events with invoice - * metadata stored elsewhere. - * - * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment - * [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash - */ - uint64_t user_payment_id; } LDKPaymentPurpose_LDKInvoicePayment_Body; typedef struct MUST_USE_STRUCT LDKPaymentPurpose { @@ -2646,10 +2665,13 @@ typedef struct MUST_USE_STRUCT LDKPaymentPurpose { typedef enum LDKEvent_Tag { /** * Used to indicate that the client should generate a funding transaction with the given - * parameters and then call ChannelManager::funding_transaction_generated. - * Generated in ChannelManager message handling. + * parameters and then call [`ChannelManager::funding_transaction_generated`]. + * Generated in [`ChannelManager`] message handling. * Note that *all inputs* in the funding transaction must spend SegWit outputs or your * counterparty can steal your funds! + * + * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager + * [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated */ LDKEvent_FundingGenerationReady, /** @@ -2662,6 +2684,10 @@ typedef enum LDKEvent_Tag { * [`ChannelManager::fail_htlc_backwards`] within the HTLC's timeout, the HTLC will be * automatically failed. * + * # Note + * LDK will not stop an inbound payment from being paid multiple times, so multiple + * `PaymentReceived` events may be generated for the same payment. + * * [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds * [`ChannelManager::fail_htlc_backwards`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards */ @@ -2675,13 +2701,31 @@ typedef enum LDKEvent_Tag { */ LDKEvent_PaymentSent, /** - * Indicates an outbound payment we made failed. Probably some intermediary node dropped + * Indicates an outbound HTLC we sent failed. Probably some intermediary node dropped * something. You may wish to retry with a different route. + * + * Note that this does *not* indicate that all paths for an MPP payment have failed, see + * [`Event::PaymentFailed`] and [`all_paths_failed`]. + * + * [`all_paths_failed`]: Self::all_paths_failed */ LDKEvent_PaymentPathFailed, /** - * Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a - * time in the future. + * Indicates an outbound payment failed. Individual [`Event::PaymentPathFailed`] events + * provide failure information for each MPP part in the payment. + * + * This event is provided once there are no further pending HTLCs for the payment and the + * payment is no longer retryable, either due to a several-block timeout or because + * [`ChannelManager::abandon_payment`] was previously called for the corresponding payment. + * + * [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment + */ + LDKEvent_PaymentFailed, + /** + * Used to indicate that [`ChannelManager::process_pending_htlc_forwards`] should be called at + * a time in the future. + * + * [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards */ LDKEvent_PendingHTLCsForwardable, /** @@ -2706,6 +2750,13 @@ typedef enum LDKEvent_Tag { * inputs for another purpose. */ LDKEvent_DiscardFunding, + /** + * Indicates that a path for an outbound payment was successful. + * + * Always generated after [`Event::PaymentSent`] and thus useful for scoring channels. See + * [`Event::PaymentSent`] for obtaining the payment preimage. + */ + LDKEvent_PaymentPathSuccessful, /** * Must be last for serialization purposes */ @@ -2737,7 +2788,8 @@ typedef struct LDKEvent_LDKFundingGenerationReady_Body { typedef struct LDKEvent_LDKPaymentReceived_Body { /** - * The hash for which the preimage should be handed to the ChannelManager. + * The hash for which the preimage should be handed to the ChannelManager. Note that LDK will + * not stop you from registering duplicate payment hashes for inbound payments. */ struct LDKThirtyTwoBytes payment_hash; /** @@ -2769,7 +2821,7 @@ typedef struct LDKEvent_LDKPaymentSent_Body { */ struct LDKThirtyTwoBytes payment_preimage; /** - * The hash which was given to [`ChannelManager::send_payment`]. + * The hash that was given to [`ChannelManager::send_payment`]. * * [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment */ @@ -2791,16 +2843,19 @@ typedef struct LDKEvent_LDKPaymentSent_Body { typedef struct LDKEvent_LDKPaymentPathFailed_Body { /** * The id returned by [`ChannelManager::send_payment`] and used with - * [`ChannelManager::retry_payment`]. + * [`ChannelManager::retry_payment`] and [`ChannelManager::abandon_payment`]. * * [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment * [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment + * [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment * * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None */ struct LDKThirtyTwoBytes payment_id; /** - * The hash which was given to ChannelManager::send_payment. + * The hash that was given to [`ChannelManager::send_payment`]. + * + * [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment */ struct LDKThirtyTwoBytes payment_hash; /** @@ -2824,6 +2879,20 @@ typedef struct LDKEvent_LDKPaymentPathFailed_Body { * For both single-path and multi-path payments, this is set if all paths of the payment have * failed. This will be set to false if (1) this is an MPP payment and (2) other parts of the * larger MPP payment were still in flight when this event was generated. + * + * Note that if you are retrying individual MPP parts, using this value to determine if a + * payment has fully failed is race-y. Because multiple failures can happen prior to events + * being processed, you may retry in response to a first failure, with a second failure + * (with `all_paths_failed` set) still pending. Then, when the second failure is processed + * you will see `all_paths_failed` set even though the retry of the first failure still + * has an associated in-flight HTLC. See (1) for an example of such a failure. + * + * If you wish to retry individual MPP parts and learn when a payment has failed, you must + * call [`ChannelManager::abandon_payment`] and wait for a [`Event::PaymentFailed`] event. + * + * (1) + * + * [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment */ bool all_paths_failed; /** @@ -2850,6 +2919,24 @@ typedef struct LDKEvent_LDKPaymentPathFailed_Body { struct LDKRouteParameters retry; } LDKEvent_LDKPaymentPathFailed_Body; +typedef struct LDKEvent_LDKPaymentFailed_Body { + /** + * The id returned by [`ChannelManager::send_payment`] and used with + * [`ChannelManager::retry_payment`] and [`ChannelManager::abandon_payment`]. + * + * [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + * [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment + * [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment + */ + struct LDKThirtyTwoBytes payment_id; + /** + * The hash that was given to [`ChannelManager::send_payment`]. + * + * [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + */ + struct LDKThirtyTwoBytes payment_hash; +} LDKEvent_LDKPaymentFailed_Body; + typedef struct LDKEvent_LDKPendingHTLCsForwardable_Body { /** * The minimum amount of time that should be waited prior to calling @@ -2922,6 +3009,31 @@ typedef struct LDKEvent_LDKDiscardFunding_Body { struct LDKTransaction transaction; } LDKEvent_LDKDiscardFunding_Body; +typedef struct LDKEvent_LDKPaymentPathSuccessful_Body { + /** + * The id returned by [`ChannelManager::send_payment`] and used with + * [`ChannelManager::retry_payment`]. + * + * [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + * [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment + */ + struct LDKThirtyTwoBytes payment_id; + /** + * The hash that was given to [`ChannelManager::send_payment`]. + * + * [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + * + * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None + */ + struct LDKThirtyTwoBytes payment_hash; + /** + * The payment path that was successful. + * + * May contain a closed channel if the HTLC sent along the path was fulfilled on chain. + */ + struct LDKCVec_RouteHopZ path; +} LDKEvent_LDKPaymentPathSuccessful_Body; + typedef struct MUST_USE_STRUCT LDKEvent { LDKEvent_Tag tag; union { @@ -2929,11 +3041,13 @@ typedef struct MUST_USE_STRUCT LDKEvent { LDKEvent_LDKPaymentReceived_Body payment_received; LDKEvent_LDKPaymentSent_Body payment_sent; LDKEvent_LDKPaymentPathFailed_Body payment_path_failed; + LDKEvent_LDKPaymentFailed_Body payment_failed; LDKEvent_LDKPendingHTLCsForwardable_Body pending_htl_cs_forwardable; LDKEvent_LDKSpendableOutputs_Body spendable_outputs; LDKEvent_LDKPaymentForwarded_Body payment_forwarded; LDKEvent_LDKChannelClosed_Body channel_closed; LDKEvent_LDKDiscardFunding_Body discard_funding; + LDKEvent_LDKPaymentPathSuccessful_Body payment_path_successful; }; } LDKEvent; @@ -3295,6 +3409,12 @@ typedef enum LDKErrorAction_Tag { * If the error is logged, log it at the given level. */ LDKErrorAction_IgnoreAndLog, + /** + * The peer provided us with a gossip message which we'd already seen. In most cases this + * should be ignored, but it may result in the message being forwarded if it is a duplicate of + * our own channel announcements. + */ + LDKErrorAction_IgnoreDuplicateGossip, /** * The peer did something incorrect. Tell them. */ @@ -3755,327 +3875,389 @@ typedef struct LDKCVec_MessageSendEventZ { /** - * Features used within an `init` message. + * Parameters for configuring [`Scorer`]. */ -typedef struct MUST_USE_STRUCT LDKInitFeatures { +typedef struct MUST_USE_STRUCT LDKScoringParameters { /** * 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. */ - LDKnativeInitFeatures *inner; + LDKnativeScoringParameters *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; -} LDKInitFeatures; +} LDKScoringParameters; /** - * The contents of CResult_InitFeaturesDecodeErrorZ + * The contents of CResult_ScoringParametersDecodeErrorZ */ -typedef union LDKCResult_InitFeaturesDecodeErrorZPtr { +typedef union LDKCResult_ScoringParametersDecodeErrorZPtr { /** * A pointer to the contents in the success state. * Reading from this pointer when `result_ok` is not set is undefined. */ - struct LDKInitFeatures *result; + struct LDKScoringParameters *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_InitFeaturesDecodeErrorZPtr; +} LDKCResult_ScoringParametersDecodeErrorZPtr; /** - * A CResult_InitFeaturesDecodeErrorZ represents the result of a fallible operation, - * containing a crate::lightning::ln::features::InitFeatures on success and a crate::lightning::ln::msgs::DecodeError on failure. + * A CResult_ScoringParametersDecodeErrorZ represents the result of a fallible operation, + * containing a crate::lightning::routing::scoring::ScoringParameters 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_InitFeaturesDecodeErrorZ { +typedef struct LDKCResult_ScoringParametersDecodeErrorZ { /** - * The contents of this CResult_InitFeaturesDecodeErrorZ, accessible via either + * The contents of this CResult_ScoringParametersDecodeErrorZ, accessible via either * `err` or `result` depending on the state of `result_ok`. */ - union LDKCResult_InitFeaturesDecodeErrorZPtr contents; + union LDKCResult_ScoringParametersDecodeErrorZPtr contents; /** - * Whether this CResult_InitFeaturesDecodeErrorZ represents a success state. + * Whether this CResult_ScoringParametersDecodeErrorZ represents a success state. */ bool result_ok; -} LDKCResult_InitFeaturesDecodeErrorZ; +} LDKCResult_ScoringParametersDecodeErrorZ; /** - * Features used within a `node_announcement` message. + * [`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. Will further penalize channels that fail to relay payments. + * + * See [module-level documentation] for usage. + * + * [module-level documentation]: crate::routing::scoring */ -typedef struct MUST_USE_STRUCT LDKNodeFeatures { +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. */ - LDKnativeNodeFeatures *inner; + 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; -} LDKNodeFeatures; +} LDKScorer; /** - * The contents of CResult_NodeFeaturesDecodeErrorZ + * The contents of CResult_ScorerDecodeErrorZ */ -typedef union LDKCResult_NodeFeaturesDecodeErrorZPtr { +typedef union LDKCResult_ScorerDecodeErrorZPtr { /** * A pointer to the contents in the success state. * Reading from this pointer when `result_ok` is not set is undefined. */ - struct LDKNodeFeatures *result; + struct LDKScorer *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_NodeFeaturesDecodeErrorZPtr; +} LDKCResult_ScorerDecodeErrorZPtr; /** - * A CResult_NodeFeaturesDecodeErrorZ represents the result of a fallible operation, - * containing a crate::lightning::ln::features::NodeFeatures on success and a crate::lightning::ln::msgs::DecodeError on failure. + * A CResult_ScorerDecodeErrorZ represents the result of a fallible operation, + * containing a crate::lightning::routing::scoring::Scorer 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_NodeFeaturesDecodeErrorZ { +typedef struct LDKCResult_ScorerDecodeErrorZ { /** - * The contents of this CResult_NodeFeaturesDecodeErrorZ, accessible via either + * The contents of this CResult_ScorerDecodeErrorZ, accessible via either * `err` or `result` depending on the state of `result_ok`. */ - union LDKCResult_NodeFeaturesDecodeErrorZPtr contents; + union LDKCResult_ScorerDecodeErrorZPtr contents; /** - * Whether this CResult_NodeFeaturesDecodeErrorZ represents a success state. + * Whether this CResult_ScorerDecodeErrorZ represents a success state. */ bool result_ok; -} LDKCResult_NodeFeaturesDecodeErrorZ; +} LDKCResult_ScorerDecodeErrorZ; /** - * Features used within a `channel_announcement` message. + * Features used within an `init` message. */ -typedef struct MUST_USE_STRUCT LDKChannelFeatures { +typedef struct MUST_USE_STRUCT LDKInitFeatures { /** * 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. */ - LDKnativeChannelFeatures *inner; + LDKnativeInitFeatures *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; -} LDKChannelFeatures; +} LDKInitFeatures; /** - * The contents of CResult_ChannelFeaturesDecodeErrorZ + * The contents of CResult_InitFeaturesDecodeErrorZ */ -typedef union LDKCResult_ChannelFeaturesDecodeErrorZPtr { +typedef union LDKCResult_InitFeaturesDecodeErrorZPtr { /** * A pointer to the contents in the success state. * Reading from this pointer when `result_ok` is not set is undefined. */ - struct LDKChannelFeatures *result; + struct LDKInitFeatures *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_ChannelFeaturesDecodeErrorZPtr; +} LDKCResult_InitFeaturesDecodeErrorZPtr; /** - * A CResult_ChannelFeaturesDecodeErrorZ represents the result of a fallible operation, - * containing a crate::lightning::ln::features::ChannelFeatures on success and a crate::lightning::ln::msgs::DecodeError on failure. + * A CResult_InitFeaturesDecodeErrorZ represents the result of a fallible operation, + * containing a crate::lightning::ln::features::InitFeatures 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_ChannelFeaturesDecodeErrorZ { +typedef struct LDKCResult_InitFeaturesDecodeErrorZ { /** - * The contents of this CResult_ChannelFeaturesDecodeErrorZ, accessible via either + * The contents of this CResult_InitFeaturesDecodeErrorZ, accessible via either * `err` or `result` depending on the state of `result_ok`. */ - union LDKCResult_ChannelFeaturesDecodeErrorZPtr contents; + union LDKCResult_InitFeaturesDecodeErrorZPtr contents; /** - * Whether this CResult_ChannelFeaturesDecodeErrorZ represents a success state. + * Whether this CResult_InitFeaturesDecodeErrorZ represents a success state. */ bool result_ok; -} LDKCResult_ChannelFeaturesDecodeErrorZ; +} LDKCResult_InitFeaturesDecodeErrorZ; /** - * Features used within an invoice. + * Features used within a `channel_announcement` message. */ -typedef struct MUST_USE_STRUCT LDKInvoiceFeatures { +typedef struct MUST_USE_STRUCT LDKChannelFeatures { /** * 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. */ - LDKnativeInvoiceFeatures *inner; + LDKnativeChannelFeatures *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; -} LDKInvoiceFeatures; +} LDKChannelFeatures; /** - * The contents of CResult_InvoiceFeaturesDecodeErrorZ + * The contents of CResult_ChannelFeaturesDecodeErrorZ */ -typedef union LDKCResult_InvoiceFeaturesDecodeErrorZPtr { +typedef union LDKCResult_ChannelFeaturesDecodeErrorZPtr { /** * A pointer to the contents in the success state. * Reading from this pointer when `result_ok` is not set is undefined. */ - struct LDKInvoiceFeatures *result; + struct LDKChannelFeatures *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_InvoiceFeaturesDecodeErrorZPtr; +} LDKCResult_ChannelFeaturesDecodeErrorZPtr; /** - * A CResult_InvoiceFeaturesDecodeErrorZ represents the result of a fallible operation, - * containing a crate::lightning::ln::features::InvoiceFeatures on success and a crate::lightning::ln::msgs::DecodeError on failure. + * A CResult_ChannelFeaturesDecodeErrorZ represents the result of a fallible operation, + * containing a crate::lightning::ln::features::ChannelFeatures 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_InvoiceFeaturesDecodeErrorZ { +typedef struct LDKCResult_ChannelFeaturesDecodeErrorZ { /** - * The contents of this CResult_InvoiceFeaturesDecodeErrorZ, accessible via either + * The contents of this CResult_ChannelFeaturesDecodeErrorZ, accessible via either * `err` or `result` depending on the state of `result_ok`. */ - union LDKCResult_InvoiceFeaturesDecodeErrorZPtr contents; + union LDKCResult_ChannelFeaturesDecodeErrorZPtr contents; /** - * Whether this CResult_InvoiceFeaturesDecodeErrorZ represents a success state. + * Whether this CResult_ChannelFeaturesDecodeErrorZ represents a success state. */ bool result_ok; -} LDKCResult_InvoiceFeaturesDecodeErrorZ; +} LDKCResult_ChannelFeaturesDecodeErrorZ; /** - * Parameters for configuring [`Scorer`]. + * Features used within a `node_announcement` message. */ -typedef struct MUST_USE_STRUCT LDKScoringParameters { +typedef struct MUST_USE_STRUCT LDKNodeFeatures { /** * 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. */ - LDKnativeScoringParameters *inner; + LDKnativeNodeFeatures *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; -} LDKScoringParameters; +} LDKNodeFeatures; /** - * The contents of CResult_ScoringParametersDecodeErrorZ + * The contents of CResult_NodeFeaturesDecodeErrorZ */ -typedef union LDKCResult_ScoringParametersDecodeErrorZPtr { +typedef union LDKCResult_NodeFeaturesDecodeErrorZPtr { /** * A pointer to the contents in the success state. * Reading from this pointer when `result_ok` is not set is undefined. */ - struct LDKScoringParameters *result; + struct LDKNodeFeatures *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_ScoringParametersDecodeErrorZPtr; +} LDKCResult_NodeFeaturesDecodeErrorZPtr; /** - * A CResult_ScoringParametersDecodeErrorZ represents the result of a fallible operation, - * containing a crate::lightning::routing::scorer::ScoringParameters on success and a crate::lightning::ln::msgs::DecodeError on failure. + * A CResult_NodeFeaturesDecodeErrorZ represents the result of a fallible operation, + * containing a crate::lightning::ln::features::NodeFeatures 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_ScoringParametersDecodeErrorZ { +typedef struct LDKCResult_NodeFeaturesDecodeErrorZ { /** - * The contents of this CResult_ScoringParametersDecodeErrorZ, accessible via either + * The contents of this CResult_NodeFeaturesDecodeErrorZ, accessible via either * `err` or `result` depending on the state of `result_ok`. */ - union LDKCResult_ScoringParametersDecodeErrorZPtr contents; + union LDKCResult_NodeFeaturesDecodeErrorZPtr contents; /** - * Whether this CResult_ScoringParametersDecodeErrorZ represents a success state. + * Whether this CResult_NodeFeaturesDecodeErrorZ represents a success state. */ bool result_ok; -} LDKCResult_ScoringParametersDecodeErrorZ; +} LDKCResult_NodeFeaturesDecodeErrorZ; /** - * [`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. Will further penalize channels that fail to relay payments. - * - * See [module-level documentation] for usage. - * - * [module-level documentation]: crate::routing::scorer + * Features used within an invoice. */ -typedef struct MUST_USE_STRUCT LDKScorer { +typedef struct MUST_USE_STRUCT LDKInvoiceFeatures { /** * 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; + LDKnativeInvoiceFeatures *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; +} LDKInvoiceFeatures; /** - * The contents of CResult_ScorerDecodeErrorZ + * The contents of CResult_InvoiceFeaturesDecodeErrorZ */ -typedef union LDKCResult_ScorerDecodeErrorZPtr { +typedef union LDKCResult_InvoiceFeaturesDecodeErrorZPtr { /** * A pointer to the contents in the success state. * Reading from this pointer when `result_ok` is not set is undefined. */ - struct LDKScorer *result; + struct LDKInvoiceFeatures *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_ScorerDecodeErrorZPtr; +} LDKCResult_InvoiceFeaturesDecodeErrorZPtr; /** - * A CResult_ScorerDecodeErrorZ represents the result of a fallible operation, - * containing a crate::lightning::routing::scorer::Scorer on success and a crate::lightning::ln::msgs::DecodeError on failure. + * A CResult_InvoiceFeaturesDecodeErrorZ represents the result of a fallible operation, + * containing a crate::lightning::ln::features::InvoiceFeatures 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_ScorerDecodeErrorZ { +typedef struct LDKCResult_InvoiceFeaturesDecodeErrorZ { /** - * The contents of this CResult_ScorerDecodeErrorZ, accessible via either + * The contents of this CResult_InvoiceFeaturesDecodeErrorZ, accessible via either * `err` or `result` depending on the state of `result_ok`. */ - union LDKCResult_ScorerDecodeErrorZPtr contents; + union LDKCResult_InvoiceFeaturesDecodeErrorZPtr contents; /** - * Whether this CResult_ScorerDecodeErrorZ represents a success state. + * Whether this CResult_InvoiceFeaturesDecodeErrorZ represents a success state. */ bool result_ok; -} LDKCResult_ScorerDecodeErrorZ; +} LDKCResult_InvoiceFeaturesDecodeErrorZ; + + + +/** + * Features used within the channel_type field in an OpenChannel message. + * + * A channel is always of some known \"type\", describing the transaction formats used and the exact + * semantics of our interaction with our peer. + * + * Note that because a channel is a specific type which is proposed by the opener and accepted by + * the counterparty, only required features are allowed here. + * + * This is serialized differently from other feature types - it is not prefixed by a length, and + * thus must only appear inside a TLV where its length is known in advance. + */ +typedef struct MUST_USE_STRUCT LDKChannelTypeFeatures { + /** + * 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. + */ + LDKnativeChannelTypeFeatures *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; +} LDKChannelTypeFeatures; + +/** + * The contents of CResult_ChannelTypeFeaturesDecodeErrorZ + */ +typedef union LDKCResult_ChannelTypeFeaturesDecodeErrorZPtr { + /** + * A pointer to the contents in the success state. + * Reading from this pointer when `result_ok` is not set is undefined. + */ + struct LDKChannelTypeFeatures *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_ChannelTypeFeaturesDecodeErrorZPtr; + +/** + * A CResult_ChannelTypeFeaturesDecodeErrorZ represents the result of a fallible operation, + * containing a crate::lightning::ln::features::ChannelTypeFeatures 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_ChannelTypeFeaturesDecodeErrorZ { + /** + * The contents of this CResult_ChannelTypeFeaturesDecodeErrorZ, accessible via either + * `err` or `result` depending on the state of `result_ok`. + */ + union LDKCResult_ChannelTypeFeaturesDecodeErrorZPtr contents; + /** + * Whether this CResult_ChannelTypeFeaturesDecodeErrorZ represents a success state. + */ + bool result_ok; +} LDKCResult_ChannelTypeFeaturesDecodeErrorZ; /** * The contents of CResult_DelayedPaymentOutputDescriptorDecodeErrorZ @@ -5320,14 +5502,14 @@ typedef struct LDKSixteenBytes { } LDKSixteenBytes; /** - * A 10-byte byte array. + * A 12-byte byte array. */ -typedef struct LDKTenBytes { +typedef struct LDKTwelveBytes { /** - * The ten bytes + * The twelve bytes */ - uint8_t data[10]; -} LDKTenBytes; + uint8_t data[12]; +} LDKTwelveBytes; /** * An address which can be used to connect to a remote peer @@ -5343,6 +5525,9 @@ typedef enum LDKNetAddress_Tag { LDKNetAddress_IPv6, /** * An old-style Tor onion address/port on which the peer is listening. + * + * This field is deprecated and the Tor network generally no longer supports V2 Onion + * addresses. Thus, the details are not parsed here. */ LDKNetAddress_OnionV2, /** @@ -5379,17 +5564,6 @@ typedef struct LDKNetAddress_LDKIPv6_Body { uint16_t port; } LDKNetAddress_LDKIPv6_Body; -typedef struct LDKNetAddress_LDKOnionV2_Body { - /** - * The bytes (usually encoded in base32 with \".onion\" appended) - */ - struct LDKTenBytes addr; - /** - * The port on which the node is listening - */ - uint16_t port; -} LDKNetAddress_LDKOnionV2_Body; - typedef struct LDKNetAddress_LDKOnionV3_Body { /** * The ed25519 long-term public key of the peer @@ -5414,7 +5588,9 @@ typedef struct MUST_USE_STRUCT LDKNetAddress { union { LDKNetAddress_LDKIPv4_Body i_pv4; LDKNetAddress_LDKIPv6_Body i_pv6; - LDKNetAddress_LDKOnionV2_Body onion_v2; + struct { + struct LDKTwelveBytes onion_v2; + }; LDKNetAddress_LDKOnionV3_Body onion_v3; }; } LDKNetAddress; @@ -5449,6 +5625,103 @@ typedef struct LDKC2Tuple_PaymentHashPaymentSecretZ { struct LDKThirtyTwoBytes b; } LDKC2Tuple_PaymentHashPaymentSecretZ; +/** + * The contents of CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ + */ +typedef union LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZPtr { + /** + * A pointer to the contents in the success state. + * Reading from this pointer when `result_ok` is not set is undefined. + */ + struct LDKC2Tuple_PaymentHashPaymentSecretZ *result; + /** + * Note that this value is always NULL, as there are no contents in the Err variant + */ + void *err; +} LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZPtr; + +/** + * A CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ represents the result of a fallible operation, + * containing a crate::c_types::derived::C2Tuple_PaymentHashPaymentSecretZ on success and a () on failure. + * `result_ok` indicates the overall state, and the contents are provided via `contents`. + */ +typedef struct LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZ { + /** + * The contents of this CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ, accessible via either + * `err` or `result` depending on the state of `result_ok`. + */ + union LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZPtr contents; + /** + * Whether this CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ represents a success state. + */ + bool result_ok; +} LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZ; + +/** + * The contents of CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ + */ +typedef union LDKCResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZPtr { + /** + * A pointer to the contents in the success state. + * Reading from this pointer when `result_ok` is not set is undefined. + */ + struct LDKC2Tuple_PaymentHashPaymentSecretZ *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_C2Tuple_PaymentHashPaymentSecretZAPIErrorZPtr; + +/** + * A CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ represents the result of a fallible operation, + * containing a crate::c_types::derived::C2Tuple_PaymentHashPaymentSecretZ 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_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ { + /** + * The contents of this CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ, accessible via either + * `err` or `result` depending on the state of `result_ok`. + */ + union LDKCResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZPtr contents; + /** + * Whether this CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ represents a success state. + */ + bool result_ok; +} LDKCResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ; + +/** + * The contents of CResult_PaymentSecretNoneZ + */ +typedef union LDKCResult_PaymentSecretNoneZPtr { + /** + * A pointer to the contents in the success state. + * Reading from this pointer when `result_ok` is not set is undefined. + */ + struct LDKThirtyTwoBytes *result; + /** + * Note that this value is always NULL, as there are no contents in the Err variant + */ + void *err; +} LDKCResult_PaymentSecretNoneZPtr; + +/** + * A CResult_PaymentSecretNoneZ represents the result of a fallible operation, + * containing a crate::c_types::ThirtyTwoBytes on success and a () on failure. + * `result_ok` indicates the overall state, and the contents are provided via `contents`. + */ +typedef struct LDKCResult_PaymentSecretNoneZ { + /** + * The contents of this CResult_PaymentSecretNoneZ, accessible via either + * `err` or `result` depending on the state of `result_ok`. + */ + union LDKCResult_PaymentSecretNoneZPtr contents; + /** + * Whether this CResult_PaymentSecretNoneZ represents a success state. + */ + bool result_ok; +} LDKCResult_PaymentSecretNoneZ; + /** * The contents of CResult_PaymentSecretAPIErrorZ */ @@ -5482,6 +5755,39 @@ typedef struct LDKCResult_PaymentSecretAPIErrorZ { bool result_ok; } LDKCResult_PaymentSecretAPIErrorZ; +/** + * The contents of CResult_PaymentPreimageAPIErrorZ + */ +typedef union LDKCResult_PaymentPreimageAPIErrorZPtr { + /** + * 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_PaymentPreimageAPIErrorZPtr; + +/** + * A CResult_PaymentPreimageAPIErrorZ 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_PaymentPreimageAPIErrorZ { + /** + * The contents of this CResult_PaymentPreimageAPIErrorZ, accessible via either + * `err` or `result` depending on the state of `result_ok`. + */ + union LDKCResult_PaymentPreimageAPIErrorZPtr contents; + /** + * Whether this CResult_PaymentPreimageAPIErrorZ represents a success state. + */ + bool result_ok; +} LDKCResult_PaymentPreimageAPIErrorZ; + /** * A dynamically-allocated array of crate::lightning::chain::channelmonitor::ChannelMonitors of arbitrary size. * This corresponds to std::vector in C++ @@ -5684,6 +5990,12 @@ typedef struct LDKKeysInterface { * blindly signing the hash. */ struct LDKCResult_RecoverableSignatureNoneZ (*sign_invoice)(const void *this_arg, struct LDKCVec_u8Z invoice_preimage); + /** + * Get secret key material as bytes for use in encrypting and decrypting inbound payment data. + * + * This method must return the same value each time it is called. + */ + struct LDKThirtyTwoBytes (*get_inbound_payment_key_material)(const void *this_arg); /** * Frees any resources associated with this object given its this_arg pointer. * Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. @@ -5707,12 +6019,12 @@ typedef struct LDKFeeEstimator { /** * Gets estimated satoshis of fee required per 1000 Weight-Units. * - * Must be no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later round-downs - * don't put us below 1 satoshi-per-byte). + * Must return a value no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later + * round-downs don't put us below 1 satoshi-per-byte). * - * This translates to: - * * satoshis-per-byte * 250 - * * ceil(satoshis-per-kbyte / 4) + * This method can be implemented with the following unit conversions: + * * max(satoshis-per-byte * 250, 253) + * * max(satoshis-per-kbyte / 4, 253) */ uint32_t (*get_est_sat_per_1000_weight)(const void *this_arg, enum LDKConfirmationTarget confirmation_target); /** @@ -6842,62 +7154,6 @@ typedef struct LDKCResult_HTLCUpdateDecodeErrorZ { bool result_ok; } LDKCResult_HTLCUpdateDecodeErrorZ; - - -/** - * General Err type for ChannelMonitor actions. Generally, this implies that the data provided is - * inconsistent with the ChannelMonitor being called. eg for ChannelMonitor::update_monitor this - * means you tried to update a monitor for a different channel or the ChannelMonitorUpdate was - * corrupted. - * Contains a developer-readable error message. - */ -typedef struct MUST_USE_STRUCT LDKMonitorUpdateError { - /** - * 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. - */ - LDKnativeMonitorUpdateError *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; -} LDKMonitorUpdateError; - -/** - * The contents of CResult_NoneMonitorUpdateErrorZ - */ -typedef union LDKCResult_NoneMonitorUpdateErrorZPtr { - /** - * Note that this value is always NULL, as there are no contents in the OK variant - */ - void *result; - /** - * A pointer to the contents in the error state. - * Reading from this pointer when `result_ok` is set is undefined. - */ - struct LDKMonitorUpdateError *err; -} LDKCResult_NoneMonitorUpdateErrorZPtr; - -/** - * A CResult_NoneMonitorUpdateErrorZ represents the result of a fallible operation, - * containing a () on success and a crate::lightning::chain::channelmonitor::MonitorUpdateError on failure. - * `result_ok` indicates the overall state, and the contents are provided via `contents`. - */ -typedef struct LDKCResult_NoneMonitorUpdateErrorZ { - /** - * The contents of this CResult_NoneMonitorUpdateErrorZ, accessible via either - * `err` or `result` depending on the state of `result_ok`. - */ - union LDKCResult_NoneMonitorUpdateErrorZPtr contents; - /** - * Whether this CResult_NoneMonitorUpdateErrorZ represents a success state. - */ - bool result_ok; -} LDKCResult_NoneMonitorUpdateErrorZ; - /** * A tuple of 2 elements. See the individual fields for the types contained. */ @@ -10738,6 +10994,53 @@ typedef struct MUST_USE_STRUCT LDKDirectedChannelTransactionParameters { bool is_owned; } LDKDirectedChannelTransactionParameters; + + +/** + * A read-only view of [`NetworkGraph`]. + */ +typedef struct MUST_USE_STRUCT LDKReadOnlyNetworkGraph { + /** + * 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. + */ + LDKnativeReadOnlyNetworkGraph *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; +} LDKReadOnlyNetworkGraph; + + + +/** + * Receives and validates network updates from peers, + * stores authentic and relevant data as a network graph. + * This network graph is then used for routing payments. + * Provides interface to help with initial routing sync by + * serving historical announcements. + * + * Serves as an [`EventHandler`] for applying updates from [`Event::PaymentPathFailed`] to the + * [`NetworkGraph`]. + */ +typedef struct MUST_USE_STRUCT LDKNetGraphMsgHandler { + /** + * 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. + */ + LDKnativeNetGraphMsgHandler *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; +} LDKNetGraphMsgHandler; + /** * An interface used to score payment channels for path finding. * @@ -10750,14 +11053,28 @@ typedef struct LDKScore { */ void *this_arg; /** - * Returns the fee in msats willing to be paid to avoid routing through the given channel - * in the direction from `source` to `target`. + * Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the + * given channel in the direction from `source` to `target`. + * + * The channel's capacity (less any other MPP parts which are also being considered for use in + * the same payment) is given by `channel_capacity_msat`. It may be guessed from various + * sources or assumed from no data at all. + * + * For hints provided in the invoice, we assume the channel has sufficient capacity to accept + * the invoice's full amount, and provide a `channel_capacity_msat` of `None`. In all other + * cases it is set to `Some`, even if we're guessing at the channel value. + * + * Your code should be overflow-safe through a `channel_capacity_msat` of 21 million BTC. */ - uint64_t (*channel_penalty_msat)(const void *this_arg, uint64_t short_channel_id, const struct LDKNodeId *NONNULL_PTR source, const struct LDKNodeId *NONNULL_PTR target); + uint64_t (*channel_penalty_msat)(const void *this_arg, uint64_t short_channel_id, uint64_t send_amt_msat, struct LDKCOption_u64Z channel_capacity_msat, const struct LDKNodeId *NONNULL_PTR source, const struct LDKNodeId *NONNULL_PTR target); /** * Handles updating channel penalties after failing to route through a channel. */ void (*payment_path_failed)(void *this_arg, struct LDKCVec_RouteHopZ path, uint64_t short_channel_id); + /** + * Handles updating channel penalties after successfully routing along a path. + */ + void (*payment_path_successful)(void *this_arg, struct LDKCVec_RouteHopZ path); /** * Serialize the object into a byte array */ @@ -10769,8 +11086,6 @@ typedef struct LDKScore { void (*free)(void *this_arg); } LDKScore; - - /** * A scorer that is accessed under a lock. * @@ -10781,67 +11096,42 @@ typedef struct LDKScore { * * [`find_route`]: crate::routing::router::find_route */ -typedef struct MUST_USE_STRUCT LDKLockableScore { +typedef struct LDKLockableScore { /** - * 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. - */ - LDKnativeLockableScore *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. + * 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. */ - bool is_owned; -} LDKLockableScore; - - - -/** - * A read-only view of [`NetworkGraph`]. - */ -typedef struct MUST_USE_STRUCT LDKReadOnlyNetworkGraph { + void *this_arg; /** - * 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. + * Returns the locked scorer. */ - LDKnativeReadOnlyNetworkGraph *inner; + struct LDKScore (*lock)(const 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. + * 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. */ - bool is_owned; -} LDKReadOnlyNetworkGraph; + void (*free)(void *this_arg); +} LDKLockableScore; /** - * Receives and validates network updates from peers, - * stores authentic and relevant data as a network graph. - * This network graph is then used for routing payments. - * Provides interface to help with initial routing sync by - * serving historical announcements. - * - * Serves as an [`EventHandler`] for applying updates from [`Event::PaymentPathFailed`] to the - * [`NetworkGraph`]. + * A concrete implementation of [`LockableScore`] which supports multi-threading. */ -typedef struct MUST_USE_STRUCT LDKNetGraphMsgHandler { +typedef struct MUST_USE_STRUCT LDKMultiThreadedLockableScore { /** * 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. */ - LDKnativeNetGraphMsgHandler *inner; + LDKnativeMultiThreadedLockableScore *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; -} LDKNetGraphMsgHandler; +} LDKMultiThreadedLockableScore; @@ -10886,6 +11176,8 @@ typedef struct MUST_USE_STRUCT LDKFilesystemPersister { * [`ChannelManager`] persistence should be done in the background. * * Calling [`ChannelManager::timer_tick_occurred`] and [`PeerManager::timer_tick_occurred`] * at the appropriate intervals. + * * Calling [`NetworkGraph::remove_stale_channels`] (if a [`NetGraphMsgHandler`] is provided to + * [`BackgroundProcessor::start`]). * * It will also call [`PeerManager::process_events`] periodically though this shouldn't be relied * upon as doing so may result in high latency. @@ -11072,10 +11364,18 @@ typedef struct LDKPayer { * Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None */ struct LDKCResult_PaymentIdPaymentSendFailureZ (*send_payment)(const void *this_arg, const struct LDKRoute *NONNULL_PTR route, struct LDKThirtyTwoBytes payment_hash, struct LDKThirtyTwoBytes payment_secret); + /** + * Sends a spontaneous payment over the Lightning Network using the given [`Route`]. + */ + struct LDKCResult_PaymentIdPaymentSendFailureZ (*send_spontaneous_payment)(const void *this_arg, const struct LDKRoute *NONNULL_PTR route, struct LDKThirtyTwoBytes payment_preimage); /** * Retries a failed payment path for the [`PaymentId`] using the given [`Route`]. */ struct LDKCResult_NonePaymentSendFailureZ (*retry_payment)(const void *this_arg, const struct LDKRoute *NONNULL_PTR route, struct LDKThirtyTwoBytes payment_id); + /** + * Signals that no further retries for the given payment will occur. + */ + void (*abandon_payment)(const void *this_arg, struct LDKThirtyTwoBytes payment_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. @@ -11097,7 +11397,7 @@ typedef struct LDKRouter { * * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None */ - struct LDKCResult_RouteLightningErrorZ (*find_route)(const void *this_arg, struct LDKPublicKey payer, const struct LDKRouteParameters *NONNULL_PTR params, struct LDKCVec_ChannelDetailsZ *first_hops, const struct LDKScore *NONNULL_PTR scorer); + struct LDKCResult_RouteLightningErrorZ (*find_route)(const void *this_arg, struct LDKPublicKey payer, const struct LDKRouteParameters *NONNULL_PTR params, const uint8_t (*payment_hash)[32], struct LDKCVec_ChannelDetailsZ *first_hops, const struct LDKScore *NONNULL_PTR scorer); /** * 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. @@ -11108,7 +11408,11 @@ typedef struct LDKRouter { /** - * A utility for paying [`Invoice]`s. + * A utility for paying [`Invoice`]s and sending spontaneous payments. + * + * See [module-level documentation] for details. + * + * [module-level documentation]: crate::payment */ typedef struct MUST_USE_STRUCT LDKInvoicePayer { /** @@ -11417,6 +11721,21 @@ void CResult_HTLCOutputInCommitmentDecodeErrorZ_free(struct LDKCResult_HTLCOutpu */ struct LDKCResult_HTLCOutputInCommitmentDecodeErrorZ CResult_HTLCOutputInCommitmentDecodeErrorZ_clone(const struct LDKCResult_HTLCOutputInCommitmentDecodeErrorZ *NONNULL_PTR orig); +/** + * Constructs a new COption_NoneZ containing a + */ +enum LDKCOption_NoneZ COption_NoneZ_some(void); + +/** + * Constructs a new COption_NoneZ containing nothing + */ +enum LDKCOption_NoneZ COption_NoneZ_none(void); + +/** + * Frees any resources associated with the , if we are in the Some state + */ +void COption_NoneZ_free(enum LDKCOption_NoneZ _res); + /** * Creates a new CResult_CounterpartyChannelTransactionParametersDecodeErrorZ in the success state. */ @@ -11664,6 +11983,12 @@ bool CResult_ShutdownScriptInvalidShutdownScriptZ_is_ok(const struct LDKCResult_ */ void CResult_ShutdownScriptInvalidShutdownScriptZ_free(struct LDKCResult_ShutdownScriptInvalidShutdownScriptZ _res); +/** + * Creates a new CResult_ShutdownScriptInvalidShutdownScriptZ which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. + */ +struct LDKCResult_ShutdownScriptInvalidShutdownScriptZ CResult_ShutdownScriptInvalidShutdownScriptZ_clone(const struct LDKCResult_ShutdownScriptInvalidShutdownScriptZ *NONNULL_PTR orig); + /** * Creates a new CResult_NoneErrorZ in the success state. */ @@ -12148,44 +12473,64 @@ struct LDKCResult_COption_EventZDecodeErrorZ CResult_COption_EventZDecodeErrorZ_ void CVec_MessageSendEventZ_free(struct LDKCVec_MessageSendEventZ _res); /** - * Creates a new CResult_InitFeaturesDecodeErrorZ in the success state. + * Creates a new CResult_ScoringParametersDecodeErrorZ in the success state. */ -struct LDKCResult_InitFeaturesDecodeErrorZ CResult_InitFeaturesDecodeErrorZ_ok(struct LDKInitFeatures o); +struct LDKCResult_ScoringParametersDecodeErrorZ CResult_ScoringParametersDecodeErrorZ_ok(struct LDKScoringParameters o); /** - * Creates a new CResult_InitFeaturesDecodeErrorZ in the error state. + * Creates a new CResult_ScoringParametersDecodeErrorZ in the error state. */ -struct LDKCResult_InitFeaturesDecodeErrorZ CResult_InitFeaturesDecodeErrorZ_err(struct LDKDecodeError e); +struct LDKCResult_ScoringParametersDecodeErrorZ CResult_ScoringParametersDecodeErrorZ_err(struct LDKDecodeError e); /** * Checks if the given object is currently in the success state */ -bool CResult_InitFeaturesDecodeErrorZ_is_ok(const struct LDKCResult_InitFeaturesDecodeErrorZ *NONNULL_PTR o); +bool CResult_ScoringParametersDecodeErrorZ_is_ok(const struct LDKCResult_ScoringParametersDecodeErrorZ *NONNULL_PTR o); /** - * Frees any resources used by the CResult_InitFeaturesDecodeErrorZ. + * Frees any resources used by the CResult_ScoringParametersDecodeErrorZ. */ -void CResult_InitFeaturesDecodeErrorZ_free(struct LDKCResult_InitFeaturesDecodeErrorZ _res); +void CResult_ScoringParametersDecodeErrorZ_free(struct LDKCResult_ScoringParametersDecodeErrorZ _res); /** - * Creates a new CResult_NodeFeaturesDecodeErrorZ in the success state. + * Creates a new CResult_ScorerDecodeErrorZ in the success state. */ -struct LDKCResult_NodeFeaturesDecodeErrorZ CResult_NodeFeaturesDecodeErrorZ_ok(struct LDKNodeFeatures o); +struct LDKCResult_ScorerDecodeErrorZ CResult_ScorerDecodeErrorZ_ok(struct LDKScorer o); /** - * Creates a new CResult_NodeFeaturesDecodeErrorZ in the error state. + * Creates a new CResult_ScorerDecodeErrorZ in the error state. */ -struct LDKCResult_NodeFeaturesDecodeErrorZ CResult_NodeFeaturesDecodeErrorZ_err(struct LDKDecodeError e); +struct LDKCResult_ScorerDecodeErrorZ CResult_ScorerDecodeErrorZ_err(struct LDKDecodeError e); /** * Checks if the given object is currently in the success state */ -bool CResult_NodeFeaturesDecodeErrorZ_is_ok(const struct LDKCResult_NodeFeaturesDecodeErrorZ *NONNULL_PTR o); +bool CResult_ScorerDecodeErrorZ_is_ok(const struct LDKCResult_ScorerDecodeErrorZ *NONNULL_PTR o); /** - * Frees any resources used by the CResult_NodeFeaturesDecodeErrorZ. + * Frees any resources used by the CResult_ScorerDecodeErrorZ. */ -void CResult_NodeFeaturesDecodeErrorZ_free(struct LDKCResult_NodeFeaturesDecodeErrorZ _res); +void CResult_ScorerDecodeErrorZ_free(struct LDKCResult_ScorerDecodeErrorZ _res); + +/** + * Creates a new CResult_InitFeaturesDecodeErrorZ in the success state. + */ +struct LDKCResult_InitFeaturesDecodeErrorZ CResult_InitFeaturesDecodeErrorZ_ok(struct LDKInitFeatures o); + +/** + * Creates a new CResult_InitFeaturesDecodeErrorZ in the error state. + */ +struct LDKCResult_InitFeaturesDecodeErrorZ CResult_InitFeaturesDecodeErrorZ_err(struct LDKDecodeError e); + +/** + * Checks if the given object is currently in the success state + */ +bool CResult_InitFeaturesDecodeErrorZ_is_ok(const struct LDKCResult_InitFeaturesDecodeErrorZ *NONNULL_PTR o); + +/** + * Frees any resources used by the CResult_InitFeaturesDecodeErrorZ. + */ +void CResult_InitFeaturesDecodeErrorZ_free(struct LDKCResult_InitFeaturesDecodeErrorZ _res); /** * Creates a new CResult_ChannelFeaturesDecodeErrorZ in the success state. @@ -12208,64 +12553,64 @@ bool CResult_ChannelFeaturesDecodeErrorZ_is_ok(const struct LDKCResult_ChannelFe void CResult_ChannelFeaturesDecodeErrorZ_free(struct LDKCResult_ChannelFeaturesDecodeErrorZ _res); /** - * Creates a new CResult_InvoiceFeaturesDecodeErrorZ in the success state. + * Creates a new CResult_NodeFeaturesDecodeErrorZ in the success state. */ -struct LDKCResult_InvoiceFeaturesDecodeErrorZ CResult_InvoiceFeaturesDecodeErrorZ_ok(struct LDKInvoiceFeatures o); +struct LDKCResult_NodeFeaturesDecodeErrorZ CResult_NodeFeaturesDecodeErrorZ_ok(struct LDKNodeFeatures o); /** - * Creates a new CResult_InvoiceFeaturesDecodeErrorZ in the error state. + * Creates a new CResult_NodeFeaturesDecodeErrorZ in the error state. */ -struct LDKCResult_InvoiceFeaturesDecodeErrorZ CResult_InvoiceFeaturesDecodeErrorZ_err(struct LDKDecodeError e); +struct LDKCResult_NodeFeaturesDecodeErrorZ CResult_NodeFeaturesDecodeErrorZ_err(struct LDKDecodeError e); /** * Checks if the given object is currently in the success state */ -bool CResult_InvoiceFeaturesDecodeErrorZ_is_ok(const struct LDKCResult_InvoiceFeaturesDecodeErrorZ *NONNULL_PTR o); +bool CResult_NodeFeaturesDecodeErrorZ_is_ok(const struct LDKCResult_NodeFeaturesDecodeErrorZ *NONNULL_PTR o); /** - * Frees any resources used by the CResult_InvoiceFeaturesDecodeErrorZ. + * Frees any resources used by the CResult_NodeFeaturesDecodeErrorZ. */ -void CResult_InvoiceFeaturesDecodeErrorZ_free(struct LDKCResult_InvoiceFeaturesDecodeErrorZ _res); +void CResult_NodeFeaturesDecodeErrorZ_free(struct LDKCResult_NodeFeaturesDecodeErrorZ _res); /** - * Creates a new CResult_ScoringParametersDecodeErrorZ in the success state. + * Creates a new CResult_InvoiceFeaturesDecodeErrorZ in the success state. */ -struct LDKCResult_ScoringParametersDecodeErrorZ CResult_ScoringParametersDecodeErrorZ_ok(struct LDKScoringParameters o); +struct LDKCResult_InvoiceFeaturesDecodeErrorZ CResult_InvoiceFeaturesDecodeErrorZ_ok(struct LDKInvoiceFeatures o); /** - * Creates a new CResult_ScoringParametersDecodeErrorZ in the error state. + * Creates a new CResult_InvoiceFeaturesDecodeErrorZ in the error state. */ -struct LDKCResult_ScoringParametersDecodeErrorZ CResult_ScoringParametersDecodeErrorZ_err(struct LDKDecodeError e); +struct LDKCResult_InvoiceFeaturesDecodeErrorZ CResult_InvoiceFeaturesDecodeErrorZ_err(struct LDKDecodeError e); /** * Checks if the given object is currently in the success state */ -bool CResult_ScoringParametersDecodeErrorZ_is_ok(const struct LDKCResult_ScoringParametersDecodeErrorZ *NONNULL_PTR o); +bool CResult_InvoiceFeaturesDecodeErrorZ_is_ok(const struct LDKCResult_InvoiceFeaturesDecodeErrorZ *NONNULL_PTR o); /** - * Frees any resources used by the CResult_ScoringParametersDecodeErrorZ. + * Frees any resources used by the CResult_InvoiceFeaturesDecodeErrorZ. */ -void CResult_ScoringParametersDecodeErrorZ_free(struct LDKCResult_ScoringParametersDecodeErrorZ _res); +void CResult_InvoiceFeaturesDecodeErrorZ_free(struct LDKCResult_InvoiceFeaturesDecodeErrorZ _res); /** - * Creates a new CResult_ScorerDecodeErrorZ in the success state. + * Creates a new CResult_ChannelTypeFeaturesDecodeErrorZ in the success state. */ -struct LDKCResult_ScorerDecodeErrorZ CResult_ScorerDecodeErrorZ_ok(struct LDKScorer o); +struct LDKCResult_ChannelTypeFeaturesDecodeErrorZ CResult_ChannelTypeFeaturesDecodeErrorZ_ok(struct LDKChannelTypeFeatures o); /** - * Creates a new CResult_ScorerDecodeErrorZ in the error state. + * Creates a new CResult_ChannelTypeFeaturesDecodeErrorZ in the error state. */ -struct LDKCResult_ScorerDecodeErrorZ CResult_ScorerDecodeErrorZ_err(struct LDKDecodeError e); +struct LDKCResult_ChannelTypeFeaturesDecodeErrorZ CResult_ChannelTypeFeaturesDecodeErrorZ_err(struct LDKDecodeError e); /** * Checks if the given object is currently in the success state */ -bool CResult_ScorerDecodeErrorZ_is_ok(const struct LDKCResult_ScorerDecodeErrorZ *NONNULL_PTR o); +bool CResult_ChannelTypeFeaturesDecodeErrorZ_is_ok(const struct LDKCResult_ChannelTypeFeaturesDecodeErrorZ *NONNULL_PTR o); /** - * Frees any resources used by the CResult_ScorerDecodeErrorZ. + * Frees any resources used by the CResult_ChannelTypeFeaturesDecodeErrorZ. */ -void CResult_ScorerDecodeErrorZ_free(struct LDKCResult_ScorerDecodeErrorZ _res); +void CResult_ChannelTypeFeaturesDecodeErrorZ_free(struct LDKCResult_ChannelTypeFeaturesDecodeErrorZ _res); /** * Creates a new CResult_DelayedPaymentOutputDescriptorDecodeErrorZ in the success state. @@ -12817,6 +13162,84 @@ struct LDKC2Tuple_PaymentHashPaymentSecretZ C2Tuple_PaymentHashPaymentSecretZ_ne */ void C2Tuple_PaymentHashPaymentSecretZ_free(struct LDKC2Tuple_PaymentHashPaymentSecretZ _res); +/** + * Creates a new CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ in the success state. + */ +struct LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZ CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ_ok(struct LDKC2Tuple_PaymentHashPaymentSecretZ o); + +/** + * Creates a new CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ in the error state. + */ +struct LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZ CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ_err(void); + +/** + * Checks if the given object is currently in the success state + */ +bool CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ_is_ok(const struct LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZ *NONNULL_PTR o); + +/** + * Frees any resources used by the CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ. + */ +void CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ_free(struct LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZ _res); + +/** + * Creates a new CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. + */ +struct LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZ CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ_clone(const struct LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZ *NONNULL_PTR orig); + +/** + * Creates a new CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ in the success state. + */ +struct LDKCResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ_ok(struct LDKC2Tuple_PaymentHashPaymentSecretZ o); + +/** + * Creates a new CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ in the error state. + */ +struct LDKCResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ_err(struct LDKAPIError e); + +/** + * Checks if the given object is currently in the success state + */ +bool CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ_is_ok(const struct LDKCResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ *NONNULL_PTR o); + +/** + * Frees any resources used by the CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ. + */ +void CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ_free(struct LDKCResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ _res); + +/** + * Creates a new CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. + */ +struct LDKCResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ_clone(const struct LDKCResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ *NONNULL_PTR orig); + +/** + * Creates a new CResult_PaymentSecretNoneZ in the success state. + */ +struct LDKCResult_PaymentSecretNoneZ CResult_PaymentSecretNoneZ_ok(struct LDKThirtyTwoBytes o); + +/** + * Creates a new CResult_PaymentSecretNoneZ in the error state. + */ +struct LDKCResult_PaymentSecretNoneZ CResult_PaymentSecretNoneZ_err(void); + +/** + * Checks if the given object is currently in the success state + */ +bool CResult_PaymentSecretNoneZ_is_ok(const struct LDKCResult_PaymentSecretNoneZ *NONNULL_PTR o); + +/** + * Frees any resources used by the CResult_PaymentSecretNoneZ. + */ +void CResult_PaymentSecretNoneZ_free(struct LDKCResult_PaymentSecretNoneZ _res); + +/** + * Creates a new CResult_PaymentSecretNoneZ which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. + */ +struct LDKCResult_PaymentSecretNoneZ CResult_PaymentSecretNoneZ_clone(const struct LDKCResult_PaymentSecretNoneZ *NONNULL_PTR orig); + /** * Creates a new CResult_PaymentSecretAPIErrorZ in the success state. */ @@ -12843,6 +13266,32 @@ void CResult_PaymentSecretAPIErrorZ_free(struct LDKCResult_PaymentSecretAPIError */ struct LDKCResult_PaymentSecretAPIErrorZ CResult_PaymentSecretAPIErrorZ_clone(const struct LDKCResult_PaymentSecretAPIErrorZ *NONNULL_PTR orig); +/** + * Creates a new CResult_PaymentPreimageAPIErrorZ in the success state. + */ +struct LDKCResult_PaymentPreimageAPIErrorZ CResult_PaymentPreimageAPIErrorZ_ok(struct LDKThirtyTwoBytes o); + +/** + * Creates a new CResult_PaymentPreimageAPIErrorZ in the error state. + */ +struct LDKCResult_PaymentPreimageAPIErrorZ CResult_PaymentPreimageAPIErrorZ_err(struct LDKAPIError e); + +/** + * Checks if the given object is currently in the success state + */ +bool CResult_PaymentPreimageAPIErrorZ_is_ok(const struct LDKCResult_PaymentPreimageAPIErrorZ *NONNULL_PTR o); + +/** + * Frees any resources used by the CResult_PaymentPreimageAPIErrorZ. + */ +void CResult_PaymentPreimageAPIErrorZ_free(struct LDKCResult_PaymentPreimageAPIErrorZ _res); + +/** + * Creates a new CResult_PaymentPreimageAPIErrorZ which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. + */ +struct LDKCResult_PaymentPreimageAPIErrorZ CResult_PaymentPreimageAPIErrorZ_clone(const struct LDKCResult_PaymentPreimageAPIErrorZ *NONNULL_PTR orig); + /** * Frees the buffer pointed to by `data` if `datalen` is non-0. */ @@ -13391,32 +13840,6 @@ void CResult_HTLCUpdateDecodeErrorZ_free(struct LDKCResult_HTLCUpdateDecodeError */ struct LDKCResult_HTLCUpdateDecodeErrorZ CResult_HTLCUpdateDecodeErrorZ_clone(const struct LDKCResult_HTLCUpdateDecodeErrorZ *NONNULL_PTR orig); -/** - * Creates a new CResult_NoneMonitorUpdateErrorZ in the success state. - */ -struct LDKCResult_NoneMonitorUpdateErrorZ CResult_NoneMonitorUpdateErrorZ_ok(void); - -/** - * Creates a new CResult_NoneMonitorUpdateErrorZ in the error state. - */ -struct LDKCResult_NoneMonitorUpdateErrorZ CResult_NoneMonitorUpdateErrorZ_err(struct LDKMonitorUpdateError e); - -/** - * Checks if the given object is currently in the success state - */ -bool CResult_NoneMonitorUpdateErrorZ_is_ok(const struct LDKCResult_NoneMonitorUpdateErrorZ *NONNULL_PTR o); - -/** - * Frees any resources used by the CResult_NoneMonitorUpdateErrorZ. - */ -void CResult_NoneMonitorUpdateErrorZ_free(struct LDKCResult_NoneMonitorUpdateErrorZ _res); - -/** - * Creates a new CResult_NoneMonitorUpdateErrorZ which has the same data as `orig` - * but with all dynamically-allocated buffers duplicated in new buffers. - */ -struct LDKCResult_NoneMonitorUpdateErrorZ CResult_NoneMonitorUpdateErrorZ_clone(const struct LDKCResult_NoneMonitorUpdateErrorZ *NONNULL_PTR orig); - /** * Creates a new tuple which has the same data as `orig` * but with all dynamically-allocated buffers duplicated in new buffers. @@ -14934,7 +15357,7 @@ struct LDKPaymentPurpose PaymentPurpose_clone(const struct LDKPaymentPurpose *NO /** * Utility method to constructs a new InvoicePayment-variant PaymentPurpose */ -struct LDKPaymentPurpose PaymentPurpose_invoice_payment(struct LDKThirtyTwoBytes payment_preimage, struct LDKThirtyTwoBytes payment_secret, uint64_t user_payment_id); +struct LDKPaymentPurpose PaymentPurpose_invoice_payment(struct LDKThirtyTwoBytes payment_preimage, struct LDKThirtyTwoBytes payment_secret); /** * Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose @@ -14971,6 +15394,11 @@ struct LDKClosureReason ClosureReason_cooperative_closure(void); */ struct LDKClosureReason ClosureReason_commitment_tx_confirmed(void); +/** + * Utility method to constructs a new FundingTimedOut-variant ClosureReason + */ +struct LDKClosureReason ClosureReason_funding_timed_out(void); + /** * Utility method to constructs a new ProcessingError-variant ClosureReason */ @@ -15026,6 +15454,11 @@ struct LDKEvent Event_payment_sent(struct LDKThirtyTwoBytes payment_id, struct L */ struct LDKEvent Event_payment_path_failed(struct LDKThirtyTwoBytes payment_id, 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, struct LDKRouteParameters retry); +/** + * Utility method to constructs a new PaymentFailed-variant Event + */ +struct LDKEvent Event_payment_failed(struct LDKThirtyTwoBytes payment_id, struct LDKThirtyTwoBytes payment_hash); + /** * Utility method to constructs a new PendingHTLCsForwardable-variant Event */ @@ -15051,6 +15484,11 @@ struct LDKEvent Event_channel_closed(struct LDKThirtyTwoBytes channel_id, uint64 */ struct LDKEvent Event_discard_funding(struct LDKThirtyTwoBytes channel_id, struct LDKTransaction transaction); +/** + * Utility method to constructs a new PaymentPathSuccessful-variant Event + */ +struct LDKEvent Event_payment_path_successful(struct LDKThirtyTwoBytes payment_id, struct LDKThirtyTwoBytes payment_hash, struct LDKCVec_RouteHopZ path); + /** * Serialize the Event object into a byte array which can be read by Event_read */ @@ -15244,6 +15682,11 @@ bool verify(struct LDKu8slice msg, struct LDKStr sig, struct LDKPublicKey pk); */ enum LDKLevel Level_clone(const enum LDKLevel *NONNULL_PTR orig); +/** + * Utility method to constructs a new Gossip-variant Level + */ +enum LDKLevel Level_gossip(void); + /** * Utility method to constructs a new Trace-variant Level */ @@ -15969,10 +16412,22 @@ bool UserConfig_get_accept_forwards_to_priv_channels(const struct LDKUserConfig */ void UserConfig_set_accept_forwards_to_priv_channels(struct LDKUserConfig *NONNULL_PTR this_ptr, bool val); +/** + * If this is set to false, we do not accept inbound requests to open a new channel. + * Default value: true. + */ +bool UserConfig_get_accept_inbound_channels(const struct LDKUserConfig *NONNULL_PTR this_ptr); + +/** + * If this is set to false, we do not accept inbound requests to open a new channel. + * Default value: true. + */ +void UserConfig_set_accept_inbound_channels(struct LDKUserConfig *NONNULL_PTR this_ptr, bool val); + /** * Constructs a new UserConfig given each field */ -MUST_USE_RES struct LDKUserConfig UserConfig_new(struct LDKChannelHandshakeConfig own_channel_config_arg, struct LDKChannelHandshakeLimits peer_channel_config_limits_arg, struct LDKChannelConfig channel_options_arg, bool accept_forwards_to_priv_channels_arg); +MUST_USE_RES struct LDKUserConfig UserConfig_new(struct LDKChannelHandshakeConfig own_channel_config_arg, struct LDKChannelHandshakeLimits peer_channel_config_limits_arg, struct LDKChannelConfig channel_options_arg, bool accept_forwards_to_priv_channels_arg, bool accept_inbound_channels_arg); /** * Creates a copy of the UserConfig @@ -16329,25 +16784,6 @@ struct LDKCVec_u8Z ChannelMonitorUpdate_write(const struct LDKChannelMonitorUpda */ struct LDKCResult_ChannelMonitorUpdateDecodeErrorZ ChannelMonitorUpdate_read(struct LDKu8slice ser); -/** - * Frees any resources used by the MonitorUpdateError, if is_owned is set and inner is non-NULL. - */ -void MonitorUpdateError_free(struct LDKMonitorUpdateError this_obj); - -struct LDKStr MonitorUpdateError_get_a(const struct LDKMonitorUpdateError *NONNULL_PTR this_ptr); - -void MonitorUpdateError_set_a(struct LDKMonitorUpdateError *NONNULL_PTR this_ptr, struct LDKStr val); - -/** - * Constructs a new MonitorUpdateError given each field - */ -MUST_USE_RES struct LDKMonitorUpdateError MonitorUpdateError_new(struct LDKStr a_arg); - -/** - * Creates a copy of the MonitorUpdateError - */ -struct LDKMonitorUpdateError MonitorUpdateError_clone(const struct LDKMonitorUpdateError *NONNULL_PTR orig); - /** * Frees any resources used by the MonitorEvent */ @@ -16460,7 +16896,7 @@ struct LDKCVec_u8Z ChannelMonitor_write(const struct LDKChannelMonitor *NONNULL_ * * panics if the given update is not the next update by update_id. */ -MUST_USE_RES struct LDKCResult_NoneMonitorUpdateErrorZ ChannelMonitor_update_monitor(const struct LDKChannelMonitor *NONNULL_PTR this_arg, const struct LDKChannelMonitorUpdate *NONNULL_PTR updates, const struct LDKBroadcasterInterface *NONNULL_PTR broadcaster, const struct LDKFeeEstimator *NONNULL_PTR fee_estimator, const struct LDKLogger *NONNULL_PTR logger); +MUST_USE_RES struct LDKCResult_NoneNoneZ ChannelMonitor_update_monitor(const struct LDKChannelMonitor *NONNULL_PTR this_arg, const struct LDKChannelMonitorUpdate *NONNULL_PTR updates, const struct LDKBroadcasterInterface *NONNULL_PTR broadcaster, const struct LDKFeeEstimator *NONNULL_PTR fee_estimator, const struct LDKLogger *NONNULL_PTR logger); /** * Gets the update_id from the latest ChannelMonitorUpdate which was applied to this @@ -16998,6 +17434,12 @@ MUST_USE_RES struct LDKOutPoint InMemorySigner_funding_outpoint(const struct LDK */ MUST_USE_RES struct LDKChannelTransactionParameters InMemorySigner_get_channel_parameters(const struct LDKInMemorySigner *NONNULL_PTR this_arg); +/** + * Whether anchors should be used. + * Will panic if ready_channel wasn't called. + */ +MUST_USE_RES bool InMemorySigner_opt_anchors(const struct LDKInMemorySigner *NONNULL_PTR this_arg); + /** * Sign the single input of spend_tx at index `input_idx` which spends the output * described by descriptor, returning the witness stack for the input. @@ -17378,12 +17820,42 @@ uint64_t ChannelDetails_get_user_channel_id(const struct LDKChannelDetails *NONN */ void ChannelDetails_set_user_channel_id(struct LDKChannelDetails *NONNULL_PTR this_ptr, uint64_t val); +/** + * Our total balance. This is the amount we would get if we close the channel. + * This value is not exact. Due to various in-flight changes and feerate changes, exactly this + * amount is not likely to be recoverable on close. + * + * This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose + * balance is not available for inclusion in new outbound HTLCs). This further does not include + * any pending outgoing HTLCs which are awaiting some other resolution to be sent. + * This does not consider any on-chain fees. + * + * See also [`ChannelDetails::outbound_capacity_msat`] + */ +uint64_t ChannelDetails_get_balance_msat(const struct LDKChannelDetails *NONNULL_PTR this_ptr); + +/** + * Our total balance. This is the amount we would get if we close the channel. + * This value is not exact. Due to various in-flight changes and feerate changes, exactly this + * amount is not likely to be recoverable on close. + * + * This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose + * balance is not available for inclusion in new outbound HTLCs). This further does not include + * any pending outgoing HTLCs which are awaiting some other resolution to be sent. + * This does not consider any on-chain fees. + * + * See also [`ChannelDetails::outbound_capacity_msat`] + */ +void ChannelDetails_set_balance_msat(struct LDKChannelDetails *NONNULL_PTR this_ptr, uint64_t 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 + * any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not * available for inclusion in new outbound HTLCs). This further does not include any pending * outgoing HTLCs which are awaiting some other resolution to be sent. * + * See also [`ChannelDetails::balance_msat`] + * * This value is not exact. Due to various in-flight changes, feerate changes, and our * conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we * should be able to spend nearly this amount. @@ -17392,10 +17864,12 @@ uint64_t ChannelDetails_get_outbound_capacity_msat(const struct LDKChannelDetail /** * 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 + * any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not * available for inclusion in new outbound HTLCs). This further does not include any pending * outgoing HTLCs which are awaiting some other resolution to be sent. * + * See also [`ChannelDetails::balance_msat`] + * * This value is not exact. Due to various in-flight changes, feerate changes, and our * conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we * should be able to spend nearly this amount. @@ -17404,7 +17878,7 @@ void ChannelDetails_set_outbound_capacity_msat(struct LDKChannelDetails *NONNULL /** * The available inbound capacity for the remote peer to send HTLCs to us. This does not - * include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not + * include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not * available for inclusion in new inbound HTLCs). * Note that there are some corner cases not fully handled here, so the actual available * inbound capacity may be slightly higher than this. @@ -17417,7 +17891,7 @@ uint64_t ChannelDetails_get_inbound_capacity_msat(const struct LDKChannelDetails /** * The available inbound capacity for the remote peer to send HTLCs to us. This does not - * include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not + * include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not * available for inclusion in new inbound HTLCs). * Note that there are some corner cases not fully handled here, so the actual available * inbound capacity may be slightly higher than this. @@ -17541,7 +18015,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_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); +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 balance_msat_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 @@ -17753,13 +18227,33 @@ MUST_USE_RES struct LDKCResult_PaymentIdPaymentSendFailureZ ChannelManager_send_ * * 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). + * retry amount puts the payment more than 10% over the payment's total amount, if the payment + * for the given `payment_id` cannot be found (likely due to timeout or success), or if + * further retries have been disabled with [`abandon_payment`]. * * [`send_payment`]: [`ChannelManager::send_payment`] + * [`abandon_payment`]: [`ChannelManager::abandon_payment`] */ MUST_USE_RES struct LDKCResult_NonePaymentSendFailureZ ChannelManager_retry_payment(const struct LDKChannelManager *NONNULL_PTR this_arg, const struct LDKRoute *NONNULL_PTR route, struct LDKThirtyTwoBytes payment_id); +/** + * Signals that no further retries for the given payment will occur. + * + * After this method returns, any future calls to [`retry_payment`] for the given `payment_id` + * will fail with [`PaymentSendFailure::ParameterError`]. If no such event has been generated, + * an [`Event::PaymentFailed`] event will be generated as soon as there are no remaining + * pending HTLCs for this payment. + * + * Note that calling this method does *not* prevent a payment from succeeding. You must still + * wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to + * determine the ultimate status of a payment. + * + * [`retry_payment`]: Self::retry_payment + * [`Event::PaymentFailed`]: events::Event::PaymentFailed + * [`Event::PaymentSent`]: events::Event::PaymentSent + */ +void ChannelManager_abandon_payment(const struct LDKChannelManager *NONNULL_PTR this_arg, struct LDKThirtyTwoBytes payment_id); + /** * Send a spontaneous payment, which is a payment that does not require the recipient to have * generated an invoice. Optionally, you may specify the preimage. If you do choose to specify @@ -17786,7 +18280,8 @@ MUST_USE_RES struct LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ * Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs * or if no output was found which matches the parameters in [`Event::FundingGenerationReady`]. * - * Panics if a funding transaction has already been provided for this channel. + * Returns [`APIError::ChannelUnavailable`] if a funding transaction has already been provided + * for the channel or if the channel has been closed as indicated by [`Event::ChannelClosed`]. * * May panic if the output found in the funding transaction is duplicative with some other * channel (note that this should be trivially prevented by using unique funding transaction @@ -17801,6 +18296,7 @@ MUST_USE_RES struct LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ * create a new channel with a conflicting funding transaction. * * [`Event::FundingGenerationReady`]: crate::util::events::Event::FundingGenerationReady + * [`Event::ChannelClosed`]: crate::util::events::Event::ChannelClosed */ MUST_USE_RES struct LDKCResult_NoneAPIErrorZ ChannelManager_funding_transaction_generated(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*temporary_channel_id)[32], struct LDKTransaction funding_transaction); @@ -17858,19 +18354,21 @@ void ChannelManager_timer_tick_occurred(const struct LDKChannelManager *NONNULL_ MUST_USE_RES bool ChannelManager_fail_htlc_backwards(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*payment_hash)[32]); /** - * Provides a payment preimage in response to a PaymentReceived event, returning true and - * generating message events for the net layer to claim the payment, if possible. Thus, you - * should probably kick the net layer to go send messages if this returns true! + * Provides a payment preimage in response to [`Event::PaymentReceived`], generating any + * [`MessageSendEvent`]s needed to claim the payment. * * Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or * [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentReceived` * event matches your expectation. If you fail to do so and call this method, you may provide * the sender \"proof-of-payment\" when they did not fulfill the full expected payment. * - * May panic if called except in response to a PaymentReceived event. + * Returns whether any HTLCs were claimed, and thus if any new [`MessageSendEvent`]s are now + * pending for processing via [`get_and_clear_pending_msg_events`]. * + * [`Event::PaymentReceived`]: crate::util::events::Event::PaymentReceived * [`create_inbound_payment`]: Self::create_inbound_payment * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash + * [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events */ MUST_USE_RES bool ChannelManager_claim_funds(const struct LDKChannelManager *NONNULL_PTR this_arg, struct LDKThirtyTwoBytes payment_preimage); @@ -17884,7 +18382,7 @@ MUST_USE_RES struct LDKPublicKey ChannelManager_get_our_node_id(const struct LDK * to pay us. * * This differs from [`create_inbound_payment_for_hash`] only in that it generates the - * [`PaymentHash`] and [`PaymentPreimage`] for you, returning the first and storing the second. + * [`PaymentHash`] and [`PaymentPreimage`] for you. * * The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentReceived`], which * will have the [`PaymentReceived::payment_preimage`] field filled in. That should then be @@ -17892,12 +18390,33 @@ MUST_USE_RES struct LDKPublicKey ChannelManager_get_our_node_id(const struct LDK * * See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements. * + * Note that a malicious eavesdropper can intuit whether an inbound payment was created by + * `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime. + * + * # Note + * + * If you register an inbound payment with this method, then serialize the `ChannelManager`, then + * deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received. + * + * Errors if `min_value_msat` is greater than total bitcoin supply. + * * [`claim_funds`]: Self::claim_funds * [`PaymentReceived`]: events::Event::PaymentReceived * [`PaymentReceived::payment_preimage`]: events::Event::PaymentReceived::payment_preimage * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash */ -MUST_USE_RES struct LDKC2Tuple_PaymentHashPaymentSecretZ ChannelManager_create_inbound_payment(const struct LDKChannelManager *NONNULL_PTR this_arg, struct LDKCOption_u64Z min_value_msat, uint32_t invoice_expiry_delta_secs, uint64_t user_payment_id); +MUST_USE_RES struct LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZ ChannelManager_create_inbound_payment(const struct LDKChannelManager *NONNULL_PTR this_arg, struct LDKCOption_u64Z min_value_msat, uint32_t invoice_expiry_delta_secs); + +/** + * Legacy version of [`create_inbound_payment`]. Use this method if you wish to share + * serialized state with LDK node(s) running 0.0.103 and earlier. + * + * # Note + * This method is deprecated and will be removed soon. + * + * [`create_inbound_payment`]: Self::create_inbound_payment + */ +MUST_USE_RES struct LDKCResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ ChannelManager_create_inbound_payment_legacy(const struct LDKChannelManager *NONNULL_PTR this_arg, struct LDKCOption_u64Z min_value_msat, uint32_t invoice_expiry_delta_secs); /** * Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is @@ -17907,14 +18426,9 @@ MUST_USE_RES struct LDKC2Tuple_PaymentHashPaymentSecretZ ChannelManager_create_i * payment secret fetched via this method or [`create_inbound_payment`], and which is at least * the `min_value_msat` provided here, if one is provided. * - * The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) must be globally unique. This - * method may return an Err if another payment with the same payment_hash is still pending. - * - * `user_payment_id` will be provided back in [`PaymentPurpose::InvoicePayment::user_payment_id`] events to - * allow tracking of which events correspond with which calls to this and - * [`create_inbound_payment`]. `user_payment_id` has no meaning inside of LDK, it is simply - * copied to events and otherwise ignored. It may be used to correlate PaymentReceived events - * with invoice metadata stored elsewhere. + * The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) should be globally unique, though + * note that LDK will not stop you from registering duplicate payment hashes for inbound + * payments. * * `min_value_msat` should be set if the invoice being generated contains a value. Any payment * received for the returned [`PaymentHash`] will be required to be at least `min_value_msat` @@ -17933,20 +18447,44 @@ MUST_USE_RES struct LDKC2Tuple_PaymentHashPaymentSecretZ ChannelManager_create_i * If you need exact expiry semantics, you should enforce them upon receipt of * [`PaymentReceived`]. * - * Pending inbound payments are stored in memory and in serialized versions of this - * [`ChannelManager`]. If potentially unbounded numbers of inbound payments may exist and - * space is limited, you may wish to rate-limit inbound payment creation. - * * May panic if `invoice_expiry_delta_secs` is greater than one year. * * Note that invoices generated for inbound payments should have their `min_final_cltv_expiry` * set to at least [`MIN_FINAL_CLTV_EXPIRY`]. * + * Note that a malicious eavesdropper can intuit whether an inbound payment was created by + * `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime. + * + * # Note + * + * If you register an inbound payment with this method, then serialize the `ChannelManager`, then + * deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received. + * + * Errors if `min_value_msat` is greater than total bitcoin supply. + * * [`create_inbound_payment`]: Self::create_inbound_payment * [`PaymentReceived`]: events::Event::PaymentReceived - * [`PaymentPurpose::InvoicePayment::user_payment_id`]: events::PaymentPurpose::InvoicePayment::user_payment_id */ -MUST_USE_RES struct LDKCResult_PaymentSecretAPIErrorZ ChannelManager_create_inbound_payment_for_hash(const struct LDKChannelManager *NONNULL_PTR this_arg, struct LDKThirtyTwoBytes payment_hash, struct LDKCOption_u64Z min_value_msat, uint32_t invoice_expiry_delta_secs, uint64_t user_payment_id); +MUST_USE_RES struct LDKCResult_PaymentSecretNoneZ ChannelManager_create_inbound_payment_for_hash(const struct LDKChannelManager *NONNULL_PTR this_arg, struct LDKThirtyTwoBytes payment_hash, struct LDKCOption_u64Z min_value_msat, uint32_t invoice_expiry_delta_secs); + +/** + * Legacy version of [`create_inbound_payment_for_hash`]. Use this method if you wish to share + * serialized state with LDK node(s) running 0.0.103 and earlier. + * + * # Note + * This method is deprecated and will be removed soon. + * + * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash + */ +MUST_USE_RES struct LDKCResult_PaymentSecretAPIErrorZ ChannelManager_create_inbound_payment_for_hash_legacy(const struct LDKChannelManager *NONNULL_PTR this_arg, struct LDKThirtyTwoBytes payment_hash, struct LDKCOption_u64Z min_value_msat, uint32_t invoice_expiry_delta_secs); + +/** + * Gets an LDK-generated payment preimage from a payment hash and payment secret that were + * previously returned from [`create_inbound_payment`]. + * + * [`create_inbound_payment`]: Self::create_inbound_payment + */ +MUST_USE_RES struct LDKCResult_PaymentPreimageAPIErrorZ ChannelManager_get_payment_preimage(const struct LDKChannelManager *NONNULL_PTR this_arg, struct LDKThirtyTwoBytes payment_hash, struct LDKThirtyTwoBytes payment_secret); /** * Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg. @@ -17977,7 +18515,8 @@ struct LDKConfirm ChannelManager_as_Confirm(const struct LDKChannelManager *NONN * indicating whether persistence is necessary. Only one listener on * `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken * up. - * Note that the feature `allow_wallclock_use` must be enabled to use this function. + * + * Note that this method is not available with the `no-std` feature. */ MUST_USE_RES bool ChannelManager_await_persistable_update_timeout(const struct LDKChannelManager *NONNULL_PTR this_arg, uint64_t max_wait); @@ -18431,6 +18970,24 @@ uint8_t OpenChannel_get_channel_flags(const struct LDKOpenChannel *NONNULL_PTR t */ void OpenChannel_set_channel_flags(struct LDKOpenChannel *NONNULL_PTR this_ptr, uint8_t val); +/** + * The channel type that this channel will represent. If none is set, we derive the channel + * type from the intersection of our feature bits with our counterparty's feature bits from + * the Init message. + * + * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None + */ +struct LDKChannelTypeFeatures OpenChannel_get_channel_type(const struct LDKOpenChannel *NONNULL_PTR this_ptr); + +/** + * The channel type that this channel will represent. If none is set, we derive the channel + * type from the intersection of our feature bits with our counterparty's feature bits from + * the Init message. + * + * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None + */ +void OpenChannel_set_channel_type(struct LDKOpenChannel *NONNULL_PTR this_ptr, struct LDKChannelTypeFeatures val); + /** * Creates a copy of the OpenChannel */ @@ -19298,7 +19855,7 @@ struct LDKNetAddress NetAddress_ipv6(struct LDKSixteenBytes addr, uint16_t port) /** * Utility method to constructs a new OnionV2-variant NetAddress */ -struct LDKNetAddress NetAddress_onion_v2(struct LDKTenBytes addr, uint16_t port); +struct LDKNetAddress NetAddress_onion_v2(struct LDKTwelveBytes a); /** * Utility method to constructs a new OnionV3-variant NetAddress @@ -19945,6 +20502,11 @@ struct LDKErrorAction ErrorAction_ignore_error(void); */ struct LDKErrorAction ErrorAction_ignore_and_log(enum LDKLevel a); +/** + * Utility method to constructs a new IgnoreDuplicateGossip-variant ErrorAction + */ +struct LDKErrorAction ErrorAction_ignore_duplicate_gossip(void); + /** * Utility method to constructs a new SendErrorMessage-variant ErrorAction */ @@ -20682,6 +21244,16 @@ void PeerManager_disconnect_all_peers(const struct LDKPeerManager *NONNULL_PTR t */ void PeerManager_timer_tick_occurred(const struct LDKPeerManager *NONNULL_PTR this_arg); +/** + * Gets the weight for an HTLC-Success transaction. + */ +uint64_t htlc_success_tx_weight(bool opt_anchors); + +/** + * Gets the weight for an HTLC-Timeout transaction. + */ +uint64_t htlc_timeout_tx_weight(bool opt_anchors); + /** * Build the commitment secret from the seed and the commitment number */ @@ -21021,7 +21593,7 @@ struct LDKCResult_HTLCOutputInCommitmentDecodeErrorZ HTLCOutputInCommitment_read * Gets the witness redeemscript for an HTLC output in a commitment transaction. Note that htlc * does not need to have its previous_output_index filled. */ -struct LDKCVec_u8Z get_htlc_redeemscript(const struct LDKHTLCOutputInCommitment *NONNULL_PTR htlc, const struct LDKTxCreationKeys *NONNULL_PTR keys); +struct LDKCVec_u8Z get_htlc_redeemscript(const struct LDKHTLCOutputInCommitment *NONNULL_PTR htlc, bool opt_anchors, const struct LDKTxCreationKeys *NONNULL_PTR keys); /** * Gets the redeemscript for a funding output from the two funding public keys. @@ -21038,7 +21610,17 @@ struct LDKCVec_u8Z make_funding_redeemscript(struct LDKPublicKey broadcaster, st * Panics if htlc.transaction_output_index.is_none() (as such HTLCs do not appear in the * commitment transaction). */ -struct LDKTransaction build_htlc_transaction(const uint8_t (*commitment_txid)[32], uint32_t feerate_per_kw, uint16_t contest_delay, const struct LDKHTLCOutputInCommitment *NONNULL_PTR htlc, struct LDKPublicKey broadcaster_delayed_payment_key, struct LDKPublicKey revocation_key); +struct LDKTransaction build_htlc_transaction(const uint8_t (*commitment_txid)[32], uint32_t feerate_per_kw, uint16_t contest_delay, const struct LDKHTLCOutputInCommitment *NONNULL_PTR htlc, bool opt_anchors, struct LDKPublicKey broadcaster_delayed_payment_key, struct LDKPublicKey revocation_key); + +/** + * Gets the witnessScript for an anchor output from the funding public key. + * The witness in the spending input must be: + * + * After 16 blocks of confirmation, an alternative satisfying witness could be: + * <> + * (empty vector required to satisfy compliance with MINIMALIF-standard rule) + */ +struct LDKCVec_u8Z get_anchor_redeemscript(struct LDKPublicKey funding_pubkey); /** * Frees any resources used by the ChannelTransactionParameters, if is_owned is set and inner is non-NULL. @@ -21107,10 +21689,20 @@ struct LDKOutPoint ChannelTransactionParameters_get_funding_outpoint(const struc */ void ChannelTransactionParameters_set_funding_outpoint(struct LDKChannelTransactionParameters *NONNULL_PTR this_ptr, struct LDKOutPoint val); +/** + * Are anchors used for this channel. Boolean is serialization backwards-compatible + */ +enum LDKCOption_NoneZ ChannelTransactionParameters_get_opt_anchors(const struct LDKChannelTransactionParameters *NONNULL_PTR this_ptr); + +/** + * Are anchors used for this channel. Boolean is serialization backwards-compatible + */ +void ChannelTransactionParameters_set_opt_anchors(struct LDKChannelTransactionParameters *NONNULL_PTR this_ptr, enum LDKCOption_NoneZ val); + /** * Constructs a new ChannelTransactionParameters given each field */ -MUST_USE_RES struct LDKChannelTransactionParameters ChannelTransactionParameters_new(struct LDKChannelPublicKeys holder_pubkeys_arg, uint16_t holder_selected_contest_delay_arg, bool is_outbound_from_holder_arg, struct LDKCounterpartyChannelTransactionParameters counterparty_parameters_arg, struct LDKOutPoint funding_outpoint_arg); +MUST_USE_RES struct LDKChannelTransactionParameters ChannelTransactionParameters_new(struct LDKChannelPublicKeys holder_pubkeys_arg, uint16_t holder_selected_contest_delay_arg, bool is_outbound_from_holder_arg, struct LDKCounterpartyChannelTransactionParameters counterparty_parameters_arg, struct LDKOutPoint funding_outpoint_arg, enum LDKCOption_NoneZ opt_anchors_arg); /** * Creates a copy of the ChannelTransactionParameters @@ -21227,6 +21819,11 @@ MUST_USE_RES bool DirectedChannelTransactionParameters_is_outbound(const struct */ MUST_USE_RES struct LDKOutPoint DirectedChannelTransactionParameters_funding_outpoint(const struct LDKDirectedChannelTransactionParameters *NONNULL_PTR this_arg); +/** + * Whether to use anchors for this channel + */ +MUST_USE_RES bool DirectedChannelTransactionParameters_opt_anchors(const struct LDKDirectedChannelTransactionParameters *NONNULL_PTR this_arg); + /** * Frees any resources used by the HolderCommitmentTransaction, if is_owned is set and inner is non-NULL. */ @@ -21337,6 +21934,16 @@ MUST_USE_RES struct LDKSignature BuiltCommitmentTransaction_sign(const struct LD */ void ClosingTransaction_free(struct LDKClosingTransaction this_obj); +/** + * Creates a copy of the ClosingTransaction + */ +struct LDKClosingTransaction ClosingTransaction_clone(const struct LDKClosingTransaction *NONNULL_PTR orig); + +/** + * Checks if two ClosingTransactions contain equal inner contents. + */ +uint64_t ClosingTransaction_hash(const struct LDKClosingTransaction *NONNULL_PTR o); + /** * Construct an object of the class */ @@ -21485,6 +22092,11 @@ MUST_USE_RES struct LDKBuiltCommitmentTransaction TrustedCommitmentTransaction_b */ MUST_USE_RES struct LDKTxCreationKeys TrustedCommitmentTransaction_keys(const struct LDKTrustedCommitmentTransaction *NONNULL_PTR this_arg); +/** + * Should anchors be used. + */ +MUST_USE_RES bool TrustedCommitmentTransaction_opt_anchors(const struct LDKTrustedCommitmentTransaction *NONNULL_PTR this_arg); + /** * Get a signature for each HTLC which was included in the commitment transaction (ie for * which HTLCOutputInCommitment::transaction_output_index.is_some()). @@ -21531,6 +22143,13 @@ bool ChannelFeatures_eq(const struct LDKChannelFeatures *NONNULL_PTR a, const st */ bool InvoiceFeatures_eq(const struct LDKInvoiceFeatures *NONNULL_PTR a, const struct LDKInvoiceFeatures *NONNULL_PTR b); +/** + * Checks if two ChannelTypeFeaturess 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 ChannelTypeFeatures_eq(const struct LDKChannelTypeFeatures *NONNULL_PTR a, const struct LDKChannelTypeFeatures *NONNULL_PTR b); + /** * Creates a copy of the InitFeatures */ @@ -21551,6 +22170,11 @@ struct LDKChannelFeatures ChannelFeatures_clone(const struct LDKChannelFeatures */ struct LDKInvoiceFeatures InvoiceFeatures_clone(const struct LDKInvoiceFeatures *NONNULL_PTR orig); +/** + * Creates a copy of the ChannelTypeFeatures + */ +struct LDKChannelTypeFeatures ChannelTypeFeatures_clone(const struct LDKChannelTypeFeatures *NONNULL_PTR orig); + /** * Frees any resources used by the InitFeatures, if is_owned is set and inner is non-NULL. */ @@ -21571,6 +22195,11 @@ void ChannelFeatures_free(struct LDKChannelFeatures this_obj); */ void InvoiceFeatures_free(struct LDKInvoiceFeatures this_obj); +/** + * Frees any resources used by the ChannelTypeFeatures, if is_owned is set and inner is non-NULL. + */ +void ChannelTypeFeatures_free(struct LDKChannelTypeFeatures this_obj); + /** * Create a blank Features with no features set */ @@ -21636,19 +22265,20 @@ MUST_USE_RES struct LDKInvoiceFeatures InvoiceFeatures_known(void); MUST_USE_RES bool InvoiceFeatures_requires_unknown_bits(const struct LDKInvoiceFeatures *NONNULL_PTR this_arg); /** - * Returns whether the `payment_secret` feature is supported. + * Create a blank Features with no features set */ -MUST_USE_RES bool InitFeatures_supports_payment_secret(const struct LDKInitFeatures *NONNULL_PTR this_arg); +MUST_USE_RES struct LDKChannelTypeFeatures ChannelTypeFeatures_empty(void); /** - * Returns whether the `payment_secret` feature is supported. + * Creates a Features with the bits set which are known by the implementation */ -MUST_USE_RES bool NodeFeatures_supports_payment_secret(const struct LDKNodeFeatures *NONNULL_PTR this_arg); +MUST_USE_RES struct LDKChannelTypeFeatures ChannelTypeFeatures_known(void); /** - * Returns whether the `payment_secret` feature is supported. + * Returns true if this `Features` object contains unknown feature flags which are set as + * \"required\". */ -MUST_USE_RES bool InvoiceFeatures_supports_payment_secret(const struct LDKInvoiceFeatures *NONNULL_PTR this_arg); +MUST_USE_RES bool ChannelTypeFeatures_requires_unknown_bits(const struct LDKChannelTypeFeatures *NONNULL_PTR this_arg); /** * Serialize the InitFeatures object into a byte array which can be read by InitFeatures_read @@ -21656,9 +22286,9 @@ MUST_USE_RES bool InvoiceFeatures_supports_payment_secret(const struct LDKInvoic struct LDKCVec_u8Z InitFeatures_write(const struct LDKInitFeatures *NONNULL_PTR obj); /** - * Serialize the NodeFeatures object into a byte array which can be read by NodeFeatures_read + * Read a InitFeatures from a byte array, created by InitFeatures_write */ -struct LDKCVec_u8Z NodeFeatures_write(const struct LDKNodeFeatures *NONNULL_PTR obj); +struct LDKCResult_InitFeaturesDecodeErrorZ InitFeatures_read(struct LDKu8slice ser); /** * Serialize the ChannelFeatures object into a byte array which can be read by ChannelFeatures_read @@ -21666,14 +22296,14 @@ struct LDKCVec_u8Z NodeFeatures_write(const struct LDKNodeFeatures *NONNULL_PTR struct LDKCVec_u8Z ChannelFeatures_write(const struct LDKChannelFeatures *NONNULL_PTR obj); /** - * Serialize the InvoiceFeatures object into a byte array which can be read by InvoiceFeatures_read + * Read a ChannelFeatures from a byte array, created by ChannelFeatures_write */ -struct LDKCVec_u8Z InvoiceFeatures_write(const struct LDKInvoiceFeatures *NONNULL_PTR obj); +struct LDKCResult_ChannelFeaturesDecodeErrorZ ChannelFeatures_read(struct LDKu8slice ser); /** - * Read a InitFeatures from a byte array, created by InitFeatures_write + * Serialize the NodeFeatures object into a byte array which can be read by NodeFeatures_read */ -struct LDKCResult_InitFeaturesDecodeErrorZ InitFeatures_read(struct LDKu8slice ser); +struct LDKCVec_u8Z NodeFeatures_write(const struct LDKNodeFeatures *NONNULL_PTR obj); /** * Read a NodeFeatures from a byte array, created by NodeFeatures_write @@ -21681,15 +22311,25 @@ struct LDKCResult_InitFeaturesDecodeErrorZ InitFeatures_read(struct LDKu8slice s struct LDKCResult_NodeFeaturesDecodeErrorZ NodeFeatures_read(struct LDKu8slice ser); /** - * Read a ChannelFeatures from a byte array, created by ChannelFeatures_write + * Serialize the InvoiceFeatures object into a byte array which can be read by InvoiceFeatures_read */ -struct LDKCResult_ChannelFeaturesDecodeErrorZ ChannelFeatures_read(struct LDKu8slice ser); +struct LDKCVec_u8Z InvoiceFeatures_write(const struct LDKInvoiceFeatures *NONNULL_PTR obj); /** * Read a InvoiceFeatures from a byte array, created by InvoiceFeatures_write */ struct LDKCResult_InvoiceFeaturesDecodeErrorZ InvoiceFeatures_read(struct LDKu8slice ser); +/** + * Serialize the ChannelTypeFeatures object into a byte array which can be read by ChannelTypeFeatures_read + */ +struct LDKCVec_u8Z ChannelTypeFeatures_write(const struct LDKChannelTypeFeatures *NONNULL_PTR obj); + +/** + * Read a ChannelTypeFeatures from a byte array, created by ChannelTypeFeatures_write + */ +struct LDKCResult_ChannelTypeFeaturesDecodeErrorZ ChannelTypeFeatures_read(struct LDKu8slice ser); + /** * Frees any resources used by the ShutdownScript, if is_owned is set and inner is non-NULL. */ @@ -21724,6 +22364,11 @@ void InvalidShutdownScript_set_script(struct LDKInvalidShutdownScript *NONNULL_P */ MUST_USE_RES struct LDKInvalidShutdownScript InvalidShutdownScript_new(struct LDKCVec_u8Z script_arg); +/** + * Creates a copy of the InvalidShutdownScript + */ +struct LDKInvalidShutdownScript InvalidShutdownScript_clone(const struct LDKInvalidShutdownScript *NONNULL_PTR orig); + /** * Serialize the ShutdownScript object into a byte array which can be read by ShutdownScript_read */ @@ -21785,26 +22430,6 @@ void CustomMessageReader_free(struct LDKCustomMessageReader this_ptr); */ void Type_free(struct LDKType this_ptr); -/** - * Calls the free function if one is set - */ -void Score_free(struct LDKScore this_ptr); - -/** - * Frees any resources used by the LockableScore, if is_owned is set and inner is non-NULL. - */ -void LockableScore_free(struct LDKLockableScore this_obj); - -/** - * Constructs a new LockableScore from a Score - */ -MUST_USE_RES struct LDKLockableScore LockableScore_new(struct LDKScore score); - -/** - * Serialize the LockableScore object into a byte array which can be read by LockableScore_read - */ -struct LDKCVec_u8Z LockableScore_write(const struct LDKLockableScore *NONNULL_PTR obj); - /** * Frees any resources used by the NodeId, if is_owned is set and inner is non-NULL. */ @@ -22129,11 +22754,6 @@ struct LDKChannelAnnouncement ChannelInfo_get_announcement_message(const struct */ void ChannelInfo_set_announcement_message(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKChannelAnnouncement val); -/** - * Constructs a new ChannelInfo given each field - */ -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 */ @@ -22443,6 +23063,20 @@ void NetworkGraph_close_channel_from_update(const struct LDKNetworkGraph *NONNUL */ void NetworkGraph_fail_node(const struct LDKNetworkGraph *NONNULL_PTR this_arg, struct LDKPublicKey _node_id, bool is_permanent); +/** + * Removes information about channels that we haven't heard any updates about in some time. + * This can be used regularly to prune the network graph of channels that likely no longer + * exist. + * + * While there is no formal requirement that nodes regularly re-broadcast their channel + * updates every two weeks, the non-normative section of BOLT 7 currently suggests that + * pruning occur for updates which are at least two weeks old, which we implement here. + * + * This function takes the current unix time as an argument. For users with the `std` feature + * enabled, [`NetworkGraph::remove_stale_channels`] may be preferable. + */ +void NetworkGraph_remove_stale_channels_with_time(const struct LDKNetworkGraph *NONNULL_PTR this_arg, uint64_t current_time_unix); + /** * For an already known (from announcement) channel, update info about one of the directions * of the channel. @@ -22450,6 +23084,9 @@ void NetworkGraph_fail_node(const struct LDKNetworkGraph *NONNULL_PTR this_arg, * You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept * routing messages from a source using a protocol other than the lightning P2P protocol. + * + * If built with `no-std`, any updates with a timestamp more than two weeks in the past or + * materially in the future will be rejected. */ MUST_USE_RES struct LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel(const struct LDKNetworkGraph *NONNULL_PTR this_arg, const struct LDKChannelUpdate *NONNULL_PTR msg); @@ -22457,6 +23094,9 @@ MUST_USE_RES struct LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel(c * For an already known (from announcement) channel, update info about one of the directions * of the channel without verifying the associated signatures. Because we aren't given the * associated signatures here we cannot relay the channel update to any of our peers. + * + * If built with `no-std`, any updates with a timestamp more than two weeks in the past or + * materially in the future will be rejected. */ MUST_USE_RES struct LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel_unsigned(const struct LDKNetworkGraph *NONNULL_PTR this_arg, const struct LDKUnsignedChannelUpdate *NONNULL_PTR msg); @@ -22994,6 +23634,26 @@ struct LDKCResult_RouteHintHopDecodeErrorZ RouteHintHop_read(struct LDKu8slice s */ struct LDKCResult_RouteLightningErrorZ find_route(struct LDKPublicKey our_node_pubkey, const struct LDKRouteParameters *NONNULL_PTR params, const struct LDKNetworkGraph *NONNULL_PTR network, struct LDKCVec_ChannelDetailsZ *first_hops, struct LDKLogger logger, const struct LDKScore *NONNULL_PTR scorer); +/** + * Calls the free function if one is set + */ +void Score_free(struct LDKScore this_ptr); + +/** + * Calls the free function if one is set + */ +void LockableScore_free(struct LDKLockableScore this_ptr); + +/** + * Frees any resources used by the MultiThreadedLockableScore, if is_owned is set and inner is non-NULL. + */ +void MultiThreadedLockableScore_free(struct LDKMultiThreadedLockableScore this_obj); + +/** + * Creates a new [`MultiThreadedLockableScore`] given an underlying [`Score`]. + */ +MUST_USE_RES struct LDKMultiThreadedLockableScore MultiThreadedLockableScore_new(struct LDKScore score); + /** * Frees any resources used by the Scorer, if is_owned is set and inner is non-NULL. */ @@ -23006,11 +23666,15 @@ void ScoringParameters_free(struct LDKScoringParameters this_obj); /** * A fixed penalty in msats to apply to each channel. + * + * Default value: 500 msat */ uint64_t ScoringParameters_get_base_penalty_msat(const struct LDKScoringParameters *NONNULL_PTR this_ptr); /** * A fixed penalty in msats to apply to each channel. + * + * Default value: 500 msat */ void ScoringParameters_set_base_penalty_msat(struct LDKScoringParameters *NONNULL_PTR this_ptr, uint64_t val); @@ -23018,7 +23682,9 @@ void ScoringParameters_set_base_penalty_msat(struct LDKScoringParameters *NONNUL * A penalty in msats to apply to a channel upon failing to relay a payment. * * This accumulates for each failure but may be reduced over time based on - * [`failure_penalty_half_life`]. + * [`failure_penalty_half_life`] or when successfully routing through a channel. + * + * Default value: 1,024,000 msat * * [`failure_penalty_half_life`]: Self::failure_penalty_half_life */ @@ -23028,20 +23694,66 @@ uint64_t ScoringParameters_get_failure_penalty_msat(const struct LDKScoringParam * A penalty in msats to apply to a channel upon failing to relay a payment. * * This accumulates for each failure but may be reduced over time based on - * [`failure_penalty_half_life`]. + * [`failure_penalty_half_life`] or when successfully routing through a channel. + * + * Default value: 1,024,000 msat * * [`failure_penalty_half_life`]: Self::failure_penalty_half_life */ void ScoringParameters_set_failure_penalty_msat(struct LDKScoringParameters *NONNULL_PTR this_ptr, uint64_t val); +/** + * When the amount being sent over a channel is this many 1024ths of the total channel + * capacity, we begin applying [`overuse_penalty_msat_per_1024th`]. + * + * Default value: 128 1024ths (i.e. begin penalizing when an HTLC uses 1/8th of a channel) + * + * [`overuse_penalty_msat_per_1024th`]: Self::overuse_penalty_msat_per_1024th + */ +uint16_t ScoringParameters_get_overuse_penalty_start_1024th(const struct LDKScoringParameters *NONNULL_PTR this_ptr); + +/** + * When the amount being sent over a channel is this many 1024ths of the total channel + * capacity, we begin applying [`overuse_penalty_msat_per_1024th`]. + * + * Default value: 128 1024ths (i.e. begin penalizing when an HTLC uses 1/8th of a channel) + * + * [`overuse_penalty_msat_per_1024th`]: Self::overuse_penalty_msat_per_1024th + */ +void ScoringParameters_set_overuse_penalty_start_1024th(struct LDKScoringParameters *NONNULL_PTR this_ptr, uint16_t val); + +/** + * A penalty applied, per whole 1024ths of the channel capacity which the amount being sent + * over the channel exceeds [`overuse_penalty_start_1024th`] by. + * + * Default value: 20 msat (i.e. 2560 msat penalty to use 1/4th of a channel, 7680 msat penalty + * to use half a channel, and 12,560 msat penalty to use 3/4ths of a channel) + * + * [`overuse_penalty_start_1024th`]: Self::overuse_penalty_start_1024th + */ +uint64_t ScoringParameters_get_overuse_penalty_msat_per_1024th(const struct LDKScoringParameters *NONNULL_PTR this_ptr); + +/** + * A penalty applied, per whole 1024ths of the channel capacity which the amount being sent + * over the channel exceeds [`overuse_penalty_start_1024th`] by. + * + * Default value: 20 msat (i.e. 2560 msat penalty to use 1/4th of a channel, 7680 msat penalty + * to use half a channel, and 12,560 msat penalty to use 3/4ths of a channel) + * + * [`overuse_penalty_start_1024th`]: Self::overuse_penalty_start_1024th + */ +void ScoringParameters_set_overuse_penalty_msat_per_1024th(struct LDKScoringParameters *NONNULL_PTR this_ptr, uint64_t val); + /** * The time required to elapse before any accumulated [`failure_penalty_msat`] penalties are * cut in half. * + * Successfully routing through a channel will immediately cut the penalty in half as well. + * * # Note * - * When time is an [`Eternity`], as is default when enabling feature `no-std`, it will never - * elapse. Therefore, this penalty will never decay. + * When built with the `no-std` feature, time will never elapse. Therefore, this penalty will + * never decay. * * [`failure_penalty_msat`]: Self::failure_penalty_msat */ @@ -23051,10 +23763,12 @@ uint64_t ScoringParameters_get_failure_penalty_half_life(const struct LDKScoring * The time required to elapse before any accumulated [`failure_penalty_msat`] penalties are * cut in half. * + * Successfully routing through a channel will immediately cut the penalty in half as well. + * * # Note * - * When time is an [`Eternity`], as is default when enabling feature `no-std`, it will never - * elapse. Therefore, this penalty will never decay. + * When built with the `no-std` feature, time will never elapse. Therefore, this penalty will + * never decay. * * [`failure_penalty_msat`]: Self::failure_penalty_msat */ @@ -23063,7 +23777,7 @@ void ScoringParameters_set_failure_penalty_half_life(struct LDKScoringParameters /** * Constructs a new ScoringParameters given each field */ -MUST_USE_RES struct LDKScoringParameters ScoringParameters_new(uint64_t base_penalty_msat_arg, uint64_t failure_penalty_msat_arg, uint64_t failure_penalty_half_life_arg); +MUST_USE_RES struct LDKScoringParameters ScoringParameters_new(uint64_t base_penalty_msat_arg, uint64_t failure_penalty_msat_arg, uint16_t overuse_penalty_start_1024th_arg, uint64_t overuse_penalty_msat_per_1024th_arg, uint64_t failure_penalty_half_life_arg); /** * Serialize the ScoringParameters object into a byte array which can be read by ScoringParameters_read @@ -23175,7 +23889,7 @@ void ChannelManagerPersister_free(struct LDKChannelManagerPersister this_ptr); * functionality implemented by other handlers. * * [`NetGraphMsgHandler`] if given will update the [`NetworkGraph`] based on payment failures. * - * [top-level documentation]: Self + * [top-level documentation]: BackgroundProcessor * [`join`]: Self::join * [`stop`]: Self::stop * [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager @@ -23909,6 +24623,11 @@ enum LDKCreationError CreationError_timestamp_out_of_bounds(void); */ enum LDKCreationError CreationError_expiry_time_out_of_bounds(void); +/** + * Utility method to constructs a new InvalidAmount-variant CreationError + */ +enum LDKCreationError CreationError_invalid_amount(void); + /** * Checks if two CreationErrors contain equal inner contents. * This ignores pointers and is_owned flags and looks at the values in fields. @@ -24094,7 +24813,7 @@ struct LDKPaymentError PaymentError_sending(struct LDKPaymentSendFailure a); * Will forward any [`Event::PaymentPathFailed`] events to the decorated `event_handler` once * `retry_attempts` has been exceeded for a given [`Invoice`]. */ -MUST_USE_RES struct LDKInvoicePayer InvoicePayer_new(struct LDKPayer payer, struct LDKRouter router, const struct LDKLockableScore *NONNULL_PTR scorer, struct LDKLogger logger, struct LDKEventHandler event_handler, struct LDKRetryAttempts retry_attempts); +MUST_USE_RES struct LDKInvoicePayer InvoicePayer_new(struct LDKPayer payer, struct LDKRouter router, const struct LDKMultiThreadedLockableScore *NONNULL_PTR scorer, struct LDKLogger logger, struct LDKEventHandler event_handler, struct LDKRetryAttempts retry_attempts); /** * Pays the given [`Invoice`], caching it for later use in case a retry is needed. @@ -24115,6 +24834,15 @@ MUST_USE_RES struct LDKCResult_PaymentIdPaymentErrorZ InvoicePayer_pay_invoice(c */ MUST_USE_RES struct LDKCResult_PaymentIdPaymentErrorZ InvoicePayer_pay_zero_value_invoice(const struct LDKInvoicePayer *NONNULL_PTR this_arg, const struct LDKInvoice *NONNULL_PTR invoice, uint64_t amount_msats); +/** + * Pays `pubkey` an amount using the hash of the given preimage, caching it for later use in + * case a retry is needed. + * + * You should ensure that `payment_preimage` is unique and that its `payment_hash` has never + * been paid before. Because [`InvoicePayer`] is stateless no effort is made to do so for you. + */ +MUST_USE_RES struct LDKCResult_PaymentIdPaymentErrorZ InvoicePayer_pay_pubkey(const struct LDKInvoicePayer *NONNULL_PTR this_arg, struct LDKPublicKey pubkey, struct LDKThirtyTwoBytes payment_preimage, uint64_t amount_msats, uint32_t final_cltv_expiry_delta); + /** * Removes the payment cached by the given payment hash. * diff --git a/lightning-c-bindings/include/lightningpp.hpp b/lightning-c-bindings/include/lightningpp.hpp index d4c68a5..0b964d7 100644 --- a/lightning-c-bindings/include/lightningpp.hpp +++ b/lightning-c-bindings/include/lightningpp.hpp @@ -45,12 +45,14 @@ class EventsProvider; class EventHandler; class Score; class LockableScore; +class MultiThreadedLockableScore; +class Scorer; +class ScoringParameters; class InitFeatures; class NodeFeatures; class ChannelFeatures; class InvoiceFeatures; -class Scorer; -class ScoringParameters; +class ChannelTypeFeatures; class DelayedPaymentOutputDescriptor; class StaticPaymentOutputDescriptor; class SpendableOutputDescriptor; @@ -99,7 +101,6 @@ class CreationError; class SemanticError; class SignOrCreationError; class ChannelMonitorUpdate; -class MonitorUpdateError; class MonitorEvent; class HTLCUpdate; class Balance; @@ -188,20 +189,20 @@ class COption_NetworkUpdateZ; class COption_u64Z; class CResult_TxOutAccessErrorZ; class CResult_TrustedClosingTransactionNoneZ; +class CResult_PaymentPreimageAPIErrorZ; class CResult_ChannelMonitorUpdateDecodeErrorZ; -class C2Tuple_PublicKeyTypeZ; class CResult_RouteHintDecodeErrorZ; +class C2Tuple_PublicKeyTypeZ; class CResult_NetAddressDecodeErrorZ; class CResult_ChannelReestablishDecodeErrorZ; -class CResult_UnsignedNodeAnnouncementDecodeErrorZ; class CResult_CommitmentSignedDecodeErrorZ; class CVec_UpdateAddHTLCZ; -class CResult_ReplyChannelRangeDecodeErrorZ; +class CResult_UnsignedNodeAnnouncementDecodeErrorZ; +class CResult_StaticPaymentOutputDescriptorDecodeErrorZ; class COption_u32Z; class CResult_InitFeaturesDecodeErrorZ; -class CResult_StaticPaymentOutputDescriptorDecodeErrorZ; class CResult_PaymentIdPaymentSendFailureZ; -class CResult_GossipTimestampFilterDecodeErrorZ; +class CResult_ReplyChannelRangeDecodeErrorZ; class CResult_CommitmentTransactionDecodeErrorZ; class COption_C2Tuple_usizeTransactionZZ; class CResult_TransactionNoneZ; @@ -209,12 +210,12 @@ class CResult_SignedRawInvoiceNoneZ; class CResult_ExpiryTimeCreationErrorZ; class CResult_ClosingSignedFeeRangeDecodeErrorZ; class CResult_PingDecodeErrorZ; -class CResult_InvoiceSignOrCreationErrorZ; +class CResult_GossipTimestampFilterDecodeErrorZ; class CVec_TransactionOutputsZ; class CResult_ErrorMessageDecodeErrorZ; class CResult_OpenChannelDecodeErrorZ; class CVec_CVec_u8ZZ; -class COption_FilterZ; +class CResult_InvoiceSignOrCreationErrorZ; class CResult_SecretKeyErrorZ; class CResult_ShutdownScriptDecodeErrorZ; class CResult_InvoiceNoneZ; @@ -240,6 +241,7 @@ class CResult_NodeAnnouncementInfoDecodeErrorZ; class C3Tuple_RawInvoice_u832InvoiceSignatureZ; class CVec_UpdateFailMalformedHTLCZ; class CResult_FundingSignedDecodeErrorZ; +class COption_FilterZ; class CResult_NetworkGraphDecodeErrorZ; class CVec_RouteHopZ; class CVec_C2Tuple_BlockHashChannelMonitorZZ; @@ -253,6 +255,7 @@ class CResult_HolderCommitmentTransactionDecodeErrorZ; class CVec_CResult_NoneAPIErrorZZ; class CResult_SignatureNoneZ; class CVec_RouteHintHopZ; +class CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ; class C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ; class CResult_InitDecodeErrorZ; class CResult_OutPointDecodeErrorZ; @@ -265,27 +268,28 @@ class CResult_UpdateFailMalformedHTLCDecodeErrorZ; class CVec_NodeAnnouncementZ; class CResult_UnsignedChannelAnnouncementDecodeErrorZ; class CVec_TxidZ; -class CResult_NoneMonitorUpdateErrorZ; +class COption_AccessZ; class CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ; class CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ; class CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ; class CResult_CVec_CVec_u8ZZNoneZ; class C2Tuple_PaymentHashPaymentSecretZ; -class COption_AccessZ; +class CResult_AcceptChannelDecodeErrorZ; class C2Tuple_BlockHashChannelManagerZ; class CResult_ChannelTransactionParametersDecodeErrorZ; -class CResult_AcceptChannelDecodeErrorZ; +class CResult_PongDecodeErrorZ; class CVec_SignatureZ; class CVec_u64Z; class CResult_ScorerDecodeErrorZ; class CResult_DelayedPaymentOutputDescriptorDecodeErrorZ; class C2Tuple_PaymentHashPaymentIdZ; -class CResult_StringErrorZ; +class CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ; class CResult_NoneErrorZ; +class CResult_StringErrorZ; class C2Tuple_TxidCVec_C2Tuple_u32ScriptZZZ; -class CResult_PongDecodeErrorZ; class CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ; class COption_EventZ; +class CResult_ChannelTypeFeaturesDecodeErrorZ; class CVec_RouteHintZ; class COption_u16Z; class CVec_CVec_RouteHopZZ; @@ -317,6 +321,7 @@ class CResult_COption_TypeZDecodeErrorZ; class CResult_DirectionalChannelInfoDecodeErrorZ; class C2Tuple_u32TxOutZ; class CResult_UpdateFailHTLCDecodeErrorZ; +class CResult_PaymentSecretNoneZ; class CResult_ChannelConfigDecodeErrorZ; class CVec_PrivateRouteZ; class CResult_SpendableOutputDescriptorDecodeErrorZ; @@ -332,9 +337,9 @@ class CResult_COption_ClosureReasonZDecodeErrorZ; class CResult_SiPrefixNoneZ; class CResult_PublicKeyErrorZ; class C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ; -class CResult_NoneNoneZ; class CResult_RouteParametersDecodeErrorZ; class COption_ClosureReasonZ; +class CResult_NoneNoneZ; class CVec_APIErrorZ; class CResult_PrivateRouteCreationErrorZ; class CResult_boolPeerHandleErrorZ; @@ -349,8 +354,9 @@ class C2Tuple_u32ScriptZ; class CResult_ReplyShortChannelIdsEndDecodeErrorZ; class CResult_RouteDecodeErrorZ; class CResult_BuiltCommitmentTransactionDecodeErrorZ; -class CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ; +class COption_NoneZ; class CVec_TxOutZ; +class CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ; class CVec_UpdateFailHTLCZ; class CResult_FundingLockedDecodeErrorZ; @@ -756,12 +762,12 @@ public: /** * Gets estimated satoshis of fee required per 1000 Weight-Units. * - * Must be no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later round-downs - * don't put us below 1 satoshi-per-byte). + * Must return a value no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later + * round-downs don't put us below 1 satoshi-per-byte). * - * This translates to: - * * satoshis-per-byte * 250 - * * ceil(satoshis-per-kbyte / 4) + * This method can be implemented with the following unit conversions: + * * max(satoshis-per-byte * 250, 253) + * * max(satoshis-per-kbyte / 4, 253) */ inline uint32_t get_est_sat_per_1000_weight(enum LDKConfirmationTarget confirmation_target); }; @@ -1156,14 +1162,28 @@ public: 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 - * in the direction from `source` to `target`. + * Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the + * given channel in the direction from `source` to `target`. + * + * The channel's capacity (less any other MPP parts which are also being considered for use in + * the same payment) is given by `channel_capacity_msat`. It may be guessed from various + * sources or assumed from no data at all. + * + * For hints provided in the invoice, we assume the channel has sufficient capacity to accept + * the invoice's full amount, and provide a `channel_capacity_msat` of `None`. In all other + * cases it is set to `Some`, even if we're guessing at the channel value. + * + * Your code should be overflow-safe through a `channel_capacity_msat` of 21 million BTC. */ - inline uint64_t channel_penalty_msat(uint64_t short_channel_id, const struct LDKNodeId *NONNULL_PTR source, const struct LDKNodeId *NONNULL_PTR target); + inline uint64_t channel_penalty_msat(uint64_t short_channel_id, uint64_t send_amt_msat, struct LDKCOption_u64Z channel_capacity_msat, const struct LDKNodeId *NONNULL_PTR source, const struct LDKNodeId *NONNULL_PTR target); /** * Handles updating channel penalties after failing to route through a channel. */ inline void payment_path_failed(struct LDKCVec_RouteHopZ path, uint64_t short_channel_id); + /** + * Handles updating channel penalties after successfully routing along a path. + */ + inline void payment_path_successful(struct LDKCVec_RouteHopZ path); }; class LockableScore { private: @@ -1179,6 +1199,55 @@ public: LDKLockableScore* operator ->() { return &self; } const LDKLockableScore* operator &() const { return &self; } const LDKLockableScore* operator ->() const { return &self; } + /** + * Returns the locked scorer. + */ + inline LDK::Score lock(); +}; +class MultiThreadedLockableScore { +private: + LDKMultiThreadedLockableScore self; +public: + MultiThreadedLockableScore(const MultiThreadedLockableScore&) = delete; + MultiThreadedLockableScore(MultiThreadedLockableScore&& o) : self(o.self) { memset(&o, 0, sizeof(MultiThreadedLockableScore)); } + MultiThreadedLockableScore(LDKMultiThreadedLockableScore&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKMultiThreadedLockableScore)); } + operator LDKMultiThreadedLockableScore() && { LDKMultiThreadedLockableScore res = self; memset(&self, 0, sizeof(LDKMultiThreadedLockableScore)); return res; } + ~MultiThreadedLockableScore() { MultiThreadedLockableScore_free(self); } + MultiThreadedLockableScore& operator=(MultiThreadedLockableScore&& o) { MultiThreadedLockableScore_free(self); self = o.self; memset(&o, 0, sizeof(MultiThreadedLockableScore)); return *this; } + LDKMultiThreadedLockableScore* operator &() { return &self; } + LDKMultiThreadedLockableScore* operator ->() { return &self; } + const LDKMultiThreadedLockableScore* operator &() const { return &self; } + const LDKMultiThreadedLockableScore* 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 ScoringParameters { +private: + LDKScoringParameters self; +public: + ScoringParameters(const ScoringParameters&) = delete; + ScoringParameters(ScoringParameters&& o) : self(o.self) { memset(&o, 0, sizeof(ScoringParameters)); } + ScoringParameters(LDKScoringParameters&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKScoringParameters)); } + operator LDKScoringParameters() && { LDKScoringParameters res = self; memset(&self, 0, sizeof(LDKScoringParameters)); return res; } + ~ScoringParameters() { ScoringParameters_free(self); } + ScoringParameters& operator=(ScoringParameters&& o) { ScoringParameters_free(self); self = o.self; memset(&o, 0, sizeof(ScoringParameters)); return *this; } + LDKScoringParameters* operator &() { return &self; } + LDKScoringParameters* operator ->() { return &self; } + const LDKScoringParameters* operator &() const { return &self; } + const LDKScoringParameters* operator ->() const { return &self; } }; class InitFeatures { private: @@ -1240,35 +1309,20 @@ public: const LDKInvoiceFeatures* operator &() const { return &self; } const LDKInvoiceFeatures* operator ->() const { return &self; } }; -class Scorer { +class ChannelTypeFeatures { private: - LDKScorer self; + LDKChannelTypeFeatures 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 ScoringParameters { -private: - LDKScoringParameters self; -public: - ScoringParameters(const ScoringParameters&) = delete; - ScoringParameters(ScoringParameters&& o) : self(o.self) { memset(&o, 0, sizeof(ScoringParameters)); } - ScoringParameters(LDKScoringParameters&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKScoringParameters)); } - operator LDKScoringParameters() && { LDKScoringParameters res = self; memset(&self, 0, sizeof(LDKScoringParameters)); return res; } - ~ScoringParameters() { ScoringParameters_free(self); } - ScoringParameters& operator=(ScoringParameters&& o) { ScoringParameters_free(self); self = o.self; memset(&o, 0, sizeof(ScoringParameters)); return *this; } - LDKScoringParameters* operator &() { return &self; } - LDKScoringParameters* operator ->() { return &self; } - const LDKScoringParameters* operator &() const { return &self; } - const LDKScoringParameters* operator ->() const { return &self; } + ChannelTypeFeatures(const ChannelTypeFeatures&) = delete; + ChannelTypeFeatures(ChannelTypeFeatures&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelTypeFeatures)); } + ChannelTypeFeatures(LDKChannelTypeFeatures&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelTypeFeatures)); } + operator LDKChannelTypeFeatures() && { LDKChannelTypeFeatures res = self; memset(&self, 0, sizeof(LDKChannelTypeFeatures)); return res; } + ~ChannelTypeFeatures() { ChannelTypeFeatures_free(self); } + ChannelTypeFeatures& operator=(ChannelTypeFeatures&& o) { ChannelTypeFeatures_free(self); self = o.self; memset(&o, 0, sizeof(ChannelTypeFeatures)); return *this; } + LDKChannelTypeFeatures* operator &() { return &self; } + LDKChannelTypeFeatures* operator ->() { return &self; } + const LDKChannelTypeFeatures* operator &() const { return &self; } + const LDKChannelTypeFeatures* operator ->() const { return &self; } }; class DelayedPaymentOutputDescriptor { private: @@ -1558,6 +1612,12 @@ public: * blindly signing the hash. */ inline LDK::CResult_RecoverableSignatureNoneZ sign_invoice(struct LDKCVec_u8Z invoice_preimage); + /** + * Get secret key material as bytes for use in encrypting and decrypting inbound payment data. + * + * This method must return the same value each time it is called. + */ + inline LDKThirtyTwoBytes get_inbound_payment_key_material(); }; class InMemorySigner { private: @@ -1887,10 +1947,18 @@ public: * Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None */ inline LDK::CResult_PaymentIdPaymentSendFailureZ send_payment(const struct LDKRoute *NONNULL_PTR route, struct LDKThirtyTwoBytes payment_hash, struct LDKThirtyTwoBytes payment_secret); + /** + * Sends a spontaneous payment over the Lightning Network using the given [`Route`]. + */ + inline LDK::CResult_PaymentIdPaymentSendFailureZ send_spontaneous_payment(const struct LDKRoute *NONNULL_PTR route, struct LDKThirtyTwoBytes payment_preimage); /** * Retries a failed payment path for the [`PaymentId`] using the given [`Route`]. */ inline LDK::CResult_NonePaymentSendFailureZ retry_payment(const struct LDKRoute *NONNULL_PTR route, struct LDKThirtyTwoBytes payment_id); + /** + * Signals that no further retries for the given payment will occur. + */ + inline void abandon_payment(struct LDKThirtyTwoBytes payment_id); }; class Router { private: @@ -1911,7 +1979,7 @@ public: * * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None */ - inline LDK::CResult_RouteLightningErrorZ find_route(struct LDKPublicKey payer, const struct LDKRouteParameters *NONNULL_PTR params, struct LDKCVec_ChannelDetailsZ *first_hops, const struct LDKScore *NONNULL_PTR scorer); + inline LDK::CResult_RouteLightningErrorZ find_route(struct LDKPublicKey payer, const struct LDKRouteParameters *NONNULL_PTR params, const uint8_t (*payment_hash)[32], struct LDKCVec_ChannelDetailsZ *first_hops, const struct LDKScore *NONNULL_PTR scorer); }; class RetryAttempts { private: @@ -2224,21 +2292,6 @@ public: const LDKChannelMonitorUpdate* operator &() const { return &self; } const LDKChannelMonitorUpdate* operator ->() const { return &self; } }; -class MonitorUpdateError { -private: - LDKMonitorUpdateError self; -public: - MonitorUpdateError(const MonitorUpdateError&) = delete; - MonitorUpdateError(MonitorUpdateError&& o) : self(o.self) { memset(&o, 0, sizeof(MonitorUpdateError)); } - MonitorUpdateError(LDKMonitorUpdateError&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKMonitorUpdateError)); } - operator LDKMonitorUpdateError() && { LDKMonitorUpdateError res = self; memset(&self, 0, sizeof(LDKMonitorUpdateError)); return res; } - ~MonitorUpdateError() { MonitorUpdateError_free(self); } - MonitorUpdateError& operator=(MonitorUpdateError&& o) { MonitorUpdateError_free(self); self = o.self; memset(&o, 0, sizeof(MonitorUpdateError)); return *this; } - LDKMonitorUpdateError* operator &() { return &self; } - LDKMonitorUpdateError* operator ->() { return &self; } - const LDKMonitorUpdateError* operator &() const { return &self; } - const LDKMonitorUpdateError* operator ->() const { return &self; } -}; class MonitorEvent { private: LDKMonitorEvent self; @@ -3806,6 +3859,21 @@ public: const LDKCResult_TrustedClosingTransactionNoneZ* operator &() const { return &self; } const LDKCResult_TrustedClosingTransactionNoneZ* operator ->() const { return &self; } }; +class CResult_PaymentPreimageAPIErrorZ { +private: + LDKCResult_PaymentPreimageAPIErrorZ self; +public: + CResult_PaymentPreimageAPIErrorZ(const CResult_PaymentPreimageAPIErrorZ&) = delete; + CResult_PaymentPreimageAPIErrorZ(CResult_PaymentPreimageAPIErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_PaymentPreimageAPIErrorZ)); } + CResult_PaymentPreimageAPIErrorZ(LDKCResult_PaymentPreimageAPIErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_PaymentPreimageAPIErrorZ)); } + operator LDKCResult_PaymentPreimageAPIErrorZ() && { LDKCResult_PaymentPreimageAPIErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_PaymentPreimageAPIErrorZ)); return res; } + ~CResult_PaymentPreimageAPIErrorZ() { CResult_PaymentPreimageAPIErrorZ_free(self); } + CResult_PaymentPreimageAPIErrorZ& operator=(CResult_PaymentPreimageAPIErrorZ&& o) { CResult_PaymentPreimageAPIErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_PaymentPreimageAPIErrorZ)); return *this; } + LDKCResult_PaymentPreimageAPIErrorZ* operator &() { return &self; } + LDKCResult_PaymentPreimageAPIErrorZ* operator ->() { return &self; } + const LDKCResult_PaymentPreimageAPIErrorZ* operator &() const { return &self; } + const LDKCResult_PaymentPreimageAPIErrorZ* operator ->() const { return &self; } +}; class CResult_ChannelMonitorUpdateDecodeErrorZ { private: LDKCResult_ChannelMonitorUpdateDecodeErrorZ self; @@ -3821,21 +3889,6 @@ public: const LDKCResult_ChannelMonitorUpdateDecodeErrorZ* operator &() const { return &self; } const LDKCResult_ChannelMonitorUpdateDecodeErrorZ* operator ->() const { return &self; } }; -class C2Tuple_PublicKeyTypeZ { -private: - LDKC2Tuple_PublicKeyTypeZ self; -public: - C2Tuple_PublicKeyTypeZ(const C2Tuple_PublicKeyTypeZ&) = delete; - C2Tuple_PublicKeyTypeZ(C2Tuple_PublicKeyTypeZ&& o) : self(o.self) { memset(&o, 0, sizeof(C2Tuple_PublicKeyTypeZ)); } - C2Tuple_PublicKeyTypeZ(LDKC2Tuple_PublicKeyTypeZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKC2Tuple_PublicKeyTypeZ)); } - operator LDKC2Tuple_PublicKeyTypeZ() && { LDKC2Tuple_PublicKeyTypeZ res = self; memset(&self, 0, sizeof(LDKC2Tuple_PublicKeyTypeZ)); return res; } - ~C2Tuple_PublicKeyTypeZ() { C2Tuple_PublicKeyTypeZ_free(self); } - C2Tuple_PublicKeyTypeZ& operator=(C2Tuple_PublicKeyTypeZ&& o) { C2Tuple_PublicKeyTypeZ_free(self); self = o.self; memset(&o, 0, sizeof(C2Tuple_PublicKeyTypeZ)); return *this; } - LDKC2Tuple_PublicKeyTypeZ* operator &() { return &self; } - LDKC2Tuple_PublicKeyTypeZ* operator ->() { return &self; } - const LDKC2Tuple_PublicKeyTypeZ* operator &() const { return &self; } - const LDKC2Tuple_PublicKeyTypeZ* operator ->() const { return &self; } -}; class CResult_RouteHintDecodeErrorZ { private: LDKCResult_RouteHintDecodeErrorZ self; @@ -3851,6 +3904,21 @@ public: const LDKCResult_RouteHintDecodeErrorZ* operator &() const { return &self; } const LDKCResult_RouteHintDecodeErrorZ* operator ->() const { return &self; } }; +class C2Tuple_PublicKeyTypeZ { +private: + LDKC2Tuple_PublicKeyTypeZ self; +public: + C2Tuple_PublicKeyTypeZ(const C2Tuple_PublicKeyTypeZ&) = delete; + C2Tuple_PublicKeyTypeZ(C2Tuple_PublicKeyTypeZ&& o) : self(o.self) { memset(&o, 0, sizeof(C2Tuple_PublicKeyTypeZ)); } + C2Tuple_PublicKeyTypeZ(LDKC2Tuple_PublicKeyTypeZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKC2Tuple_PublicKeyTypeZ)); } + operator LDKC2Tuple_PublicKeyTypeZ() && { LDKC2Tuple_PublicKeyTypeZ res = self; memset(&self, 0, sizeof(LDKC2Tuple_PublicKeyTypeZ)); return res; } + ~C2Tuple_PublicKeyTypeZ() { C2Tuple_PublicKeyTypeZ_free(self); } + C2Tuple_PublicKeyTypeZ& operator=(C2Tuple_PublicKeyTypeZ&& o) { C2Tuple_PublicKeyTypeZ_free(self); self = o.self; memset(&o, 0, sizeof(C2Tuple_PublicKeyTypeZ)); return *this; } + LDKC2Tuple_PublicKeyTypeZ* operator &() { return &self; } + LDKC2Tuple_PublicKeyTypeZ* operator ->() { return &self; } + const LDKC2Tuple_PublicKeyTypeZ* operator &() const { return &self; } + const LDKC2Tuple_PublicKeyTypeZ* operator ->() const { return &self; } +}; class CResult_NetAddressDecodeErrorZ { private: LDKCResult_NetAddressDecodeErrorZ self; @@ -3881,21 +3949,6 @@ public: const LDKCResult_ChannelReestablishDecodeErrorZ* operator &() const { return &self; } const LDKCResult_ChannelReestablishDecodeErrorZ* operator ->() const { return &self; } }; -class CResult_UnsignedNodeAnnouncementDecodeErrorZ { -private: - LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ self; -public: - CResult_UnsignedNodeAnnouncementDecodeErrorZ(const CResult_UnsignedNodeAnnouncementDecodeErrorZ&) = delete; - CResult_UnsignedNodeAnnouncementDecodeErrorZ(CResult_UnsignedNodeAnnouncementDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_UnsignedNodeAnnouncementDecodeErrorZ)); } - CResult_UnsignedNodeAnnouncementDecodeErrorZ(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ)); } - operator LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ() && { LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ)); return res; } - ~CResult_UnsignedNodeAnnouncementDecodeErrorZ() { CResult_UnsignedNodeAnnouncementDecodeErrorZ_free(self); } - CResult_UnsignedNodeAnnouncementDecodeErrorZ& operator=(CResult_UnsignedNodeAnnouncementDecodeErrorZ&& o) { CResult_UnsignedNodeAnnouncementDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_UnsignedNodeAnnouncementDecodeErrorZ)); return *this; } - LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* operator &() { return &self; } - LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* operator ->() const { return &self; } -}; class CResult_CommitmentSignedDecodeErrorZ { private: LDKCResult_CommitmentSignedDecodeErrorZ self; @@ -3926,20 +3979,35 @@ public: const LDKCVec_UpdateAddHTLCZ* operator &() const { return &self; } const LDKCVec_UpdateAddHTLCZ* operator ->() const { return &self; } }; -class CResult_ReplyChannelRangeDecodeErrorZ { +class CResult_UnsignedNodeAnnouncementDecodeErrorZ { private: - LDKCResult_ReplyChannelRangeDecodeErrorZ self; + LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ self; public: - CResult_ReplyChannelRangeDecodeErrorZ(const CResult_ReplyChannelRangeDecodeErrorZ&) = delete; - CResult_ReplyChannelRangeDecodeErrorZ(CResult_ReplyChannelRangeDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ReplyChannelRangeDecodeErrorZ)); } - CResult_ReplyChannelRangeDecodeErrorZ(LDKCResult_ReplyChannelRangeDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ)); } - operator LDKCResult_ReplyChannelRangeDecodeErrorZ() && { LDKCResult_ReplyChannelRangeDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ)); return res; } - ~CResult_ReplyChannelRangeDecodeErrorZ() { CResult_ReplyChannelRangeDecodeErrorZ_free(self); } - CResult_ReplyChannelRangeDecodeErrorZ& operator=(CResult_ReplyChannelRangeDecodeErrorZ&& o) { CResult_ReplyChannelRangeDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_ReplyChannelRangeDecodeErrorZ)); return *this; } - LDKCResult_ReplyChannelRangeDecodeErrorZ* operator &() { return &self; } - LDKCResult_ReplyChannelRangeDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_ReplyChannelRangeDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_ReplyChannelRangeDecodeErrorZ* operator ->() const { return &self; } + CResult_UnsignedNodeAnnouncementDecodeErrorZ(const CResult_UnsignedNodeAnnouncementDecodeErrorZ&) = delete; + CResult_UnsignedNodeAnnouncementDecodeErrorZ(CResult_UnsignedNodeAnnouncementDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_UnsignedNodeAnnouncementDecodeErrorZ)); } + CResult_UnsignedNodeAnnouncementDecodeErrorZ(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ)); } + operator LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ() && { LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ)); return res; } + ~CResult_UnsignedNodeAnnouncementDecodeErrorZ() { CResult_UnsignedNodeAnnouncementDecodeErrorZ_free(self); } + CResult_UnsignedNodeAnnouncementDecodeErrorZ& operator=(CResult_UnsignedNodeAnnouncementDecodeErrorZ&& o) { CResult_UnsignedNodeAnnouncementDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_UnsignedNodeAnnouncementDecodeErrorZ)); return *this; } + LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* operator &() { return &self; } + LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* operator ->() { return &self; } + const LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* operator &() const { return &self; } + const LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* operator ->() const { return &self; } +}; +class CResult_StaticPaymentOutputDescriptorDecodeErrorZ { +private: + LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ self; +public: + CResult_StaticPaymentOutputDescriptorDecodeErrorZ(const CResult_StaticPaymentOutputDescriptorDecodeErrorZ&) = delete; + CResult_StaticPaymentOutputDescriptorDecodeErrorZ(CResult_StaticPaymentOutputDescriptorDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_StaticPaymentOutputDescriptorDecodeErrorZ)); } + CResult_StaticPaymentOutputDescriptorDecodeErrorZ(LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ)); } + operator LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ() && { LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ)); return res; } + ~CResult_StaticPaymentOutputDescriptorDecodeErrorZ() { CResult_StaticPaymentOutputDescriptorDecodeErrorZ_free(self); } + CResult_StaticPaymentOutputDescriptorDecodeErrorZ& operator=(CResult_StaticPaymentOutputDescriptorDecodeErrorZ&& o) { CResult_StaticPaymentOutputDescriptorDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_StaticPaymentOutputDescriptorDecodeErrorZ)); return *this; } + LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ* operator &() { return &self; } + LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ* operator ->() { return &self; } + const LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ* operator &() const { return &self; } + const LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ* operator ->() const { return &self; } }; class COption_u32Z { private: @@ -3971,21 +4039,6 @@ public: const LDKCResult_InitFeaturesDecodeErrorZ* operator &() const { return &self; } const LDKCResult_InitFeaturesDecodeErrorZ* operator ->() const { return &self; } }; -class CResult_StaticPaymentOutputDescriptorDecodeErrorZ { -private: - LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ self; -public: - CResult_StaticPaymentOutputDescriptorDecodeErrorZ(const CResult_StaticPaymentOutputDescriptorDecodeErrorZ&) = delete; - CResult_StaticPaymentOutputDescriptorDecodeErrorZ(CResult_StaticPaymentOutputDescriptorDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_StaticPaymentOutputDescriptorDecodeErrorZ)); } - CResult_StaticPaymentOutputDescriptorDecodeErrorZ(LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ)); } - operator LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ() && { LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ)); return res; } - ~CResult_StaticPaymentOutputDescriptorDecodeErrorZ() { CResult_StaticPaymentOutputDescriptorDecodeErrorZ_free(self); } - CResult_StaticPaymentOutputDescriptorDecodeErrorZ& operator=(CResult_StaticPaymentOutputDescriptorDecodeErrorZ&& o) { CResult_StaticPaymentOutputDescriptorDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_StaticPaymentOutputDescriptorDecodeErrorZ)); return *this; } - LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ* operator &() { return &self; } - LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_StaticPaymentOutputDescriptorDecodeErrorZ* operator ->() const { return &self; } -}; class CResult_PaymentIdPaymentSendFailureZ { private: LDKCResult_PaymentIdPaymentSendFailureZ self; @@ -4001,20 +4054,20 @@ public: const LDKCResult_PaymentIdPaymentSendFailureZ* operator &() const { return &self; } const LDKCResult_PaymentIdPaymentSendFailureZ* operator ->() const { return &self; } }; -class CResult_GossipTimestampFilterDecodeErrorZ { +class CResult_ReplyChannelRangeDecodeErrorZ { private: - LDKCResult_GossipTimestampFilterDecodeErrorZ self; + LDKCResult_ReplyChannelRangeDecodeErrorZ self; public: - CResult_GossipTimestampFilterDecodeErrorZ(const CResult_GossipTimestampFilterDecodeErrorZ&) = delete; - CResult_GossipTimestampFilterDecodeErrorZ(CResult_GossipTimestampFilterDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_GossipTimestampFilterDecodeErrorZ)); } - CResult_GossipTimestampFilterDecodeErrorZ(LDKCResult_GossipTimestampFilterDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ)); } - operator LDKCResult_GossipTimestampFilterDecodeErrorZ() && { LDKCResult_GossipTimestampFilterDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ)); return res; } - ~CResult_GossipTimestampFilterDecodeErrorZ() { CResult_GossipTimestampFilterDecodeErrorZ_free(self); } - CResult_GossipTimestampFilterDecodeErrorZ& operator=(CResult_GossipTimestampFilterDecodeErrorZ&& o) { CResult_GossipTimestampFilterDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_GossipTimestampFilterDecodeErrorZ)); return *this; } - LDKCResult_GossipTimestampFilterDecodeErrorZ* operator &() { return &self; } - LDKCResult_GossipTimestampFilterDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_GossipTimestampFilterDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_GossipTimestampFilterDecodeErrorZ* operator ->() const { return &self; } + CResult_ReplyChannelRangeDecodeErrorZ(const CResult_ReplyChannelRangeDecodeErrorZ&) = delete; + CResult_ReplyChannelRangeDecodeErrorZ(CResult_ReplyChannelRangeDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ReplyChannelRangeDecodeErrorZ)); } + CResult_ReplyChannelRangeDecodeErrorZ(LDKCResult_ReplyChannelRangeDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ)); } + operator LDKCResult_ReplyChannelRangeDecodeErrorZ() && { LDKCResult_ReplyChannelRangeDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ)); return res; } + ~CResult_ReplyChannelRangeDecodeErrorZ() { CResult_ReplyChannelRangeDecodeErrorZ_free(self); } + CResult_ReplyChannelRangeDecodeErrorZ& operator=(CResult_ReplyChannelRangeDecodeErrorZ&& o) { CResult_ReplyChannelRangeDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_ReplyChannelRangeDecodeErrorZ)); return *this; } + LDKCResult_ReplyChannelRangeDecodeErrorZ* operator &() { return &self; } + LDKCResult_ReplyChannelRangeDecodeErrorZ* operator ->() { return &self; } + const LDKCResult_ReplyChannelRangeDecodeErrorZ* operator &() const { return &self; } + const LDKCResult_ReplyChannelRangeDecodeErrorZ* operator ->() const { return &self; } }; class CResult_CommitmentTransactionDecodeErrorZ { private: @@ -4121,20 +4174,20 @@ public: const LDKCResult_PingDecodeErrorZ* operator &() const { return &self; } const LDKCResult_PingDecodeErrorZ* operator ->() const { return &self; } }; -class CResult_InvoiceSignOrCreationErrorZ { +class CResult_GossipTimestampFilterDecodeErrorZ { private: - LDKCResult_InvoiceSignOrCreationErrorZ self; + LDKCResult_GossipTimestampFilterDecodeErrorZ self; public: - CResult_InvoiceSignOrCreationErrorZ(const CResult_InvoiceSignOrCreationErrorZ&) = delete; - CResult_InvoiceSignOrCreationErrorZ(CResult_InvoiceSignOrCreationErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_InvoiceSignOrCreationErrorZ)); } - CResult_InvoiceSignOrCreationErrorZ(LDKCResult_InvoiceSignOrCreationErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_InvoiceSignOrCreationErrorZ)); } - operator LDKCResult_InvoiceSignOrCreationErrorZ() && { LDKCResult_InvoiceSignOrCreationErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_InvoiceSignOrCreationErrorZ)); return res; } - ~CResult_InvoiceSignOrCreationErrorZ() { CResult_InvoiceSignOrCreationErrorZ_free(self); } - CResult_InvoiceSignOrCreationErrorZ& operator=(CResult_InvoiceSignOrCreationErrorZ&& o) { CResult_InvoiceSignOrCreationErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_InvoiceSignOrCreationErrorZ)); return *this; } - LDKCResult_InvoiceSignOrCreationErrorZ* operator &() { return &self; } - LDKCResult_InvoiceSignOrCreationErrorZ* operator ->() { return &self; } - const LDKCResult_InvoiceSignOrCreationErrorZ* operator &() const { return &self; } - const LDKCResult_InvoiceSignOrCreationErrorZ* operator ->() const { return &self; } + CResult_GossipTimestampFilterDecodeErrorZ(const CResult_GossipTimestampFilterDecodeErrorZ&) = delete; + CResult_GossipTimestampFilterDecodeErrorZ(CResult_GossipTimestampFilterDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_GossipTimestampFilterDecodeErrorZ)); } + CResult_GossipTimestampFilterDecodeErrorZ(LDKCResult_GossipTimestampFilterDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ)); } + operator LDKCResult_GossipTimestampFilterDecodeErrorZ() && { LDKCResult_GossipTimestampFilterDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ)); return res; } + ~CResult_GossipTimestampFilterDecodeErrorZ() { CResult_GossipTimestampFilterDecodeErrorZ_free(self); } + CResult_GossipTimestampFilterDecodeErrorZ& operator=(CResult_GossipTimestampFilterDecodeErrorZ&& o) { CResult_GossipTimestampFilterDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_GossipTimestampFilterDecodeErrorZ)); return *this; } + LDKCResult_GossipTimestampFilterDecodeErrorZ* operator &() { return &self; } + LDKCResult_GossipTimestampFilterDecodeErrorZ* operator ->() { return &self; } + const LDKCResult_GossipTimestampFilterDecodeErrorZ* operator &() const { return &self; } + const LDKCResult_GossipTimestampFilterDecodeErrorZ* operator ->() const { return &self; } }; class CVec_TransactionOutputsZ { private: @@ -4196,20 +4249,20 @@ public: const LDKCVec_CVec_u8ZZ* operator &() const { return &self; } const LDKCVec_CVec_u8ZZ* operator ->() const { return &self; } }; -class COption_FilterZ { +class CResult_InvoiceSignOrCreationErrorZ { private: - LDKCOption_FilterZ self; + LDKCResult_InvoiceSignOrCreationErrorZ 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; } + CResult_InvoiceSignOrCreationErrorZ(const CResult_InvoiceSignOrCreationErrorZ&) = delete; + CResult_InvoiceSignOrCreationErrorZ(CResult_InvoiceSignOrCreationErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_InvoiceSignOrCreationErrorZ)); } + CResult_InvoiceSignOrCreationErrorZ(LDKCResult_InvoiceSignOrCreationErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_InvoiceSignOrCreationErrorZ)); } + operator LDKCResult_InvoiceSignOrCreationErrorZ() && { LDKCResult_InvoiceSignOrCreationErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_InvoiceSignOrCreationErrorZ)); return res; } + ~CResult_InvoiceSignOrCreationErrorZ() { CResult_InvoiceSignOrCreationErrorZ_free(self); } + CResult_InvoiceSignOrCreationErrorZ& operator=(CResult_InvoiceSignOrCreationErrorZ&& o) { CResult_InvoiceSignOrCreationErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_InvoiceSignOrCreationErrorZ)); return *this; } + LDKCResult_InvoiceSignOrCreationErrorZ* operator &() { return &self; } + LDKCResult_InvoiceSignOrCreationErrorZ* operator ->() { return &self; } + const LDKCResult_InvoiceSignOrCreationErrorZ* operator &() const { return &self; } + const LDKCResult_InvoiceSignOrCreationErrorZ* operator ->() const { return &self; } }; class CResult_SecretKeyErrorZ { private: @@ -4586,6 +4639,21 @@ public: const LDKCResult_FundingSignedDecodeErrorZ* operator &() const { return &self; } const LDKCResult_FundingSignedDecodeErrorZ* 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_NetworkGraphDecodeErrorZ { private: LDKCResult_NetworkGraphDecodeErrorZ self; @@ -4781,6 +4849,21 @@ public: const LDKCVec_RouteHintHopZ* operator &() const { return &self; } const LDKCVec_RouteHintHopZ* operator ->() const { return &self; } }; +class CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ { +private: + LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZ self; +public: + CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ(const CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ&) = delete; + CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ(CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ)); } + CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ(LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZ)); } + operator LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZ() && { LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZ res = self; memset(&self, 0, sizeof(LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZ)); return res; } + ~CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ() { CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ_free(self); } + CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ& operator=(CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ&& o) { CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ)); return *this; } + LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZ* operator &() { return &self; } + LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZ* operator ->() { return &self; } + const LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZ* operator &() const { return &self; } + const LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZ* operator ->() const { return &self; } +}; class C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ { private: LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ self; @@ -4961,20 +5044,20 @@ public: const LDKCVec_TxidZ* operator &() const { return &self; } const LDKCVec_TxidZ* operator ->() const { return &self; } }; -class CResult_NoneMonitorUpdateErrorZ { +class COption_AccessZ { private: - LDKCResult_NoneMonitorUpdateErrorZ self; + LDKCOption_AccessZ self; public: - CResult_NoneMonitorUpdateErrorZ(const CResult_NoneMonitorUpdateErrorZ&) = delete; - CResult_NoneMonitorUpdateErrorZ(CResult_NoneMonitorUpdateErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NoneMonitorUpdateErrorZ)); } - CResult_NoneMonitorUpdateErrorZ(LDKCResult_NoneMonitorUpdateErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NoneMonitorUpdateErrorZ)); } - operator LDKCResult_NoneMonitorUpdateErrorZ() && { LDKCResult_NoneMonitorUpdateErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_NoneMonitorUpdateErrorZ)); return res; } - ~CResult_NoneMonitorUpdateErrorZ() { CResult_NoneMonitorUpdateErrorZ_free(self); } - CResult_NoneMonitorUpdateErrorZ& operator=(CResult_NoneMonitorUpdateErrorZ&& o) { CResult_NoneMonitorUpdateErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NoneMonitorUpdateErrorZ)); return *this; } - LDKCResult_NoneMonitorUpdateErrorZ* operator &() { return &self; } - LDKCResult_NoneMonitorUpdateErrorZ* operator ->() { return &self; } - const LDKCResult_NoneMonitorUpdateErrorZ* operator &() const { return &self; } - const LDKCResult_NoneMonitorUpdateErrorZ* operator ->() const { return &self; } + COption_AccessZ(const COption_AccessZ&) = delete; + COption_AccessZ(COption_AccessZ&& o) : self(o.self) { memset(&o, 0, sizeof(COption_AccessZ)); } + COption_AccessZ(LDKCOption_AccessZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCOption_AccessZ)); } + operator LDKCOption_AccessZ() && { LDKCOption_AccessZ res = self; memset(&self, 0, sizeof(LDKCOption_AccessZ)); return res; } + ~COption_AccessZ() { COption_AccessZ_free(self); } + COption_AccessZ& operator=(COption_AccessZ&& o) { COption_AccessZ_free(self); self = o.self; memset(&o, 0, sizeof(COption_AccessZ)); return *this; } + LDKCOption_AccessZ* operator &() { return &self; } + LDKCOption_AccessZ* operator ->() { return &self; } + const LDKCOption_AccessZ* operator &() const { return &self; } + const LDKCOption_AccessZ* operator ->() const { return &self; } }; class CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ { private: @@ -5051,20 +5134,20 @@ public: const LDKC2Tuple_PaymentHashPaymentSecretZ* operator &() const { return &self; } const LDKC2Tuple_PaymentHashPaymentSecretZ* operator ->() const { return &self; } }; -class COption_AccessZ { +class CResult_AcceptChannelDecodeErrorZ { private: - LDKCOption_AccessZ self; + LDKCResult_AcceptChannelDecodeErrorZ self; public: - COption_AccessZ(const COption_AccessZ&) = delete; - COption_AccessZ(COption_AccessZ&& o) : self(o.self) { memset(&o, 0, sizeof(COption_AccessZ)); } - COption_AccessZ(LDKCOption_AccessZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCOption_AccessZ)); } - operator LDKCOption_AccessZ() && { LDKCOption_AccessZ res = self; memset(&self, 0, sizeof(LDKCOption_AccessZ)); return res; } - ~COption_AccessZ() { COption_AccessZ_free(self); } - COption_AccessZ& operator=(COption_AccessZ&& o) { COption_AccessZ_free(self); self = o.self; memset(&o, 0, sizeof(COption_AccessZ)); return *this; } - LDKCOption_AccessZ* operator &() { return &self; } - LDKCOption_AccessZ* operator ->() { return &self; } - const LDKCOption_AccessZ* operator &() const { return &self; } - const LDKCOption_AccessZ* operator ->() const { return &self; } + CResult_AcceptChannelDecodeErrorZ(const CResult_AcceptChannelDecodeErrorZ&) = delete; + CResult_AcceptChannelDecodeErrorZ(CResult_AcceptChannelDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_AcceptChannelDecodeErrorZ)); } + CResult_AcceptChannelDecodeErrorZ(LDKCResult_AcceptChannelDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_AcceptChannelDecodeErrorZ)); } + operator LDKCResult_AcceptChannelDecodeErrorZ() && { LDKCResult_AcceptChannelDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_AcceptChannelDecodeErrorZ)); return res; } + ~CResult_AcceptChannelDecodeErrorZ() { CResult_AcceptChannelDecodeErrorZ_free(self); } + CResult_AcceptChannelDecodeErrorZ& operator=(CResult_AcceptChannelDecodeErrorZ&& o) { CResult_AcceptChannelDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_AcceptChannelDecodeErrorZ)); return *this; } + LDKCResult_AcceptChannelDecodeErrorZ* operator &() { return &self; } + LDKCResult_AcceptChannelDecodeErrorZ* operator ->() { return &self; } + const LDKCResult_AcceptChannelDecodeErrorZ* operator &() const { return &self; } + const LDKCResult_AcceptChannelDecodeErrorZ* operator ->() const { return &self; } }; class C2Tuple_BlockHashChannelManagerZ { private: @@ -5096,20 +5179,20 @@ public: const LDKCResult_ChannelTransactionParametersDecodeErrorZ* operator &() const { return &self; } const LDKCResult_ChannelTransactionParametersDecodeErrorZ* operator ->() const { return &self; } }; -class CResult_AcceptChannelDecodeErrorZ { +class CResult_PongDecodeErrorZ { private: - LDKCResult_AcceptChannelDecodeErrorZ self; + LDKCResult_PongDecodeErrorZ self; public: - CResult_AcceptChannelDecodeErrorZ(const CResult_AcceptChannelDecodeErrorZ&) = delete; - CResult_AcceptChannelDecodeErrorZ(CResult_AcceptChannelDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_AcceptChannelDecodeErrorZ)); } - CResult_AcceptChannelDecodeErrorZ(LDKCResult_AcceptChannelDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_AcceptChannelDecodeErrorZ)); } - operator LDKCResult_AcceptChannelDecodeErrorZ() && { LDKCResult_AcceptChannelDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_AcceptChannelDecodeErrorZ)); return res; } - ~CResult_AcceptChannelDecodeErrorZ() { CResult_AcceptChannelDecodeErrorZ_free(self); } - CResult_AcceptChannelDecodeErrorZ& operator=(CResult_AcceptChannelDecodeErrorZ&& o) { CResult_AcceptChannelDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_AcceptChannelDecodeErrorZ)); return *this; } - LDKCResult_AcceptChannelDecodeErrorZ* operator &() { return &self; } - LDKCResult_AcceptChannelDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_AcceptChannelDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_AcceptChannelDecodeErrorZ* operator ->() const { return &self; } + CResult_PongDecodeErrorZ(const CResult_PongDecodeErrorZ&) = delete; + CResult_PongDecodeErrorZ(CResult_PongDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_PongDecodeErrorZ)); } + CResult_PongDecodeErrorZ(LDKCResult_PongDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_PongDecodeErrorZ)); } + operator LDKCResult_PongDecodeErrorZ() && { LDKCResult_PongDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_PongDecodeErrorZ)); return res; } + ~CResult_PongDecodeErrorZ() { CResult_PongDecodeErrorZ_free(self); } + CResult_PongDecodeErrorZ& operator=(CResult_PongDecodeErrorZ&& o) { CResult_PongDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_PongDecodeErrorZ)); return *this; } + LDKCResult_PongDecodeErrorZ* operator &() { return &self; } + LDKCResult_PongDecodeErrorZ* operator ->() { return &self; } + const LDKCResult_PongDecodeErrorZ* operator &() const { return &self; } + const LDKCResult_PongDecodeErrorZ* operator ->() const { return &self; } }; class CVec_SignatureZ { private: @@ -5186,20 +5269,20 @@ public: const LDKC2Tuple_PaymentHashPaymentIdZ* operator &() const { return &self; } const LDKC2Tuple_PaymentHashPaymentIdZ* operator ->() const { return &self; } }; -class CResult_StringErrorZ { +class CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ { private: - LDKCResult_StringErrorZ self; + LDKCResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ self; public: - CResult_StringErrorZ(const CResult_StringErrorZ&) = delete; - CResult_StringErrorZ(CResult_StringErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_StringErrorZ)); } - CResult_StringErrorZ(LDKCResult_StringErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_StringErrorZ)); } - operator LDKCResult_StringErrorZ() && { LDKCResult_StringErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_StringErrorZ)); return res; } - ~CResult_StringErrorZ() { CResult_StringErrorZ_free(self); } - CResult_StringErrorZ& operator=(CResult_StringErrorZ&& o) { CResult_StringErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_StringErrorZ)); return *this; } - LDKCResult_StringErrorZ* operator &() { return &self; } - LDKCResult_StringErrorZ* operator ->() { return &self; } - const LDKCResult_StringErrorZ* operator &() const { return &self; } - const LDKCResult_StringErrorZ* operator ->() const { return &self; } + CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ(const CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ&) = delete; + CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ(CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ)); } + CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ(LDKCResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ)); } + operator LDKCResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ() && { LDKCResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ)); return res; } + ~CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ() { CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ_free(self); } + CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ& operator=(CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ&& o) { CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ)); return *this; } + LDKCResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ* operator &() { return &self; } + LDKCResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ* operator ->() { return &self; } + const LDKCResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ* operator &() const { return &self; } + const LDKCResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ* operator ->() const { return &self; } }; class CResult_NoneErrorZ { private: @@ -5216,6 +5299,21 @@ public: const LDKCResult_NoneErrorZ* operator &() const { return &self; } const LDKCResult_NoneErrorZ* operator ->() const { return &self; } }; +class CResult_StringErrorZ { +private: + LDKCResult_StringErrorZ self; +public: + CResult_StringErrorZ(const CResult_StringErrorZ&) = delete; + CResult_StringErrorZ(CResult_StringErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_StringErrorZ)); } + CResult_StringErrorZ(LDKCResult_StringErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_StringErrorZ)); } + operator LDKCResult_StringErrorZ() && { LDKCResult_StringErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_StringErrorZ)); return res; } + ~CResult_StringErrorZ() { CResult_StringErrorZ_free(self); } + CResult_StringErrorZ& operator=(CResult_StringErrorZ&& o) { CResult_StringErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_StringErrorZ)); return *this; } + LDKCResult_StringErrorZ* operator &() { return &self; } + LDKCResult_StringErrorZ* operator ->() { return &self; } + const LDKCResult_StringErrorZ* operator &() const { return &self; } + const LDKCResult_StringErrorZ* operator ->() const { return &self; } +}; class C2Tuple_TxidCVec_C2Tuple_u32ScriptZZZ { private: LDKC2Tuple_TxidCVec_C2Tuple_u32ScriptZZZ self; @@ -5231,21 +5329,6 @@ public: const LDKC2Tuple_TxidCVec_C2Tuple_u32ScriptZZZ* operator &() const { return &self; } const LDKC2Tuple_TxidCVec_C2Tuple_u32ScriptZZZ* operator ->() const { return &self; } }; -class CResult_PongDecodeErrorZ { -private: - LDKCResult_PongDecodeErrorZ self; -public: - CResult_PongDecodeErrorZ(const CResult_PongDecodeErrorZ&) = delete; - CResult_PongDecodeErrorZ(CResult_PongDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_PongDecodeErrorZ)); } - CResult_PongDecodeErrorZ(LDKCResult_PongDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_PongDecodeErrorZ)); } - operator LDKCResult_PongDecodeErrorZ() && { LDKCResult_PongDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_PongDecodeErrorZ)); return res; } - ~CResult_PongDecodeErrorZ() { CResult_PongDecodeErrorZ_free(self); } - CResult_PongDecodeErrorZ& operator=(CResult_PongDecodeErrorZ&& o) { CResult_PongDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_PongDecodeErrorZ)); return *this; } - LDKCResult_PongDecodeErrorZ* operator &() { return &self; } - LDKCResult_PongDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_PongDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_PongDecodeErrorZ* operator ->() const { return &self; } -}; class CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ { private: LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ self; @@ -5276,6 +5359,21 @@ public: const LDKCOption_EventZ* operator &() const { return &self; } const LDKCOption_EventZ* operator ->() const { return &self; } }; +class CResult_ChannelTypeFeaturesDecodeErrorZ { +private: + LDKCResult_ChannelTypeFeaturesDecodeErrorZ self; +public: + CResult_ChannelTypeFeaturesDecodeErrorZ(const CResult_ChannelTypeFeaturesDecodeErrorZ&) = delete; + CResult_ChannelTypeFeaturesDecodeErrorZ(CResult_ChannelTypeFeaturesDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ChannelTypeFeaturesDecodeErrorZ)); } + CResult_ChannelTypeFeaturesDecodeErrorZ(LDKCResult_ChannelTypeFeaturesDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ChannelTypeFeaturesDecodeErrorZ)); } + operator LDKCResult_ChannelTypeFeaturesDecodeErrorZ() && { LDKCResult_ChannelTypeFeaturesDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ChannelTypeFeaturesDecodeErrorZ)); return res; } + ~CResult_ChannelTypeFeaturesDecodeErrorZ() { CResult_ChannelTypeFeaturesDecodeErrorZ_free(self); } + CResult_ChannelTypeFeaturesDecodeErrorZ& operator=(CResult_ChannelTypeFeaturesDecodeErrorZ&& o) { CResult_ChannelTypeFeaturesDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_ChannelTypeFeaturesDecodeErrorZ)); return *this; } + LDKCResult_ChannelTypeFeaturesDecodeErrorZ* operator &() { return &self; } + LDKCResult_ChannelTypeFeaturesDecodeErrorZ* operator ->() { return &self; } + const LDKCResult_ChannelTypeFeaturesDecodeErrorZ* operator &() const { return &self; } + const LDKCResult_ChannelTypeFeaturesDecodeErrorZ* operator ->() const { return &self; } +}; class CVec_RouteHintZ { private: LDKCVec_RouteHintZ self; @@ -5741,6 +5839,21 @@ public: const LDKCResult_UpdateFailHTLCDecodeErrorZ* operator &() const { return &self; } const LDKCResult_UpdateFailHTLCDecodeErrorZ* operator ->() const { return &self; } }; +class CResult_PaymentSecretNoneZ { +private: + LDKCResult_PaymentSecretNoneZ self; +public: + CResult_PaymentSecretNoneZ(const CResult_PaymentSecretNoneZ&) = delete; + CResult_PaymentSecretNoneZ(CResult_PaymentSecretNoneZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_PaymentSecretNoneZ)); } + CResult_PaymentSecretNoneZ(LDKCResult_PaymentSecretNoneZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_PaymentSecretNoneZ)); } + operator LDKCResult_PaymentSecretNoneZ() && { LDKCResult_PaymentSecretNoneZ res = self; memset(&self, 0, sizeof(LDKCResult_PaymentSecretNoneZ)); return res; } + ~CResult_PaymentSecretNoneZ() { CResult_PaymentSecretNoneZ_free(self); } + CResult_PaymentSecretNoneZ& operator=(CResult_PaymentSecretNoneZ&& o) { CResult_PaymentSecretNoneZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_PaymentSecretNoneZ)); return *this; } + LDKCResult_PaymentSecretNoneZ* operator &() { return &self; } + LDKCResult_PaymentSecretNoneZ* operator ->() { return &self; } + const LDKCResult_PaymentSecretNoneZ* operator &() const { return &self; } + const LDKCResult_PaymentSecretNoneZ* operator ->() const { return &self; } +}; class CResult_ChannelConfigDecodeErrorZ { private: LDKCResult_ChannelConfigDecodeErrorZ self; @@ -5966,21 +6079,6 @@ public: const LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* operator &() const { return &self; } const LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* operator ->() const { return &self; } }; -class CResult_NoneNoneZ { -private: - LDKCResult_NoneNoneZ self; -public: - CResult_NoneNoneZ(const CResult_NoneNoneZ&) = delete; - CResult_NoneNoneZ(CResult_NoneNoneZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NoneNoneZ)); } - CResult_NoneNoneZ(LDKCResult_NoneNoneZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NoneNoneZ)); } - operator LDKCResult_NoneNoneZ() && { LDKCResult_NoneNoneZ res = self; memset(&self, 0, sizeof(LDKCResult_NoneNoneZ)); return res; } - ~CResult_NoneNoneZ() { CResult_NoneNoneZ_free(self); } - CResult_NoneNoneZ& operator=(CResult_NoneNoneZ&& o) { CResult_NoneNoneZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NoneNoneZ)); return *this; } - LDKCResult_NoneNoneZ* operator &() { return &self; } - LDKCResult_NoneNoneZ* operator ->() { return &self; } - const LDKCResult_NoneNoneZ* operator &() const { return &self; } - const LDKCResult_NoneNoneZ* operator ->() const { return &self; } -}; class CResult_RouteParametersDecodeErrorZ { private: LDKCResult_RouteParametersDecodeErrorZ self; @@ -6011,6 +6109,21 @@ public: const LDKCOption_ClosureReasonZ* operator &() const { return &self; } const LDKCOption_ClosureReasonZ* operator ->() const { return &self; } }; +class CResult_NoneNoneZ { +private: + LDKCResult_NoneNoneZ self; +public: + CResult_NoneNoneZ(const CResult_NoneNoneZ&) = delete; + CResult_NoneNoneZ(CResult_NoneNoneZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NoneNoneZ)); } + CResult_NoneNoneZ(LDKCResult_NoneNoneZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NoneNoneZ)); } + operator LDKCResult_NoneNoneZ() && { LDKCResult_NoneNoneZ res = self; memset(&self, 0, sizeof(LDKCResult_NoneNoneZ)); return res; } + ~CResult_NoneNoneZ() { CResult_NoneNoneZ_free(self); } + CResult_NoneNoneZ& operator=(CResult_NoneNoneZ&& o) { CResult_NoneNoneZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NoneNoneZ)); return *this; } + LDKCResult_NoneNoneZ* operator &() { return &self; } + LDKCResult_NoneNoneZ* operator ->() { return &self; } + const LDKCResult_NoneNoneZ* operator &() const { return &self; } + const LDKCResult_NoneNoneZ* operator ->() const { return &self; } +}; class CVec_APIErrorZ { private: LDKCVec_APIErrorZ self; @@ -6221,20 +6334,20 @@ public: const LDKCResult_BuiltCommitmentTransactionDecodeErrorZ* operator &() const { return &self; } const LDKCResult_BuiltCommitmentTransactionDecodeErrorZ* operator ->() const { return &self; } }; -class CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ { +class COption_NoneZ { private: - LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ self; + LDKCOption_NoneZ self; public: - CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ(const CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ&) = delete; - CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ(CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ)); } - CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ)); } - operator LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ() && { LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ)); return res; } - ~CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ() { CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(self); } - CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ& operator=(CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ&& o) { CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ)); return *this; } - LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* operator &() { return &self; } - LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* operator ->() const { return &self; } + COption_NoneZ(const COption_NoneZ&) = delete; + COption_NoneZ(COption_NoneZ&& o) : self(o.self) { memset(&o, 0, sizeof(COption_NoneZ)); } + COption_NoneZ(LDKCOption_NoneZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCOption_NoneZ)); } + operator LDKCOption_NoneZ() && { LDKCOption_NoneZ res = self; memset(&self, 0, sizeof(LDKCOption_NoneZ)); return res; } + ~COption_NoneZ() { COption_NoneZ_free(self); } + COption_NoneZ& operator=(COption_NoneZ&& o) { COption_NoneZ_free(self); self = o.self; memset(&o, 0, sizeof(COption_NoneZ)); return *this; } + LDKCOption_NoneZ* operator &() { return &self; } + LDKCOption_NoneZ* operator ->() { return &self; } + const LDKCOption_NoneZ* operator &() const { return &self; } + const LDKCOption_NoneZ* operator ->() const { return &self; } }; class CVec_TxOutZ { private: @@ -6251,6 +6364,21 @@ public: const LDKCVec_TxOutZ* operator &() const { return &self; } const LDKCVec_TxOutZ* operator ->() const { return &self; } }; +class CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ { +private: + LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ self; +public: + CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ(const CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ&) = delete; + CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ(CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ)); } + CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ)); } + operator LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ() && { LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ)); return res; } + ~CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ() { CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(self); } + CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ& operator=(CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ&& o) { CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ)); return *this; } + LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* operator &() { return &self; } + LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* operator ->() { return &self; } + const LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* operator &() const { return &self; } + const LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* operator ->() const { return &self; } +}; class CVec_UpdateFailHTLCZ { private: LDKCVec_UpdateFailHTLCZ self; @@ -6345,13 +6473,20 @@ 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, const struct LDKNodeId *NONNULL_PTR source, const struct LDKNodeId *NONNULL_PTR target) { - uint64_t ret = (self.channel_penalty_msat)(self.this_arg, short_channel_id, source, target); +inline uint64_t Score::channel_penalty_msat(uint64_t short_channel_id, uint64_t send_amt_msat, struct LDKCOption_u64Z channel_capacity_msat, const struct LDKNodeId *NONNULL_PTR source, const struct LDKNodeId *NONNULL_PTR target) { + uint64_t ret = (self.channel_penalty_msat)(self.this_arg, short_channel_id, send_amt_msat, channel_capacity_msat, source, target); return ret; } inline void Score::payment_path_failed(struct LDKCVec_RouteHopZ path, uint64_t short_channel_id) { (self.payment_path_failed)(self.this_arg, path, short_channel_id); } +inline void Score::payment_path_successful(struct LDKCVec_RouteHopZ path) { + (self.payment_path_successful)(self.this_arg, path); +} +inline LDK::Score LockableScore::lock() { + LDK::Score ret = (self.lock)(self.this_arg); + 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; @@ -6431,6 +6566,10 @@ inline LDK::CResult_RecoverableSignatureNoneZ KeysInterface::sign_invoice(struct LDK::CResult_RecoverableSignatureNoneZ ret = (self.sign_invoice)(self.this_arg, invoice_preimage); return ret; } +inline LDKThirtyTwoBytes KeysInterface::get_inbound_payment_key_material() { + LDKThirtyTwoBytes ret = (self.get_inbound_payment_key_material)(self.this_arg); + return ret; +} inline LDK::CResult_COption_TypeZDecodeErrorZ CustomMessageReader::read(uint16_t message_type, struct LDKu8slice buffer) { LDK::CResult_COption_TypeZDecodeErrorZ ret = (self.read)(self.this_arg, message_type, buffer); return ret; @@ -6455,12 +6594,19 @@ inline LDK::CResult_PaymentIdPaymentSendFailureZ Payer::send_payment(const struc LDK::CResult_PaymentIdPaymentSendFailureZ ret = (self.send_payment)(self.this_arg, route, payment_hash, payment_secret); return ret; } +inline LDK::CResult_PaymentIdPaymentSendFailureZ Payer::send_spontaneous_payment(const struct LDKRoute *NONNULL_PTR route, struct LDKThirtyTwoBytes payment_preimage) { + LDK::CResult_PaymentIdPaymentSendFailureZ ret = (self.send_spontaneous_payment)(self.this_arg, route, payment_preimage); + return ret; +} inline LDK::CResult_NonePaymentSendFailureZ Payer::retry_payment(const struct LDKRoute *NONNULL_PTR route, struct LDKThirtyTwoBytes payment_id) { LDK::CResult_NonePaymentSendFailureZ ret = (self.retry_payment)(self.this_arg, route, payment_id); return ret; } -inline LDK::CResult_RouteLightningErrorZ Router::find_route(struct LDKPublicKey payer, const struct LDKRouteParameters *NONNULL_PTR params, struct LDKCVec_ChannelDetailsZ *first_hops, const struct LDKScore *NONNULL_PTR scorer) { - LDK::CResult_RouteLightningErrorZ ret = (self.find_route)(self.this_arg, payer, params, first_hops, scorer); +inline void Payer::abandon_payment(struct LDKThirtyTwoBytes payment_id) { + (self.abandon_payment)(self.this_arg, payment_id); +} +inline LDK::CResult_RouteLightningErrorZ Router::find_route(struct LDKPublicKey payer, const struct LDKRouteParameters *NONNULL_PTR params, const uint8_t (*payment_hash)[32], struct LDKCVec_ChannelDetailsZ *first_hops, const struct LDKScore *NONNULL_PTR scorer) { + LDK::CResult_RouteLightningErrorZ ret = (self.find_route)(self.this_arg, payer, params, payment_hash, first_hops, scorer); return ret; } inline LDK::CResult_NoneLightningErrorZ CustomMessageHandler::handle_custom_message(struct LDKType msg, struct LDKPublicKey sender_node_id) { diff --git a/lightning-c-bindings/src/c_types/derived.rs b/lightning-c-bindings/src/c_types/derived.rs index 68ca65a..d2fd004 100644 --- a/lightning-c-bindings/src/c_types/derived.rs +++ b/lightning-c-bindings/src/c_types/derived.rs @@ -472,7 +472,7 @@ pub enum COption_u32Z { } impl COption_u32Z { #[allow(unused)] pub(crate) fn is_some(&self) -> bool { - if let Self::Some(_) = self { true } else { false } + if let Self::None = self { false } else { true } } #[allow(unused)] pub(crate) fn is_none(&self) -> bool { !self.is_some() @@ -595,6 +595,35 @@ impl Clone for CResult_HTLCOutputInCommitmentDecodeErrorZ { /// but with all dynamically-allocated buffers duplicated in new buffers. pub extern "C" fn CResult_HTLCOutputInCommitmentDecodeErrorZ_clone(orig: &CResult_HTLCOutputInCommitmentDecodeErrorZ) -> CResult_HTLCOutputInCommitmentDecodeErrorZ { Clone::clone(&orig) } #[repr(C)] +/// An enum which can either contain a or not +pub enum COption_NoneZ { + /// When we're in this state, this COption_NoneZ contains a + Some, + /// When we're in this state, this COption_NoneZ contains nothing + None +} +impl COption_NoneZ { + #[allow(unused)] pub(crate) fn is_some(&self) -> bool { + if let Self::None = self { false } else { true } + } + #[allow(unused)] pub(crate) fn is_none(&self) -> bool { + !self.is_some() + } +} +#[no_mangle] +/// Constructs a new COption_NoneZ containing a +pub extern "C" fn COption_NoneZ_some() -> COption_NoneZ { + COption_NoneZ::Some +} +#[no_mangle] +/// Constructs a new COption_NoneZ containing nothing +pub extern "C" fn COption_NoneZ_none() -> COption_NoneZ { + COption_NoneZ::None +} +#[no_mangle] +/// Frees any resources associated with the , if we are in the Some state +pub extern "C" fn COption_NoneZ_free(_res: COption_NoneZ) { } +#[repr(C)] /// The contents of CResult_CounterpartyChannelTransactionParametersDecodeErrorZ pub union CResult_CounterpartyChannelTransactionParametersDecodeErrorZPtr { /// A pointer to the contents in the success state. @@ -1537,6 +1566,23 @@ impl From Self { + if self.result_ok { + Self { result_ok: true, contents: CResult_ShutdownScriptInvalidShutdownScriptZPtr { + result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) + } } + } else { + Self { result_ok: false, contents: CResult_ShutdownScriptInvalidShutdownScriptZPtr { + err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) + } } + } + } +} +#[no_mangle] +/// Creates a new CResult_ShutdownScriptInvalidShutdownScriptZ which has the same data as `orig` +/// but with all dynamically-allocated buffers duplicated in new buffers. +pub extern "C" fn CResult_ShutdownScriptInvalidShutdownScriptZ_clone(orig: &CResult_ShutdownScriptInvalidShutdownScriptZ) -> CResult_ShutdownScriptInvalidShutdownScriptZ { Clone::clone(&orig) } #[repr(C)] /// The contents of CResult_NoneErrorZ pub union CResult_NoneErrorZPtr { @@ -2066,7 +2112,7 @@ pub enum COption_u64Z { } impl COption_u64Z { #[allow(unused)] pub(crate) fn is_some(&self) -> bool { - if let Self::Some(_) = self { true } else { false } + if let Self::None = self { false } else { true } } #[allow(unused)] pub(crate) fn is_none(&self) -> bool { !self.is_some() @@ -2947,7 +2993,7 @@ pub enum COption_C2Tuple_usizeTransactionZZ { } impl COption_C2Tuple_usizeTransactionZZ { #[allow(unused)] pub(crate) fn is_some(&self) -> bool { - if let Self::Some(_) = self { true } else { false } + if let Self::None = self { false } else { true } } #[allow(unused)] pub(crate) fn is_none(&self) -> bool { !self.is_some() @@ -2984,7 +3030,7 @@ pub enum COption_ClosureReasonZ { } impl COption_ClosureReasonZ { #[allow(unused)] pub(crate) fn is_some(&self) -> bool { - if let Self::Some(_) = self { true } else { false } + if let Self::None = self { false } else { true } } #[allow(unused)] pub(crate) fn is_none(&self) -> bool { !self.is_some() @@ -3117,7 +3163,7 @@ pub enum COption_NetworkUpdateZ { } impl COption_NetworkUpdateZ { #[allow(unused)] pub(crate) fn is_some(&self) -> bool { - if let Self::Some(_) = self { true } else { false } + if let Self::None = self { false } else { true } } #[allow(unused)] pub(crate) fn is_none(&self) -> bool { !self.is_some() @@ -3200,7 +3246,7 @@ pub enum COption_EventZ { } impl COption_EventZ { #[allow(unused)] pub(crate) fn is_some(&self) -> bool { - if let Self::Some(_) = self { true } else { false } + if let Self::None = self { false } else { true } } #[allow(unused)] pub(crate) fn is_none(&self) -> bool { !self.is_some() @@ -3369,41 +3415,41 @@ impl Clone for CVec_MessageSendEventZ { } } #[repr(C)] -/// The contents of CResult_InitFeaturesDecodeErrorZ -pub union CResult_InitFeaturesDecodeErrorZPtr { +/// The contents of CResult_ScoringParametersDecodeErrorZ +pub union CResult_ScoringParametersDecodeErrorZPtr { /// 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::features::InitFeatures, + pub result: *mut crate::lightning::routing::scoring::ScoringParameters, /// 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_InitFeaturesDecodeErrorZ represents the result of a fallible operation, -/// containing a crate::lightning::ln::features::InitFeatures on success and a crate::lightning::ln::msgs::DecodeError on failure. +/// A CResult_ScoringParametersDecodeErrorZ represents the result of a fallible operation, +/// containing a crate::lightning::routing::scoring::ScoringParameters 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_InitFeaturesDecodeErrorZ { - /// The contents of this CResult_InitFeaturesDecodeErrorZ, accessible via either +pub struct CResult_ScoringParametersDecodeErrorZ { + /// The contents of this CResult_ScoringParametersDecodeErrorZ, accessible via either /// `err` or `result` depending on the state of `result_ok`. - pub contents: CResult_InitFeaturesDecodeErrorZPtr, - /// Whether this CResult_InitFeaturesDecodeErrorZ represents a success state. + pub contents: CResult_ScoringParametersDecodeErrorZPtr, + /// Whether this CResult_ScoringParametersDecodeErrorZ represents a success state. pub result_ok: bool, } #[no_mangle] -/// Creates a new CResult_InitFeaturesDecodeErrorZ in the success state. -pub extern "C" fn CResult_InitFeaturesDecodeErrorZ_ok(o: crate::lightning::ln::features::InitFeatures) -> CResult_InitFeaturesDecodeErrorZ { - CResult_InitFeaturesDecodeErrorZ { - contents: CResult_InitFeaturesDecodeErrorZPtr { +/// Creates a new CResult_ScoringParametersDecodeErrorZ in the success state. +pub extern "C" fn CResult_ScoringParametersDecodeErrorZ_ok(o: crate::lightning::routing::scoring::ScoringParameters) -> CResult_ScoringParametersDecodeErrorZ { + CResult_ScoringParametersDecodeErrorZ { + contents: CResult_ScoringParametersDecodeErrorZPtr { result: Box::into_raw(Box::new(o)), }, result_ok: true, } } #[no_mangle] -/// Creates a new CResult_InitFeaturesDecodeErrorZ in the error state. -pub extern "C" fn CResult_InitFeaturesDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_InitFeaturesDecodeErrorZ { - CResult_InitFeaturesDecodeErrorZ { - contents: CResult_InitFeaturesDecodeErrorZPtr { +/// Creates a new CResult_ScoringParametersDecodeErrorZ in the error state. +pub extern "C" fn CResult_ScoringParametersDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_ScoringParametersDecodeErrorZ { + CResult_ScoringParametersDecodeErrorZ { + contents: CResult_ScoringParametersDecodeErrorZPtr { err: Box::into_raw(Box::new(e)), }, result_ok: false, @@ -3411,13 +3457,13 @@ pub extern "C" fn CResult_InitFeaturesDecodeErrorZ_err(e: crate::lightning::ln:: } /// Checks if the given object is currently in the success state #[no_mangle] -pub extern "C" fn CResult_InitFeaturesDecodeErrorZ_is_ok(o: &CResult_InitFeaturesDecodeErrorZ) -> bool { +pub extern "C" fn CResult_ScoringParametersDecodeErrorZ_is_ok(o: &CResult_ScoringParametersDecodeErrorZ) -> bool { o.result_ok } #[no_mangle] -/// Frees any resources used by the CResult_InitFeaturesDecodeErrorZ. -pub extern "C" fn CResult_InitFeaturesDecodeErrorZ_free(_res: CResult_InitFeaturesDecodeErrorZ) { } -impl Drop for CResult_InitFeaturesDecodeErrorZ { +/// Frees any resources used by the CResult_ScoringParametersDecodeErrorZ. +pub extern "C" fn CResult_ScoringParametersDecodeErrorZ_free(_res: CResult_ScoringParametersDecodeErrorZ) { } +impl Drop for CResult_ScoringParametersDecodeErrorZ { fn drop(&mut self) { if self.result_ok { if unsafe { !(self.contents.result as *mut ()).is_null() } { @@ -3430,16 +3476,16 @@ impl Drop for CResult_InitFeaturesDecodeErrorZ { } } } -impl From> for CResult_InitFeaturesDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { +impl From> for CResult_ScoringParametersDecodeErrorZ { + 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_InitFeaturesDecodeErrorZPtr { result } + CResult_ScoringParametersDecodeErrorZPtr { result } } else { let err = unsafe { o.contents.err }; unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_InitFeaturesDecodeErrorZPtr { err } + CResult_ScoringParametersDecodeErrorZPtr { err } }; Self { contents, @@ -3448,41 +3494,41 @@ impl From CResult_NodeFeaturesDecodeErrorZ { - CResult_NodeFeaturesDecodeErrorZ { - contents: CResult_NodeFeaturesDecodeErrorZPtr { +/// Creates a new CResult_ScorerDecodeErrorZ in the success state. +pub extern "C" fn CResult_ScorerDecodeErrorZ_ok(o: crate::lightning::routing::scoring::Scorer) -> CResult_ScorerDecodeErrorZ { + CResult_ScorerDecodeErrorZ { + contents: CResult_ScorerDecodeErrorZPtr { result: Box::into_raw(Box::new(o)), }, result_ok: true, } } #[no_mangle] -/// Creates a new CResult_NodeFeaturesDecodeErrorZ in the error state. -pub extern "C" fn CResult_NodeFeaturesDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_NodeFeaturesDecodeErrorZ { - CResult_NodeFeaturesDecodeErrorZ { - contents: CResult_NodeFeaturesDecodeErrorZPtr { +/// Creates a new CResult_ScorerDecodeErrorZ in the error state. +pub extern "C" fn CResult_ScorerDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_ScorerDecodeErrorZ { + CResult_ScorerDecodeErrorZ { + contents: CResult_ScorerDecodeErrorZPtr { err: Box::into_raw(Box::new(e)), }, result_ok: false, @@ -3490,13 +3536,13 @@ pub extern "C" fn CResult_NodeFeaturesDecodeErrorZ_err(e: crate::lightning::ln:: } /// Checks if the given object is currently in the success state #[no_mangle] -pub extern "C" fn CResult_NodeFeaturesDecodeErrorZ_is_ok(o: &CResult_NodeFeaturesDecodeErrorZ) -> bool { +pub extern "C" fn CResult_ScorerDecodeErrorZ_is_ok(o: &CResult_ScorerDecodeErrorZ) -> bool { o.result_ok } #[no_mangle] -/// Frees any resources used by the CResult_NodeFeaturesDecodeErrorZ. -pub extern "C" fn CResult_NodeFeaturesDecodeErrorZ_free(_res: CResult_NodeFeaturesDecodeErrorZ) { } -impl Drop for CResult_NodeFeaturesDecodeErrorZ { +/// Frees any resources used by the CResult_ScorerDecodeErrorZ. +pub extern "C" fn CResult_ScorerDecodeErrorZ_free(_res: CResult_ScorerDecodeErrorZ) { } +impl Drop for CResult_ScorerDecodeErrorZ { fn drop(&mut self) { if self.result_ok { if unsafe { !(self.contents.result as *mut ()).is_null() } { @@ -3509,16 +3555,16 @@ impl Drop for CResult_NodeFeaturesDecodeErrorZ { } } } -impl From> for CResult_NodeFeaturesDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { +impl From> for CResult_ScorerDecodeErrorZ { + 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_NodeFeaturesDecodeErrorZPtr { result } + CResult_ScorerDecodeErrorZPtr { result } } else { let err = unsafe { o.contents.err }; unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_NodeFeaturesDecodeErrorZPtr { err } + CResult_ScorerDecodeErrorZPtr { err } }; Self { contents, @@ -3527,41 +3573,41 @@ impl From CResult_ChannelFeaturesDecodeErrorZ { - CResult_ChannelFeaturesDecodeErrorZ { - contents: CResult_ChannelFeaturesDecodeErrorZPtr { +/// Creates a new CResult_InitFeaturesDecodeErrorZ in the success state. +pub extern "C" fn CResult_InitFeaturesDecodeErrorZ_ok(o: crate::lightning::ln::features::InitFeatures) -> CResult_InitFeaturesDecodeErrorZ { + CResult_InitFeaturesDecodeErrorZ { + contents: CResult_InitFeaturesDecodeErrorZPtr { result: Box::into_raw(Box::new(o)), }, result_ok: true, } } #[no_mangle] -/// Creates a new CResult_ChannelFeaturesDecodeErrorZ in the error state. -pub extern "C" fn CResult_ChannelFeaturesDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_ChannelFeaturesDecodeErrorZ { - CResult_ChannelFeaturesDecodeErrorZ { - contents: CResult_ChannelFeaturesDecodeErrorZPtr { +/// Creates a new CResult_InitFeaturesDecodeErrorZ in the error state. +pub extern "C" fn CResult_InitFeaturesDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_InitFeaturesDecodeErrorZ { + CResult_InitFeaturesDecodeErrorZ { + contents: CResult_InitFeaturesDecodeErrorZPtr { err: Box::into_raw(Box::new(e)), }, result_ok: false, @@ -3569,13 +3615,13 @@ pub extern "C" fn CResult_ChannelFeaturesDecodeErrorZ_err(e: crate::lightning::l } /// Checks if the given object is currently in the success state #[no_mangle] -pub extern "C" fn CResult_ChannelFeaturesDecodeErrorZ_is_ok(o: &CResult_ChannelFeaturesDecodeErrorZ) -> bool { +pub extern "C" fn CResult_InitFeaturesDecodeErrorZ_is_ok(o: &CResult_InitFeaturesDecodeErrorZ) -> bool { o.result_ok } #[no_mangle] -/// Frees any resources used by the CResult_ChannelFeaturesDecodeErrorZ. -pub extern "C" fn CResult_ChannelFeaturesDecodeErrorZ_free(_res: CResult_ChannelFeaturesDecodeErrorZ) { } -impl Drop for CResult_ChannelFeaturesDecodeErrorZ { +/// Frees any resources used by the CResult_InitFeaturesDecodeErrorZ. +pub extern "C" fn CResult_InitFeaturesDecodeErrorZ_free(_res: CResult_InitFeaturesDecodeErrorZ) { } +impl Drop for CResult_InitFeaturesDecodeErrorZ { fn drop(&mut self) { if self.result_ok { if unsafe { !(self.contents.result as *mut ()).is_null() } { @@ -3588,16 +3634,16 @@ impl Drop for CResult_ChannelFeaturesDecodeErrorZ { } } } -impl From> for CResult_ChannelFeaturesDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { +impl From> for CResult_InitFeaturesDecodeErrorZ { + 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_ChannelFeaturesDecodeErrorZPtr { result } + CResult_InitFeaturesDecodeErrorZPtr { result } } else { let err = unsafe { o.contents.err }; unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_ChannelFeaturesDecodeErrorZPtr { err } + CResult_InitFeaturesDecodeErrorZPtr { err } }; Self { contents, @@ -3606,41 +3652,41 @@ impl From CResult_InvoiceFeaturesDecodeErrorZ { - CResult_InvoiceFeaturesDecodeErrorZ { - contents: CResult_InvoiceFeaturesDecodeErrorZPtr { +/// Creates a new CResult_ChannelFeaturesDecodeErrorZ in the success state. +pub extern "C" fn CResult_ChannelFeaturesDecodeErrorZ_ok(o: crate::lightning::ln::features::ChannelFeatures) -> CResult_ChannelFeaturesDecodeErrorZ { + CResult_ChannelFeaturesDecodeErrorZ { + contents: CResult_ChannelFeaturesDecodeErrorZPtr { result: Box::into_raw(Box::new(o)), }, result_ok: true, } } #[no_mangle] -/// Creates a new CResult_InvoiceFeaturesDecodeErrorZ in the error state. -pub extern "C" fn CResult_InvoiceFeaturesDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_InvoiceFeaturesDecodeErrorZ { - CResult_InvoiceFeaturesDecodeErrorZ { - contents: CResult_InvoiceFeaturesDecodeErrorZPtr { +/// Creates a new CResult_ChannelFeaturesDecodeErrorZ in the error state. +pub extern "C" fn CResult_ChannelFeaturesDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_ChannelFeaturesDecodeErrorZ { + CResult_ChannelFeaturesDecodeErrorZ { + contents: CResult_ChannelFeaturesDecodeErrorZPtr { err: Box::into_raw(Box::new(e)), }, result_ok: false, @@ -3648,13 +3694,13 @@ pub extern "C" fn CResult_InvoiceFeaturesDecodeErrorZ_err(e: crate::lightning::l } /// Checks if the given object is currently in the success state #[no_mangle] -pub extern "C" fn CResult_InvoiceFeaturesDecodeErrorZ_is_ok(o: &CResult_InvoiceFeaturesDecodeErrorZ) -> bool { +pub extern "C" fn CResult_ChannelFeaturesDecodeErrorZ_is_ok(o: &CResult_ChannelFeaturesDecodeErrorZ) -> bool { o.result_ok } #[no_mangle] -/// Frees any resources used by the CResult_InvoiceFeaturesDecodeErrorZ. -pub extern "C" fn CResult_InvoiceFeaturesDecodeErrorZ_free(_res: CResult_InvoiceFeaturesDecodeErrorZ) { } -impl Drop for CResult_InvoiceFeaturesDecodeErrorZ { +/// Frees any resources used by the CResult_ChannelFeaturesDecodeErrorZ. +pub extern "C" fn CResult_ChannelFeaturesDecodeErrorZ_free(_res: CResult_ChannelFeaturesDecodeErrorZ) { } +impl Drop for CResult_ChannelFeaturesDecodeErrorZ { fn drop(&mut self) { if self.result_ok { if unsafe { !(self.contents.result as *mut ()).is_null() } { @@ -3667,16 +3713,16 @@ impl Drop for CResult_InvoiceFeaturesDecodeErrorZ { } } } -impl From> for CResult_InvoiceFeaturesDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { +impl From> for CResult_ChannelFeaturesDecodeErrorZ { + 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_InvoiceFeaturesDecodeErrorZPtr { result } + CResult_ChannelFeaturesDecodeErrorZPtr { result } } else { let err = unsafe { o.contents.err }; unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_InvoiceFeaturesDecodeErrorZPtr { err } + CResult_ChannelFeaturesDecodeErrorZPtr { err } }; Self { contents, @@ -3685,41 +3731,41 @@ impl From CResult_ScoringParametersDecodeErrorZ { - CResult_ScoringParametersDecodeErrorZ { - contents: CResult_ScoringParametersDecodeErrorZPtr { +/// Creates a new CResult_NodeFeaturesDecodeErrorZ in the success state. +pub extern "C" fn CResult_NodeFeaturesDecodeErrorZ_ok(o: crate::lightning::ln::features::NodeFeatures) -> CResult_NodeFeaturesDecodeErrorZ { + CResult_NodeFeaturesDecodeErrorZ { + contents: CResult_NodeFeaturesDecodeErrorZPtr { result: Box::into_raw(Box::new(o)), }, result_ok: true, } } #[no_mangle] -/// Creates a new CResult_ScoringParametersDecodeErrorZ in the error state. -pub extern "C" fn CResult_ScoringParametersDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_ScoringParametersDecodeErrorZ { - CResult_ScoringParametersDecodeErrorZ { - contents: CResult_ScoringParametersDecodeErrorZPtr { +/// Creates a new CResult_NodeFeaturesDecodeErrorZ in the error state. +pub extern "C" fn CResult_NodeFeaturesDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_NodeFeaturesDecodeErrorZ { + CResult_NodeFeaturesDecodeErrorZ { + contents: CResult_NodeFeaturesDecodeErrorZPtr { err: Box::into_raw(Box::new(e)), }, result_ok: false, @@ -3727,13 +3773,13 @@ pub extern "C" fn CResult_ScoringParametersDecodeErrorZ_err(e: crate::lightning: } /// Checks if the given object is currently in the success state #[no_mangle] -pub extern "C" fn CResult_ScoringParametersDecodeErrorZ_is_ok(o: &CResult_ScoringParametersDecodeErrorZ) -> bool { +pub extern "C" fn CResult_NodeFeaturesDecodeErrorZ_is_ok(o: &CResult_NodeFeaturesDecodeErrorZ) -> bool { o.result_ok } #[no_mangle] -/// Frees any resources used by the CResult_ScoringParametersDecodeErrorZ. -pub extern "C" fn CResult_ScoringParametersDecodeErrorZ_free(_res: CResult_ScoringParametersDecodeErrorZ) { } -impl Drop for CResult_ScoringParametersDecodeErrorZ { +/// Frees any resources used by the CResult_NodeFeaturesDecodeErrorZ. +pub extern "C" fn CResult_NodeFeaturesDecodeErrorZ_free(_res: CResult_NodeFeaturesDecodeErrorZ) { } +impl Drop for CResult_NodeFeaturesDecodeErrorZ { fn drop(&mut self) { if self.result_ok { if unsafe { !(self.contents.result as *mut ()).is_null() } { @@ -3746,16 +3792,16 @@ impl Drop for CResult_ScoringParametersDecodeErrorZ { } } } -impl From> for CResult_ScoringParametersDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { +impl From> for CResult_NodeFeaturesDecodeErrorZ { + 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_ScoringParametersDecodeErrorZPtr { result } + CResult_NodeFeaturesDecodeErrorZPtr { result } } else { let err = unsafe { o.contents.err }; unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_ScoringParametersDecodeErrorZPtr { err } + CResult_NodeFeaturesDecodeErrorZPtr { err } }; Self { contents, @@ -3764,41 +3810,41 @@ impl From CResult_ScorerDecodeErrorZ { - CResult_ScorerDecodeErrorZ { - contents: CResult_ScorerDecodeErrorZPtr { +/// Creates a new CResult_InvoiceFeaturesDecodeErrorZ in the success state. +pub extern "C" fn CResult_InvoiceFeaturesDecodeErrorZ_ok(o: crate::lightning::ln::features::InvoiceFeatures) -> CResult_InvoiceFeaturesDecodeErrorZ { + CResult_InvoiceFeaturesDecodeErrorZ { + contents: CResult_InvoiceFeaturesDecodeErrorZPtr { result: Box::into_raw(Box::new(o)), }, result_ok: true, } } #[no_mangle] -/// Creates a new CResult_ScorerDecodeErrorZ in the error state. -pub extern "C" fn CResult_ScorerDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_ScorerDecodeErrorZ { - CResult_ScorerDecodeErrorZ { - contents: CResult_ScorerDecodeErrorZPtr { +/// Creates a new CResult_InvoiceFeaturesDecodeErrorZ in the error state. +pub extern "C" fn CResult_InvoiceFeaturesDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_InvoiceFeaturesDecodeErrorZ { + CResult_InvoiceFeaturesDecodeErrorZ { + contents: CResult_InvoiceFeaturesDecodeErrorZPtr { err: Box::into_raw(Box::new(e)), }, result_ok: false, @@ -3806,13 +3852,13 @@ pub extern "C" fn CResult_ScorerDecodeErrorZ_err(e: crate::lightning::ln::msgs:: } /// Checks if the given object is currently in the success state #[no_mangle] -pub extern "C" fn CResult_ScorerDecodeErrorZ_is_ok(o: &CResult_ScorerDecodeErrorZ) -> bool { +pub extern "C" fn CResult_InvoiceFeaturesDecodeErrorZ_is_ok(o: &CResult_InvoiceFeaturesDecodeErrorZ) -> bool { o.result_ok } #[no_mangle] -/// Frees any resources used by the CResult_ScorerDecodeErrorZ. -pub extern "C" fn CResult_ScorerDecodeErrorZ_free(_res: CResult_ScorerDecodeErrorZ) { } -impl Drop for CResult_ScorerDecodeErrorZ { +/// Frees any resources used by the CResult_InvoiceFeaturesDecodeErrorZ. +pub extern "C" fn CResult_InvoiceFeaturesDecodeErrorZ_free(_res: CResult_InvoiceFeaturesDecodeErrorZ) { } +impl Drop for CResult_InvoiceFeaturesDecodeErrorZ { fn drop(&mut self) { if self.result_ok { if unsafe { !(self.contents.result as *mut ()).is_null() } { @@ -3825,16 +3871,95 @@ impl Drop for CResult_ScorerDecodeErrorZ { } } } -impl From> for CResult_ScorerDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { +impl From> for CResult_InvoiceFeaturesDecodeErrorZ { + 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_ScorerDecodeErrorZPtr { result } + CResult_InvoiceFeaturesDecodeErrorZPtr { result } } else { let err = unsafe { o.contents.err }; unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_ScorerDecodeErrorZPtr { err } + CResult_InvoiceFeaturesDecodeErrorZPtr { err } + }; + Self { + contents, + result_ok: o.result_ok, + } + } +} +#[repr(C)] +/// The contents of CResult_ChannelTypeFeaturesDecodeErrorZ +pub union CResult_ChannelTypeFeaturesDecodeErrorZPtr { + /// 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::features::ChannelTypeFeatures, + /// 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_ChannelTypeFeaturesDecodeErrorZ represents the result of a fallible operation, +/// containing a crate::lightning::ln::features::ChannelTypeFeatures 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_ChannelTypeFeaturesDecodeErrorZ { + /// The contents of this CResult_ChannelTypeFeaturesDecodeErrorZ, accessible via either + /// `err` or `result` depending on the state of `result_ok`. + pub contents: CResult_ChannelTypeFeaturesDecodeErrorZPtr, + /// Whether this CResult_ChannelTypeFeaturesDecodeErrorZ represents a success state. + pub result_ok: bool, +} +#[no_mangle] +/// Creates a new CResult_ChannelTypeFeaturesDecodeErrorZ in the success state. +pub extern "C" fn CResult_ChannelTypeFeaturesDecodeErrorZ_ok(o: crate::lightning::ln::features::ChannelTypeFeatures) -> CResult_ChannelTypeFeaturesDecodeErrorZ { + CResult_ChannelTypeFeaturesDecodeErrorZ { + contents: CResult_ChannelTypeFeaturesDecodeErrorZPtr { + result: Box::into_raw(Box::new(o)), + }, + result_ok: true, + } +} +#[no_mangle] +/// Creates a new CResult_ChannelTypeFeaturesDecodeErrorZ in the error state. +pub extern "C" fn CResult_ChannelTypeFeaturesDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_ChannelTypeFeaturesDecodeErrorZ { + CResult_ChannelTypeFeaturesDecodeErrorZ { + contents: CResult_ChannelTypeFeaturesDecodeErrorZPtr { + err: Box::into_raw(Box::new(e)), + }, + result_ok: false, + } +} +/// Checks if the given object is currently in the success state +#[no_mangle] +pub extern "C" fn CResult_ChannelTypeFeaturesDecodeErrorZ_is_ok(o: &CResult_ChannelTypeFeaturesDecodeErrorZ) -> bool { + o.result_ok +} +#[no_mangle] +/// Frees any resources used by the CResult_ChannelTypeFeaturesDecodeErrorZ. +pub extern "C" fn CResult_ChannelTypeFeaturesDecodeErrorZ_free(_res: CResult_ChannelTypeFeaturesDecodeErrorZ) { } +impl Drop for CResult_ChannelTypeFeaturesDecodeErrorZ { + 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_ChannelTypeFeaturesDecodeErrorZ { + 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_ChannelTypeFeaturesDecodeErrorZPtr { result } + } else { + let err = unsafe { o.contents.err }; + unsafe { o.contents.err = std::ptr::null_mut(); } + CResult_ChannelTypeFeaturesDecodeErrorZPtr { err } }; Self { contents, @@ -5208,7 +5333,7 @@ pub enum COption_u16Z { } impl COption_u16Z { #[allow(unused)] pub(crate) fn is_some(&self) -> bool { - if let Self::Some(_) = self { true } else { false } + if let Self::None = self { false } else { true } } #[allow(unused)] pub(crate) fn is_none(&self) -> bool { !self.is_some() @@ -5929,6 +6054,286 @@ pub extern "C" fn C2Tuple_PaymentHashPaymentSecretZ_new(a: crate::c_types::Thirt /// Frees any resources used by the C2Tuple_PaymentHashPaymentSecretZ. pub extern "C" fn C2Tuple_PaymentHashPaymentSecretZ_free(_res: C2Tuple_PaymentHashPaymentSecretZ) { } #[repr(C)] +/// The contents of CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ +pub union CResult_C2Tuple_PaymentHashPaymentSecretZNoneZPtr { + /// A pointer to the contents in the success state. + /// Reading from this pointer when `result_ok` is not set is undefined. + pub result: *mut crate::c_types::derived::C2Tuple_PaymentHashPaymentSecretZ, + /// 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_C2Tuple_PaymentHashPaymentSecretZNoneZ represents the result of a fallible operation, +/// containing a crate::c_types::derived::C2Tuple_PaymentHashPaymentSecretZ on success and a () on failure. +/// `result_ok` indicates the overall state, and the contents are provided via `contents`. +pub struct CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ { + /// The contents of this CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ, accessible via either + /// `err` or `result` depending on the state of `result_ok`. + pub contents: CResult_C2Tuple_PaymentHashPaymentSecretZNoneZPtr, + /// Whether this CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ represents a success state. + pub result_ok: bool, +} +#[no_mangle] +/// Creates a new CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ in the success state. +pub extern "C" fn CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ_ok(o: crate::c_types::derived::C2Tuple_PaymentHashPaymentSecretZ) -> CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ { + CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ { + contents: CResult_C2Tuple_PaymentHashPaymentSecretZNoneZPtr { + result: Box::into_raw(Box::new(o)), + }, + result_ok: true, + } +} +#[no_mangle] +/// Creates a new CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ in the error state. +pub extern "C" fn CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ_err() -> CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ { + CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ { + contents: CResult_C2Tuple_PaymentHashPaymentSecretZNoneZPtr { + err: std::ptr::null_mut(), + }, + result_ok: false, + } +} +/// Checks if the given object is currently in the success state +#[no_mangle] +pub extern "C" fn CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ_is_ok(o: &CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ) -> bool { + o.result_ok +} +#[no_mangle] +/// Frees any resources used by the CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ. +pub extern "C" fn CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ_free(_res: CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ) { } +impl Drop for CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ { + 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_C2Tuple_PaymentHashPaymentSecretZNoneZ { + 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_C2Tuple_PaymentHashPaymentSecretZNoneZPtr { result } + } else { + let _ = unsafe { Box::from_raw(o.contents.err) }; + o.contents.err = std::ptr::null_mut(); + CResult_C2Tuple_PaymentHashPaymentSecretZNoneZPtr { err: std::ptr::null_mut() } + }; + Self { + contents, + result_ok: o.result_ok, + } + } +} +impl Clone for CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ { + fn clone(&self) -> Self { + if self.result_ok { + Self { result_ok: true, contents: CResult_C2Tuple_PaymentHashPaymentSecretZNoneZPtr { + result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) + } } + } else { + Self { result_ok: false, contents: CResult_C2Tuple_PaymentHashPaymentSecretZNoneZPtr { + err: std::ptr::null_mut() + } } + } + } +} +#[no_mangle] +/// Creates a new CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ which has the same data as `orig` +/// but with all dynamically-allocated buffers duplicated in new buffers. +pub extern "C" fn CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ_clone(orig: &CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ) -> CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ { Clone::clone(&orig) } +#[repr(C)] +/// The contents of CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ +pub union CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZPtr { + /// A pointer to the contents in the success state. + /// Reading from this pointer when `result_ok` is not set is undefined. + pub result: *mut crate::c_types::derived::C2Tuple_PaymentHashPaymentSecretZ, + /// 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_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ represents the result of a fallible operation, +/// containing a crate::c_types::derived::C2Tuple_PaymentHashPaymentSecretZ 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_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ { + /// The contents of this CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ, accessible via either + /// `err` or `result` depending on the state of `result_ok`. + pub contents: CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZPtr, + /// Whether this CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ represents a success state. + pub result_ok: bool, +} +#[no_mangle] +/// Creates a new CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ in the success state. +pub extern "C" fn CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ_ok(o: crate::c_types::derived::C2Tuple_PaymentHashPaymentSecretZ) -> CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ { + CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ { + contents: CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZPtr { + result: Box::into_raw(Box::new(o)), + }, + result_ok: true, + } +} +#[no_mangle] +/// Creates a new CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ in the error state. +pub extern "C" fn CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ_err(e: crate::lightning::util::errors::APIError) -> CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ { + CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ { + contents: CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZPtr { + err: Box::into_raw(Box::new(e)), + }, + result_ok: false, + } +} +/// Checks if the given object is currently in the success state +#[no_mangle] +pub extern "C" fn CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ_is_ok(o: &CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ) -> bool { + o.result_ok +} +#[no_mangle] +/// Frees any resources used by the CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ. +pub extern "C" fn CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ_free(_res: CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ) { } +impl Drop for CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ { + 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_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ { + 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_C2Tuple_PaymentHashPaymentSecretZAPIErrorZPtr { result } + } else { + let err = unsafe { o.contents.err }; + unsafe { o.contents.err = std::ptr::null_mut(); } + CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZPtr { err } + }; + Self { + contents, + result_ok: o.result_ok, + } + } +} +impl Clone for CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ { + fn clone(&self) -> Self { + if self.result_ok { + Self { result_ok: true, contents: CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZPtr { + result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) + } } + } else { + Self { result_ok: false, contents: CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZPtr { + err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) + } } + } + } +} +#[no_mangle] +/// Creates a new CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ which has the same data as `orig` +/// but with all dynamically-allocated buffers duplicated in new buffers. +pub extern "C" fn CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ_clone(orig: &CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ) -> CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ { Clone::clone(&orig) } +#[repr(C)] +/// The contents of CResult_PaymentSecretNoneZ +pub union CResult_PaymentSecretNoneZPtr { + /// 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, + /// 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_PaymentSecretNoneZ represents the result of a fallible operation, +/// containing a crate::c_types::ThirtyTwoBytes on success and a () on failure. +/// `result_ok` indicates the overall state, and the contents are provided via `contents`. +pub struct CResult_PaymentSecretNoneZ { + /// The contents of this CResult_PaymentSecretNoneZ, accessible via either + /// `err` or `result` depending on the state of `result_ok`. + pub contents: CResult_PaymentSecretNoneZPtr, + /// Whether this CResult_PaymentSecretNoneZ represents a success state. + pub result_ok: bool, +} +#[no_mangle] +/// Creates a new CResult_PaymentSecretNoneZ in the success state. +pub extern "C" fn CResult_PaymentSecretNoneZ_ok(o: crate::c_types::ThirtyTwoBytes) -> CResult_PaymentSecretNoneZ { + CResult_PaymentSecretNoneZ { + contents: CResult_PaymentSecretNoneZPtr { + result: Box::into_raw(Box::new(o)), + }, + result_ok: true, + } +} +#[no_mangle] +/// Creates a new CResult_PaymentSecretNoneZ in the error state. +pub extern "C" fn CResult_PaymentSecretNoneZ_err() -> CResult_PaymentSecretNoneZ { + CResult_PaymentSecretNoneZ { + contents: CResult_PaymentSecretNoneZPtr { + err: std::ptr::null_mut(), + }, + result_ok: false, + } +} +/// Checks if the given object is currently in the success state +#[no_mangle] +pub extern "C" fn CResult_PaymentSecretNoneZ_is_ok(o: &CResult_PaymentSecretNoneZ) -> bool { + o.result_ok +} +#[no_mangle] +/// Frees any resources used by the CResult_PaymentSecretNoneZ. +pub extern "C" fn CResult_PaymentSecretNoneZ_free(_res: CResult_PaymentSecretNoneZ) { } +impl Drop for CResult_PaymentSecretNoneZ { + 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_PaymentSecretNoneZ { + 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_PaymentSecretNoneZPtr { result } + } else { + let _ = unsafe { Box::from_raw(o.contents.err) }; + o.contents.err = std::ptr::null_mut(); + CResult_PaymentSecretNoneZPtr { err: std::ptr::null_mut() } + }; + Self { + contents, + result_ok: o.result_ok, + } + } +} +impl Clone for CResult_PaymentSecretNoneZ { + fn clone(&self) -> Self { + if self.result_ok { + Self { result_ok: true, contents: CResult_PaymentSecretNoneZPtr { + result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) + } } + } else { + Self { result_ok: false, contents: CResult_PaymentSecretNoneZPtr { + err: std::ptr::null_mut() + } } + } + } +} +#[no_mangle] +/// Creates a new CResult_PaymentSecretNoneZ which has the same data as `orig` +/// but with all dynamically-allocated buffers duplicated in new buffers. +pub extern "C" fn CResult_PaymentSecretNoneZ_clone(orig: &CResult_PaymentSecretNoneZ) -> CResult_PaymentSecretNoneZ { Clone::clone(&orig) } +#[repr(C)] /// The contents of CResult_PaymentSecretAPIErrorZ pub union CResult_PaymentSecretAPIErrorZPtr { /// A pointer to the contents in the success state. @@ -6025,6 +6430,102 @@ impl Clone for CResult_PaymentSecretAPIErrorZ { /// but with all dynamically-allocated buffers duplicated in new buffers. pub extern "C" fn CResult_PaymentSecretAPIErrorZ_clone(orig: &CResult_PaymentSecretAPIErrorZ) -> CResult_PaymentSecretAPIErrorZ { Clone::clone(&orig) } #[repr(C)] +/// The contents of CResult_PaymentPreimageAPIErrorZ +pub union CResult_PaymentPreimageAPIErrorZPtr { + /// 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_PaymentPreimageAPIErrorZ 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_PaymentPreimageAPIErrorZ { + /// The contents of this CResult_PaymentPreimageAPIErrorZ, accessible via either + /// `err` or `result` depending on the state of `result_ok`. + pub contents: CResult_PaymentPreimageAPIErrorZPtr, + /// Whether this CResult_PaymentPreimageAPIErrorZ represents a success state. + pub result_ok: bool, +} +#[no_mangle] +/// Creates a new CResult_PaymentPreimageAPIErrorZ in the success state. +pub extern "C" fn CResult_PaymentPreimageAPIErrorZ_ok(o: crate::c_types::ThirtyTwoBytes) -> CResult_PaymentPreimageAPIErrorZ { + CResult_PaymentPreimageAPIErrorZ { + contents: CResult_PaymentPreimageAPIErrorZPtr { + result: Box::into_raw(Box::new(o)), + }, + result_ok: true, + } +} +#[no_mangle] +/// Creates a new CResult_PaymentPreimageAPIErrorZ in the error state. +pub extern "C" fn CResult_PaymentPreimageAPIErrorZ_err(e: crate::lightning::util::errors::APIError) -> CResult_PaymentPreimageAPIErrorZ { + CResult_PaymentPreimageAPIErrorZ { + contents: CResult_PaymentPreimageAPIErrorZPtr { + err: Box::into_raw(Box::new(e)), + }, + result_ok: false, + } +} +/// Checks if the given object is currently in the success state +#[no_mangle] +pub extern "C" fn CResult_PaymentPreimageAPIErrorZ_is_ok(o: &CResult_PaymentPreimageAPIErrorZ) -> bool { + o.result_ok +} +#[no_mangle] +/// Frees any resources used by the CResult_PaymentPreimageAPIErrorZ. +pub extern "C" fn CResult_PaymentPreimageAPIErrorZ_free(_res: CResult_PaymentPreimageAPIErrorZ) { } +impl Drop for CResult_PaymentPreimageAPIErrorZ { + 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_PaymentPreimageAPIErrorZ { + 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_PaymentPreimageAPIErrorZPtr { result } + } else { + let err = unsafe { o.contents.err }; + unsafe { o.contents.err = std::ptr::null_mut(); } + CResult_PaymentPreimageAPIErrorZPtr { err } + }; + Self { + contents, + result_ok: o.result_ok, + } + } +} +impl Clone for CResult_PaymentPreimageAPIErrorZ { + fn clone(&self) -> Self { + if self.result_ok { + Self { result_ok: true, contents: CResult_PaymentPreimageAPIErrorZPtr { + result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) + } } + } else { + Self { result_ok: false, contents: CResult_PaymentPreimageAPIErrorZPtr { + err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) + } } + } + } +} +#[no_mangle] +/// Creates a new CResult_PaymentPreimageAPIErrorZ which has the same data as `orig` +/// but with all dynamically-allocated buffers duplicated in new buffers. +pub extern "C" fn CResult_PaymentPreimageAPIErrorZ_clone(orig: &CResult_PaymentPreimageAPIErrorZ) -> CResult_PaymentPreimageAPIErrorZ { Clone::clone(&orig) } +#[repr(C)] /// A dynamically-allocated array of crate::lightning::chain::channelmonitor::ChannelMonitors of arbitrary size. /// This corresponds to std::vector in C++ pub struct CVec_ChannelMonitorZ { @@ -6373,7 +6874,7 @@ pub enum COption_TypeZ { } impl COption_TypeZ { #[allow(unused)] pub(crate) fn is_some(&self) -> bool { - if let Self::Some(_) = self { true } else { false } + if let Self::None = self { false } else { true } } #[allow(unused)] pub(crate) fn is_none(&self) -> bool { !self.is_some() @@ -7792,7 +8293,7 @@ pub enum COption_MonitorEventZ { } impl COption_MonitorEventZ { #[allow(unused)] pub(crate) fn is_some(&self) -> bool { - if let Self::Some(_) = self { true } else { false } + if let Self::None = self { false } else { true } } #[allow(unused)] pub(crate) fn is_none(&self) -> bool { !self.is_some() @@ -8011,98 +8512,6 @@ impl Clone for CResult_HTLCUpdateDecodeErrorZ { /// but with all dynamically-allocated buffers duplicated in new buffers. pub extern "C" fn CResult_HTLCUpdateDecodeErrorZ_clone(orig: &CResult_HTLCUpdateDecodeErrorZ) -> CResult_HTLCUpdateDecodeErrorZ { Clone::clone(&orig) } #[repr(C)] -/// The contents of CResult_NoneMonitorUpdateErrorZ -pub union CResult_NoneMonitorUpdateErrorZPtr { - /// Note that this value is always NULL, as there are no contents in the OK variant - 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::MonitorUpdateError, -} -#[repr(C)] -/// A CResult_NoneMonitorUpdateErrorZ represents the result of a fallible operation, -/// containing a () on success and a crate::lightning::chain::channelmonitor::MonitorUpdateError on failure. -/// `result_ok` indicates the overall state, and the contents are provided via `contents`. -pub struct CResult_NoneMonitorUpdateErrorZ { - /// The contents of this CResult_NoneMonitorUpdateErrorZ, accessible via either - /// `err` or `result` depending on the state of `result_ok`. - pub contents: CResult_NoneMonitorUpdateErrorZPtr, - /// Whether this CResult_NoneMonitorUpdateErrorZ represents a success state. - pub result_ok: bool, -} -#[no_mangle] -/// Creates a new CResult_NoneMonitorUpdateErrorZ in the success state. -pub extern "C" fn CResult_NoneMonitorUpdateErrorZ_ok() -> CResult_NoneMonitorUpdateErrorZ { - CResult_NoneMonitorUpdateErrorZ { - contents: CResult_NoneMonitorUpdateErrorZPtr { - result: std::ptr::null_mut(), - }, - result_ok: true, - } -} -#[no_mangle] -/// Creates a new CResult_NoneMonitorUpdateErrorZ in the error state. -pub extern "C" fn CResult_NoneMonitorUpdateErrorZ_err(e: crate::lightning::chain::channelmonitor::MonitorUpdateError) -> CResult_NoneMonitorUpdateErrorZ { - CResult_NoneMonitorUpdateErrorZ { - contents: CResult_NoneMonitorUpdateErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -/// Checks if the given object is currently in the success state -#[no_mangle] -pub extern "C" fn CResult_NoneMonitorUpdateErrorZ_is_ok(o: &CResult_NoneMonitorUpdateErrorZ) -> bool { - o.result_ok -} -#[no_mangle] -/// Frees any resources used by the CResult_NoneMonitorUpdateErrorZ. -pub extern "C" fn CResult_NoneMonitorUpdateErrorZ_free(_res: CResult_NoneMonitorUpdateErrorZ) { } -impl Drop for CResult_NoneMonitorUpdateErrorZ { - fn drop(&mut self) { - if self.result_ok { - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_NoneMonitorUpdateErrorZ { - fn from(mut o: crate::c_types::CResultTempl<(), crate::lightning::chain::channelmonitor::MonitorUpdateError>) -> Self { - let contents = if o.result_ok { - let _ = unsafe { Box::from_raw(o.contents.result) }; - o.contents.result = std::ptr::null_mut(); - CResult_NoneMonitorUpdateErrorZPtr { result: std::ptr::null_mut() } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_NoneMonitorUpdateErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_NoneMonitorUpdateErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_NoneMonitorUpdateErrorZPtr { - result: std::ptr::null_mut() - } } - } else { - Self { result_ok: false, contents: CResult_NoneMonitorUpdateErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -/// Creates a new CResult_NoneMonitorUpdateErrorZ which has the same data as `orig` -/// but with all dynamically-allocated buffers duplicated in new buffers. -pub extern "C" fn CResult_NoneMonitorUpdateErrorZ_clone(orig: &CResult_NoneMonitorUpdateErrorZ) -> CResult_NoneMonitorUpdateErrorZ { Clone::clone(&orig) } -#[repr(C)] /// A tuple of 2 elements. See the individual fields for the types contained. pub struct C2Tuple_OutPointScriptZ { /// The element at position 0 @@ -9639,7 +10048,7 @@ pub enum COption_AccessZ { } impl COption_AccessZ { #[allow(unused)] pub(crate) fn is_some(&self) -> bool { - if let Self::Some(_) = self { true } else { false } + if let Self::None = self { false } else { true } } #[allow(unused)] pub(crate) fn is_none(&self) -> bool { !self.is_some() @@ -10294,7 +10703,7 @@ pub enum COption_CVec_NetAddressZZ { } impl COption_CVec_NetAddressZZ { #[allow(unused)] pub(crate) fn is_some(&self) -> bool { - if let Self::Some(_) = self { true } else { false } + if let Self::None = self { false } else { true } } #[allow(unused)] pub(crate) fn is_none(&self) -> bool { !self.is_some() @@ -13778,7 +14187,7 @@ pub enum COption_FilterZ { } impl COption_FilterZ { #[allow(unused)] pub(crate) fn is_some(&self) -> bool { - if let Self::Some(_) = self { true } else { false } + if let Self::None = self { false } else { true } } #[allow(unused)] pub(crate) fn is_none(&self) -> bool { !self.is_some() diff --git a/lightning-c-bindings/src/lightning/chain/chaininterface.rs b/lightning-c-bindings/src/lightning/chain/chaininterface.rs index b6c13b1..b1c180b 100644 --- a/lightning-c-bindings/src/lightning/chain/chaininterface.rs +++ b/lightning-c-bindings/src/lightning/chain/chaininterface.rs @@ -149,12 +149,12 @@ pub struct FeeEstimator { pub this_arg: *mut c_void, /// Gets estimated satoshis of fee required per 1000 Weight-Units. /// - /// Must be no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later round-downs - /// don't put us below 1 satoshi-per-byte). + /// Must return a value no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later + /// round-downs don't put us below 1 satoshi-per-byte). /// - /// This translates to: - /// * satoshis-per-byte * 250 - /// * ceil(satoshis-per-kbyte / 4) + /// This method can be implemented with the following unit conversions: + /// * max(satoshis-per-byte * 250, 253) + /// * max(satoshis-per-kbyte / 4, 253) #[must_use] pub get_est_sat_per_1000_weight: extern "C" fn (this_arg: *const c_void, confirmation_target: crate::lightning::chain::chaininterface::ConfirmationTarget) -> u32, /// Frees any resources associated with this object given its this_arg pointer. diff --git a/lightning-c-bindings/src/lightning/chain/channelmonitor.rs b/lightning-c-bindings/src/lightning/chain/channelmonitor.rs index a55bee5..1484bbf 100644 --- a/lightning-c-bindings/src/lightning/chain/channelmonitor.rs +++ b/lightning-c-bindings/src/lightning/chain/channelmonitor.rs @@ -153,97 +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 } - -use lightning::chain::channelmonitor::MonitorUpdateError as nativeMonitorUpdateErrorImport; -pub(crate) type nativeMonitorUpdateError = nativeMonitorUpdateErrorImport; - -/// General Err type for ChannelMonitor actions. Generally, this implies that the data provided is -/// inconsistent with the ChannelMonitor being called. eg for ChannelMonitor::update_monitor this -/// means you tried to update a monitor for a different channel or the ChannelMonitorUpdate was -/// corrupted. -/// Contains a developer-readable error message. -#[must_use] -#[repr(C)] -pub struct MonitorUpdateError { - /// 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 nativeMonitorUpdateError, - /// 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 MonitorUpdateError { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeMonitorUpdateError>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; - } - } -} -/// Frees any resources used by the MonitorUpdateError, if is_owned is set and inner is non-NULL. -#[no_mangle] -pub extern "C" fn MonitorUpdateError_free(this_obj: MonitorUpdateError) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn MonitorUpdateError_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMonitorUpdateError); } -} -#[allow(unused)] -impl MonitorUpdateError { - pub(crate) fn get_native_ref(&self) -> &'static nativeMonitorUpdateError { - unsafe { &*ObjOps::untweak_ptr(self.inner) } - } - pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMonitorUpdateError { - 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 nativeMonitorUpdateError { - assert!(self.is_owned); - let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); - ret - } -} -#[no_mangle] -pub extern "C" fn MonitorUpdateError_get_a(this_ptr: &MonitorUpdateError) -> crate::c_types::Str { - let mut inner_val = &mut this_ptr.get_native_mut_ref().0; - inner_val.into() -} -#[no_mangle] -pub extern "C" fn MonitorUpdateError_set_a(this_ptr: &mut MonitorUpdateError, mut val: crate::c_types::Str) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_str(); -} -/// Constructs a new MonitorUpdateError given each field -#[must_use] -#[no_mangle] -pub extern "C" fn MonitorUpdateError_new(mut a_arg: crate::c_types::Str) -> MonitorUpdateError { - MonitorUpdateError { inner: ObjOps::heap_alloc(lightning::chain::channelmonitor::MonitorUpdateError ( - a_arg.into_str(), - )), is_owned: true } -} -impl Clone for MonitorUpdateError { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeMonitorUpdateError>::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 MonitorUpdateError_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMonitorUpdateError)).clone() })) as *mut c_void -} -#[no_mangle] -/// Creates a copy of the MonitorUpdateError -pub extern "C" fn MonitorUpdateError_clone(orig: &MonitorUpdateError) -> MonitorUpdateError { - orig.clone() -} /// An event to be processed by the ChannelManager. #[must_use] #[derive(Clone)] @@ -839,9 +748,9 @@ pub(crate) extern "C" fn ChannelMonitor_write_void(obj: *const c_void) -> crate: /// panics if the given update is not the next update by update_id. #[must_use] #[no_mangle] -pub extern "C" fn ChannelMonitor_update_monitor(this_arg: &ChannelMonitor, updates: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate, broadcaster: &crate::lightning::chain::chaininterface::BroadcasterInterface, fee_estimator: &crate::lightning::chain::chaininterface::FeeEstimator, logger: &crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_NoneMonitorUpdateErrorZ { +pub extern "C" fn ChannelMonitor_update_monitor(this_arg: &ChannelMonitor, updates: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate, broadcaster: &crate::lightning::chain::chaininterface::BroadcasterInterface, fee_estimator: &crate::lightning::chain::chaininterface::FeeEstimator, logger: &crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_NoneNoneZ { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_monitor(updates.get_native_ref(), broadcaster, fee_estimator, logger); - 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::MonitorUpdateError { inner: ObjOps::heap_alloc(e), is_owned: true } }).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( { () /*e*/ }).into() }; local_ret } diff --git a/lightning-c-bindings/src/lightning/chain/keysinterface.rs b/lightning-c-bindings/src/lightning/chain/keysinterface.rs index 360d33e..0841758 100644 --- a/lightning-c-bindings/src/lightning/chain/keysinterface.rs +++ b/lightning-c-bindings/src/lightning/chain/keysinterface.rs @@ -999,6 +999,11 @@ pub struct KeysInterface { /// blindly signing the hash. #[must_use] pub sign_invoice: extern "C" fn (this_arg: *const c_void, invoice_preimage: crate::c_types::derived::CVec_u8Z) -> crate::c_types::derived::CResult_RecoverableSignatureNoneZ, + /// Get secret key material as bytes for use in encrypting and decrypting inbound payment data. + /// + /// This method must return the same value each time it is called. + #[must_use] + pub get_inbound_payment_key_material: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes, /// 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, @@ -1016,6 +1021,7 @@ pub(crate) extern "C" fn KeysInterface_clone_fields(orig: &KeysInterface) -> Key get_secure_random_bytes: Clone::clone(&orig.get_secure_random_bytes), read_chan_signer: Clone::clone(&orig.read_chan_signer), sign_invoice: Clone::clone(&orig.sign_invoice), + get_inbound_payment_key_material: Clone::clone(&orig.get_inbound_payment_key_material), free: Clone::clone(&orig.free), } } @@ -1055,6 +1061,10 @@ impl rustKeysInterface for KeysInterface { let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; local_ret } + fn get_inbound_payment_key_material(&self) -> lightning::chain::keysinterface::KeyMaterial { + let mut ret = (self.get_inbound_payment_key_material)(self.this_arg); + ::lightning::chain::keysinterface::KeyMaterial(ret.data) + } } // We're essentially a pointer already, or at least a set of pointers, so allow us to be used @@ -1282,6 +1292,15 @@ pub extern "C" fn InMemorySigner_get_channel_parameters(this_arg: &InMemorySigne crate::lightning::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::chan_utils::ChannelTransactionParameters<>) as *mut _) }, is_owned: false } } +/// Whether anchors should be used. +/// Will panic if ready_channel wasn't called. +#[must_use] +#[no_mangle] +pub extern "C" fn InMemorySigner_opt_anchors(this_arg: &InMemorySigner) -> bool { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.opt_anchors(); + ret +} + /// Sign the single input of spend_tx at index `input_idx` which spends the output /// described by descriptor, returning the witness stack for the input. /// @@ -1635,6 +1654,7 @@ pub extern "C" fn KeysManager_as_KeysInterface(this_arg: &KeysManager) -> crate: get_secure_random_bytes: KeysManager_KeysInterface_get_secure_random_bytes, read_chan_signer: KeysManager_KeysInterface_read_chan_signer, sign_invoice: KeysManager_KeysInterface_sign_invoice, + get_inbound_payment_key_material: KeysManager_KeysInterface_get_inbound_payment_key_material, } } @@ -1644,6 +1664,11 @@ extern "C" fn KeysManager_KeysInterface_get_node_secret(this_arg: *const c_void) crate::c_types::SecretKey::from_rust(ret) } #[must_use] +extern "C" fn KeysManager_KeysInterface_get_inbound_payment_key_material(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes { + let mut ret = >::get_inbound_payment_key_material(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, ); + crate::c_types::ThirtyTwoBytes { data: ret.0 } +} +#[must_use] extern "C" fn KeysManager_KeysInterface_get_destination_script(this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z { let mut ret = >::get_destination_script(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, ); ret.into_bytes().into() diff --git a/lightning-c-bindings/src/lightning/ln/chan_utils.rs b/lightning-c-bindings/src/lightning/ln/chan_utils.rs index 519744c..02f7f7b 100644 --- a/lightning-c-bindings/src/lightning/ln/chan_utils.rs +++ b/lightning-c-bindings/src/lightning/ln/chan_utils.rs @@ -15,6 +15,20 @@ use core::convert::Infallible; use bitcoin::hashes::Hash; use crate::c_types::*; +/// Gets the weight for an HTLC-Success transaction. +#[no_mangle] +pub extern "C" fn htlc_success_tx_weight(mut opt_anchors: bool) -> u64 { + let mut ret = lightning::ln::chan_utils::htlc_success_tx_weight(opt_anchors); + ret +} + +/// Gets the weight for an HTLC-Timeout transaction. +#[no_mangle] +pub extern "C" fn htlc_timeout_tx_weight(mut opt_anchors: bool) -> u64 { + let mut ret = lightning::ln::chan_utils::htlc_timeout_tx_weight(opt_anchors); + ret +} + /// Build the commitment secret from the seed and the commitment number #[no_mangle] pub extern "C" fn build_commitment_secret(commitment_seed: *const [u8; 32], mut idx: u64) -> crate::c_types::ThirtyTwoBytes { @@ -630,8 +644,8 @@ pub extern "C" fn HTLCOutputInCommitment_read(ser: crate::c_types::u8slice) -> c /// Gets the witness redeemscript for an HTLC output in a commitment transaction. Note that htlc /// does not need to have its previous_output_index filled. #[no_mangle] -pub extern "C" fn get_htlc_redeemscript(htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment, keys: &crate::lightning::ln::chan_utils::TxCreationKeys) -> crate::c_types::derived::CVec_u8Z { - let mut ret = lightning::ln::chan_utils::get_htlc_redeemscript(htlc.get_native_ref(), keys.get_native_ref()); +pub extern "C" fn get_htlc_redeemscript(htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment, mut opt_anchors: bool, keys: &crate::lightning::ln::chan_utils::TxCreationKeys) -> crate::c_types::derived::CVec_u8Z { + let mut ret = lightning::ln::chan_utils::get_htlc_redeemscript(htlc.get_native_ref(), opt_anchors, keys.get_native_ref()); ret.into_bytes().into() } @@ -651,11 +665,23 @@ pub extern "C" fn make_funding_redeemscript(mut broadcaster: crate::c_types::Pub /// Panics if htlc.transaction_output_index.is_none() (as such HTLCs do not appear in the /// commitment transaction). #[no_mangle] -pub extern "C" fn build_htlc_transaction(commitment_txid: *const [u8; 32], mut feerate_per_kw: u32, mut contest_delay: u16, htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment, mut broadcaster_delayed_payment_key: crate::c_types::PublicKey, mut revocation_key: crate::c_types::PublicKey) -> crate::c_types::Transaction { - let mut ret = lightning::ln::chan_utils::build_htlc_transaction(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*commitment_txid }[..]).unwrap(), feerate_per_kw, contest_delay, htlc.get_native_ref(), &broadcaster_delayed_payment_key.into_rust(), &revocation_key.into_rust()); +pub extern "C" fn build_htlc_transaction(commitment_txid: *const [u8; 32], mut feerate_per_kw: u32, mut contest_delay: u16, htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment, mut opt_anchors: bool, mut broadcaster_delayed_payment_key: crate::c_types::PublicKey, mut revocation_key: crate::c_types::PublicKey) -> crate::c_types::Transaction { + let mut ret = lightning::ln::chan_utils::build_htlc_transaction(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*commitment_txid }[..]).unwrap(), feerate_per_kw, contest_delay, htlc.get_native_ref(), opt_anchors, &broadcaster_delayed_payment_key.into_rust(), &revocation_key.into_rust()); crate::c_types::Transaction::from_bitcoin(&ret) } +/// Gets the witnessScript for an anchor output from the funding public key. +/// The witness in the spending input must be: +/// +/// After 16 blocks of confirmation, an alternative satisfying witness could be: +/// <> +/// (empty vector required to satisfy compliance with MINIMALIF-standard rule) +#[no_mangle] +pub extern "C" fn get_anchor_redeemscript(mut funding_pubkey: crate::c_types::PublicKey) -> crate::c_types::derived::CVec_u8Z { + let mut ret = lightning::ln::chan_utils::get_anchor_redeemscript(&funding_pubkey.into_rust()); + ret.into_bytes().into() +} + use lightning::ln::chan_utils::ChannelTransactionParameters as nativeChannelTransactionParametersImport; pub(crate) type nativeChannelTransactionParameters = nativeChannelTransactionParametersImport; @@ -782,18 +808,33 @@ pub extern "C" fn ChannelTransactionParameters_set_funding_outpoint(this_ptr: &m let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_outpoint = local_val; } +/// Are anchors used for this channel. Boolean is serialization backwards-compatible +#[no_mangle] +pub extern "C" fn ChannelTransactionParameters_get_opt_anchors(this_ptr: &ChannelTransactionParameters) -> crate::c_types::derived::COption_NoneZ { + let mut inner_val = &mut this_ptr.get_native_mut_ref().opt_anchors; + let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_NoneZ::None } else { crate::c_types::derived::COption_NoneZ::Some /* { () /**/ } */}; + local_inner_val +} +/// Are anchors used for this channel. Boolean is serialization backwards-compatible +#[no_mangle] +pub extern "C" fn ChannelTransactionParameters_set_opt_anchors(this_ptr: &mut ChannelTransactionParameters, mut val: crate::c_types::derived::COption_NoneZ) { + let mut local_val = if val.is_some() { Some( { () /*val.take()*/ }) } else { None }; + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.opt_anchors = local_val; +} /// Constructs a new ChannelTransactionParameters given each field #[must_use] #[no_mangle] -pub extern "C" fn ChannelTransactionParameters_new(mut holder_pubkeys_arg: crate::lightning::ln::chan_utils::ChannelPublicKeys, mut holder_selected_contest_delay_arg: u16, mut is_outbound_from_holder_arg: bool, mut counterparty_parameters_arg: crate::lightning::ln::chan_utils::CounterpartyChannelTransactionParameters, mut funding_outpoint_arg: crate::lightning::chain::transaction::OutPoint) -> ChannelTransactionParameters { +pub extern "C" fn ChannelTransactionParameters_new(mut holder_pubkeys_arg: crate::lightning::ln::chan_utils::ChannelPublicKeys, mut holder_selected_contest_delay_arg: u16, mut is_outbound_from_holder_arg: bool, mut counterparty_parameters_arg: crate::lightning::ln::chan_utils::CounterpartyChannelTransactionParameters, mut funding_outpoint_arg: crate::lightning::chain::transaction::OutPoint, mut opt_anchors_arg: crate::c_types::derived::COption_NoneZ) -> ChannelTransactionParameters { let mut local_counterparty_parameters_arg = if counterparty_parameters_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(counterparty_parameters_arg.take_inner()) } }) }; let mut local_funding_outpoint_arg = if funding_outpoint_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(funding_outpoint_arg.take_inner()) } }) }; + let mut local_opt_anchors_arg = if opt_anchors_arg.is_some() { Some( { () /*opt_anchors_arg.take()*/ }) } else { None }; ChannelTransactionParameters { inner: ObjOps::heap_alloc(nativeChannelTransactionParameters { holder_pubkeys: *unsafe { Box::from_raw(holder_pubkeys_arg.take_inner()) }, holder_selected_contest_delay: holder_selected_contest_delay_arg, is_outbound_from_holder: is_outbound_from_holder_arg, counterparty_parameters: local_counterparty_parameters_arg, funding_outpoint: local_funding_outpoint_arg, + opt_anchors: local_opt_anchors_arg, }), is_owned: true } } impl Clone for ChannelTransactionParameters { @@ -1077,6 +1118,14 @@ pub extern "C" fn DirectedChannelTransactionParameters_funding_outpoint(this_arg crate::c_types::bitcoin_to_C_outpoint(ret) } +/// Whether to use anchors for this channel +#[must_use] +#[no_mangle] +pub extern "C" fn DirectedChannelTransactionParameters_opt_anchors(this_arg: &DirectedChannelTransactionParameters) -> bool { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.opt_anchors(); + ret +} + use lightning::ln::chan_utils::HolderCommitmentTransaction as nativeHolderCommitmentTransactionImport; pub(crate) type nativeHolderCommitmentTransaction = nativeHolderCommitmentTransactionImport; @@ -1389,6 +1438,35 @@ impl ClosingTransaction { ret } } +impl Clone for ClosingTransaction { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeClosingTransaction>::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 ClosingTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeClosingTransaction)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the ClosingTransaction +pub extern "C" fn ClosingTransaction_clone(orig: &ClosingTransaction) -> ClosingTransaction { + orig.clone() +} +/// Checks if two ClosingTransactions contain equal inner contents. +#[no_mangle] +pub extern "C" fn ClosingTransaction_hash(o: &ClosingTransaction) -> 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) +} /// Construct an object of the class #[must_use] #[no_mangle] @@ -1769,6 +1847,14 @@ pub extern "C" fn TrustedCommitmentTransaction_keys(this_arg: &TrustedCommitment crate::lightning::ln::chan_utils::TxCreationKeys { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::chan_utils::TxCreationKeys<>) as *mut _) }, is_owned: false } } +/// Should anchors be used. +#[must_use] +#[no_mangle] +pub extern "C" fn TrustedCommitmentTransaction_opt_anchors(this_arg: &TrustedCommitmentTransaction) -> bool { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.opt_anchors(); + ret +} + /// Get a signature for each HTLC which was included in the commitment transaction (ie for /// which HTLCOutputInCommitment::transaction_output_index.is_some()). /// diff --git a/lightning-c-bindings/src/lightning/ln/channelmanager.rs b/lightning-c-bindings/src/lightning/ln/channelmanager.rs index 3141dd4..ddf271c 100644 --- a/lightning-c-bindings/src/lightning/ln/channelmanager.rs +++ b/lightning-c-bindings/src/lightning/ln/channelmanager.rs @@ -23,6 +23,15 @@ use core::convert::Infallible; use bitcoin::hashes::Hash; use crate::c_types::*; +mod inbound_payment { + +use std::str::FromStr; +use std::ffi::c_void; +use core::convert::Infallible; +use bitcoin::hashes::Hash; +use crate::c_types::*; + +} use lightning::ln::channelmanager::ChannelManager as nativeChannelManagerImport; pub(crate) type nativeChannelManager = nativeChannelManagerImport; @@ -680,11 +689,42 @@ pub extern "C" fn ChannelDetails_get_user_channel_id(this_ptr: &ChannelDetails) 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; } +/// Our total balance. This is the amount we would get if we close the channel. +/// This value is not exact. Due to various in-flight changes and feerate changes, exactly this +/// amount is not likely to be recoverable on close. +/// +/// This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose +/// balance is not available for inclusion in new outbound HTLCs). This further does not include +/// any pending outgoing HTLCs which are awaiting some other resolution to be sent. +/// This does not consider any on-chain fees. +/// +/// See also [`ChannelDetails::outbound_capacity_msat`] +#[no_mangle] +pub extern "C" fn ChannelDetails_get_balance_msat(this_ptr: &ChannelDetails) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().balance_msat; + *inner_val +} +/// Our total balance. This is the amount we would get if we close the channel. +/// This value is not exact. Due to various in-flight changes and feerate changes, exactly this +/// amount is not likely to be recoverable on close. +/// +/// This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose +/// balance is not available for inclusion in new outbound HTLCs). This further does not include +/// any pending outgoing HTLCs which are awaiting some other resolution to be sent. +/// This does not consider any on-chain fees. +/// +/// See also [`ChannelDetails::outbound_capacity_msat`] +#[no_mangle] +pub extern "C" fn ChannelDetails_set_balance_msat(this_ptr: &mut ChannelDetails, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.balance_msat = 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 +/// any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not /// available for inclusion in new outbound HTLCs). This further does not include any pending /// outgoing HTLCs which are awaiting some other resolution to be sent. /// +/// See also [`ChannelDetails::balance_msat`] +/// /// This value is not exact. Due to various in-flight changes, feerate changes, and our /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we /// should be able to spend nearly this amount. @@ -694,10 +734,12 @@ pub extern "C" fn ChannelDetails_get_outbound_capacity_msat(this_ptr: &ChannelDe *inner_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 +/// any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not /// available for inclusion in new outbound HTLCs). This further does not include any pending /// outgoing HTLCs which are awaiting some other resolution to be sent. /// +/// See also [`ChannelDetails::balance_msat`] +/// /// This value is not exact. Due to various in-flight changes, feerate changes, and our /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we /// should be able to spend nearly this amount. @@ -706,7 +748,7 @@ pub extern "C" fn ChannelDetails_set_outbound_capacity_msat(this_ptr: &mut Chann unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_capacity_msat = val; } /// The available inbound capacity for the remote peer to send HTLCs to us. This does not -/// include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not +/// include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not /// available for inclusion in new inbound HTLCs). /// Note that there are some corner cases not fully handled here, so the actual available /// inbound capacity may be slightly higher than this. @@ -720,7 +762,7 @@ pub extern "C" fn ChannelDetails_get_inbound_capacity_msat(this_ptr: &ChannelDet *inner_val } /// The available inbound capacity for the remote peer to send HTLCs to us. This does not -/// include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not +/// include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not /// available for inclusion in new inbound HTLCs). /// Note that there are some corner cases not fully handled here, so the actual available /// inbound capacity may be slightly higher than this. @@ -855,7 +897,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_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 { +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 balance_msat_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 }; @@ -869,6 +911,7 @@ pub extern "C" fn ChannelDetails_new(mut channel_id_arg: crate::c_types::ThirtyT channel_value_satoshis: channel_value_satoshis_arg, unspendable_punishment_reserve: local_unspendable_punishment_reserve_arg, user_channel_id: user_channel_id_arg, + balance_msat: balance_msat_arg, outbound_capacity_msat: outbound_capacity_msat_arg, inbound_capacity_msat: inbound_capacity_msat_arg, confirmations_required: local_confirmations_required_arg, @@ -1328,10 +1371,12 @@ pub extern "C" fn ChannelManager_send_payment(this_arg: &ChannelManager, 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). +/// retry amount puts the payment more than 10% over the payment's total amount, if the payment +/// for the given `payment_id` cannot be found (likely due to timeout or success), or if +/// further retries have been disabled with [`abandon_payment`]. /// /// [`send_payment`]: [`ChannelManager::send_payment`] +/// [`abandon_payment`]: [`ChannelManager::abandon_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::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_NonePaymentSendFailureZ { @@ -1340,6 +1385,25 @@ pub extern "C" fn ChannelManager_retry_payment(this_arg: &ChannelManager, route: local_ret } +/// Signals that no further retries for the given payment will occur. +/// +/// After this method returns, any future calls to [`retry_payment`] for the given `payment_id` +/// will fail with [`PaymentSendFailure::ParameterError`]. If no such event has been generated, +/// an [`Event::PaymentFailed`] event will be generated as soon as there are no remaining +/// pending HTLCs for this payment. +/// +/// Note that calling this method does *not* prevent a payment from succeeding. You must still +/// wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to +/// determine the ultimate status of a payment. +/// +/// [`retry_payment`]: Self::retry_payment +/// [`Event::PaymentFailed`]: events::Event::PaymentFailed +/// [`Event::PaymentSent`]: events::Event::PaymentSent +#[no_mangle] +pub extern "C" fn ChannelManager_abandon_payment(this_arg: &ChannelManager, mut payment_id: crate::c_types::ThirtyTwoBytes) { + unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.abandon_payment(::lightning::ln::channelmanager::PaymentId(payment_id.data)) +} + /// Send a spontaneous payment, which is a payment that does not require the recipient to have /// generated an invoice. Optionally, you may specify the preimage. If you do choose to specify /// the preimage, it must be a cryptographically secure random value that no intermediate node @@ -1370,7 +1434,8 @@ pub extern "C" fn ChannelManager_send_spontaneous_payment(this_arg: &ChannelMana /// Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs /// or if no output was found which matches the parameters in [`Event::FundingGenerationReady`]. /// -/// Panics if a funding transaction has already been provided for this channel. +/// Returns [`APIError::ChannelUnavailable`] if a funding transaction has already been provided +/// for the channel or if the channel has been closed as indicated by [`Event::ChannelClosed`]. /// /// May panic if the output found in the funding transaction is duplicative with some other /// channel (note that this should be trivially prevented by using unique funding transaction @@ -1385,6 +1450,7 @@ pub extern "C" fn ChannelManager_send_spontaneous_payment(this_arg: &ChannelMana /// create a new channel with a conflicting funding transaction. /// /// [`Event::FundingGenerationReady`]: crate::util::events::Event::FundingGenerationReady +/// [`Event::ChannelClosed`]: crate::util::events::Event::ChannelClosed #[must_use] #[no_mangle] pub extern "C" fn ChannelManager_funding_transaction_generated(this_arg: &ChannelManager, temporary_channel_id: *const [u8; 32], mut funding_transaction: crate::c_types::Transaction) -> crate::c_types::derived::CResult_NoneAPIErrorZ { @@ -1453,19 +1519,21 @@ pub extern "C" fn ChannelManager_fail_htlc_backwards(this_arg: &ChannelManager, ret } -/// Provides a payment preimage in response to a PaymentReceived event, returning true and -/// generating message events for the net layer to claim the payment, if possible. Thus, you -/// should probably kick the net layer to go send messages if this returns true! +/// Provides a payment preimage in response to [`Event::PaymentReceived`], generating any +/// [`MessageSendEvent`]s needed to claim the payment. /// /// Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or /// [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentReceived` /// event matches your expectation. If you fail to do so and call this method, you may provide /// the sender \"proof-of-payment\" when they did not fulfill the full expected payment. /// -/// May panic if called except in response to a PaymentReceived event. +/// Returns whether any HTLCs were claimed, and thus if any new [`MessageSendEvent`]s are now +/// pending for processing via [`get_and_clear_pending_msg_events`]. /// +/// [`Event::PaymentReceived`]: crate::util::events::Event::PaymentReceived /// [`create_inbound_payment`]: Self::create_inbound_payment /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash +/// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events #[must_use] #[no_mangle] pub extern "C" fn ChannelManager_claim_funds(this_arg: &ChannelManager, mut payment_preimage: crate::c_types::ThirtyTwoBytes) -> bool { @@ -1485,7 +1553,7 @@ pub extern "C" fn ChannelManager_get_our_node_id(this_arg: &ChannelManager) -> c /// to pay us. /// /// This differs from [`create_inbound_payment_for_hash`] only in that it generates the -/// [`PaymentHash`] and [`PaymentPreimage`] for you, returning the first and storing the second. +/// [`PaymentHash`] and [`PaymentPreimage`] for you. /// /// The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentReceived`], which /// will have the [`PaymentReceived::payment_preimage`] field filled in. That should then be @@ -1493,16 +1561,42 @@ pub extern "C" fn ChannelManager_get_our_node_id(this_arg: &ChannelManager) -> c /// /// See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements. /// +/// Note that a malicious eavesdropper can intuit whether an inbound payment was created by +/// `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime. +/// +/// # Note +/// +/// If you register an inbound payment with this method, then serialize the `ChannelManager`, then +/// deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received. +/// +/// Errors if `min_value_msat` is greater than total bitcoin supply. +/// /// [`claim_funds`]: Self::claim_funds /// [`PaymentReceived`]: events::Event::PaymentReceived /// [`PaymentReceived::payment_preimage`]: events::Event::PaymentReceived::payment_preimage /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash #[must_use] #[no_mangle] -pub extern "C" fn ChannelManager_create_inbound_payment(this_arg: &ChannelManager, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32, mut user_payment_id: u64) -> crate::c_types::derived::C2Tuple_PaymentHashPaymentSecretZ { +pub extern "C" fn ChannelManager_create_inbound_payment(this_arg: &ChannelManager, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32) -> crate::c_types::derived::CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ { let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None }; - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment(local_min_value_msat, invoice_expiry_delta_secs, user_payment_id); - let (mut orig_ret_0, mut orig_ret_1) = ret; let mut local_ret = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0.0 }, crate::c_types::ThirtyTwoBytes { data: orig_ret_1.0 }).into(); + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment(local_min_value_msat, invoice_expiry_delta_secs); + 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::c_types::ThirtyTwoBytes { data: orig_ret_0_1.0 }).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() }; + local_ret +} + +/// Legacy version of [`create_inbound_payment`]. Use this method if you wish to share +/// serialized state with LDK node(s) running 0.0.103 and earlier. +/// +/// # Note +/// This method is deprecated and will be removed soon. +/// +/// [`create_inbound_payment`]: Self::create_inbound_payment +#[must_use] +#[no_mangle] +pub extern "C" fn ChannelManager_create_inbound_payment_legacy(this_arg: &ChannelManager, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32) -> crate::c_types::derived::CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ { + let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None }; + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment_legacy(local_min_value_msat, invoice_expiry_delta_secs); + 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::c_types::ThirtyTwoBytes { data: orig_ret_0_1.0 }).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() }; local_ret } @@ -1513,14 +1607,9 @@ pub extern "C" fn ChannelManager_create_inbound_payment(this_arg: &ChannelManage /// payment secret fetched via this method or [`create_inbound_payment`], and which is at least /// the `min_value_msat` provided here, if one is provided. /// -/// The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) must be globally unique. This -/// method may return an Err if another payment with the same payment_hash is still pending. -/// -/// `user_payment_id` will be provided back in [`PaymentPurpose::InvoicePayment::user_payment_id`] events to -/// allow tracking of which events correspond with which calls to this and -/// [`create_inbound_payment`]. `user_payment_id` has no meaning inside of LDK, it is simply -/// copied to events and otherwise ignored. It may be used to correlate PaymentReceived events -/// with invoice metadata stored elsewhere. +/// The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) should be globally unique, though +/// note that LDK will not stop you from registering duplicate payment hashes for inbound +/// payments. /// /// `min_value_msat` should be set if the invoice being generated contains a value. Any payment /// received for the returned [`PaymentHash`] will be required to be at least `min_value_msat` @@ -1539,23 +1628,56 @@ pub extern "C" fn ChannelManager_create_inbound_payment(this_arg: &ChannelManage /// If you need exact expiry semantics, you should enforce them upon receipt of /// [`PaymentReceived`]. /// -/// Pending inbound payments are stored in memory and in serialized versions of this -/// [`ChannelManager`]. If potentially unbounded numbers of inbound payments may exist and -/// space is limited, you may wish to rate-limit inbound payment creation. -/// /// May panic if `invoice_expiry_delta_secs` is greater than one year. /// /// Note that invoices generated for inbound payments should have their `min_final_cltv_expiry` /// set to at least [`MIN_FINAL_CLTV_EXPIRY`]. /// +/// Note that a malicious eavesdropper can intuit whether an inbound payment was created by +/// `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime. +/// +/// # Note +/// +/// If you register an inbound payment with this method, then serialize the `ChannelManager`, then +/// deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received. +/// +/// Errors if `min_value_msat` is greater than total bitcoin supply. +/// /// [`create_inbound_payment`]: Self::create_inbound_payment /// [`PaymentReceived`]: events::Event::PaymentReceived -/// [`PaymentPurpose::InvoicePayment::user_payment_id`]: events::PaymentPurpose::InvoicePayment::user_payment_id #[must_use] #[no_mangle] -pub extern "C" fn ChannelManager_create_inbound_payment_for_hash(this_arg: &ChannelManager, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32, mut user_payment_id: u64) -> crate::c_types::derived::CResult_PaymentSecretAPIErrorZ { +pub extern "C" fn ChannelManager_create_inbound_payment_for_hash(this_arg: &ChannelManager, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32) -> crate::c_types::derived::CResult_PaymentSecretNoneZ { let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None }; - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment_for_hash(::lightning::ln::PaymentHash(payment_hash.data), local_min_value_msat, invoice_expiry_delta_secs, user_payment_id); + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment_for_hash(::lightning::ln::PaymentHash(payment_hash.data), local_min_value_msat, invoice_expiry_delta_secs); + 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( { () /*e*/ }).into() }; + local_ret +} + +/// Legacy version of [`create_inbound_payment_for_hash`]. Use this method if you wish to share +/// serialized state with LDK node(s) running 0.0.103 and earlier. +/// +/// # Note +/// This method is deprecated and will be removed soon. +/// +/// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash +#[must_use] +#[no_mangle] +pub extern "C" fn ChannelManager_create_inbound_payment_for_hash_legacy(this_arg: &ChannelManager, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32) -> crate::c_types::derived::CResult_PaymentSecretAPIErrorZ { + let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None }; + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment_for_hash_legacy(::lightning::ln::PaymentHash(payment_hash.data), local_min_value_msat, invoice_expiry_delta_secs); + 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::util::errors::APIError::native_into(e) }).into() }; + local_ret +} + +/// Gets an LDK-generated payment preimage from a payment hash and payment secret that were +/// previously returned from [`create_inbound_payment`]. +/// +/// [`create_inbound_payment`]: Self::create_inbound_payment +#[must_use] +#[no_mangle] +pub extern "C" fn ChannelManager_get_payment_preimage(this_arg: &ChannelManager, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut payment_secret: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_PaymentPreimageAPIErrorZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_payment_preimage(::lightning::ln::PaymentHash(payment_hash.data), ::lightning::ln::PaymentSecret(payment_secret.data)); 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::util::errors::APIError::native_into(e) }).into() }; local_ret } @@ -1687,7 +1809,8 @@ extern "C" fn ChannelManager_Confirm_transaction_unconfirmed(this_arg: *const c_ /// indicating whether persistence is necessary. Only one listener on /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken /// up. -/// Note that the feature `allow_wallclock_use` must be enabled to use this function. +/// +/// Note that this method is not available with the `no-std` feature. #[must_use] #[no_mangle] pub extern "C" fn ChannelManager_await_persistable_update_timeout(this_arg: &ChannelManager, mut max_wait: u64) -> bool { diff --git a/lightning-c-bindings/src/lightning/ln/features.rs b/lightning-c-bindings/src/lightning/ln/features.rs index 591173e..c0a52b3 100644 --- a/lightning-c-bindings/src/lightning/ln/features.rs +++ b/lightning-c-bindings/src/lightning/ln/features.rs @@ -72,6 +72,15 @@ pub extern "C" fn InvoiceFeatures_eq(a: &InvoiceFeatures, b: &InvoiceFeatures) - if a.inner.is_null() || b.inner.is_null() { return false; } if a.get_native_ref() == b.get_native_ref() { true } else { false } } +/// Checks if two ChannelTypeFeaturess 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 ChannelTypeFeatures_eq(a: &ChannelTypeFeatures, b: &ChannelTypeFeatures) -> 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 } +} impl Clone for InitFeatures { fn clone(&self) -> Self { Self { @@ -148,6 +157,25 @@ pub(crate) extern "C" fn InvoiceFeatures_clone_void(this_ptr: *const c_void) -> pub extern "C" fn InvoiceFeatures_clone(orig: &InvoiceFeatures) -> InvoiceFeatures { orig.clone() } +impl Clone for ChannelTypeFeatures { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeChannelTypeFeatures>::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 ChannelTypeFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelTypeFeatures)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the ChannelTypeFeatures +pub extern "C" fn ChannelTypeFeatures_clone(orig: &ChannelTypeFeatures) -> ChannelTypeFeatures { + orig.clone() +} use lightning::ln::features::InitFeatures as nativeInitFeaturesImport; pub(crate) type nativeInitFeatures = nativeInitFeaturesImport; @@ -352,6 +380,66 @@ impl InvoiceFeatures { ret } } + +use lightning::ln::features::ChannelTypeFeatures as nativeChannelTypeFeaturesImport; +pub(crate) type nativeChannelTypeFeatures = nativeChannelTypeFeaturesImport; + +/// Features used within the channel_type field in an OpenChannel message. +/// +/// A channel is always of some known \"type\", describing the transaction formats used and the exact +/// semantics of our interaction with our peer. +/// +/// Note that because a channel is a specific type which is proposed by the opener and accepted by +/// the counterparty, only required features are allowed here. +/// +/// This is serialized differently from other feature types - it is not prefixed by a length, and +/// thus must only appear inside a TLV where its length is known in advance. +#[must_use] +#[repr(C)] +pub struct ChannelTypeFeatures { + /// 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 nativeChannelTypeFeatures, + /// 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 ChannelTypeFeatures { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeChannelTypeFeatures>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the ChannelTypeFeatures, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn ChannelTypeFeatures_free(this_obj: ChannelTypeFeatures) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ChannelTypeFeatures_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelTypeFeatures); } +} +#[allow(unused)] +impl ChannelTypeFeatures { + pub(crate) fn get_native_ref(&self) -> &'static nativeChannelTypeFeatures { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelTypeFeatures { + 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 nativeChannelTypeFeatures { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = std::ptr::null_mut(); + ret + } +} /// Create a blank Features with no features set #[must_use] #[no_mangle] @@ -452,27 +540,28 @@ pub extern "C" fn InvoiceFeatures_requires_unknown_bits(this_arg: &InvoiceFeatur ret } -/// Returns whether the `payment_secret` feature is supported. +/// Create a blank Features with no features set #[must_use] #[no_mangle] -pub extern "C" fn InitFeatures_supports_payment_secret(this_arg: &InitFeatures) -> bool { - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supports_payment_secret(); - ret +pub extern "C" fn ChannelTypeFeatures_empty() -> ChannelTypeFeatures { + let mut ret = lightning::ln::features::ChannelTypeFeatures::empty(); + ChannelTypeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true } } -/// Returns whether the `payment_secret` feature is supported. +/// Creates a Features with the bits set which are known by the implementation #[must_use] #[no_mangle] -pub extern "C" fn NodeFeatures_supports_payment_secret(this_arg: &NodeFeatures) -> bool { - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supports_payment_secret(); - ret +pub extern "C" fn ChannelTypeFeatures_known() -> ChannelTypeFeatures { + let mut ret = lightning::ln::features::ChannelTypeFeatures::known(); + ChannelTypeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true } } -/// Returns whether the `payment_secret` feature is supported. +/// Returns true if this `Features` object contains unknown feature flags which are set as +/// \"required\". #[must_use] #[no_mangle] -pub extern "C" fn InvoiceFeatures_supports_payment_secret(this_arg: &InvoiceFeatures) -> bool { - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supports_payment_secret(); +pub extern "C" fn ChannelTypeFeatures_requires_unknown_bits(this_arg: &ChannelTypeFeatures) -> bool { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.requires_unknown_bits(); ret } @@ -486,13 +575,11 @@ pub(crate) extern "C" fn InitFeatures_write_void(obj: *const c_void) -> crate::c crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInitFeatures) }) } #[no_mangle] -/// Serialize the NodeFeatures object into a byte array which can be read by NodeFeatures_read -pub extern "C" fn NodeFeatures_write(obj: &NodeFeatures) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) -} -#[no_mangle] -pub(crate) extern "C" fn NodeFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeFeatures) }) +/// Read a InitFeatures from a byte array, created by InitFeatures_write +pub extern "C" fn InitFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InitFeaturesDecodeErrorZ { + let res: Result = crate::c_types::deserialize_obj(ser); + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::features::InitFeatures { 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 } #[no_mangle] /// Serialize the ChannelFeatures object into a byte array which can be read by ChannelFeatures_read @@ -504,20 +591,20 @@ pub(crate) extern "C" fn ChannelFeatures_write_void(obj: *const c_void) -> crate crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelFeatures) }) } #[no_mangle] -/// Serialize the InvoiceFeatures object into a byte array which can be read by InvoiceFeatures_read -pub extern "C" fn InvoiceFeatures_write(obj: &InvoiceFeatures) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +/// Read a ChannelFeatures from a byte array, created by ChannelFeatures_write +pub extern "C" fn ChannelFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelFeaturesDecodeErrorZ { + let res: Result = crate::c_types::deserialize_obj(ser); + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::features::ChannelFeatures { 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 } #[no_mangle] -pub(crate) extern "C" fn InvoiceFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInvoiceFeatures) }) +/// Serialize the NodeFeatures object into a byte array which can be read by NodeFeatures_read +pub extern "C" fn NodeFeatures_write(obj: &NodeFeatures) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } #[no_mangle] -/// Read a InitFeatures from a byte array, created by InitFeatures_write -pub extern "C" fn InitFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InitFeaturesDecodeErrorZ { - let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::features::InitFeatures { 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 +pub(crate) extern "C" fn NodeFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeFeatures) }) } #[no_mangle] /// Read a NodeFeatures from a byte array, created by NodeFeatures_write @@ -527,11 +614,13 @@ pub extern "C" fn NodeFeatures_read(ser: crate::c_types::u8slice) -> crate::c_ty local_res } #[no_mangle] -/// Read a ChannelFeatures from a byte array, created by ChannelFeatures_write -pub extern "C" fn ChannelFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelFeaturesDecodeErrorZ { - let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::features::ChannelFeatures { 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 +/// Serialize the InvoiceFeatures object into a byte array which can be read by InvoiceFeatures_read +pub extern "C" fn InvoiceFeatures_write(obj: &InvoiceFeatures) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[no_mangle] +pub(crate) extern "C" fn InvoiceFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInvoiceFeatures) }) } #[no_mangle] /// Read a InvoiceFeatures from a byte array, created by InvoiceFeatures_write @@ -540,3 +629,19 @@ pub extern "C" fn InvoiceFeatures_read(ser: crate::c_types::u8slice) -> crate::c let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::features::InvoiceFeatures { 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 } +#[no_mangle] +/// Serialize the ChannelTypeFeatures object into a byte array which can be read by ChannelTypeFeatures_read +pub extern "C" fn ChannelTypeFeatures_write(obj: &ChannelTypeFeatures) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[no_mangle] +pub(crate) extern "C" fn ChannelTypeFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelTypeFeatures) }) +} +#[no_mangle] +/// Read a ChannelTypeFeatures from a byte array, created by ChannelTypeFeatures_write +pub extern "C" fn ChannelTypeFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelTypeFeaturesDecodeErrorZ { + let res: Result = crate::c_types::deserialize_obj(ser); + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::features::ChannelTypeFeatures { 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 +} diff --git a/lightning-c-bindings/src/lightning/ln/msgs.rs b/lightning-c-bindings/src/lightning/ln/msgs.rs index 62bfae5..a5a729c 100644 --- a/lightning-c-bindings/src/lightning/ln/msgs.rs +++ b/lightning-c-bindings/src/lightning/ln/msgs.rs @@ -738,6 +738,27 @@ pub extern "C" fn OpenChannel_get_channel_flags(this_ptr: &OpenChannel) -> u8 { pub extern "C" fn OpenChannel_set_channel_flags(this_ptr: &mut OpenChannel, mut val: u8) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_flags = val; } +/// The channel type that this channel will represent. If none is set, we derive the channel +/// type from the intersection of our feature bits with our counterparty's feature bits from +/// the Init message. +/// +/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None +#[no_mangle] +pub extern "C" fn OpenChannel_get_channel_type(this_ptr: &OpenChannel) -> crate::lightning::ln::features::ChannelTypeFeatures { + let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_type; + let mut local_inner_val = crate::lightning::ln::features::ChannelTypeFeatures { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::features::ChannelTypeFeatures<>) as *mut _ }, is_owned: false }; + local_inner_val +} +/// The channel type that this channel will represent. If none is set, we derive the channel +/// type from the intersection of our feature bits with our counterparty's feature bits from +/// the Init message. +/// +/// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None +#[no_mangle] +pub extern "C" fn OpenChannel_set_channel_type(this_ptr: &mut OpenChannel, mut val: crate::lightning::ln::features::ChannelTypeFeatures) { + let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_type = local_val; +} impl Clone for OpenChannel { fn clone(&self) -> Self { Self { @@ -2762,12 +2783,10 @@ pub enum NetAddress { port: u16, }, /// An old-style Tor onion address/port on which the peer is listening. - OnionV2 { - /// The bytes (usually encoded in base32 with \".onion\" appended) - addr: crate::c_types::TenBytes, - /// The port on which the node is listening - port: u16, - }, + /// + /// This field is deprecated and the Tor network generally no longer supports V2 Onion + /// addresses. Thus, the details are not parsed here. + OnionV2(crate::c_types::TwelveBytes), /// A new-style Tor onion address/port on which the peer is listening. /// To create the human-readable \"hostname\", concatenate ed25519_pubkey, checksum, and version, /// wrap as base32 and append \".onion\". @@ -2803,13 +2822,11 @@ impl NetAddress { port: port_nonref, } }, - NetAddress::OnionV2 {ref addr, ref port, } => { - let mut addr_nonref = (*addr).clone(); - let mut port_nonref = (*port).clone(); - nativeNetAddress::OnionV2 { - addr: addr_nonref.data, - port: port_nonref, - } + NetAddress::OnionV2 (ref a, ) => { + let mut a_nonref = (*a).clone(); + nativeNetAddress::OnionV2 ( + a_nonref.data, + ) }, NetAddress::OnionV3 {ref ed25519_pubkey, ref checksum, ref version, ref port, } => { let mut ed25519_pubkey_nonref = (*ed25519_pubkey).clone(); @@ -2840,11 +2857,10 @@ impl NetAddress { port: port, } }, - NetAddress::OnionV2 {mut addr, mut port, } => { - nativeNetAddress::OnionV2 { - addr: addr.data, - port: port, - } + NetAddress::OnionV2 (mut a, ) => { + nativeNetAddress::OnionV2 ( + a.data, + ) }, NetAddress::OnionV3 {mut ed25519_pubkey, mut checksum, mut version, mut port, } => { nativeNetAddress::OnionV3 { @@ -2875,13 +2891,11 @@ impl NetAddress { port: port_nonref, } }, - nativeNetAddress::OnionV2 {ref addr, ref port, } => { - let mut addr_nonref = (*addr).clone(); - let mut port_nonref = (*port).clone(); - NetAddress::OnionV2 { - addr: crate::c_types::TenBytes { data: addr_nonref }, - port: port_nonref, - } + nativeNetAddress::OnionV2 (ref a, ) => { + let mut a_nonref = (*a).clone(); + NetAddress::OnionV2 ( + crate::c_types::TwelveBytes { data: a_nonref }, + ) }, nativeNetAddress::OnionV3 {ref ed25519_pubkey, ref checksum, ref version, ref port, } => { let mut ed25519_pubkey_nonref = (*ed25519_pubkey).clone(); @@ -2912,11 +2926,10 @@ impl NetAddress { port: port, } }, - nativeNetAddress::OnionV2 {mut addr, mut port, } => { - NetAddress::OnionV2 { - addr: crate::c_types::TenBytes { data: addr }, - port: port, - } + nativeNetAddress::OnionV2 (mut a, ) => { + NetAddress::OnionV2 ( + crate::c_types::TwelveBytes { data: a }, + ) }, nativeNetAddress::OnionV3 {mut ed25519_pubkey, mut checksum, mut version, mut port, } => { NetAddress::OnionV3 { @@ -2955,11 +2968,8 @@ pub extern "C" fn NetAddress_ipv6(addr: crate::c_types::SixteenBytes, port: u16) } #[no_mangle] /// Utility method to constructs a new OnionV2-variant NetAddress -pub extern "C" fn NetAddress_onion_v2(addr: crate::c_types::TenBytes, port: u16) -> NetAddress { - NetAddress::OnionV2 { - addr, - port, - } +pub extern "C" fn NetAddress_onion_v2(a: crate::c_types::TwelveBytes) -> NetAddress { + NetAddress::OnionV2(a, ) } #[no_mangle] /// Utility method to constructs a new OnionV3-variant NetAddress @@ -4373,6 +4383,10 @@ pub enum ErrorAction { /// The peer did something harmless that we weren't able to meaningfully process. /// If the error is logged, log it at the given level. IgnoreAndLog(crate::lightning::util::logger::Level), + /// The peer provided us with a gossip message which we'd already seen. In most cases this + /// should be ignored, but it may result in the message being forwarded if it is a duplicate of + /// our own channel announcements. + IgnoreDuplicateGossip, /// The peer did something incorrect. Tell them. SendErrorMessage { /// The message to send. @@ -4398,6 +4412,7 @@ impl ErrorAction { a_nonref.into_native(), ) }, + ErrorAction::IgnoreDuplicateGossip => nativeErrorAction::IgnoreDuplicateGossip, ErrorAction::SendErrorMessage {ref msg, } => { let mut msg_nonref = (*msg).clone(); nativeErrorAction::SendErrorMessage { @@ -4421,6 +4436,7 @@ impl ErrorAction { a.into_native(), ) }, + ErrorAction::IgnoreDuplicateGossip => nativeErrorAction::IgnoreDuplicateGossip, ErrorAction::SendErrorMessage {mut msg, } => { nativeErrorAction::SendErrorMessage { msg: *unsafe { Box::from_raw(msg.take_inner()) }, @@ -4445,6 +4461,7 @@ impl ErrorAction { crate::lightning::util::logger::Level::native_into(a_nonref), ) }, + nativeErrorAction::IgnoreDuplicateGossip => ErrorAction::IgnoreDuplicateGossip, nativeErrorAction::SendErrorMessage {ref msg, } => { let mut msg_nonref = (*msg).clone(); ErrorAction::SendErrorMessage { @@ -4468,6 +4485,7 @@ impl ErrorAction { crate::lightning::util::logger::Level::native_into(a), ) }, + nativeErrorAction::IgnoreDuplicateGossip => ErrorAction::IgnoreDuplicateGossip, nativeErrorAction::SendErrorMessage {mut msg, } => { ErrorAction::SendErrorMessage { msg: crate::lightning::ln::msgs::ErrorMessage { inner: ObjOps::heap_alloc(msg), is_owned: true }, @@ -4501,6 +4519,10 @@ pub extern "C" fn ErrorAction_ignore_and_log(a: crate::lightning::util::logger:: ErrorAction::IgnoreAndLog(a, ) } #[no_mangle] +/// Utility method to constructs a new IgnoreDuplicateGossip-variant ErrorAction +pub extern "C" fn ErrorAction_ignore_duplicate_gossip() -> ErrorAction { + ErrorAction::IgnoreDuplicateGossip} +#[no_mangle] /// Utility method to constructs a new SendErrorMessage-variant ErrorAction pub extern "C" fn ErrorAction_send_error_message(msg: crate::lightning::ln::msgs::ErrorMessage) -> ErrorAction { ErrorAction::SendErrorMessage { diff --git a/lightning-c-bindings/src/lightning/ln/script.rs b/lightning-c-bindings/src/lightning/ln/script.rs index f40f364..b171adb 100644 --- a/lightning-c-bindings/src/lightning/ln/script.rs +++ b/lightning-c-bindings/src/lightning/ln/script.rs @@ -160,6 +160,25 @@ pub extern "C" fn InvalidShutdownScript_new(mut script_arg: crate::c_types::deri script: ::bitcoin::blockdata::script::Script::from(script_arg.into_rust()), }), is_owned: true } } +impl Clone for InvalidShutdownScript { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeInvalidShutdownScript>::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 InvalidShutdownScript_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvalidShutdownScript)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the InvalidShutdownScript +pub extern "C" fn InvalidShutdownScript_clone(orig: &InvalidShutdownScript) -> InvalidShutdownScript { + orig.clone() +} #[no_mangle] /// Serialize the ShutdownScript object into a byte array which can be read by ShutdownScript_read pub extern "C" fn ShutdownScript_write(obj: &ShutdownScript) -> crate::c_types::derived::CVec_u8Z { diff --git a/lightning-c-bindings/src/lightning/routing/mod.rs b/lightning-c-bindings/src/lightning/routing/mod.rs index 3348db0..40f2cd2 100644 --- a/lightning-c-bindings/src/lightning/routing/mod.rs +++ b/lightning-c-bindings/src/lightning/routing/mod.rs @@ -16,148 +16,4 @@ use crate::c_types::*; 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 - /// in the direction from `source` to `target`. - #[must_use] - pub channel_penalty_msat: extern "C" fn (this_arg: *const c_void, short_channel_id: u64, source: &crate::lightning::routing::network_graph::NodeId, target: &crate::lightning::routing::network_graph::NodeId) -> u64, - /// Handles updating channel penalties after failing to route through a channel. - pub payment_path_failed: extern "C" fn (this_arg: *mut c_void, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: u64), - /// Serialize the object into a byte array - pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z, - /// 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), - payment_path_failed: Clone::clone(&orig.payment_path_failed), - write: Clone::clone(&orig.write), - free: Clone::clone(&orig.free), - } -} -impl lightning::util::ser::Writeable for Score { - fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { - let vec = (self.write)(self.this_arg); - w.write_all(vec.as_slice()) - } -} - -use lightning::routing::Score as rustScore; -impl rustScore for Score { - fn channel_penalty_msat(&self, mut short_channel_id: u64, mut source: &lightning::routing::network_graph::NodeId, mut target: &lightning::routing::network_graph::NodeId) -> u64 { - let mut ret = (self.channel_penalty_msat)(self.this_arg, short_channel_id, &crate::lightning::routing::network_graph::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((source as *const lightning::routing::network_graph::NodeId<>) as *mut _) }, is_owned: false }, &crate::lightning::routing::network_graph::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((target as *const lightning::routing::network_graph::NodeId<>) as *mut _) }, is_owned: false }); - ret - } - fn payment_path_failed(&mut self, mut path: &[&lightning::routing::router::RouteHop], mut short_channel_id: u64) { - let mut local_path = Vec::new(); for item in path.iter() { local_path.push( { crate::lightning::routing::router::RouteHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner(((*item) as *const lightning::routing::router::RouteHop<>) as *mut _) }, is_owned: false } }); }; - (self.payment_path_failed)(self.this_arg, local_path.into(), short_channel_id) - } -} - -// 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); - } - } -} - -use lightning::routing::LockableScore as nativeLockableScoreImport; -pub(crate) type nativeLockableScore = nativeLockableScoreImport; - -/// A scorer that is accessed under a lock. -/// -/// Needed so that calls to [`Score::channel_penalty_msat`] in [`find_route`] can be made while -/// having shared ownership of a scorer but without requiring internal locking in [`Score`] -/// implementations. Internal locking would be detrimental to route finding performance and could -/// result in [`Score::channel_penalty_msat`] returning a different value for the same channel. -/// -/// [`find_route`]: crate::routing::router::find_route -#[must_use] -#[repr(C)] -pub struct LockableScore { - /// 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 nativeLockableScore, - /// 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 LockableScore { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeLockableScore>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; - } - } -} -/// Frees any resources used by the LockableScore, if is_owned is set and inner is non-NULL. -#[no_mangle] -pub extern "C" fn LockableScore_free(this_obj: LockableScore) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn LockableScore_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeLockableScore); } -} -#[allow(unused)] -impl LockableScore { - pub(crate) fn get_native_ref(&self) -> &'static nativeLockableScore { - unsafe { &*ObjOps::untweak_ptr(self.inner) } - } - pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeLockableScore { - 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 nativeLockableScore { - assert!(self.is_owned); - let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); - ret - } -} -/// Constructs a new LockableScore from a Score -#[must_use] -#[no_mangle] -pub extern "C" fn LockableScore_new(mut score: crate::lightning::routing::Score) -> LockableScore { - let mut ret = lightning::routing::LockableScore::new(score); - LockableScore { inner: ObjOps::heap_alloc(ret), is_owned: true } -} - -#[no_mangle] -/// Serialize the LockableScore object into a byte array which can be read by LockableScore_read -pub extern "C" fn LockableScore_write(obj: &LockableScore) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) -} -#[no_mangle] -pub(crate) extern "C" fn LockableScore_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeLockableScore) }) -} +pub mod scoring; diff --git a/lightning-c-bindings/src/lightning/routing/network_graph.rs b/lightning-c-bindings/src/lightning/routing/network_graph.rs index 9c7e3e3..6356160 100644 --- a/lightning-c-bindings/src/lightning/routing/network_graph.rs +++ b/lightning-c-bindings/src/lightning/routing/network_graph.rs @@ -1003,24 +1003,6 @@ pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInf let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val; } -/// 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::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: *unsafe { Box::from_raw(node_one_arg.take_inner()) }, - one_to_two: local_one_to_two_arg, - 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, - }), is_owned: true } -} impl Clone for ChannelInfo { fn clone(&self) -> Self { Self { @@ -1626,12 +1608,30 @@ pub extern "C" fn NetworkGraph_fail_node(this_arg: &NetworkGraph, mut _node_id: unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_node(&_node_id.into_rust(), is_permanent) } +/// Removes information about channels that we haven't heard any updates about in some time. +/// This can be used regularly to prune the network graph of channels that likely no longer +/// exist. +/// +/// While there is no formal requirement that nodes regularly re-broadcast their channel +/// updates every two weeks, the non-normative section of BOLT 7 currently suggests that +/// pruning occur for updates which are at least two weeks old, which we implement here. +/// +/// This function takes the current unix time as an argument. For users with the `std` feature +/// enabled, [`NetworkGraph::remove_stale_channels`] may be preferable. +#[no_mangle] +pub extern "C" fn NetworkGraph_remove_stale_channels_with_time(this_arg: &NetworkGraph, mut current_time_unix: u64) { + unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.remove_stale_channels_with_time(current_time_unix) +} + /// For an already known (from announcement) channel, update info about one of the directions /// of the channel. /// /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept /// routing messages from a source using a protocol other than the lightning P2P protocol. +/// +/// If built with `no-std`, any updates with a timestamp more than two weeks in the past or +/// materially in the future will be rejected. #[must_use] #[no_mangle] pub extern "C" fn NetworkGraph_update_channel(this_arg: &NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ { @@ -1643,6 +1643,9 @@ pub extern "C" fn NetworkGraph_update_channel(this_arg: &NetworkGraph, msg: &cra /// For an already known (from announcement) channel, update info about one of the directions /// of the channel without verifying the associated signatures. Because we aren't given the /// associated signatures here we cannot relay the channel update to any of our peers. +/// +/// If built with `no-std`, any updates with a timestamp more than two weeks in the past or +/// materially in the future will be rejected. #[must_use] #[no_mangle] pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ { diff --git a/lightning-c-bindings/src/lightning/routing/router.rs b/lightning-c-bindings/src/lightning/routing/router.rs index 6f8692a..af38952 100644 --- a/lightning-c-bindings/src/lightning/routing/router.rs +++ b/lightning-c-bindings/src/lightning/routing/router.rs @@ -1074,7 +1074,7 @@ pub extern "C" fn RouteHintHop_read(ser: crate::c_types::u8slice) -> crate::c_ty /// /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None #[no_mangle] -pub extern "C" fn find_route(mut our_node_pubkey: crate::c_types::PublicKey, params: &crate::lightning::routing::router::RouteParameters, network: &crate::lightning::routing::network_graph::NetworkGraph, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut logger: crate::lightning::util::logger::Logger, scorer: &crate::lightning::routing::Score) -> crate::c_types::derived::CResult_RouteLightningErrorZ { +pub extern "C" fn find_route(mut our_node_pubkey: crate::c_types::PublicKey, params: &crate::lightning::routing::router::RouteParameters, network: &crate::lightning::routing::network_graph::NetworkGraph, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut logger: crate::lightning::util::logger::Logger, scorer: &crate::lightning::routing::scoring::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 ret = lightning::routing::router::find_route(&our_node_pubkey.into_rust(), params.get_native_ref(), network.get_native_ref(), local_first_hops, 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() }; diff --git a/lightning-c-bindings/src/lightning/routing/scorer.rs b/lightning-c-bindings/src/lightning/routing/scorer.rs deleted file mode 100644 index 00dd4ab..0000000 --- a/lightning-c-bindings/src/lightning/routing/scorer.rs +++ /dev/null @@ -1,331 +0,0 @@ -// 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 [`find_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::{RouteParameters, find_route}; -//! # use lightning::routing::scorer::{Scorer, ScoringParameters}; -//! # 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, params: RouteParameters, network_graph: NetworkGraph) { -//! # let logger = FakeLogger {}; -//! # -//! // Use the default channel penalties. -//! let scorer = Scorer::default(); -//! -//! // Or use custom channel penalties. -//! let scorer = Scorer::new(ScoringParameters { -//! base_penalty_msat: 1000, -//! failure_penalty_msat: 2 * 1024 * 1000, -//! ..ScoringParameters::default() -//! }); -//! -//! let route = find_route(&payer, ¶ms, &network_graph, None, &logger, &scorer); -//! # } -//! ``` -//! -//! # Note -//! -//! If persisting [`Scorer`], it must be restored using the same [`Time`] parameterization. Using a -//! different type results in undefined behavior. Specifically, persisting when built with feature -//! `no-std` and restoring without it, or vice versa, uses different types and thus is undefined. -//! -//! [`find_route`]: crate::routing::router::find_route - -use std::str::FromStr; -use std::ffi::c_void; -use core::convert::Infallible; -use bitcoin::hashes::Hash; -use crate::c_types::*; - -mod sealed { - -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; -pub(crate) 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. Will further penalize channels that fail to relay payments. -/// -/// 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 -pub(crate) 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 - } -} - -use lightning::routing::scorer::ScoringParameters as nativeScoringParametersImport; -pub(crate) type nativeScoringParameters = nativeScoringParametersImport; - -/// Parameters for configuring [`Scorer`]. -#[must_use] -#[repr(C)] -pub struct ScoringParameters { - /// 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 nativeScoringParameters, - /// 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 ScoringParameters { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeScoringParameters>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; - } - } -} -/// Frees any resources used by the ScoringParameters, if is_owned is set and inner is non-NULL. -#[no_mangle] -pub extern "C" fn ScoringParameters_free(this_obj: ScoringParameters) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ScoringParameters_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeScoringParameters); } -} -#[allow(unused)] -impl ScoringParameters { - pub(crate) fn get_native_ref(&self) -> &'static nativeScoringParameters { - unsafe { &*ObjOps::untweak_ptr(self.inner) } - } - pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeScoringParameters { - 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 nativeScoringParameters { - assert!(self.is_owned); - let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); - ret - } -} -/// A fixed penalty in msats to apply to each channel. -#[no_mangle] -pub extern "C" fn ScoringParameters_get_base_penalty_msat(this_ptr: &ScoringParameters) -> u64 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().base_penalty_msat; - *inner_val -} -/// A fixed penalty in msats to apply to each channel. -#[no_mangle] -pub extern "C" fn ScoringParameters_set_base_penalty_msat(this_ptr: &mut ScoringParameters, mut val: u64) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_penalty_msat = val; -} -/// A penalty in msats to apply to a channel upon failing to relay a payment. -/// -/// This accumulates for each failure but may be reduced over time based on -/// [`failure_penalty_half_life`]. -/// -/// [`failure_penalty_half_life`]: Self::failure_penalty_half_life -#[no_mangle] -pub extern "C" fn ScoringParameters_get_failure_penalty_msat(this_ptr: &ScoringParameters) -> u64 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().failure_penalty_msat; - *inner_val -} -/// A penalty in msats to apply to a channel upon failing to relay a payment. -/// -/// This accumulates for each failure but may be reduced over time based on -/// [`failure_penalty_half_life`]. -/// -/// [`failure_penalty_half_life`]: Self::failure_penalty_half_life -#[no_mangle] -pub extern "C" fn ScoringParameters_set_failure_penalty_msat(this_ptr: &mut ScoringParameters, mut val: u64) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.failure_penalty_msat = val; -} -/// The time required to elapse before any accumulated [`failure_penalty_msat`] penalties are -/// cut in half. -/// -/// # Note -/// -/// When time is an [`Eternity`], as is default when enabling feature `no-std`, it will never -/// elapse. Therefore, this penalty will never decay. -/// -/// [`failure_penalty_msat`]: Self::failure_penalty_msat -#[no_mangle] -pub extern "C" fn ScoringParameters_get_failure_penalty_half_life(this_ptr: &ScoringParameters) -> u64 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().failure_penalty_half_life; - inner_val.as_secs() -} -/// The time required to elapse before any accumulated [`failure_penalty_msat`] penalties are -/// cut in half. -/// -/// # Note -/// -/// When time is an [`Eternity`], as is default when enabling feature `no-std`, it will never -/// elapse. Therefore, this penalty will never decay. -/// -/// [`failure_penalty_msat`]: Self::failure_penalty_msat -#[no_mangle] -pub extern "C" fn ScoringParameters_set_failure_penalty_half_life(this_ptr: &mut ScoringParameters, mut val: u64) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.failure_penalty_half_life = std::time::Duration::from_secs(val); -} -/// Constructs a new ScoringParameters given each field -#[must_use] -#[no_mangle] -pub extern "C" fn ScoringParameters_new(mut base_penalty_msat_arg: u64, mut failure_penalty_msat_arg: u64, mut failure_penalty_half_life_arg: u64) -> ScoringParameters { - ScoringParameters { inner: ObjOps::heap_alloc(nativeScoringParameters { - base_penalty_msat: base_penalty_msat_arg, - failure_penalty_msat: failure_penalty_msat_arg, - failure_penalty_half_life: std::time::Duration::from_secs(failure_penalty_half_life_arg), - }), is_owned: true } -} -#[no_mangle] -/// Serialize the ScoringParameters object into a byte array which can be read by ScoringParameters_read -pub extern "C" fn ScoringParameters_write(obj: &ScoringParameters) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) -} -#[no_mangle] -pub(crate) extern "C" fn ScoringParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeScoringParameters) }) -} -#[no_mangle] -/// Read a ScoringParameters from a byte array, created by ScoringParameters_write -pub extern "C" fn ScoringParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ScoringParametersDecodeErrorZ { - let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::scorer::ScoringParameters { 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 -} -/// Creates a new scorer using the given scoring parameters. -#[must_use] -#[no_mangle] -pub extern "C" fn Scorer_new(mut params: crate::lightning::routing::scorer::ScoringParameters) -> Scorer { - let mut ret = lightning::routing::scorer::Scorer::new(*unsafe { Box::from_raw(params.take_inner()) }); - 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 } -} -/// Creates a "default" ScoringParameters. See struct and individual field documentaiton for details on which values are used. -#[must_use] -#[no_mangle] -pub extern "C" fn ScoringParameters_default() -> ScoringParameters { - ScoringParameters { 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, - payment_path_failed: Scorer_Score_payment_path_failed, - write: Scorer_write_void, - } -} - -#[must_use] -extern "C" fn Scorer_Score_channel_penalty_msat(this_arg: *const c_void, mut short_channel_id: u64, _source: &crate::lightning::routing::network_graph::NodeId, _target: &crate::lightning::routing::network_graph::NodeId) -> u64 { - let mut ret = >::channel_penalty_msat(unsafe { &mut *(this_arg as *mut nativeScorer) }, short_channel_id, _source.get_native_ref(), _target.get_native_ref()); - ret -} -extern "C" fn Scorer_Score_payment_path_failed(this_arg: *mut c_void, mut _path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) { - let mut local__path = Vec::new(); for mut item in _path.as_slice().iter() { local__path.push( { item.get_native_ref() }); }; - >::payment_path_failed(unsafe { &mut *(this_arg as *mut nativeScorer) }, &local__path[..], short_channel_id) -} - -#[no_mangle] -/// Serialize the Scorer object into a byte array which can be read by Scorer_read -pub extern "C" fn Scorer_write(obj: &Scorer) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) -} -#[no_mangle] -pub(crate) extern "C" fn Scorer_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeScorer) }) -} -#[no_mangle] -/// Read a Scorer from a byte array, created by Scorer_write -pub extern "C" fn Scorer_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ScorerDecodeErrorZ { - let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::scorer::Scorer { 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 -} diff --git a/lightning-c-bindings/src/lightning/routing/scoring.rs b/lightning-c-bindings/src/lightning/routing/scoring.rs new file mode 100644 index 0000000..bc3af0a --- /dev/null +++ b/lightning-c-bindings/src/lightning/routing/scoring.rs @@ -0,0 +1,598 @@ +// 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 [`find_route`] to score payment channels during path finding when a +//! custom [`Score`] implementation is not needed. +//! +//! # Example +//! +//! ``` +//! # extern crate secp256k1; +//! # +//! # use lightning::routing::network_graph::NetworkGraph; +//! # use lightning::routing::router::{RouteParameters, find_route}; +//! # use lightning::routing::scoring::{Scorer, ScoringParameters}; +//! # 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, params: RouteParameters, network_graph: NetworkGraph) { +//! # let logger = FakeLogger {}; +//! # +//! // Use the default channel penalties. +//! let scorer = Scorer::default(); +//! +//! // Or use custom channel penalties. +//! let scorer = Scorer::new(ScoringParameters { +//! base_penalty_msat: 1000, +//! failure_penalty_msat: 2 * 1024 * 1000, +//! ..ScoringParameters::default() +//! }); +//! +//! let route = find_route(&payer, ¶ms, &network_graph, None, &logger, &scorer); +//! # } +//! ``` +//! +//! # Note +//! +//! Persisting when built with feature `no-std` and restoring without it, or vice versa, uses +//! different types and thus is undefined. +//! +//! [`find_route`]: crate::routing::router::find_route + +use std::str::FromStr; +use std::ffi::c_void; +use core::convert::Infallible; +use bitcoin::hashes::Hash; +use crate::c_types::*; + +/// 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 `send_amt_msat` through the + /// given channel in the direction from `source` to `target`. + /// + /// The channel's capacity (less any other MPP parts which are also being considered for use in + /// the same payment) is given by `channel_capacity_msat`. It may be guessed from various + /// sources or assumed from no data at all. + /// + /// For hints provided in the invoice, we assume the channel has sufficient capacity to accept + /// the invoice's full amount, and provide a `channel_capacity_msat` of `None`. In all other + /// cases it is set to `Some`, even if we're guessing at the channel value. + /// + /// Your code should be overflow-safe through a `channel_capacity_msat` of 21 million BTC. + #[must_use] + pub channel_penalty_msat: extern "C" fn (this_arg: *const c_void, short_channel_id: u64, send_amt_msat: u64, channel_capacity_msat: crate::c_types::derived::COption_u64Z, source: &crate::lightning::routing::network_graph::NodeId, target: &crate::lightning::routing::network_graph::NodeId) -> u64, + /// Handles updating channel penalties after failing to route through a channel. + pub payment_path_failed: extern "C" fn (this_arg: *mut c_void, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: u64), + /// Handles updating channel penalties after successfully routing along a path. + pub payment_path_successful: extern "C" fn (this_arg: *mut c_void, path: crate::c_types::derived::CVec_RouteHopZ), + /// Serialize the object into a byte array + pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z, + /// 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), + payment_path_failed: Clone::clone(&orig.payment_path_failed), + payment_path_successful: Clone::clone(&orig.payment_path_successful), + write: Clone::clone(&orig.write), + free: Clone::clone(&orig.free), + } +} +impl lightning::util::ser::Writeable for Score { + fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { + let vec = (self.write)(self.this_arg); + w.write_all(vec.as_slice()) + } +} + +use lightning::routing::scoring::Score as rustScore; +impl rustScore for Score { + fn channel_penalty_msat(&self, mut short_channel_id: u64, mut send_amt_msat: u64, mut channel_capacity_msat: Option, mut source: &lightning::routing::network_graph::NodeId, mut target: &lightning::routing::network_graph::NodeId) -> u64 { + let mut local_channel_capacity_msat = if channel_capacity_msat.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { channel_capacity_msat.unwrap() }) }; + let mut ret = (self.channel_penalty_msat)(self.this_arg, short_channel_id, send_amt_msat, local_channel_capacity_msat, &crate::lightning::routing::network_graph::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((source as *const lightning::routing::network_graph::NodeId<>) as *mut _) }, is_owned: false }, &crate::lightning::routing::network_graph::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((target as *const lightning::routing::network_graph::NodeId<>) as *mut _) }, is_owned: false }); + ret + } + fn payment_path_failed(&mut self, mut path: &[&lightning::routing::router::RouteHop], mut short_channel_id: u64) { + let mut local_path = Vec::new(); for item in path.iter() { local_path.push( { crate::lightning::routing::router::RouteHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner(((*item) as *const lightning::routing::router::RouteHop<>) as *mut _) }, is_owned: false } }); }; + (self.payment_path_failed)(self.this_arg, local_path.into(), short_channel_id) + } + fn payment_path_successful(&mut self, mut path: &[&lightning::routing::router::RouteHop]) { + let mut local_path = Vec::new(); for item in path.iter() { local_path.push( { crate::lightning::routing::router::RouteHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner(((*item) as *const lightning::routing::router::RouteHop<>) as *mut _) }, is_owned: false } }); }; + (self.payment_path_successful)(self.this_arg, local_path.into()) + } +} + +// 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); + } + } +} +/// A scorer that is accessed under a lock. +/// +/// Needed so that calls to [`Score::channel_penalty_msat`] in [`find_route`] can be made while +/// having shared ownership of a scorer but without requiring internal locking in [`Score`] +/// implementations. Internal locking would be detrimental to route finding performance and could +/// result in [`Score::channel_penalty_msat`] returning a different value for the same channel. +/// +/// [`find_route`]: crate::routing::router::find_route +#[repr(C)] +pub struct LockableScore { + /// 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 locked scorer. + #[must_use] + pub lock: extern "C" fn (this_arg: *const c_void) -> crate::lightning::routing::scoring::Score, + /// 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 LockableScore {} +unsafe impl Sync for LockableScore {} +#[no_mangle] +pub(crate) extern "C" fn LockableScore_clone_fields(orig: &LockableScore) -> LockableScore { + LockableScore { + this_arg: orig.this_arg, + lock: Clone::clone(&orig.lock), + free: Clone::clone(&orig.free), + } +} + +use lightning::routing::scoring::LockableScore as rustLockableScore; +impl<'a> rustLockableScore<'a> for LockableScore { + type Locked = crate::lightning::routing::scoring::Score; + fn lock(&'a self) -> crate::lightning::routing::scoring::Score { + let mut ret = (self.lock)(self.this_arg); + 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 LockableScore { + type Target = Self; + fn deref(&self) -> &Self { + self + } +} +/// Calls the free function if one is set +#[no_mangle] +pub extern "C" fn LockableScore_free(this_ptr: LockableScore) { } +impl Drop for LockableScore { + fn drop(&mut self) { + if let Some(f) = self.free { + f(self.this_arg); + } + } +} + +use lightning::routing::scoring::MultiThreadedLockableScore as nativeMultiThreadedLockableScoreImport; +pub(crate) type nativeMultiThreadedLockableScore = nativeMultiThreadedLockableScoreImport; + +/// A concrete implementation of [`LockableScore`] which supports multi-threading. +#[must_use] +#[repr(C)] +pub struct MultiThreadedLockableScore { + /// 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 nativeMultiThreadedLockableScore, + /// 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 MultiThreadedLockableScore { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeMultiThreadedLockableScore>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the MultiThreadedLockableScore, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn MultiThreadedLockableScore_free(this_obj: MultiThreadedLockableScore) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn MultiThreadedLockableScore_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMultiThreadedLockableScore); } +} +#[allow(unused)] +impl MultiThreadedLockableScore { + pub(crate) fn get_native_ref(&self) -> &'static nativeMultiThreadedLockableScore { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMultiThreadedLockableScore { + 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 nativeMultiThreadedLockableScore { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = std::ptr::null_mut(); + ret + } +} +/// Creates a new [`MultiThreadedLockableScore`] given an underlying [`Score`]. +#[must_use] +#[no_mangle] +pub extern "C" fn MultiThreadedLockableScore_new(mut score: crate::lightning::routing::scoring::Score) -> MultiThreadedLockableScore { + let mut ret = lightning::routing::scoring::MultiThreadedLockableScore::new(score); + MultiThreadedLockableScore { inner: ObjOps::heap_alloc(ret), is_owned: true } +} + + +use lightning::routing::scoring::Scorer as nativeScorerImport; +pub(crate) type nativeScorer = nativeScorerImport; + +/// [`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. Will further penalize channels that fail to relay payments. +/// +/// See [module-level documentation] for usage. +/// +/// [module-level documentation]: crate::routing::scoring +#[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 +pub(crate) 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 + } +} + +use lightning::routing::scoring::ScoringParameters as nativeScoringParametersImport; +pub(crate) type nativeScoringParameters = nativeScoringParametersImport; + +/// Parameters for configuring [`Scorer`]. +#[must_use] +#[repr(C)] +pub struct ScoringParameters { + /// 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 nativeScoringParameters, + /// 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 ScoringParameters { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeScoringParameters>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the ScoringParameters, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn ScoringParameters_free(this_obj: ScoringParameters) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ScoringParameters_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeScoringParameters); } +} +#[allow(unused)] +impl ScoringParameters { + pub(crate) fn get_native_ref(&self) -> &'static nativeScoringParameters { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeScoringParameters { + 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 nativeScoringParameters { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = std::ptr::null_mut(); + ret + } +} +/// A fixed penalty in msats to apply to each channel. +/// +/// Default value: 500 msat +#[no_mangle] +pub extern "C" fn ScoringParameters_get_base_penalty_msat(this_ptr: &ScoringParameters) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().base_penalty_msat; + *inner_val +} +/// A fixed penalty in msats to apply to each channel. +/// +/// Default value: 500 msat +#[no_mangle] +pub extern "C" fn ScoringParameters_set_base_penalty_msat(this_ptr: &mut ScoringParameters, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_penalty_msat = val; +} +/// A penalty in msats to apply to a channel upon failing to relay a payment. +/// +/// This accumulates for each failure but may be reduced over time based on +/// [`failure_penalty_half_life`] or when successfully routing through a channel. +/// +/// Default value: 1,024,000 msat +/// +/// [`failure_penalty_half_life`]: Self::failure_penalty_half_life +#[no_mangle] +pub extern "C" fn ScoringParameters_get_failure_penalty_msat(this_ptr: &ScoringParameters) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().failure_penalty_msat; + *inner_val +} +/// A penalty in msats to apply to a channel upon failing to relay a payment. +/// +/// This accumulates for each failure but may be reduced over time based on +/// [`failure_penalty_half_life`] or when successfully routing through a channel. +/// +/// Default value: 1,024,000 msat +/// +/// [`failure_penalty_half_life`]: Self::failure_penalty_half_life +#[no_mangle] +pub extern "C" fn ScoringParameters_set_failure_penalty_msat(this_ptr: &mut ScoringParameters, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.failure_penalty_msat = val; +} +/// When the amount being sent over a channel is this many 1024ths of the total channel +/// capacity, we begin applying [`overuse_penalty_msat_per_1024th`]. +/// +/// Default value: 128 1024ths (i.e. begin penalizing when an HTLC uses 1/8th of a channel) +/// +/// [`overuse_penalty_msat_per_1024th`]: Self::overuse_penalty_msat_per_1024th +#[no_mangle] +pub extern "C" fn ScoringParameters_get_overuse_penalty_start_1024th(this_ptr: &ScoringParameters) -> u16 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().overuse_penalty_start_1024th; + *inner_val +} +/// When the amount being sent over a channel is this many 1024ths of the total channel +/// capacity, we begin applying [`overuse_penalty_msat_per_1024th`]. +/// +/// Default value: 128 1024ths (i.e. begin penalizing when an HTLC uses 1/8th of a channel) +/// +/// [`overuse_penalty_msat_per_1024th`]: Self::overuse_penalty_msat_per_1024th +#[no_mangle] +pub extern "C" fn ScoringParameters_set_overuse_penalty_start_1024th(this_ptr: &mut ScoringParameters, mut val: u16) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.overuse_penalty_start_1024th = val; +} +/// A penalty applied, per whole 1024ths of the channel capacity which the amount being sent +/// over the channel exceeds [`overuse_penalty_start_1024th`] by. +/// +/// Default value: 20 msat (i.e. 2560 msat penalty to use 1/4th of a channel, 7680 msat penalty +/// to use half a channel, and 12,560 msat penalty to use 3/4ths of a channel) +/// +/// [`overuse_penalty_start_1024th`]: Self::overuse_penalty_start_1024th +#[no_mangle] +pub extern "C" fn ScoringParameters_get_overuse_penalty_msat_per_1024th(this_ptr: &ScoringParameters) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().overuse_penalty_msat_per_1024th; + *inner_val +} +/// A penalty applied, per whole 1024ths of the channel capacity which the amount being sent +/// over the channel exceeds [`overuse_penalty_start_1024th`] by. +/// +/// Default value: 20 msat (i.e. 2560 msat penalty to use 1/4th of a channel, 7680 msat penalty +/// to use half a channel, and 12,560 msat penalty to use 3/4ths of a channel) +/// +/// [`overuse_penalty_start_1024th`]: Self::overuse_penalty_start_1024th +#[no_mangle] +pub extern "C" fn ScoringParameters_set_overuse_penalty_msat_per_1024th(this_ptr: &mut ScoringParameters, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.overuse_penalty_msat_per_1024th = val; +} +/// The time required to elapse before any accumulated [`failure_penalty_msat`] penalties are +/// cut in half. +/// +/// Successfully routing through a channel will immediately cut the penalty in half as well. +/// +/// # Note +/// +/// When built with the `no-std` feature, time will never elapse. Therefore, this penalty will +/// never decay. +/// +/// [`failure_penalty_msat`]: Self::failure_penalty_msat +#[no_mangle] +pub extern "C" fn ScoringParameters_get_failure_penalty_half_life(this_ptr: &ScoringParameters) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().failure_penalty_half_life; + inner_val.as_secs() +} +/// The time required to elapse before any accumulated [`failure_penalty_msat`] penalties are +/// cut in half. +/// +/// Successfully routing through a channel will immediately cut the penalty in half as well. +/// +/// # Note +/// +/// When built with the `no-std` feature, time will never elapse. Therefore, this penalty will +/// never decay. +/// +/// [`failure_penalty_msat`]: Self::failure_penalty_msat +#[no_mangle] +pub extern "C" fn ScoringParameters_set_failure_penalty_half_life(this_ptr: &mut ScoringParameters, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.failure_penalty_half_life = std::time::Duration::from_secs(val); +} +/// Constructs a new ScoringParameters given each field +#[must_use] +#[no_mangle] +pub extern "C" fn ScoringParameters_new(mut base_penalty_msat_arg: u64, mut failure_penalty_msat_arg: u64, mut overuse_penalty_start_1024th_arg: u16, mut overuse_penalty_msat_per_1024th_arg: u64, mut failure_penalty_half_life_arg: u64) -> ScoringParameters { + ScoringParameters { inner: ObjOps::heap_alloc(nativeScoringParameters { + base_penalty_msat: base_penalty_msat_arg, + failure_penalty_msat: failure_penalty_msat_arg, + overuse_penalty_start_1024th: overuse_penalty_start_1024th_arg, + overuse_penalty_msat_per_1024th: overuse_penalty_msat_per_1024th_arg, + failure_penalty_half_life: std::time::Duration::from_secs(failure_penalty_half_life_arg), + }), is_owned: true } +} +#[no_mangle] +/// Serialize the ScoringParameters object into a byte array which can be read by ScoringParameters_read +pub extern "C" fn ScoringParameters_write(obj: &ScoringParameters) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[no_mangle] +pub(crate) extern "C" fn ScoringParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeScoringParameters) }) +} +#[no_mangle] +/// Read a ScoringParameters from a byte array, created by ScoringParameters_write +pub extern "C" fn ScoringParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ScoringParametersDecodeErrorZ { + let res: Result = crate::c_types::deserialize_obj(ser); + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::scoring::ScoringParameters { 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 +} +/// Creates a new scorer using the given scoring parameters. +#[must_use] +#[no_mangle] +pub extern "C" fn Scorer_new(mut params: crate::lightning::routing::scoring::ScoringParameters) -> Scorer { + let mut ret = lightning::routing::scoring::Scorer::new(*unsafe { Box::from_raw(params.take_inner()) }); + 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 } +} +/// Creates a "default" ScoringParameters. See struct and individual field documentaiton for details on which values are used. +#[must_use] +#[no_mangle] +pub extern "C" fn ScoringParameters_default() -> ScoringParameters { + ScoringParameters { inner: ObjOps::heap_alloc(Default::default()), is_owned: true } +} +impl From for crate::lightning::routing::scoring::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::scoring::Score { + crate::lightning::routing::scoring::Score { + this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, + free: None, + channel_penalty_msat: Scorer_Score_channel_penalty_msat, + payment_path_failed: Scorer_Score_payment_path_failed, + payment_path_successful: Scorer_Score_payment_path_successful, + write: Scorer_write_void, + } +} + +#[must_use] +extern "C" fn Scorer_Score_channel_penalty_msat(this_arg: *const c_void, mut short_channel_id: u64, mut send_amt_msat: u64, mut chan_capacity_opt: crate::c_types::derived::COption_u64Z, _source: &crate::lightning::routing::network_graph::NodeId, _target: &crate::lightning::routing::network_graph::NodeId) -> u64 { + let mut local_chan_capacity_opt = if chan_capacity_opt.is_some() { Some( { chan_capacity_opt.take() }) } else { None }; + let mut ret = >::channel_penalty_msat(unsafe { &mut *(this_arg as *mut nativeScorer) }, short_channel_id, send_amt_msat, local_chan_capacity_opt, _source.get_native_ref(), _target.get_native_ref()); + ret +} +extern "C" fn Scorer_Score_payment_path_failed(this_arg: *mut c_void, mut _path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) { + let mut local__path = Vec::new(); for mut item in _path.as_slice().iter() { local__path.push( { item.get_native_ref() }); }; + >::payment_path_failed(unsafe { &mut *(this_arg as *mut nativeScorer) }, &local__path[..], short_channel_id) +} +extern "C" fn Scorer_Score_payment_path_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) { + let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); }; + >::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeScorer) }, &local_path[..]) +} + +#[no_mangle] +/// Serialize the Scorer object into a byte array which can be read by Scorer_read +pub extern "C" fn Scorer_write(obj: &Scorer) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[no_mangle] +pub(crate) extern "C" fn Scorer_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeScorer) }) +} +#[no_mangle] +/// Read a Scorer from a byte array, created by Scorer_write +pub extern "C" fn Scorer_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ScorerDecodeErrorZ { + let res: Result = crate::c_types::deserialize_obj(ser); + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::scoring::Scorer { 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 +} +mod time { + +use std::str::FromStr; +use std::ffi::c_void; +use core::convert::Infallible; +use bitcoin::hashes::Hash; +use crate::c_types::*; + +} diff --git a/lightning-c-bindings/src/lightning/util/config.rs b/lightning-c-bindings/src/lightning/util/config.rs index dd2dc3d..d1251b8 100644 --- a/lightning-c-bindings/src/lightning/util/config.rs +++ b/lightning-c-bindings/src/lightning/util/config.rs @@ -931,15 +931,29 @@ pub extern "C" fn UserConfig_get_accept_forwards_to_priv_channels(this_ptr: &Use pub extern "C" fn UserConfig_set_accept_forwards_to_priv_channels(this_ptr: &mut UserConfig, mut val: bool) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.accept_forwards_to_priv_channels = val; } +/// If this is set to false, we do not accept inbound requests to open a new channel. +/// Default value: true. +#[no_mangle] +pub extern "C" fn UserConfig_get_accept_inbound_channels(this_ptr: &UserConfig) -> bool { + let mut inner_val = &mut this_ptr.get_native_mut_ref().accept_inbound_channels; + *inner_val +} +/// If this is set to false, we do not accept inbound requests to open a new channel. +/// Default value: true. +#[no_mangle] +pub extern "C" fn UserConfig_set_accept_inbound_channels(this_ptr: &mut UserConfig, mut val: bool) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.accept_inbound_channels = val; +} /// Constructs a new UserConfig given each field #[must_use] #[no_mangle] -pub extern "C" fn UserConfig_new(mut own_channel_config_arg: crate::lightning::util::config::ChannelHandshakeConfig, mut peer_channel_config_limits_arg: crate::lightning::util::config::ChannelHandshakeLimits, mut channel_options_arg: crate::lightning::util::config::ChannelConfig, mut accept_forwards_to_priv_channels_arg: bool) -> UserConfig { +pub extern "C" fn UserConfig_new(mut own_channel_config_arg: crate::lightning::util::config::ChannelHandshakeConfig, mut peer_channel_config_limits_arg: crate::lightning::util::config::ChannelHandshakeLimits, mut channel_options_arg: crate::lightning::util::config::ChannelConfig, mut accept_forwards_to_priv_channels_arg: bool, mut accept_inbound_channels_arg: bool) -> UserConfig { UserConfig { inner: ObjOps::heap_alloc(nativeUserConfig { own_channel_config: *unsafe { Box::from_raw(own_channel_config_arg.take_inner()) }, peer_channel_config_limits: *unsafe { Box::from_raw(peer_channel_config_limits_arg.take_inner()) }, channel_options: *unsafe { Box::from_raw(channel_options_arg.take_inner()) }, accept_forwards_to_priv_channels: accept_forwards_to_priv_channels_arg, + accept_inbound_channels: accept_inbound_channels_arg, }), is_owned: true } } impl Clone for UserConfig { diff --git a/lightning-c-bindings/src/lightning/util/events.rs b/lightning-c-bindings/src/lightning/util/events.rs index a507a9e..1291bbc 100644 --- a/lightning-c-bindings/src/lightning/util/events.rs +++ b/lightning-c-bindings/src/lightning/util/events.rs @@ -47,15 +47,6 @@ pub enum PaymentPurpose { /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash payment_secret: crate::c_types::ThirtyTwoBytes, - /// This is the `user_payment_id` which was provided to - /// [`ChannelManager::create_inbound_payment_for_hash`] or - /// [`ChannelManager::create_inbound_payment`]. It has no meaning inside of LDK and is - /// simply copied here. It may be used to correlate PaymentReceived events with invoice - /// metadata stored elsewhere. - /// - /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment - /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash - user_payment_id: u64, }, /// Because this is a spontaneous payment, the payer generated their own preimage rather than us /// (the payee) providing a preimage. @@ -66,15 +57,13 @@ impl PaymentPurpose { #[allow(unused)] pub(crate) fn to_native(&self) -> nativePaymentPurpose { match self { - PaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, ref user_payment_id, } => { + PaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, } => { let mut payment_preimage_nonref = (*payment_preimage).clone(); let mut local_payment_preimage_nonref = if payment_preimage_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data) }) }; let mut payment_secret_nonref = (*payment_secret).clone(); - let mut user_payment_id_nonref = (*user_payment_id).clone(); nativePaymentPurpose::InvoicePayment { payment_preimage: local_payment_preimage_nonref, payment_secret: ::lightning::ln::PaymentSecret(payment_secret_nonref.data), - user_payment_id: user_payment_id_nonref, } }, PaymentPurpose::SpontaneousPayment (ref a, ) => { @@ -88,12 +77,11 @@ impl PaymentPurpose { #[allow(unused)] pub(crate) fn into_native(self) -> nativePaymentPurpose { match self { - PaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, mut user_payment_id, } => { + PaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, } => { let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) }; nativePaymentPurpose::InvoicePayment { payment_preimage: local_payment_preimage, payment_secret: ::lightning::ln::PaymentSecret(payment_secret.data), - user_payment_id: user_payment_id, } }, PaymentPurpose::SpontaneousPayment (mut a, ) => { @@ -106,15 +94,13 @@ impl PaymentPurpose { #[allow(unused)] pub(crate) fn from_native(native: &nativePaymentPurpose) -> Self { match native { - nativePaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, ref user_payment_id, } => { + nativePaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, } => { let mut payment_preimage_nonref = (*payment_preimage).clone(); let mut local_payment_preimage_nonref = if payment_preimage_nonref.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_preimage_nonref.unwrap()).0 } } }; let mut payment_secret_nonref = (*payment_secret).clone(); - let mut user_payment_id_nonref = (*user_payment_id).clone(); PaymentPurpose::InvoicePayment { payment_preimage: local_payment_preimage_nonref, payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret_nonref.0 }, - user_payment_id: user_payment_id_nonref, } }, nativePaymentPurpose::SpontaneousPayment (ref a, ) => { @@ -128,12 +114,11 @@ impl PaymentPurpose { #[allow(unused)] pub(crate) fn native_into(native: nativePaymentPurpose) -> Self { match native { - nativePaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, mut user_payment_id, } => { + nativePaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, } => { let mut local_payment_preimage = if payment_preimage.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_preimage.unwrap()).0 } } }; PaymentPurpose::InvoicePayment { payment_preimage: local_payment_preimage, payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret.0 }, - user_payment_id: user_payment_id, } }, nativePaymentPurpose::SpontaneousPayment (mut a, ) => { @@ -154,11 +139,10 @@ pub extern "C" fn PaymentPurpose_clone(orig: &PaymentPurpose) -> PaymentPurpose } #[no_mangle] /// Utility method to constructs a new InvoicePayment-variant PaymentPurpose -pub extern "C" fn PaymentPurpose_invoice_payment(payment_preimage: crate::c_types::ThirtyTwoBytes, payment_secret: crate::c_types::ThirtyTwoBytes, user_payment_id: u64) -> PaymentPurpose { +pub extern "C" fn PaymentPurpose_invoice_payment(payment_preimage: crate::c_types::ThirtyTwoBytes, payment_secret: crate::c_types::ThirtyTwoBytes) -> PaymentPurpose { PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, - user_payment_id, } } #[no_mangle] @@ -194,6 +178,8 @@ pub enum ClosureReason { /// commitment transaction came from our counterparty, but it may also have come from /// a copy of our own `ChannelMonitor`. CommitmentTxConfirmed, + /// The funding transaction failed to confirm in a timely manner on an inbound channel. + FundingTimedOut, /// Closure generated from processing an event, likely a HTLC forward/relay/reception. ProcessingError { /// A developer-readable error message which we generated. @@ -223,6 +209,7 @@ impl ClosureReason { ClosureReason::HolderForceClosed => nativeClosureReason::HolderForceClosed, ClosureReason::CooperativeClosure => nativeClosureReason::CooperativeClosure, ClosureReason::CommitmentTxConfirmed => nativeClosureReason::CommitmentTxConfirmed, + ClosureReason::FundingTimedOut => nativeClosureReason::FundingTimedOut, ClosureReason::ProcessingError {ref err, } => { let mut err_nonref = (*err).clone(); nativeClosureReason::ProcessingError { @@ -244,6 +231,7 @@ impl ClosureReason { ClosureReason::HolderForceClosed => nativeClosureReason::HolderForceClosed, ClosureReason::CooperativeClosure => nativeClosureReason::CooperativeClosure, ClosureReason::CommitmentTxConfirmed => nativeClosureReason::CommitmentTxConfirmed, + ClosureReason::FundingTimedOut => nativeClosureReason::FundingTimedOut, ClosureReason::ProcessingError {mut err, } => { nativeClosureReason::ProcessingError { err: err.into_string(), @@ -265,6 +253,7 @@ impl ClosureReason { nativeClosureReason::HolderForceClosed => ClosureReason::HolderForceClosed, nativeClosureReason::CooperativeClosure => ClosureReason::CooperativeClosure, nativeClosureReason::CommitmentTxConfirmed => ClosureReason::CommitmentTxConfirmed, + nativeClosureReason::FundingTimedOut => ClosureReason::FundingTimedOut, nativeClosureReason::ProcessingError {ref err, } => { let mut err_nonref = (*err).clone(); ClosureReason::ProcessingError { @@ -286,6 +275,7 @@ impl ClosureReason { nativeClosureReason::HolderForceClosed => ClosureReason::HolderForceClosed, nativeClosureReason::CooperativeClosure => ClosureReason::CooperativeClosure, nativeClosureReason::CommitmentTxConfirmed => ClosureReason::CommitmentTxConfirmed, + nativeClosureReason::FundingTimedOut => ClosureReason::FundingTimedOut, nativeClosureReason::ProcessingError {mut err, } => { ClosureReason::ProcessingError { err: err.into(), @@ -324,6 +314,10 @@ pub extern "C" fn ClosureReason_cooperative_closure() -> ClosureReason { pub extern "C" fn ClosureReason_commitment_tx_confirmed() -> ClosureReason { ClosureReason::CommitmentTxConfirmed} #[no_mangle] +/// Utility method to constructs a new FundingTimedOut-variant ClosureReason +pub extern "C" fn ClosureReason_funding_timed_out() -> ClosureReason { + ClosureReason::FundingTimedOut} +#[no_mangle] /// Utility method to constructs a new ProcessingError-variant ClosureReason pub extern "C" fn ClosureReason_processing_error(err: crate::c_types::Str) -> ClosureReason { ClosureReason::ProcessingError { @@ -360,10 +354,13 @@ pub extern "C" fn ClosureReason_read(ser: crate::c_types::u8slice) -> crate::c_t #[repr(C)] pub enum Event { /// Used to indicate that the client should generate a funding transaction with the given - /// parameters and then call ChannelManager::funding_transaction_generated. - /// Generated in ChannelManager message handling. + /// parameters and then call [`ChannelManager::funding_transaction_generated`]. + /// Generated in [`ChannelManager`] message handling. /// Note that *all inputs* in the funding transaction must spend SegWit outputs or your /// counterparty can steal your funds! + /// + /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager + /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated FundingGenerationReady { /// The random channel_id we picked which you'll need to pass into /// ChannelManager::funding_transaction_generated. @@ -387,10 +384,15 @@ pub enum Event { /// [`ChannelManager::fail_htlc_backwards`] within the HTLC's timeout, the HTLC will be /// automatically failed. /// + /// # Note + /// LDK will not stop an inbound payment from being paid multiple times, so multiple + /// `PaymentReceived` events may be generated for the same payment. + /// /// [`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. + /// The hash for which the preimage should be handed to the ChannelManager. Note that LDK will + /// not stop you from registering duplicate payment hashes for inbound payments. payment_hash: crate::c_types::ThirtyTwoBytes, /// The value, in thousandths of a satoshi, that this payment is for. amt: u64, @@ -416,7 +418,7 @@ 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`]. + /// The hash that was given to [`ChannelManager::send_payment`]. /// /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment payment_hash: crate::c_types::ThirtyTwoBytes, @@ -431,18 +433,26 @@ pub enum Event { /// [`Route::get_total_fees`]: crate::routing::router::Route::get_total_fees fee_paid_msat: crate::c_types::derived::COption_u64Z, }, - /// Indicates an outbound payment we made failed. Probably some intermediary node dropped + /// Indicates an outbound HTLC we sent failed. Probably some intermediary node dropped /// something. You may wish to retry with a different route. + /// + /// Note that this does *not* indicate that all paths for an MPP payment have failed, see + /// [`Event::PaymentFailed`] and [`all_paths_failed`]. + /// + /// [`all_paths_failed`]: Self::all_paths_failed PaymentPathFailed { /// The id returned by [`ChannelManager::send_payment`] and used with - /// [`ChannelManager::retry_payment`]. + /// [`ChannelManager::retry_payment`] and [`ChannelManager::abandon_payment`]. /// /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment + /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment /// /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None payment_id: crate::c_types::ThirtyTwoBytes, - /// The hash which was given to ChannelManager::send_payment. + /// The hash that was given to [`ChannelManager::send_payment`]. + /// + /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment payment_hash: crate::c_types::ThirtyTwoBytes, /// Indicates the payment was rejected for some reason by the recipient. This implies that /// the payment has failed, not just the route in question. If this is not set, you may @@ -460,6 +470,20 @@ pub enum Event { /// For both single-path and multi-path payments, this is set if all paths of the payment have /// failed. This will be set to false if (1) this is an MPP payment and (2) other parts of the /// larger MPP payment were still in flight when this event was generated. + /// + /// Note that if you are retrying individual MPP parts, using this value to determine if a + /// payment has fully failed is race-y. Because multiple failures can happen prior to events + /// being processed, you may retry in response to a first failure, with a second failure + /// (with `all_paths_failed` set) still pending. Then, when the second failure is processed + /// you will see `all_paths_failed` set even though the retry of the first failure still + /// has an associated in-flight HTLC. See (1) for an example of such a failure. + /// + /// If you wish to retry individual MPP parts and learn when a payment has failed, you must + /// call [`ChannelManager::abandon_payment`] and wait for a [`Event::PaymentFailed`] event. + /// + /// (1) + /// + /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment all_paths_failed: bool, /// The payment path that failed. path: crate::c_types::derived::CVec_RouteHopZ, @@ -478,8 +502,31 @@ pub enum Event { /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None retry: crate::lightning::routing::router::RouteParameters, }, - /// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a - /// time in the future. + /// Indicates an outbound payment failed. Individual [`Event::PaymentPathFailed`] events + /// provide failure information for each MPP part in the payment. + /// + /// This event is provided once there are no further pending HTLCs for the payment and the + /// payment is no longer retryable, either due to a several-block timeout or because + /// [`ChannelManager::abandon_payment`] was previously called for the corresponding payment. + /// + /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment + PaymentFailed { + /// The id returned by [`ChannelManager::send_payment`] and used with + /// [`ChannelManager::retry_payment`] and [`ChannelManager::abandon_payment`]. + /// + /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment + /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment + payment_id: crate::c_types::ThirtyTwoBytes, + /// The hash that was given to [`ChannelManager::send_payment`]. + /// + /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + payment_hash: crate::c_types::ThirtyTwoBytes, + }, + /// Used to indicate that [`ChannelManager::process_pending_htlc_forwards`] should be called at + /// a time in the future. + /// + /// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards PendingHTLCsForwardable { /// The minimum amount of time that should be waited prior to calling /// process_pending_htlc_forwards. To increase the effort required to correlate payments, @@ -539,6 +586,28 @@ pub enum Event { /// The full transaction received from the user transaction: crate::c_types::Transaction, }, + /// Indicates that a path for an outbound payment was successful. + /// + /// Always generated after [`Event::PaymentSent`] and thus useful for scoring channels. See + /// [`Event::PaymentSent`] for obtaining the payment preimage. + PaymentPathSuccessful { + /// The id returned by [`ChannelManager::send_payment`] and used with + /// [`ChannelManager::retry_payment`]. + /// + /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment + payment_id: crate::c_types::ThirtyTwoBytes, + /// The hash that was given to [`ChannelManager::send_payment`]. + /// + /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + /// + /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None + payment_hash: crate::c_types::ThirtyTwoBytes, + /// The payment path that was successful. + /// + /// May contain a closed channel if the HTLC sent along the path was fulfilled on chain. + path: crate::c_types::derived::CVec_RouteHopZ, + }, } use lightning::util::events::Event as nativeEvent; impl Event { @@ -606,6 +675,14 @@ impl Event { retry: local_retry_nonref, } }, + Event::PaymentFailed {ref payment_id, ref payment_hash, } => { + let mut payment_id_nonref = (*payment_id).clone(); + let mut payment_hash_nonref = (*payment_hash).clone(); + nativeEvent::PaymentFailed { + payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data), + payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data), + } + }, Event::PendingHTLCsForwardable {ref time_forwardable, } => { let mut time_forwardable_nonref = (*time_forwardable).clone(); nativeEvent::PendingHTLCsForwardable { @@ -646,6 +723,18 @@ impl Event { transaction: transaction_nonref.into_bitcoin(), } }, + Event::PaymentPathSuccessful {ref payment_id, ref payment_hash, ref path, } => { + let mut payment_id_nonref = (*payment_id).clone(); + let mut payment_hash_nonref = (*payment_hash).clone(); + let mut local_payment_hash_nonref = if payment_hash_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentHash(payment_hash_nonref.data) }) }; + 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()) } }); }; + nativeEvent::PaymentPathSuccessful { + payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data), + payment_hash: local_payment_hash_nonref, + path: local_path_nonref, + } + }, } } #[allow(unused)] @@ -693,6 +782,12 @@ impl Event { retry: local_retry, } }, + Event::PaymentFailed {mut payment_id, mut payment_hash, } => { + nativeEvent::PaymentFailed { + payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data), + payment_hash: ::lightning::ln::PaymentHash(payment_hash.data), + } + }, Event::PendingHTLCsForwardable {mut time_forwardable, } => { nativeEvent::PendingHTLCsForwardable { time_forwardable: std::time::Duration::from_secs(time_forwardable), @@ -724,6 +819,15 @@ impl Event { transaction: transaction.into_bitcoin(), } }, + Event::PaymentPathSuccessful {mut payment_id, mut payment_hash, mut path, } => { + let mut local_payment_hash = if payment_hash.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentHash(payment_hash.data) }) }; + let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; + nativeEvent::PaymentPathSuccessful { + payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data), + payment_hash: local_payment_hash, + path: local_path, + } + }, } } #[allow(unused)] @@ -790,6 +894,14 @@ impl Event { retry: local_retry_nonref, } }, + nativeEvent::PaymentFailed {ref payment_id, ref payment_hash, } => { + let mut payment_id_nonref = (*payment_id).clone(); + let mut payment_hash_nonref = (*payment_hash).clone(); + Event::PaymentFailed { + payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 }, + payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 }, + } + }, nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => { let mut time_forwardable_nonref = (*time_forwardable).clone(); Event::PendingHTLCsForwardable { @@ -830,6 +942,18 @@ impl Event { transaction: crate::c_types::Transaction::from_bitcoin(&transaction_nonref), } }, + nativeEvent::PaymentPathSuccessful {ref payment_id, ref payment_hash, ref path, } => { + let mut payment_id_nonref = (*payment_id).clone(); + let mut payment_hash_nonref = (*payment_hash).clone(); + let mut local_payment_hash_nonref = if payment_hash_nonref.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_hash_nonref.unwrap()).0 } } }; + 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 } }); }; + Event::PaymentPathSuccessful { + payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 }, + payment_hash: local_payment_hash_nonref, + path: local_path_nonref.into(), + } + }, } } #[allow(unused)] @@ -877,6 +1001,12 @@ impl Event { retry: local_retry, } }, + nativeEvent::PaymentFailed {mut payment_id, mut payment_hash, } => { + Event::PaymentFailed { + payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 }, + payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 }, + } + }, nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => { Event::PendingHTLCsForwardable { time_forwardable: time_forwardable.as_secs(), @@ -908,6 +1038,15 @@ impl Event { transaction: crate::c_types::Transaction::from_bitcoin(&transaction), } }, + nativeEvent::PaymentPathSuccessful {mut payment_id, mut payment_hash, mut path, } => { + let mut local_payment_hash = if payment_hash.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_hash.unwrap()).0 } } }; + 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 } }); }; + Event::PaymentPathSuccessful { + payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 }, + payment_hash: local_payment_hash, + path: local_path.into(), + } + }, } } } @@ -963,6 +1102,14 @@ pub extern "C" fn Event_payment_path_failed(payment_id: crate::c_types::ThirtyTw } } #[no_mangle] +/// Utility method to constructs a new PaymentFailed-variant Event +pub extern "C" fn Event_payment_failed(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes) -> Event { + Event::PaymentFailed { + payment_id, + payment_hash, + } +} +#[no_mangle] /// Utility method to constructs a new PendingHTLCsForwardable-variant Event pub extern "C" fn Event_pending_htlcs_forwardable(time_forwardable: u64) -> Event { Event::PendingHTLCsForwardable { @@ -1002,6 +1149,15 @@ pub extern "C" fn Event_discard_funding(channel_id: crate::c_types::ThirtyTwoByt } } #[no_mangle] +/// Utility method to constructs a new PaymentPathSuccessful-variant Event +pub extern "C" fn Event_payment_path_successful(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, path: crate::c_types::derived::CVec_RouteHopZ) -> Event { + Event::PaymentPathSuccessful { + payment_id, + payment_hash, + path, + } +} +#[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/util/logger.rs b/lightning-c-bindings/src/lightning/util/logger.rs index b4d7c1a..7d0e795 100644 --- a/lightning-c-bindings/src/lightning/util/logger.rs +++ b/lightning-c-bindings/src/lightning/util/logger.rs @@ -24,6 +24,8 @@ use crate::c_types::*; #[derive(Clone)] #[repr(C)] pub enum Level { + /// Designates extremely verbose information, including gossip-induced messages + Gossip, /// Designates very low priority, often extremely verbose, information Trace, /// Designates lower priority information @@ -40,6 +42,7 @@ impl Level { #[allow(unused)] pub(crate) fn to_native(&self) -> nativeLevel { match self { + Level::Gossip => nativeLevel::Gossip, Level::Trace => nativeLevel::Trace, Level::Debug => nativeLevel::Debug, Level::Info => nativeLevel::Info, @@ -50,6 +53,7 @@ impl Level { #[allow(unused)] pub(crate) fn into_native(self) -> nativeLevel { match self { + Level::Gossip => nativeLevel::Gossip, Level::Trace => nativeLevel::Trace, Level::Debug => nativeLevel::Debug, Level::Info => nativeLevel::Info, @@ -60,6 +64,7 @@ impl Level { #[allow(unused)] pub(crate) fn from_native(native: &nativeLevel) -> Self { match native { + nativeLevel::Gossip => Level::Gossip, nativeLevel::Trace => Level::Trace, nativeLevel::Debug => Level::Debug, nativeLevel::Info => Level::Info, @@ -70,6 +75,7 @@ impl Level { #[allow(unused)] pub(crate) fn native_into(native: nativeLevel) -> Self { match native { + nativeLevel::Gossip => Level::Gossip, nativeLevel::Trace => Level::Trace, nativeLevel::Debug => Level::Debug, nativeLevel::Info => Level::Info, @@ -84,6 +90,10 @@ pub extern "C" fn Level_clone(orig: &Level) -> Level { orig.clone() } #[no_mangle] +/// Utility method to constructs a new Gossip-variant Level +pub extern "C" fn Level_gossip() -> Level { + Level::Gossip} +#[no_mangle] /// Utility method to constructs a new Trace-variant Level pub extern "C" fn Level_trace() -> Level { Level::Trace} diff --git a/lightning-c-bindings/src/lightning_background_processor.rs b/lightning-c-bindings/src/lightning_background_processor.rs index c35788f..5dc282a 100644 --- a/lightning-c-bindings/src/lightning_background_processor.rs +++ b/lightning-c-bindings/src/lightning_background_processor.rs @@ -29,6 +29,8 @@ pub(crate) type nativeBackgroundProcessor = nativeBackgroundProcessorImport; /// [`ChannelManager`] persistence should be done in the background. /// * Calling [`ChannelManager::timer_tick_occurred`] and [`PeerManager::timer_tick_occurred`] /// at the appropriate intervals. +/// * Calling [`NetworkGraph::remove_stale_channels`] (if a [`NetGraphMsgHandler`] is provided to +/// [`BackgroundProcessor::start`]). /// /// It will also call [`PeerManager::process_events`] periodically though this shouldn't be relied /// upon as doing so may result in high latency. @@ -170,7 +172,7 @@ impl Drop for ChannelManagerPersister { /// functionality implemented by other handlers. /// * [`NetGraphMsgHandler`] if given will update the [`NetworkGraph`] based on payment failures. /// -/// [top-level documentation]: Self +/// [top-level documentation]: BackgroundProcessor /// [`join`]: Self::join /// [`stop`]: Self::stop /// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager diff --git a/lightning-c-bindings/src/lightning_invoice/mod.rs b/lightning-c-bindings/src/lightning_invoice/mod.rs index 5331433..cb19024 100644 --- a/lightning-c-bindings/src/lightning_invoice/mod.rs +++ b/lightning-c-bindings/src/lightning_invoice/mod.rs @@ -2035,6 +2035,8 @@ pub enum CreationError { TimestampOutOfBounds, /// The supplied expiry time could cause an overflow if added to a `PositiveTimestamp` ExpiryTimeOutOfBounds, + /// The supplied millisatoshi amount was greater than the total bitcoin supply. + InvalidAmount, } use lightning_invoice::CreationError as nativeCreationError; impl CreationError { @@ -2045,6 +2047,7 @@ impl CreationError { CreationError::RouteTooLong => nativeCreationError::RouteTooLong, CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds, CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds, + CreationError::InvalidAmount => nativeCreationError::InvalidAmount, } } #[allow(unused)] @@ -2054,6 +2057,7 @@ impl CreationError { CreationError::RouteTooLong => nativeCreationError::RouteTooLong, CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds, CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds, + CreationError::InvalidAmount => nativeCreationError::InvalidAmount, } } #[allow(unused)] @@ -2063,6 +2067,7 @@ impl CreationError { nativeCreationError::RouteTooLong => CreationError::RouteTooLong, nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds, nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds, + nativeCreationError::InvalidAmount => CreationError::InvalidAmount, } } #[allow(unused)] @@ -2072,6 +2077,7 @@ impl CreationError { nativeCreationError::RouteTooLong => CreationError::RouteTooLong, nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds, nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds, + nativeCreationError::InvalidAmount => CreationError::InvalidAmount, } } } @@ -2096,6 +2102,10 @@ pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError { /// Utility method to constructs a new ExpiryTimeOutOfBounds-variant CreationError pub extern "C" fn CreationError_expiry_time_out_of_bounds() -> CreationError { CreationError::ExpiryTimeOutOfBounds} +#[no_mangle] +/// Utility method to constructs a new InvalidAmount-variant CreationError +pub extern "C" fn CreationError_invalid_amount() -> CreationError { + CreationError::InvalidAmount} /// Checks if two CreationErrors contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. #[no_mangle] diff --git a/lightning-c-bindings/src/lightning_invoice/payment.rs b/lightning-c-bindings/src/lightning_invoice/payment.rs index 6c7a2ca..f53e73e 100644 --- a/lightning-c-bindings/src/lightning_invoice/payment.rs +++ b/lightning-c-bindings/src/lightning_invoice/payment.rs @@ -6,12 +6,17 @@ // license as that which applies to the original source files from which this // source was automatically generated. -//! A module for paying Lightning invoices. +//! A module for paying Lightning invoices and sending spontaneous payments. //! -//! Defines an [`InvoicePayer`] utility for paying invoices, parameterized by [`Payer`] and +//! Defines an [`InvoicePayer`] utility for sending payments, parameterized by [`Payer`] and //! [`Router`] traits. Implementations of [`Payer`] provide the payer's node id, channels, and means //! to send a payment over a [`Route`]. Implementations of [`Router`] find a [`Route`] between payer -//! and payee using information provided by the payer and from the payee's [`Invoice`]. +//! and payee using information provided by the payer and from the payee's [`Invoice`], when +//! applicable. +//! +//! [`InvoicePayer`] is parameterized by a [`LockableScore`], which it uses for scoring failed and +//! successful payment paths upon receiving [`Event::PaymentPathFailed`] and +//! [`Event::PaymentPathSuccessful`] events, respectively. //! //! [`InvoicePayer`] is capable of retrying failed payments. It accomplishes this by implementing //! [`EventHandler`] which decorates a user-provided handler. It will intercept any @@ -26,14 +31,15 @@ //! # extern crate lightning_invoice; //! # extern crate secp256k1; //! # -//! # use lightning::ln::{PaymentHash, PaymentSecret}; +//! # use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret}; //! # use lightning::ln::channelmanager::{ChannelDetails, PaymentId, PaymentSendFailure}; //! # use lightning::ln::msgs::LightningError; -//! # use lightning::routing::{self, LockableScore}; +//! # use lightning::routing::scoring::Score; //! # use lightning::routing::network_graph::NodeId; //! # use lightning::routing::router::{Route, RouteHop, RouteParameters}; //! # use lightning::util::events::{Event, EventHandler, EventsProvider}; //! # use lightning::util::logger::{Logger, Record}; +//! # use lightning::util::ser::{Writeable, Writer}; //! # use lightning_invoice::Invoice; //! # use lightning_invoice::payment::{InvoicePayer, Payer, RetryAttempts, Router}; //! # use secp256k1::key::PublicKey; @@ -52,31 +58,36 @@ //! # fn send_payment( //! # &self, route: &Route, payment_hash: PaymentHash, payment_secret: &Option //! # ) -> Result { unimplemented!() } +//! # fn send_spontaneous_payment( +//! # &self, route: &Route, payment_preimage: PaymentPreimage +//! # ) -> Result { unimplemented!() } //! # fn retry_payment( //! # &self, route: &Route, payment_id: PaymentId //! # ) -> Result<(), PaymentSendFailure> { unimplemented!() } +//! # fn abandon_payment(&self, payment_id: PaymentId) { unimplemented!() } //! # } //! # -//! # struct FakeRouter {}; -//! # impl Router for FakeRouter { +//! # struct FakeRouter {} +//! # impl Router for FakeRouter { //! # fn find_route( -//! # &self, payer: &PublicKey, params: &RouteParameters, +//! # &self, payer: &PublicKey, params: &RouteParameters, payment_hash: &PaymentHash, //! # first_hops: Option<&[&ChannelDetails]>, scorer: &S //! # ) -> Result { unimplemented!() } //! # } //! # -//! # struct FakeScorer {}; -//! # impl lightning::util::ser::Writeable for FakeScorer { -//! # fn write(&self, _: &mut W) -> Result<(), std::io::Error> { unreachable!(); } +//! # struct FakeScorer {} +//! # impl Writeable for FakeScorer { +//! # fn write(&self, w: &mut W) -> Result<(), std::io::Error> { unimplemented!(); } //! # } -//! # impl routing::Score for FakeScorer { +//! # impl Score for FakeScorer { //! # fn channel_penalty_msat( -//! # &self, _short_channel_id: u64, _source: &NodeId, _target: &NodeId +//! # &self, _short_channel_id: u64, _send_amt: u64, _chan_amt: Option, _source: &NodeId, _target: &NodeId //! # ) -> u64 { 0 } //! # fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {} +//! # fn payment_path_successful(&mut self, _path: &[&RouteHop]) {} //! # } //! # -//! # struct FakeLogger {}; +//! # struct FakeLogger {} //! # impl Logger for FakeLogger { //! # fn log(&self, record: &Record) { unimplemented!() } //! # } @@ -91,17 +102,18 @@ //! }; //! # let payer = FakePayer {}; //! # let router = FakeRouter {}; -//! # let scorer = LockableScore::new(FakeScorer {}); +//! # let scorer = RefCell::new(FakeScorer {}); //! # let logger = FakeLogger {}; //! let invoice_payer = InvoicePayer::new(&payer, router, &scorer, &logger, event_handler, RetryAttempts(2)); //! //! let invoice = \"...\"; -//! let invoice = invoice.parse::().unwrap(); -//! invoice_payer.pay_invoice(&invoice).unwrap(); +//! if let Ok(invoice) = invoice.parse::() { +//! invoice_payer.pay_invoice(&invoice).unwrap(); //! //! # let event_provider = FakeEventProvider {}; -//! loop { -//! event_provider.process_pending_events(&invoice_payer); +//! loop { +//! event_provider.process_pending_events(&invoice_payer); +//! } //! } //! # } //! ``` @@ -120,9 +132,13 @@ use crate::c_types::*; use lightning_invoice::payment::InvoicePayer as nativeInvoicePayerImport; -pub(crate) type nativeInvoicePayer = nativeInvoicePayerImport, crate::lightning::util::logger::Logger, crate::lightning::util::events::EventHandler>; +pub(crate) type nativeInvoicePayer = nativeInvoicePayerImport, crate::lightning::util::logger::Logger, crate::lightning::util::events::EventHandler>; -/// A utility for paying [`Invoice]`s. +/// A utility for paying [`Invoice`]s and sending spontaneous payments. +/// +/// See [module-level documentation] for details. +/// +/// [module-level documentation]: crate::payment #[must_use] #[repr(C)] pub struct InvoicePayer { @@ -186,9 +202,14 @@ pub struct Payer { /// Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] pub send_payment: extern "C" fn (this_arg: *const c_void, route: &crate::lightning::routing::router::Route, payment_hash: crate::c_types::ThirtyTwoBytes, payment_secret: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_PaymentIdPaymentSendFailureZ, + /// Sends a spontaneous payment over the Lightning Network using the given [`Route`]. + #[must_use] + pub send_spontaneous_payment: extern "C" fn (this_arg: *const c_void, route: &crate::lightning::routing::router::Route, payment_preimage: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_PaymentIdPaymentSendFailureZ, /// Retries a failed payment path for the [`PaymentId`] using the given [`Route`]. #[must_use] pub retry_payment: extern "C" fn (this_arg: *const c_void, route: &crate::lightning::routing::router::Route, payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_NonePaymentSendFailureZ, + /// Signals that no further retries for the given payment will occur. + pub abandon_payment: extern "C" fn (this_arg: *const c_void, payment_id: crate::c_types::ThirtyTwoBytes), /// 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, @@ -202,7 +223,9 @@ pub(crate) extern "C" fn Payer_clone_fields(orig: &Payer) -> Payer { node_id: Clone::clone(&orig.node_id), first_hops: Clone::clone(&orig.first_hops), send_payment: Clone::clone(&orig.send_payment), + send_spontaneous_payment: Clone::clone(&orig.send_spontaneous_payment), retry_payment: Clone::clone(&orig.retry_payment), + abandon_payment: Clone::clone(&orig.abandon_payment), free: Clone::clone(&orig.free), } } @@ -224,11 +247,19 @@ impl rustPayer for Payer { let mut local_ret = match ret.result_ok { true => Ok( { ::lightning::ln::channelmanager::PaymentId((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).data) }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })}; local_ret } + fn send_spontaneous_payment(&self, mut route: &lightning::routing::router::Route, mut payment_preimage: lightning::ln::PaymentPreimage) -> Result { + let mut ret = (self.send_spontaneous_payment)(self.this_arg, &crate::lightning::routing::router::Route { inner: unsafe { ObjOps::nonnull_ptr_to_inner((route as *const lightning::routing::router::Route<>) as *mut _) }, is_owned: false }, crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 }); + let mut local_ret = match ret.result_ok { true => Ok( { ::lightning::ln::channelmanager::PaymentId((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).data) }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })}; + local_ret + } fn retry_payment(&self, mut route: &lightning::routing::router::Route, mut payment_id: lightning::ln::channelmanager::PaymentId) -> Result<(), lightning::ln::channelmanager::PaymentSendFailure> { let mut ret = (self.retry_payment)(self.this_arg, &crate::lightning::routing::router::Route { inner: unsafe { ObjOps::nonnull_ptr_to_inner((route as *const lightning::routing::router::Route<>) as *mut _) }, is_owned: false }, crate::c_types::ThirtyTwoBytes { data: payment_id.0 }); 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 abandon_payment(&self, mut payment_id: lightning::ln::channelmanager::PaymentId) { + (self.abandon_payment)(self.this_arg, crate::c_types::ThirtyTwoBytes { data: payment_id.0 }) + } } // We're essentially a pointer already, or at least a set of pointers, so allow us to be used @@ -259,7 +290,7 @@ pub struct Router { /// /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] - pub find_route: extern "C" fn (this_arg: *const c_void, payer: crate::c_types::PublicKey, params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, scorer: &crate::lightning::routing::Score) -> crate::c_types::derived::CResult_RouteLightningErrorZ, + pub find_route: extern "C" fn (this_arg: *const c_void, payer: crate::c_types::PublicKey, params: &crate::lightning::routing::router::RouteParameters, payment_hash: *const [u8; 32], first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, scorer: &crate::lightning::routing::scoring::Score) -> crate::c_types::derived::CResult_RouteLightningErrorZ, /// 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, @@ -276,10 +307,10 @@ pub(crate) extern "C" fn Router_clone_fields(orig: &Router) -> Router { } use lightning_invoice::payment::Router as rustRouter; -impl rustRouter for Router { - fn find_route(&self, mut payer: &secp256k1::key::PublicKey, mut params: &lightning::routing::router::RouteParameters, mut first_hops: Option<&[&lightning::ln::channelmanager::ChannelDetails]>, mut scorer: &crate::lightning::routing::Score) -> Result { +impl rustRouter for Router { + fn find_route(&self, mut payer: &secp256k1::key::PublicKey, mut params: &lightning::routing::router::RouteParameters, mut payment_hash: &lightning::ln::PaymentHash, mut first_hops: Option<&[&lightning::ln::channelmanager::ChannelDetails]>, mut scorer: &crate::lightning::routing::scoring::Score) -> Result { let mut local_first_hops_base = if first_hops.is_none() { SmartPtr::null() } else { SmartPtr::from_obj( { let mut local_first_hops_0 = Vec::new(); for item in (first_hops.unwrap()).iter() { local_first_hops_0.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: unsafe { ObjOps::nonnull_ptr_to_inner(((*item) as *const lightning::ln::channelmanager::ChannelDetails<>) as *mut _) }, is_owned: false } }); }; local_first_hops_0.into() }) }; let mut local_first_hops = *local_first_hops_base; - let mut ret = (self.find_route)(self.this_arg, crate::c_types::PublicKey::from_rust(&payer), &crate::lightning::routing::router::RouteParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((params as *const lightning::routing::router::RouteParameters<>) as *mut _) }, is_owned: false }, local_first_hops, scorer); + let mut ret = (self.find_route)(self.this_arg, crate::c_types::PublicKey::from_rust(&payer), &crate::lightning::routing::router::RouteParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((params as *const lightning::routing::router::RouteParameters<>) as *mut _) }, is_owned: false }, &payment_hash.0, local_first_hops, scorer); let mut local_ret = match ret.result_ok { true => Ok( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).take_inner()) } }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; local_ret } @@ -543,7 +574,7 @@ pub extern "C" fn PaymentError_sending(a: crate::lightning::ln::channelmanager:: /// `retry_attempts` has been exceeded for a given [`Invoice`]. #[must_use] #[no_mangle] -pub extern "C" fn InvoicePayer_new(mut payer: crate::lightning_invoice::payment::Payer, mut router: crate::lightning_invoice::payment::Router, scorer: &crate::lightning::routing::LockableScore, mut logger: crate::lightning::util::logger::Logger, mut event_handler: crate::lightning::util::events::EventHandler, mut retry_attempts: crate::lightning_invoice::payment::RetryAttempts) -> InvoicePayer { +pub extern "C" fn InvoicePayer_new(mut payer: crate::lightning_invoice::payment::Payer, mut router: crate::lightning_invoice::payment::Router, scorer: &crate::lightning::routing::scoring::MultiThreadedLockableScore, mut logger: crate::lightning::util::logger::Logger, mut event_handler: crate::lightning::util::events::EventHandler, mut retry_attempts: crate::lightning_invoice::payment::RetryAttempts) -> InvoicePayer { let mut ret = lightning_invoice::payment::InvoicePayer::new(payer, router, scorer.get_native_ref(), logger, event_handler, *unsafe { Box::from_raw(retry_attempts.take_inner()) }); InvoicePayer { inner: ObjOps::heap_alloc(ret), is_owned: true } } @@ -575,6 +606,19 @@ pub extern "C" fn InvoicePayer_pay_zero_value_invoice(this_arg: &InvoicePayer, i local_ret } +/// Pays `pubkey` an amount using the hash of the given preimage, caching it for later use in +/// case a retry is needed. +/// +/// You should ensure that `payment_preimage` is unique and that its `payment_hash` has never +/// been paid before. Because [`InvoicePayer`] is stateless no effort is made to do so for you. +#[must_use] +#[no_mangle] +pub extern "C" fn InvoicePayer_pay_pubkey(this_arg: &InvoicePayer, mut pubkey: crate::c_types::PublicKey, mut payment_preimage: crate::c_types::ThirtyTwoBytes, mut amount_msats: u64, mut final_cltv_expiry_delta: u32) -> crate::c_types::derived::CResult_PaymentIdPaymentErrorZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.pay_pubkey(pubkey.into_rust(), ::lightning::ln::PaymentPreimage(payment_preimage.data), amount_msats, final_cltv_expiry_delta); + 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_invoice::payment::PaymentError::native_into(e) }).into() }; + local_ret +} + /// Removes the payment cached by the given payment hash. /// /// Should be called once a payment has failed or succeeded if not using [`InvoicePayer`] as an diff --git a/lightning-c-bindings/src/lightning_invoice/utils.rs b/lightning-c-bindings/src/lightning_invoice/utils.rs index aeb6f1c..ef8b51f 100644 --- a/lightning-c-bindings/src/lightning_invoice/utils.rs +++ b/lightning-c-bindings/src/lightning_invoice/utils.rs @@ -108,9 +108,9 @@ pub extern "C" fn DefaultRouter_as_Router(this_arg: &DefaultRouter) -> crate::li } #[must_use] -extern "C" fn DefaultRouter_Router_find_route(this_arg: *const c_void, mut payer: crate::c_types::PublicKey, params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, scorer: &crate::lightning::routing::Score) -> crate::c_types::derived::CResult_RouteLightningErrorZ { +extern "C" fn DefaultRouter_Router_find_route(this_arg: *const c_void, mut payer: crate::c_types::PublicKey, params: &crate::lightning::routing::router::RouteParameters, _payment_hash: *const [u8; 32], first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, scorer: &crate::lightning::routing::scoring::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 ret = >::find_route(unsafe { &mut *(this_arg as *mut nativeDefaultRouter) }, &payer.into_rust(), params.get_native_ref(), local_first_hops, scorer); + let mut ret = >::find_route(unsafe { &mut *(this_arg as *mut nativeDefaultRouter) }, &payer.into_rust(), params.get_native_ref(), &::lightning::ln::PaymentHash(unsafe { *_payment_hash }), local_first_hops, 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 } @@ -138,7 +138,9 @@ pub extern "C" fn ChannelManager_as_Payer(this_arg: &ChannelManager) -> crate::l node_id: ChannelManager_Payer_node_id, first_hops: ChannelManager_Payer_first_hops, send_payment: ChannelManager_Payer_send_payment, + send_spontaneous_payment: ChannelManager_Payer_send_spontaneous_payment, retry_payment: ChannelManager_Payer_retry_payment, + abandon_payment: ChannelManager_Payer_abandon_payment, } } @@ -161,9 +163,18 @@ extern "C" fn ChannelManager_Payer_send_payment(this_arg: *const c_void, route: local_ret } #[must_use] +extern "C" fn ChannelManager_Payer_send_spontaneous_payment(this_arg: *const c_void, route: &crate::lightning::routing::router::Route, mut payment_preimage: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_PaymentIdPaymentSendFailureZ { + let mut ret = >::send_spontaneous_payment(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, route.get_native_ref(), ::lightning::ln::PaymentPreimage(payment_preimage.data)); + 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() }; + local_ret +} +#[must_use] extern "C" fn ChannelManager_Payer_retry_payment(this_arg: *const c_void, route: &crate::lightning::routing::router::Route, mut payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_NonePaymentSendFailureZ { let mut ret = >::retry_payment(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, route.get_native_ref(), ::lightning::ln::channelmanager::PaymentId(payment_id.data)); 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 } +extern "C" fn ChannelManager_Payer_abandon_payment(this_arg: *const c_void, mut payment_id: crate::c_types::ThirtyTwoBytes) { + >::abandon_payment(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, ::lightning::ln::channelmanager::PaymentId(payment_id.data)) +} -- 2.39.5