* counterparty can steal your funds!
*/
LDKEvent_FundingGenerationReady,
- /**
- * Used to indicate that the client may now broadcast the funding transaction it created for a
- * channel. Broadcasting such a transaction prior to this event may lead to our counterparty
- * trivially stealing all funds in the funding transaction!
- */
- LDKEvent_FundingBroadcastSafe,
/**
* Indicates we've received money! Just gotta dig out that payment preimage and feed it to
* ChannelManager::claim_funds to get it....
uint64_t user_channel_id;
} LDKEvent_LDKFundingGenerationReady_Body;
-typedef struct LDKEvent_LDKFundingBroadcastSafe_Body {
- /**
- * The output, which was passed to ChannelManager::funding_transaction_generated, which is
- * now safe to broadcast.
- */
- struct LDKOutPoint funding_txo;
- /**
- * The value passed in to ChannelManager::create_channel
- */
- uint64_t user_channel_id;
-} LDKEvent_LDKFundingBroadcastSafe_Body;
-
typedef struct LDKEvent_LDKPaymentReceived_Body {
/**
* The hash for which the preimage should be handed to the ChannelManager.
LDKEvent_Tag tag;
union {
LDKEvent_LDKFundingGenerationReady_Body funding_generation_ready;
- LDKEvent_LDKFundingBroadcastSafe_Body funding_broadcast_safe;
LDKEvent_LDKPaymentReceived_Body payment_received;
LDKEvent_LDKPaymentSent_Body payment_sent;
LDKEvent_LDKPaymentFailed_Body payment_failed;
bool result_ok;
} LDKCResult_NonePaymentSendFailureZ;
+/**
+ * A dynamically-allocated array of crate::c_types::ThirtyTwoBytess of arbitrary size.
+ * This corresponds to std::vector in C++
+ */
+typedef struct LDKCVec_TxidZ {
+ /**
+ * The elements in the array.
+ * If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc().
+ */
+ struct LDKThirtyTwoBytes *data;
+ /**
+ * The number of elements pointed to by `data`.
+ */
+ uintptr_t datalen;
+} LDKCVec_TxidZ;
+
/**
* A dynamically-allocated array of crate::chain::channelmonitor::ChannelMonitors of arbitrary size.
* This corresponds to std::vector in C++
*/
struct LDKCResult_NonePaymentSendFailureZ CResult_NonePaymentSendFailureZ_clone(const struct LDKCResult_NonePaymentSendFailureZ *NONNULL_PTR orig);
+/**
+ * Frees the buffer pointed to by `data` if `datalen` is non-0.
+ */
+void CVec_TxidZ_free(struct LDKCVec_TxidZ _res);
+
/**
* Frees the buffer pointed to by `data` if `datalen` is non-0.
*/
*/
MUST_USE_RES struct LDKChannelManager ChannelManager_new(struct LDKFeeEstimator fee_est, struct LDKWatch chain_monitor, struct LDKBroadcasterInterface tx_broadcaster, struct LDKLogger logger, struct LDKKeysInterface keys_manager, struct LDKUserConfig config, struct LDKChainParameters params);
+/**
+ * Gets the current configuration applied to all new channels, as
+ */
+MUST_USE_RES struct LDKUserConfig ChannelManager_get_current_default_configuration(const struct LDKChannelManager *NONNULL_PTR this_arg);
+
/**
* Creates a new outbound channel to the given remote node and with the given value.
*
* Note that ALL inputs in the transaction pointed to by funding_txo MUST spend SegWit outputs
* or your counterparty can steal your funds!
*
+ * Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
+ * or the output didn't match the parameters in [`Event::FundingGenerationReady`].
+ *
* Panics if a funding transaction has already been provided for this channel.
*
* May panic if the funding_txo is duplicative with some other channel (note that this should
* be trivially prevented by using unique funding transaction keys per-channel).
*/
-void ChannelManager_funding_transaction_generated(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*temporary_channel_id)[32], struct LDKOutPoint funding_txo);
+MUST_USE_RES struct LDKCResult_NoneAPIErrorZ ChannelManager_funding_transaction_generated(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*temporary_channel_id)[32], struct LDKTransaction funding_transaction, uint16_t output_index);
/**
* Generates a signed node_announcement from the given arguments and creates a
struct LDKListen ChannelManager_as_Listen(const struct LDKChannelManager *NONNULL_PTR this_arg);
/**
- * Updates channel state based on transactions seen in a connected block.
+ * 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 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`).
*/
-void ChannelManager_block_connected(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*header)[80], struct LDKCVec_C2Tuple_usizeTransactionZZ txdata, uint32_t height);
+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 based on a disconnected block.
+ * 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.
*
- * If necessary, the channel may be force-closed without letting the counterparty participate
- * in the shutdown.
+ * 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. XXX: Docs
+ */
+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 XXX: Docs
*/
-void ChannelManager_block_disconnected(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*header)[80]);
+void ChannelManager_transaction_unconfirmed(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*txid)[32]);
/**
* Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
const LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* operator &() const { return &self; }
const LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* operator ->() const { return &self; }
};
-class CResult_PongDecodeErrorZ {
+class CVec_TxidZ {
private:
- LDKCResult_PongDecodeErrorZ self;
+ LDKCVec_TxidZ self;
public:
- CResult_PongDecodeErrorZ(const CResult_PongDecodeErrorZ&) = delete;
- CResult_PongDecodeErrorZ(CResult_PongDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_PongDecodeErrorZ)); }
- CResult_PongDecodeErrorZ(LDKCResult_PongDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_PongDecodeErrorZ)); }
- operator LDKCResult_PongDecodeErrorZ() && { LDKCResult_PongDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_PongDecodeErrorZ)); return res; }
- ~CResult_PongDecodeErrorZ() { CResult_PongDecodeErrorZ_free(self); }
- CResult_PongDecodeErrorZ& operator=(CResult_PongDecodeErrorZ&& o) { CResult_PongDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_PongDecodeErrorZ)); return *this; }
- LDKCResult_PongDecodeErrorZ* operator &() { return &self; }
- LDKCResult_PongDecodeErrorZ* operator ->() { return &self; }
- const LDKCResult_PongDecodeErrorZ* operator &() const { return &self; }
- const LDKCResult_PongDecodeErrorZ* operator ->() const { return &self; }
+ CVec_TxidZ(const CVec_TxidZ&) = delete;
+ CVec_TxidZ(CVec_TxidZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_TxidZ)); }
+ CVec_TxidZ(LDKCVec_TxidZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_TxidZ)); }
+ operator LDKCVec_TxidZ() && { LDKCVec_TxidZ res = self; memset(&self, 0, sizeof(LDKCVec_TxidZ)); return res; }
+ ~CVec_TxidZ() { CVec_TxidZ_free(self); }
+ CVec_TxidZ& operator=(CVec_TxidZ&& o) { CVec_TxidZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_TxidZ)); return *this; }
+ LDKCVec_TxidZ* operator &() { return &self; }
+ LDKCVec_TxidZ* operator ->() { return &self; }
+ const LDKCVec_TxidZ* operator &() const { return &self; }
+ const LDKCVec_TxidZ* operator ->() const { return &self; }
};
class CResult_NoneMonitorUpdateErrorZ {
private:
const LDKCResult_AcceptChannelDecodeErrorZ* operator &() const { return &self; }
const LDKCResult_AcceptChannelDecodeErrorZ* operator ->() const { return &self; }
};
+class CResult_PongDecodeErrorZ {
+private:
+ LDKCResult_PongDecodeErrorZ self;
+public:
+ CResult_PongDecodeErrorZ(const CResult_PongDecodeErrorZ&) = delete;
+ CResult_PongDecodeErrorZ(CResult_PongDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_PongDecodeErrorZ)); }
+ CResult_PongDecodeErrorZ(LDKCResult_PongDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_PongDecodeErrorZ)); }
+ operator LDKCResult_PongDecodeErrorZ() && { LDKCResult_PongDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_PongDecodeErrorZ)); return res; }
+ ~CResult_PongDecodeErrorZ() { CResult_PongDecodeErrorZ_free(self); }
+ CResult_PongDecodeErrorZ& operator=(CResult_PongDecodeErrorZ&& o) { CResult_PongDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_PongDecodeErrorZ)); return *this; }
+ LDKCResult_PongDecodeErrorZ* operator &() { return &self; }
+ LDKCResult_PongDecodeErrorZ* operator ->() { return &self; }
+ const LDKCResult_PongDecodeErrorZ* operator &() const { return &self; }
+ const LDKCResult_PongDecodeErrorZ* operator ->() const { return &self; }
+};
class C2Tuple_BlockHashChannelManagerZ {
private:
LDKC2Tuple_BlockHashChannelManagerZ self;
const LDKCResult_BuiltCommitmentTransactionDecodeErrorZ* operator &() const { return &self; }
const LDKCResult_BuiltCommitmentTransactionDecodeErrorZ* operator ->() const { return &self; }
};
-class CResult_RouteDecodeErrorZ {
+class CResult_FundingLockedDecodeErrorZ {
private:
- LDKCResult_RouteDecodeErrorZ self;
+ LDKCResult_FundingLockedDecodeErrorZ self;
public:
- CResult_RouteDecodeErrorZ(const CResult_RouteDecodeErrorZ&) = delete;
- CResult_RouteDecodeErrorZ(CResult_RouteDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_RouteDecodeErrorZ)); }
- CResult_RouteDecodeErrorZ(LDKCResult_RouteDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_RouteDecodeErrorZ)); }
- operator LDKCResult_RouteDecodeErrorZ() && { LDKCResult_RouteDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_RouteDecodeErrorZ)); return res; }
- ~CResult_RouteDecodeErrorZ() { CResult_RouteDecodeErrorZ_free(self); }
- CResult_RouteDecodeErrorZ& operator=(CResult_RouteDecodeErrorZ&& o) { CResult_RouteDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_RouteDecodeErrorZ)); return *this; }
- LDKCResult_RouteDecodeErrorZ* operator &() { return &self; }
- LDKCResult_RouteDecodeErrorZ* operator ->() { return &self; }
- const LDKCResult_RouteDecodeErrorZ* operator &() const { return &self; }
- const LDKCResult_RouteDecodeErrorZ* operator ->() const { return &self; }
+ CResult_FundingLockedDecodeErrorZ(const CResult_FundingLockedDecodeErrorZ&) = delete;
+ CResult_FundingLockedDecodeErrorZ(CResult_FundingLockedDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_FundingLockedDecodeErrorZ)); }
+ CResult_FundingLockedDecodeErrorZ(LDKCResult_FundingLockedDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_FundingLockedDecodeErrorZ)); }
+ operator LDKCResult_FundingLockedDecodeErrorZ() && { LDKCResult_FundingLockedDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_FundingLockedDecodeErrorZ)); return res; }
+ ~CResult_FundingLockedDecodeErrorZ() { CResult_FundingLockedDecodeErrorZ_free(self); }
+ CResult_FundingLockedDecodeErrorZ& operator=(CResult_FundingLockedDecodeErrorZ&& o) { CResult_FundingLockedDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_FundingLockedDecodeErrorZ)); return *this; }
+ LDKCResult_FundingLockedDecodeErrorZ* operator &() { return &self; }
+ LDKCResult_FundingLockedDecodeErrorZ* operator ->() { return &self; }
+ const LDKCResult_FundingLockedDecodeErrorZ* operator &() const { return &self; }
+ const LDKCResult_FundingLockedDecodeErrorZ* operator ->() const { return &self; }
};
class CVec_TxOutZ {
private:
const LDKCVec_TxOutZ* operator &() const { return &self; }
const LDKCVec_TxOutZ* operator ->() const { return &self; }
};
+class CResult_RouteDecodeErrorZ {
+private:
+ LDKCResult_RouteDecodeErrorZ self;
+public:
+ CResult_RouteDecodeErrorZ(const CResult_RouteDecodeErrorZ&) = delete;
+ CResult_RouteDecodeErrorZ(CResult_RouteDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_RouteDecodeErrorZ)); }
+ CResult_RouteDecodeErrorZ(LDKCResult_RouteDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_RouteDecodeErrorZ)); }
+ operator LDKCResult_RouteDecodeErrorZ() && { LDKCResult_RouteDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_RouteDecodeErrorZ)); return res; }
+ ~CResult_RouteDecodeErrorZ() { CResult_RouteDecodeErrorZ_free(self); }
+ CResult_RouteDecodeErrorZ& operator=(CResult_RouteDecodeErrorZ&& o) { CResult_RouteDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_RouteDecodeErrorZ)); return *this; }
+ LDKCResult_RouteDecodeErrorZ* operator &() { return &self; }
+ LDKCResult_RouteDecodeErrorZ* operator ->() { return &self; }
+ const LDKCResult_RouteDecodeErrorZ* operator &() const { return &self; }
+ const LDKCResult_RouteDecodeErrorZ* operator ->() const { return &self; }
+};
class CVec_UpdateFailHTLCZ {
private:
LDKCVec_UpdateFailHTLCZ self;
const LDKCVec_UpdateFailHTLCZ* operator &() const { return &self; }
const LDKCVec_UpdateFailHTLCZ* operator ->() const { return &self; }
};
-class CResult_FundingLockedDecodeErrorZ {
-private:
- LDKCResult_FundingLockedDecodeErrorZ self;
-public:
- CResult_FundingLockedDecodeErrorZ(const CResult_FundingLockedDecodeErrorZ&) = delete;
- CResult_FundingLockedDecodeErrorZ(CResult_FundingLockedDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_FundingLockedDecodeErrorZ)); }
- CResult_FundingLockedDecodeErrorZ(LDKCResult_FundingLockedDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_FundingLockedDecodeErrorZ)); }
- operator LDKCResult_FundingLockedDecodeErrorZ() && { LDKCResult_FundingLockedDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_FundingLockedDecodeErrorZ)); return res; }
- ~CResult_FundingLockedDecodeErrorZ() { CResult_FundingLockedDecodeErrorZ_free(self); }
- CResult_FundingLockedDecodeErrorZ& operator=(CResult_FundingLockedDecodeErrorZ&& o) { CResult_FundingLockedDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_FundingLockedDecodeErrorZ)); return *this; }
- LDKCResult_FundingLockedDecodeErrorZ* operator &() { return &self; }
- LDKCResult_FundingLockedDecodeErrorZ* operator ->() { return &self; }
- const LDKCResult_FundingLockedDecodeErrorZ* operator &() const { return &self; }
- const LDKCResult_FundingLockedDecodeErrorZ* operator ->() const { return &self; }
-};
}
/// but with all dynamically-allocated buffers duplicated in new buffers.
pub extern "C" fn CResult_NonePaymentSendFailureZ_clone(orig: &CResult_NonePaymentSendFailureZ) -> CResult_NonePaymentSendFailureZ { orig.clone() }
#[repr(C)]
+/// A dynamically-allocated array of crate::c_types::ThirtyTwoBytess of arbitrary size.
+/// This corresponds to std::vector in C++
+pub struct CVec_TxidZ {
+ /// 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::c_types::ThirtyTwoBytes,
+ /// The number of elements pointed to by `data`.
+ pub datalen: usize
+}
+impl CVec_TxidZ {
+ #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec<crate::c_types::ThirtyTwoBytes> {
+ if self.datalen == 0 { return Vec::new(); }
+ let ret = unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }.into();
+ self.data = std::ptr::null_mut();
+ self.datalen = 0;
+ ret
+ }
+ #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::c_types::ThirtyTwoBytes] {
+ unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) }
+ }
+}
+impl From<Vec<crate::c_types::ThirtyTwoBytes>> for CVec_TxidZ {
+ fn from(v: Vec<crate::c_types::ThirtyTwoBytes>) -> 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_TxidZ_free(_res: CVec_TxidZ) { }
+impl Drop for CVec_TxidZ {
+ fn drop(&mut self) {
+ if self.datalen == 0 { return; }
+ unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) };
+ }
+}
+#[repr(C)]
/// A dynamically-allocated array of crate::chain::channelmonitor::ChannelMonitors of arbitrary size.
/// This corresponds to std::vector in C++
pub struct CVec_ChannelMonitorZ {
ChannelManager { inner: Box::into_raw(Box::new(ret)), is_owned: true }
}
+/// Gets the current configuration applied to all new channels, as
+#[must_use]
+#[no_mangle]
+pub extern "C" fn ChannelManager_get_current_default_configuration(this_arg: &ChannelManager) -> crate::util::config::UserConfig {
+ let mut ret = unsafe { &*this_arg.inner }.get_current_default_configuration();
+ crate::util::config::UserConfig { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
+}
+
/// Creates a new outbound channel to the given remote node and with the given value.
///
/// user_id will be provided back as user_channel_id in FundingGenerationReady and
/// Note that ALL inputs in the transaction pointed to by funding_txo MUST spend SegWit outputs
/// or your counterparty can steal your funds!
///
+/// Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
+/// or the output didn't match the parameters in [`Event::FundingGenerationReady`].
+///
/// Panics if a funding transaction has already been provided for this channel.
///
/// May panic if the funding_txo is duplicative with some other channel (note that this should
/// be trivially prevented by using unique funding transaction keys per-channel).
+#[must_use]
#[no_mangle]
-pub extern "C" fn ChannelManager_funding_transaction_generated(this_arg: &ChannelManager, temporary_channel_id: *const [u8; 32], mut funding_txo: crate::chain::transaction::OutPoint) {
- unsafe { &*this_arg.inner }.funding_transaction_generated(unsafe { &*temporary_channel_id}, *unsafe { Box::from_raw(funding_txo.take_inner()) })
+pub extern "C" fn ChannelManager_funding_transaction_generated(this_arg: &ChannelManager, temporary_channel_id: *const [u8; 32], mut funding_transaction: crate::c_types::Transaction, mut output_index: u16) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
+ let mut ret = unsafe { &*this_arg.inner }.funding_transaction_generated(unsafe { &*temporary_channel_id}, funding_transaction.into_bitcoin(), output_index);
+ let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::util::errors::APIError::native_into(e) }).into() };
+ local_ret
}
/// Generates a signed node_announcement from the given arguments and creates a
extern "C" fn ChannelManager_Listen_block_connected(this_arg: *const c_void, mut block: crate::c_types::u8slice, mut height: u32) {
<nativeChannelManager as lightning::chain::Listen<>>::block_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height)
}
-extern "C" fn ChannelManager_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut _height: u32) {
- <nativeChannelManager as lightning::chain::Listen<>>::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), _height)
+extern "C" fn ChannelManager_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
+ <nativeChannelManager as lightning::chain::Listen<>>::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
}
-/// Updates channel state based on transactions seen in a connected block.
+/// 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 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`).
#[no_mangle]
-pub extern "C" fn ChannelManager_block_connected(this_arg: &ChannelManager, header: *const [u8; 80], mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, mut height: u32) {
+pub extern "C" fn ChannelManager_transactions_confirmed(this_arg: &ChannelManager, header: *const [u8; 80], mut height: u32, mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ) {
let mut local_txdata = Vec::new(); for mut item in txdata.into_rust().drain(..) { local_txdata.push( { let (mut orig_txdata_0_0, mut orig_txdata_0_1) = item.to_rust(); let mut local_txdata_0 = (orig_txdata_0_0, orig_txdata_0_1.into_bitcoin()); local_txdata_0 }); };
- unsafe { &*this_arg.inner }.block_connected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), &local_txdata.iter().map(|(a, b)| (*a, b)).collect::<Vec<_>>()[..], height)
+ unsafe { &*this_arg.inner }.transactions_confirmed(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height, &local_txdata.iter().map(|(a, b)| (*a, b)).collect::<Vec<_>>()[..])
}
-/// Updates channel state based on a disconnected block.
+/// 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.
///
-/// If necessary, the channel may be force-closed without letting the counterparty participate
-/// in the shutdown.
+/// 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.
+#[no_mangle]
+pub extern "C" fn ChannelManager_update_best_block(this_arg: &ChannelManager, header: *const [u8; 80], mut height: u32) {
+ unsafe { &*this_arg.inner }.update_best_block(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
+}
+
+/// Gets the set of txids which should be monitored for their confirmation state. XXX: Docs
+#[must_use]
+#[no_mangle]
+pub extern "C" fn ChannelManager_get_relevant_txids(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_TxidZ {
+ let mut ret = unsafe { &*this_arg.inner }.get_relevant_txids();
+ let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::ThirtyTwoBytes { data: item.into_inner() } }); };
+ local_ret.into()
+}
+
+/// Marks a transaction as having been reorganized out of the blockchain XXX: Docs
#[no_mangle]
-pub extern "C" fn ChannelManager_block_disconnected(this_arg: &ChannelManager, header: *const [u8; 80]) {
- unsafe { &*this_arg.inner }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap())
+pub extern "C" fn ChannelManager_transaction_unconfirmed(this_arg: &ChannelManager, txid: *const [u8; 32]) {
+ unsafe { &*this_arg.inner }.transaction_unconfirmed(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap())
}
/// Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
/// The value passed in to ChannelManager::create_channel
user_channel_id: u64,
},
- /// Used to indicate that the client may now broadcast the funding transaction it created for a
- /// channel. Broadcasting such a transaction prior to this event may lead to our counterparty
- /// trivially stealing all funds in the funding transaction!
- FundingBroadcastSafe {
- /// The output, which was passed to ChannelManager::funding_transaction_generated, which is
- /// now safe to broadcast.
- funding_txo: crate::chain::transaction::OutPoint,
- /// The value passed in to ChannelManager::create_channel
- user_channel_id: u64,
- },
/// Indicates we've received money! Just gotta dig out that payment preimage and feed it to
/// ChannelManager::claim_funds to get it....
/// Note that if the preimage is not known or the amount paid is incorrect, you should call
user_channel_id: user_channel_id_nonref,
}
},
- Event::FundingBroadcastSafe {ref funding_txo, ref user_channel_id, } => {
- let mut funding_txo_nonref = (*funding_txo).clone();
- let mut user_channel_id_nonref = (*user_channel_id).clone();
- nativeEvent::FundingBroadcastSafe {
- funding_txo: *unsafe { Box::from_raw(funding_txo_nonref.take_inner()) },
- user_channel_id: user_channel_id_nonref,
- }
- },
Event::PaymentReceived {ref payment_hash, ref payment_secret, ref amt, } => {
let mut payment_hash_nonref = (*payment_hash).clone();
let mut payment_secret_nonref = (*payment_secret).clone();
user_channel_id: user_channel_id,
}
},
- Event::FundingBroadcastSafe {mut funding_txo, mut user_channel_id, } => {
- nativeEvent::FundingBroadcastSafe {
- funding_txo: *unsafe { Box::from_raw(funding_txo.take_inner()) },
- user_channel_id: user_channel_id,
- }
- },
Event::PaymentReceived {mut payment_hash, mut payment_secret, mut amt, } => {
let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentSecret(payment_secret.data) }) };
nativeEvent::PaymentReceived {
user_channel_id: user_channel_id_nonref,
}
},
- nativeEvent::FundingBroadcastSafe {ref funding_txo, ref user_channel_id, } => {
- let mut funding_txo_nonref = (*funding_txo).clone();
- let mut user_channel_id_nonref = (*user_channel_id).clone();
- Event::FundingBroadcastSafe {
- funding_txo: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(funding_txo_nonref)), is_owned: true },
- user_channel_id: user_channel_id_nonref,
- }
- },
nativeEvent::PaymentReceived {ref payment_hash, ref payment_secret, ref amt, } => {
let mut payment_hash_nonref = (*payment_hash).clone();
let mut payment_secret_nonref = (*payment_secret).clone();
user_channel_id: user_channel_id,
}
},
- nativeEvent::FundingBroadcastSafe {mut funding_txo, mut user_channel_id, } => {
- Event::FundingBroadcastSafe {
- funding_txo: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(funding_txo)), is_owned: true },
- user_channel_id: user_channel_id,
- }
- },
nativeEvent::PaymentReceived {mut payment_hash, mut payment_secret, mut amt, } => {
let mut local_payment_secret = if payment_secret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_secret.unwrap()).0 } } };
Event::PaymentReceived {