#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
pub(crate) extern "C" fn ChannelMonitorUpdate_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelMonitorUpdate); }
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelMonitorUpdate) };
}
#[allow(unused)]
impl ChannelMonitorUpdate {
}
/// The sequence number of this update. Updates *must* be replayed in-order according to this
/// sequence number (and updates may panic if they are not). The update_id values are strictly
-/// increasing and increase by one for each new update, with one exception specified below.
+/// increasing and increase by one for each new update, with two exceptions specified below.
///
/// This sequence number is also used to track up to which points updates which returned
/// [`ChannelMonitorUpdateStatus::InProgress`] have been applied to all copies of a given
/// ChannelMonitor when ChannelManager::channel_monitor_updated is called.
///
-/// The only instance where update_id values are not strictly increasing is the case where we
-/// allow post-force-close updates with a special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. See
-/// its docs for more details.
+/// The only instances we allow where update_id values are not strictly increasing have a
+/// special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. This update ID is used for updates that
+/// will force close the channel by broadcasting the latest commitment transaction or
+/// special post-force-close updates, like providing preimages necessary to claim outputs on the
+/// broadcast commitment transaction. See its docs for more details.
///
/// [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
#[no_mangle]
}
/// The sequence number of this update. Updates *must* be replayed in-order according to this
/// sequence number (and updates may panic if they are not). The update_id values are strictly
-/// increasing and increase by one for each new update, with one exception specified below.
+/// increasing and increase by one for each new update, with two exceptions specified below.
///
/// This sequence number is also used to track up to which points updates which returned
/// [`ChannelMonitorUpdateStatus::InProgress`] have been applied to all copies of a given
/// ChannelMonitor when ChannelManager::channel_monitor_updated is called.
///
-/// The only instance where update_id values are not strictly increasing is the case where we
-/// allow post-force-close updates with a special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. See
-/// its docs for more details.
+/// The only instances we allow where update_id values are not strictly increasing have a
+/// special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. This update ID is used for updates that
+/// will force close the channel by broadcasting the latest commitment transaction or
+/// special post-force-close updates, like providing preimages necessary to claim outputs on the
+/// broadcast commitment transaction. See its docs for more details.
///
/// [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
#[no_mangle]
pub extern "C" fn ChannelMonitorUpdate_clone(orig: &ChannelMonitorUpdate) -> ChannelMonitorUpdate {
orig.clone()
}
-/// If:
-/// (1) a channel has been force closed and
-/// (2) we receive a preimage from a forward link that allows us to spend an HTLC output on
-/// this channel's (the backward link's) broadcasted commitment transaction
-/// then we allow the `ChannelManager` to send a `ChannelMonitorUpdate` with this update ID,
-/// with the update providing said payment preimage. No other update types are allowed after
-/// force-close.
+/// Checks if two ChannelMonitorUpdates contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+/// Two objects with NULL inner values will be considered "equal" here.
+#[no_mangle]
+pub extern "C" fn ChannelMonitorUpdate_eq(a: &ChannelMonitorUpdate, b: &ChannelMonitorUpdate) -> bool {
+ if a.inner == b.inner { return true; }
+ if a.inner.is_null() || b.inner.is_null() { return false; }
+ if a.get_native_ref() == b.get_native_ref() { true } else { false }
+}
+/// The update ID used for a [`ChannelMonitorUpdate`] that is either:
+///
+///\t(1) attempting to force close the channel by broadcasting our latest commitment transaction or
+///\t(2) providing a preimage (after the channel has been force closed) from a forward link that
+///\t\tallows us to spend an HTLC output on this channel's (the backward link's) broadcasted
+///\t\tcommitment transaction.
+///
+/// No other [`ChannelMonitorUpdate`]s are allowed after force-close.
#[no_mangle]
pub static CLOSED_CHANNEL_UPDATE_ID: u64 = lightning::chain::channelmonitor::CLOSED_CHANNEL_UPDATE_ID;
pub(crate) fn to_native(&self) -> nativeMonitorEvent {
match self {
MonitorEvent::HTLCEvent (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
nativeMonitorEvent::HTLCEvent (
*unsafe { Box::from_raw(a_nonref.take_inner()) },
)
},
MonitorEvent::CommitmentTxConfirmed (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
nativeMonitorEvent::CommitmentTxConfirmed (
*unsafe { Box::from_raw(a_nonref.take_inner()) },
)
},
MonitorEvent::Completed {ref funding_txo, ref monitor_update_id, } => {
- let mut funding_txo_nonref = (*funding_txo).clone();
- let mut monitor_update_id_nonref = (*monitor_update_id).clone();
+ let mut funding_txo_nonref = Clone::clone(funding_txo);
+ let mut monitor_update_id_nonref = Clone::clone(monitor_update_id);
nativeMonitorEvent::Completed {
funding_txo: *unsafe { Box::from_raw(funding_txo_nonref.take_inner()) },
monitor_update_id: monitor_update_id_nonref,
}
},
MonitorEvent::UpdateFailed (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
nativeMonitorEvent::UpdateFailed (
*unsafe { Box::from_raw(a_nonref.take_inner()) },
)
pub(crate) fn from_native(native: &nativeMonitorEvent) -> Self {
match native {
nativeMonitorEvent::HTLCEvent (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
MonitorEvent::HTLCEvent (
crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
)
},
nativeMonitorEvent::CommitmentTxConfirmed (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
MonitorEvent::CommitmentTxConfirmed (
crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
)
},
nativeMonitorEvent::Completed {ref funding_txo, ref monitor_update_id, } => {
- let mut funding_txo_nonref = (*funding_txo).clone();
- let mut monitor_update_id_nonref = (*monitor_update_id).clone();
+ let mut funding_txo_nonref = Clone::clone(funding_txo);
+ let mut monitor_update_id_nonref = Clone::clone(monitor_update_id);
MonitorEvent::Completed {
funding_txo: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo_nonref), is_owned: true },
monitor_update_id: monitor_update_id_nonref,
}
},
nativeMonitorEvent::UpdateFailed (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
MonitorEvent::UpdateFailed (
crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
)
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
pub(crate) extern "C" fn HTLCUpdate_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHTLCUpdate); }
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeHTLCUpdate) };
}
#[allow(unused)]
impl HTLCUpdate {
/// The height at which the counterparty may be able to claim the balance if we have not
/// done so.
timeout_height: u32,
+ /// The payment hash that locks this HTLC.
+ payment_hash: crate::c_types::ThirtyTwoBytes,
+ /// The preimage that can be used to claim this HTLC.
+ payment_preimage: crate::c_types::ThirtyTwoBytes,
},
/// HTLCs which we sent to our counterparty which are claimable after a timeout (less on-chain
/// fees) if the counterparty does not know the preimage for the HTLCs. These are somewhat
/// The height at which we will be able to claim the balance if our counterparty has not
/// done so.
claimable_height: u32,
+ /// The payment hash whose preimage our counterparty needs to claim this HTLC.
+ payment_hash: crate::c_types::ThirtyTwoBytes,
},
/// HTLCs which we received from our counterparty which are claimable with a preimage which we
/// do not currently have. This will only be claimable if we receive the preimage from the node
/// The height at which our counterparty will be able to claim the balance if we have not
/// yet received the preimage and claimed it ourselves.
expiry_height: u32,
+ /// The payment hash whose preimage we need to claim this HTLC.
+ payment_hash: crate::c_types::ThirtyTwoBytes,
},
/// The channel has been closed, and our counterparty broadcasted a revoked commitment
/// transaction.
pub(crate) fn to_native(&self) -> nativeBalance {
match self {
Balance::ClaimableOnChannelClose {ref claimable_amount_satoshis, } => {
- let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
+ let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
nativeBalance::ClaimableOnChannelClose {
claimable_amount_satoshis: claimable_amount_satoshis_nonref,
}
},
Balance::ClaimableAwaitingConfirmations {ref claimable_amount_satoshis, ref confirmation_height, } => {
- let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
- let mut confirmation_height_nonref = (*confirmation_height).clone();
+ let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
+ let mut confirmation_height_nonref = Clone::clone(confirmation_height);
nativeBalance::ClaimableAwaitingConfirmations {
claimable_amount_satoshis: claimable_amount_satoshis_nonref,
confirmation_height: confirmation_height_nonref,
}
},
- Balance::ContentiousClaimable {ref claimable_amount_satoshis, ref timeout_height, } => {
- let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
- let mut timeout_height_nonref = (*timeout_height).clone();
+ Balance::ContentiousClaimable {ref claimable_amount_satoshis, ref timeout_height, ref payment_hash, ref payment_preimage, } => {
+ let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
+ let mut timeout_height_nonref = Clone::clone(timeout_height);
+ let mut payment_hash_nonref = Clone::clone(payment_hash);
+ let mut payment_preimage_nonref = Clone::clone(payment_preimage);
nativeBalance::ContentiousClaimable {
claimable_amount_satoshis: claimable_amount_satoshis_nonref,
timeout_height: timeout_height_nonref,
+ payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
+ payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
}
},
- Balance::MaybeTimeoutClaimableHTLC {ref claimable_amount_satoshis, ref claimable_height, } => {
- let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
- let mut claimable_height_nonref = (*claimable_height).clone();
+ Balance::MaybeTimeoutClaimableHTLC {ref claimable_amount_satoshis, ref claimable_height, ref payment_hash, } => {
+ let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
+ let mut claimable_height_nonref = Clone::clone(claimable_height);
+ let mut payment_hash_nonref = Clone::clone(payment_hash);
nativeBalance::MaybeTimeoutClaimableHTLC {
claimable_amount_satoshis: claimable_amount_satoshis_nonref,
claimable_height: claimable_height_nonref,
+ payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
}
},
- Balance::MaybePreimageClaimableHTLC {ref claimable_amount_satoshis, ref expiry_height, } => {
- let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
- let mut expiry_height_nonref = (*expiry_height).clone();
+ Balance::MaybePreimageClaimableHTLC {ref claimable_amount_satoshis, ref expiry_height, ref payment_hash, } => {
+ let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
+ let mut expiry_height_nonref = Clone::clone(expiry_height);
+ let mut payment_hash_nonref = Clone::clone(payment_hash);
nativeBalance::MaybePreimageClaimableHTLC {
claimable_amount_satoshis: claimable_amount_satoshis_nonref,
expiry_height: expiry_height_nonref,
+ payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
}
},
Balance::CounterpartyRevokedOutputClaimable {ref claimable_amount_satoshis, } => {
- let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
+ let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
nativeBalance::CounterpartyRevokedOutputClaimable {
claimable_amount_satoshis: claimable_amount_satoshis_nonref,
}
confirmation_height: confirmation_height,
}
},
- Balance::ContentiousClaimable {mut claimable_amount_satoshis, mut timeout_height, } => {
+ Balance::ContentiousClaimable {mut claimable_amount_satoshis, mut timeout_height, mut payment_hash, mut payment_preimage, } => {
nativeBalance::ContentiousClaimable {
claimable_amount_satoshis: claimable_amount_satoshis,
timeout_height: timeout_height,
+ payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
+ payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
}
},
- Balance::MaybeTimeoutClaimableHTLC {mut claimable_amount_satoshis, mut claimable_height, } => {
+ Balance::MaybeTimeoutClaimableHTLC {mut claimable_amount_satoshis, mut claimable_height, mut payment_hash, } => {
nativeBalance::MaybeTimeoutClaimableHTLC {
claimable_amount_satoshis: claimable_amount_satoshis,
claimable_height: claimable_height,
+ payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
}
},
- Balance::MaybePreimageClaimableHTLC {mut claimable_amount_satoshis, mut expiry_height, } => {
+ Balance::MaybePreimageClaimableHTLC {mut claimable_amount_satoshis, mut expiry_height, mut payment_hash, } => {
nativeBalance::MaybePreimageClaimableHTLC {
claimable_amount_satoshis: claimable_amount_satoshis,
expiry_height: expiry_height,
+ payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
}
},
Balance::CounterpartyRevokedOutputClaimable {mut claimable_amount_satoshis, } => {
pub(crate) fn from_native(native: &nativeBalance) -> Self {
match native {
nativeBalance::ClaimableOnChannelClose {ref claimable_amount_satoshis, } => {
- let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
+ let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
Balance::ClaimableOnChannelClose {
claimable_amount_satoshis: claimable_amount_satoshis_nonref,
}
},
nativeBalance::ClaimableAwaitingConfirmations {ref claimable_amount_satoshis, ref confirmation_height, } => {
- let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
- let mut confirmation_height_nonref = (*confirmation_height).clone();
+ let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
+ let mut confirmation_height_nonref = Clone::clone(confirmation_height);
Balance::ClaimableAwaitingConfirmations {
claimable_amount_satoshis: claimable_amount_satoshis_nonref,
confirmation_height: confirmation_height_nonref,
}
},
- nativeBalance::ContentiousClaimable {ref claimable_amount_satoshis, ref timeout_height, } => {
- let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
- let mut timeout_height_nonref = (*timeout_height).clone();
+ nativeBalance::ContentiousClaimable {ref claimable_amount_satoshis, ref timeout_height, ref payment_hash, ref payment_preimage, } => {
+ let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
+ let mut timeout_height_nonref = Clone::clone(timeout_height);
+ let mut payment_hash_nonref = Clone::clone(payment_hash);
+ let mut payment_preimage_nonref = Clone::clone(payment_preimage);
Balance::ContentiousClaimable {
claimable_amount_satoshis: claimable_amount_satoshis_nonref,
timeout_height: timeout_height_nonref,
+ payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
+ payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
}
},
- nativeBalance::MaybeTimeoutClaimableHTLC {ref claimable_amount_satoshis, ref claimable_height, } => {
- let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
- let mut claimable_height_nonref = (*claimable_height).clone();
+ nativeBalance::MaybeTimeoutClaimableHTLC {ref claimable_amount_satoshis, ref claimable_height, ref payment_hash, } => {
+ let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
+ let mut claimable_height_nonref = Clone::clone(claimable_height);
+ let mut payment_hash_nonref = Clone::clone(payment_hash);
Balance::MaybeTimeoutClaimableHTLC {
claimable_amount_satoshis: claimable_amount_satoshis_nonref,
claimable_height: claimable_height_nonref,
+ payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
}
},
- nativeBalance::MaybePreimageClaimableHTLC {ref claimable_amount_satoshis, ref expiry_height, } => {
- let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
- let mut expiry_height_nonref = (*expiry_height).clone();
+ nativeBalance::MaybePreimageClaimableHTLC {ref claimable_amount_satoshis, ref expiry_height, ref payment_hash, } => {
+ let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
+ let mut expiry_height_nonref = Clone::clone(expiry_height);
+ let mut payment_hash_nonref = Clone::clone(payment_hash);
Balance::MaybePreimageClaimableHTLC {
claimable_amount_satoshis: claimable_amount_satoshis_nonref,
expiry_height: expiry_height_nonref,
+ payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
}
},
nativeBalance::CounterpartyRevokedOutputClaimable {ref claimable_amount_satoshis, } => {
- let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
+ let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
Balance::CounterpartyRevokedOutputClaimable {
claimable_amount_satoshis: claimable_amount_satoshis_nonref,
}
confirmation_height: confirmation_height,
}
},
- nativeBalance::ContentiousClaimable {mut claimable_amount_satoshis, mut timeout_height, } => {
+ nativeBalance::ContentiousClaimable {mut claimable_amount_satoshis, mut timeout_height, mut payment_hash, mut payment_preimage, } => {
Balance::ContentiousClaimable {
claimable_amount_satoshis: claimable_amount_satoshis,
timeout_height: timeout_height,
+ payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
+ payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
}
},
- nativeBalance::MaybeTimeoutClaimableHTLC {mut claimable_amount_satoshis, mut claimable_height, } => {
+ nativeBalance::MaybeTimeoutClaimableHTLC {mut claimable_amount_satoshis, mut claimable_height, mut payment_hash, } => {
Balance::MaybeTimeoutClaimableHTLC {
claimable_amount_satoshis: claimable_amount_satoshis,
claimable_height: claimable_height,
+ payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
}
},
- nativeBalance::MaybePreimageClaimableHTLC {mut claimable_amount_satoshis, mut expiry_height, } => {
+ nativeBalance::MaybePreimageClaimableHTLC {mut claimable_amount_satoshis, mut expiry_height, mut payment_hash, } => {
Balance::MaybePreimageClaimableHTLC {
claimable_amount_satoshis: claimable_amount_satoshis,
expiry_height: expiry_height,
+ payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
}
},
nativeBalance::CounterpartyRevokedOutputClaimable {mut claimable_amount_satoshis, } => {
}
#[no_mangle]
/// Utility method to constructs a new ContentiousClaimable-variant Balance
-pub extern "C" fn Balance_contentious_claimable(claimable_amount_satoshis: u64, timeout_height: u32) -> Balance {
+pub extern "C" fn Balance_contentious_claimable(claimable_amount_satoshis: u64, timeout_height: u32, payment_hash: crate::c_types::ThirtyTwoBytes, payment_preimage: crate::c_types::ThirtyTwoBytes) -> Balance {
Balance::ContentiousClaimable {
claimable_amount_satoshis,
timeout_height,
+ payment_hash,
+ payment_preimage,
}
}
#[no_mangle]
/// Utility method to constructs a new MaybeTimeoutClaimableHTLC-variant Balance
-pub extern "C" fn Balance_maybe_timeout_claimable_htlc(claimable_amount_satoshis: u64, claimable_height: u32) -> Balance {
+pub extern "C" fn Balance_maybe_timeout_claimable_htlc(claimable_amount_satoshis: u64, claimable_height: u32, payment_hash: crate::c_types::ThirtyTwoBytes) -> Balance {
Balance::MaybeTimeoutClaimableHTLC {
claimable_amount_satoshis,
claimable_height,
+ payment_hash,
}
}
#[no_mangle]
/// Utility method to constructs a new MaybePreimageClaimableHTLC-variant Balance
-pub extern "C" fn Balance_maybe_preimage_claimable_htlc(claimable_amount_satoshis: u64, expiry_height: u32) -> Balance {
+pub extern "C" fn Balance_maybe_preimage_claimable_htlc(claimable_amount_satoshis: u64, expiry_height: u32, payment_hash: crate::c_types::ThirtyTwoBytes) -> Balance {
Balance::MaybePreimageClaimableHTLC {
claimable_amount_satoshis,
expiry_height,
+ payment_hash,
}
}
#[no_mangle]
pub extern "C" fn Balance_eq(a: &Balance, b: &Balance) -> bool {
if &a.to_native() == &b.to_native() { true } else { false }
}
+/// The amount claimable, in satoshis. This excludes balances that we are unsure if we are able
+/// to claim, this is because we are waiting for a preimage or for a timeout to expire. For more
+/// information on these balances see [`Balance::MaybeTimeoutClaimableHTLC`] and
+/// [`Balance::MaybePreimageClaimableHTLC`].
+///
+/// On-chain fees required to claim the balance are not included in this amount.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Balance_claimable_amount_satoshis(this_arg: &crate::lightning::chain::channelmonitor::Balance) -> u64 {
+ let mut ret = this_arg.to_native().claimable_amount_satoshis();
+ ret
+}
+
use lightning::chain::channelmonitor::ChannelMonitor as nativeChannelMonitorImport;
-pub(crate) type nativeChannelMonitor = nativeChannelMonitorImport<crate::lightning::chain::keysinterface::Sign>;
+pub(crate) type nativeChannelMonitor = nativeChannelMonitorImport<crate::lightning::sign::WriteableEcdsaChannelSigner>;
/// 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 (BlockHash, 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
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
pub(crate) extern "C" fn ChannelMonitor_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelMonitor); }
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelMonitor) };
}
#[allow(unused)]
impl ChannelMonitor {
local_ret.into()
}
-/// Gets the list of pending events which were generated by previous actions, clearing the list
-/// in the process.
+/// Processes [`SpendableOutputs`] events produced from each [`ChannelMonitor`] upon maturity.
///
-/// This is called by ChainMonitor::get_and_clear_pending_events() and is equivalent to
-/// EventsProvider::get_and_clear_pending_events() except that it requires &mut self as we do
-/// no internal locking in ChannelMonitors.
-#[must_use]
+/// For channels featuring anchor outputs, this method will also process [`BumpTransaction`]
+/// events produced from each [`ChannelMonitor`] while there is a balance to claim onchain
+/// within each channel. As the confirmation of a commitment transaction may be critical to the
+/// safety of funds, we recommend invoking this every 30 seconds, or lower if running in an
+/// environment with spotty connections, like on mobile.
+///
+/// An [`EventHandler`] may safely call back to the provider, though this shouldn't be needed in
+/// order to handle these events.
+///
+/// [`SpendableOutputs`]: crate::events::Event::SpendableOutputs
+/// [`BumpTransaction`]: crate::events::Event::BumpTransaction
#[no_mangle]
-pub extern "C" fn ChannelMonitor_get_and_clear_pending_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_EventZ {
- let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_and_clear_pending_events();
- let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::Event::native_into(item) }); };
- local_ret.into()
+pub extern "C" fn ChannelMonitor_process_pending_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, handler: &crate::lightning::events::EventHandler) {
+ unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_pending_events(handler)
}
/// Gets the `node_id` of the counterparty for this channel.
pub extern "C" fn ChannelMonitor_block_connected(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, header: *const [u8; 80], mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, mut height: u32, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, mut logger: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CVec_TransactionOutputsZ {
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 }); };
let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.block_connected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), &local_txdata.iter().map(|(a, b)| (*a, b)).collect::<Vec<_>>()[..], height, broadcaster, fee_estimator, logger);
- let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { let (mut orig_orig_ret_0_1_0_0, mut orig_orig_ret_0_1_0_1) = item; let mut local_orig_ret_0_1_0 = (orig_orig_ret_0_1_0_0, crate::c_types::TxOut::from_rust(orig_orig_ret_0_1_0_1)).into(); local_orig_ret_0_1_0 }); }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.into_inner() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); };
+ let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { let (mut orig_orig_ret_0_1_0_0, mut orig_orig_ret_0_1_0_1) = item; let mut local_orig_ret_0_1_0 = (orig_orig_ret_0_1_0_0, crate::c_types::TxOut::from_rust(&orig_orig_ret_0_1_0_1)).into(); local_orig_ret_0_1_0 }); }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.into_inner() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); };
local_ret.into()
}
pub extern "C" fn ChannelMonitor_transactions_confirmed(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, header: *const [u8; 80], mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, mut height: u32, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, mut logger: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CVec_TransactionOutputsZ {
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 }); };
let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.transactions_confirmed(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), &local_txdata.iter().map(|(a, b)| (*a, b)).collect::<Vec<_>>()[..], height, broadcaster, fee_estimator, logger);
- let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { let (mut orig_orig_ret_0_1_0_0, mut orig_orig_ret_0_1_0_1) = item; let mut local_orig_ret_0_1_0 = (orig_orig_ret_0_1_0_0, crate::c_types::TxOut::from_rust(orig_orig_ret_0_1_0_1)).into(); local_orig_ret_0_1_0 }); }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.into_inner() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); };
+ let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { let (mut orig_orig_ret_0_1_0_0, mut orig_orig_ret_0_1_0_1) = item; let mut local_orig_ret_0_1_0 = (orig_orig_ret_0_1_0_0, crate::c_types::TxOut::from_rust(&orig_orig_ret_0_1_0_1)).into(); local_orig_ret_0_1_0 }); }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.into_inner() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); };
local_ret.into()
}
#[no_mangle]
pub extern "C" fn ChannelMonitor_best_block_updated(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, header: *const [u8; 80], mut height: u32, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, mut logger: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CVec_TransactionOutputsZ {
let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.best_block_updated(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height, broadcaster, fee_estimator, logger);
- let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { let (mut orig_orig_ret_0_1_0_0, mut orig_orig_ret_0_1_0_1) = item; let mut local_orig_ret_0_1_0 = (orig_orig_ret_0_1_0_0, crate::c_types::TxOut::from_rust(orig_orig_ret_0_1_0_1)).into(); local_orig_ret_0_1_0 }); }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.into_inner() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); };
+ let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { let (mut orig_orig_ret_0_1_0_0, mut orig_orig_ret_0_1_0_1) = item; let mut local_orig_ret_0_1_0 = (orig_orig_ret_0_1_0_0, crate::c_types::TxOut::from_rust(&orig_orig_ret_0_1_0_1)).into(); local_orig_ret_0_1_0 }); }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.into_inner() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); };
local_ret.into()
}
/// Returns the set of txids that should be monitored for re-organization out of the chain.
#[must_use]
#[no_mangle]
-pub extern "C" fn ChannelMonitor_get_relevant_txids(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_TxidZ {
+pub extern "C" fn ChannelMonitor_get_relevant_txids(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_C2Tuple_TxidCOption_BlockHashZZZ {
let mut ret = unsafe { &*ObjOps::untweak_ptr(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() } }); };
+ let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = if orig_ret_0_1.is_none() { crate::c_types::derived::COption_BlockHashZ::None } else { crate::c_types::derived::COption_BlockHashZ::Some( { crate::c_types::ThirtyTwoBytes { data: orig_ret_0_1.unwrap().into_inner() } }) }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.into_inner() }, local_orig_ret_0_1).into(); local_ret_0 }); };
local_ret.into()
}
crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
}
+/// Triggers rebroadcasts/fee-bumps of pending claims from a force-closed channel. This is
+/// crucial in preventing certain classes of pinning attacks, detecting substantial mempool
+/// feerate changes between blocks, and ensuring reliability if broadcasting fails. We recommend
+/// invoking this every 30 seconds, or lower if running in an environment with spotty
+/// connections, like on mobile.
+#[no_mangle]
+pub extern "C" fn ChannelMonitor_rebroadcast_pending_claims(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, mut logger: crate::lightning::util::logger::Logger) {
+ unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.rebroadcast_pending_claims(broadcaster, fee_estimator, logger)
+}
+
/// Gets the balances in this channel which are either claimable by us if we were to
/// force-close the channel now or which are claimable on-chain (possibly awaiting
/// confirmation).
#[no_mangle]
/// Read a C2Tuple_BlockHashChannelMonitorZ from a byte array, created by C2Tuple_BlockHashChannelMonitorZ_write
-pub extern "C" fn C2Tuple_BlockHashChannelMonitorZ_read(ser: crate::c_types::u8slice, arg: &crate::lightning::chain::keysinterface::KeysInterface) -> crate::c_types::derived::CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ {
- let arg_conv = arg;
- let res: Result<(bitcoin::hash_types::BlockHash, lightning::chain::channelmonitor::ChannelMonitor<crate::lightning::chain::keysinterface::Sign>), lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
+pub extern "C" fn C2Tuple_BlockHashChannelMonitorZ_read(ser: crate::c_types::u8slice, arg_a: &crate::lightning::sign::EntropySource, arg_b: &crate::lightning::sign::SignerProvider) -> crate::c_types::derived::CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ {
+ let arg_a_conv = arg_a;
+ let arg_b_conv = arg_b;
+ let arg_conv = (arg_a_conv, arg_b_conv);
+ let res: Result<(bitcoin::hash_types::BlockHash, lightning::chain::channelmonitor::ChannelMonitor<crate::lightning::sign::WriteableEcdsaChannelSigner>), lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_res_0_0, mut orig_res_0_1) = o; let mut local_res_0 = (crate::c_types::ThirtyTwoBytes { data: orig_res_0_0.into_inner() }, crate::lightning::chain::channelmonitor::ChannelMonitor { inner: ObjOps::heap_alloc(orig_res_0_1), is_owned: true }).into(); local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
local_res
}