From 3b909ef20b6c2f73aadbcde3f1885d67a401d530 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 5 Jun 2024 14:34:15 +0000 Subject: [PATCH] Update auto-generated bindings to include ln-transaction-sync --- lightning-c-bindings/include/ldk_rust_types.h | 4 + lightning-c-bindings/include/lightning.h | 498 ++++++++++++++---- lightning-c-bindings/include/lightningpp.hpp | 179 +++++-- lightning-c-bindings/src/c_types/derived.rs | 192 +++++++ .../lightning_transaction_sync/electrum.rs | 139 +++++ .../src/lightning_transaction_sync/error.rs | 79 +++ .../src/lightning_transaction_sync/esplora.rs | 142 +++++ .../src/lightning_transaction_sync/mod.rs | 92 ++++ 8 files changed, 1173 insertions(+), 152 deletions(-) create mode 100644 lightning-c-bindings/src/lightning_transaction_sync/electrum.rs create mode 100644 lightning-c-bindings/src/lightning_transaction_sync/error.rs create mode 100644 lightning-c-bindings/src/lightning_transaction_sync/esplora.rs create mode 100644 lightning-c-bindings/src/lightning_transaction_sync/mod.rs diff --git a/lightning-c-bindings/include/ldk_rust_types.h b/lightning-c-bindings/include/ldk_rust_types.h index e37879c..edf493f 100644 --- a/lightning-c-bindings/include/ldk_rust_types.h +++ b/lightning-c-bindings/include/ldk_rust_types.h @@ -383,6 +383,10 @@ struct nativePacketOpaque; typedef struct nativePacketOpaque LDKnativePacket; struct nativeClaimedHTLCOpaque; typedef struct nativeClaimedHTLCOpaque LDKnativeClaimedHTLC; +struct nativeElectrumSyncClientOpaque; +typedef struct nativeElectrumSyncClientOpaque LDKnativeElectrumSyncClient; +struct nativeEsploraSyncClientOpaque; +typedef struct nativeEsploraSyncClientOpaque LDKnativeEsploraSyncClient; struct nativeBolt11InvoiceOpaque; typedef struct nativeBolt11InvoiceOpaque LDKnativeBolt11Invoice; struct nativeSignedRawBolt11InvoiceOpaque; diff --git a/lightning-c-bindings/include/lightning.h b/lightning-c-bindings/include/lightning.h index fad8366..a5b1181 100644 --- a/lightning-c-bindings/include/lightning.h +++ b/lightning-c-bindings/include/lightning.h @@ -996,6 +996,20 @@ typedef enum LDKSocketAddressParseError { LDKSocketAddressParseError_Sentinel, } LDKSocketAddressParseError; +/** + * An error that possibly needs to be handled by the user. + */ +typedef enum LDKTxSyncError { + /** + * A transaction sync failed and needs to be retried eventually. + */ + LDKTxSyncError_Failed, + /** + * Must be last for serialization purposes + */ + LDKTxSyncError_Sentinel, +} LDKTxSyncError; + /** * An error when accessing the chain via [`UtxoLookup`]. */ @@ -19446,6 +19460,228 @@ typedef struct LDKCResult_COption_EventZDecodeErrorZ { bool result_ok; } LDKCResult_COption_EventZDecodeErrorZ; + + +/** + * Synchronizes LDK with a given Electrum server. + * + * Needs to be registered with a [`ChainMonitor`] via the [`Filter`] interface to be informed of + * transactions and outputs to monitor for on-chain confirmation, unconfirmation, and + * reconfirmation. + * + * Note that registration via [`Filter`] needs to happen before any calls to + * [`Watch::watch_channel`] to ensure we get notified of the items to monitor. + * + * [`ChainMonitor`]: lightning::chain::chainmonitor::ChainMonitor + * [`Watch::watch_channel`]: lightning::chain::Watch::watch_channel + * [`Filter`]: lightning::chain::Filter + */ +typedef struct MUST_USE_STRUCT LDKElectrumSyncClient { + /** + * 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. + */ + LDKnativeElectrumSyncClient *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; +} LDKElectrumSyncClient; + +/** + * The contents of CResult_ElectrumSyncClientTxSyncErrorZ + */ +typedef union LDKCResult_ElectrumSyncClientTxSyncErrorZPtr { + /** + * A pointer to the contents in the success state. + * Reading from this pointer when `result_ok` is not set is undefined. + */ + struct LDKElectrumSyncClient *result; + /** + * A pointer to the contents in the error state. + * Reading from this pointer when `result_ok` is set is undefined. + */ + enum LDKTxSyncError *err; +} LDKCResult_ElectrumSyncClientTxSyncErrorZPtr; + +/** + * A CResult_ElectrumSyncClientTxSyncErrorZ represents the result of a fallible operation, + * containing a crate::lightning_transaction_sync::electrum::ElectrumSyncClient on success and a crate::lightning_transaction_sync::error::TxSyncError on failure. + * `result_ok` indicates the overall state, and the contents are provided via `contents`. + */ +typedef struct LDKCResult_ElectrumSyncClientTxSyncErrorZ { + /** + * The contents of this CResult_ElectrumSyncClientTxSyncErrorZ, accessible via either + * `err` or `result` depending on the state of `result_ok`. + */ + union LDKCResult_ElectrumSyncClientTxSyncErrorZPtr contents; + /** + * Whether this CResult_ElectrumSyncClientTxSyncErrorZ represents a success state. + */ + bool result_ok; +} LDKCResult_ElectrumSyncClientTxSyncErrorZ; + +/** + * The `Confirm` trait is used to notify LDK when relevant transactions have been confirmed on + * chain or unconfirmed during a chain reorganization. + * + * Clients sourcing chain data using a transaction-oriented API should prefer this interface over + * [`Listen`]. For instance, an Electrum-based transaction sync implementation may implement + * [`Filter`] to subscribe to relevant transactions and unspent outputs it should monitor for + * on-chain activity. Then, it needs to notify LDK via this interface upon observing any changes + * with reference to the confirmation status of the monitored objects. + * + * # Use + * The intended use is as follows: + * - Call [`transactions_confirmed`] to notify LDK whenever any of the registered transactions or + * outputs are, respectively, confirmed or spent on chain. + * - Call [`transaction_unconfirmed`] to notify LDK whenever any transaction returned by + * [`get_relevant_txids`] is no longer confirmed in the block with the given block hash. + * - Call [`best_block_updated`] to notify LDK whenever a new chain tip becomes available. + * + * # Order + * + * Clients must call these methods in chain order. Specifically: + * - Transactions which are confirmed in a particular block must be given before transactions + * confirmed in a later block. + * - Dependent transactions within the same block must be given in topological order, possibly in + * separate calls. + * - All unconfirmed transactions must be given after the original confirmations and before *any* + * reconfirmations, i.e., [`transactions_confirmed`] and [`transaction_unconfirmed`] calls should + * never be interleaved, but always conduced *en bloc*. + * - Any reconfirmed transactions need to be explicitly unconfirmed before they are reconfirmed + * in regard to the new block. + * + * See individual method documentation for further details. + * + * [`transactions_confirmed`]: Self::transactions_confirmed + * [`transaction_unconfirmed`]: Self::transaction_unconfirmed + * [`best_block_updated`]: Self::best_block_updated + * [`get_relevant_txids`]: Self::get_relevant_txids + */ +typedef struct LDKConfirm { + /** + * An opaque pointer which is passed to your function implementations as an argument. + * This has no meaning in the LDK, and can be NULL or any other value. + */ + void *this_arg; + /** + * Notifies LDK of transactions confirmed in a block with a given header and height. + * + * Must be called for any transactions registered by [`Filter::register_tx`] or any + * transactions spending an output registered by [`Filter::register_output`]. Such transactions + * appearing in the same block do not need to be included in the same call; instead, multiple + * calls with additional transactions may be made so long as they are made in [chain order]. + * + * May be called before or after [`best_block_updated`] for the corresponding block. However, + * in the event of a chain reorganization, it must not be called with a `header` that is no + * longer in the chain as of the last call to [`best_block_updated`]. + * + * [chain order]: Confirm#order + * [`best_block_updated`]: Self::best_block_updated + */ + void (*transactions_confirmed)(const void *this_arg, const uint8_t (*header)[80], struct LDKCVec_C2Tuple_usizeTransactionZZ txdata, uint32_t height); + /** + * Notifies LDK of a transaction that is no longer confirmed as result of a chain reorganization. + * + * Must be called for any transaction returned by [`get_relevant_txids`] if it has been + * reorganized out of the best chain or if it is no longer confirmed in the block with the + * given block hash. Once called, the given transaction will not be returned + * by [`get_relevant_txids`], unless it has been reconfirmed via [`transactions_confirmed`]. + * + * [`get_relevant_txids`]: Self::get_relevant_txids + * [`transactions_confirmed`]: Self::transactions_confirmed + */ + void (*transaction_unconfirmed)(const void *this_arg, const uint8_t (*txid)[32]); + /** + * Notifies LDK of an update to the best header connected at the given height. + * + * Must be called whenever a new chain tip becomes available. May be skipped for intermediary + * blocks. + */ + void (*best_block_updated)(const void *this_arg, const uint8_t (*header)[80], uint32_t height); + /** + * Returns transactions that must be monitored for reorganization out of the chain along + * with the height and the hash of the block as part of which it had been previously confirmed. + * + * Note that the returned `Option` might be `None` for channels created with LDK + * 0.0.112 and prior, in which case you need to manually track previous confirmations. + * + * Will include any transactions passed to [`transactions_confirmed`] that have insufficient + * confirmations to be safe from a chain reorganization. Will not include any transactions + * passed to [`transaction_unconfirmed`], unless later reconfirmed. + * + * Must be called to determine the subset of transactions that must be monitored for + * reorganization. Will be idempotent between calls but may change as a result of calls to the + * other interface methods. Thus, this is useful to determine which transactions must be + * given to [`transaction_unconfirmed`]. + * + * If any of the returned transactions are confirmed in a block other than the one with the + * given hash at the given height, they need to be unconfirmed and reconfirmed via + * [`transaction_unconfirmed`] and [`transactions_confirmed`], respectively. + * + * [`transactions_confirmed`]: Self::transactions_confirmed + * [`transaction_unconfirmed`]: Self::transaction_unconfirmed + */ + struct LDKCVec_C3Tuple_ThirtyTwoBytesu32COption_ThirtyTwoBytesZZZ (*get_relevant_txids)(const void *this_arg); + /** + * Frees any resources associated with this object given its this_arg pointer. + * Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. + */ + void (*free)(void *this_arg); +} LDKConfirm; + +/** + * A dynamically-allocated array of crate::lightning::chain::Confirms of arbitrary size. + * This corresponds to std::vector in C++ + */ +typedef struct LDKCVec_ConfirmZ { + /** + * The elements in the array. + * If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc(). + */ + struct LDKConfirm *data; + /** + * The number of elements pointed to by `data`. + */ + uintptr_t datalen; +} LDKCVec_ConfirmZ; + +/** + * The contents of CResult_NoneTxSyncErrorZ + */ +typedef union LDKCResult_NoneTxSyncErrorZPtr { + /** + * Note that this value is always NULL, as there are no contents in the OK variant + */ + void *result; + /** + * A pointer to the contents in the error state. + * Reading from this pointer when `result_ok` is set is undefined. + */ + enum LDKTxSyncError *err; +} LDKCResult_NoneTxSyncErrorZPtr; + +/** + * A CResult_NoneTxSyncErrorZ represents the result of a fallible operation, + * containing a () on success and a crate::lightning_transaction_sync::error::TxSyncError on failure. + * `result_ok` indicates the overall state, and the contents are provided via `contents`. + */ +typedef struct LDKCResult_NoneTxSyncErrorZ { + /** + * The contents of this CResult_NoneTxSyncErrorZ, accessible via either + * `err` or `result` depending on the state of `result_ok`. + */ + union LDKCResult_NoneTxSyncErrorZPtr contents; + /** + * Whether this CResult_NoneTxSyncErrorZ represents a success state. + */ + bool result_ok; +} LDKCResult_NoneTxSyncErrorZ; + /** * Sub-errors which don't have specific information in them use this type. */ @@ -22542,116 +22778,6 @@ typedef struct LDKListen { void (*free)(void *this_arg); } LDKListen; -/** - * The `Confirm` trait is used to notify LDK when relevant transactions have been confirmed on - * chain or unconfirmed during a chain reorganization. - * - * Clients sourcing chain data using a transaction-oriented API should prefer this interface over - * [`Listen`]. For instance, an Electrum-based transaction sync implementation may implement - * [`Filter`] to subscribe to relevant transactions and unspent outputs it should monitor for - * on-chain activity. Then, it needs to notify LDK via this interface upon observing any changes - * with reference to the confirmation status of the monitored objects. - * - * # Use - * The intended use is as follows: - * - Call [`transactions_confirmed`] to notify LDK whenever any of the registered transactions or - * outputs are, respectively, confirmed or spent on chain. - * - Call [`transaction_unconfirmed`] to notify LDK whenever any transaction returned by - * [`get_relevant_txids`] is no longer confirmed in the block with the given block hash. - * - Call [`best_block_updated`] to notify LDK whenever a new chain tip becomes available. - * - * # Order - * - * Clients must call these methods in chain order. Specifically: - * - Transactions which are confirmed in a particular block must be given before transactions - * confirmed in a later block. - * - Dependent transactions within the same block must be given in topological order, possibly in - * separate calls. - * - All unconfirmed transactions must be given after the original confirmations and before *any* - * reconfirmations, i.e., [`transactions_confirmed`] and [`transaction_unconfirmed`] calls should - * never be interleaved, but always conduced *en bloc*. - * - Any reconfirmed transactions need to be explicitly unconfirmed before they are reconfirmed - * in regard to the new block. - * - * See individual method documentation for further details. - * - * [`transactions_confirmed`]: Self::transactions_confirmed - * [`transaction_unconfirmed`]: Self::transaction_unconfirmed - * [`best_block_updated`]: Self::best_block_updated - * [`get_relevant_txids`]: Self::get_relevant_txids - */ -typedef struct LDKConfirm { - /** - * An opaque pointer which is passed to your function implementations as an argument. - * This has no meaning in the LDK, and can be NULL or any other value. - */ - void *this_arg; - /** - * Notifies LDK of transactions confirmed in a block with a given header and height. - * - * Must be called for any transactions registered by [`Filter::register_tx`] or any - * transactions spending an output registered by [`Filter::register_output`]. Such transactions - * appearing in the same block do not need to be included in the same call; instead, multiple - * calls with additional transactions may be made so long as they are made in [chain order]. - * - * May be called before or after [`best_block_updated`] for the corresponding block. However, - * in the event of a chain reorganization, it must not be called with a `header` that is no - * longer in the chain as of the last call to [`best_block_updated`]. - * - * [chain order]: Confirm#order - * [`best_block_updated`]: Self::best_block_updated - */ - void (*transactions_confirmed)(const void *this_arg, const uint8_t (*header)[80], struct LDKCVec_C2Tuple_usizeTransactionZZ txdata, uint32_t height); - /** - * Notifies LDK of a transaction that is no longer confirmed as result of a chain reorganization. - * - * Must be called for any transaction returned by [`get_relevant_txids`] if it has been - * reorganized out of the best chain or if it is no longer confirmed in the block with the - * given block hash. Once called, the given transaction will not be returned - * by [`get_relevant_txids`], unless it has been reconfirmed via [`transactions_confirmed`]. - * - * [`get_relevant_txids`]: Self::get_relevant_txids - * [`transactions_confirmed`]: Self::transactions_confirmed - */ - void (*transaction_unconfirmed)(const void *this_arg, const uint8_t (*txid)[32]); - /** - * Notifies LDK of an update to the best header connected at the given height. - * - * Must be called whenever a new chain tip becomes available. May be skipped for intermediary - * blocks. - */ - void (*best_block_updated)(const void *this_arg, const uint8_t (*header)[80], uint32_t height); - /** - * Returns transactions that must be monitored for reorganization out of the chain along - * with the height and the hash of the block as part of which it had been previously confirmed. - * - * Note that the returned `Option` might be `None` for channels created with LDK - * 0.0.112 and prior, in which case you need to manually track previous confirmations. - * - * Will include any transactions passed to [`transactions_confirmed`] that have insufficient - * confirmations to be safe from a chain reorganization. Will not include any transactions - * passed to [`transaction_unconfirmed`], unless later reconfirmed. - * - * Must be called to determine the subset of transactions that must be monitored for - * reorganization. Will be idempotent between calls but may change as a result of calls to the - * other interface methods. Thus, this is useful to determine which transactions must be - * given to [`transaction_unconfirmed`]. - * - * If any of the returned transactions are confirmed in a block other than the one with the - * given hash at the given height, they need to be unconfirmed and reconfirmed via - * [`transaction_unconfirmed`] and [`transactions_confirmed`], respectively. - * - * [`transactions_confirmed`]: Self::transactions_confirmed - * [`transaction_unconfirmed`]: Self::transaction_unconfirmed - */ - struct LDKCVec_C3Tuple_ThirtyTwoBytesu32COption_ThirtyTwoBytesZZZ (*get_relevant_txids)(const void *this_arg); - /** - * Frees any resources associated with this object given its this_arg pointer. - * Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. - */ - void (*free)(void *this_arg); -} LDKConfirm; - /** * A `enum` signalling to the [`OutputSweeper`] that it should delay spending an output until a * future block height is reached. @@ -25208,6 +25334,41 @@ typedef struct MUST_USE_STRUCT LDKFallback { }; } LDKFallback; + + +/** + * Synchronizes LDK with a given [`Esplora`] server. + * + * Needs to be registered with a [`ChainMonitor`] via the [`Filter`] interface to be informed of + * transactions and outputs to monitor for on-chain confirmation, unconfirmation, and + * reconfirmation. + * + * Note that registration via [`Filter`] needs to happen before any calls to + * [`Watch::watch_channel`] to ensure we get notified of the items to monitor. + * + * This uses and exposes either a blocking or async client variant dependent on whether the + * `esplora-blocking` or the `esplora-async` feature is enabled. + * + * [`Esplora`]: https://github.com/Blockstream/electrs + * [`ChainMonitor`]: lightning::chain::chainmonitor::ChainMonitor + * [`Watch::watch_channel`]: lightning::chain::Watch::watch_channel + * [`Filter`]: lightning::chain::Filter + */ +typedef struct MUST_USE_STRUCT LDKEsploraSyncClient { + /** + * 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. + */ + LDKnativeEsploraSyncClient *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; +} LDKEsploraSyncClient; + extern const uintptr_t MAX_BUF_SIZE; extern const uintptr_t KVSTORE_NAMESPACE_KEY_MAX_LEN; @@ -32087,6 +32248,51 @@ void CResult_COption_EventZDecodeErrorZ_free(struct LDKCResult_COption_EventZDec */ struct LDKCResult_COption_EventZDecodeErrorZ CResult_COption_EventZDecodeErrorZ_clone(const struct LDKCResult_COption_EventZDecodeErrorZ *NONNULL_PTR orig); +/** + * Creates a new CResult_ElectrumSyncClientTxSyncErrorZ in the success state. + */ +struct LDKCResult_ElectrumSyncClientTxSyncErrorZ CResult_ElectrumSyncClientTxSyncErrorZ_ok(struct LDKElectrumSyncClient o); + +/** + * Creates a new CResult_ElectrumSyncClientTxSyncErrorZ in the error state. + */ +struct LDKCResult_ElectrumSyncClientTxSyncErrorZ CResult_ElectrumSyncClientTxSyncErrorZ_err(enum LDKTxSyncError e); + +/** + * Checks if the given object is currently in the success state + */ +bool CResult_ElectrumSyncClientTxSyncErrorZ_is_ok(const struct LDKCResult_ElectrumSyncClientTxSyncErrorZ *NONNULL_PTR o); + +/** + * Frees any resources used by the CResult_ElectrumSyncClientTxSyncErrorZ. + */ +void CResult_ElectrumSyncClientTxSyncErrorZ_free(struct LDKCResult_ElectrumSyncClientTxSyncErrorZ _res); + +/** + * Frees the buffer pointed to by `data` if `datalen` is non-0. + */ +void CVec_ConfirmZ_free(struct LDKCVec_ConfirmZ _res); + +/** + * Creates a new CResult_NoneTxSyncErrorZ in the success state. + */ +struct LDKCResult_NoneTxSyncErrorZ CResult_NoneTxSyncErrorZ_ok(void); + +/** + * Creates a new CResult_NoneTxSyncErrorZ in the error state. + */ +struct LDKCResult_NoneTxSyncErrorZ CResult_NoneTxSyncErrorZ_err(enum LDKTxSyncError e); + +/** + * Checks if the given object is currently in the success state + */ +bool CResult_NoneTxSyncErrorZ_is_ok(const struct LDKCResult_NoneTxSyncErrorZ *NONNULL_PTR o); + +/** + * Frees any resources used by the CResult_NoneTxSyncErrorZ. + */ +void CResult_NoneTxSyncErrorZ_free(struct LDKCResult_NoneTxSyncErrorZ _res); + /** * Creates a new CResult_SiPrefixBolt11ParseErrorZ in the success state. */ @@ -57915,6 +58121,78 @@ MUST_USE_RES struct LDKCResult_u32GraphSyncErrorZ RapidGossipSync_update_network */ MUST_USE_RES bool RapidGossipSync_is_initial_sync_complete(const struct LDKRapidGossipSync *NONNULL_PTR this_arg); +/** + * Frees any resources used by the EsploraSyncClient, if is_owned is set and inner is non-NULL. + */ +void EsploraSyncClient_free(struct LDKEsploraSyncClient this_obj); + +/** + * Returns a new [`EsploraSyncClient`] object. + */ +MUST_USE_RES struct LDKEsploraSyncClient EsploraSyncClient_new(struct LDKStr server_url, struct LDKLogger logger); + +/** + * Synchronizes the given `confirmables` via their [`Confirm`] interface implementations. This + * method should be called regularly to keep LDK up-to-date with current chain data. + * + * For example, instances of [`ChannelManager`] and [`ChainMonitor`] can be informed about the + * newest on-chain activity related to the items previously registered via the [`Filter`] + * interface. + * + * [`Confirm`]: lightning::chain::Confirm + * [`ChainMonitor`]: lightning::chain::chainmonitor::ChainMonitor + * [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager + * [`Filter`]: lightning::chain::Filter + */ +MUST_USE_RES struct LDKCResult_NoneTxSyncErrorZ EsploraSyncClient_sync(const struct LDKEsploraSyncClient *NONNULL_PTR this_arg, struct LDKCVec_ConfirmZ confirmables); + +/** + * Constructs a new Filter which calls the relevant methods on this_arg. + * This copies the `inner` pointer in this_arg and thus the returned Filter must be freed before this_arg is + */ +struct LDKFilter EsploraSyncClient_as_Filter(const struct LDKEsploraSyncClient *NONNULL_PTR this_arg); + +/** + * Frees any resources used by the ElectrumSyncClient, if is_owned is set and inner is non-NULL. + */ +void ElectrumSyncClient_free(struct LDKElectrumSyncClient this_obj); + +/** + * Returns a new [`ElectrumSyncClient`] object. + */ +MUST_USE_RES struct LDKCResult_ElectrumSyncClientTxSyncErrorZ ElectrumSyncClient_new(struct LDKStr server_url, struct LDKLogger logger); + +/** + * Synchronizes the given `confirmables` via their [`Confirm`] interface implementations. This + * method should be called regularly to keep LDK up-to-date with current chain data. + * + * For example, instances of [`ChannelManager`] and [`ChainMonitor`] can be informed about the + * newest on-chain activity related to the items previously registered via the [`Filter`] + * interface. + * + * [`Confirm`]: lightning::chain::Confirm + * [`ChainMonitor`]: lightning::chain::chainmonitor::ChainMonitor + * [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager + * [`Filter`]: lightning::chain::Filter + */ +MUST_USE_RES struct LDKCResult_NoneTxSyncErrorZ ElectrumSyncClient_sync(const struct LDKElectrumSyncClient *NONNULL_PTR this_arg, struct LDKCVec_ConfirmZ confirmables); + +/** + * Constructs a new Filter which calls the relevant methods on this_arg. + * This copies the `inner` pointer in this_arg and thus the returned Filter must be freed before this_arg is + */ +struct LDKFilter ElectrumSyncClient_as_Filter(const struct LDKElectrumSyncClient *NONNULL_PTR this_arg); + +/** + * Creates a copy of the TxSyncError + */ +enum LDKTxSyncError TxSyncError_clone(const enum LDKTxSyncError *NONNULL_PTR orig); + +/** + * Utility method to constructs a new Failed-variant TxSyncError + */ +enum LDKTxSyncError TxSyncError_failed(void); + #endif /* LDK_C_BINDINGS_H */ #include "ldk_ver.h" diff --git a/lightning-c-bindings/include/lightningpp.hpp b/lightning-c-bindings/include/lightningpp.hpp index 0f40b39..f84cf23 100644 --- a/lightning-c-bindings/include/lightningpp.hpp +++ b/lightning-c-bindings/include/lightningpp.hpp @@ -273,6 +273,8 @@ class MessageSendEvent; class MessageSendEventsProvider; class EventsProvider; class EventHandler; +class ElectrumSyncClient; +class EsploraSyncClient; class Bolt11ParseError; class ParseOrSemanticError; class Bolt11Invoice; @@ -325,6 +327,7 @@ class SendError; class CustomOnionMessageHandler; class PeeledOnion; class FilesystemStore; +class TxSyncError; class NextMessageHop; class BlindedPath; class IntroductionNode; @@ -367,6 +370,7 @@ class COption_NetworkUpdateZ; class COption_u64Z; class CResult_OnionPacketDecodeErrorZ; class CResult_GossipTimestampFilterDecodeErrorZ; +class CVec_ConfirmZ; class CResult_RouteHintDecodeErrorZ; class COption_FilterZ; class C2Tuple_ThirtyTwoBytesCVec_C2Tuple_u32CVec_u8ZZZZ; @@ -481,11 +485,12 @@ class COption_C2Tuple_ThirtyTwoU16sThirtyTwoU16sZZ; class CResult_COption_OutboundHTLCStateDetailsZDecodeErrorZ; class CResult_RoutingFeesDecodeErrorZ; class CVec_C2Tuple_ThirtyTwoBytesCVec_C2Tuple_u32CVec_u8ZZZZZ; +class CResult_NoneTxSyncErrorZ; class CResult_DescriptionCreationErrorZ; -class CResult_PaymentRelayDecodeErrorZ; class CResult_QueryShortChannelIdsDecodeErrorZ; class CResult_VerifiedInvoiceRequestNoneZ; class CResult_UpdateAddHTLCDecodeErrorZ; +class CResult_PaymentRelayDecodeErrorZ; class COption_OutboundHTLCStateDetailsZ; class COption_MonitorEventZ; class COption_TypeZ; @@ -572,7 +577,7 @@ class COption_StrZ; class CResult_ProbabilisticScorerDecodeErrorZ; class CResult_COption_InboundHTLCStateDetailsZDecodeErrorZ; class CResult_ShutdownScriptDecodeErrorZ; -class CResult_SiPrefixBolt11ParseErrorZ; +class CResult_ElectrumSyncClientTxSyncErrorZ; class C2Tuple_usizeTransactionZ; class CResult_NodeAnnouncementDecodeErrorZ; class CVec_FutureZ; @@ -584,7 +589,7 @@ class CResult_OfferIdDecodeErrorZ; class CVec_HTLCOutputInCommitmentZ; class CResult_CoinSelectionNoneZ; class CResult_TxCreationKeysDecodeErrorZ; -class CResult_BlindedPathDecodeErrorZ; +class CResult_SiPrefixBolt11ParseErrorZ; class CResult_RefundBolt12SemanticErrorZ; class CResult_NoneIOErrorZ; class CResult_MaxDustHTLCExposureDecodeErrorZ; @@ -594,6 +599,7 @@ class CResult_FundingSignedDecodeErrorZ; class CResult_RecoverableSignatureNoneZ; class CResult_SocketAddressDecodeErrorZ; class C2Tuple_Z; +class CResult_BlindedPathDecodeErrorZ; class CResult_InboundHTLCDetailsDecodeErrorZ; class C2Tuple_ECDSASignatureCVec_ECDSASignatureZZ; class CVec_PathZ; @@ -5942,6 +5948,36 @@ public: */ inline void handle_event(struct LDKEvent event); }; +class ElectrumSyncClient { +private: + LDKElectrumSyncClient self; +public: + ElectrumSyncClient(const ElectrumSyncClient&) = delete; + ElectrumSyncClient(ElectrumSyncClient&& o) : self(o.self) { memset(&o, 0, sizeof(ElectrumSyncClient)); } + ElectrumSyncClient(LDKElectrumSyncClient&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKElectrumSyncClient)); } + operator LDKElectrumSyncClient() && { LDKElectrumSyncClient res = self; memset(&self, 0, sizeof(LDKElectrumSyncClient)); return res; } + ~ElectrumSyncClient() { ElectrumSyncClient_free(self); } + ElectrumSyncClient& operator=(ElectrumSyncClient&& o) { ElectrumSyncClient_free(self); self = o.self; memset(&o, 0, sizeof(ElectrumSyncClient)); return *this; } + LDKElectrumSyncClient* operator &() { return &self; } + LDKElectrumSyncClient* operator ->() { return &self; } + const LDKElectrumSyncClient* operator &() const { return &self; } + const LDKElectrumSyncClient* operator ->() const { return &self; } +}; +class EsploraSyncClient { +private: + LDKEsploraSyncClient self; +public: + EsploraSyncClient(const EsploraSyncClient&) = delete; + EsploraSyncClient(EsploraSyncClient&& o) : self(o.self) { memset(&o, 0, sizeof(EsploraSyncClient)); } + EsploraSyncClient(LDKEsploraSyncClient&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKEsploraSyncClient)); } + operator LDKEsploraSyncClient() && { LDKEsploraSyncClient res = self; memset(&self, 0, sizeof(LDKEsploraSyncClient)); return res; } + ~EsploraSyncClient() { EsploraSyncClient_free(self); } + EsploraSyncClient& operator=(EsploraSyncClient&& o) { EsploraSyncClient_free(self); self = o.self; memset(&o, 0, sizeof(EsploraSyncClient)); return *this; } + LDKEsploraSyncClient* operator &() { return &self; } + LDKEsploraSyncClient* operator ->() { return &self; } + const LDKEsploraSyncClient* operator &() const { return &self; } + const LDKEsploraSyncClient* operator ->() const { return &self; } +}; class Bolt11ParseError { private: LDKBolt11ParseError self; @@ -6767,6 +6803,20 @@ public: const LDKFilesystemStore* operator &() const { return &self; } const LDKFilesystemStore* operator ->() const { return &self; } }; +class TxSyncError { +private: + LDKTxSyncError self; +public: + TxSyncError(const TxSyncError&) = delete; + TxSyncError(TxSyncError&& o) : self(o.self) { memset(&o, 0, sizeof(TxSyncError)); } + TxSyncError(LDKTxSyncError&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKTxSyncError)); } + operator LDKTxSyncError() && { LDKTxSyncError res = self; memset(&self, 0, sizeof(LDKTxSyncError)); return res; } + TxSyncError& operator=(TxSyncError&& o) { self = o.self; memset(&o, 0, sizeof(TxSyncError)); return *this; } + LDKTxSyncError* operator &() { return &self; } + LDKTxSyncError* operator ->() { return &self; } + const LDKTxSyncError* operator &() const { return &self; } + const LDKTxSyncError* operator ->() const { return &self; } +}; class NextMessageHop { private: LDKNextMessageHop self; @@ -7470,6 +7520,21 @@ public: const LDKCResult_GossipTimestampFilterDecodeErrorZ* operator &() const { return &self; } const LDKCResult_GossipTimestampFilterDecodeErrorZ* operator ->() const { return &self; } }; +class CVec_ConfirmZ { +private: + LDKCVec_ConfirmZ self; +public: + CVec_ConfirmZ(const CVec_ConfirmZ&) = delete; + CVec_ConfirmZ(CVec_ConfirmZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_ConfirmZ)); } + CVec_ConfirmZ(LDKCVec_ConfirmZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_ConfirmZ)); } + operator LDKCVec_ConfirmZ() && { LDKCVec_ConfirmZ res = self; memset(&self, 0, sizeof(LDKCVec_ConfirmZ)); return res; } + ~CVec_ConfirmZ() { CVec_ConfirmZ_free(self); } + CVec_ConfirmZ& operator=(CVec_ConfirmZ&& o) { CVec_ConfirmZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_ConfirmZ)); return *this; } + LDKCVec_ConfirmZ* operator &() { return &self; } + LDKCVec_ConfirmZ* operator ->() { return &self; } + const LDKCVec_ConfirmZ* operator &() const { return &self; } + const LDKCVec_ConfirmZ* operator ->() const { return &self; } +}; class CResult_RouteHintDecodeErrorZ { private: LDKCResult_RouteHintDecodeErrorZ self; @@ -9180,6 +9245,21 @@ public: const LDKCVec_C2Tuple_ThirtyTwoBytesCVec_C2Tuple_u32CVec_u8ZZZZZ* operator &() const { return &self; } const LDKCVec_C2Tuple_ThirtyTwoBytesCVec_C2Tuple_u32CVec_u8ZZZZZ* operator ->() const { return &self; } }; +class CResult_NoneTxSyncErrorZ { +private: + LDKCResult_NoneTxSyncErrorZ self; +public: + CResult_NoneTxSyncErrorZ(const CResult_NoneTxSyncErrorZ&) = delete; + CResult_NoneTxSyncErrorZ(CResult_NoneTxSyncErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NoneTxSyncErrorZ)); } + CResult_NoneTxSyncErrorZ(LDKCResult_NoneTxSyncErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NoneTxSyncErrorZ)); } + operator LDKCResult_NoneTxSyncErrorZ() && { LDKCResult_NoneTxSyncErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_NoneTxSyncErrorZ)); return res; } + ~CResult_NoneTxSyncErrorZ() { CResult_NoneTxSyncErrorZ_free(self); } + CResult_NoneTxSyncErrorZ& operator=(CResult_NoneTxSyncErrorZ&& o) { CResult_NoneTxSyncErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NoneTxSyncErrorZ)); return *this; } + LDKCResult_NoneTxSyncErrorZ* operator &() { return &self; } + LDKCResult_NoneTxSyncErrorZ* operator ->() { return &self; } + const LDKCResult_NoneTxSyncErrorZ* operator &() const { return &self; } + const LDKCResult_NoneTxSyncErrorZ* operator ->() const { return &self; } +}; class CResult_DescriptionCreationErrorZ { private: LDKCResult_DescriptionCreationErrorZ self; @@ -9195,21 +9275,6 @@ public: const LDKCResult_DescriptionCreationErrorZ* operator &() const { return &self; } const LDKCResult_DescriptionCreationErrorZ* operator ->() const { return &self; } }; -class CResult_PaymentRelayDecodeErrorZ { -private: - LDKCResult_PaymentRelayDecodeErrorZ self; -public: - CResult_PaymentRelayDecodeErrorZ(const CResult_PaymentRelayDecodeErrorZ&) = delete; - CResult_PaymentRelayDecodeErrorZ(CResult_PaymentRelayDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_PaymentRelayDecodeErrorZ)); } - CResult_PaymentRelayDecodeErrorZ(LDKCResult_PaymentRelayDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_PaymentRelayDecodeErrorZ)); } - operator LDKCResult_PaymentRelayDecodeErrorZ() && { LDKCResult_PaymentRelayDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_PaymentRelayDecodeErrorZ)); return res; } - ~CResult_PaymentRelayDecodeErrorZ() { CResult_PaymentRelayDecodeErrorZ_free(self); } - CResult_PaymentRelayDecodeErrorZ& operator=(CResult_PaymentRelayDecodeErrorZ&& o) { CResult_PaymentRelayDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_PaymentRelayDecodeErrorZ)); return *this; } - LDKCResult_PaymentRelayDecodeErrorZ* operator &() { return &self; } - LDKCResult_PaymentRelayDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_PaymentRelayDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_PaymentRelayDecodeErrorZ* operator ->() const { return &self; } -}; class CResult_QueryShortChannelIdsDecodeErrorZ { private: LDKCResult_QueryShortChannelIdsDecodeErrorZ self; @@ -9255,6 +9320,21 @@ public: const LDKCResult_UpdateAddHTLCDecodeErrorZ* operator &() const { return &self; } const LDKCResult_UpdateAddHTLCDecodeErrorZ* operator ->() const { return &self; } }; +class CResult_PaymentRelayDecodeErrorZ { +private: + LDKCResult_PaymentRelayDecodeErrorZ self; +public: + CResult_PaymentRelayDecodeErrorZ(const CResult_PaymentRelayDecodeErrorZ&) = delete; + CResult_PaymentRelayDecodeErrorZ(CResult_PaymentRelayDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_PaymentRelayDecodeErrorZ)); } + CResult_PaymentRelayDecodeErrorZ(LDKCResult_PaymentRelayDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_PaymentRelayDecodeErrorZ)); } + operator LDKCResult_PaymentRelayDecodeErrorZ() && { LDKCResult_PaymentRelayDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_PaymentRelayDecodeErrorZ)); return res; } + ~CResult_PaymentRelayDecodeErrorZ() { CResult_PaymentRelayDecodeErrorZ_free(self); } + CResult_PaymentRelayDecodeErrorZ& operator=(CResult_PaymentRelayDecodeErrorZ&& o) { CResult_PaymentRelayDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_PaymentRelayDecodeErrorZ)); return *this; } + LDKCResult_PaymentRelayDecodeErrorZ* operator &() { return &self; } + LDKCResult_PaymentRelayDecodeErrorZ* operator ->() { return &self; } + const LDKCResult_PaymentRelayDecodeErrorZ* operator &() const { return &self; } + const LDKCResult_PaymentRelayDecodeErrorZ* operator ->() const { return &self; } +}; class COption_OutboundHTLCStateDetailsZ { private: LDKCOption_OutboundHTLCStateDetailsZ self; @@ -10545,20 +10625,20 @@ public: const LDKCResult_ShutdownScriptDecodeErrorZ* operator &() const { return &self; } const LDKCResult_ShutdownScriptDecodeErrorZ* operator ->() const { return &self; } }; -class CResult_SiPrefixBolt11ParseErrorZ { +class CResult_ElectrumSyncClientTxSyncErrorZ { private: - LDKCResult_SiPrefixBolt11ParseErrorZ self; + LDKCResult_ElectrumSyncClientTxSyncErrorZ self; public: - CResult_SiPrefixBolt11ParseErrorZ(const CResult_SiPrefixBolt11ParseErrorZ&) = delete; - CResult_SiPrefixBolt11ParseErrorZ(CResult_SiPrefixBolt11ParseErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_SiPrefixBolt11ParseErrorZ)); } - CResult_SiPrefixBolt11ParseErrorZ(LDKCResult_SiPrefixBolt11ParseErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_SiPrefixBolt11ParseErrorZ)); } - operator LDKCResult_SiPrefixBolt11ParseErrorZ() && { LDKCResult_SiPrefixBolt11ParseErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_SiPrefixBolt11ParseErrorZ)); return res; } - ~CResult_SiPrefixBolt11ParseErrorZ() { CResult_SiPrefixBolt11ParseErrorZ_free(self); } - CResult_SiPrefixBolt11ParseErrorZ& operator=(CResult_SiPrefixBolt11ParseErrorZ&& o) { CResult_SiPrefixBolt11ParseErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_SiPrefixBolt11ParseErrorZ)); return *this; } - LDKCResult_SiPrefixBolt11ParseErrorZ* operator &() { return &self; } - LDKCResult_SiPrefixBolt11ParseErrorZ* operator ->() { return &self; } - const LDKCResult_SiPrefixBolt11ParseErrorZ* operator &() const { return &self; } - const LDKCResult_SiPrefixBolt11ParseErrorZ* operator ->() const { return &self; } + CResult_ElectrumSyncClientTxSyncErrorZ(const CResult_ElectrumSyncClientTxSyncErrorZ&) = delete; + CResult_ElectrumSyncClientTxSyncErrorZ(CResult_ElectrumSyncClientTxSyncErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ElectrumSyncClientTxSyncErrorZ)); } + CResult_ElectrumSyncClientTxSyncErrorZ(LDKCResult_ElectrumSyncClientTxSyncErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ElectrumSyncClientTxSyncErrorZ)); } + operator LDKCResult_ElectrumSyncClientTxSyncErrorZ() && { LDKCResult_ElectrumSyncClientTxSyncErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ElectrumSyncClientTxSyncErrorZ)); return res; } + ~CResult_ElectrumSyncClientTxSyncErrorZ() { CResult_ElectrumSyncClientTxSyncErrorZ_free(self); } + CResult_ElectrumSyncClientTxSyncErrorZ& operator=(CResult_ElectrumSyncClientTxSyncErrorZ&& o) { CResult_ElectrumSyncClientTxSyncErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_ElectrumSyncClientTxSyncErrorZ)); return *this; } + LDKCResult_ElectrumSyncClientTxSyncErrorZ* operator &() { return &self; } + LDKCResult_ElectrumSyncClientTxSyncErrorZ* operator ->() { return &self; } + const LDKCResult_ElectrumSyncClientTxSyncErrorZ* operator &() const { return &self; } + const LDKCResult_ElectrumSyncClientTxSyncErrorZ* operator ->() const { return &self; } }; class C2Tuple_usizeTransactionZ { private: @@ -10725,20 +10805,20 @@ public: const LDKCResult_TxCreationKeysDecodeErrorZ* operator &() const { return &self; } const LDKCResult_TxCreationKeysDecodeErrorZ* operator ->() const { return &self; } }; -class CResult_BlindedPathDecodeErrorZ { +class CResult_SiPrefixBolt11ParseErrorZ { private: - LDKCResult_BlindedPathDecodeErrorZ self; + LDKCResult_SiPrefixBolt11ParseErrorZ self; public: - CResult_BlindedPathDecodeErrorZ(const CResult_BlindedPathDecodeErrorZ&) = delete; - CResult_BlindedPathDecodeErrorZ(CResult_BlindedPathDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_BlindedPathDecodeErrorZ)); } - CResult_BlindedPathDecodeErrorZ(LDKCResult_BlindedPathDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_BlindedPathDecodeErrorZ)); } - operator LDKCResult_BlindedPathDecodeErrorZ() && { LDKCResult_BlindedPathDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_BlindedPathDecodeErrorZ)); return res; } - ~CResult_BlindedPathDecodeErrorZ() { CResult_BlindedPathDecodeErrorZ_free(self); } - CResult_BlindedPathDecodeErrorZ& operator=(CResult_BlindedPathDecodeErrorZ&& o) { CResult_BlindedPathDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_BlindedPathDecodeErrorZ)); return *this; } - LDKCResult_BlindedPathDecodeErrorZ* operator &() { return &self; } - LDKCResult_BlindedPathDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_BlindedPathDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_BlindedPathDecodeErrorZ* operator ->() const { return &self; } + CResult_SiPrefixBolt11ParseErrorZ(const CResult_SiPrefixBolt11ParseErrorZ&) = delete; + CResult_SiPrefixBolt11ParseErrorZ(CResult_SiPrefixBolt11ParseErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_SiPrefixBolt11ParseErrorZ)); } + CResult_SiPrefixBolt11ParseErrorZ(LDKCResult_SiPrefixBolt11ParseErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_SiPrefixBolt11ParseErrorZ)); } + operator LDKCResult_SiPrefixBolt11ParseErrorZ() && { LDKCResult_SiPrefixBolt11ParseErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_SiPrefixBolt11ParseErrorZ)); return res; } + ~CResult_SiPrefixBolt11ParseErrorZ() { CResult_SiPrefixBolt11ParseErrorZ_free(self); } + CResult_SiPrefixBolt11ParseErrorZ& operator=(CResult_SiPrefixBolt11ParseErrorZ&& o) { CResult_SiPrefixBolt11ParseErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_SiPrefixBolt11ParseErrorZ)); return *this; } + LDKCResult_SiPrefixBolt11ParseErrorZ* operator &() { return &self; } + LDKCResult_SiPrefixBolt11ParseErrorZ* operator ->() { return &self; } + const LDKCResult_SiPrefixBolt11ParseErrorZ* operator &() const { return &self; } + const LDKCResult_SiPrefixBolt11ParseErrorZ* operator ->() const { return &self; } }; class CResult_RefundBolt12SemanticErrorZ { private: @@ -10875,6 +10955,21 @@ public: const LDKC2Tuple_Z* operator &() const { return &self; } const LDKC2Tuple_Z* operator ->() const { return &self; } }; +class CResult_BlindedPathDecodeErrorZ { +private: + LDKCResult_BlindedPathDecodeErrorZ self; +public: + CResult_BlindedPathDecodeErrorZ(const CResult_BlindedPathDecodeErrorZ&) = delete; + CResult_BlindedPathDecodeErrorZ(CResult_BlindedPathDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_BlindedPathDecodeErrorZ)); } + CResult_BlindedPathDecodeErrorZ(LDKCResult_BlindedPathDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_BlindedPathDecodeErrorZ)); } + operator LDKCResult_BlindedPathDecodeErrorZ() && { LDKCResult_BlindedPathDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_BlindedPathDecodeErrorZ)); return res; } + ~CResult_BlindedPathDecodeErrorZ() { CResult_BlindedPathDecodeErrorZ_free(self); } + CResult_BlindedPathDecodeErrorZ& operator=(CResult_BlindedPathDecodeErrorZ&& o) { CResult_BlindedPathDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_BlindedPathDecodeErrorZ)); return *this; } + LDKCResult_BlindedPathDecodeErrorZ* operator &() { return &self; } + LDKCResult_BlindedPathDecodeErrorZ* operator ->() { return &self; } + const LDKCResult_BlindedPathDecodeErrorZ* operator &() const { return &self; } + const LDKCResult_BlindedPathDecodeErrorZ* operator ->() const { return &self; } +}; class CResult_InboundHTLCDetailsDecodeErrorZ { private: LDKCResult_InboundHTLCDetailsDecodeErrorZ self; diff --git a/lightning-c-bindings/src/c_types/derived.rs b/lightning-c-bindings/src/c_types/derived.rs index c15c8d8..646af2a 100644 --- a/lightning-c-bindings/src/c_types/derived.rs +++ b/lightning-c-bindings/src/c_types/derived.rs @@ -24030,6 +24030,198 @@ impl Clone for CResult_COption_EventZDecodeErrorZ { /// but with all dynamically-allocated buffers duplicated in new buffers. pub extern "C" fn CResult_COption_EventZDecodeErrorZ_clone(orig: &CResult_COption_EventZDecodeErrorZ) -> CResult_COption_EventZDecodeErrorZ { Clone::clone(&orig) } #[repr(C)] +/// The contents of CResult_ElectrumSyncClientTxSyncErrorZ +pub union CResult_ElectrumSyncClientTxSyncErrorZPtr { + /// 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_transaction_sync::electrum::ElectrumSyncClient, + /// 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_transaction_sync::error::TxSyncError, +} +#[repr(C)] +/// A CResult_ElectrumSyncClientTxSyncErrorZ represents the result of a fallible operation, +/// containing a crate::lightning_transaction_sync::electrum::ElectrumSyncClient on success and a crate::lightning_transaction_sync::error::TxSyncError on failure. +/// `result_ok` indicates the overall state, and the contents are provided via `contents`. +pub struct CResult_ElectrumSyncClientTxSyncErrorZ { + /// The contents of this CResult_ElectrumSyncClientTxSyncErrorZ, accessible via either + /// `err` or `result` depending on the state of `result_ok`. + pub contents: CResult_ElectrumSyncClientTxSyncErrorZPtr, + /// Whether this CResult_ElectrumSyncClientTxSyncErrorZ represents a success state. + pub result_ok: bool, +} +#[no_mangle] +/// Creates a new CResult_ElectrumSyncClientTxSyncErrorZ in the success state. +pub extern "C" fn CResult_ElectrumSyncClientTxSyncErrorZ_ok(o: crate::lightning_transaction_sync::electrum::ElectrumSyncClient) -> CResult_ElectrumSyncClientTxSyncErrorZ { + CResult_ElectrumSyncClientTxSyncErrorZ { + contents: CResult_ElectrumSyncClientTxSyncErrorZPtr { + result: Box::into_raw(Box::new(o)), + }, + result_ok: true, + } +} +#[no_mangle] +/// Creates a new CResult_ElectrumSyncClientTxSyncErrorZ in the error state. +pub extern "C" fn CResult_ElectrumSyncClientTxSyncErrorZ_err(e: crate::lightning_transaction_sync::error::TxSyncError) -> CResult_ElectrumSyncClientTxSyncErrorZ { + CResult_ElectrumSyncClientTxSyncErrorZ { + contents: CResult_ElectrumSyncClientTxSyncErrorZPtr { + 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_ElectrumSyncClientTxSyncErrorZ_is_ok(o: &CResult_ElectrumSyncClientTxSyncErrorZ) -> bool { + o.result_ok +} +#[no_mangle] +/// Frees any resources used by the CResult_ElectrumSyncClientTxSyncErrorZ. +pub extern "C" fn CResult_ElectrumSyncClientTxSyncErrorZ_free(_res: CResult_ElectrumSyncClientTxSyncErrorZ) { } +impl Drop for CResult_ElectrumSyncClientTxSyncErrorZ { + 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_ElectrumSyncClientTxSyncErrorZ { + fn from(mut o: crate::c_types::CResultTempl) -> Self { + let contents = if o.result_ok { + let result = unsafe { o.contents.result }; + unsafe { o.contents.result = core::ptr::null_mut() }; + CResult_ElectrumSyncClientTxSyncErrorZPtr { result } + } else { + let err = unsafe { o.contents.err }; + unsafe { o.contents.err = core::ptr::null_mut(); } + CResult_ElectrumSyncClientTxSyncErrorZPtr { err } + }; + Self { + contents, + result_ok: o.result_ok, + } + } +} +#[repr(C)] +/// A dynamically-allocated array of crate::lightning::chain::Confirms of arbitrary size. +/// This corresponds to std::vector in C++ +pub struct CVec_ConfirmZ { + /// The elements in the array. + /// If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc(). + pub data: *mut crate::lightning::chain::Confirm, + /// The number of elements pointed to by `data`. + pub datalen: usize +} +impl CVec_ConfirmZ { + #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { + if self.datalen == 0 { return Vec::new(); } + let ret = unsafe { Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }.into(); + self.data = core::ptr::null_mut(); + self.datalen = 0; + ret + } + #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::lightning::chain::Confirm] { + unsafe { core::slice::from_raw_parts_mut(self.data, self.datalen) } + } +} +impl From> for CVec_ConfirmZ { + fn from(v: Vec) -> Self { + let datalen = v.len(); + let data = Box::into_raw(v.into_boxed_slice()); + Self { datalen, data: unsafe { (*data).as_mut_ptr() } } + } +} +#[no_mangle] +/// Frees the buffer pointed to by `data` if `datalen` is non-0. +pub extern "C" fn CVec_ConfirmZ_free(_res: CVec_ConfirmZ) { } +impl Drop for CVec_ConfirmZ { + fn drop(&mut self) { + if self.datalen == 0 { return; } + let _ = unsafe { Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }; + } +} +#[repr(C)] +/// The contents of CResult_NoneTxSyncErrorZ +pub union CResult_NoneTxSyncErrorZPtr { + /// Note that this value is always NULL, as there are no contents in the OK variant + pub result: *mut core::ffi::c_void, + /// A pointer to the contents in the error state. + /// Reading from this pointer when `result_ok` is set is undefined. + pub err: *mut crate::lightning_transaction_sync::error::TxSyncError, +} +#[repr(C)] +/// A CResult_NoneTxSyncErrorZ represents the result of a fallible operation, +/// containing a () on success and a crate::lightning_transaction_sync::error::TxSyncError on failure. +/// `result_ok` indicates the overall state, and the contents are provided via `contents`. +pub struct CResult_NoneTxSyncErrorZ { + /// The contents of this CResult_NoneTxSyncErrorZ, accessible via either + /// `err` or `result` depending on the state of `result_ok`. + pub contents: CResult_NoneTxSyncErrorZPtr, + /// Whether this CResult_NoneTxSyncErrorZ represents a success state. + pub result_ok: bool, +} +#[no_mangle] +/// Creates a new CResult_NoneTxSyncErrorZ in the success state. +pub extern "C" fn CResult_NoneTxSyncErrorZ_ok() -> CResult_NoneTxSyncErrorZ { + CResult_NoneTxSyncErrorZ { + contents: CResult_NoneTxSyncErrorZPtr { + result: core::ptr::null_mut(), + }, + result_ok: true, + } +} +#[no_mangle] +/// Creates a new CResult_NoneTxSyncErrorZ in the error state. +pub extern "C" fn CResult_NoneTxSyncErrorZ_err(e: crate::lightning_transaction_sync::error::TxSyncError) -> CResult_NoneTxSyncErrorZ { + CResult_NoneTxSyncErrorZ { + contents: CResult_NoneTxSyncErrorZPtr { + 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_NoneTxSyncErrorZ_is_ok(o: &CResult_NoneTxSyncErrorZ) -> bool { + o.result_ok +} +#[no_mangle] +/// Frees any resources used by the CResult_NoneTxSyncErrorZ. +pub extern "C" fn CResult_NoneTxSyncErrorZ_free(_res: CResult_NoneTxSyncErrorZ) { } +impl Drop for CResult_NoneTxSyncErrorZ { + 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_NoneTxSyncErrorZ { + fn from(mut o: crate::c_types::CResultTempl<(), crate::lightning_transaction_sync::error::TxSyncError>) -> Self { + let contents = if o.result_ok { + let _ = unsafe { Box::from_raw(o.contents.result) }; + o.contents.result = core::ptr::null_mut(); + CResult_NoneTxSyncErrorZPtr { result: core::ptr::null_mut() } + } else { + let err = unsafe { o.contents.err }; + unsafe { o.contents.err = core::ptr::null_mut(); } + CResult_NoneTxSyncErrorZPtr { err } + }; + Self { + contents, + result_ok: o.result_ok, + } + } +} +#[repr(C)] /// The contents of CResult_SiPrefixBolt11ParseErrorZ pub union CResult_SiPrefixBolt11ParseErrorZPtr { /// A pointer to the contents in the success state. diff --git a/lightning-c-bindings/src/lightning_transaction_sync/electrum.rs b/lightning-c-bindings/src/lightning_transaction_sync/electrum.rs new file mode 100644 index 0000000..9870b54 --- /dev/null +++ b/lightning-c-bindings/src/lightning_transaction_sync/electrum.rs @@ -0,0 +1,139 @@ +// 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. + +//! Chain sync using the electrum protocol + +use alloc::str::FromStr; +use alloc::string::String; +use core::ffi::c_void; +use core::convert::Infallible; +use bitcoin::hashes::Hash; +use crate::c_types::*; +#[cfg(feature="no-std")] +use alloc::{vec::Vec, boxed::Box}; + + +use lightning_transaction_sync::electrum::ElectrumSyncClient as nativeElectrumSyncClientImport; +pub(crate) type nativeElectrumSyncClient = nativeElectrumSyncClientImport; + +/// Synchronizes LDK with a given Electrum server. +/// +/// Needs to be registered with a [`ChainMonitor`] via the [`Filter`] interface to be informed of +/// transactions and outputs to monitor for on-chain confirmation, unconfirmation, and +/// reconfirmation. +/// +/// Note that registration via [`Filter`] needs to happen before any calls to +/// [`Watch::watch_channel`] to ensure we get notified of the items to monitor. +/// +/// [`ChainMonitor`]: lightning::chain::chainmonitor::ChainMonitor +/// [`Watch::watch_channel`]: lightning::chain::Watch::watch_channel +/// [`Filter`]: lightning::chain::Filter +#[must_use] +#[repr(C)] +pub struct ElectrumSyncClient { + /// 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 nativeElectrumSyncClient, + /// 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 ElectrumSyncClient { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeElectrumSyncClient>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the ElectrumSyncClient, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn ElectrumSyncClient_free(this_obj: ElectrumSyncClient) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ElectrumSyncClient_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeElectrumSyncClient) }; +} +#[allow(unused)] +impl ElectrumSyncClient { + pub(crate) fn get_native_ref(&self) -> &'static nativeElectrumSyncClient { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeElectrumSyncClient { + 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 nativeElectrumSyncClient { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = core::ptr::null_mut(); + ret + } +} +/// Returns a new [`ElectrumSyncClient`] object. +#[must_use] +#[no_mangle] +pub extern "C" fn ElectrumSyncClient_new(mut server_url: crate::c_types::Str, mut logger: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_ElectrumSyncClientTxSyncErrorZ { + let mut ret = lightning_transaction_sync::electrum::ElectrumSyncClient::new(server_url.into_string(), logger); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_transaction_sync::electrum::ElectrumSyncClient { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_transaction_sync::error::TxSyncError::native_into(e) }).into() }; + local_ret +} + +/// Synchronizes the given `confirmables` via their [`Confirm`] interface implementations. This +/// method should be called regularly to keep LDK up-to-date with current chain data. +/// +/// For example, instances of [`ChannelManager`] and [`ChainMonitor`] can be informed about the +/// newest on-chain activity related to the items previously registered via the [`Filter`] +/// interface. +/// +/// [`Confirm`]: lightning::chain::Confirm +/// [`ChainMonitor`]: lightning::chain::chainmonitor::ChainMonitor +/// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager +/// [`Filter`]: lightning::chain::Filter +#[must_use] +#[no_mangle] +pub extern "C" fn ElectrumSyncClient_sync(this_arg: &crate::lightning_transaction_sync::electrum::ElectrumSyncClient, mut confirmables: crate::c_types::derived::CVec_ConfirmZ) -> crate::c_types::derived::CResult_NoneTxSyncErrorZ { + let mut local_confirmables = Vec::new(); for mut item in confirmables.into_rust().drain(..) { local_confirmables.push( { item }); }; + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.sync(local_confirmables); + 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_transaction_sync::error::TxSyncError::native_into(e) }).into() }; + local_ret +} + +impl From for crate::lightning::chain::Filter { + fn from(obj: nativeElectrumSyncClient) -> Self { + let rust_obj = crate::lightning_transaction_sync::electrum::ElectrumSyncClient { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let mut ret = ElectrumSyncClient_as_Filter(&rust_obj); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); + ret.free = Some(ElectrumSyncClient_free_void); + ret + } +} +/// Constructs a new Filter which calls the relevant methods on this_arg. +/// This copies the `inner` pointer in this_arg and thus the returned Filter must be freed before this_arg is +#[no_mangle] +pub extern "C" fn ElectrumSyncClient_as_Filter(this_arg: &ElectrumSyncClient) -> crate::lightning::chain::Filter { + crate::lightning::chain::Filter { + this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, + free: None, + register_tx: ElectrumSyncClient_Filter_register_tx, + register_output: ElectrumSyncClient_Filter_register_output, + } +} + +extern "C" fn ElectrumSyncClient_Filter_register_tx(this_arg: *const c_void, txid: *const [u8; 32], mut script_pubkey: crate::c_types::u8slice) { + ::register_tx(unsafe { &mut *(this_arg as *mut nativeElectrumSyncClient) }, &::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap(), ::bitcoin::blockdata::script::Script::from_bytes(script_pubkey.to_slice())) +} +extern "C" fn ElectrumSyncClient_Filter_register_output(this_arg: *const c_void, mut output: crate::lightning::chain::WatchedOutput) { + ::register_output(unsafe { &mut *(this_arg as *mut nativeElectrumSyncClient) }, *unsafe { Box::from_raw(output.take_inner()) }) +} + diff --git a/lightning-c-bindings/src/lightning_transaction_sync/error.rs b/lightning-c-bindings/src/lightning_transaction_sync/error.rs new file mode 100644 index 0000000..f8480b6 --- /dev/null +++ b/lightning-c-bindings/src/lightning_transaction_sync/error.rs @@ -0,0 +1,79 @@ +// 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. + +//! Common error types + +use alloc::str::FromStr; +use alloc::string::String; +use core::ffi::c_void; +use core::convert::Infallible; +use bitcoin::hashes::Hash; +use crate::c_types::*; +#[cfg(feature="no-std")] +use alloc::{vec::Vec, boxed::Box}; + +/// An error that possibly needs to be handled by the user. +#[derive(Clone)] +#[must_use] +#[repr(C)] +pub enum TxSyncError { + /// A transaction sync failed and needs to be retried eventually. + Failed, +} +use lightning_transaction_sync::error::TxSyncError as TxSyncErrorImport; +pub(crate) type nativeTxSyncError = TxSyncErrorImport; + +impl TxSyncError { + #[allow(unused)] + pub(crate) fn to_native(&self) -> nativeTxSyncError { + match self { + TxSyncError::Failed => nativeTxSyncError::Failed, + } + } + #[allow(unused)] + pub(crate) fn into_native(self) -> nativeTxSyncError { + match self { + TxSyncError::Failed => nativeTxSyncError::Failed, + } + } + #[allow(unused)] + pub(crate) fn from_native(native: &TxSyncErrorImport) -> Self { + let native = unsafe { &*(native as *const _ as *const c_void as *const nativeTxSyncError) }; + match native { + nativeTxSyncError::Failed => TxSyncError::Failed, + } + } + #[allow(unused)] + pub(crate) fn native_into(native: nativeTxSyncError) -> Self { + match native { + nativeTxSyncError::Failed => TxSyncError::Failed, + } + } +} +/// Creates a copy of the TxSyncError +#[no_mangle] +pub extern "C" fn TxSyncError_clone(orig: &TxSyncError) -> TxSyncError { + orig.clone() +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn TxSyncError_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const TxSyncError)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn TxSyncError_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut TxSyncError) }; +} +#[no_mangle] +/// Utility method to constructs a new Failed-variant TxSyncError +pub extern "C" fn TxSyncError_failed() -> TxSyncError { + TxSyncError::Failed} +/// Get a string which allows debug introspection of a TxSyncError object +pub extern "C" fn TxSyncError_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning_transaction_sync::error::TxSyncError }).into()} diff --git a/lightning-c-bindings/src/lightning_transaction_sync/esplora.rs b/lightning-c-bindings/src/lightning_transaction_sync/esplora.rs new file mode 100644 index 0000000..9b703d3 --- /dev/null +++ b/lightning-c-bindings/src/lightning_transaction_sync/esplora.rs @@ -0,0 +1,142 @@ +// 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. + +//! Chain sync using the Esplora API + +use alloc::str::FromStr; +use alloc::string::String; +use core::ffi::c_void; +use core::convert::Infallible; +use bitcoin::hashes::Hash; +use crate::c_types::*; +#[cfg(feature="no-std")] +use alloc::{vec::Vec, boxed::Box}; + + +use lightning_transaction_sync::esplora::EsploraSyncClient as nativeEsploraSyncClientImport; +pub(crate) type nativeEsploraSyncClient = nativeEsploraSyncClientImport; + +/// Synchronizes LDK with a given [`Esplora`] server. +/// +/// Needs to be registered with a [`ChainMonitor`] via the [`Filter`] interface to be informed of +/// transactions and outputs to monitor for on-chain confirmation, unconfirmation, and +/// reconfirmation. +/// +/// Note that registration via [`Filter`] needs to happen before any calls to +/// [`Watch::watch_channel`] to ensure we get notified of the items to monitor. +/// +/// This uses and exposes either a blocking or async client variant dependent on whether the +/// `esplora-blocking` or the `esplora-async` feature is enabled. +/// +/// [`Esplora`]: https://github.com/Blockstream/electrs +/// [`ChainMonitor`]: lightning::chain::chainmonitor::ChainMonitor +/// [`Watch::watch_channel`]: lightning::chain::Watch::watch_channel +/// [`Filter`]: lightning::chain::Filter +#[must_use] +#[repr(C)] +pub struct EsploraSyncClient { + /// 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 nativeEsploraSyncClient, + /// 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 EsploraSyncClient { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeEsploraSyncClient>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the EsploraSyncClient, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn EsploraSyncClient_free(this_obj: EsploraSyncClient) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn EsploraSyncClient_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeEsploraSyncClient) }; +} +#[allow(unused)] +impl EsploraSyncClient { + pub(crate) fn get_native_ref(&self) -> &'static nativeEsploraSyncClient { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeEsploraSyncClient { + 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 nativeEsploraSyncClient { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = core::ptr::null_mut(); + ret + } +} +/// Returns a new [`EsploraSyncClient`] object. +#[must_use] +#[no_mangle] +pub extern "C" fn EsploraSyncClient_new(mut server_url: crate::c_types::Str, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning_transaction_sync::esplora::EsploraSyncClient { + let mut ret = lightning_transaction_sync::esplora::EsploraSyncClient::new(server_url.into_string(), logger); + crate::lightning_transaction_sync::esplora::EsploraSyncClient { inner: ObjOps::heap_alloc(ret), is_owned: true } +} + +/// Synchronizes the given `confirmables` via their [`Confirm`] interface implementations. This +/// method should be called regularly to keep LDK up-to-date with current chain data. +/// +/// For example, instances of [`ChannelManager`] and [`ChainMonitor`] can be informed about the +/// newest on-chain activity related to the items previously registered via the [`Filter`] +/// interface. +/// +/// [`Confirm`]: lightning::chain::Confirm +/// [`ChainMonitor`]: lightning::chain::chainmonitor::ChainMonitor +/// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager +/// [`Filter`]: lightning::chain::Filter +#[must_use] +#[no_mangle] +pub extern "C" fn EsploraSyncClient_sync(this_arg: &crate::lightning_transaction_sync::esplora::EsploraSyncClient, mut confirmables: crate::c_types::derived::CVec_ConfirmZ) -> crate::c_types::derived::CResult_NoneTxSyncErrorZ { + let mut local_confirmables = Vec::new(); for mut item in confirmables.into_rust().drain(..) { local_confirmables.push( { item }); }; + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.sync(local_confirmables); + 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_transaction_sync::error::TxSyncError::native_into(e) }).into() }; + local_ret +} + +impl From for crate::lightning::chain::Filter { + fn from(obj: nativeEsploraSyncClient) -> Self { + let rust_obj = crate::lightning_transaction_sync::esplora::EsploraSyncClient { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let mut ret = EsploraSyncClient_as_Filter(&rust_obj); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); + ret.free = Some(EsploraSyncClient_free_void); + ret + } +} +/// Constructs a new Filter which calls the relevant methods on this_arg. +/// This copies the `inner` pointer in this_arg and thus the returned Filter must be freed before this_arg is +#[no_mangle] +pub extern "C" fn EsploraSyncClient_as_Filter(this_arg: &EsploraSyncClient) -> crate::lightning::chain::Filter { + crate::lightning::chain::Filter { + this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, + free: None, + register_tx: EsploraSyncClient_Filter_register_tx, + register_output: EsploraSyncClient_Filter_register_output, + } +} + +extern "C" fn EsploraSyncClient_Filter_register_tx(this_arg: *const c_void, txid: *const [u8; 32], mut script_pubkey: crate::c_types::u8slice) { + ::register_tx(unsafe { &mut *(this_arg as *mut nativeEsploraSyncClient) }, &::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap(), ::bitcoin::blockdata::script::Script::from_bytes(script_pubkey.to_slice())) +} +extern "C" fn EsploraSyncClient_Filter_register_output(this_arg: *const c_void, mut output: crate::lightning::chain::WatchedOutput) { + ::register_output(unsafe { &mut *(this_arg as *mut nativeEsploraSyncClient) }, *unsafe { Box::from_raw(output.take_inner()) }) +} + diff --git a/lightning-c-bindings/src/lightning_transaction_sync/mod.rs b/lightning-c-bindings/src/lightning_transaction_sync/mod.rs new file mode 100644 index 0000000..6bc590b --- /dev/null +++ b/lightning-c-bindings/src/lightning_transaction_sync/mod.rs @@ -0,0 +1,92 @@ +// 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. + +//! Provides utilities for syncing LDK via the transaction-based [`Confirm`] interface. +//! +//! The provided synchronization clients need to be registered with a [`ChainMonitor`] via the +//! [`Filter`] interface. Then, the respective `fn sync` needs to be called with the [`Confirm`] +//! implementations to be synchronized, i.e., usually instances of [`ChannelManager`] and +//! [`ChainMonitor`]. +//! +//! ## Features and Backend Support +//! +//!- `esplora-blocking` enables syncing against an Esplora backend based on a blocking client. +//!- `esplora-async` enables syncing against an Esplora backend based on an async client. +//!- `esplora-async-https` enables the async Esplora client with support for HTTPS. +//! +//! ## Version Compatibility +//! +//! Currently this crate is compatible with LDK version 0.0.114 and above using channels which were +//! created on LDK version 0.0.113 and above. +//! +//! ## Usage Example: +//! +//! ```ignore +//! let tx_sync = Arc::new(EsploraSyncClient::new( +//! \tesplora_server_url, +//! \tArc::clone(&some_logger), +//! )); +//! +//! let chain_monitor = Arc::new(ChainMonitor::new( +//! \tSome(Arc::clone(&tx_sync)), +//! \tArc::clone(&some_broadcaster), +//! \tArc::clone(&some_logger), +//! \tArc::clone(&some_fee_estimator), +//! \tArc::clone(&some_persister), +//! )); +//! +//! let channel_manager = Arc::new(ChannelManager::new( +//! \tArc::clone(&some_fee_estimator), +//! \tArc::clone(&chain_monitor), +//! \tArc::clone(&some_broadcaster), +//! \tArc::clone(&some_router), +//! \tArc::clone(&some_logger), +//! \tArc::clone(&some_entropy_source), +//! \tArc::clone(&some_node_signer), +//! \tArc::clone(&some_signer_provider), +//! \tuser_config, +//! \tchain_params, +//! )); +//! +//! let confirmables = vec![ +//! \t&*channel_manager as &(dyn Confirm + Sync + Send), +//! \t&*chain_monitor as &(dyn Confirm + Sync + Send), +//! ]; +//! +//! tx_sync.sync(confirmables).unwrap(); +//! ``` +//! +//! [`Confirm`]: lightning::chain::Confirm +//! [`Filter`]: lightning::chain::Filter +//! [`ChainMonitor`]: lightning::chain::chainmonitor::ChainMonitor +//! [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager + +use alloc::str::FromStr; +use alloc::string::String; +use core::ffi::c_void; +use core::convert::Infallible; +use bitcoin::hashes::Hash; +use crate::c_types::*; +#[cfg(feature="no-std")] +use alloc::{vec::Vec, boxed::Box}; + +pub mod esplora; +pub mod electrum; +pub mod error; +mod common { + +use alloc::str::FromStr; +use alloc::string::String; +use core::ffi::c_void; +use core::convert::Infallible; +use bitcoin::hashes::Hash; +use crate::c_types::*; +#[cfg(feature="no-std")] +use alloc::{vec::Vec, boxed::Box}; + +} -- 2.30.2