X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-c-bindings;a=blobdiff_plain;f=lightning-c-bindings%2Finclude%2Flightning.h;h=4ae3d0bfd5822f6d769f70199ac4182e783fb88d;hp=c23de7ed40aaae73e34fbb65ea908d053f5a9ef9;hb=c35ef17b94a8f4e9e019a2b63e0ed22110671b9c;hpb=d9866e870bbe080412dc70b1421e28a756e4407e diff --git a/lightning-c-bindings/include/lightning.h b/lightning-c-bindings/include/lightning.h index c23de7e..4ae3d0b 100644 --- a/lightning-c-bindings/include/lightning.h +++ b/lightning-c-bindings/include/lightning.h @@ -1,4 +1,5 @@ -/* Text to put at the beginning of the generated file. Probably a license. */ +#ifndef LDK_C_BINDINGS_H +#define LDK_C_BINDINGS_H /* Generated with cbindgen:0.16.0 */ @@ -120,6 +121,34 @@ typedef enum LDKConfirmationTarget { LDKConfirmationTarget_Sentinel, } LDKConfirmationTarget; +/** + * Represents an IO Error. Note that some information is lost in the conversion from Rust. + */ +typedef enum LDKIOError { + LDKIOError_NotFound, + LDKIOError_PermissionDenied, + LDKIOError_ConnectionRefused, + LDKIOError_ConnectionReset, + LDKIOError_ConnectionAborted, + LDKIOError_NotConnected, + LDKIOError_AddrInUse, + LDKIOError_AddrNotAvailable, + LDKIOError_BrokenPipe, + LDKIOError_AlreadyExists, + LDKIOError_WouldBlock, + LDKIOError_InvalidInput, + LDKIOError_InvalidData, + LDKIOError_TimedOut, + LDKIOError_WriteZero, + LDKIOError_Interrupted, + LDKIOError_Other, + LDKIOError_UnexpectedEof, + /** + * Must be last for serialization purposes + */ + LDKIOError_Sentinel, +} LDKIOError; + /** * An enum representing the available verbosity levels of the logger. */ @@ -1125,6 +1154,39 @@ typedef struct LDKCResult_CVec_SignatureZNoneZ { bool result_ok; } LDKCResult_CVec_SignatureZNoneZ; +/** + * The contents of CResult_StringErrorZ + */ +typedef union LDKCResult_StringErrorZPtr { + /** + * A pointer to the contents in the success state. + * Reading from this pointer when `result_ok` is not set is undefined. + */ + struct LDKCVec_u8Z *result; + /** + * A pointer to the contents in the error state. + * Reading from this pointer when `result_ok` is set is undefined. + */ + enum LDKSecp256k1Error *err; +} LDKCResult_StringErrorZPtr; + +/** + * A CResult_StringErrorZ represents the result of a fallible operation, + * containing a crate::c_types::derived::CVec_u8Z on success and a crate::c_types::Secp256k1Error on failure. + * `result_ok` indicates the overall state, and the contents are provided via `contents`. + */ +typedef struct LDKCResult_StringErrorZ { + /** + * The contents of this CResult_StringErrorZ, accessible via either + * `err` or `result` depending on the state of `result_ok`. + */ + union LDKCResult_StringErrorZPtr contents; + /** + * Whether this CResult_StringErrorZ represents a success state. + */ + bool result_ok; +} LDKCResult_StringErrorZ; + /** @@ -2441,36 +2503,36 @@ typedef struct LDKCVec_ChannelDetailsZ { /** * A channel descriptor which provides a last-hop route to get_route */ -typedef struct MUST_USE_STRUCT LDKRouteHint { +typedef struct MUST_USE_STRUCT LDKRouteHintHop { /** * A pointer to the opaque Rust object. * Nearly everywhere, inner must be non-null, however in places where * the Rust equivalent takes an Option, it may be set to null to indicate None. */ - LDKnativeRouteHint *inner; + LDKnativeRouteHintHop *inner; /** * Indicates that this is the only struct which contains the same pointer. * Rust functions which take ownership of an object provided via an argument require * this to be true and invalidate the object pointed to by inner. */ bool is_owned; -} LDKRouteHint; +} LDKRouteHintHop; /** - * A dynamically-allocated array of crate::lightning::routing::router::RouteHints of arbitrary size. + * A dynamically-allocated array of crate::lightning::routing::router::RouteHintHops of arbitrary size. * This corresponds to std::vector in C++ */ -typedef struct LDKCVec_RouteHintZ { +typedef struct LDKCVec_RouteHintHopZ { /** * The elements in the array. * If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc(). */ - struct LDKRouteHint *data; + struct LDKRouteHintHop *data; /** * The number of elements pointed to by `data`. */ uintptr_t datalen; -} LDKCVec_RouteHintZ; +} LDKCVec_RouteHintHopZ; @@ -5981,6 +6043,87 @@ typedef struct LDKCResult_TransactionNoneZ { bool result_ok; } LDKCResult_TransactionNoneZ; +/** + * The contents of CResult_NoneErrorZ + */ +typedef union LDKCResult_NoneErrorZPtr { + /** + * 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 LDKIOError *err; +} LDKCResult_NoneErrorZPtr; + +/** + * A CResult_NoneErrorZ represents the result of a fallible operation, + * containing a () on success and a crate::c_types::IOError on failure. + * `result_ok` indicates the overall state, and the contents are provided via `contents`. + */ +typedef struct LDKCResult_NoneErrorZ { + /** + * The contents of this CResult_NoneErrorZ, accessible via either + * `err` or `result` depending on the state of `result_ok`. + */ + union LDKCResult_NoneErrorZPtr contents; + /** + * Whether this CResult_NoneErrorZ represents a success state. + */ + bool result_ok; +} LDKCResult_NoneErrorZ; + +/** + * A dynamically-allocated array of crate::c_types::derived::C2Tuple_BlockHashChannelMonitorZs of arbitrary size. + * This corresponds to std::vector in C++ + */ +typedef struct LDKCVec_C2Tuple_BlockHashChannelMonitorZZ { + /** + * The elements in the array. + * If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc(). + */ + struct LDKC2Tuple_BlockHashChannelMonitorZ *data; + /** + * The number of elements pointed to by `data`. + */ + uintptr_t datalen; +} LDKCVec_C2Tuple_BlockHashChannelMonitorZZ; + +/** + * The contents of CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ + */ +typedef union LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZPtr { + /** + * A pointer to the contents in the success state. + * Reading from this pointer when `result_ok` is not set is undefined. + */ + struct LDKCVec_C2Tuple_BlockHashChannelMonitorZZ *result; + /** + * A pointer to the contents in the error state. + * Reading from this pointer when `result_ok` is set is undefined. + */ + enum LDKIOError *err; +} LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZPtr; + +/** + * A CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ represents the result of a fallible operation, + * containing a crate::c_types::derived::CVec_C2Tuple_BlockHashChannelMonitorZZ on success and a crate::c_types::IOError on failure. + * `result_ok` indicates the overall state, and the contents are provided via `contents`. + */ +typedef struct LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ { + /** + * The contents of this CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ, accessible via either + * `err` or `result` depending on the state of `result_ok`. + */ + union LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZPtr contents; + /** + * Whether this CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ represents a success state. + */ + bool result_ok; +} LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ; + /** * A Rust str object, ie a reference to a UTF8-valid string. * This is *not* null-terminated so cannot be used directly as a C string! @@ -6710,10 +6853,13 @@ typedef struct LDKAccess { } LDKAccess; /** - * The `Listen` trait is used to be notified of when blocks have been connected or disconnected - * from the chain. + * The `Listen` trait is used to notify when blocks have been connected or disconnected from the + * chain. * - * Useful when needing to replay chain data upon startup or as new chain events occur. + * Useful when needing to replay chain data upon startup or as new chain events occur. Clients + * sourcing chain data using a block-oriented API should prefer this interface over [`Confirm`]. + * Such clients fetch the entire header chain whereas clients using [`Confirm`] only fetch headers + * when needed. */ typedef struct LDKListen { /** @@ -6736,6 +6882,103 @@ typedef struct LDKListen { void (*free)(void *this_arg); } LDKListen; +/** + * The `Confirm` trait is used to notify when 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 client may implement [`Filter`] by subscribing to activity + * related to registered transactions and outputs. Upon notification, it would pass along the + * matching transactions using this interface. + * + * # Use + * + * The intended use is as follows: + * - Call [`transactions_confirmed`] to process any on-chain activity of interest. + * - Call [`transaction_unconfirmed`] to process any transaction returned by [`get_relevant_txids`] + * that has been reorganized out of the chain. + * - Call [`best_block_updated`] whenever a new chain tip becomes available. + * + * # Order + * + * Clients must call these methods in chain order. Specifically: + * - Transactions confirmed in a 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. + * - Unconfirmed transactions must be given after the original confirmations and before any + * reconfirmation. + * + * 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; + /** + * Processes transactions confirmed in a block with a given header and height. + * + * Should 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]: Self#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); + /** + * Processes a transaction that is no longer confirmed as result of a chain reorganization. + * + * Should be called for any transaction returned by [`get_relevant_txids`] if it has been + * reorganized out of the best chain. Once called, the given transaction should 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]); + /** + * Processes an update to the best header connected at the given height. + * + * Should be called when a new header is available but may be skipped for intermediary blocks + * if they become available at the same time. + */ + void (*best_block_updated)(const void *this_arg, const uint8_t (*header)[80], uint32_t height); + /** + * Returns transactions that should be monitored for reorganization out of the chain. + * + * Should include any transactions passed to [`transactions_confirmed`] that have insufficient + * confirmations to be safe from a chain reorganization. Should not include any transactions + * passed to [`transaction_unconfirmed`] unless later reconfirmed. + * + * May be called to determine the subset of transactions that must still 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 may need to be + * given to [`transaction_unconfirmed`]. + * + * [`transactions_confirmed`]: Self::transactions_confirmed + * [`transaction_unconfirmed`]: Self::transaction_unconfirmed + */ + struct LDKCVec_TxidZ (*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; + /** @@ -7473,6 +7716,37 @@ typedef struct MUST_USE_STRUCT LDKNetGraphMsgHandler { bool is_owned; } LDKNetGraphMsgHandler; + + +/** + * FilesystemPersister persists channel data on disk, where each channel's + * data is stored in a file named after its funding outpoint. + * + * Warning: this module does the best it can with calls to persist data, but it + * can only guarantee that the data is passed to the drive. It is up to the + * drive manufacturers to do the actual persistence properly, which they often + * don't (especially on consumer-grade hardware). Therefore, it is up to the + * user to validate their entire storage stack, to ensure the writes are + * persistent. + * Corollary: especially when dealing with larger amounts of money, it is best + * practice to have multiple channel data backups and not rely only on one + * FilesystemPersister. + */ +typedef struct MUST_USE_STRUCT LDKFilesystemPersister { + /** + * 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. + */ + LDKnativeFilesystemPersister *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; +} LDKFilesystemPersister; + extern const uintptr_t MAX_BUF_SIZE; extern const uint64_t MIN_RELAY_FEE_SAT_PER_1000_WEIGHT; @@ -7817,6 +8091,21 @@ void CResult_CVec_SignatureZNoneZ_free(struct LDKCResult_CVec_SignatureZNoneZ _r */ struct LDKCResult_CVec_SignatureZNoneZ CResult_CVec_SignatureZNoneZ_clone(const struct LDKCResult_CVec_SignatureZNoneZ *NONNULL_PTR orig); +/** + * Creates a new CResult_StringErrorZ in the success state. + */ +struct LDKCResult_StringErrorZ CResult_StringErrorZ_ok(struct LDKCVec_u8Z o); + +/** + * Creates a new CResult_StringErrorZ in the error state. + */ +struct LDKCResult_StringErrorZ CResult_StringErrorZ_err(enum LDKSecp256k1Error e); + +/** + * Frees any resources used by the CResult_StringErrorZ. + */ +void CResult_StringErrorZ_free(struct LDKCResult_StringErrorZ _res); + /** * Creates a new CResult_ChannelMonitorUpdateDecodeErrorZ in the success state. */ @@ -8097,7 +8386,7 @@ void CVec_ChannelDetailsZ_free(struct LDKCVec_ChannelDetailsZ _res); /** * Frees the buffer pointed to by `data` if `datalen` is non-0. */ -void CVec_RouteHintZ_free(struct LDKCVec_RouteHintZ _res); +void CVec_RouteHintHopZ_free(struct LDKCVec_RouteHintHopZ _res); /** * Creates a new CResult_RouteLightningErrorZ in the success state. @@ -9383,6 +9672,41 @@ struct LDKCResult_TransactionNoneZ CResult_TransactionNoneZ_err(void); */ void CResult_TransactionNoneZ_free(struct LDKCResult_TransactionNoneZ _res); +/** + * Creates a new CResult_NoneErrorZ in the success state. + */ +struct LDKCResult_NoneErrorZ CResult_NoneErrorZ_ok(void); + +/** + * Creates a new CResult_NoneErrorZ in the error state. + */ +struct LDKCResult_NoneErrorZ CResult_NoneErrorZ_err(enum LDKIOError e); + +/** + * Frees any resources used by the CResult_NoneErrorZ. + */ +void CResult_NoneErrorZ_free(struct LDKCResult_NoneErrorZ _res); + +/** + * Frees the buffer pointed to by `data` if `datalen` is non-0. + */ +void CVec_C2Tuple_BlockHashChannelMonitorZZ_free(struct LDKCVec_C2Tuple_BlockHashChannelMonitorZZ _res); + +/** + * Creates a new CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ in the success state. + */ +struct LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ_ok(struct LDKCVec_C2Tuple_BlockHashChannelMonitorZZ o); + +/** + * Creates a new CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ in the error state. + */ +struct LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ_err(enum LDKIOError e); + +/** + * Frees any resources used by the CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ. + */ +void CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ_free(struct LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ _res); + /** * Creates a new CResult_NoneAPIErrorZ in the success state. */ @@ -9510,6 +9834,24 @@ void APIError_free(struct LDKAPIError this_ptr); */ struct LDKAPIError APIError_clone(const struct LDKAPIError *NONNULL_PTR orig); +/** + * Creates a digital signature of a message given a SecretKey, like the node's secret. + * A receiver knowing the PublicKey (e.g. the node's id) and the message can be sure that the signature was generated by the caller. + * Signatures are EC recoverable, meaning that given the message and the signature the PublicKey of the signer can be extracted. + */ +struct LDKCResult_StringErrorZ sign(struct LDKu8slice msg, struct LDKSecretKey sk); + +/** + * Recovers the PublicKey of the signer of the message given the message and the signature. + */ +struct LDKCResult_PublicKeyErrorZ recover_pk(struct LDKu8slice msg, struct LDKStr sig); + +/** + * Verifies a message was signed by a PrivateKey that derives to a given PublicKey, given a message, a signature, + * and the PublicKey. + */ +bool verify(struct LDKu8slice msg, struct LDKStr sig, struct LDKPublicKey pk); + /** * Creates a copy of the Level */ @@ -10048,6 +10390,11 @@ void Access_free(struct LDKAccess this_ptr); */ void Listen_free(struct LDKListen this_ptr); +/** + * Calls the free function if one is set + */ +void Confirm_free(struct LDKConfirm this_ptr); + /** * Calls the free function if one is set */ @@ -10118,79 +10465,6 @@ void FeeEstimator_free(struct LDKFeeEstimator this_ptr); */ void ChainMonitor_free(struct LDKChainMonitor this_obj); -/** - * Dispatches to per-channel monitors, which are responsible for updating their on-chain view - * of a channel and reacting accordingly based on transactions in the connected block. See - * [`ChannelMonitor::block_connected`] for details. Any HTLCs that were resolved on chain will - * be returned by [`chain::Watch::release_pending_monitor_events`]. - * - * Calls back to [`chain::Filter`] if any monitor indicated new outputs to watch. Subsequent - * calls must not exclude any transactions matching the new outputs nor any in-block - * descendants of such transactions. It is not necessary to re-fetch the block to obtain - * updated `txdata`. - */ -void ChainMonitor_block_connected(const struct LDKChainMonitor *NONNULL_PTR this_arg, const uint8_t (*header)[80], struct LDKCVec_C2Tuple_usizeTransactionZZ txdata, uint32_t height); - -/** - * Dispatches to per-channel monitors, which are responsible for updating their on-chain view - * of a channel and reacting accordingly to newly confirmed transactions. For details, see - * [`ChannelMonitor::transactions_confirmed`]. - * - * Used instead of [`block_connected`] by clients that are notified of transactions rather than - * blocks. May be called before or after [`update_best_block`] for transactions in the - * corresponding block. See [`update_best_block`] for further calling expectations. - * - * [`block_connected`]: Self::block_connected - * [`update_best_block`]: Self::update_best_block - */ -void ChainMonitor_transactions_confirmed(const struct LDKChainMonitor *NONNULL_PTR this_arg, const uint8_t (*header)[80], struct LDKCVec_C2Tuple_usizeTransactionZZ txdata, uint32_t height); - -/** - * Dispatches to per-channel monitors, which are responsible for updating their on-chain view - * of a channel and reacting accordingly based on the new chain tip. For details, see - * [`ChannelMonitor::update_best_block`]. - * - * Used instead of [`block_connected`] by clients that are notified of transactions rather than - * blocks. May be called before or after [`transactions_confirmed`] for the corresponding - * block. - * - * Must be called after new blocks become available for the most recent block. Intermediary - * blocks, however, may be safely skipped. In the event of a chain re-organization, this only - * needs to be called for the most recent block assuming `transaction_unconfirmed` is called - * for any affected transactions. - * - * [`block_connected`]: Self::block_connected - * [`transactions_confirmed`]: Self::transactions_confirmed - * [`transaction_unconfirmed`]: Self::transaction_unconfirmed - */ -void ChainMonitor_update_best_block(const struct LDKChainMonitor *NONNULL_PTR this_arg, const uint8_t (*header)[80], uint32_t height); - -/** - * Dispatches to per-channel monitors, which are responsible for updating their on-chain view - * of a channel based on the disconnected block. See [`ChannelMonitor::block_disconnected`] for - * details. - */ -void ChainMonitor_block_disconnected(const struct LDKChainMonitor *NONNULL_PTR this_arg, const uint8_t (*header)[80], uint32_t disconnected_height); - -/** - * Dispatches to per-channel monitors, which are responsible for updating their on-chain view - * of a channel based on transactions unconfirmed as a result of a chain reorganization. See - * [`ChannelMonitor::transaction_unconfirmed`] for details. - * - * Used instead of [`block_disconnected`] by clients that are notified of transactions rather - * than blocks. May be called before or after [`update_best_block`] for transactions in the - * corresponding block. See [`update_best_block`] for further calling expectations. - * - * [`block_disconnected`]: Self::block_disconnected - * [`update_best_block`]: Self::update_best_block - */ -void ChainMonitor_transaction_unconfirmed(const struct LDKChainMonitor *NONNULL_PTR this_arg, const uint8_t (*txid)[32]); - -/** - * Returns the set of txids that should be monitored for re-organization out of the chain. - */ -MUST_USE_RES struct LDKCVec_TxidZ ChainMonitor_get_relevant_txids(const struct LDKChainMonitor *NONNULL_PTR this_arg); - /** * Creates a new `ChainMonitor` used to watch on-chain activity pertaining to channels. * @@ -10406,11 +10680,9 @@ void ChannelMonitor_block_disconnected(const struct LDKChannelMonitor *NONNULL_P * outputs to watch. See [`block_connected`] for details. * * Used instead of [`block_connected`] by clients that are notified of transactions rather than - * blocks. May be called before or after [`update_best_block`] for transactions in the - * corresponding block. See [`update_best_block`] for further calling expectations. + * blocks. See [`chain::Confirm`] for calling expectations. * * [`block_connected`]: Self::block_connected - * [`update_best_block`]: Self::update_best_block */ MUST_USE_RES struct LDKCVec_TransactionOutputsZ ChannelMonitor_transactions_confirmed(const struct LDKChannelMonitor *NONNULL_PTR this_arg, const uint8_t (*header)[80], struct LDKCVec_C2Tuple_usizeTransactionZZ txdata, uint32_t height, struct LDKBroadcasterInterface broadcaster, struct LDKFeeEstimator fee_estimator, struct LDKLogger logger); @@ -10418,11 +10690,9 @@ MUST_USE_RES struct LDKCVec_TransactionOutputsZ ChannelMonitor_transactions_conf * Processes a transaction that was reorganized out of the chain. * * Used instead of [`block_disconnected`] by clients that are notified of transactions rather - * than blocks. May be called before or after [`update_best_block`] for transactions in the - * corresponding block. See [`update_best_block`] for further calling expectations. + * than blocks. See [`chain::Confirm`] for calling expectations. * * [`block_disconnected`]: Self::block_disconnected - * [`update_best_block`]: Self::update_best_block */ void ChannelMonitor_transaction_unconfirmed(const struct LDKChannelMonitor *NONNULL_PTR this_arg, const uint8_t (*txid)[32], struct LDKBroadcasterInterface broadcaster, struct LDKFeeEstimator fee_estimator, struct LDKLogger logger); @@ -10431,19 +10701,11 @@ void ChannelMonitor_transaction_unconfirmed(const struct LDKChannelMonitor *NONN * [`block_connected`] for details. * * Used instead of [`block_connected`] by clients that are notified of transactions rather than - * blocks. May be called before or after [`transactions_confirmed`] for the corresponding - * block. - * - * Must be called after new blocks become available for the most recent block. Intermediary - * blocks, however, may be safely skipped. In the event of a chain re-organization, this only - * needs to be called for the most recent block assuming `transaction_unconfirmed` is called - * for any affected transactions. + * blocks. See [`chain::Confirm`] for calling expectations. * * [`block_connected`]: Self::block_connected - * [`transactions_confirmed`]: Self::transactions_confirmed - * [`transaction_unconfirmed`]: Self::transaction_unconfirmed */ -MUST_USE_RES struct LDKCVec_TransactionOutputsZ ChannelMonitor_update_best_block(const struct LDKChannelMonitor *NONNULL_PTR this_arg, const uint8_t (*header)[80], uint32_t height, struct LDKBroadcasterInterface broadcaster, struct LDKFeeEstimator fee_estimator, struct LDKLogger logger); +MUST_USE_RES struct LDKCVec_TransactionOutputsZ ChannelMonitor_best_block_updated(const struct LDKChannelMonitor *NONNULL_PTR this_arg, const uint8_t (*header)[80], uint32_t height, struct LDKBroadcasterInterface broadcaster, struct LDKFeeEstimator fee_estimator, struct LDKLogger logger); /** * Returns the set of txids that should be monitored for re-organization out of the chain. @@ -11366,83 +11628,10 @@ struct LDKEventsProvider ChannelManager_as_EventsProvider(const struct LDKChanne struct LDKListen ChannelManager_as_Listen(const struct LDKChannelManager *NONNULL_PTR this_arg); /** - * Updates channel state to take note of transactions which were confirmed in the given block - * at the given height. - * - * Note that you must still call (or have called) [`update_best_block`] with the block - * information which is included here. - * - * This method may be called before or after [`update_best_block`] for a given block's - * transaction data and may be called multiple times with additional transaction data for a - * given block. - * - * This method may be called for a previous block after an [`update_best_block`] call has - * been made for a later block, however it must *not* be called with transaction data from a - * block which is no longer in the best chain (ie where [`update_best_block`] has already - * been informed about a blockchain reorganization which no longer includes the block which - * corresponds to `header`). - * - * [`update_best_block`]: `Self::update_best_block` + * Constructs a new Confirm which calls the relevant methods on this_arg. + * This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is */ -void ChannelManager_transactions_confirmed(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*header)[80], uint32_t height, struct LDKCVec_C2Tuple_usizeTransactionZZ txdata); - -/** - * Updates channel state with the current best blockchain tip. You should attempt to call this - * quickly after a new block becomes available, however if multiple new blocks become - * available at the same time, only a single `update_best_block()` call needs to be made. - * - * This method should also be called immediately after any block disconnections, once at the - * reorganization fork point, and once with the new chain tip. Calling this method at the - * blockchain reorganization fork point ensures we learn when a funding transaction which was - * previously confirmed is reorganized out of the blockchain, ensuring we do not continue to - * accept payments which cannot be enforced on-chain. - * - * In both the block-connection and block-disconnection case, this method may be called either - * once per block connected or disconnected, or simply at the fork point and new tip(s), - * skipping any intermediary blocks. - */ -void ChannelManager_update_best_block(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*header)[80], uint32_t height); - -/** - * Gets the set of txids which should be monitored for their confirmation state. - * - * If you're providing information about reorganizations via [`transaction_unconfirmed`], this - * is the set of transactions which you may need to call [`transaction_unconfirmed`] for. - * - * This may be useful to poll to determine the set of transactions which must be registered - * with an Electrum server or for which an Electrum server needs to be polled to determine - * transaction confirmation state. - * - * This may update after any [`transactions_confirmed`] or [`block_connected`] call. - * - * Note that this is NOT the set of transactions which must be included in calls to - * [`transactions_confirmed`] if they are confirmed, but a small subset of it. - * - * [`transactions_confirmed`]: Self::transactions_confirmed - * [`transaction_unconfirmed`]: Self::transaction_unconfirmed - * [`block_connected`]: chain::Listen::block_connected - */ -MUST_USE_RES struct LDKCVec_TxidZ ChannelManager_get_relevant_txids(const struct LDKChannelManager *NONNULL_PTR this_arg); - -/** - * Marks a transaction as having been reorganized out of the blockchain. - * - * If a transaction is included in [`get_relevant_txids`], and is no longer in the main branch - * of the blockchain, this function should be called to indicate that the transaction should - * be considered reorganized out. - * - * Once this is called, the given transaction will no longer appear on [`get_relevant_txids`], - * though this may be called repeatedly for a given transaction without issue. - * - * Note that if the transaction is confirmed on the main chain in a different block (indicated - * via a call to [`transactions_confirmed`]), it may re-appear in [`get_relevant_txids`], thus - * be very wary of race-conditions wherein the final state of a transaction indicated via - * these APIs is not the same as its state on the blockchain. - * - * [`transactions_confirmed`]: Self::transactions_confirmed - * [`get_relevant_txids`]: Self::get_relevant_txids - */ -void ChannelManager_transaction_unconfirmed(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*txid)[32]); +struct LDKConfirm ChannelManager_as_Confirm(const struct LDKChannelManager *NONNULL_PTR this_arg); /** * Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool @@ -14939,79 +15128,79 @@ struct LDKCVec_u8Z Route_write(const struct LDKRoute *NONNULL_PTR obj); struct LDKCResult_RouteDecodeErrorZ Route_read(struct LDKu8slice ser); /** - * Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL. + * Frees any resources used by the RouteHintHop, if is_owned is set and inner is non-NULL. */ -void RouteHint_free(struct LDKRouteHint this_obj); +void RouteHintHop_free(struct LDKRouteHintHop this_obj); /** * The node_id of the non-target end of the route */ -struct LDKPublicKey RouteHint_get_src_node_id(const struct LDKRouteHint *NONNULL_PTR this_ptr); +struct LDKPublicKey RouteHintHop_get_src_node_id(const struct LDKRouteHintHop *NONNULL_PTR this_ptr); /** * The node_id of the non-target end of the route */ -void RouteHint_set_src_node_id(struct LDKRouteHint *NONNULL_PTR this_ptr, struct LDKPublicKey val); +void RouteHintHop_set_src_node_id(struct LDKRouteHintHop *NONNULL_PTR this_ptr, struct LDKPublicKey val); /** * The short_channel_id of this channel */ -uint64_t RouteHint_get_short_channel_id(const struct LDKRouteHint *NONNULL_PTR this_ptr); +uint64_t RouteHintHop_get_short_channel_id(const struct LDKRouteHintHop *NONNULL_PTR this_ptr); /** * The short_channel_id of this channel */ -void RouteHint_set_short_channel_id(struct LDKRouteHint *NONNULL_PTR this_ptr, uint64_t val); +void RouteHintHop_set_short_channel_id(struct LDKRouteHintHop *NONNULL_PTR this_ptr, uint64_t val); /** * The fees which must be paid to use this channel */ -struct LDKRoutingFees RouteHint_get_fees(const struct LDKRouteHint *NONNULL_PTR this_ptr); +struct LDKRoutingFees RouteHintHop_get_fees(const struct LDKRouteHintHop *NONNULL_PTR this_ptr); /** * The fees which must be paid to use this channel */ -void RouteHint_set_fees(struct LDKRouteHint *NONNULL_PTR this_ptr, struct LDKRoutingFees val); +void RouteHintHop_set_fees(struct LDKRouteHintHop *NONNULL_PTR this_ptr, struct LDKRoutingFees val); /** * The difference in CLTV values between this node and the next node. */ -uint16_t RouteHint_get_cltv_expiry_delta(const struct LDKRouteHint *NONNULL_PTR this_ptr); +uint16_t RouteHintHop_get_cltv_expiry_delta(const struct LDKRouteHintHop *NONNULL_PTR this_ptr); /** * The difference in CLTV values between this node and the next node. */ -void RouteHint_set_cltv_expiry_delta(struct LDKRouteHint *NONNULL_PTR this_ptr, uint16_t val); +void RouteHintHop_set_cltv_expiry_delta(struct LDKRouteHintHop *NONNULL_PTR this_ptr, uint16_t val); /** * The minimum value, in msat, which must be relayed to the next hop. */ -struct LDKCOption_u64Z RouteHint_get_htlc_minimum_msat(const struct LDKRouteHint *NONNULL_PTR this_ptr); +struct LDKCOption_u64Z RouteHintHop_get_htlc_minimum_msat(const struct LDKRouteHintHop *NONNULL_PTR this_ptr); /** * The minimum value, in msat, which must be relayed to the next hop. */ -void RouteHint_set_htlc_minimum_msat(struct LDKRouteHint *NONNULL_PTR this_ptr, struct LDKCOption_u64Z val); +void RouteHintHop_set_htlc_minimum_msat(struct LDKRouteHintHop *NONNULL_PTR this_ptr, struct LDKCOption_u64Z val); /** * The maximum value in msat available for routing with a single HTLC. */ -struct LDKCOption_u64Z RouteHint_get_htlc_maximum_msat(const struct LDKRouteHint *NONNULL_PTR this_ptr); +struct LDKCOption_u64Z RouteHintHop_get_htlc_maximum_msat(const struct LDKRouteHintHop *NONNULL_PTR this_ptr); /** * The maximum value in msat available for routing with a single HTLC. */ -void RouteHint_set_htlc_maximum_msat(struct LDKRouteHint *NONNULL_PTR this_ptr, struct LDKCOption_u64Z val); +void RouteHintHop_set_htlc_maximum_msat(struct LDKRouteHintHop *NONNULL_PTR this_ptr, struct LDKCOption_u64Z val); /** - * Constructs a new RouteHint given each field + * Constructs a new RouteHintHop given each field */ -MUST_USE_RES struct LDKRouteHint RouteHint_new(struct LDKPublicKey src_node_id_arg, uint64_t short_channel_id_arg, struct LDKRoutingFees fees_arg, uint16_t cltv_expiry_delta_arg, struct LDKCOption_u64Z htlc_minimum_msat_arg, struct LDKCOption_u64Z htlc_maximum_msat_arg); +MUST_USE_RES struct LDKRouteHintHop RouteHintHop_new(struct LDKPublicKey src_node_id_arg, uint64_t short_channel_id_arg, struct LDKRoutingFees fees_arg, uint16_t cltv_expiry_delta_arg, struct LDKCOption_u64Z htlc_minimum_msat_arg, struct LDKCOption_u64Z htlc_maximum_msat_arg); /** - * Creates a copy of the RouteHint + * Creates a copy of the RouteHintHop */ -struct LDKRouteHint RouteHint_clone(const struct LDKRouteHint *NONNULL_PTR orig); +struct LDKRouteHintHop RouteHintHop_clone(const struct LDKRouteHintHop *NONNULL_PTR orig); /** * Gets a route from us (payer) to the given target node (payee). @@ -15034,7 +15223,7 @@ struct LDKRouteHint RouteHint_clone(const struct LDKRouteHint *NONNULL_PTR orig) * equal), however the enabled/disabled bit on such channels as well as the * htlc_minimum_msat/htlc_maximum_msat *are* checked as they may change based on the receiving node. */ -struct LDKCResult_RouteLightningErrorZ get_route(struct LDKPublicKey our_node_id, const struct LDKNetworkGraph *NONNULL_PTR network, struct LDKPublicKey payee, struct LDKInvoiceFeatures payee_features, struct LDKCVec_ChannelDetailsZ *first_hops, struct LDKCVec_RouteHintZ last_hops, uint64_t final_value_msat, uint32_t final_cltv, struct LDKLogger logger); +struct LDKCResult_RouteLightningErrorZ get_route(struct LDKPublicKey our_node_id, const struct LDKNetworkGraph *NONNULL_PTR network, struct LDKPublicKey payee, struct LDKInvoiceFeatures payee_features, struct LDKCVec_ChannelDetailsZ *first_hops, struct LDKCVec_RouteHintHopZ last_hops, uint64_t final_value_msat, uint32_t final_cltv, struct LDKLogger logger); /** * Frees any resources used by the NetworkGraph, if is_owned is set and inner is non-NULL. @@ -15584,4 +15773,37 @@ MUST_USE_RES struct LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel(s */ MUST_USE_RES struct LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel_unsigned(struct LDKNetworkGraph *NONNULL_PTR this_arg, const struct LDKUnsignedChannelUpdate *NONNULL_PTR msg); -/* Text to put at the end of the generated file */ +/** + * Frees any resources used by the FilesystemPersister, if is_owned is set and inner is non-NULL. + */ +void FilesystemPersister_free(struct LDKFilesystemPersister this_obj); + +/** + * Initialize a new FilesystemPersister and set the path to the individual channels' + * files. + */ +MUST_USE_RES struct LDKFilesystemPersister FilesystemPersister_new(struct LDKCVec_u8Z path_to_channel_data); + +/** + * Get the directory which was provided when this persister was initialized. + */ +MUST_USE_RES struct LDKCVec_u8Z FilesystemPersister_get_data_dir(const struct LDKFilesystemPersister *NONNULL_PTR this_arg); + +/** + * Writes the provided `ChannelManager` to the path provided at `FilesystemPersister` + * initialization, within a file called \"manager\". + */ +MUST_USE_RES struct LDKCResult_NoneErrorZ FilesystemPersister_persist_manager(struct LDKCVec_u8Z data_dir, const struct LDKChannelManager *NONNULL_PTR manager); + +/** + * Read `ChannelMonitor`s from disk. + */ +MUST_USE_RES struct LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ FilesystemPersister_read_channelmonitors(const struct LDKFilesystemPersister *NONNULL_PTR this_arg, struct LDKKeysInterface keys_manager); + +/** + * Constructs a new Persist which calls the relevant methods on this_arg. + * This copies the `inner` pointer in this_arg and thus the returned Persist must be freed before this_arg is + */ +struct LDKPersist FilesystemPersister_as_Persist(const struct LDKFilesystemPersister *NONNULL_PTR this_arg); + +#endif /* LDK_C_BINDINGS_H */