X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Fchain%2Fchannelmonitor.rs;h=45e7998d7e2a83d794130d5fce06bb04faf00ae6;hb=HEAD;hp=c37e29e979e90ce9cf995e0b819eb91e33406233;hpb=5502fccd64611f16f5ebba3759c68b1a4d69b537;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/lightning/chain/channelmonitor.rs b/lightning-c-bindings/src/lightning/chain/channelmonitor.rs index c37e29e..9835584 100644 --- a/lightning-c-bindings/src/lightning/chain/channelmonitor.rs +++ b/lightning-c-bindings/src/lightning/chain/channelmonitor.rs @@ -124,6 +124,29 @@ pub extern "C" fn ChannelMonitorUpdate_get_update_id(this_ptr: &ChannelMonitorUp pub extern "C" fn ChannelMonitorUpdate_set_update_id(this_ptr: &mut ChannelMonitorUpdate, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.update_id = val; } +/// The channel ID associated with these updates. +/// +/// Will be `None` for `ChannelMonitorUpdate`s constructed on LDK versions prior to 0.0.121 and +/// always `Some` otherwise. +/// +/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None +#[no_mangle] +pub extern "C" fn ChannelMonitorUpdate_get_channel_id(this_ptr: &ChannelMonitorUpdate) -> crate::lightning::ln::types::ChannelId { + let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; + let mut local_inner_val = crate::lightning::ln::types::ChannelId { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::types::ChannelId<>) as *mut _ }, is_owned: false }; + local_inner_val +} +/// The channel ID associated with these updates. +/// +/// Will be `None` for `ChannelMonitorUpdate`s constructed on LDK versions prior to 0.0.121 and +/// always `Some` otherwise. +/// +/// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None +#[no_mangle] +pub extern "C" fn ChannelMonitorUpdate_set_channel_id(this_ptr: &mut ChannelMonitorUpdate, mut val: crate::lightning::ln::types::ChannelId) { + let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = local_val; +} impl Clone for ChannelMonitorUpdate { fn clone(&self) -> Self { Self { @@ -143,6 +166,9 @@ pub(crate) extern "C" fn ChannelMonitorUpdate_clone_void(this_ptr: *const c_void pub extern "C" fn ChannelMonitorUpdate_clone(orig: &ChannelMonitorUpdate) -> ChannelMonitorUpdate { orig.clone() } +/// Get a string which allows debug introspection of a ChannelMonitorUpdate object +pub extern "C" fn ChannelMonitorUpdate_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::chain::channelmonitor::ChannelMonitorUpdate }).into()} /// 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. @@ -187,7 +213,18 @@ pub enum MonitorEvent { /// A monitor event containing an HTLCUpdate. HTLCEvent( crate::lightning::chain::channelmonitor::HTLCUpdate), - /// A monitor event that the Channel's commitment transaction was confirmed. + /// Indicates we broadcasted the channel's latest commitment transaction and thus closed the + /// channel. Holds information about the channel and why it was closed. + HolderForceClosedWithInfo { + /// The reason the channel was closed. + reason: crate::lightning::events::ClosureReason, + /// The funding outpoint of the channel. + outpoint: crate::lightning::chain::transaction::OutPoint, + /// The channel ID of the channel. + channel_id: crate::lightning::ln::types::ChannelId, + }, + /// Indicates we broadcasted the channel's latest commitment transaction and thus closed the + /// channel. HolderForceClosed( crate::lightning::chain::transaction::OutPoint), /// Indicates a [`ChannelMonitor`] update has completed. See @@ -197,6 +234,8 @@ pub enum MonitorEvent { Completed { /// The funding outpoint of the [`ChannelMonitor`] that was updated funding_txo: crate::lightning::chain::transaction::OutPoint, + /// The channel ID of the channel associated with the [`ChannelMonitor`] + channel_id: crate::lightning::ln::types::ChannelId, /// The Update ID from [`ChannelMonitorUpdate::update_id`] which was applied or /// [`ChannelMonitor::get_latest_update_id`]. /// @@ -218,17 +257,29 @@ impl MonitorEvent { *unsafe { Box::from_raw(a_nonref.take_inner()) }, ) }, + MonitorEvent::HolderForceClosedWithInfo {ref reason, ref outpoint, ref channel_id, } => { + let mut reason_nonref = Clone::clone(reason); + let mut outpoint_nonref = Clone::clone(outpoint); + let mut channel_id_nonref = Clone::clone(channel_id); + nativeMonitorEvent::HolderForceClosedWithInfo { + reason: reason_nonref.into_native(), + outpoint: *unsafe { Box::from_raw(outpoint_nonref.take_inner()) }, + channel_id: *unsafe { Box::from_raw(channel_id_nonref.take_inner()) }, + } + }, MonitorEvent::HolderForceClosed (ref a, ) => { let mut a_nonref = Clone::clone(a); nativeMonitorEvent::HolderForceClosed ( *unsafe { Box::from_raw(a_nonref.take_inner()) }, ) }, - MonitorEvent::Completed {ref funding_txo, ref monitor_update_id, } => { + MonitorEvent::Completed {ref funding_txo, ref channel_id, ref monitor_update_id, } => { let mut funding_txo_nonref = Clone::clone(funding_txo); + let mut channel_id_nonref = Clone::clone(channel_id); let mut monitor_update_id_nonref = Clone::clone(monitor_update_id); nativeMonitorEvent::Completed { funding_txo: *unsafe { Box::from_raw(funding_txo_nonref.take_inner()) }, + channel_id: *unsafe { Box::from_raw(channel_id_nonref.take_inner()) }, monitor_update_id: monitor_update_id_nonref, } }, @@ -242,21 +293,30 @@ impl MonitorEvent { *unsafe { Box::from_raw(a.take_inner()) }, ) }, + MonitorEvent::HolderForceClosedWithInfo {mut reason, mut outpoint, mut channel_id, } => { + nativeMonitorEvent::HolderForceClosedWithInfo { + reason: reason.into_native(), + outpoint: *unsafe { Box::from_raw(outpoint.take_inner()) }, + channel_id: *unsafe { Box::from_raw(channel_id.take_inner()) }, + } + }, MonitorEvent::HolderForceClosed (mut a, ) => { nativeMonitorEvent::HolderForceClosed ( *unsafe { Box::from_raw(a.take_inner()) }, ) }, - MonitorEvent::Completed {mut funding_txo, mut monitor_update_id, } => { + MonitorEvent::Completed {mut funding_txo, mut channel_id, mut monitor_update_id, } => { nativeMonitorEvent::Completed { funding_txo: *unsafe { Box::from_raw(funding_txo.take_inner()) }, + channel_id: *unsafe { Box::from_raw(channel_id.take_inner()) }, monitor_update_id: monitor_update_id, } }, } } #[allow(unused)] - pub(crate) fn from_native(native: &nativeMonitorEvent) -> Self { + pub(crate) fn from_native(native: &MonitorEventImport) -> Self { + let native = unsafe { &*(native as *const _ as *const c_void as *const nativeMonitorEvent) }; match native { nativeMonitorEvent::HTLCEvent (ref a, ) => { let mut a_nonref = Clone::clone(a); @@ -264,17 +324,29 @@ impl MonitorEvent { crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true }, ) }, + nativeMonitorEvent::HolderForceClosedWithInfo {ref reason, ref outpoint, ref channel_id, } => { + let mut reason_nonref = Clone::clone(reason); + let mut outpoint_nonref = Clone::clone(outpoint); + let mut channel_id_nonref = Clone::clone(channel_id); + MonitorEvent::HolderForceClosedWithInfo { + reason: crate::lightning::events::ClosureReason::native_into(reason_nonref), + outpoint: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(outpoint_nonref), is_owned: true }, + channel_id: crate::lightning::ln::types::ChannelId { inner: ObjOps::heap_alloc(channel_id_nonref), is_owned: true }, + } + }, nativeMonitorEvent::HolderForceClosed (ref a, ) => { let mut a_nonref = Clone::clone(a); MonitorEvent::HolderForceClosed ( crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a_nonref), is_owned: true }, ) }, - nativeMonitorEvent::Completed {ref funding_txo, ref monitor_update_id, } => { + nativeMonitorEvent::Completed {ref funding_txo, ref channel_id, ref monitor_update_id, } => { let mut funding_txo_nonref = Clone::clone(funding_txo); + let mut channel_id_nonref = Clone::clone(channel_id); 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 }, + channel_id: crate::lightning::ln::types::ChannelId { inner: ObjOps::heap_alloc(channel_id_nonref), is_owned: true }, monitor_update_id: monitor_update_id_nonref, } }, @@ -288,14 +360,22 @@ impl MonitorEvent { crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a), is_owned: true }, ) }, + nativeMonitorEvent::HolderForceClosedWithInfo {mut reason, mut outpoint, mut channel_id, } => { + MonitorEvent::HolderForceClosedWithInfo { + reason: crate::lightning::events::ClosureReason::native_into(reason), + outpoint: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(outpoint), is_owned: true }, + channel_id: crate::lightning::ln::types::ChannelId { inner: ObjOps::heap_alloc(channel_id), is_owned: true }, + } + }, nativeMonitorEvent::HolderForceClosed (mut a, ) => { MonitorEvent::HolderForceClosed ( crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a), is_owned: true }, ) }, - nativeMonitorEvent::Completed {mut funding_txo, mut monitor_update_id, } => { + nativeMonitorEvent::Completed {mut funding_txo, mut channel_id, mut monitor_update_id, } => { MonitorEvent::Completed { funding_txo: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo), is_owned: true }, + channel_id: crate::lightning::ln::types::ChannelId { inner: ObjOps::heap_alloc(channel_id), is_owned: true }, monitor_update_id: monitor_update_id, } }, @@ -326,15 +406,25 @@ pub extern "C" fn MonitorEvent_htlcevent(a: crate::lightning::chain::channelmoni MonitorEvent::HTLCEvent(a, ) } #[no_mangle] +/// Utility method to constructs a new HolderForceClosedWithInfo-variant MonitorEvent +pub extern "C" fn MonitorEvent_holder_force_closed_with_info(reason: crate::lightning::events::ClosureReason, outpoint: crate::lightning::chain::transaction::OutPoint, channel_id: crate::lightning::ln::types::ChannelId) -> MonitorEvent { + MonitorEvent::HolderForceClosedWithInfo { + reason, + outpoint, + channel_id, + } +} +#[no_mangle] /// Utility method to constructs a new HolderForceClosed-variant MonitorEvent pub extern "C" fn MonitorEvent_holder_force_closed(a: crate::lightning::chain::transaction::OutPoint) -> MonitorEvent { MonitorEvent::HolderForceClosed(a, ) } #[no_mangle] /// Utility method to constructs a new Completed-variant MonitorEvent -pub extern "C" fn MonitorEvent_completed(funding_txo: crate::lightning::chain::transaction::OutPoint, monitor_update_id: u64) -> MonitorEvent { +pub extern "C" fn MonitorEvent_completed(funding_txo: crate::lightning::chain::transaction::OutPoint, channel_id: crate::lightning::ln::types::ChannelId, monitor_update_id: u64) -> MonitorEvent { MonitorEvent::Completed { funding_txo, + channel_id, monitor_update_id, } } @@ -580,8 +670,8 @@ impl Balance { nativeBalance::ContentiousClaimable { amount_satoshis: 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), + payment_hash: ::lightning::ln::types::PaymentHash(payment_hash_nonref.data), + payment_preimage: ::lightning::ln::types::PaymentPreimage(payment_preimage_nonref.data), } }, Balance::MaybeTimeoutClaimableHTLC {ref amount_satoshis, ref claimable_height, ref payment_hash, } => { @@ -591,7 +681,7 @@ impl Balance { nativeBalance::MaybeTimeoutClaimableHTLC { amount_satoshis: amount_satoshis_nonref, claimable_height: claimable_height_nonref, - payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data), + payment_hash: ::lightning::ln::types::PaymentHash(payment_hash_nonref.data), } }, Balance::MaybePreimageClaimableHTLC {ref amount_satoshis, ref expiry_height, ref payment_hash, } => { @@ -601,7 +691,7 @@ impl Balance { nativeBalance::MaybePreimageClaimableHTLC { amount_satoshis: amount_satoshis_nonref, expiry_height: expiry_height_nonref, - payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data), + payment_hash: ::lightning::ln::types::PaymentHash(payment_hash_nonref.data), } }, Balance::CounterpartyRevokedOutputClaimable {ref amount_satoshis, } => { @@ -630,22 +720,22 @@ impl Balance { nativeBalance::ContentiousClaimable { amount_satoshis: amount_satoshis, timeout_height: timeout_height, - payment_hash: ::lightning::ln::PaymentHash(payment_hash.data), - payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data), + payment_hash: ::lightning::ln::types::PaymentHash(payment_hash.data), + payment_preimage: ::lightning::ln::types::PaymentPreimage(payment_preimage.data), } }, Balance::MaybeTimeoutClaimableHTLC {mut amount_satoshis, mut claimable_height, mut payment_hash, } => { nativeBalance::MaybeTimeoutClaimableHTLC { amount_satoshis: amount_satoshis, claimable_height: claimable_height, - payment_hash: ::lightning::ln::PaymentHash(payment_hash.data), + payment_hash: ::lightning::ln::types::PaymentHash(payment_hash.data), } }, Balance::MaybePreimageClaimableHTLC {mut amount_satoshis, mut expiry_height, mut payment_hash, } => { nativeBalance::MaybePreimageClaimableHTLC { amount_satoshis: amount_satoshis, expiry_height: expiry_height, - payment_hash: ::lightning::ln::PaymentHash(payment_hash.data), + payment_hash: ::lightning::ln::types::PaymentHash(payment_hash.data), } }, Balance::CounterpartyRevokedOutputClaimable {mut amount_satoshis, } => { @@ -656,7 +746,8 @@ impl Balance { } } #[allow(unused)] - pub(crate) fn from_native(native: &nativeBalance) -> Self { + pub(crate) fn from_native(native: &BalanceImport) -> Self { + let native = unsafe { &*(native as *const _ as *const c_void as *const nativeBalance) }; match native { nativeBalance::ClaimableOnChannelClose {ref amount_satoshis, } => { let mut amount_satoshis_nonref = Clone::clone(amount_satoshis); @@ -824,6 +915,9 @@ pub extern "C" fn Balance_counterparty_revoked_output_claimable(amount_satoshis: amount_satoshis, } } +/// Get a string which allows debug introspection of a Balance object +pub extern "C" fn Balance_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::chain::channelmonitor::Balance }).into()} /// Checks if two Balances contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. #[no_mangle] @@ -845,7 +939,7 @@ pub extern "C" fn Balance_claimable_amount_satoshis(this_arg: &crate::lightning: use lightning::chain::channelmonitor::ChannelMonitor as nativeChannelMonitorImport; -pub(crate) type nativeChannelMonitor = nativeChannelMonitorImport; +pub(crate) type nativeChannelMonitor = nativeChannelMonitorImport; /// A ChannelMonitor handles chain events (blocks connected and disconnected) and generates /// on-chain transactions to ensure no loss of funds occurs. @@ -958,17 +1052,25 @@ pub extern "C" fn ChannelMonitor_get_latest_update_id(this_arg: &crate::lightnin #[no_mangle] pub extern "C" fn ChannelMonitor_get_funding_txo(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::C2Tuple_OutPointCVec_u8ZZ { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_funding_txo(); - let (mut orig_ret_0, mut orig_ret_1) = ret; let mut local_ret = (crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(orig_ret_0), is_owned: true }, orig_ret_1.into_bytes().into()).into(); + let (mut orig_ret_0, mut orig_ret_1) = ret; let mut local_ret = (crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(orig_ret_0), is_owned: true }, orig_ret_1.to_bytes().into()).into(); local_ret } +/// Gets the channel_id of the channel this ChannelMonitor is monitoring for. +#[must_use] +#[no_mangle] +pub extern "C" fn ChannelMonitor_channel_id(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::lightning::ln::types::ChannelId { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_id(); + crate::lightning::ln::types::ChannelId { inner: ObjOps::heap_alloc(ret), is_owned: true } +} + /// Gets a list of txids, with their output scripts (in the order they appear in the /// transaction), which we must learn about spends of via block_connected(). #[must_use] #[no_mangle] pub extern "C" fn ChannelMonitor_get_outputs_to_watch(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_C2Tuple_ThirtyTwoBytesCVec_C2Tuple_u32CVec_u8ZZZZZ { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_outputs_to_watch(); - 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, orig_orig_ret_0_1_0_1.into_bytes().into()).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, orig_orig_ret_0_1_0_1.to_bytes().into()).into(); local_orig_ret_0_1_0 }); }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: *orig_ret_0_0.as_ref() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); }; local_ret.into() } @@ -976,8 +1078,8 @@ pub extern "C" fn ChannelMonitor_get_outputs_to_watch(this_arg: &crate::lightnin /// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs /// have been registered. #[no_mangle] -pub extern "C" fn ChannelMonitor_load_outputs_to_watch(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, filter: &crate::lightning::chain::Filter) { - unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.load_outputs_to_watch(filter) +pub extern "C" fn ChannelMonitor_load_outputs_to_watch(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, filter: &crate::lightning::chain::Filter, logger: &crate::lightning::util::logger::Logger) { + unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.load_outputs_to_watch(filter, logger) } /// Get the list of HTLCs who's status has been updated on chain. This should be called by @@ -1073,7 +1175,7 @@ pub extern "C" fn ChannelMonitor_counterparty_commitment_txs_from_update(this_ar /// to the commitment transaction being revoked, this will return a signed transaction, but /// the signature will not be valid. /// -/// [`EcdsaChannelSigner::sign_justice_revoked_output`]: crate::sign::EcdsaChannelSigner::sign_justice_revoked_output +/// [`EcdsaChannelSigner::sign_justice_revoked_output`]: crate::sign::ecdsa::EcdsaChannelSigner::sign_justice_revoked_output /// [`Persist`]: crate::chain::chainmonitor::Persist #[must_use] #[no_mangle] @@ -1097,26 +1199,18 @@ pub extern "C" fn ChannelMonitor_get_counterparty_node_id(this_arg: &crate::ligh local_ret } -/// Used by [`ChannelManager`] deserialization to broadcast the latest holder state if its copy -/// of the channel state was out-of-date. -/// -/// You may also use this to broadcast the latest local commitment transaction, either because +/// You may use this to broadcast the latest local commitment transaction, either because /// a monitor update failed or because we've fallen behind (i.e. we've received proof that our /// counterparty side knows a revocation secret we gave them that they shouldn't know). /// -/// Broadcasting these transactions in the second case is UNSAFE, as they allow counterparty +/// Broadcasting these transactions in this manner is UNSAFE, as they allow counterparty /// side to punish you. Nevertheless you may want to broadcast them if counterparty doesn't /// close channel with their commitment transaction after a substantial amount of time. Best /// may be to contact the other node operator out-of-band to coordinate other options available /// to you. -/// -/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager -#[must_use] #[no_mangle] -pub extern "C" fn ChannelMonitor_get_latest_holder_commitment_txn(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, logger: &crate::lightning::util::logger::Logger) -> crate::c_types::derived::CVec_TransactionZ { - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_latest_holder_commitment_txn(logger); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::Transaction::from_bitcoin(&item) }); }; - local_ret.into() +pub extern "C" fn ChannelMonitor_broadcast_latest_holder_commitment_txn(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, broadcaster: &crate::lightning::chain::chaininterface::BroadcasterInterface, fee_estimator: &crate::lightning::chain::chaininterface::FeeEstimator, logger: &crate::lightning::util::logger::Logger) { + unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.broadcast_latest_holder_commitment_txn(broadcaster, fee_estimator, logger) } /// Processes transactions in a newly connected block, which may result in any of the following: @@ -1132,17 +1226,17 @@ pub extern "C" fn ChannelMonitor_get_latest_holder_commitment_txn(this_arg: &cra /// [`get_outputs_to_watch`]: #method.get_outputs_to_watch #[must_use] #[no_mangle] -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 { +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, 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::>()[..], 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.as_ref() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); }; local_ret.into() } /// Determines if the disconnected block contained any transactions of interest and updates /// appropriately. #[no_mangle] -pub extern "C" fn ChannelMonitor_block_disconnected(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) { +pub extern "C" fn ChannelMonitor_block_disconnected(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, logger: &crate::lightning::util::logger::Logger) { unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height, broadcaster, fee_estimator, logger) } @@ -1155,10 +1249,10 @@ pub extern "C" fn ChannelMonitor_block_disconnected(this_arg: &crate::lightning: /// [`block_connected`]: Self::block_connected #[must_use] #[no_mangle] -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 { +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, 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::>()[..], 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.as_ref() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); }; local_ret.into() } @@ -1169,7 +1263,7 @@ pub extern "C" fn ChannelMonitor_transactions_confirmed(this_arg: &crate::lightn /// /// [`block_disconnected`]: Self::block_disconnected #[no_mangle] -pub extern "C" fn ChannelMonitor_transaction_unconfirmed(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, txid: *const [u8; 32], mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, mut logger: crate::lightning::util::logger::Logger) { +pub extern "C" fn ChannelMonitor_transaction_unconfirmed(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, txid: *const [u8; 32], mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, logger: &crate::lightning::util::logger::Logger) { unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.transaction_unconfirmed(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap(), broadcaster, fee_estimator, logger) } @@ -1182,18 +1276,18 @@ pub extern "C" fn ChannelMonitor_transaction_unconfirmed(this_arg: &crate::light /// [`block_connected`]: Self::block_connected #[must_use] #[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 { +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, 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.as_ref() }, 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_C2Tuple_ThirtyTwoBytesCOption_ThirtyTwoBytesZZZ { +pub extern "C" fn ChannelMonitor_get_relevant_txids(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_C3Tuple_ThirtyTwoBytesu32COption_ThirtyTwoBytesZZZ { 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( { 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_ThirtyTwoBytesZ::None } else { crate::c_types::derived::COption_ThirtyTwoBytesZ::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 }); }; + 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, mut orig_ret_0_2) = item; let mut local_orig_ret_0_2 = if orig_ret_0_2.is_none() { crate::c_types::derived::COption_ThirtyTwoBytesZ::None } else { crate::c_types::derived::COption_ThirtyTwoBytesZ::Some( { crate::c_types::ThirtyTwoBytes { data: *orig_ret_0_2.unwrap().as_ref() } }) }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: *orig_ret_0_0.as_ref() }, orig_ret_0_1, local_orig_ret_0_2).into(); local_ret_0 }); }; local_ret.into() } @@ -1212,10 +1306,17 @@ pub extern "C" fn ChannelMonitor_current_best_block(this_arg: &crate::lightning: /// 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) { +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, logger: &crate::lightning::util::logger::Logger) { unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.rebroadcast_pending_claims(broadcaster, fee_estimator, logger) } +/// Triggers rebroadcasts of pending claims from a force-closed channel after a transaction +/// signature generation failure. +#[no_mangle] +pub extern "C" fn ChannelMonitor_signer_unblocked(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, logger: &crate::lightning::util::logger::Logger) { + unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signer_unblocked(broadcaster, fee_estimator, logger) +} + /// Returns the descriptors for relevant outputs (i.e., those that we can spend) within the /// transaction if they exist and the transaction has at least [`ANTI_REORG_DELAY`] /// confirmations. For [`SpendableOutputDescriptor::DelayedPaymentOutput`] descriptors to be @@ -1242,6 +1343,18 @@ pub extern "C" fn ChannelMonitor_get_spendable_outputs(this_arg: &crate::lightni local_ret.into() } +/// Checks if the monitor is fully resolved. Resolved monitor is one that has claimed all of +/// its outputs and balances (i.e. [`Self::get_claimable_balances`] returns an empty set). +/// +/// This function returns true only if [`Self::get_claimable_balances`] has been empty for at least +/// 4032 blocks as an additional protection against any bugs resulting in spuriously empty balance sets. +#[must_use] +#[no_mangle] +pub extern "C" fn ChannelMonitor_is_fully_resolved(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, logger: &crate::lightning::util::logger::Logger) -> bool { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_fully_resolved(logger); + ret +} + /// 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). @@ -1270,7 +1383,7 @@ pub extern "C" fn C2Tuple_ThirtyTwoBytesChannelMonitorZ_read(ser: crate::c_types 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), 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() }; + let res: Result<(bitcoin::hash_types::BlockHash, lightning::chain::channelmonitor::ChannelMonitor), 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.as_ref() }, 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 }