+ * Signing services could be implemented on a hardware wallet. In this case,
+ * the current Sign would be a front-end on top of a communication
+ * channel connected to your secure device and lightning key material wouldn't
+ * reside on a hot server. Nevertheless, a this deployment would still need
+ * to trust the ChannelManager to avoid loss of funds as this latest component
+ * could ask to sign commitment transaction with HTLCs paying to attacker pubkeys.
+ *
+ * A more secure iteration would be to use hashlock (or payment points) to pair
+ * invoice/incoming HTLCs with outgoing HTLCs to implement a no-trust-ChannelManager
+ * at the price of more state and computation on the hardware wallet side. In the future,
+ * we are looking forward to design such interface.
+ *
+ * In any case, ChannelMonitor or fallback watchtowers are always going to be trusted
+ * to act, as liveness and breach reply correctness are always going to be hard requirements
+ * of LN security model, orthogonal of key management issues.
+ */
+typedef struct LDKSign {
+ void *this_arg;
+ /**
+ * Gets the per-commitment point for a specific commitment number
+ *
+ * Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
+ */
+ struct LDKPublicKey (*get_per_commitment_point)(const void *this_arg, uint64_t idx);
+ /**
+ * Gets the commitment secret for a specific commitment number as part of the revocation process
+ *
+ * An external signer implementation should error here if the commitment was already signed
+ * and should refuse to sign it in the future.
+ *
+ * May be called more than once for the same index.
+ *
+ * Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
+ */
+ struct LDKThirtyTwoBytes (*release_commitment_secret)(const void *this_arg, uint64_t idx);
+ /**
+ * Gets the holder's channel public keys and basepoints
+ */
+ struct LDKChannelPublicKeys pubkeys;
+ /**
+ * Fill in the pubkeys field as a reference to it will be given to Rust after this returns
+ * Note that this takes a pointer to this object, not the this_ptr like other methods do
+ * This function pointer may be NULL if pubkeys is filled in when this object is created and never needs updating.
+ */
+ void (*set_pubkeys)(const struct LDKSign*NONNULL_PTR );
+ /**
+ * Gets an arbitrary identifier describing the set of keys which are provided back to you in
+ * some SpendableOutputDescriptor types. This should be sufficient to identify this
+ * Sign object uniquely and lookup or re-derive its keys.
+ */
+ struct LDKThirtyTwoBytes (*channel_keys_id)(const void *this_arg);
+ /**
+ * Create a signature for a counterparty's commitment transaction and associated HTLC transactions.
+ *
+ * Note that if signing fails or is rejected, the channel will be force-closed.
+ */
+ struct LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ (*sign_counterparty_commitment)(const void *this_arg, const struct LDKCommitmentTransaction *NONNULL_PTR commitment_tx);
+ /**
+ * Create a signatures for a holder's commitment transaction and its claiming HTLC transactions.
+ * This will only ever be called with a non-revoked commitment_tx. This will be called with the
+ * latest commitment_tx when we initiate a force-close.
+ * This will be called with the previous latest, just to get claiming HTLC signatures, if we are
+ * reacting to a ChannelMonitor replica that decided to broadcast before it had been updated to
+ * the latest.
+ * This may be called multiple times for the same transaction.
+ *
+ * An external signer implementation should check that the commitment has not been revoked.
+ *
+ * May return Err if key derivation fails. Callers, such as ChannelMonitor, will panic in such a case.
+ */
+ struct LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ (*sign_holder_commitment_and_htlcs)(const void *this_arg, const struct LDKHolderCommitmentTransaction *NONNULL_PTR commitment_tx);
+ /**
+ * Create a signature for the given input in a transaction spending an HTLC or commitment
+ * transaction output when our counterparty broadcasts an old state.
+ *
+ * A justice transaction may claim multiples outputs at the same time if timelocks are
+ * similar, but only a signature for the input at index `input` should be signed for here.
+ * It may be called multiples time for same output(s) if a fee-bump is needed with regards
+ * to an upcoming timelock expiration.
+ *
+ * Amount is value of the output spent by this input, committed to in the BIP 143 signature.
+ *
+ * per_commitment_key is revocation secret which was provided by our counterparty when they
+ * revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
+ * not allow the spending of any funds by itself (you need our holder revocation_secret to do
+ * so).
+ *
+ * htlc holds HTLC elements (hash, timelock) if the output being spent is a HTLC output, thus
+ * changing the format of the witness script (which is committed to in the BIP 143
+ * signatures).
+ */
+ struct LDKCResult_SignatureNoneZ (*sign_justice_transaction)(const void *this_arg, struct LDKTransaction justice_tx, uintptr_t input, uint64_t amount, const uint8_t (*per_commitment_key)[32], const struct LDKHTLCOutputInCommitment *NONNULL_PTR htlc);
+ /**
+ * Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
+ * transaction, either offered or received.
+ *
+ * Such a transaction may claim multiples offered outputs at same time if we know the
+ * preimage for each when we create it, but only the input at index `input` should be
+ * signed for here. It may be called multiple times for same output(s) if a fee-bump is
+ * needed with regards to an upcoming timelock expiration.
+ *
+ * Witness_script is either a offered or received script as defined in BOLT3 for HTLC
+ * outputs.
+ *
+ * Amount is value of the output spent by this input, committed to in the BIP 143 signature.
+ *
+ * Per_commitment_point is the dynamic point corresponding to the channel state
+ * detected onchain. It has been generated by our counterparty and is used to derive
+ * channel state keys, which are then included in the witness script and committed to in the
+ * BIP 143 signature.
+ */
+ struct LDKCResult_SignatureNoneZ (*sign_counterparty_htlc_transaction)(const void *this_arg, struct LDKTransaction htlc_tx, uintptr_t input, uint64_t amount, struct LDKPublicKey per_commitment_point, const struct LDKHTLCOutputInCommitment *NONNULL_PTR htlc);
+ /**
+ * Create a signature for a (proposed) closing transaction.
+ *
+ * Note that, due to rounding, there may be one \"missing\" satoshi, and either party may have
+ * chosen to forgo their output as dust.
+ */
+ struct LDKCResult_SignatureNoneZ (*sign_closing_transaction)(const void *this_arg, struct LDKTransaction closing_tx);
+ /**
+ * Signs a channel announcement message with our funding key, proving it comes from one
+ * of the channel participants.
+ *
+ * Note that if this fails or is rejected, the channel will not be publicly announced and
+ * our counterparty may (though likely will not) close the channel on us for violating the
+ * protocol.
+ */
+ struct LDKCResult_SignatureNoneZ (*sign_channel_announcement)(const void *this_arg, const struct LDKUnsignedChannelAnnouncement *NONNULL_PTR msg);
+ /**
+ * Set the counterparty static channel data, including basepoints,
+ * counterparty_selected/holder_selected_contest_delay and funding outpoint.
+ * This is done as soon as the funding outpoint is known. Since these are static channel data,
+ * they MUST NOT be allowed to change to different values once set.
+ *
+ * channel_parameters.is_populated() MUST be true.
+ *
+ * We bind holder_selected_contest_delay late here for API convenience.
+ *
+ * Will be called before any signatures are applied.
+ */
+ void (*ready_channel)(void *this_arg, const struct LDKChannelTransactionParameters *NONNULL_PTR channel_parameters);
+ void *(*clone)(const void *this_arg);
+ struct LDKCVec_u8Z (*write)(const void *this_arg);
+ void (*free)(void *this_arg);
+} LDKSign;
+
+
+
+/**
+ * A ChannelMonitor handles chain events (blocks connected and disconnected) and generates
+ * on-chain transactions to ensure no loss of funds occurs.
+ *
+ * You MUST ensure that no ChannelMonitors for a given channel anywhere contain out-of-date
+ * information and are actively monitoring the chain.
+ *
+ * Pending Events or updated HTLCs which have not yet been read out by
+ * get_and_clear_pending_monitor_events or get_and_clear_pending_events are serialized to disk and
+ * reloaded at deserialize-time. Thus, you must ensure that, when handling events, all events
+ * gotten are fully handled before re-serializing the new state.
+ *
+ * Note that the deserializer is only implemented for (Sha256dHash, ChannelMonitor), which
+ * tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
+ * the \"reorg path\" (ie disconnecting blocks until you find a common ancestor from both the
+ * returned block hash and the the current chain and then reconnecting blocks to get to the
+ * best chain) upon deserializing the object!
+ */
+typedef struct MUST_USE_STRUCT LDKChannelMonitor {
+ /**
+ * 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.
+ */
+ LDKnativeChannelMonitor *inner;
+ bool is_owned;
+} LDKChannelMonitor;
+
+typedef struct LDKC2Tuple_BlockHashChannelMonitorZ {
+ struct LDKThirtyTwoBytes a;
+ struct LDKChannelMonitor b;
+} LDKC2Tuple_BlockHashChannelMonitorZ;
+
+typedef union LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZPtr {
+ struct LDKC2Tuple_BlockHashChannelMonitorZ *result;
+ struct LDKDecodeError *err;
+} LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZPtr;
+
+typedef struct LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ {
+ union LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ;
+
+typedef union LDKCResult_TxOutAccessErrorZPtr {
+ struct LDKTxOut *result;
+ enum LDKAccessError *err;
+} LDKCResult_TxOutAccessErrorZPtr;
+
+typedef struct LDKCResult_TxOutAccessErrorZ {
+ union LDKCResult_TxOutAccessErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_TxOutAccessErrorZ;
+
+/**
+ * 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!
+ */
+typedef struct LDKStr {
+ const uint8_t *chars;
+ uintptr_t len;
+} LDKStr;
+
+/**
+ * Indicates an error on the client's part (usually some variant of attempting to use too-low or
+ * too-high values)
+ */
+typedef enum LDKAPIError_Tag {
+ /**
+ * Indicates the API was wholly misused (see err for more). Cases where these can be returned
+ * are documented, but generally indicates some precondition of a function was violated.
+ */
+ LDKAPIError_APIMisuseError,
+ /**
+ * Due to a high feerate, we were unable to complete the request.
+ * For example, this may be returned if the feerate implies we cannot open a channel at the
+ * requested value, but opening a larger channel would succeed.
+ */
+ LDKAPIError_FeeRateTooHigh,
+ /**
+ * A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route,
+ * too-many-hops, etc).
+ */
+ LDKAPIError_RouteError,
+ /**
+ * We were unable to complete the request as the Channel required to do so is unable to
+ * complete the request (or was not found). This can take many forms, including disconnected
+ * peer, channel at capacity, channel shutting down, etc.
+ */
+ LDKAPIError_ChannelUnavailable,
+ /**
+ * An attempt to call watch/update_channel returned an Err (ie you did this!), causing the
+ * attempted action to fail.
+ */
+ LDKAPIError_MonitorUpdateFailed,
+ /**
+ * Must be last for serialization purposes
+ */
+ LDKAPIError_Sentinel,
+} LDKAPIError_Tag;
+
+typedef struct LDKAPIError_LDKAPIMisuseError_Body {
+ struct LDKCVec_u8Z err;
+} LDKAPIError_LDKAPIMisuseError_Body;
+
+typedef struct LDKAPIError_LDKFeeRateTooHigh_Body {
+ struct LDKCVec_u8Z err;
+ uint32_t feerate;
+} LDKAPIError_LDKFeeRateTooHigh_Body;
+
+typedef struct LDKAPIError_LDKRouteError_Body {
+ struct LDKStr err;
+} LDKAPIError_LDKRouteError_Body;
+
+typedef struct LDKAPIError_LDKChannelUnavailable_Body {
+ struct LDKCVec_u8Z err;
+} LDKAPIError_LDKChannelUnavailable_Body;
+
+typedef struct MUST_USE_STRUCT LDKAPIError {
+ LDKAPIError_Tag tag;
+ union {
+ LDKAPIError_LDKAPIMisuseError_Body api_misuse_error;
+ LDKAPIError_LDKFeeRateTooHigh_Body fee_rate_too_high;
+ LDKAPIError_LDKRouteError_Body route_error;
+ LDKAPIError_LDKChannelUnavailable_Body channel_unavailable;
+ };
+} LDKAPIError;
+
+typedef union LDKCResult_NoneAPIErrorZPtr {
+ /**
+ * Note that this value is always NULL, as there are no contents in the OK variant
+ */
+ void *result;
+ struct LDKAPIError *err;
+} LDKCResult_NoneAPIErrorZPtr;
+
+typedef struct LDKCResult_NoneAPIErrorZ {
+ union LDKCResult_NoneAPIErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_NoneAPIErrorZ;
+
+typedef struct LDKCVec_CResult_NoneAPIErrorZZ {
+ struct LDKCResult_NoneAPIErrorZ *data;
+ uintptr_t datalen;
+} LDKCVec_CResult_NoneAPIErrorZZ;
+
+typedef struct LDKCVec_APIErrorZ {
+ struct LDKAPIError *data;
+ uintptr_t datalen;
+} LDKCVec_APIErrorZ;
+
+
+
+/**
+ * Details of a channel, as returned by ChannelManager::list_channels and ChannelManager::list_usable_channels
+ */
+typedef struct MUST_USE_STRUCT LDKChannelDetails {
+ /**
+ * 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.
+ */
+ LDKnativeChannelDetails *inner;
+ bool is_owned;
+} LDKChannelDetails;
+
+typedef struct LDKCVec_ChannelDetailsZ {
+ struct LDKChannelDetails *data;
+ uintptr_t datalen;
+} LDKCVec_ChannelDetailsZ;
+
+/**
+ * If a payment fails to send, it can be in one of several states. This enum is returned as the
+ * Err() type describing which state the payment is in, see the description of individual enum
+ * states for more.
+ */
+typedef enum LDKPaymentSendFailure_Tag {
+ /**
+ * A parameter which was passed to send_payment was invalid, preventing us from attempting to
+ * send the payment at all. No channel state has been changed or messages sent to peers, and
+ * once you've changed the parameter at error, you can freely retry the payment in full.
+ */
+ LDKPaymentSendFailure_ParameterError,
+ /**
+ * A parameter in a single path which was passed to send_payment was invalid, preventing us
+ * from attempting to send the payment at all. No channel state has been changed or messages
+ * sent to peers, and once you've changed the parameter at error, you can freely retry the
+ * payment in full.
+ *
+ * The results here are ordered the same as the paths in the route object which was passed to
+ * send_payment.
+ */
+ LDKPaymentSendFailure_PathParameterError,
+ /**
+ * All paths which were attempted failed to send, with no channel state change taking place.
+ * You can freely retry the payment in full (though you probably want to do so over different
+ * paths than the ones selected).
+ */
+ LDKPaymentSendFailure_AllFailedRetrySafe,
+ /**
+ * Some paths which were attempted failed to send, though possibly not all. At least some
+ * paths have irrevocably committed to the HTLC and retrying the payment in full would result
+ * in over-/re-payment.
+ *
+ * The results here are ordered the same as the paths in the route object which was passed to
+ * send_payment, and any Errs which are not APIError::MonitorUpdateFailed can be safely
+ * retried (though there is currently no API with which to do so).
+ *
+ * Any entries which contain Err(APIError::MonitorUpdateFailed) or Ok(()) MUST NOT be retried
+ * as they will result in over-/re-payment. These HTLCs all either successfully sent (in the
+ * case of Ok(())) or will send once channel_monitor_updated is called on the next-hop channel
+ * with the latest update_id.
+ */
+ LDKPaymentSendFailure_PartialFailure,
+ /**
+ * Must be last for serialization purposes
+ */
+ LDKPaymentSendFailure_Sentinel,
+} LDKPaymentSendFailure_Tag;
+
+typedef struct MUST_USE_STRUCT LDKPaymentSendFailure {
+ LDKPaymentSendFailure_Tag tag;
+ union {
+ struct {
+ struct LDKAPIError parameter_error;
+ };
+ struct {
+ struct LDKCVec_CResult_NoneAPIErrorZZ path_parameter_error;
+ };
+ struct {
+ struct LDKCVec_APIErrorZ all_failed_retry_safe;
+ };
+ struct {
+ struct LDKCVec_CResult_NoneAPIErrorZZ partial_failure;
+ };
+ };
+} LDKPaymentSendFailure;
+
+typedef union LDKCResult_NonePaymentSendFailureZPtr {
+ /**
+ * Note that this value is always NULL, as there are no contents in the OK variant
+ */
+ void *result;
+ struct LDKPaymentSendFailure *err;
+} LDKCResult_NonePaymentSendFailureZPtr;
+
+typedef struct LDKCResult_NonePaymentSendFailureZ {
+ union LDKCResult_NonePaymentSendFailureZPtr contents;
+ bool result_ok;
+} LDKCResult_NonePaymentSendFailureZ;
+
+typedef struct LDKCVec_ChannelMonitorZ {
+ struct LDKChannelMonitor *data;
+ uintptr_t datalen;
+} LDKCVec_ChannelMonitorZ;
+
+/**
+ * The `Watch` trait defines behavior for watching on-chain activity pertaining to channels as
+ * blocks are connected and disconnected.
+ *
+ * Each channel is associated with a [`ChannelMonitor`]. Implementations of this trait are
+ * responsible for maintaining a set of monitors such that they can be updated accordingly as
+ * channel state changes and HTLCs are resolved. See method documentation for specific
+ * requirements.
+ *
+ * Implementations **must** ensure that updates are successfully applied and persisted upon method
+ * completion. If an update fails with a [`PermanentFailure`], then it must immediately shut down
+ * without taking any further action such as persisting the current state.
+ *
+ * If an implementation maintains multiple instances of a channel's monitor (e.g., by storing
+ * backup copies), then it must ensure that updates are applied across all instances. Otherwise, it
+ * could result in a revoked transaction being broadcast, allowing the counterparty to claim all
+ * funds in the channel. See [`ChannelMonitorUpdateErr`] for more details about how to handle
+ * multiple instances.
+ *
+ * [`ChannelMonitor`]: channelmonitor/struct.ChannelMonitor.html
+ * [`ChannelMonitorUpdateErr`]: channelmonitor/enum.ChannelMonitorUpdateErr.html
+ * [`PermanentFailure`]: channelmonitor/enum.ChannelMonitorUpdateErr.html#variant.PermanentFailure
+ */
+typedef struct LDKWatch {
+ void *this_arg;
+ /**
+ * Watches a channel identified by `funding_txo` using `monitor`.
+ *
+ * Implementations are responsible for watching the chain for the funding transaction along
+ * with any spends of outputs returned by [`get_outputs_to_watch`]. In practice, this means
+ * calling [`block_connected`] and [`block_disconnected`] on the monitor.
+ *
+ * [`get_outputs_to_watch`]: channelmonitor/struct.ChannelMonitor.html#method.get_outputs_to_watch
+ * [`block_connected`]: channelmonitor/struct.ChannelMonitor.html#method.block_connected
+ * [`block_disconnected`]: channelmonitor/struct.ChannelMonitor.html#method.block_disconnected
+ */
+ struct LDKCResult_NoneChannelMonitorUpdateErrZ (*watch_channel)(const void *this_arg, struct LDKOutPoint funding_txo, struct LDKChannelMonitor monitor);
+ /**
+ * Updates a channel identified by `funding_txo` by applying `update` to its monitor.
+ *
+ * Implementations must call [`update_monitor`] with the given update. See
+ * [`ChannelMonitorUpdateErr`] for invariants around returning an error.
+ *
+ * [`update_monitor`]: channelmonitor/struct.ChannelMonitor.html#method.update_monitor
+ * [`ChannelMonitorUpdateErr`]: channelmonitor/enum.ChannelMonitorUpdateErr.html
+ */
+ struct LDKCResult_NoneChannelMonitorUpdateErrZ (*update_channel)(const void *this_arg, struct LDKOutPoint funding_txo, struct LDKChannelMonitorUpdate update);
+ /**
+ * Returns any monitor events since the last call. Subsequent calls must only return new
+ * events.
+ */
+ struct LDKCVec_MonitorEventZ (*release_pending_monitor_events)(const void *this_arg);
+ void (*free)(void *this_arg);
+} LDKWatch;
+
+/**
+ * An interface to send a transaction to the Bitcoin network.
+ */
+typedef struct LDKBroadcasterInterface {
+ void *this_arg;
+ /**
+ * Sends a transaction out to (hopefully) be mined.
+ */
+ void (*broadcast_transaction)(const void *this_arg, struct LDKTransaction tx);
+ void (*free)(void *this_arg);
+} LDKBroadcasterInterface;
+
+typedef union LDKCResult_SignDecodeErrorZPtr {
+ struct LDKSign *result;
+ struct LDKDecodeError *err;
+} LDKCResult_SignDecodeErrorZPtr;
+
+typedef struct LDKCResult_SignDecodeErrorZ {
+ union LDKCResult_SignDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_SignDecodeErrorZ;
+
+typedef struct LDKu8slice {
+ const uint8_t *data;
+ uintptr_t datalen;
+} LDKu8slice;
+
+/**
+ * A trait to describe an object which can get user secrets and key material.
+ */
+typedef struct LDKKeysInterface {
+ void *this_arg;
+ /**
+ * Get node secret key (aka node_id or network_key).
+ *
+ * This method must return the same value each time it is called.
+ */
+ struct LDKSecretKey (*get_node_secret)(const void *this_arg);
+ /**
+ * Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
+ *
+ * This method should return a different value each time it is called, to avoid linking
+ * on-chain funds across channels as controlled to the same user.
+ */
+ struct LDKCVec_u8Z (*get_destination_script)(const void *this_arg);
+ /**
+ * Get a public key which we will send funds to (in the form of a P2WPKH output) when closing
+ * a channel.
+ *
+ * This method should return a different value each time it is called, to avoid linking
+ * on-chain funds across channels as controlled to the same user.
+ */
+ struct LDKPublicKey (*get_shutdown_pubkey)(const void *this_arg);
+ /**
+ * Get a new set of Sign for per-channel secrets. These MUST be unique even if you
+ * restarted with some stale data!
+ *
+ * This method must return a different value each time it is called.
+ */
+ struct LDKSign (*get_channel_signer)(const void *this_arg, bool inbound, uint64_t channel_value_satoshis);
+ /**
+ * Gets a unique, cryptographically-secure, random 32 byte value. This is used for encrypting
+ * onion packets and for temporary channel IDs. There is no requirement that these be
+ * persisted anywhere, though they must be unique across restarts.
+ *
+ * This method must return a different value each time it is called.
+ */
+ struct LDKThirtyTwoBytes (*get_secure_random_bytes)(const void *this_arg);
+ /**
+ * Reads a `Signer` for this `KeysInterface` from the given input stream.
+ * This is only called during deserialization of other objects which contain
+ * `Sign`-implementing objects (ie `ChannelMonitor`s and `ChannelManager`s).
+ * The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
+ * contain no versioning scheme. You may wish to include your own version prefix and ensure
+ * you've read all of the provided bytes to ensure no corruption occurred.
+ */
+ struct LDKCResult_SignDecodeErrorZ (*read_chan_signer)(const void *this_arg, struct LDKu8slice reader);
+ void (*free)(void *this_arg);
+} LDKKeysInterface;
+
+/**
+ * A trait which should be implemented to provide feerate information on a number of time
+ * horizons.
+ *
+ * Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're
+ * called from inside the library in response to chain events, P2P events, or timer events).
+ */
+typedef struct LDKFeeEstimator {
+ void *this_arg;
+ /**
+ * Gets estimated satoshis of fee required per 1000 Weight-Units.
+ *
+ * Must be no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later round-downs
+ * don't put us below 1 satoshi-per-byte).
+ *
+ * This translates to:
+ * * satoshis-per-byte * 250
+ * * ceil(satoshis-per-kbyte / 4)
+ */
+ uint32_t (*get_est_sat_per_1000_weight)(const void *this_arg, enum LDKConfirmationTarget confirmation_target);
+ void (*free)(void *this_arg);
+} LDKFeeEstimator;
+
+/**
+ * A trait encapsulating the operations required of a logger
+ */
+typedef struct LDKLogger {
+ void *this_arg;
+ /**
+ * Logs the `Record`
+ */
+ void (*log)(const void *this_arg, const char *record);
+ void (*free)(void *this_arg);
+} LDKLogger;
+
+
+
+/**
+ * Manager which keeps track of a number of channels and sends messages to the appropriate
+ * channel, also tracking HTLC preimages and forwarding onion packets appropriately.
+ *
+ * Implements ChannelMessageHandler, handling the multi-channel parts and passing things through
+ * to individual Channels.
+ *
+ * Implements Writeable to write out all channel state to disk. Implies peer_disconnected() for
+ * all peers during write/read (though does not modify this instance, only the instance being
+ * serialized). This will result in any channels which have not yet exchanged funding_created (ie
+ * called funding_transaction_generated for outbound channels).
+ *
+ * Note that you can be a bit lazier about writing out ChannelManager than you can be with
+ * ChannelMonitors. With ChannelMonitors you MUST write each monitor update out to disk before
+ * returning from chain::Watch::watch_/update_channel, with ChannelManagers, writing updates
+ * happens out-of-band (and will prevent any other ChannelManager operations from occurring during
+ * the serialization process). If the deserialized version is out-of-date compared to the
+ * ChannelMonitors passed by reference to read(), those channels will be force-closed based on the
+ * ChannelMonitor state and no funds will be lost (mod on-chain transaction fees).
+ *
+ * Note that the deserializer is only implemented for (Sha256dHash, ChannelManager), which
+ * tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
+ * the \"reorg path\" (ie call block_disconnected() until you get to a common block and then call
+ * block_connected() to step towards your best block) upon deserialization before using the
+ * object!
+ *
+ * Note that ChannelManager is responsible for tracking liveness of its channels and generating
+ * ChannelUpdate messages informing peers that the channel is temporarily disabled. To avoid
+ * spam due to quick disconnection/reconnection, updates are not sent until the channel has been
+ * offline for a full minute. In order to track this, you must call
+ * timer_chan_freshness_every_min roughly once per minute, though it doesn't have to be perfect.
+ *
+ * Rather than using a plain ChannelManager, it is preferable to use either a SimpleArcChannelManager
+ * a SimpleRefChannelManager, for conciseness. See their documentation for more details, but
+ * essentially you should default to using a SimpleRefChannelManager, and use a
+ * SimpleArcChannelManager when you require a ChannelManager with a static lifetime, such as when
+ * you're using lightning-net-tokio.
+ */
+typedef struct MUST_USE_STRUCT LDKChannelManager {
+ /**
+ * 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.
+ */
+ LDKnativeChannelManager *inner;
+ bool is_owned;
+} LDKChannelManager;
+
+typedef struct LDKC2Tuple_BlockHashChannelManagerZ {
+ struct LDKThirtyTwoBytes a;
+ struct LDKChannelManager b;
+} LDKC2Tuple_BlockHashChannelManagerZ;
+
+typedef union LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZPtr {
+ struct LDKC2Tuple_BlockHashChannelManagerZ *result;
+ struct LDKDecodeError *err;
+} LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZPtr;
+
+typedef struct LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ {
+ union LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ;
+
+typedef union LDKCResult_SpendableOutputDescriptorDecodeErrorZPtr {
+ struct LDKSpendableOutputDescriptor *result;
+ struct LDKDecodeError *err;
+} LDKCResult_SpendableOutputDescriptorDecodeErrorZPtr;
+
+typedef struct LDKCResult_SpendableOutputDescriptorDecodeErrorZ {
+ union LDKCResult_SpendableOutputDescriptorDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_SpendableOutputDescriptorDecodeErrorZ;
+
+typedef struct LDKCVec_CVec_u8ZZ {
+ struct LDKCVec_u8Z *data;
+ uintptr_t datalen;
+} LDKCVec_CVec_u8ZZ;
+
+typedef union LDKCResult_CVec_CVec_u8ZZNoneZPtr {
+ struct LDKCVec_CVec_u8ZZ *result;
+ /**
+ * Note that this value is always NULL, as there are no contents in the Err variant
+ */
+ void *err;
+} LDKCResult_CVec_CVec_u8ZZNoneZPtr;
+
+typedef struct LDKCResult_CVec_CVec_u8ZZNoneZ {
+ union LDKCResult_CVec_CVec_u8ZZNoneZPtr contents;
+ bool result_ok;
+} LDKCResult_CVec_CVec_u8ZZNoneZ;
+
+
+
+/**
+ * A simple implementation of Sign that just keeps the private keys in memory.
+ *
+ * This implementation performs no policy checks and is insufficient by itself as
+ * a secure external signer.
+ */
+typedef struct MUST_USE_STRUCT LDKInMemorySigner {
+ /**
+ * 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.
+ */
+ LDKnativeInMemorySigner *inner;
+ bool is_owned;
+} LDKInMemorySigner;
+
+typedef union LDKCResult_InMemorySignerDecodeErrorZPtr {
+ struct LDKInMemorySigner *result;
+ struct LDKDecodeError *err;
+} LDKCResult_InMemorySignerDecodeErrorZPtr;
+
+typedef struct LDKCResult_InMemorySignerDecodeErrorZ {
+ union LDKCResult_InMemorySignerDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_InMemorySignerDecodeErrorZ;
+
+typedef struct LDKCVec_TxOutZ {
+ struct LDKTxOut *data;
+ uintptr_t datalen;
+} LDKCVec_TxOutZ;
+
+typedef union LDKCResult_TransactionNoneZPtr {
+ struct LDKTransaction *result;
+ /**
+ * Note that this value is always NULL, as there are no contents in the Err variant
+ */
+ void *err;
+} LDKCResult_TransactionNoneZPtr;
+
+typedef struct LDKCResult_TransactionNoneZ {
+ union LDKCResult_TransactionNoneZPtr contents;
+ bool result_ok;
+} LDKCResult_TransactionNoneZ;
+
+
+
+/**
+ * A hop in a route
+ */
+typedef struct MUST_USE_STRUCT LDKRouteHop {
+ /**
+ * 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.
+ */
+ LDKnativeRouteHop *inner;
+ bool is_owned;
+} LDKRouteHop;
+
+typedef struct LDKCVec_RouteHopZ {
+ struct LDKRouteHop *data;
+ uintptr_t datalen;
+} LDKCVec_RouteHopZ;
+
+typedef struct LDKCVec_CVec_RouteHopZZ {
+ struct LDKCVec_RouteHopZ *data;
+ uintptr_t datalen;
+} LDKCVec_CVec_RouteHopZZ;
+
+
+
+/**
+ * A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP,
+ * it can take multiple paths. Each path is composed of one or more hops through the network.
+ */
+typedef struct MUST_USE_STRUCT LDKRoute {
+ /**
+ * 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.
+ */
+ LDKnativeRoute *inner;
+ bool is_owned;
+} LDKRoute;
+
+typedef union LDKCResult_RouteDecodeErrorZPtr {
+ struct LDKRoute *result;
+ struct LDKDecodeError *err;
+} LDKCResult_RouteDecodeErrorZPtr;
+
+typedef struct LDKCResult_RouteDecodeErrorZ {
+ union LDKCResult_RouteDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_RouteDecodeErrorZ;
+
+
+
+/**
+ * A channel descriptor which provides a last-hop route to get_route
+ */
+typedef struct MUST_USE_STRUCT LDKRouteHint {
+ /**
+ * 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;
+ bool is_owned;
+} LDKRouteHint;
+
+typedef struct LDKCVec_RouteHintZ {
+ struct LDKRouteHint *data;
+ uintptr_t datalen;
+} LDKCVec_RouteHintZ;
+
+typedef union LDKCResult_RouteLightningErrorZPtr {
+ struct LDKRoute *result;
+ struct LDKLightningError *err;
+} LDKCResult_RouteLightningErrorZPtr;
+
+typedef struct LDKCResult_RouteLightningErrorZ {
+ union LDKCResult_RouteLightningErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_RouteLightningErrorZ;
+
+typedef union LDKCResult_NetAddressu8ZPtr {
+ struct LDKNetAddress *result;
+ uint8_t *err;
+} LDKCResult_NetAddressu8ZPtr;
+
+typedef struct LDKCResult_NetAddressu8Z {
+ union LDKCResult_NetAddressu8ZPtr contents;
+ bool result_ok;
+} LDKCResult_NetAddressu8Z;
+
+typedef union LDKCResult_CResult_NetAddressu8ZDecodeErrorZPtr {
+ struct LDKCResult_NetAddressu8Z *result;
+ struct LDKDecodeError *err;
+} LDKCResult_CResult_NetAddressu8ZDecodeErrorZPtr;
+
+typedef struct LDKCResult_CResult_NetAddressu8ZDecodeErrorZ {
+ union LDKCResult_CResult_NetAddressu8ZDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_CResult_NetAddressu8ZDecodeErrorZ;
+
+
+
+/**
+ * An update_add_htlc message to be sent or received from a peer
+ */
+typedef struct MUST_USE_STRUCT LDKUpdateAddHTLC {
+ /**
+ * 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.
+ */
+ LDKnativeUpdateAddHTLC *inner;
+ bool is_owned;
+} LDKUpdateAddHTLC;
+
+typedef struct LDKCVec_UpdateAddHTLCZ {
+ struct LDKUpdateAddHTLC *data;
+ uintptr_t datalen;
+} LDKCVec_UpdateAddHTLCZ;
+
+
+
+/**
+ * An update_fulfill_htlc message to be sent or received from a peer
+ */
+typedef struct MUST_USE_STRUCT LDKUpdateFulfillHTLC {
+ /**
+ * 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.
+ */
+ LDKnativeUpdateFulfillHTLC *inner;
+ bool is_owned;
+} LDKUpdateFulfillHTLC;
+
+typedef struct LDKCVec_UpdateFulfillHTLCZ {
+ struct LDKUpdateFulfillHTLC *data;
+ uintptr_t datalen;
+} LDKCVec_UpdateFulfillHTLCZ;
+
+
+
+/**
+ * An update_fail_htlc message to be sent or received from a peer
+ */
+typedef struct MUST_USE_STRUCT LDKUpdateFailHTLC {
+ /**
+ * 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.
+ */
+ LDKnativeUpdateFailHTLC *inner;
+ bool is_owned;
+} LDKUpdateFailHTLC;
+
+typedef struct LDKCVec_UpdateFailHTLCZ {
+ struct LDKUpdateFailHTLC *data;
+ uintptr_t datalen;
+} LDKCVec_UpdateFailHTLCZ;
+
+
+
+/**
+ * An update_fail_malformed_htlc message to be sent or received from a peer
+ */
+typedef struct MUST_USE_STRUCT LDKUpdateFailMalformedHTLC {
+ /**
+ * 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.
+ */
+ LDKnativeUpdateFailMalformedHTLC *inner;
+ bool is_owned;
+} LDKUpdateFailMalformedHTLC;
+
+typedef struct LDKCVec_UpdateFailMalformedHTLCZ {
+ struct LDKUpdateFailMalformedHTLC *data;
+ uintptr_t datalen;
+} LDKCVec_UpdateFailMalformedHTLCZ;
+
+typedef union LDKCResult_AcceptChannelDecodeErrorZPtr {
+ struct LDKAcceptChannel *result;
+ struct LDKDecodeError *err;
+} LDKCResult_AcceptChannelDecodeErrorZPtr;
+
+typedef struct LDKCResult_AcceptChannelDecodeErrorZ {
+ union LDKCResult_AcceptChannelDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_AcceptChannelDecodeErrorZ;
+
+typedef union LDKCResult_AnnouncementSignaturesDecodeErrorZPtr {
+ struct LDKAnnouncementSignatures *result;
+ struct LDKDecodeError *err;
+} LDKCResult_AnnouncementSignaturesDecodeErrorZPtr;
+
+typedef struct LDKCResult_AnnouncementSignaturesDecodeErrorZ {
+ union LDKCResult_AnnouncementSignaturesDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_AnnouncementSignaturesDecodeErrorZ;
+
+typedef union LDKCResult_ChannelReestablishDecodeErrorZPtr {
+ struct LDKChannelReestablish *result;
+ struct LDKDecodeError *err;
+} LDKCResult_ChannelReestablishDecodeErrorZPtr;
+
+typedef struct LDKCResult_ChannelReestablishDecodeErrorZ {
+ union LDKCResult_ChannelReestablishDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_ChannelReestablishDecodeErrorZ;
+
+typedef union LDKCResult_ClosingSignedDecodeErrorZPtr {
+ struct LDKClosingSigned *result;
+ struct LDKDecodeError *err;
+} LDKCResult_ClosingSignedDecodeErrorZPtr;
+
+typedef struct LDKCResult_ClosingSignedDecodeErrorZ {
+ union LDKCResult_ClosingSignedDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_ClosingSignedDecodeErrorZ;
+
+
+
+/**
+ * A commitment_signed message to be sent or received from a peer
+ */
+typedef struct MUST_USE_STRUCT LDKCommitmentSigned {
+ /**
+ * 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.
+ */
+ LDKnativeCommitmentSigned *inner;
+ bool is_owned;
+} LDKCommitmentSigned;
+
+typedef union LDKCResult_CommitmentSignedDecodeErrorZPtr {
+ struct LDKCommitmentSigned *result;
+ struct LDKDecodeError *err;
+} LDKCResult_CommitmentSignedDecodeErrorZPtr;
+
+typedef struct LDKCResult_CommitmentSignedDecodeErrorZ {
+ union LDKCResult_CommitmentSignedDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_CommitmentSignedDecodeErrorZ;
+
+typedef union LDKCResult_FundingCreatedDecodeErrorZPtr {
+ struct LDKFundingCreated *result;
+ struct LDKDecodeError *err;
+} LDKCResult_FundingCreatedDecodeErrorZPtr;
+
+typedef struct LDKCResult_FundingCreatedDecodeErrorZ {
+ union LDKCResult_FundingCreatedDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_FundingCreatedDecodeErrorZ;
+
+typedef union LDKCResult_FundingSignedDecodeErrorZPtr {
+ struct LDKFundingSigned *result;
+ struct LDKDecodeError *err;
+} LDKCResult_FundingSignedDecodeErrorZPtr;
+
+typedef struct LDKCResult_FundingSignedDecodeErrorZ {
+ union LDKCResult_FundingSignedDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_FundingSignedDecodeErrorZ;
+
+typedef union LDKCResult_FundingLockedDecodeErrorZPtr {
+ struct LDKFundingLocked *result;
+ struct LDKDecodeError *err;
+} LDKCResult_FundingLockedDecodeErrorZPtr;
+
+typedef struct LDKCResult_FundingLockedDecodeErrorZ {
+ union LDKCResult_FundingLockedDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_FundingLockedDecodeErrorZ;
+
+
+
+/**
+ * An init message to be sent or received from a peer
+ */
+typedef struct MUST_USE_STRUCT LDKInit {
+ /**
+ * 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.
+ */
+ LDKnativeInit *inner;
+ bool is_owned;
+} LDKInit;
+
+typedef union LDKCResult_InitDecodeErrorZPtr {
+ struct LDKInit *result;
+ struct LDKDecodeError *err;
+} LDKCResult_InitDecodeErrorZPtr;
+
+typedef struct LDKCResult_InitDecodeErrorZ {
+ union LDKCResult_InitDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_InitDecodeErrorZ;
+
+typedef union LDKCResult_OpenChannelDecodeErrorZPtr {
+ struct LDKOpenChannel *result;
+ struct LDKDecodeError *err;
+} LDKCResult_OpenChannelDecodeErrorZPtr;
+
+typedef struct LDKCResult_OpenChannelDecodeErrorZ {
+ union LDKCResult_OpenChannelDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_OpenChannelDecodeErrorZ;
+
+typedef union LDKCResult_RevokeAndACKDecodeErrorZPtr {
+ struct LDKRevokeAndACK *result;
+ struct LDKDecodeError *err;
+} LDKCResult_RevokeAndACKDecodeErrorZPtr;
+
+typedef struct LDKCResult_RevokeAndACKDecodeErrorZ {
+ union LDKCResult_RevokeAndACKDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_RevokeAndACKDecodeErrorZ;
+
+typedef union LDKCResult_ShutdownDecodeErrorZPtr {
+ struct LDKShutdown *result;
+ struct LDKDecodeError *err;
+} LDKCResult_ShutdownDecodeErrorZPtr;
+
+typedef struct LDKCResult_ShutdownDecodeErrorZ {
+ union LDKCResult_ShutdownDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_ShutdownDecodeErrorZ;
+
+typedef union LDKCResult_UpdateFailHTLCDecodeErrorZPtr {
+ struct LDKUpdateFailHTLC *result;
+ struct LDKDecodeError *err;
+} LDKCResult_UpdateFailHTLCDecodeErrorZPtr;
+
+typedef struct LDKCResult_UpdateFailHTLCDecodeErrorZ {
+ union LDKCResult_UpdateFailHTLCDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_UpdateFailHTLCDecodeErrorZ;
+
+typedef union LDKCResult_UpdateFailMalformedHTLCDecodeErrorZPtr {
+ struct LDKUpdateFailMalformedHTLC *result;
+ struct LDKDecodeError *err;
+} LDKCResult_UpdateFailMalformedHTLCDecodeErrorZPtr;
+
+typedef struct LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ {
+ union LDKCResult_UpdateFailMalformedHTLCDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ;
+
+
+
+/**
+ * An update_fee message to be sent or received from a peer
+ */
+typedef struct MUST_USE_STRUCT LDKUpdateFee {
+ /**
+ * 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.
+ */
+ LDKnativeUpdateFee *inner;
+ bool is_owned;
+} LDKUpdateFee;
+
+typedef union LDKCResult_UpdateFeeDecodeErrorZPtr {
+ struct LDKUpdateFee *result;
+ struct LDKDecodeError *err;
+} LDKCResult_UpdateFeeDecodeErrorZPtr;
+
+typedef struct LDKCResult_UpdateFeeDecodeErrorZ {
+ union LDKCResult_UpdateFeeDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_UpdateFeeDecodeErrorZ;
+
+typedef union LDKCResult_UpdateFulfillHTLCDecodeErrorZPtr {
+ struct LDKUpdateFulfillHTLC *result;
+ struct LDKDecodeError *err;
+} LDKCResult_UpdateFulfillHTLCDecodeErrorZPtr;
+
+typedef struct LDKCResult_UpdateFulfillHTLCDecodeErrorZ {
+ union LDKCResult_UpdateFulfillHTLCDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_UpdateFulfillHTLCDecodeErrorZ;
+
+typedef union LDKCResult_UpdateAddHTLCDecodeErrorZPtr {
+ struct LDKUpdateAddHTLC *result;
+ struct LDKDecodeError *err;
+} LDKCResult_UpdateAddHTLCDecodeErrorZPtr;
+
+typedef struct LDKCResult_UpdateAddHTLCDecodeErrorZ {
+ union LDKCResult_UpdateAddHTLCDecodeErrorZPtr contents;
+ bool result_ok;
+} LDKCResult_UpdateAddHTLCDecodeErrorZ;
+
+
+
+/**
+ * A ping message to be sent or received from a peer