1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! The logic to monitor for on-chain transactions and create the relevant claim responses lives
12 //! ChannelMonitor objects are generated by ChannelManager in response to relevant
13 //! messages/actions, and MUST be persisted to disk (and, preferably, remotely) before progress can
14 //! be made in responding to certain messages, see [`chain::Watch`] for more.
16 //! Note that ChannelMonitors are an important part of the lightning trust model and a copy of the
17 //! latest ChannelMonitor must always be actively monitoring for chain updates (and no out-of-date
18 //! ChannelMonitors should do so). Thus, if you're building rust-lightning into an HSM or other
19 //! security-domain-separated system design, you should consider having multiple paths for
20 //! ChannelMonitors to get out of the HSM and onto monitoring devices.
22 use alloc::str::FromStr;
23 use alloc::string::String;
24 use core::ffi::c_void;
25 use core::convert::Infallible;
26 use bitcoin::hashes::Hash;
27 use crate::c_types::*;
28 #[cfg(feature="no-std")]
29 use alloc::{vec::Vec, boxed::Box};
32 use lightning::chain::channelmonitor::ChannelMonitorUpdate as nativeChannelMonitorUpdateImport;
33 pub(crate) type nativeChannelMonitorUpdate = nativeChannelMonitorUpdateImport;
35 /// An update generated by the underlying channel itself which contains some new information the
36 /// [`ChannelMonitor`] should be made aware of.
38 /// Because this represents only a small number of updates to the underlying state, it is generally
39 /// much smaller than a full [`ChannelMonitor`]. However, for large single commitment transaction
40 /// updates (e.g. ones during which there are hundreds of HTLCs pending on the commitment
41 /// transaction), a single update may reach upwards of 1 MiB in serialized size.
44 pub struct ChannelMonitorUpdate {
45 /// A pointer to the opaque Rust object.
47 /// Nearly everywhere, inner must be non-null, however in places where
48 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
49 pub inner: *mut nativeChannelMonitorUpdate,
50 /// Indicates that this is the only struct which contains the same pointer.
52 /// Rust functions which take ownership of an object provided via an argument require
53 /// this to be true and invalidate the object pointed to by inner.
57 impl Drop for ChannelMonitorUpdate {
59 if self.is_owned && !<*mut nativeChannelMonitorUpdate>::is_null(self.inner) {
60 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
64 /// Frees any resources used by the ChannelMonitorUpdate, if is_owned is set and inner is non-NULL.
66 pub extern "C" fn ChannelMonitorUpdate_free(this_obj: ChannelMonitorUpdate) { }
68 /// Used only if an object of this type is returned as a trait impl by a method
69 pub(crate) extern "C" fn ChannelMonitorUpdate_free_void(this_ptr: *mut c_void) {
70 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelMonitorUpdate) };
73 impl ChannelMonitorUpdate {
74 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelMonitorUpdate {
75 unsafe { &*ObjOps::untweak_ptr(self.inner) }
77 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelMonitorUpdate {
78 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
80 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
81 pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitorUpdate {
82 assert!(self.is_owned);
83 let ret = ObjOps::untweak_ptr(self.inner);
84 self.inner = core::ptr::null_mut();
88 /// The sequence number of this update. Updates *must* be replayed in-order according to this
89 /// sequence number (and updates may panic if they are not). The update_id values are strictly
90 /// increasing and increase by one for each new update, with two exceptions specified below.
92 /// This sequence number is also used to track up to which points updates which returned
93 /// [`ChannelMonitorUpdateStatus::InProgress`] have been applied to all copies of a given
94 /// ChannelMonitor when ChannelManager::channel_monitor_updated is called.
96 /// The only instances we allow where update_id values are not strictly increasing have a
97 /// special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. This update ID is used for updates that
98 /// will force close the channel by broadcasting the latest commitment transaction or
99 /// special post-force-close updates, like providing preimages necessary to claim outputs on the
100 /// broadcast commitment transaction. See its docs for more details.
102 /// [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
104 pub extern "C" fn ChannelMonitorUpdate_get_update_id(this_ptr: &ChannelMonitorUpdate) -> u64 {
105 let mut inner_val = &mut this_ptr.get_native_mut_ref().update_id;
108 /// The sequence number of this update. Updates *must* be replayed in-order according to this
109 /// sequence number (and updates may panic if they are not). The update_id values are strictly
110 /// increasing and increase by one for each new update, with two exceptions specified below.
112 /// This sequence number is also used to track up to which points updates which returned
113 /// [`ChannelMonitorUpdateStatus::InProgress`] have been applied to all copies of a given
114 /// ChannelMonitor when ChannelManager::channel_monitor_updated is called.
116 /// The only instances we allow where update_id values are not strictly increasing have a
117 /// special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. This update ID is used for updates that
118 /// will force close the channel by broadcasting the latest commitment transaction or
119 /// special post-force-close updates, like providing preimages necessary to claim outputs on the
120 /// broadcast commitment transaction. See its docs for more details.
122 /// [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
124 pub extern "C" fn ChannelMonitorUpdate_set_update_id(this_ptr: &mut ChannelMonitorUpdate, mut val: u64) {
125 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.update_id = val;
127 impl Clone for ChannelMonitorUpdate {
128 fn clone(&self) -> Self {
130 inner: if <*mut nativeChannelMonitorUpdate>::is_null(self.inner) { core::ptr::null_mut() } else {
131 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
137 /// Used only if an object of this type is returned as a trait impl by a method
138 pub(crate) extern "C" fn ChannelMonitorUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
139 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelMonitorUpdate)).clone() })) as *mut c_void
142 /// Creates a copy of the ChannelMonitorUpdate
143 pub extern "C" fn ChannelMonitorUpdate_clone(orig: &ChannelMonitorUpdate) -> ChannelMonitorUpdate {
146 /// Get a string which allows debug introspection of a ChannelMonitorUpdate object
147 pub extern "C" fn ChannelMonitorUpdate_debug_str_void(o: *const c_void) -> Str {
148 alloc::format!("{:?}", unsafe { o as *const crate::lightning::chain::channelmonitor::ChannelMonitorUpdate }).into()}
149 /// Checks if two ChannelMonitorUpdates contain equal inner contents.
150 /// This ignores pointers and is_owned flags and looks at the values in fields.
151 /// Two objects with NULL inner values will be considered "equal" here.
153 pub extern "C" fn ChannelMonitorUpdate_eq(a: &ChannelMonitorUpdate, b: &ChannelMonitorUpdate) -> bool {
154 if a.inner == b.inner { return true; }
155 if a.inner.is_null() || b.inner.is_null() { return false; }
156 if a.get_native_ref() == b.get_native_ref() { true } else { false }
158 /// The update ID used for a [`ChannelMonitorUpdate`] that is either:
160 ///\t(1) attempting to force close the channel by broadcasting our latest commitment transaction or
161 ///\t(2) providing a preimage (after the channel has been force closed) from a forward link that
162 ///\t\tallows us to spend an HTLC output on this channel's (the backward link's) broadcasted
163 ///\t\tcommitment transaction.
165 /// No other [`ChannelMonitorUpdate`]s are allowed after force-close.
168 pub static CLOSED_CHANNEL_UPDATE_ID: u64 = lightning::chain::channelmonitor::CLOSED_CHANNEL_UPDATE_ID;
170 /// Serialize the ChannelMonitorUpdate object into a byte array which can be read by ChannelMonitorUpdate_read
171 pub extern "C" fn ChannelMonitorUpdate_write(obj: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate) -> crate::c_types::derived::CVec_u8Z {
172 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
175 pub(crate) extern "C" fn ChannelMonitorUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
176 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitorUpdate) })
179 /// Read a ChannelMonitorUpdate from a byte array, created by ChannelMonitorUpdate_write
180 pub extern "C" fn ChannelMonitorUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelMonitorUpdateDecodeErrorZ {
181 let res: Result<lightning::chain::channelmonitor::ChannelMonitorUpdate, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
182 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::channelmonitor::ChannelMonitorUpdate { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
185 /// An event to be processed by the ChannelManager.
189 pub enum MonitorEvent {
190 /// A monitor event containing an HTLCUpdate.
192 crate::lightning::chain::channelmonitor::HTLCUpdate),
193 /// Indicates we broadcasted the channel's latest commitment transaction and thus closed the
196 crate::lightning::chain::transaction::OutPoint),
197 /// Indicates a [`ChannelMonitor`] update has completed. See
198 /// [`ChannelMonitorUpdateStatus::InProgress`] for more information on how this is used.
200 /// [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
202 /// The funding outpoint of the [`ChannelMonitor`] that was updated
203 funding_txo: crate::lightning::chain::transaction::OutPoint,
204 /// The Update ID from [`ChannelMonitorUpdate::update_id`] which was applied or
205 /// [`ChannelMonitor::get_latest_update_id`].
207 /// Note that this should only be set to a given update's ID if all previous updates for the
208 /// same [`ChannelMonitor`] have been applied and persisted.
209 monitor_update_id: u64,
212 use lightning::chain::channelmonitor::MonitorEvent as MonitorEventImport;
213 pub(crate) type nativeMonitorEvent = MonitorEventImport;
217 pub(crate) fn to_native(&self) -> nativeMonitorEvent {
219 MonitorEvent::HTLCEvent (ref a, ) => {
220 let mut a_nonref = Clone::clone(a);
221 nativeMonitorEvent::HTLCEvent (
222 *unsafe { Box::from_raw(a_nonref.take_inner()) },
225 MonitorEvent::HolderForceClosed (ref a, ) => {
226 let mut a_nonref = Clone::clone(a);
227 nativeMonitorEvent::HolderForceClosed (
228 *unsafe { Box::from_raw(a_nonref.take_inner()) },
231 MonitorEvent::Completed {ref funding_txo, ref monitor_update_id, } => {
232 let mut funding_txo_nonref = Clone::clone(funding_txo);
233 let mut monitor_update_id_nonref = Clone::clone(monitor_update_id);
234 nativeMonitorEvent::Completed {
235 funding_txo: *unsafe { Box::from_raw(funding_txo_nonref.take_inner()) },
236 monitor_update_id: monitor_update_id_nonref,
242 pub(crate) fn into_native(self) -> nativeMonitorEvent {
244 MonitorEvent::HTLCEvent (mut a, ) => {
245 nativeMonitorEvent::HTLCEvent (
246 *unsafe { Box::from_raw(a.take_inner()) },
249 MonitorEvent::HolderForceClosed (mut a, ) => {
250 nativeMonitorEvent::HolderForceClosed (
251 *unsafe { Box::from_raw(a.take_inner()) },
254 MonitorEvent::Completed {mut funding_txo, mut monitor_update_id, } => {
255 nativeMonitorEvent::Completed {
256 funding_txo: *unsafe { Box::from_raw(funding_txo.take_inner()) },
257 monitor_update_id: monitor_update_id,
263 pub(crate) fn from_native(native: &MonitorEventImport) -> Self {
264 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeMonitorEvent) };
266 nativeMonitorEvent::HTLCEvent (ref a, ) => {
267 let mut a_nonref = Clone::clone(a);
268 MonitorEvent::HTLCEvent (
269 crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
272 nativeMonitorEvent::HolderForceClosed (ref a, ) => {
273 let mut a_nonref = Clone::clone(a);
274 MonitorEvent::HolderForceClosed (
275 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
278 nativeMonitorEvent::Completed {ref funding_txo, ref monitor_update_id, } => {
279 let mut funding_txo_nonref = Clone::clone(funding_txo);
280 let mut monitor_update_id_nonref = Clone::clone(monitor_update_id);
281 MonitorEvent::Completed {
282 funding_txo: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo_nonref), is_owned: true },
283 monitor_update_id: monitor_update_id_nonref,
289 pub(crate) fn native_into(native: nativeMonitorEvent) -> Self {
291 nativeMonitorEvent::HTLCEvent (mut a, ) => {
292 MonitorEvent::HTLCEvent (
293 crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a), is_owned: true },
296 nativeMonitorEvent::HolderForceClosed (mut a, ) => {
297 MonitorEvent::HolderForceClosed (
298 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a), is_owned: true },
301 nativeMonitorEvent::Completed {mut funding_txo, mut monitor_update_id, } => {
302 MonitorEvent::Completed {
303 funding_txo: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo), is_owned: true },
304 monitor_update_id: monitor_update_id,
310 /// Frees any resources used by the MonitorEvent
312 pub extern "C" fn MonitorEvent_free(this_ptr: MonitorEvent) { }
313 /// Creates a copy of the MonitorEvent
315 pub extern "C" fn MonitorEvent_clone(orig: &MonitorEvent) -> MonitorEvent {
319 /// Used only if an object of this type is returned as a trait impl by a method
320 pub(crate) extern "C" fn MonitorEvent_clone_void(this_ptr: *const c_void) -> *mut c_void {
321 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const MonitorEvent)).clone() })) as *mut c_void
324 /// Used only if an object of this type is returned as a trait impl by a method
325 pub(crate) extern "C" fn MonitorEvent_free_void(this_ptr: *mut c_void) {
326 let _ = unsafe { Box::from_raw(this_ptr as *mut MonitorEvent) };
329 /// Utility method to constructs a new HTLCEvent-variant MonitorEvent
330 pub extern "C" fn MonitorEvent_htlcevent(a: crate::lightning::chain::channelmonitor::HTLCUpdate) -> MonitorEvent {
331 MonitorEvent::HTLCEvent(a, )
334 /// Utility method to constructs a new HolderForceClosed-variant MonitorEvent
335 pub extern "C" fn MonitorEvent_holder_force_closed(a: crate::lightning::chain::transaction::OutPoint) -> MonitorEvent {
336 MonitorEvent::HolderForceClosed(a, )
339 /// Utility method to constructs a new Completed-variant MonitorEvent
340 pub extern "C" fn MonitorEvent_completed(funding_txo: crate::lightning::chain::transaction::OutPoint, monitor_update_id: u64) -> MonitorEvent {
341 MonitorEvent::Completed {
346 /// Checks if two MonitorEvents contain equal inner contents.
347 /// This ignores pointers and is_owned flags and looks at the values in fields.
349 pub extern "C" fn MonitorEvent_eq(a: &MonitorEvent, b: &MonitorEvent) -> bool {
350 if &a.to_native() == &b.to_native() { true } else { false }
353 /// Serialize the MonitorEvent object into a byte array which can be read by MonitorEvent_read
354 pub extern "C" fn MonitorEvent_write(obj: &crate::lightning::chain::channelmonitor::MonitorEvent) -> crate::c_types::derived::CVec_u8Z {
355 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
358 pub(crate) extern "C" fn MonitorEvent_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
359 MonitorEvent_write(unsafe { &*(obj as *const MonitorEvent) })
362 /// Read a MonitorEvent from a byte array, created by MonitorEvent_write
363 pub extern "C" fn MonitorEvent_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_MonitorEventZDecodeErrorZ {
364 let res: Result<Option<lightning::chain::channelmonitor::MonitorEvent>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
365 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_MonitorEventZ::None } else { crate::c_types::derived::COption_MonitorEventZ::Some( { crate::lightning::chain::channelmonitor::MonitorEvent::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
369 use lightning::chain::channelmonitor::HTLCUpdate as nativeHTLCUpdateImport;
370 pub(crate) type nativeHTLCUpdate = nativeHTLCUpdateImport;
372 /// Simple structure sent back by `chain::Watch` when an HTLC from a forward channel is detected on
373 /// chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the
374 /// preimage claim backward will lead to loss of funds.
377 pub struct HTLCUpdate {
378 /// A pointer to the opaque Rust object.
380 /// Nearly everywhere, inner must be non-null, however in places where
381 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
382 pub inner: *mut nativeHTLCUpdate,
383 /// Indicates that this is the only struct which contains the same pointer.
385 /// Rust functions which take ownership of an object provided via an argument require
386 /// this to be true and invalidate the object pointed to by inner.
390 impl Drop for HTLCUpdate {
392 if self.is_owned && !<*mut nativeHTLCUpdate>::is_null(self.inner) {
393 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
397 /// Frees any resources used by the HTLCUpdate, if is_owned is set and inner is non-NULL.
399 pub extern "C" fn HTLCUpdate_free(this_obj: HTLCUpdate) { }
401 /// Used only if an object of this type is returned as a trait impl by a method
402 pub(crate) extern "C" fn HTLCUpdate_free_void(this_ptr: *mut c_void) {
403 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeHTLCUpdate) };
407 pub(crate) fn get_native_ref(&self) -> &'static nativeHTLCUpdate {
408 unsafe { &*ObjOps::untweak_ptr(self.inner) }
410 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHTLCUpdate {
411 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
413 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
414 pub(crate) fn take_inner(mut self) -> *mut nativeHTLCUpdate {
415 assert!(self.is_owned);
416 let ret = ObjOps::untweak_ptr(self.inner);
417 self.inner = core::ptr::null_mut();
421 impl Clone for HTLCUpdate {
422 fn clone(&self) -> Self {
424 inner: if <*mut nativeHTLCUpdate>::is_null(self.inner) { core::ptr::null_mut() } else {
425 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
431 /// Used only if an object of this type is returned as a trait impl by a method
432 pub(crate) extern "C" fn HTLCUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
433 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeHTLCUpdate)).clone() })) as *mut c_void
436 /// Creates a copy of the HTLCUpdate
437 pub extern "C" fn HTLCUpdate_clone(orig: &HTLCUpdate) -> HTLCUpdate {
440 /// Checks if two HTLCUpdates contain equal inner contents.
441 /// This ignores pointers and is_owned flags and looks at the values in fields.
442 /// Two objects with NULL inner values will be considered "equal" here.
444 pub extern "C" fn HTLCUpdate_eq(a: &HTLCUpdate, b: &HTLCUpdate) -> bool {
445 if a.inner == b.inner { return true; }
446 if a.inner.is_null() || b.inner.is_null() { return false; }
447 if a.get_native_ref() == b.get_native_ref() { true } else { false }
450 /// Serialize the HTLCUpdate object into a byte array which can be read by HTLCUpdate_read
451 pub extern "C" fn HTLCUpdate_write(obj: &crate::lightning::chain::channelmonitor::HTLCUpdate) -> crate::c_types::derived::CVec_u8Z {
452 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
455 pub(crate) extern "C" fn HTLCUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
456 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCUpdate) })
459 /// Read a HTLCUpdate from a byte array, created by HTLCUpdate_write
460 pub extern "C" fn HTLCUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCUpdateDecodeErrorZ {
461 let res: Result<lightning::chain::channelmonitor::HTLCUpdate, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
462 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
465 /// Number of blocks we wait on seeing a HTLC output being solved before we fail corresponding
466 /// inbound HTLCs. This prevents us from failing backwards and then getting a reorg resulting in us
469 /// Note that this is a library-wide security assumption. If a reorg deeper than this number of
470 /// blocks occurs, counterparties may be able to steal funds or claims made by and balances exposed
471 /// by a [`ChannelMonitor`] may be incorrect.
474 pub static ANTI_REORG_DELAY: u32 = lightning::chain::channelmonitor::ANTI_REORG_DELAY;
475 /// Details about the balance(s) available for spending once the channel appears on chain.
477 /// See [`ChannelMonitor::get_claimable_balances`] for more details on when these will or will not
483 /// The channel is not yet closed (or the commitment or closing transaction has not yet
484 /// appeared in a block). The given balance is claimable (less on-chain fees) if the channel is
485 /// force-closed now.
486 ClaimableOnChannelClose {
487 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
488 /// required to do so.
489 amount_satoshis: u64,
491 /// The channel has been closed, and the given balance is ours but awaiting confirmations until
492 /// we consider it spendable.
493 ClaimableAwaitingConfirmations {
494 /// The amount available to claim, in satoshis, possibly excluding the on-chain fees which
495 /// were spent in broadcasting the transaction.
496 amount_satoshis: u64,
497 /// The height at which an [`Event::SpendableOutputs`] event will be generated for this
499 confirmation_height: u32,
501 /// The channel has been closed, and the given balance should be ours but awaiting spending
502 /// transaction confirmation. If the spending transaction does not confirm in time, it is
503 /// possible our counterparty can take the funds by broadcasting an HTLC timeout on-chain.
505 /// Once the spending transaction confirms, before it has reached enough confirmations to be
506 /// considered safe from chain reorganizations, the balance will instead be provided via
507 /// [`Balance::ClaimableAwaitingConfirmations`].
508 ContentiousClaimable {
509 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
510 /// required to do so.
511 amount_satoshis: u64,
512 /// The height at which the counterparty may be able to claim the balance if we have not
515 /// The payment hash that locks this HTLC.
516 payment_hash: crate::c_types::ThirtyTwoBytes,
517 /// The preimage that can be used to claim this HTLC.
518 payment_preimage: crate::c_types::ThirtyTwoBytes,
520 /// HTLCs which we sent to our counterparty which are claimable after a timeout (less on-chain
521 /// fees) if the counterparty does not know the preimage for the HTLCs. These are somewhat
522 /// likely to be claimed by our counterparty before we do.
523 MaybeTimeoutClaimableHTLC {
524 /// The amount potentially available to claim, in satoshis, excluding the on-chain fees
525 /// which will be required to do so.
526 amount_satoshis: u64,
527 /// The height at which we will be able to claim the balance if our counterparty has not
529 claimable_height: u32,
530 /// The payment hash whose preimage our counterparty needs to claim this HTLC.
531 payment_hash: crate::c_types::ThirtyTwoBytes,
533 /// HTLCs which we received from our counterparty which are claimable with a preimage which we
534 /// do not currently have. This will only be claimable if we receive the preimage from the node
535 /// to which we forwarded this HTLC before the timeout.
536 MaybePreimageClaimableHTLC {
537 /// The amount potentially available to claim, in satoshis, excluding the on-chain fees
538 /// which will be required to do so.
539 amount_satoshis: u64,
540 /// The height at which our counterparty will be able to claim the balance if we have not
541 /// yet received the preimage and claimed it ourselves.
543 /// The payment hash whose preimage we need to claim this HTLC.
544 payment_hash: crate::c_types::ThirtyTwoBytes,
546 /// The channel has been closed, and our counterparty broadcasted a revoked commitment
549 /// Thus, we're able to claim all outputs in the commitment transaction, one of which has the
550 /// following amount.
551 CounterpartyRevokedOutputClaimable {
552 /// The amount, in satoshis, of the output which we can claim.
554 /// Note that for outputs from HTLC balances this may be excluding some on-chain fees that
555 /// were already spent.
556 amount_satoshis: u64,
559 use lightning::chain::channelmonitor::Balance as BalanceImport;
560 pub(crate) type nativeBalance = BalanceImport;
564 pub(crate) fn to_native(&self) -> nativeBalance {
566 Balance::ClaimableOnChannelClose {ref amount_satoshis, } => {
567 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
568 nativeBalance::ClaimableOnChannelClose {
569 amount_satoshis: amount_satoshis_nonref,
572 Balance::ClaimableAwaitingConfirmations {ref amount_satoshis, ref confirmation_height, } => {
573 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
574 let mut confirmation_height_nonref = Clone::clone(confirmation_height);
575 nativeBalance::ClaimableAwaitingConfirmations {
576 amount_satoshis: amount_satoshis_nonref,
577 confirmation_height: confirmation_height_nonref,
580 Balance::ContentiousClaimable {ref amount_satoshis, ref timeout_height, ref payment_hash, ref payment_preimage, } => {
581 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
582 let mut timeout_height_nonref = Clone::clone(timeout_height);
583 let mut payment_hash_nonref = Clone::clone(payment_hash);
584 let mut payment_preimage_nonref = Clone::clone(payment_preimage);
585 nativeBalance::ContentiousClaimable {
586 amount_satoshis: amount_satoshis_nonref,
587 timeout_height: timeout_height_nonref,
588 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
589 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
592 Balance::MaybeTimeoutClaimableHTLC {ref amount_satoshis, ref claimable_height, ref payment_hash, } => {
593 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
594 let mut claimable_height_nonref = Clone::clone(claimable_height);
595 let mut payment_hash_nonref = Clone::clone(payment_hash);
596 nativeBalance::MaybeTimeoutClaimableHTLC {
597 amount_satoshis: amount_satoshis_nonref,
598 claimable_height: claimable_height_nonref,
599 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
602 Balance::MaybePreimageClaimableHTLC {ref amount_satoshis, ref expiry_height, ref payment_hash, } => {
603 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
604 let mut expiry_height_nonref = Clone::clone(expiry_height);
605 let mut payment_hash_nonref = Clone::clone(payment_hash);
606 nativeBalance::MaybePreimageClaimableHTLC {
607 amount_satoshis: amount_satoshis_nonref,
608 expiry_height: expiry_height_nonref,
609 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
612 Balance::CounterpartyRevokedOutputClaimable {ref amount_satoshis, } => {
613 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
614 nativeBalance::CounterpartyRevokedOutputClaimable {
615 amount_satoshis: amount_satoshis_nonref,
621 pub(crate) fn into_native(self) -> nativeBalance {
623 Balance::ClaimableOnChannelClose {mut amount_satoshis, } => {
624 nativeBalance::ClaimableOnChannelClose {
625 amount_satoshis: amount_satoshis,
628 Balance::ClaimableAwaitingConfirmations {mut amount_satoshis, mut confirmation_height, } => {
629 nativeBalance::ClaimableAwaitingConfirmations {
630 amount_satoshis: amount_satoshis,
631 confirmation_height: confirmation_height,
634 Balance::ContentiousClaimable {mut amount_satoshis, mut timeout_height, mut payment_hash, mut payment_preimage, } => {
635 nativeBalance::ContentiousClaimable {
636 amount_satoshis: amount_satoshis,
637 timeout_height: timeout_height,
638 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
639 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
642 Balance::MaybeTimeoutClaimableHTLC {mut amount_satoshis, mut claimable_height, mut payment_hash, } => {
643 nativeBalance::MaybeTimeoutClaimableHTLC {
644 amount_satoshis: amount_satoshis,
645 claimable_height: claimable_height,
646 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
649 Balance::MaybePreimageClaimableHTLC {mut amount_satoshis, mut expiry_height, mut payment_hash, } => {
650 nativeBalance::MaybePreimageClaimableHTLC {
651 amount_satoshis: amount_satoshis,
652 expiry_height: expiry_height,
653 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
656 Balance::CounterpartyRevokedOutputClaimable {mut amount_satoshis, } => {
657 nativeBalance::CounterpartyRevokedOutputClaimable {
658 amount_satoshis: amount_satoshis,
664 pub(crate) fn from_native(native: &BalanceImport) -> Self {
665 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeBalance) };
667 nativeBalance::ClaimableOnChannelClose {ref amount_satoshis, } => {
668 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
669 Balance::ClaimableOnChannelClose {
670 amount_satoshis: amount_satoshis_nonref,
673 nativeBalance::ClaimableAwaitingConfirmations {ref amount_satoshis, ref confirmation_height, } => {
674 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
675 let mut confirmation_height_nonref = Clone::clone(confirmation_height);
676 Balance::ClaimableAwaitingConfirmations {
677 amount_satoshis: amount_satoshis_nonref,
678 confirmation_height: confirmation_height_nonref,
681 nativeBalance::ContentiousClaimable {ref amount_satoshis, ref timeout_height, ref payment_hash, ref payment_preimage, } => {
682 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
683 let mut timeout_height_nonref = Clone::clone(timeout_height);
684 let mut payment_hash_nonref = Clone::clone(payment_hash);
685 let mut payment_preimage_nonref = Clone::clone(payment_preimage);
686 Balance::ContentiousClaimable {
687 amount_satoshis: amount_satoshis_nonref,
688 timeout_height: timeout_height_nonref,
689 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
690 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
693 nativeBalance::MaybeTimeoutClaimableHTLC {ref amount_satoshis, ref claimable_height, ref payment_hash, } => {
694 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
695 let mut claimable_height_nonref = Clone::clone(claimable_height);
696 let mut payment_hash_nonref = Clone::clone(payment_hash);
697 Balance::MaybeTimeoutClaimableHTLC {
698 amount_satoshis: amount_satoshis_nonref,
699 claimable_height: claimable_height_nonref,
700 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
703 nativeBalance::MaybePreimageClaimableHTLC {ref amount_satoshis, ref expiry_height, ref payment_hash, } => {
704 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
705 let mut expiry_height_nonref = Clone::clone(expiry_height);
706 let mut payment_hash_nonref = Clone::clone(payment_hash);
707 Balance::MaybePreimageClaimableHTLC {
708 amount_satoshis: amount_satoshis_nonref,
709 expiry_height: expiry_height_nonref,
710 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
713 nativeBalance::CounterpartyRevokedOutputClaimable {ref amount_satoshis, } => {
714 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
715 Balance::CounterpartyRevokedOutputClaimable {
716 amount_satoshis: amount_satoshis_nonref,
722 pub(crate) fn native_into(native: nativeBalance) -> Self {
724 nativeBalance::ClaimableOnChannelClose {mut amount_satoshis, } => {
725 Balance::ClaimableOnChannelClose {
726 amount_satoshis: amount_satoshis,
729 nativeBalance::ClaimableAwaitingConfirmations {mut amount_satoshis, mut confirmation_height, } => {
730 Balance::ClaimableAwaitingConfirmations {
731 amount_satoshis: amount_satoshis,
732 confirmation_height: confirmation_height,
735 nativeBalance::ContentiousClaimable {mut amount_satoshis, mut timeout_height, mut payment_hash, mut payment_preimage, } => {
736 Balance::ContentiousClaimable {
737 amount_satoshis: amount_satoshis,
738 timeout_height: timeout_height,
739 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
740 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
743 nativeBalance::MaybeTimeoutClaimableHTLC {mut amount_satoshis, mut claimable_height, mut payment_hash, } => {
744 Balance::MaybeTimeoutClaimableHTLC {
745 amount_satoshis: amount_satoshis,
746 claimable_height: claimable_height,
747 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
750 nativeBalance::MaybePreimageClaimableHTLC {mut amount_satoshis, mut expiry_height, mut payment_hash, } => {
751 Balance::MaybePreimageClaimableHTLC {
752 amount_satoshis: amount_satoshis,
753 expiry_height: expiry_height,
754 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
757 nativeBalance::CounterpartyRevokedOutputClaimable {mut amount_satoshis, } => {
758 Balance::CounterpartyRevokedOutputClaimable {
759 amount_satoshis: amount_satoshis,
765 /// Frees any resources used by the Balance
767 pub extern "C" fn Balance_free(this_ptr: Balance) { }
768 /// Creates a copy of the Balance
770 pub extern "C" fn Balance_clone(orig: &Balance) -> Balance {
774 /// Used only if an object of this type is returned as a trait impl by a method
775 pub(crate) extern "C" fn Balance_clone_void(this_ptr: *const c_void) -> *mut c_void {
776 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Balance)).clone() })) as *mut c_void
779 /// Used only if an object of this type is returned as a trait impl by a method
780 pub(crate) extern "C" fn Balance_free_void(this_ptr: *mut c_void) {
781 let _ = unsafe { Box::from_raw(this_ptr as *mut Balance) };
784 /// Utility method to constructs a new ClaimableOnChannelClose-variant Balance
785 pub extern "C" fn Balance_claimable_on_channel_close(amount_satoshis: u64) -> Balance {
786 Balance::ClaimableOnChannelClose {
791 /// Utility method to constructs a new ClaimableAwaitingConfirmations-variant Balance
792 pub extern "C" fn Balance_claimable_awaiting_confirmations(amount_satoshis: u64, confirmation_height: u32) -> Balance {
793 Balance::ClaimableAwaitingConfirmations {
799 /// Utility method to constructs a new ContentiousClaimable-variant Balance
800 pub extern "C" fn Balance_contentious_claimable(amount_satoshis: u64, timeout_height: u32, payment_hash: crate::c_types::ThirtyTwoBytes, payment_preimage: crate::c_types::ThirtyTwoBytes) -> Balance {
801 Balance::ContentiousClaimable {
809 /// Utility method to constructs a new MaybeTimeoutClaimableHTLC-variant Balance
810 pub extern "C" fn Balance_maybe_timeout_claimable_htlc(amount_satoshis: u64, claimable_height: u32, payment_hash: crate::c_types::ThirtyTwoBytes) -> Balance {
811 Balance::MaybeTimeoutClaimableHTLC {
818 /// Utility method to constructs a new MaybePreimageClaimableHTLC-variant Balance
819 pub extern "C" fn Balance_maybe_preimage_claimable_htlc(amount_satoshis: u64, expiry_height: u32, payment_hash: crate::c_types::ThirtyTwoBytes) -> Balance {
820 Balance::MaybePreimageClaimableHTLC {
827 /// Utility method to constructs a new CounterpartyRevokedOutputClaimable-variant Balance
828 pub extern "C" fn Balance_counterparty_revoked_output_claimable(amount_satoshis: u64) -> Balance {
829 Balance::CounterpartyRevokedOutputClaimable {
833 /// Get a string which allows debug introspection of a Balance object
834 pub extern "C" fn Balance_debug_str_void(o: *const c_void) -> Str {
835 alloc::format!("{:?}", unsafe { o as *const crate::lightning::chain::channelmonitor::Balance }).into()}
836 /// Checks if two Balances contain equal inner contents.
837 /// This ignores pointers and is_owned flags and looks at the values in fields.
839 pub extern "C" fn Balance_eq(a: &Balance, b: &Balance) -> bool {
840 if &a.to_native() == &b.to_native() { true } else { false }
842 /// The amount claimable, in satoshis. This excludes balances that we are unsure if we are able
843 /// to claim, this is because we are waiting for a preimage or for a timeout to expire. For more
844 /// information on these balances see [`Balance::MaybeTimeoutClaimableHTLC`] and
845 /// [`Balance::MaybePreimageClaimableHTLC`].
847 /// On-chain fees required to claim the balance are not included in this amount.
850 pub extern "C" fn Balance_claimable_amount_satoshis(this_arg: &crate::lightning::chain::channelmonitor::Balance) -> u64 {
851 let mut ret = this_arg.to_native().claimable_amount_satoshis();
856 use lightning::chain::channelmonitor::ChannelMonitor as nativeChannelMonitorImport;
857 pub(crate) type nativeChannelMonitor = nativeChannelMonitorImport<crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner>;
859 /// A ChannelMonitor handles chain events (blocks connected and disconnected) and generates
860 /// on-chain transactions to ensure no loss of funds occurs.
862 /// You MUST ensure that no ChannelMonitors for a given channel anywhere contain out-of-date
863 /// information and are actively monitoring the chain.
865 /// Note that the deserializer is only implemented for (BlockHash, ChannelMonitor), which
866 /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
867 /// the \"reorg path\" (ie disconnecting blocks until you find a common ancestor from both the
868 /// returned block hash and the the current chain and then reconnecting blocks to get to the
869 /// best chain) upon deserializing the object!
872 pub struct ChannelMonitor {
873 /// A pointer to the opaque Rust object.
875 /// Nearly everywhere, inner must be non-null, however in places where
876 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
877 pub inner: *mut nativeChannelMonitor,
878 /// Indicates that this is the only struct which contains the same pointer.
880 /// Rust functions which take ownership of an object provided via an argument require
881 /// this to be true and invalidate the object pointed to by inner.
885 impl Drop for ChannelMonitor {
887 if self.is_owned && !<*mut nativeChannelMonitor>::is_null(self.inner) {
888 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
892 /// Frees any resources used by the ChannelMonitor, if is_owned is set and inner is non-NULL.
894 pub extern "C" fn ChannelMonitor_free(this_obj: ChannelMonitor) { }
896 /// Used only if an object of this type is returned as a trait impl by a method
897 pub(crate) extern "C" fn ChannelMonitor_free_void(this_ptr: *mut c_void) {
898 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelMonitor) };
901 impl ChannelMonitor {
902 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelMonitor {
903 unsafe { &*ObjOps::untweak_ptr(self.inner) }
905 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelMonitor {
906 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
908 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
909 pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitor {
910 assert!(self.is_owned);
911 let ret = ObjOps::untweak_ptr(self.inner);
912 self.inner = core::ptr::null_mut();
916 impl Clone for ChannelMonitor {
917 fn clone(&self) -> Self {
919 inner: if <*mut nativeChannelMonitor>::is_null(self.inner) { core::ptr::null_mut() } else {
920 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
926 /// Used only if an object of this type is returned as a trait impl by a method
927 pub(crate) extern "C" fn ChannelMonitor_clone_void(this_ptr: *const c_void) -> *mut c_void {
928 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelMonitor)).clone() })) as *mut c_void
931 /// Creates a copy of the ChannelMonitor
932 pub extern "C" fn ChannelMonitor_clone(orig: &ChannelMonitor) -> ChannelMonitor {
936 /// Serialize the ChannelMonitor object into a byte array which can be read by ChannelMonitor_read
937 pub extern "C" fn ChannelMonitor_write(obj: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_u8Z {
938 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
941 pub(crate) extern "C" fn ChannelMonitor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
942 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitor) })
944 /// Updates a ChannelMonitor on the basis of some new information provided by the Channel
947 /// panics if the given update is not the next update by update_id.
950 pub extern "C" fn ChannelMonitor_update_monitor(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, updates: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate, broadcaster: &crate::lightning::chain::chaininterface::BroadcasterInterface, fee_estimator: &crate::lightning::chain::chaininterface::FeeEstimator, logger: &crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_NoneNoneZ {
951 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_monitor(updates.get_native_ref(), broadcaster, fee_estimator, logger);
952 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
956 /// Gets the update_id from the latest ChannelMonitorUpdate which was applied to this
960 pub extern "C" fn ChannelMonitor_get_latest_update_id(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> u64 {
961 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_latest_update_id();
965 /// Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for.
968 pub extern "C" fn ChannelMonitor_get_funding_txo(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::C2Tuple_OutPointCVec_u8ZZ {
969 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_funding_txo();
970 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();
974 /// Gets a list of txids, with their output scripts (in the order they appear in the
975 /// transaction), which we must learn about spends of via block_connected().
978 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 {
979 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_outputs_to_watch();
980 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 }); };
984 /// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly
985 /// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs
986 /// have been registered.
988 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) {
989 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.load_outputs_to_watch(filter, logger)
992 /// Get the list of HTLCs who's status has been updated on chain. This should be called by
993 /// ChannelManager via [`chain::Watch::release_pending_monitor_events`].
996 pub extern "C" fn ChannelMonitor_get_and_clear_pending_monitor_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_MonitorEventZ {
997 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_and_clear_pending_monitor_events();
998 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::MonitorEvent::native_into(item) }); };
1002 /// Processes [`SpendableOutputs`] events produced from each [`ChannelMonitor`] upon maturity.
1004 /// For channels featuring anchor outputs, this method will also process [`BumpTransaction`]
1005 /// events produced from each [`ChannelMonitor`] while there is a balance to claim onchain
1006 /// within each channel. As the confirmation of a commitment transaction may be critical to the
1007 /// safety of funds, we recommend invoking this every 30 seconds, or lower if running in an
1008 /// environment with spotty connections, like on mobile.
1010 /// An [`EventHandler`] may safely call back to the provider, though this shouldn't be needed in
1011 /// order to handle these events.
1013 /// [`SpendableOutputs`]: crate::events::Event::SpendableOutputs
1014 /// [`BumpTransaction`]: crate::events::Event::BumpTransaction
1016 pub extern "C" fn ChannelMonitor_process_pending_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, handler: &crate::lightning::events::EventHandler) {
1017 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_pending_events(handler)
1020 /// Gets the counterparty's initial commitment transaction. The returned commitment
1021 /// transaction is unsigned. This is intended to be called during the initial persistence of
1022 /// the monitor (inside an implementation of [`Persist::persist_new_channel`]), to allow for
1023 /// watchtowers in the persistence pipeline to have enough data to form justice transactions.
1025 /// This is similar to [`Self::counterparty_commitment_txs_from_update`], except
1026 /// that for the initial commitment transaction, we don't have a corresponding update.
1028 /// This will only return `Some` for channel monitors that have been created after upgrading
1029 /// to LDK 0.0.117+.
1031 /// [`Persist::persist_new_channel`]: crate::chain::chainmonitor::Persist::persist_new_channel
1033 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1036 pub extern "C" fn ChannelMonitor_initial_counterparty_commitment_tx(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::lightning::ln::chan_utils::CommitmentTransaction {
1037 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.initial_counterparty_commitment_tx();
1038 let mut local_ret = crate::lightning::ln::chan_utils::CommitmentTransaction { inner: if ret.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true };
1042 /// Gets all of the counterparty commitment transactions provided by the given update. This
1043 /// may be empty if the update doesn't include any new counterparty commitments. Returned
1044 /// commitment transactions are unsigned.
1046 /// This is provided so that watchtower clients in the persistence pipeline are able to build
1047 /// justice transactions for each counterparty commitment upon each update. It's intended to be
1048 /// used within an implementation of [`Persist::update_persisted_channel`], which is provided
1049 /// with a monitor and an update. Once revoked, signing a justice transaction can be done using
1050 /// [`Self::sign_to_local_justice_tx`].
1052 /// It is expected that a watchtower client may use this method to retrieve the latest counterparty
1053 /// commitment transaction(s), and then hold the necessary data until a later update in which
1054 /// the monitor has been updated with the corresponding revocation data, at which point the
1055 /// monitor can sign the justice transaction.
1057 /// This will only return a non-empty list for monitor updates that have been created after
1058 /// upgrading to LDK 0.0.117+. Note that no restriction lies on the monitors themselves, which
1059 /// may have been created prior to upgrading.
1061 /// [`Persist::update_persisted_channel`]: crate::chain::chainmonitor::Persist::update_persisted_channel
1064 pub extern "C" fn ChannelMonitor_counterparty_commitment_txs_from_update(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, update: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate) -> crate::c_types::derived::CVec_CommitmentTransactionZ {
1065 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.counterparty_commitment_txs_from_update(update.get_native_ref());
1066 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::chan_utils::CommitmentTransaction { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1070 /// Wrapper around [`EcdsaChannelSigner::sign_justice_revoked_output`] to make
1071 /// signing the justice transaction easier for implementors of
1072 /// [`chain::chainmonitor::Persist`]. On success this method returns the provided transaction
1073 /// signing the input at `input_idx`. This method will only produce a valid signature for
1074 /// a transaction spending the `to_local` output of a commitment transaction, i.e. this cannot
1075 /// be used for revoked HTLC outputs.
1077 /// `Value` is the value of the output being spent by the input at `input_idx`, committed
1078 /// in the BIP 143 signature.
1080 /// This method will only succeed if this monitor has received the revocation secret for the
1081 /// provided `commitment_number`. If a commitment number is provided that does not correspond
1082 /// to the commitment transaction being revoked, this will return a signed transaction, but
1083 /// the signature will not be valid.
1085 /// [`EcdsaChannelSigner::sign_justice_revoked_output`]: crate::sign::ecdsa::EcdsaChannelSigner::sign_justice_revoked_output
1086 /// [`Persist`]: crate::chain::chainmonitor::Persist
1089 pub extern "C" fn ChannelMonitor_sign_to_local_justice_tx(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, mut justice_tx: crate::c_types::Transaction, mut input_idx: usize, mut value: u64, mut commitment_number: u64) -> crate::c_types::derived::CResult_TransactionNoneZ {
1090 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.sign_to_local_justice_tx(justice_tx.into_bitcoin(), input_idx, value, commitment_number);
1091 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Transaction::from_bitcoin(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1095 /// Gets the `node_id` of the counterparty for this channel.
1097 /// Will be `None` for channels constructed on LDK versions prior to 0.0.110 and always `Some`
1100 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1103 pub extern "C" fn ChannelMonitor_get_counterparty_node_id(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::PublicKey {
1104 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_counterparty_node_id();
1105 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
1109 /// Used by [`ChannelManager`] deserialization to broadcast the latest holder state if its copy
1110 /// of the channel state was out-of-date.
1112 /// You may also use this to broadcast the latest local commitment transaction, either because
1113 /// a monitor update failed or because we've fallen behind (i.e. we've received proof that our
1114 /// counterparty side knows a revocation secret we gave them that they shouldn't know).
1116 /// Broadcasting these transactions in the second case is UNSAFE, as they allow counterparty
1117 /// side to punish you. Nevertheless you may want to broadcast them if counterparty doesn't
1118 /// close channel with their commitment transaction after a substantial amount of time. Best
1119 /// may be to contact the other node operator out-of-band to coordinate other options available
1122 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
1125 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 {
1126 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_latest_holder_commitment_txn(logger);
1127 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::Transaction::from_bitcoin(&item) }); };
1131 /// Processes transactions in a newly connected block, which may result in any of the following:
1132 /// - update the monitor's state against resolved HTLCs
1133 /// - punish the counterparty in the case of seeing a revoked commitment transaction
1134 /// - force close the channel and claim/timeout incoming/outgoing HTLCs if near expiration
1135 /// - detect settled outputs for later spending
1136 /// - schedule and bump any in-flight claims
1138 /// Returns any new outputs to watch from `txdata`; after called, these are also included in
1139 /// [`get_outputs_to_watch`].
1141 /// [`get_outputs_to_watch`]: #method.get_outputs_to_watch
1144 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 {
1145 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 }); };
1146 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);
1147 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 }); };
1151 /// Determines if the disconnected block contained any transactions of interest and updates
1154 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) {
1155 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height, broadcaster, fee_estimator, logger)
1158 /// Processes transactions confirmed in a block with the given header and height, returning new
1159 /// outputs to watch. See [`block_connected`] for details.
1161 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
1162 /// blocks. See [`chain::Confirm`] for calling expectations.
1164 /// [`block_connected`]: Self::block_connected
1167 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 {
1168 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 }); };
1169 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);
1170 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 }); };
1174 /// Processes a transaction that was reorganized out of the chain.
1176 /// Used instead of [`block_disconnected`] by clients that are notified of transactions rather
1177 /// than blocks. See [`chain::Confirm`] for calling expectations.
1179 /// [`block_disconnected`]: Self::block_disconnected
1181 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) {
1182 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.transaction_unconfirmed(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap(), broadcaster, fee_estimator, logger)
1185 /// Updates the monitor with the current best chain tip, returning new outputs to watch. See
1186 /// [`block_connected`] for details.
1188 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
1189 /// blocks. See [`chain::Confirm`] for calling expectations.
1191 /// [`block_connected`]: Self::block_connected
1194 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 {
1195 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);
1196 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 }); };
1200 /// Returns the set of txids that should be monitored for re-organization out of the chain.
1203 pub extern "C" fn ChannelMonitor_get_relevant_txids(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_C3Tuple_ThirtyTwoBytesu32COption_ThirtyTwoBytesZZZ {
1204 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_relevant_txids();
1205 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 }); };
1209 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
1210 /// [`chain::Confirm`] interfaces.
1213 pub extern "C" fn ChannelMonitor_current_best_block(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::lightning::chain::BestBlock {
1214 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
1215 crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
1218 /// Triggers rebroadcasts/fee-bumps of pending claims from a force-closed channel. This is
1219 /// crucial in preventing certain classes of pinning attacks, detecting substantial mempool
1220 /// feerate changes between blocks, and ensuring reliability if broadcasting fails. We recommend
1221 /// invoking this every 30 seconds, or lower if running in an environment with spotty
1222 /// connections, like on mobile.
1224 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) {
1225 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.rebroadcast_pending_claims(broadcaster, fee_estimator, logger)
1228 /// Returns the descriptors for relevant outputs (i.e., those that we can spend) within the
1229 /// transaction if they exist and the transaction has at least [`ANTI_REORG_DELAY`]
1230 /// confirmations. For [`SpendableOutputDescriptor::DelayedPaymentOutput`] descriptors to be
1231 /// returned, the transaction must have at least `max(ANTI_REORG_DELAY, to_self_delay)`
1234 /// Descriptors returned by this method are primarily exposed via [`Event::SpendableOutputs`]
1235 /// once they are no longer under reorg risk. This method serves as a way to retrieve these
1236 /// descriptors at a later time, either for historical purposes, or to replay any
1237 /// missed/unhandled descriptors. For the purpose of gathering historical records, if the
1238 /// channel close has fully resolved (i.e., [`ChannelMonitor::get_claimable_balances`] returns
1239 /// an empty set), you can retrieve all spendable outputs by providing all descendant spending
1240 /// transactions starting from the channel's funding transaction and going down three levels.
1242 /// `tx` is a transaction we'll scan the outputs of. Any transaction can be provided. If any
1243 /// outputs which can be spent by us are found, at least one descriptor is returned.
1245 /// `confirmation_height` must be the height of the block in which `tx` was included in.
1248 pub extern "C" fn ChannelMonitor_get_spendable_outputs(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, mut tx: crate::c_types::Transaction, mut confirmation_height: u32) -> crate::c_types::derived::CVec_SpendableOutputDescriptorZ {
1249 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_spendable_outputs(&tx.into_bitcoin(), confirmation_height);
1250 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::sign::SpendableOutputDescriptor::native_into(item) }); };
1254 /// Gets the balances in this channel which are either claimable by us if we were to
1255 /// force-close the channel now or which are claimable on-chain (possibly awaiting
1258 /// Any balances in the channel which are available on-chain (excluding on-chain fees) are
1259 /// included here until an [`Event::SpendableOutputs`] event has been generated for the
1260 /// balance, or until our counterparty has claimed the balance and accrued several
1261 /// confirmations on the claim transaction.
1263 /// Note that for `ChannelMonitors` which track a channel which went on-chain with versions of
1264 /// LDK prior to 0.0.111, not all or excess balances may be included.
1266 /// See [`Balance`] for additional details on the types of claimable balances which
1267 /// may be returned here and their meanings.
1270 pub extern "C" fn ChannelMonitor_get_claimable_balances(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_BalanceZ {
1271 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_claimable_balances();
1272 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::Balance::native_into(item) }); };
1277 /// Read a C2Tuple_ThirtyTwoBytesChannelMonitorZ from a byte array, created by C2Tuple_ThirtyTwoBytesChannelMonitorZ_write
1278 pub extern "C" fn C2Tuple_ThirtyTwoBytesChannelMonitorZ_read(ser: crate::c_types::u8slice, arg_a: &crate::lightning::sign::EntropySource, arg_b: &crate::lightning::sign::SignerProvider) -> crate::c_types::derived::CResult_C2Tuple_ThirtyTwoBytesChannelMonitorZDecodeErrorZ {
1279 let arg_a_conv = arg_a;
1280 let arg_b_conv = arg_b;
1281 let arg_conv = (arg_a_conv, arg_b_conv);
1282 let res: Result<(bitcoin::hash_types::BlockHash, lightning::chain::channelmonitor::ChannelMonitor<crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner>), lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
1283 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() };