From: Matt Corallo Date: Sat, 7 Aug 2021 21:42:32 +0000 (+0000) Subject: Restore auto-generated bindings to 0.0.99 X-Git-Tag: v0.0.99.3^0 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=cf24a5a34ebbf60457a5c431414a1d92a8ef1991;p=ldk-c-bindings Restore auto-generated bindings to 0.0.99 --- diff --git a/lightning-c-bindings/include/lightning.h b/lightning-c-bindings/include/lightning.h index 2a5f617..e1fba6a 100644 --- a/lightning-c-bindings/include/lightning.h +++ b/lightning-c-bindings/include/lightning.h @@ -3956,39 +3956,6 @@ typedef struct LDKCResult_NonePaymentSendFailureZ { bool result_ok; } LDKCResult_NonePaymentSendFailureZ; -/** - * The contents of CResult_PaymentHashPaymentSendFailureZ - */ -typedef union LDKCResult_PaymentHashPaymentSendFailureZPtr { - /** - * 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 LDKPaymentSendFailure *err; -} LDKCResult_PaymentHashPaymentSendFailureZPtr; - -/** - * A CResult_PaymentHashPaymentSendFailureZ represents the result of a fallible operation, - * containing a crate::c_types::ThirtyTwoBytes on success and a crate::lightning::ln::channelmanager::PaymentSendFailure on failure. - * `result_ok` indicates the overall state, and the contents are provided via `contents`. - */ -typedef struct LDKCResult_PaymentHashPaymentSendFailureZ { - /** - * The contents of this CResult_PaymentHashPaymentSendFailureZ, accessible via either - * `err` or `result` depending on the state of `result_ok`. - */ - union LDKCResult_PaymentHashPaymentSendFailureZPtr contents; - /** - * Whether this CResult_PaymentHashPaymentSendFailureZ represents a success state. - */ - bool result_ok; -} LDKCResult_PaymentHashPaymentSendFailureZ; - /** * A 4-byte byte array. */ @@ -5415,74 +5382,6 @@ typedef struct LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32ScriptZZZZ { uintptr_t datalen; } LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32ScriptZZZZ; -/** - * Some information provided on receipt of payment depends on whether the payment received is a - * spontaneous payment or a \"conventional\" lightning payment that's paying an invoice. - */ -typedef enum LDKPaymentPurpose_Tag { - /** - * Information for receiving a payment that we generated an invoice for. - */ - LDKPaymentPurpose_InvoicePayment, - /** - * Because this is a spontaneous payment, the payer generated their own preimage rather than us - * (the payee) providing a preimage. - */ - LDKPaymentPurpose_SpontaneousPayment, - /** - * Must be last for serialization purposes - */ - LDKPaymentPurpose_Sentinel, -} LDKPaymentPurpose_Tag; - -typedef struct LDKPaymentPurpose_LDKInvoicePayment_Body { - /** - * The preimage to the payment_hash, if the payment hash (and secret) were fetched via - * [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to - * [`ChannelManager::claim_funds`]. - * - * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment - * [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds - * - * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None - */ - struct LDKThirtyTwoBytes payment_preimage; - /** - * The \"payment secret\". This authenticates the sender to the recipient, preventing a - * number of deanonymization attacks during the routing process. - * It is provided here for your reference, however its accuracy is enforced directly by - * [`ChannelManager`] using the values you previously provided to - * [`ChannelManager::create_inbound_payment`] or - * [`ChannelManager::create_inbound_payment_for_hash`]. - * - * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager - * [`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 - */ - 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 { - LDKPaymentPurpose_Tag tag; - union { - LDKPaymentPurpose_LDKInvoicePayment_Body invoice_payment; - struct { - struct LDKThirtyTwoBytes spontaneous_payment; - }; - }; -} LDKPaymentPurpose; - /** * An Event which you should probably take some action in response to. * @@ -5535,11 +5434,6 @@ typedef enum LDKEvent_Tag { * somewhere and spend them when you create on-chain transactions. */ LDKEvent_SpendableOutputs, - /** - * This event is generated when a payment has been successfully forwarded through us and a - * forwarding fee earned. - */ - LDKEvent_PaymentForwarded, /** * Must be last for serialization purposes */ @@ -5571,6 +5465,30 @@ typedef struct LDKEvent_LDKPaymentReceived_Body { * The hash for which the preimage should be handed to the ChannelManager. */ struct LDKThirtyTwoBytes payment_hash; + /** + * The preimage to the payment_hash, if the payment hash (and secret) were fetched via + * [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to + * [`ChannelManager::claim_funds`]. + * + * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment + * [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds + * + * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None + */ + struct LDKThirtyTwoBytes payment_preimage; + /** + * The \"payment secret\". This authenticates the sender to the recipient, preventing a + * number of deanonymization attacks during the routing process. + * It is provided here for your reference, however its accuracy is enforced directly by + * [`ChannelManager`] using the values you previously provided to + * [`ChannelManager::create_inbound_payment`] or + * [`ChannelManager::create_inbound_payment_for_hash`]. + * + * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager + * [`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 + */ + struct LDKThirtyTwoBytes payment_secret; /** * The value, in thousandths of a satoshi, that this payment is for. Note that you must * compare this to the expected value before accepting the payment (as otherwise you are @@ -5578,10 +5496,16 @@ typedef struct LDKEvent_LDKPaymentReceived_Body { */ uint64_t amt; /** - * Information for claiming this received payment, based on whether the purpose of the - * payment is to pay an invoice or to send a spontaneous payment. + * 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 */ - struct LDKPaymentPurpose purpose; + uint64_t user_payment_id; } LDKEvent_LDKPaymentReceived_Body; typedef struct LDKEvent_LDKPaymentSent_Body { @@ -5623,30 +5547,6 @@ typedef struct LDKEvent_LDKSpendableOutputs_Body { struct LDKCVec_SpendableOutputDescriptorZ outputs; } LDKEvent_LDKSpendableOutputs_Body; -typedef struct LDKEvent_LDKPaymentForwarded_Body { - /** - * The fee, in milli-satoshis, which was earned as a result of the payment. - * - * Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC - * was pending, the amount the next hop claimed will have been rounded down to the nearest - * whole satoshi. Thus, the fee calculated here may be higher than expected as we still - * claimed the full value in millisatoshis from the source. In this case, - * `claim_from_onchain_tx` will be set. - * - * If the channel which sent us the payment has been force-closed, we will claim the funds - * via an on-chain transaction. In that case we do not yet know the on-chain transaction - * fees which we will spend and will instead set this to `None`. It is possible duplicate - * `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is - * `None`. - */ - struct LDKCOption_u64Z fee_earned_msat; - /** - * If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain - * transaction. - */ - bool claim_from_onchain_tx; -} LDKEvent_LDKPaymentForwarded_Body; - typedef struct MUST_USE_STRUCT LDKEvent { LDKEvent_Tag tag; union { @@ -5656,7 +5556,6 @@ typedef struct MUST_USE_STRUCT LDKEvent { LDKEvent_LDKPaymentFailed_Body payment_failed; LDKEvent_LDKPendingHTLCsForwardable_Body pending_htl_cs_forwardable; LDKEvent_LDKSpendableOutputs_Body spendable_outputs; - LDKEvent_LDKPaymentForwarded_Body payment_forwarded; }; } LDKEvent; @@ -9043,7 +8942,6 @@ typedef struct MUST_USE_STRUCT LDKFilesystemPersister { * then there is a risk of channels force-closing on startup when the manager realizes it's * outdated. However, as long as `ChannelMonitor` backups are sound, no funds besides those used * for unilateral chain closure fees are at risk. - *BackgroundProcessor will immediately stop on drop. It should be stored until shutdown. */ typedef struct MUST_USE_STRUCT LDKBackgroundProcessor { /** @@ -10182,27 +10080,6 @@ void CResult_NonePaymentSendFailureZ_free(struct LDKCResult_NonePaymentSendFailu */ struct LDKCResult_NonePaymentSendFailureZ CResult_NonePaymentSendFailureZ_clone(const struct LDKCResult_NonePaymentSendFailureZ *NONNULL_PTR orig); -/** - * Creates a new CResult_PaymentHashPaymentSendFailureZ in the success state. - */ -struct LDKCResult_PaymentHashPaymentSendFailureZ CResult_PaymentHashPaymentSendFailureZ_ok(struct LDKThirtyTwoBytes o); - -/** - * Creates a new CResult_PaymentHashPaymentSendFailureZ in the error state. - */ -struct LDKCResult_PaymentHashPaymentSendFailureZ CResult_PaymentHashPaymentSendFailureZ_err(struct LDKPaymentSendFailure e); - -/** - * Frees any resources used by the CResult_PaymentHashPaymentSendFailureZ. - */ -void CResult_PaymentHashPaymentSendFailureZ_free(struct LDKCResult_PaymentHashPaymentSendFailureZ _res); - -/** - * Creates a new CResult_PaymentHashPaymentSendFailureZ which has the same data as `orig` - * but with all dynamically-allocated buffers duplicated in new buffers. - */ -struct LDKCResult_PaymentHashPaymentSendFailureZ CResult_PaymentHashPaymentSendFailureZ_clone(const struct LDKCResult_PaymentHashPaymentSendFailureZ *NONNULL_PTR orig); - /** * Frees the buffer pointed to by `data` if `datalen` is non-0. */ @@ -11773,26 +11650,6 @@ void CResult_InvoiceSignOrCreationErrorZ_free(struct LDKCResult_InvoiceSignOrCre */ struct LDKCResult_InvoiceSignOrCreationErrorZ CResult_InvoiceSignOrCreationErrorZ_clone(const struct LDKCResult_InvoiceSignOrCreationErrorZ *NONNULL_PTR orig); -/** - * Frees any resources used by the PaymentPurpose - */ -void PaymentPurpose_free(struct LDKPaymentPurpose this_ptr); - -/** - * Creates a copy of the PaymentPurpose - */ -struct LDKPaymentPurpose PaymentPurpose_clone(const struct LDKPaymentPurpose *NONNULL_PTR orig); - -/** - * 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); - -/** - * Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose - */ -struct LDKPaymentPurpose PaymentPurpose_spontaneous_payment(struct LDKThirtyTwoBytes a); - /** * Frees any resources used by the Event */ @@ -11811,7 +11668,7 @@ struct LDKEvent Event_funding_generation_ready(struct LDKThirtyTwoBytes temporar /** * Utility method to constructs a new PaymentReceived-variant Event */ -struct LDKEvent Event_payment_received(struct LDKThirtyTwoBytes payment_hash, uint64_t amt, struct LDKPaymentPurpose purpose); +struct LDKEvent Event_payment_received(struct LDKThirtyTwoBytes payment_hash, struct LDKThirtyTwoBytes payment_preimage, struct LDKThirtyTwoBytes payment_secret, uint64_t amt, uint64_t user_payment_id); /** * Utility method to constructs a new PaymentSent-variant Event @@ -11833,11 +11690,6 @@ struct LDKEvent Event_pending_htlcs_forwardable(uint64_t time_forwardable); */ struct LDKEvent Event_spendable_outputs(struct LDKCVec_SpendableOutputDescriptorZ outputs); -/** - * Utility method to constructs a new PaymentForwarded-variant Event - */ -struct LDKEvent Event_payment_forwarded(struct LDKCOption_u64Z fee_earned_msat, bool claim_from_onchain_tx); - /** * Serialize the Event object into a byte array which can be read by Event_read */ @@ -14105,22 +13957,6 @@ void ChannelManager_force_close_all_channels(const struct LDKChannelManager *NON */ MUST_USE_RES struct LDKCResult_NonePaymentSendFailureZ ChannelManager_send_payment(const struct LDKChannelManager *NONNULL_PTR this_arg, const struct LDKRoute *NONNULL_PTR route, struct LDKThirtyTwoBytes payment_hash, struct LDKThirtyTwoBytes payment_secret); -/** - * 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 - * would be able to guess -- otherwise, an intermediate node may claim the payment and it will - * never reach the recipient. - * - * Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See - * [`send_payment`] for more information about the risks of duplicate preimage usage. - * - * [`send_payment`]: Self::send_payment - * - * Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None - */ -MUST_USE_RES struct LDKCResult_PaymentHashPaymentSendFailureZ ChannelManager_send_spontaneous_payment(const struct LDKChannelManager *NONNULL_PTR this_arg, const struct LDKRoute *NONNULL_PTR route, struct LDKThirtyTwoBytes payment_preimage); - /** * Call this upon creation of a funding transaction for the given channel. * @@ -14272,7 +14108,7 @@ MUST_USE_RES struct LDKC2Tuple_PaymentHashPaymentSecretZ ChannelManager_create_i * 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 + * `user_payment_id` will be provided back in [`PaymentReceived::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 @@ -14306,7 +14142,7 @@ MUST_USE_RES struct LDKC2Tuple_PaymentHashPaymentSecretZ ChannelManager_create_i * * [`create_inbound_payment`]: Self::create_inbound_payment * [`PaymentReceived`]: events::Event::PaymentReceived - * [`PaymentPurpose::InvoicePayment::user_payment_id`]: events::PaymentPurpose::InvoicePayment::user_payment_id + * [`PaymentReceived::user_payment_id`]: events::Event::PaymentReceived::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); @@ -18094,15 +17930,6 @@ bool RouteHintHop_eq(const struct LDKRouteHintHop *NONNULL_PTR a, const struct L */ struct LDKRouteHintHop RouteHintHop_clone(const struct LDKRouteHintHop *NONNULL_PTR orig); -/** - * Gets a keysend route from us (payer) to the given target node (payee). This is needed because - * keysend payments do not have an invoice from which to pull the payee's supported features, which - * makes it tricky to otherwise supply the `payee_features` parameter of `get_route`. - * - * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None - */ -struct LDKCResult_RouteLightningErrorZ get_keysend_route(struct LDKPublicKey our_node_id, const struct LDKNetworkGraph *NONNULL_PTR network, struct LDKPublicKey payee, struct LDKCVec_ChannelDetailsZ *first_hops, struct LDKCVec_RouteHintZ last_hops, uint64_t final_value_msat, uint32_t final_cltv, struct LDKLogger logger); - /** * Gets a route from us (payer) to the given target node (payee). * @@ -18766,25 +18593,21 @@ void BackgroundProcessor_free(struct LDKBackgroundProcessor this_obj); void ChannelManagerPersister_free(struct LDKChannelManagerPersister this_ptr); /** - * Start a background thread that takes care of responsibilities enumerated in the [top-level - * documentation]. - * - * The thread runs indefinitely unless the object is dropped, [`stop`] is called, or - * `persist_manager` returns an error. In case of an error, the error is retrieved by calling - * either [`join`] or [`stop`]. + * Start a background thread that takes care of responsibilities enumerated in the top-level + * documentation. * - * Typically, users should either implement [`ChannelManagerPersister`] to never return an - * error or call [`join`] and handle any error that may arise. For the latter case, the - * `BackgroundProcessor` must be restarted by calling `start` again after handling the error. + * If `persist_manager` returns an error, then this thread will return said error (and + * `start()` will need to be called again to restart the `BackgroundProcessor`). Users should + * wait on [`thread_handle`]'s `join()` method to be able to tell if and when an error is + * returned, or implement `persist_manager` such that an error is never returned to the + * `BackgroundProcessor` * * `persist_manager` is responsible for writing out the [`ChannelManager`] to disk, and/or * uploading to one or more backup services. See [`ChannelManager::write`] for writing out a * [`ChannelManager`]. See [`FilesystemPersister::persist_manager`] for Rust-Lightning's * provided implementation. * - * [top-level documentation]: Self - * [`join`]: Self::join - * [`stop`]: Self::stop + * [`thread_handle`]: BackgroundProcessor::thread_handle * [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager * [`ChannelManager::write`]: lightning::ln::channelmanager::ChannelManager#impl-Writeable * [`FilesystemPersister::persist_manager`]: lightning_persister::FilesystemPersister::persist_manager @@ -18792,28 +18615,7 @@ void ChannelManagerPersister_free(struct LDKChannelManagerPersister this_ptr); MUST_USE_RES struct LDKBackgroundProcessor BackgroundProcessor_start(struct LDKChannelManagerPersister persister, struct LDKEventHandler event_handler, const struct LDKChainMonitor *NONNULL_PTR chain_monitor, const struct LDKChannelManager *NONNULL_PTR channel_manager, const struct LDKPeerManager *NONNULL_PTR peer_manager, struct LDKLogger logger); /** - * Join `BackgroundProcessor`'s thread, returning any error that occurred while persisting - * [`ChannelManager`]. - * - * # Panics - * - * This function panics if the background thread has panicked such as while persisting or - * handling events. - * - * [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager - */ -MUST_USE_RES struct LDKCResult_NoneErrorZ BackgroundProcessor_join(struct LDKBackgroundProcessor this_arg); - -/** - * Stop `BackgroundProcessor`'s thread, returning any error that occurred while persisting - * [`ChannelManager`]. - * - * # Panics - * - * This function panics if the background thread has panicked such as while persisting or - * handling events. - * - * [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager + * Stop `BackgroundProcessor`'s thread. */ MUST_USE_RES struct LDKCResult_NoneErrorZ BackgroundProcessor_stop(struct LDKBackgroundProcessor this_arg); diff --git a/lightning-c-bindings/include/lightningpp.hpp b/lightning-c-bindings/include/lightningpp.hpp index 8d53186..f6b9dca 100644 --- a/lightning-c-bindings/include/lightningpp.hpp +++ b/lightning-c-bindings/include/lightningpp.hpp @@ -28,7 +28,6 @@ class Confirm; class Watch; class Filter; class WatchedOutput; -class PaymentPurpose; class Event; class MessageSendEvent; class MessageSendEventsProvider; @@ -269,7 +268,6 @@ class CResult_NoneSemanticErrorZ; class CVec_MonitorEventZ; class CVec_C2Tuple_u32ScriptZZ; class CResult_NoneChannelMonitorUpdateErrZ; -class CResult_PaymentHashPaymentSendFailureZ; class CResult_SiPrefixNoneZ; class CResult_PublicKeyErrorZ; class C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ; @@ -828,21 +826,6 @@ public: const LDKWatchedOutput* operator &() const { return &self; } const LDKWatchedOutput* operator ->() const { return &self; } }; -class PaymentPurpose { -private: - LDKPaymentPurpose self; -public: - PaymentPurpose(const PaymentPurpose&) = delete; - PaymentPurpose(PaymentPurpose&& o) : self(o.self) { memset(&o, 0, sizeof(PaymentPurpose)); } - PaymentPurpose(LDKPaymentPurpose&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKPaymentPurpose)); } - operator LDKPaymentPurpose() && { LDKPaymentPurpose res = self; memset(&self, 0, sizeof(LDKPaymentPurpose)); return res; } - ~PaymentPurpose() { PaymentPurpose_free(self); } - PaymentPurpose& operator=(PaymentPurpose&& o) { PaymentPurpose_free(self); self = o.self; memset(&o, 0, sizeof(PaymentPurpose)); return *this; } - LDKPaymentPurpose* operator &() { return &self; } - LDKPaymentPurpose* operator ->() { return &self; } - const LDKPaymentPurpose* operator &() const { return &self; } - const LDKPaymentPurpose* operator ->() const { return &self; } -}; class Event { private: LDKEvent self; @@ -4857,21 +4840,6 @@ public: const LDKCResult_NoneChannelMonitorUpdateErrZ* operator &() const { return &self; } const LDKCResult_NoneChannelMonitorUpdateErrZ* operator ->() const { return &self; } }; -class CResult_PaymentHashPaymentSendFailureZ { -private: - LDKCResult_PaymentHashPaymentSendFailureZ self; -public: - CResult_PaymentHashPaymentSendFailureZ(const CResult_PaymentHashPaymentSendFailureZ&) = delete; - CResult_PaymentHashPaymentSendFailureZ(CResult_PaymentHashPaymentSendFailureZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_PaymentHashPaymentSendFailureZ)); } - CResult_PaymentHashPaymentSendFailureZ(LDKCResult_PaymentHashPaymentSendFailureZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_PaymentHashPaymentSendFailureZ)); } - operator LDKCResult_PaymentHashPaymentSendFailureZ() && { LDKCResult_PaymentHashPaymentSendFailureZ res = self; memset(&self, 0, sizeof(LDKCResult_PaymentHashPaymentSendFailureZ)); return res; } - ~CResult_PaymentHashPaymentSendFailureZ() { CResult_PaymentHashPaymentSendFailureZ_free(self); } - CResult_PaymentHashPaymentSendFailureZ& operator=(CResult_PaymentHashPaymentSendFailureZ&& o) { CResult_PaymentHashPaymentSendFailureZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_PaymentHashPaymentSendFailureZ)); return *this; } - LDKCResult_PaymentHashPaymentSendFailureZ* operator &() { return &self; } - LDKCResult_PaymentHashPaymentSendFailureZ* operator ->() { return &self; } - const LDKCResult_PaymentHashPaymentSendFailureZ* operator &() const { return &self; } - const LDKCResult_PaymentHashPaymentSendFailureZ* operator ->() const { return &self; } -}; class CResult_SiPrefixNoneZ { private: LDKCResult_SiPrefixNoneZ self; diff --git a/lightning-c-bindings/src/c_types/derived.rs b/lightning-c-bindings/src/c_types/derived.rs index fef1837..c9d57ee 100644 --- a/lightning-c-bindings/src/c_types/derived.rs +++ b/lightning-c-bindings/src/c_types/derived.rs @@ -4090,97 +4090,6 @@ impl Clone for CResult_NonePaymentSendFailureZ { /// but with all dynamically-allocated buffers duplicated in new buffers. pub extern "C" fn CResult_NonePaymentSendFailureZ_clone(orig: &CResult_NonePaymentSendFailureZ) -> CResult_NonePaymentSendFailureZ { orig.clone() } #[repr(C)] -/// The contents of CResult_PaymentHashPaymentSendFailureZ -pub union CResult_PaymentHashPaymentSendFailureZPtr { - /// 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::ln::channelmanager::PaymentSendFailure, -} -#[repr(C)] -/// A CResult_PaymentHashPaymentSendFailureZ represents the result of a fallible operation, -/// containing a crate::c_types::ThirtyTwoBytes on success and a crate::lightning::ln::channelmanager::PaymentSendFailure on failure. -/// `result_ok` indicates the overall state, and the contents are provided via `contents`. -pub struct CResult_PaymentHashPaymentSendFailureZ { - /// The contents of this CResult_PaymentHashPaymentSendFailureZ, accessible via either - /// `err` or `result` depending on the state of `result_ok`. - pub contents: CResult_PaymentHashPaymentSendFailureZPtr, - /// Whether this CResult_PaymentHashPaymentSendFailureZ represents a success state. - pub result_ok: bool, -} -#[no_mangle] -/// Creates a new CResult_PaymentHashPaymentSendFailureZ in the success state. -pub extern "C" fn CResult_PaymentHashPaymentSendFailureZ_ok(o: crate::c_types::ThirtyTwoBytes) -> CResult_PaymentHashPaymentSendFailureZ { - CResult_PaymentHashPaymentSendFailureZ { - contents: CResult_PaymentHashPaymentSendFailureZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -/// Creates a new CResult_PaymentHashPaymentSendFailureZ in the error state. -pub extern "C" fn CResult_PaymentHashPaymentSendFailureZ_err(e: crate::lightning::ln::channelmanager::PaymentSendFailure) -> CResult_PaymentHashPaymentSendFailureZ { - CResult_PaymentHashPaymentSendFailureZ { - contents: CResult_PaymentHashPaymentSendFailureZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -/// Frees any resources used by the CResult_PaymentHashPaymentSendFailureZ. -pub extern "C" fn CResult_PaymentHashPaymentSendFailureZ_free(_res: CResult_PaymentHashPaymentSendFailureZ) { } -impl Drop for CResult_PaymentHashPaymentSendFailureZ { - 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_PaymentHashPaymentSendFailureZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_PaymentHashPaymentSendFailureZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_PaymentHashPaymentSendFailureZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_PaymentHashPaymentSendFailureZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_PaymentHashPaymentSendFailureZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_PaymentHashPaymentSendFailureZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -/// Creates a new CResult_PaymentHashPaymentSendFailureZ which has the same data as `orig` -/// but with all dynamically-allocated buffers duplicated in new buffers. -pub extern "C" fn CResult_PaymentHashPaymentSendFailureZ_clone(orig: &CResult_PaymentHashPaymentSendFailureZ) -> CResult_PaymentHashPaymentSendFailureZ { orig.clone() } -#[repr(C)] /// A dynamically-allocated array of crate::lightning::ln::msgs::NetAddresss of arbitrary size. /// This corresponds to std::vector in C++ pub struct CVec_NetAddressZ { diff --git a/lightning-c-bindings/src/lightning/ln/channelmanager.rs b/lightning-c-bindings/src/lightning/ln/channelmanager.rs index afdcaa9..94bcf26 100644 --- a/lightning-c-bindings/src/lightning/ln/channelmanager.rs +++ b/lightning-c-bindings/src/lightning/ln/channelmanager.rs @@ -1072,27 +1072,6 @@ pub extern "C" fn ChannelManager_send_payment(this_arg: &ChannelManager, route: local_ret } -/// 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 -/// would be able to guess -- otherwise, an intermediate node may claim the payment and it will -/// never reach the recipient. -/// -/// Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See -/// [`send_payment`] for more information about the risks of duplicate preimage usage. -/// -/// [`send_payment`]: Self::send_payment -/// -/// Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelManager_send_spontaneous_payment(this_arg: &ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_preimage: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_PaymentHashPaymentSendFailureZ { - let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) }; - let mut ret = unsafe { &*this_arg.inner }.send_spontaneous_payment(unsafe { &*route.inner }, local_payment_preimage); - let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ThirtyTwoBytes { data: o.0 } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::channelmanager::PaymentSendFailure::native_into(e) }).into() }; - local_ret -} - /// Call this upon creation of a funding transaction for the given channel. /// /// Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs @@ -1266,7 +1245,7 @@ pub extern "C" fn ChannelManager_create_inbound_payment(this_arg: &ChannelManage /// 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 +/// `user_payment_id` will be provided back in [`PaymentReceived::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 @@ -1300,7 +1279,7 @@ pub extern "C" fn ChannelManager_create_inbound_payment(this_arg: &ChannelManage /// /// [`create_inbound_payment`]: Self::create_inbound_payment /// [`PaymentReceived`]: events::Event::PaymentReceived -/// [`PaymentPurpose::InvoicePayment::user_payment_id`]: events::PaymentPurpose::InvoicePayment::user_payment_id +/// [`PaymentReceived::user_payment_id`]: events::Event::PaymentReceived::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 { diff --git a/lightning-c-bindings/src/lightning/routing/router.rs b/lightning-c-bindings/src/lightning/routing/router.rs index ad15a35..fb67474 100644 --- a/lightning-c-bindings/src/lightning/routing/router.rs +++ b/lightning-c-bindings/src/lightning/routing/router.rs @@ -517,20 +517,6 @@ pub(crate) extern "C" fn RouteHintHop_clone_void(this_ptr: *const c_void) -> *mu pub extern "C" fn RouteHintHop_clone(orig: &RouteHintHop) -> RouteHintHop { orig.clone() } -/// Gets a keysend route from us (payer) to the given target node (payee). This is needed because -/// keysend payments do not have an invoice from which to pull the payee's supported features, which -/// makes it tricky to otherwise supply the `payee_features` parameter of `get_route`. -/// -/// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None -#[no_mangle] -pub extern "C" fn get_keysend_route(mut our_node_id: crate::c_types::PublicKey, network: &crate::lightning::routing::network_graph::NetworkGraph, mut payee: crate::c_types::PublicKey, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut last_hops: crate::c_types::derived::CVec_RouteHintZ, mut final_value_msat: u64, mut final_cltv: u32, mut logger: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_RouteLightningErrorZ { - 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( { unsafe { &*item.inner } }); }; local_first_hops_0 }) }; let mut local_first_hops = local_first_hops_base.as_ref().map(|a| &a[..]); - let mut local_last_hops = Vec::new(); for mut item in last_hops.as_slice().iter() { local_last_hops.push( { unsafe { &*item.inner } }); }; - let mut ret = lightning::routing::router::get_keysend_route(&our_node_id.into_rust(), unsafe { &*network.inner }, &payee.into_rust(), local_first_hops, &local_last_hops[..], final_value_msat, final_cltv, logger); - let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::Route { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() }; - local_ret -} - /// Gets a route from us (payer) to the given target node (payee). /// /// If the payee provided features in their invoice, they should be provided via payee_features. diff --git a/lightning-c-bindings/src/lightning/util/events.rs b/lightning-c-bindings/src/lightning/util/events.rs index 491812d..e259ba7 100644 --- a/lightning-c-bindings/src/lightning/util/events.rs +++ b/lightning-c-bindings/src/lightning/util/events.rs @@ -18,153 +18,6 @@ use std::ffi::c_void; use bitcoin::hashes::Hash; use crate::c_types::*; -/// Some information provided on receipt of payment depends on whether the payment received is a -/// spontaneous payment or a \"conventional\" lightning payment that's paying an invoice. -#[must_use] -#[derive(Clone)] -#[repr(C)] -pub enum PaymentPurpose { - /// Information for receiving a payment that we generated an invoice for. - InvoicePayment { - /// The preimage to the payment_hash, if the payment hash (and secret) were fetched via - /// [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to - /// [`ChannelManager::claim_funds`]. - /// - /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment - /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds - /// - /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None - payment_preimage: crate::c_types::ThirtyTwoBytes, - /// The \"payment secret\". This authenticates the sender to the recipient, preventing a - /// number of deanonymization attacks during the routing process. - /// It is provided here for your reference, however its accuracy is enforced directly by - /// [`ChannelManager`] using the values you previously provided to - /// [`ChannelManager::create_inbound_payment`] or - /// [`ChannelManager::create_inbound_payment_for_hash`]. - /// - /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager - /// [`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. - SpontaneousPayment(crate::c_types::ThirtyTwoBytes), -} -use lightning::util::events::PaymentPurpose as nativePaymentPurpose; -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, } => { - 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, ) => { - let mut a_nonref = (*a).clone(); - nativePaymentPurpose::SpontaneousPayment ( - ::lightning::ln::PaymentPreimage(a_nonref.data), - ) - }, - } - } - #[allow(unused)] - pub(crate) fn into_native(self) -> nativePaymentPurpose { - match self { - PaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, mut user_payment_id, } => { - 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, ) => { - nativePaymentPurpose::SpontaneousPayment ( - ::lightning::ln::PaymentPreimage(a.data), - ) - }, - } - } - #[allow(unused)] - pub(crate) fn from_native(native: &nativePaymentPurpose) -> Self { - match native { - nativePaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, ref user_payment_id, } => { - 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, ) => { - let mut a_nonref = (*a).clone(); - PaymentPurpose::SpontaneousPayment ( - crate::c_types::ThirtyTwoBytes { data: a_nonref.0 }, - ) - }, - } - } - #[allow(unused)] - pub(crate) fn native_into(native: nativePaymentPurpose) -> Self { - match native { - nativePaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, mut user_payment_id, } => { - 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, ) => { - PaymentPurpose::SpontaneousPayment ( - crate::c_types::ThirtyTwoBytes { data: a.0 }, - ) - }, - } - } -} -/// Frees any resources used by the PaymentPurpose -#[no_mangle] -pub extern "C" fn PaymentPurpose_free(this_ptr: PaymentPurpose) { } -/// Creates a copy of the PaymentPurpose -#[no_mangle] -pub extern "C" fn PaymentPurpose_clone(orig: &PaymentPurpose) -> PaymentPurpose { - orig.clone() -} -#[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 { - PaymentPurpose::InvoicePayment { - payment_preimage, - payment_secret, - user_payment_id, - } -} -#[no_mangle] -/// Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose -pub extern "C" fn PaymentPurpose_spontaneous_payment(a: crate::c_types::ThirtyTwoBytes) -> PaymentPurpose { - PaymentPurpose::SpontaneousPayment(a, ) -} /// An Event which you should probably take some action in response to. /// /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use @@ -203,13 +56,39 @@ pub enum Event { PaymentReceived { /// The hash for which the preimage should be handed to the ChannelManager. payment_hash: crate::c_types::ThirtyTwoBytes, + /// The preimage to the payment_hash, if the payment hash (and secret) were fetched via + /// [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to + /// [`ChannelManager::claim_funds`]. + /// + /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment + /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds + /// + /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None + payment_preimage: crate::c_types::ThirtyTwoBytes, + /// The \"payment secret\". This authenticates the sender to the recipient, preventing a + /// number of deanonymization attacks during the routing process. + /// It is provided here for your reference, however its accuracy is enforced directly by + /// [`ChannelManager`] using the values you previously provided to + /// [`ChannelManager::create_inbound_payment`] or + /// [`ChannelManager::create_inbound_payment_for_hash`]. + /// + /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager + /// [`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, /// The value, in thousandths of a satoshi, that this payment is for. Note that you must /// compare this to the expected value before accepting the payment (as otherwise you are /// providing proof-of-payment for less than the value you expected!). amt: u64, - /// Information for claiming this received payment, based on whether the purpose of the - /// payment is to pay an invoice or to send a spontaneous payment. - purpose: crate::lightning::util::events::PaymentPurpose, + /// 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, }, /// Indicates an outbound payment we made succeeded (ie it made it all the way to its target /// and we got back the payment preimage for it). @@ -247,27 +126,6 @@ pub enum Event { /// The outputs which you should store as spendable by you. outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ, }, - /// This event is generated when a payment has been successfully forwarded through us and a - /// forwarding fee earned. - PaymentForwarded { - /// The fee, in milli-satoshis, which was earned as a result of the payment. - /// - /// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC - /// was pending, the amount the next hop claimed will have been rounded down to the nearest - /// whole satoshi. Thus, the fee calculated here may be higher than expected as we still - /// claimed the full value in millisatoshis from the source. In this case, - /// `claim_from_onchain_tx` will be set. - /// - /// If the channel which sent us the payment has been force-closed, we will claim the funds - /// via an on-chain transaction. In that case we do not yet know the on-chain transaction - /// fees which we will spend and will instead set this to `None`. It is possible duplicate - /// `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is - /// `None`. - fee_earned_msat: crate::c_types::derived::COption_u64Z, - /// If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain - /// transaction. - claim_from_onchain_tx: bool, - }, } use lightning::util::events::Event as nativeEvent; impl Event { @@ -286,14 +144,19 @@ impl Event { user_channel_id: user_channel_id_nonref, } }, - Event::PaymentReceived {ref payment_hash, ref amt, ref purpose, } => { + Event::PaymentReceived {ref payment_hash, ref payment_preimage, ref payment_secret, ref amt, ref user_payment_id, } => { let mut payment_hash_nonref = (*payment_hash).clone(); + 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 amt_nonref = (*amt).clone(); - let mut purpose_nonref = (*purpose).clone(); + let mut user_payment_id_nonref = (*user_payment_id).clone(); nativeEvent::PaymentReceived { payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data), + payment_preimage: local_payment_preimage_nonref, + payment_secret: ::lightning::ln::PaymentSecret(payment_secret_nonref.data), amt: amt_nonref, - purpose: purpose_nonref.into_native(), + user_payment_id: user_payment_id_nonref, } }, Event::PaymentSent {ref payment_preimage, } => { @@ -323,15 +186,6 @@ impl Event { outputs: local_outputs_nonref, } }, - Event::PaymentForwarded {ref fee_earned_msat, ref claim_from_onchain_tx, } => { - let mut fee_earned_msat_nonref = (*fee_earned_msat).clone(); - let mut local_fee_earned_msat_nonref = if fee_earned_msat_nonref.is_some() { Some( { fee_earned_msat_nonref.take() }) } else { None }; - let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone(); - nativeEvent::PaymentForwarded { - fee_earned_msat: local_fee_earned_msat_nonref, - claim_from_onchain_tx: claim_from_onchain_tx_nonref, - } - }, } } #[allow(unused)] @@ -345,11 +199,14 @@ impl Event { user_channel_id: user_channel_id, } }, - Event::PaymentReceived {mut payment_hash, mut amt, mut purpose, } => { + Event::PaymentReceived {mut payment_hash, mut payment_preimage, mut payment_secret, mut amt, mut user_payment_id, } => { + let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) }; nativeEvent::PaymentReceived { payment_hash: ::lightning::ln::PaymentHash(payment_hash.data), + payment_preimage: local_payment_preimage, + payment_secret: ::lightning::ln::PaymentSecret(payment_secret.data), amt: amt, - purpose: purpose.into_native(), + user_payment_id: user_payment_id, } }, Event::PaymentSent {mut payment_preimage, } => { @@ -374,13 +231,6 @@ impl Event { outputs: local_outputs, } }, - Event::PaymentForwarded {mut fee_earned_msat, mut claim_from_onchain_tx, } => { - let mut local_fee_earned_msat = if fee_earned_msat.is_some() { Some( { fee_earned_msat.take() }) } else { None }; - nativeEvent::PaymentForwarded { - fee_earned_msat: local_fee_earned_msat, - claim_from_onchain_tx: claim_from_onchain_tx, - } - }, } } #[allow(unused)] @@ -398,14 +248,19 @@ impl Event { user_channel_id: user_channel_id_nonref, } }, - nativeEvent::PaymentReceived {ref payment_hash, ref amt, ref purpose, } => { + nativeEvent::PaymentReceived {ref payment_hash, ref payment_preimage, ref payment_secret, ref amt, ref user_payment_id, } => { let mut payment_hash_nonref = (*payment_hash).clone(); + 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 amt_nonref = (*amt).clone(); - let mut purpose_nonref = (*purpose).clone(); + let mut user_payment_id_nonref = (*user_payment_id).clone(); Event::PaymentReceived { payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 }, + payment_preimage: local_payment_preimage_nonref, + payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret_nonref.0 }, amt: amt_nonref, - purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose_nonref), + user_payment_id: user_payment_id_nonref, } }, nativeEvent::PaymentSent {ref payment_preimage, } => { @@ -435,15 +290,6 @@ impl Event { outputs: local_outputs_nonref.into(), } }, - nativeEvent::PaymentForwarded {ref fee_earned_msat, ref claim_from_onchain_tx, } => { - let mut fee_earned_msat_nonref = (*fee_earned_msat).clone(); - let mut local_fee_earned_msat_nonref = if fee_earned_msat_nonref.is_none() { crate::c_types::derived::COption_u64Z::None } else { { crate::c_types::derived::COption_u64Z::Some(fee_earned_msat_nonref.unwrap()) } }; - let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone(); - Event::PaymentForwarded { - fee_earned_msat: local_fee_earned_msat_nonref, - claim_from_onchain_tx: claim_from_onchain_tx_nonref, - } - }, } } #[allow(unused)] @@ -457,11 +303,14 @@ impl Event { user_channel_id: user_channel_id, } }, - nativeEvent::PaymentReceived {mut payment_hash, mut amt, mut purpose, } => { + nativeEvent::PaymentReceived {mut payment_hash, mut payment_preimage, mut payment_secret, mut amt, mut user_payment_id, } => { + 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 } } }; Event::PaymentReceived { payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 }, + payment_preimage: local_payment_preimage, + payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret.0 }, amt: amt, - purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose), + user_payment_id: user_payment_id, } }, nativeEvent::PaymentSent {mut payment_preimage, } => { @@ -486,13 +335,6 @@ impl Event { outputs: local_outputs.into(), } }, - nativeEvent::PaymentForwarded {mut fee_earned_msat, mut claim_from_onchain_tx, } => { - let mut local_fee_earned_msat = if fee_earned_msat.is_none() { crate::c_types::derived::COption_u64Z::None } else { { crate::c_types::derived::COption_u64Z::Some(fee_earned_msat.unwrap()) } }; - Event::PaymentForwarded { - fee_earned_msat: local_fee_earned_msat, - claim_from_onchain_tx: claim_from_onchain_tx, - } - }, } } } @@ -516,11 +358,13 @@ pub extern "C" fn Event_funding_generation_ready(temporary_channel_id: crate::c_ } #[no_mangle] /// Utility method to constructs a new PaymentReceived-variant Event -pub extern "C" fn Event_payment_received(payment_hash: crate::c_types::ThirtyTwoBytes, amt: u64, purpose: crate::lightning::util::events::PaymentPurpose) -> Event { +pub extern "C" fn Event_payment_received(payment_hash: crate::c_types::ThirtyTwoBytes, payment_preimage: crate::c_types::ThirtyTwoBytes, payment_secret: crate::c_types::ThirtyTwoBytes, amt: u64, user_payment_id: u64) -> Event { Event::PaymentReceived { payment_hash, + payment_preimage, + payment_secret, amt, - purpose, + user_payment_id, } } #[no_mangle] @@ -553,14 +397,6 @@ pub extern "C" fn Event_spendable_outputs(outputs: crate::c_types::derived::CVec } } #[no_mangle] -/// Utility method to constructs a new PaymentForwarded-variant Event -pub extern "C" fn Event_payment_forwarded(fee_earned_msat: crate::c_types::derived::COption_u64Z, claim_from_onchain_tx: bool) -> Event { - Event::PaymentForwarded { - fee_earned_msat, - claim_from_onchain_tx, - } -} -#[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_background_processor.rs b/lightning-c-bindings/src/lightning_background_processor.rs index fc44da9..e42a18d 100644 --- a/lightning-c-bindings/src/lightning_background_processor.rs +++ b/lightning-c-bindings/src/lightning_background_processor.rs @@ -33,7 +33,6 @@ type nativeBackgroundProcessor = nativeBackgroundProcessorImport; /// then there is a risk of channels force-closing on startup when the manager realizes it's /// outdated. However, as long as `ChannelMonitor` backups are sound, no funds besides those used /// for unilateral chain closure fees are at risk. -///BackgroundProcessor will immediately stop on drop. It should be stored until shutdown. #[must_use] #[repr(C)] pub struct BackgroundProcessor { @@ -130,25 +129,21 @@ impl Drop for ChannelManagerPersister { } } } -/// Start a background thread that takes care of responsibilities enumerated in the [top-level -/// documentation]. +/// Start a background thread that takes care of responsibilities enumerated in the top-level +/// documentation. /// -/// The thread runs indefinitely unless the object is dropped, [`stop`] is called, or -/// `persist_manager` returns an error. In case of an error, the error is retrieved by calling -/// either [`join`] or [`stop`]. -/// -/// Typically, users should either implement [`ChannelManagerPersister`] to never return an -/// error or call [`join`] and handle any error that may arise. For the latter case, the -/// `BackgroundProcessor` must be restarted by calling `start` again after handling the error. +/// If `persist_manager` returns an error, then this thread will return said error (and +/// `start()` will need to be called again to restart the `BackgroundProcessor`). Users should +/// wait on [`thread_handle`]'s `join()` method to be able to tell if and when an error is +/// returned, or implement `persist_manager` such that an error is never returned to the +/// `BackgroundProcessor` /// /// `persist_manager` is responsible for writing out the [`ChannelManager`] to disk, and/or /// uploading to one or more backup services. See [`ChannelManager::write`] for writing out a /// [`ChannelManager`]. See [`FilesystemPersister::persist_manager`] for Rust-Lightning's /// provided implementation. /// -/// [top-level documentation]: Self -/// [`join`]: Self::join -/// [`stop`]: Self::stop +/// [`thread_handle`]: BackgroundProcessor::thread_handle /// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager /// [`ChannelManager::write`]: lightning::ln::channelmanager::ChannelManager#impl-Writeable /// [`FilesystemPersister::persist_manager`]: lightning_persister::FilesystemPersister::persist_manager @@ -159,32 +154,7 @@ pub extern "C" fn BackgroundProcessor_start(mut persister: crate::lightning_back BackgroundProcessor { inner: Box::into_raw(Box::new(ret)), is_owned: true } } -/// Join `BackgroundProcessor`'s thread, returning any error that occurred while persisting -/// [`ChannelManager`]. -/// -/// # Panics -/// -/// This function panics if the background thread has panicked such as while persisting or -/// handling events. -/// -/// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager -#[must_use] -#[no_mangle] -pub extern "C" fn BackgroundProcessor_join(mut this_arg: BackgroundProcessor) -> crate::c_types::derived::CResult_NoneErrorZ { - let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).join(); - 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::c_types::IOError::from_rust(e) }).into() }; - local_ret -} - -/// Stop `BackgroundProcessor`'s thread, returning any error that occurred while persisting -/// [`ChannelManager`]. -/// -/// # Panics -/// -/// This function panics if the background thread has panicked such as while persisting or -/// handling events. -/// -/// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager +/// Stop `BackgroundProcessor`'s thread. #[must_use] #[no_mangle] pub extern "C" fn BackgroundProcessor_stop(mut this_arg: BackgroundProcessor) -> crate::c_types::derived::CResult_NoneErrorZ {