Pin compiler_builtins to 0.1.109 when building std
[ldk-c-bindings] / lightning-c-bindings / src / lightning / ln / channelmanager.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
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.
8
9 //! The top-level channel management and payment tracking stuff lives here.
10 //!
11 //! The [`ChannelManager`] is the main chunk of logic implementing the lightning protocol and is
12 //! responsible for tracking which channels are open, HTLCs are in flight and reestablishing those
13 //! upon reconnect to the relevant peer(s).
14 //!
15 //! It does not manage routing logic (see [`Router`] for that) nor does it manage constructing
16 //! on-chain transactions (it only monitors the chain to watch for any force-closes that might
17 //! imply it needs to fail HTLCs/payments/channels it manages).
18
19 use alloc::str::FromStr;
20 use alloc::string::String;
21 use core::ffi::c_void;
22 use core::convert::Infallible;
23 use bitcoin::hashes::Hash;
24 use crate::c_types::*;
25 #[cfg(feature="no-std")]
26 use alloc::{vec::Vec, boxed::Box};
27
28 /// Information about where a received HTLC('s onion) has indicated the HTLC should go.
29 #[derive(Clone)]
30 #[must_use]
31 #[repr(C)]
32 pub enum PendingHTLCRouting {
33         /// An HTLC which should be forwarded on to another node.
34         Forward {
35                 /// The onion which should be included in the forwarded HTLC, telling the next hop what to
36                 /// do with the HTLC.
37                 onion_packet: crate::lightning::ln::msgs::OnionPacket,
38                 /// The short channel ID of the channel which we were instructed to forward this HTLC to.
39                 ///
40                 /// This could be a real on-chain SCID, an SCID alias, or some other SCID which has meaning
41                 /// to the receiving node, such as one returned from
42                 /// [`ChannelManager::get_intercept_scid`] or [`ChannelManager::get_phantom_scid`].
43                 short_channel_id: u64,
44                 /// Set if this HTLC is being forwarded within a blinded path.
45                 ///
46                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
47                 blinded: crate::lightning::ln::channelmanager::BlindedForward,
48         },
49         /// The onion indicates that this is a payment for an invoice (supposedly) generated by us.
50         ///
51         /// Note that at this point, we have not checked that the invoice being paid was actually
52         /// generated by us, but rather it's claiming to pay an invoice of ours.
53         Receive {
54                 /// Information about the amount the sender intended to pay and (potential) proof that this
55                 /// is a payment for an invoice we generated. This proof of payment is is also used for
56                 /// linking MPP parts of a larger payment.
57                 payment_data: crate::lightning::ln::msgs::FinalOnionHopData,
58                 /// Additional data which we (allegedly) instructed the sender to include in the onion.
59                 ///
60                 /// For HTLCs received by LDK, this will ultimately be exposed in
61                 /// [`Event::PaymentClaimable::onion_fields`] as
62                 /// [`RecipientOnionFields::payment_metadata`].
63                 payment_metadata: crate::c_types::derived::COption_CVec_u8ZZ,
64                 /// The context of the payment included by the recipient in a blinded path, or `None` if a
65                 /// blinded path was not used.
66                 ///
67                 /// Used in part to determine the [`events::PaymentPurpose`].
68                 payment_context: crate::c_types::derived::COption_PaymentContextZ,
69                 /// CLTV expiry of the received HTLC.
70                 ///
71                 /// Used to track when we should expire pending HTLCs that go unclaimed.
72                 incoming_cltv_expiry: u32,
73                 /// If the onion had forwarding instructions to one of our phantom node SCIDs, this will
74                 /// provide the onion shared secret used to decrypt the next level of forwarding
75                 /// instructions.
76                 ///
77                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
78                 phantom_shared_secret: crate::c_types::ThirtyTwoBytes,
79                 /// Custom TLVs which were set by the sender.
80                 ///
81                 /// For HTLCs received by LDK, this will ultimately be exposed in
82                 /// [`Event::PaymentClaimable::onion_fields`] as
83                 /// [`RecipientOnionFields::custom_tlvs`].
84                 custom_tlvs: crate::c_types::derived::CVec_C2Tuple_u64CVec_u8ZZZ,
85                 /// Set if this HTLC is the final hop in a multi-hop blinded path.
86                 requires_blinded_error: bool,
87         },
88         /// The onion indicates that this is for payment to us but which contains the preimage for
89         /// claiming included, and is unrelated to any invoice we'd previously generated (aka a
90         /// \"keysend\" or \"spontaneous\" payment).
91         ReceiveKeysend {
92                 /// Information about the amount the sender intended to pay and possibly a token to
93                 /// associate MPP parts of a larger payment.
94                 ///
95                 /// This will only be filled in if receiving MPP keysend payments is enabled, and it being
96                 /// present will cause deserialization to fail on versions of LDK prior to 0.0.116.
97                 ///
98                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
99                 payment_data: crate::lightning::ln::msgs::FinalOnionHopData,
100                 /// Preimage for this onion payment. This preimage is provided by the sender and will be
101                 /// used to settle the spontaneous payment.
102                 payment_preimage: crate::c_types::ThirtyTwoBytes,
103                 /// Additional data which we (allegedly) instructed the sender to include in the onion.
104                 ///
105                 /// For HTLCs received by LDK, this will ultimately bubble back up as
106                 /// [`RecipientOnionFields::payment_metadata`].
107                 payment_metadata: crate::c_types::derived::COption_CVec_u8ZZ,
108                 /// CLTV expiry of the received HTLC.
109                 ///
110                 /// Used to track when we should expire pending HTLCs that go unclaimed.
111                 incoming_cltv_expiry: u32,
112                 /// Custom TLVs which were set by the sender.
113                 ///
114                 /// For HTLCs received by LDK, these will ultimately bubble back up as
115                 /// [`RecipientOnionFields::custom_tlvs`].
116                 custom_tlvs: crate::c_types::derived::CVec_C2Tuple_u64CVec_u8ZZZ,
117                 /// Set if this HTLC is the final hop in a multi-hop blinded path.
118                 requires_blinded_error: bool,
119         },
120 }
121 use lightning::ln::channelmanager::PendingHTLCRouting as PendingHTLCRoutingImport;
122 pub(crate) type nativePendingHTLCRouting = PendingHTLCRoutingImport;
123
124 impl PendingHTLCRouting {
125         #[allow(unused)]
126         pub(crate) fn to_native(&self) -> nativePendingHTLCRouting {
127                 match self {
128                         PendingHTLCRouting::Forward {ref onion_packet, ref short_channel_id, ref blinded, } => {
129                                 let mut onion_packet_nonref = Clone::clone(onion_packet);
130                                 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
131                                 let mut blinded_nonref = Clone::clone(blinded);
132                                 let mut local_blinded_nonref = if blinded_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(blinded_nonref.take_inner()) } }) };
133                                 nativePendingHTLCRouting::Forward {
134                                         onion_packet: *unsafe { Box::from_raw(onion_packet_nonref.take_inner()) },
135                                         short_channel_id: short_channel_id_nonref,
136                                         blinded: local_blinded_nonref,
137                                 }
138                         },
139                         PendingHTLCRouting::Receive {ref payment_data, ref payment_metadata, ref payment_context, ref incoming_cltv_expiry, ref phantom_shared_secret, ref custom_tlvs, ref requires_blinded_error, } => {
140                                 let mut payment_data_nonref = Clone::clone(payment_data);
141                                 let mut payment_metadata_nonref = Clone::clone(payment_metadata);
142                                 let mut local_payment_metadata_nonref = { /*payment_metadata_nonref*/ let payment_metadata_nonref_opt = payment_metadata_nonref; if payment_metadata_nonref_opt.is_none() { None } else { Some({ { let mut local_payment_metadata_nonref_0 = Vec::new(); for mut item in { payment_metadata_nonref_opt.take() }.into_rust().drain(..) { local_payment_metadata_nonref_0.push( { item }); }; local_payment_metadata_nonref_0 }})} };
143                                 let mut payment_context_nonref = Clone::clone(payment_context);
144                                 let mut local_payment_context_nonref = { /*payment_context_nonref*/ let payment_context_nonref_opt = payment_context_nonref; if payment_context_nonref_opt.is_none() { None } else { Some({ { { payment_context_nonref_opt.take() }.into_native() }})} };
145                                 let mut incoming_cltv_expiry_nonref = Clone::clone(incoming_cltv_expiry);
146                                 let mut phantom_shared_secret_nonref = Clone::clone(phantom_shared_secret);
147                                 let mut local_phantom_shared_secret_nonref = if phantom_shared_secret_nonref.data == [0; 32] { None } else { Some( { phantom_shared_secret_nonref.data }) };
148                                 let mut custom_tlvs_nonref = Clone::clone(custom_tlvs);
149                                 let mut local_custom_tlvs_nonref = Vec::new(); for mut item in custom_tlvs_nonref.into_rust().drain(..) { local_custom_tlvs_nonref.push( { let (mut orig_custom_tlvs_nonref_0_0, mut orig_custom_tlvs_nonref_0_1) = item.to_rust(); let mut local_orig_custom_tlvs_nonref_0_1 = Vec::new(); for mut item in orig_custom_tlvs_nonref_0_1.into_rust().drain(..) { local_orig_custom_tlvs_nonref_0_1.push( { item }); }; let mut local_custom_tlvs_nonref_0 = (orig_custom_tlvs_nonref_0_0, local_orig_custom_tlvs_nonref_0_1); local_custom_tlvs_nonref_0 }); };
150                                 let mut requires_blinded_error_nonref = Clone::clone(requires_blinded_error);
151                                 nativePendingHTLCRouting::Receive {
152                                         payment_data: *unsafe { Box::from_raw(payment_data_nonref.take_inner()) },
153                                         payment_metadata: local_payment_metadata_nonref,
154                                         payment_context: local_payment_context_nonref,
155                                         incoming_cltv_expiry: incoming_cltv_expiry_nonref,
156                                         phantom_shared_secret: local_phantom_shared_secret_nonref,
157                                         custom_tlvs: local_custom_tlvs_nonref,
158                                         requires_blinded_error: requires_blinded_error_nonref,
159                                 }
160                         },
161                         PendingHTLCRouting::ReceiveKeysend {ref payment_data, ref payment_preimage, ref payment_metadata, ref incoming_cltv_expiry, ref custom_tlvs, ref requires_blinded_error, } => {
162                                 let mut payment_data_nonref = Clone::clone(payment_data);
163                                 let mut local_payment_data_nonref = if payment_data_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(payment_data_nonref.take_inner()) } }) };
164                                 let mut payment_preimage_nonref = Clone::clone(payment_preimage);
165                                 let mut payment_metadata_nonref = Clone::clone(payment_metadata);
166                                 let mut local_payment_metadata_nonref = { /*payment_metadata_nonref*/ let payment_metadata_nonref_opt = payment_metadata_nonref; if payment_metadata_nonref_opt.is_none() { None } else { Some({ { let mut local_payment_metadata_nonref_0 = Vec::new(); for mut item in { payment_metadata_nonref_opt.take() }.into_rust().drain(..) { local_payment_metadata_nonref_0.push( { item }); }; local_payment_metadata_nonref_0 }})} };
167                                 let mut incoming_cltv_expiry_nonref = Clone::clone(incoming_cltv_expiry);
168                                 let mut custom_tlvs_nonref = Clone::clone(custom_tlvs);
169                                 let mut local_custom_tlvs_nonref = Vec::new(); for mut item in custom_tlvs_nonref.into_rust().drain(..) { local_custom_tlvs_nonref.push( { let (mut orig_custom_tlvs_nonref_0_0, mut orig_custom_tlvs_nonref_0_1) = item.to_rust(); let mut local_orig_custom_tlvs_nonref_0_1 = Vec::new(); for mut item in orig_custom_tlvs_nonref_0_1.into_rust().drain(..) { local_orig_custom_tlvs_nonref_0_1.push( { item }); }; let mut local_custom_tlvs_nonref_0 = (orig_custom_tlvs_nonref_0_0, local_orig_custom_tlvs_nonref_0_1); local_custom_tlvs_nonref_0 }); };
170                                 let mut requires_blinded_error_nonref = Clone::clone(requires_blinded_error);
171                                 nativePendingHTLCRouting::ReceiveKeysend {
172                                         payment_data: local_payment_data_nonref,
173                                         payment_preimage: ::lightning::ln::types::PaymentPreimage(payment_preimage_nonref.data),
174                                         payment_metadata: local_payment_metadata_nonref,
175                                         incoming_cltv_expiry: incoming_cltv_expiry_nonref,
176                                         custom_tlvs: local_custom_tlvs_nonref,
177                                         requires_blinded_error: requires_blinded_error_nonref,
178                                 }
179                         },
180                 }
181         }
182         #[allow(unused)]
183         pub(crate) fn into_native(self) -> nativePendingHTLCRouting {
184                 match self {
185                         PendingHTLCRouting::Forward {mut onion_packet, mut short_channel_id, mut blinded, } => {
186                                 let mut local_blinded = if blinded.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(blinded.take_inner()) } }) };
187                                 nativePendingHTLCRouting::Forward {
188                                         onion_packet: *unsafe { Box::from_raw(onion_packet.take_inner()) },
189                                         short_channel_id: short_channel_id,
190                                         blinded: local_blinded,
191                                 }
192                         },
193                         PendingHTLCRouting::Receive {mut payment_data, mut payment_metadata, mut payment_context, mut incoming_cltv_expiry, mut phantom_shared_secret, mut custom_tlvs, mut requires_blinded_error, } => {
194                                 let mut local_payment_metadata = { /*payment_metadata*/ let payment_metadata_opt = payment_metadata; if payment_metadata_opt.is_none() { None } else { Some({ { let mut local_payment_metadata_0 = Vec::new(); for mut item in { payment_metadata_opt.take() }.into_rust().drain(..) { local_payment_metadata_0.push( { item }); }; local_payment_metadata_0 }})} };
195                                 let mut local_payment_context = { /*payment_context*/ let payment_context_opt = payment_context; if payment_context_opt.is_none() { None } else { Some({ { { payment_context_opt.take() }.into_native() }})} };
196                                 let mut local_phantom_shared_secret = if phantom_shared_secret.data == [0; 32] { None } else { Some( { phantom_shared_secret.data }) };
197                                 let mut local_custom_tlvs = Vec::new(); for mut item in custom_tlvs.into_rust().drain(..) { local_custom_tlvs.push( { let (mut orig_custom_tlvs_0_0, mut orig_custom_tlvs_0_1) = item.to_rust(); let mut local_orig_custom_tlvs_0_1 = Vec::new(); for mut item in orig_custom_tlvs_0_1.into_rust().drain(..) { local_orig_custom_tlvs_0_1.push( { item }); }; let mut local_custom_tlvs_0 = (orig_custom_tlvs_0_0, local_orig_custom_tlvs_0_1); local_custom_tlvs_0 }); };
198                                 nativePendingHTLCRouting::Receive {
199                                         payment_data: *unsafe { Box::from_raw(payment_data.take_inner()) },
200                                         payment_metadata: local_payment_metadata,
201                                         payment_context: local_payment_context,
202                                         incoming_cltv_expiry: incoming_cltv_expiry,
203                                         phantom_shared_secret: local_phantom_shared_secret,
204                                         custom_tlvs: local_custom_tlvs,
205                                         requires_blinded_error: requires_blinded_error,
206                                 }
207                         },
208                         PendingHTLCRouting::ReceiveKeysend {mut payment_data, mut payment_preimage, mut payment_metadata, mut incoming_cltv_expiry, mut custom_tlvs, mut requires_blinded_error, } => {
209                                 let mut local_payment_data = if payment_data.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(payment_data.take_inner()) } }) };
210                                 let mut local_payment_metadata = { /*payment_metadata*/ let payment_metadata_opt = payment_metadata; if payment_metadata_opt.is_none() { None } else { Some({ { let mut local_payment_metadata_0 = Vec::new(); for mut item in { payment_metadata_opt.take() }.into_rust().drain(..) { local_payment_metadata_0.push( { item }); }; local_payment_metadata_0 }})} };
211                                 let mut local_custom_tlvs = Vec::new(); for mut item in custom_tlvs.into_rust().drain(..) { local_custom_tlvs.push( { let (mut orig_custom_tlvs_0_0, mut orig_custom_tlvs_0_1) = item.to_rust(); let mut local_orig_custom_tlvs_0_1 = Vec::new(); for mut item in orig_custom_tlvs_0_1.into_rust().drain(..) { local_orig_custom_tlvs_0_1.push( { item }); }; let mut local_custom_tlvs_0 = (orig_custom_tlvs_0_0, local_orig_custom_tlvs_0_1); local_custom_tlvs_0 }); };
212                                 nativePendingHTLCRouting::ReceiveKeysend {
213                                         payment_data: local_payment_data,
214                                         payment_preimage: ::lightning::ln::types::PaymentPreimage(payment_preimage.data),
215                                         payment_metadata: local_payment_metadata,
216                                         incoming_cltv_expiry: incoming_cltv_expiry,
217                                         custom_tlvs: local_custom_tlvs,
218                                         requires_blinded_error: requires_blinded_error,
219                                 }
220                         },
221                 }
222         }
223         #[allow(unused)]
224         pub(crate) fn from_native(native: &PendingHTLCRoutingImport) -> Self {
225                 let native = unsafe { &*(native as *const _ as *const c_void as *const nativePendingHTLCRouting) };
226                 match native {
227                         nativePendingHTLCRouting::Forward {ref onion_packet, ref short_channel_id, ref blinded, } => {
228                                 let mut onion_packet_nonref = Clone::clone(onion_packet);
229                                 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
230                                 let mut blinded_nonref = Clone::clone(blinded);
231                                 let mut local_blinded_nonref = crate::lightning::ln::channelmanager::BlindedForward { inner: if blinded_nonref.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((blinded_nonref.unwrap())) } }, is_owned: true };
232                                 PendingHTLCRouting::Forward {
233                                         onion_packet: crate::lightning::ln::msgs::OnionPacket { inner: ObjOps::heap_alloc(onion_packet_nonref), is_owned: true },
234                                         short_channel_id: short_channel_id_nonref,
235                                         blinded: local_blinded_nonref,
236                                 }
237                         },
238                         nativePendingHTLCRouting::Receive {ref payment_data, ref payment_metadata, ref payment_context, ref incoming_cltv_expiry, ref phantom_shared_secret, ref custom_tlvs, ref requires_blinded_error, } => {
239                                 let mut payment_data_nonref = Clone::clone(payment_data);
240                                 let mut payment_metadata_nonref = Clone::clone(payment_metadata);
241                                 let mut local_payment_metadata_nonref = if payment_metadata_nonref.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some( { let mut local_payment_metadata_nonref_0 = Vec::new(); for mut item in payment_metadata_nonref.unwrap().drain(..) { local_payment_metadata_nonref_0.push( { item }); }; local_payment_metadata_nonref_0.into() }) };
242                                 let mut payment_context_nonref = Clone::clone(payment_context);
243                                 let mut local_payment_context_nonref = if payment_context_nonref.is_none() { crate::c_types::derived::COption_PaymentContextZ::None } else { crate::c_types::derived::COption_PaymentContextZ::Some( { crate::lightning::blinded_path::payment::PaymentContext::native_into(payment_context_nonref.unwrap()) }) };
244                                 let mut incoming_cltv_expiry_nonref = Clone::clone(incoming_cltv_expiry);
245                                 let mut phantom_shared_secret_nonref = Clone::clone(phantom_shared_secret);
246                                 let mut local_phantom_shared_secret_nonref = if phantom_shared_secret_nonref.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else {  { crate::c_types::ThirtyTwoBytes { data: (phantom_shared_secret_nonref.unwrap()) } } };
247                                 let mut custom_tlvs_nonref = Clone::clone(custom_tlvs);
248                                 let mut local_custom_tlvs_nonref = Vec::new(); for mut item in custom_tlvs_nonref.drain(..) { local_custom_tlvs_nonref.push( { let (mut orig_custom_tlvs_nonref_0_0, mut orig_custom_tlvs_nonref_0_1) = item; let mut local_orig_custom_tlvs_nonref_0_1 = Vec::new(); for mut item in orig_custom_tlvs_nonref_0_1.drain(..) { local_orig_custom_tlvs_nonref_0_1.push( { item }); }; let mut local_custom_tlvs_nonref_0 = (orig_custom_tlvs_nonref_0_0, local_orig_custom_tlvs_nonref_0_1.into()).into(); local_custom_tlvs_nonref_0 }); };
249                                 let mut requires_blinded_error_nonref = Clone::clone(requires_blinded_error);
250                                 PendingHTLCRouting::Receive {
251                                         payment_data: crate::lightning::ln::msgs::FinalOnionHopData { inner: ObjOps::heap_alloc(payment_data_nonref), is_owned: true },
252                                         payment_metadata: local_payment_metadata_nonref,
253                                         payment_context: local_payment_context_nonref,
254                                         incoming_cltv_expiry: incoming_cltv_expiry_nonref,
255                                         phantom_shared_secret: local_phantom_shared_secret_nonref,
256                                         custom_tlvs: local_custom_tlvs_nonref.into(),
257                                         requires_blinded_error: requires_blinded_error_nonref,
258                                 }
259                         },
260                         nativePendingHTLCRouting::ReceiveKeysend {ref payment_data, ref payment_preimage, ref payment_metadata, ref incoming_cltv_expiry, ref custom_tlvs, ref requires_blinded_error, } => {
261                                 let mut payment_data_nonref = Clone::clone(payment_data);
262                                 let mut local_payment_data_nonref = crate::lightning::ln::msgs::FinalOnionHopData { inner: if payment_data_nonref.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((payment_data_nonref.unwrap())) } }, is_owned: true };
263                                 let mut payment_preimage_nonref = Clone::clone(payment_preimage);
264                                 let mut payment_metadata_nonref = Clone::clone(payment_metadata);
265                                 let mut local_payment_metadata_nonref = if payment_metadata_nonref.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some( { let mut local_payment_metadata_nonref_0 = Vec::new(); for mut item in payment_metadata_nonref.unwrap().drain(..) { local_payment_metadata_nonref_0.push( { item }); }; local_payment_metadata_nonref_0.into() }) };
266                                 let mut incoming_cltv_expiry_nonref = Clone::clone(incoming_cltv_expiry);
267                                 let mut custom_tlvs_nonref = Clone::clone(custom_tlvs);
268                                 let mut local_custom_tlvs_nonref = Vec::new(); for mut item in custom_tlvs_nonref.drain(..) { local_custom_tlvs_nonref.push( { let (mut orig_custom_tlvs_nonref_0_0, mut orig_custom_tlvs_nonref_0_1) = item; let mut local_orig_custom_tlvs_nonref_0_1 = Vec::new(); for mut item in orig_custom_tlvs_nonref_0_1.drain(..) { local_orig_custom_tlvs_nonref_0_1.push( { item }); }; let mut local_custom_tlvs_nonref_0 = (orig_custom_tlvs_nonref_0_0, local_orig_custom_tlvs_nonref_0_1.into()).into(); local_custom_tlvs_nonref_0 }); };
269                                 let mut requires_blinded_error_nonref = Clone::clone(requires_blinded_error);
270                                 PendingHTLCRouting::ReceiveKeysend {
271                                         payment_data: local_payment_data_nonref,
272                                         payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
273                                         payment_metadata: local_payment_metadata_nonref,
274                                         incoming_cltv_expiry: incoming_cltv_expiry_nonref,
275                                         custom_tlvs: local_custom_tlvs_nonref.into(),
276                                         requires_blinded_error: requires_blinded_error_nonref,
277                                 }
278                         },
279                 }
280         }
281         #[allow(unused)]
282         pub(crate) fn native_into(native: nativePendingHTLCRouting) -> Self {
283                 match native {
284                         nativePendingHTLCRouting::Forward {mut onion_packet, mut short_channel_id, mut blinded, } => {
285                                 let mut local_blinded = crate::lightning::ln::channelmanager::BlindedForward { inner: if blinded.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((blinded.unwrap())) } }, is_owned: true };
286                                 PendingHTLCRouting::Forward {
287                                         onion_packet: crate::lightning::ln::msgs::OnionPacket { inner: ObjOps::heap_alloc(onion_packet), is_owned: true },
288                                         short_channel_id: short_channel_id,
289                                         blinded: local_blinded,
290                                 }
291                         },
292                         nativePendingHTLCRouting::Receive {mut payment_data, mut payment_metadata, mut payment_context, mut incoming_cltv_expiry, mut phantom_shared_secret, mut custom_tlvs, mut requires_blinded_error, } => {
293                                 let mut local_payment_metadata = if payment_metadata.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some( { let mut local_payment_metadata_0 = Vec::new(); for mut item in payment_metadata.unwrap().drain(..) { local_payment_metadata_0.push( { item }); }; local_payment_metadata_0.into() }) };
294                                 let mut local_payment_context = if payment_context.is_none() { crate::c_types::derived::COption_PaymentContextZ::None } else { crate::c_types::derived::COption_PaymentContextZ::Some( { crate::lightning::blinded_path::payment::PaymentContext::native_into(payment_context.unwrap()) }) };
295                                 let mut local_phantom_shared_secret = if phantom_shared_secret.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else {  { crate::c_types::ThirtyTwoBytes { data: (phantom_shared_secret.unwrap()) } } };
296                                 let mut local_custom_tlvs = Vec::new(); for mut item in custom_tlvs.drain(..) { local_custom_tlvs.push( { let (mut orig_custom_tlvs_0_0, mut orig_custom_tlvs_0_1) = item; let mut local_orig_custom_tlvs_0_1 = Vec::new(); for mut item in orig_custom_tlvs_0_1.drain(..) { local_orig_custom_tlvs_0_1.push( { item }); }; let mut local_custom_tlvs_0 = (orig_custom_tlvs_0_0, local_orig_custom_tlvs_0_1.into()).into(); local_custom_tlvs_0 }); };
297                                 PendingHTLCRouting::Receive {
298                                         payment_data: crate::lightning::ln::msgs::FinalOnionHopData { inner: ObjOps::heap_alloc(payment_data), is_owned: true },
299                                         payment_metadata: local_payment_metadata,
300                                         payment_context: local_payment_context,
301                                         incoming_cltv_expiry: incoming_cltv_expiry,
302                                         phantom_shared_secret: local_phantom_shared_secret,
303                                         custom_tlvs: local_custom_tlvs.into(),
304                                         requires_blinded_error: requires_blinded_error,
305                                 }
306                         },
307                         nativePendingHTLCRouting::ReceiveKeysend {mut payment_data, mut payment_preimage, mut payment_metadata, mut incoming_cltv_expiry, mut custom_tlvs, mut requires_blinded_error, } => {
308                                 let mut local_payment_data = crate::lightning::ln::msgs::FinalOnionHopData { inner: if payment_data.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((payment_data.unwrap())) } }, is_owned: true };
309                                 let mut local_payment_metadata = if payment_metadata.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some( { let mut local_payment_metadata_0 = Vec::new(); for mut item in payment_metadata.unwrap().drain(..) { local_payment_metadata_0.push( { item }); }; local_payment_metadata_0.into() }) };
310                                 let mut local_custom_tlvs = Vec::new(); for mut item in custom_tlvs.drain(..) { local_custom_tlvs.push( { let (mut orig_custom_tlvs_0_0, mut orig_custom_tlvs_0_1) = item; let mut local_orig_custom_tlvs_0_1 = Vec::new(); for mut item in orig_custom_tlvs_0_1.drain(..) { local_orig_custom_tlvs_0_1.push( { item }); }; let mut local_custom_tlvs_0 = (orig_custom_tlvs_0_0, local_orig_custom_tlvs_0_1.into()).into(); local_custom_tlvs_0 }); };
311                                 PendingHTLCRouting::ReceiveKeysend {
312                                         payment_data: local_payment_data,
313                                         payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
314                                         payment_metadata: local_payment_metadata,
315                                         incoming_cltv_expiry: incoming_cltv_expiry,
316                                         custom_tlvs: local_custom_tlvs.into(),
317                                         requires_blinded_error: requires_blinded_error,
318                                 }
319                         },
320                 }
321         }
322 }
323 /// Frees any resources used by the PendingHTLCRouting
324 #[no_mangle]
325 pub extern "C" fn PendingHTLCRouting_free(this_ptr: PendingHTLCRouting) { }
326 /// Creates a copy of the PendingHTLCRouting
327 #[no_mangle]
328 pub extern "C" fn PendingHTLCRouting_clone(orig: &PendingHTLCRouting) -> PendingHTLCRouting {
329         orig.clone()
330 }
331 #[allow(unused)]
332 /// Used only if an object of this type is returned as a trait impl by a method
333 pub(crate) extern "C" fn PendingHTLCRouting_clone_void(this_ptr: *const c_void) -> *mut c_void {
334         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const PendingHTLCRouting)).clone() })) as *mut c_void
335 }
336 #[allow(unused)]
337 /// Used only if an object of this type is returned as a trait impl by a method
338 pub(crate) extern "C" fn PendingHTLCRouting_free_void(this_ptr: *mut c_void) {
339         let _ = unsafe { Box::from_raw(this_ptr as *mut PendingHTLCRouting) };
340 }
341 #[no_mangle]
342 /// Utility method to constructs a new Forward-variant PendingHTLCRouting
343 pub extern "C" fn PendingHTLCRouting_forward(onion_packet: crate::lightning::ln::msgs::OnionPacket, short_channel_id: u64, blinded: crate::lightning::ln::channelmanager::BlindedForward) -> PendingHTLCRouting {
344         PendingHTLCRouting::Forward {
345                 onion_packet,
346                 short_channel_id,
347                 blinded,
348         }
349 }
350 #[no_mangle]
351 /// Utility method to constructs a new Receive-variant PendingHTLCRouting
352 pub extern "C" fn PendingHTLCRouting_receive(payment_data: crate::lightning::ln::msgs::FinalOnionHopData, payment_metadata: crate::c_types::derived::COption_CVec_u8ZZ, payment_context: crate::c_types::derived::COption_PaymentContextZ, incoming_cltv_expiry: u32, phantom_shared_secret: crate::c_types::ThirtyTwoBytes, custom_tlvs: crate::c_types::derived::CVec_C2Tuple_u64CVec_u8ZZZ, requires_blinded_error: bool) -> PendingHTLCRouting {
353         PendingHTLCRouting::Receive {
354                 payment_data,
355                 payment_metadata,
356                 payment_context,
357                 incoming_cltv_expiry,
358                 phantom_shared_secret,
359                 custom_tlvs,
360                 requires_blinded_error,
361         }
362 }
363 #[no_mangle]
364 /// Utility method to constructs a new ReceiveKeysend-variant PendingHTLCRouting
365 pub extern "C" fn PendingHTLCRouting_receive_keysend(payment_data: crate::lightning::ln::msgs::FinalOnionHopData, payment_preimage: crate::c_types::ThirtyTwoBytes, payment_metadata: crate::c_types::derived::COption_CVec_u8ZZ, incoming_cltv_expiry: u32, custom_tlvs: crate::c_types::derived::CVec_C2Tuple_u64CVec_u8ZZZ, requires_blinded_error: bool) -> PendingHTLCRouting {
366         PendingHTLCRouting::ReceiveKeysend {
367                 payment_data,
368                 payment_preimage,
369                 payment_metadata,
370                 incoming_cltv_expiry,
371                 custom_tlvs,
372                 requires_blinded_error,
373         }
374 }
375
376 use lightning::ln::channelmanager::BlindedForward as nativeBlindedForwardImport;
377 pub(crate) type nativeBlindedForward = nativeBlindedForwardImport;
378
379 /// Information used to forward or fail this HTLC that is being forwarded within a blinded path.
380 #[must_use]
381 #[repr(C)]
382 pub struct BlindedForward {
383         /// A pointer to the opaque Rust object.
384
385         /// Nearly everywhere, inner must be non-null, however in places where
386         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
387         pub inner: *mut nativeBlindedForward,
388         /// Indicates that this is the only struct which contains the same pointer.
389
390         /// Rust functions which take ownership of an object provided via an argument require
391         /// this to be true and invalidate the object pointed to by inner.
392         pub is_owned: bool,
393 }
394
395 impl Drop for BlindedForward {
396         fn drop(&mut self) {
397                 if self.is_owned && !<*mut nativeBlindedForward>::is_null(self.inner) {
398                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
399                 }
400         }
401 }
402 /// Frees any resources used by the BlindedForward, if is_owned is set and inner is non-NULL.
403 #[no_mangle]
404 pub extern "C" fn BlindedForward_free(this_obj: BlindedForward) { }
405 #[allow(unused)]
406 /// Used only if an object of this type is returned as a trait impl by a method
407 pub(crate) extern "C" fn BlindedForward_free_void(this_ptr: *mut c_void) {
408         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBlindedForward) };
409 }
410 #[allow(unused)]
411 impl BlindedForward {
412         pub(crate) fn get_native_ref(&self) -> &'static nativeBlindedForward {
413                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
414         }
415         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBlindedForward {
416                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
417         }
418         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
419         pub(crate) fn take_inner(mut self) -> *mut nativeBlindedForward {
420                 assert!(self.is_owned);
421                 let ret = ObjOps::untweak_ptr(self.inner);
422                 self.inner = core::ptr::null_mut();
423                 ret
424         }
425 }
426 /// The `blinding_point` that was set in the inbound [`msgs::UpdateAddHTLC`], or in the inbound
427 /// onion payload if we're the introduction node. Useful for calculating the next hop's
428 /// [`msgs::UpdateAddHTLC::blinding_point`].
429 #[no_mangle]
430 pub extern "C" fn BlindedForward_get_inbound_blinding_point(this_ptr: &BlindedForward) -> crate::c_types::PublicKey {
431         let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_blinding_point;
432         crate::c_types::PublicKey::from_rust(&inner_val)
433 }
434 /// The `blinding_point` that was set in the inbound [`msgs::UpdateAddHTLC`], or in the inbound
435 /// onion payload if we're the introduction node. Useful for calculating the next hop's
436 /// [`msgs::UpdateAddHTLC::blinding_point`].
437 #[no_mangle]
438 pub extern "C" fn BlindedForward_set_inbound_blinding_point(this_ptr: &mut BlindedForward, mut val: crate::c_types::PublicKey) {
439         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_blinding_point = val.into_rust();
440 }
441 /// If needed, this determines how this HTLC should be failed backwards, based on whether we are
442 /// the introduction node.
443 #[no_mangle]
444 pub extern "C" fn BlindedForward_get_failure(this_ptr: &BlindedForward) -> crate::lightning::ln::channelmanager::BlindedFailure {
445         let mut inner_val = &mut this_ptr.get_native_mut_ref().failure;
446         crate::lightning::ln::channelmanager::BlindedFailure::from_native(inner_val)
447 }
448 /// If needed, this determines how this HTLC should be failed backwards, based on whether we are
449 /// the introduction node.
450 #[no_mangle]
451 pub extern "C" fn BlindedForward_set_failure(this_ptr: &mut BlindedForward, mut val: crate::lightning::ln::channelmanager::BlindedFailure) {
452         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.failure = val.into_native();
453 }
454 /// Constructs a new BlindedForward given each field
455 #[must_use]
456 #[no_mangle]
457 pub extern "C" fn BlindedForward_new(mut inbound_blinding_point_arg: crate::c_types::PublicKey, mut failure_arg: crate::lightning::ln::channelmanager::BlindedFailure) -> BlindedForward {
458         BlindedForward { inner: ObjOps::heap_alloc(nativeBlindedForward {
459                 inbound_blinding_point: inbound_blinding_point_arg.into_rust(),
460                 failure: failure_arg.into_native(),
461         }), is_owned: true }
462 }
463 impl Clone for BlindedForward {
464         fn clone(&self) -> Self {
465                 Self {
466                         inner: if <*mut nativeBlindedForward>::is_null(self.inner) { core::ptr::null_mut() } else {
467                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
468                         is_owned: true,
469                 }
470         }
471 }
472 #[allow(unused)]
473 /// Used only if an object of this type is returned as a trait impl by a method
474 pub(crate) extern "C" fn BlindedForward_clone_void(this_ptr: *const c_void) -> *mut c_void {
475         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBlindedForward)).clone() })) as *mut c_void
476 }
477 #[no_mangle]
478 /// Creates a copy of the BlindedForward
479 pub extern "C" fn BlindedForward_clone(orig: &BlindedForward) -> BlindedForward {
480         orig.clone()
481 }
482 /// Get a string which allows debug introspection of a BlindedForward object
483 pub extern "C" fn BlindedForward_debug_str_void(o: *const c_void) -> Str {
484         alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channelmanager::BlindedForward }).into()}
485 /// Generates a non-cryptographic 64-bit hash of the BlindedForward.
486 #[no_mangle]
487 pub extern "C" fn BlindedForward_hash(o: &BlindedForward) -> u64 {
488         if o.inner.is_null() { return 0; }
489         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
490         #[allow(deprecated)]
491         let mut hasher = core::hash::SipHasher::new();
492         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
493         core::hash::Hasher::finish(&hasher)
494 }
495 /// Checks if two BlindedForwards contain equal inner contents.
496 /// This ignores pointers and is_owned flags and looks at the values in fields.
497 /// Two objects with NULL inner values will be considered "equal" here.
498 #[no_mangle]
499 pub extern "C" fn BlindedForward_eq(a: &BlindedForward, b: &BlindedForward) -> bool {
500         if a.inner == b.inner { return true; }
501         if a.inner.is_null() || b.inner.is_null() { return false; }
502         if a.get_native_ref() == b.get_native_ref() { true } else { false }
503 }
504
505 use lightning::ln::channelmanager::PendingHTLCInfo as nativePendingHTLCInfoImport;
506 pub(crate) type nativePendingHTLCInfo = nativePendingHTLCInfoImport;
507
508 /// Information about an incoming HTLC, including the [`PendingHTLCRouting`] describing where it
509 /// should go next.
510 #[must_use]
511 #[repr(C)]
512 pub struct PendingHTLCInfo {
513         /// A pointer to the opaque Rust object.
514
515         /// Nearly everywhere, inner must be non-null, however in places where
516         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
517         pub inner: *mut nativePendingHTLCInfo,
518         /// Indicates that this is the only struct which contains the same pointer.
519
520         /// Rust functions which take ownership of an object provided via an argument require
521         /// this to be true and invalidate the object pointed to by inner.
522         pub is_owned: bool,
523 }
524
525 impl Drop for PendingHTLCInfo {
526         fn drop(&mut self) {
527                 if self.is_owned && !<*mut nativePendingHTLCInfo>::is_null(self.inner) {
528                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
529                 }
530         }
531 }
532 /// Frees any resources used by the PendingHTLCInfo, if is_owned is set and inner is non-NULL.
533 #[no_mangle]
534 pub extern "C" fn PendingHTLCInfo_free(this_obj: PendingHTLCInfo) { }
535 #[allow(unused)]
536 /// Used only if an object of this type is returned as a trait impl by a method
537 pub(crate) extern "C" fn PendingHTLCInfo_free_void(this_ptr: *mut c_void) {
538         let _ = unsafe { Box::from_raw(this_ptr as *mut nativePendingHTLCInfo) };
539 }
540 #[allow(unused)]
541 impl PendingHTLCInfo {
542         pub(crate) fn get_native_ref(&self) -> &'static nativePendingHTLCInfo {
543                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
544         }
545         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePendingHTLCInfo {
546                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
547         }
548         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
549         pub(crate) fn take_inner(mut self) -> *mut nativePendingHTLCInfo {
550                 assert!(self.is_owned);
551                 let ret = ObjOps::untweak_ptr(self.inner);
552                 self.inner = core::ptr::null_mut();
553                 ret
554         }
555 }
556 /// Further routing details based on whether the HTLC is being forwarded or received.
557 #[no_mangle]
558 pub extern "C" fn PendingHTLCInfo_get_routing(this_ptr: &PendingHTLCInfo) -> crate::lightning::ln::channelmanager::PendingHTLCRouting {
559         let mut inner_val = &mut this_ptr.get_native_mut_ref().routing;
560         crate::lightning::ln::channelmanager::PendingHTLCRouting::from_native(inner_val)
561 }
562 /// Further routing details based on whether the HTLC is being forwarded or received.
563 #[no_mangle]
564 pub extern "C" fn PendingHTLCInfo_set_routing(this_ptr: &mut PendingHTLCInfo, mut val: crate::lightning::ln::channelmanager::PendingHTLCRouting) {
565         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.routing = val.into_native();
566 }
567 /// The onion shared secret we build with the sender used to decrypt the onion.
568 ///
569 /// This is later used to encrypt failure packets in the event that the HTLC is failed.
570 #[no_mangle]
571 pub extern "C" fn PendingHTLCInfo_get_incoming_shared_secret(this_ptr: &PendingHTLCInfo) -> *const [u8; 32] {
572         let mut inner_val = &mut this_ptr.get_native_mut_ref().incoming_shared_secret;
573         inner_val
574 }
575 /// The onion shared secret we build with the sender used to decrypt the onion.
576 ///
577 /// This is later used to encrypt failure packets in the event that the HTLC is failed.
578 #[no_mangle]
579 pub extern "C" fn PendingHTLCInfo_set_incoming_shared_secret(this_ptr: &mut PendingHTLCInfo, mut val: crate::c_types::ThirtyTwoBytes) {
580         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.incoming_shared_secret = val.data;
581 }
582 /// Hash of the payment preimage, to lock the payment until the receiver releases the preimage.
583 #[no_mangle]
584 pub extern "C" fn PendingHTLCInfo_get_payment_hash(this_ptr: &PendingHTLCInfo) -> *const [u8; 32] {
585         let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_hash;
586         &inner_val.0
587 }
588 /// Hash of the payment preimage, to lock the payment until the receiver releases the preimage.
589 #[no_mangle]
590 pub extern "C" fn PendingHTLCInfo_set_payment_hash(this_ptr: &mut PendingHTLCInfo, mut val: crate::c_types::ThirtyTwoBytes) {
591         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_hash = ::lightning::ln::types::PaymentHash(val.data);
592 }
593 /// Amount received in the incoming HTLC.
594 ///
595 /// This field was added in LDK 0.0.113 and will be `None` for objects written by prior
596 /// versions.
597 #[no_mangle]
598 pub extern "C" fn PendingHTLCInfo_get_incoming_amt_msat(this_ptr: &PendingHTLCInfo) -> crate::c_types::derived::COption_u64Z {
599         let mut inner_val = &mut this_ptr.get_native_mut_ref().incoming_amt_msat;
600         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) };
601         local_inner_val
602 }
603 /// Amount received in the incoming HTLC.
604 ///
605 /// This field was added in LDK 0.0.113 and will be `None` for objects written by prior
606 /// versions.
607 #[no_mangle]
608 pub extern "C" fn PendingHTLCInfo_set_incoming_amt_msat(this_ptr: &mut PendingHTLCInfo, mut val: crate::c_types::derived::COption_u64Z) {
609         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
610         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.incoming_amt_msat = local_val;
611 }
612 /// The amount the sender indicated should be forwarded on to the next hop or amount the sender
613 /// intended for us to receive for received payments.
614 ///
615 /// If the received amount is less than this for received payments, an intermediary hop has
616 /// attempted to steal some of our funds and we should fail the HTLC (the sender should retry
617 /// it along another path).
618 ///
619 /// Because nodes can take less than their required fees, and because senders may wish to
620 /// improve their own privacy, this amount may be less than [`Self::incoming_amt_msat`] for
621 /// received payments. In such cases, recipients must handle this HTLC as if it had received
622 /// [`Self::outgoing_amt_msat`].
623 #[no_mangle]
624 pub extern "C" fn PendingHTLCInfo_get_outgoing_amt_msat(this_ptr: &PendingHTLCInfo) -> u64 {
625         let mut inner_val = &mut this_ptr.get_native_mut_ref().outgoing_amt_msat;
626         *inner_val
627 }
628 /// The amount the sender indicated should be forwarded on to the next hop or amount the sender
629 /// intended for us to receive for received payments.
630 ///
631 /// If the received amount is less than this for received payments, an intermediary hop has
632 /// attempted to steal some of our funds and we should fail the HTLC (the sender should retry
633 /// it along another path).
634 ///
635 /// Because nodes can take less than their required fees, and because senders may wish to
636 /// improve their own privacy, this amount may be less than [`Self::incoming_amt_msat`] for
637 /// received payments. In such cases, recipients must handle this HTLC as if it had received
638 /// [`Self::outgoing_amt_msat`].
639 #[no_mangle]
640 pub extern "C" fn PendingHTLCInfo_set_outgoing_amt_msat(this_ptr: &mut PendingHTLCInfo, mut val: u64) {
641         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outgoing_amt_msat = val;
642 }
643 /// The CLTV the sender has indicated we should set on the forwarded HTLC (or has indicated
644 /// should have been set on the received HTLC for received payments).
645 #[no_mangle]
646 pub extern "C" fn PendingHTLCInfo_get_outgoing_cltv_value(this_ptr: &PendingHTLCInfo) -> u32 {
647         let mut inner_val = &mut this_ptr.get_native_mut_ref().outgoing_cltv_value;
648         *inner_val
649 }
650 /// The CLTV the sender has indicated we should set on the forwarded HTLC (or has indicated
651 /// should have been set on the received HTLC for received payments).
652 #[no_mangle]
653 pub extern "C" fn PendingHTLCInfo_set_outgoing_cltv_value(this_ptr: &mut PendingHTLCInfo, mut val: u32) {
654         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outgoing_cltv_value = val;
655 }
656 /// The fee taken for this HTLC in addition to the standard protocol HTLC fees.
657 ///
658 /// If this is a payment for forwarding, this is the fee we are taking before forwarding the
659 /// HTLC.
660 ///
661 /// If this is a received payment, this is the fee that our counterparty took.
662 ///
663 /// This is used to allow LSPs to take fees as a part of payments, without the sender having to
664 /// shoulder them.
665 #[no_mangle]
666 pub extern "C" fn PendingHTLCInfo_get_skimmed_fee_msat(this_ptr: &PendingHTLCInfo) -> crate::c_types::derived::COption_u64Z {
667         let mut inner_val = &mut this_ptr.get_native_mut_ref().skimmed_fee_msat;
668         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) };
669         local_inner_val
670 }
671 /// The fee taken for this HTLC in addition to the standard protocol HTLC fees.
672 ///
673 /// If this is a payment for forwarding, this is the fee we are taking before forwarding the
674 /// HTLC.
675 ///
676 /// If this is a received payment, this is the fee that our counterparty took.
677 ///
678 /// This is used to allow LSPs to take fees as a part of payments, without the sender having to
679 /// shoulder them.
680 #[no_mangle]
681 pub extern "C" fn PendingHTLCInfo_set_skimmed_fee_msat(this_ptr: &mut PendingHTLCInfo, mut val: crate::c_types::derived::COption_u64Z) {
682         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
683         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.skimmed_fee_msat = local_val;
684 }
685 /// Constructs a new PendingHTLCInfo given each field
686 #[must_use]
687 #[no_mangle]
688 pub extern "C" fn PendingHTLCInfo_new(mut routing_arg: crate::lightning::ln::channelmanager::PendingHTLCRouting, mut incoming_shared_secret_arg: crate::c_types::ThirtyTwoBytes, mut payment_hash_arg: crate::c_types::ThirtyTwoBytes, mut incoming_amt_msat_arg: crate::c_types::derived::COption_u64Z, mut outgoing_amt_msat_arg: u64, mut outgoing_cltv_value_arg: u32, mut skimmed_fee_msat_arg: crate::c_types::derived::COption_u64Z) -> PendingHTLCInfo {
689         let mut local_incoming_amt_msat_arg = if incoming_amt_msat_arg.is_some() { Some( { incoming_amt_msat_arg.take() }) } else { None };
690         let mut local_skimmed_fee_msat_arg = if skimmed_fee_msat_arg.is_some() { Some( { skimmed_fee_msat_arg.take() }) } else { None };
691         PendingHTLCInfo { inner: ObjOps::heap_alloc(nativePendingHTLCInfo {
692                 routing: routing_arg.into_native(),
693                 incoming_shared_secret: incoming_shared_secret_arg.data,
694                 payment_hash: ::lightning::ln::types::PaymentHash(payment_hash_arg.data),
695                 incoming_amt_msat: local_incoming_amt_msat_arg,
696                 outgoing_amt_msat: outgoing_amt_msat_arg,
697                 outgoing_cltv_value: outgoing_cltv_value_arg,
698                 skimmed_fee_msat: local_skimmed_fee_msat_arg,
699         }), is_owned: true }
700 }
701 impl Clone for PendingHTLCInfo {
702         fn clone(&self) -> Self {
703                 Self {
704                         inner: if <*mut nativePendingHTLCInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
705                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
706                         is_owned: true,
707                 }
708         }
709 }
710 #[allow(unused)]
711 /// Used only if an object of this type is returned as a trait impl by a method
712 pub(crate) extern "C" fn PendingHTLCInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
713         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePendingHTLCInfo)).clone() })) as *mut c_void
714 }
715 #[no_mangle]
716 /// Creates a copy of the PendingHTLCInfo
717 pub extern "C" fn PendingHTLCInfo_clone(orig: &PendingHTLCInfo) -> PendingHTLCInfo {
718         orig.clone()
719 }
720 /// Whether this blinded HTLC is being failed backwards by the introduction node or a blinded node,
721 /// which determines the failure message that should be used.
722 #[derive(Clone)]
723 #[must_use]
724 #[repr(C)]
725 pub enum BlindedFailure {
726         /// This HTLC is being failed backwards by the introduction node, and thus should be failed with
727         /// [`msgs::UpdateFailHTLC`] and error code `0x8000|0x4000|24`.
728         FromIntroductionNode,
729         /// This HTLC is being failed backwards by a blinded node within the path, and thus should be
730         /// failed with [`msgs::UpdateFailMalformedHTLC`] and error code `0x8000|0x4000|24`.
731         FromBlindedNode,
732 }
733 use lightning::ln::channelmanager::BlindedFailure as BlindedFailureImport;
734 pub(crate) type nativeBlindedFailure = BlindedFailureImport;
735
736 impl BlindedFailure {
737         #[allow(unused)]
738         pub(crate) fn to_native(&self) -> nativeBlindedFailure {
739                 match self {
740                         BlindedFailure::FromIntroductionNode => nativeBlindedFailure::FromIntroductionNode,
741                         BlindedFailure::FromBlindedNode => nativeBlindedFailure::FromBlindedNode,
742                 }
743         }
744         #[allow(unused)]
745         pub(crate) fn into_native(self) -> nativeBlindedFailure {
746                 match self {
747                         BlindedFailure::FromIntroductionNode => nativeBlindedFailure::FromIntroductionNode,
748                         BlindedFailure::FromBlindedNode => nativeBlindedFailure::FromBlindedNode,
749                 }
750         }
751         #[allow(unused)]
752         pub(crate) fn from_native(native: &BlindedFailureImport) -> Self {
753                 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeBlindedFailure) };
754                 match native {
755                         nativeBlindedFailure::FromIntroductionNode => BlindedFailure::FromIntroductionNode,
756                         nativeBlindedFailure::FromBlindedNode => BlindedFailure::FromBlindedNode,
757                 }
758         }
759         #[allow(unused)]
760         pub(crate) fn native_into(native: nativeBlindedFailure) -> Self {
761                 match native {
762                         nativeBlindedFailure::FromIntroductionNode => BlindedFailure::FromIntroductionNode,
763                         nativeBlindedFailure::FromBlindedNode => BlindedFailure::FromBlindedNode,
764                 }
765         }
766 }
767 /// Creates a copy of the BlindedFailure
768 #[no_mangle]
769 pub extern "C" fn BlindedFailure_clone(orig: &BlindedFailure) -> BlindedFailure {
770         orig.clone()
771 }
772 #[allow(unused)]
773 /// Used only if an object of this type is returned as a trait impl by a method
774 pub(crate) extern "C" fn BlindedFailure_clone_void(this_ptr: *const c_void) -> *mut c_void {
775         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const BlindedFailure)).clone() })) as *mut c_void
776 }
777 #[allow(unused)]
778 /// Used only if an object of this type is returned as a trait impl by a method
779 pub(crate) extern "C" fn BlindedFailure_free_void(this_ptr: *mut c_void) {
780         let _ = unsafe { Box::from_raw(this_ptr as *mut BlindedFailure) };
781 }
782 #[no_mangle]
783 /// Utility method to constructs a new FromIntroductionNode-variant BlindedFailure
784 pub extern "C" fn BlindedFailure_from_introduction_node() -> BlindedFailure {
785         BlindedFailure::FromIntroductionNode}
786 #[no_mangle]
787 /// Utility method to constructs a new FromBlindedNode-variant BlindedFailure
788 pub extern "C" fn BlindedFailure_from_blinded_node() -> BlindedFailure {
789         BlindedFailure::FromBlindedNode}
790 /// Get a string which allows debug introspection of a BlindedFailure object
791 pub extern "C" fn BlindedFailure_debug_str_void(o: *const c_void) -> Str {
792         alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channelmanager::BlindedFailure }).into()}
793 /// Generates a non-cryptographic 64-bit hash of the BlindedFailure.
794 #[no_mangle]
795 pub extern "C" fn BlindedFailure_hash(o: &BlindedFailure) -> u64 {
796         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
797         #[allow(deprecated)]
798         let mut hasher = core::hash::SipHasher::new();
799         core::hash::Hash::hash(&o.to_native(), &mut hasher);
800         core::hash::Hasher::finish(&hasher)
801 }
802 /// Checks if two BlindedFailures contain equal inner contents.
803 /// This ignores pointers and is_owned flags and looks at the values in fields.
804 #[no_mangle]
805 pub extern "C" fn BlindedFailure_eq(a: &BlindedFailure, b: &BlindedFailure) -> bool {
806         if &a.to_native() == &b.to_native() { true } else { false }
807 }
808 /// This enum is used to specify which error data to send to peers when failing back an HTLC
809 /// using [`ChannelManager::fail_htlc_backwards_with_reason`].
810 ///
811 /// For more info on failure codes, see <https://github.com/lightning/bolts/blob/master/04-onion-routing.md#failure-messages>.
812 #[derive(Clone)]
813 #[must_use]
814 #[repr(C)]
815 pub enum FailureCode {
816         /// We had a temporary error processing the payment. Useful if no other error codes fit
817         /// and you want to indicate that the payer may want to retry.
818         TemporaryNodeFailure,
819         /// We have a required feature which was not in this onion. For example, you may require
820         /// some additional metadata that was not provided with this payment.
821         RequiredNodeFeatureMissing,
822         /// You may wish to use this when a `payment_preimage` is unknown, or the CLTV expiry of
823         /// the HTLC is too close to the current block height for safe handling.
824         /// Using this failure code in [`ChannelManager::fail_htlc_backwards_with_reason`] is
825         /// equivalent to calling [`ChannelManager::fail_htlc_backwards`].
826         IncorrectOrUnknownPaymentDetails,
827         /// We failed to process the payload after the onion was decrypted. You may wish to
828         /// use this when receiving custom HTLC TLVs with even type numbers that you don't recognize.
829         ///
830         /// If available, the tuple data may include the type number and byte offset in the
831         /// decrypted byte stream where the failure occurred.
832         InvalidOnionPayload(
833                 crate::c_types::derived::COption_C2Tuple_u64u16ZZ),
834 }
835 use lightning::ln::channelmanager::FailureCode as FailureCodeImport;
836 pub(crate) type nativeFailureCode = FailureCodeImport;
837
838 impl FailureCode {
839         #[allow(unused)]
840         pub(crate) fn to_native(&self) -> nativeFailureCode {
841                 match self {
842                         FailureCode::TemporaryNodeFailure => nativeFailureCode::TemporaryNodeFailure,
843                         FailureCode::RequiredNodeFeatureMissing => nativeFailureCode::RequiredNodeFeatureMissing,
844                         FailureCode::IncorrectOrUnknownPaymentDetails => nativeFailureCode::IncorrectOrUnknownPaymentDetails,
845                         FailureCode::InvalidOnionPayload (ref a, ) => {
846                                 let mut a_nonref = Clone::clone(a);
847                                 let mut local_a_nonref = if a_nonref.is_some() { Some( { let (mut orig_a_nonref_0_0, mut orig_a_nonref_0_1) = a_nonref.take().to_rust(); let mut local_a_nonref_0 = (orig_a_nonref_0_0, orig_a_nonref_0_1); local_a_nonref_0 }) } else { None };
848                                 nativeFailureCode::InvalidOnionPayload (
849                                         local_a_nonref,
850                                 )
851                         },
852                 }
853         }
854         #[allow(unused)]
855         pub(crate) fn into_native(self) -> nativeFailureCode {
856                 match self {
857                         FailureCode::TemporaryNodeFailure => nativeFailureCode::TemporaryNodeFailure,
858                         FailureCode::RequiredNodeFeatureMissing => nativeFailureCode::RequiredNodeFeatureMissing,
859                         FailureCode::IncorrectOrUnknownPaymentDetails => nativeFailureCode::IncorrectOrUnknownPaymentDetails,
860                         FailureCode::InvalidOnionPayload (mut a, ) => {
861                                 let mut local_a = if a.is_some() { Some( { let (mut orig_a_0_0, mut orig_a_0_1) = a.take().to_rust(); let mut local_a_0 = (orig_a_0_0, orig_a_0_1); local_a_0 }) } else { None };
862                                 nativeFailureCode::InvalidOnionPayload (
863                                         local_a,
864                                 )
865                         },
866                 }
867         }
868         #[allow(unused)]
869         pub(crate) fn from_native(native: &FailureCodeImport) -> Self {
870                 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeFailureCode) };
871                 match native {
872                         nativeFailureCode::TemporaryNodeFailure => FailureCode::TemporaryNodeFailure,
873                         nativeFailureCode::RequiredNodeFeatureMissing => FailureCode::RequiredNodeFeatureMissing,
874                         nativeFailureCode::IncorrectOrUnknownPaymentDetails => FailureCode::IncorrectOrUnknownPaymentDetails,
875                         nativeFailureCode::InvalidOnionPayload (ref a, ) => {
876                                 let mut a_nonref = Clone::clone(a);
877                                 let mut local_a_nonref = if a_nonref.is_none() { crate::c_types::derived::COption_C2Tuple_u64u16ZZ::None } else { crate::c_types::derived::COption_C2Tuple_u64u16ZZ::Some( { let (mut orig_a_nonref_0_0, mut orig_a_nonref_0_1) = (a_nonref.unwrap()); let mut local_a_nonref_0 = (orig_a_nonref_0_0, orig_a_nonref_0_1).into(); local_a_nonref_0 }) };
878                                 FailureCode::InvalidOnionPayload (
879                                         local_a_nonref,
880                                 )
881                         },
882                 }
883         }
884         #[allow(unused)]
885         pub(crate) fn native_into(native: nativeFailureCode) -> Self {
886                 match native {
887                         nativeFailureCode::TemporaryNodeFailure => FailureCode::TemporaryNodeFailure,
888                         nativeFailureCode::RequiredNodeFeatureMissing => FailureCode::RequiredNodeFeatureMissing,
889                         nativeFailureCode::IncorrectOrUnknownPaymentDetails => FailureCode::IncorrectOrUnknownPaymentDetails,
890                         nativeFailureCode::InvalidOnionPayload (mut a, ) => {
891                                 let mut local_a = if a.is_none() { crate::c_types::derived::COption_C2Tuple_u64u16ZZ::None } else { crate::c_types::derived::COption_C2Tuple_u64u16ZZ::Some( { let (mut orig_a_0_0, mut orig_a_0_1) = (a.unwrap()); let mut local_a_0 = (orig_a_0_0, orig_a_0_1).into(); local_a_0 }) };
892                                 FailureCode::InvalidOnionPayload (
893                                         local_a,
894                                 )
895                         },
896                 }
897         }
898 }
899 /// Frees any resources used by the FailureCode
900 #[no_mangle]
901 pub extern "C" fn FailureCode_free(this_ptr: FailureCode) { }
902 /// Creates a copy of the FailureCode
903 #[no_mangle]
904 pub extern "C" fn FailureCode_clone(orig: &FailureCode) -> FailureCode {
905         orig.clone()
906 }
907 #[allow(unused)]
908 /// Used only if an object of this type is returned as a trait impl by a method
909 pub(crate) extern "C" fn FailureCode_clone_void(this_ptr: *const c_void) -> *mut c_void {
910         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const FailureCode)).clone() })) as *mut c_void
911 }
912 #[allow(unused)]
913 /// Used only if an object of this type is returned as a trait impl by a method
914 pub(crate) extern "C" fn FailureCode_free_void(this_ptr: *mut c_void) {
915         let _ = unsafe { Box::from_raw(this_ptr as *mut FailureCode) };
916 }
917 #[no_mangle]
918 /// Utility method to constructs a new TemporaryNodeFailure-variant FailureCode
919 pub extern "C" fn FailureCode_temporary_node_failure() -> FailureCode {
920         FailureCode::TemporaryNodeFailure}
921 #[no_mangle]
922 /// Utility method to constructs a new RequiredNodeFeatureMissing-variant FailureCode
923 pub extern "C" fn FailureCode_required_node_feature_missing() -> FailureCode {
924         FailureCode::RequiredNodeFeatureMissing}
925 #[no_mangle]
926 /// Utility method to constructs a new IncorrectOrUnknownPaymentDetails-variant FailureCode
927 pub extern "C" fn FailureCode_incorrect_or_unknown_payment_details() -> FailureCode {
928         FailureCode::IncorrectOrUnknownPaymentDetails}
929 #[no_mangle]
930 /// Utility method to constructs a new InvalidOnionPayload-variant FailureCode
931 pub extern "C" fn FailureCode_invalid_onion_payload(a: crate::c_types::derived::COption_C2Tuple_u64u16ZZ) -> FailureCode {
932         FailureCode::InvalidOnionPayload(a, )
933 }
934
935 use lightning::ln::channelmanager::ChannelManager as nativeChannelManagerImport;
936 pub(crate) type nativeChannelManager = nativeChannelManagerImport<crate::lightning::chain::Watch, crate::lightning::chain::chaininterface::BroadcasterInterface, crate::lightning::sign::EntropySource, crate::lightning::sign::NodeSigner, crate::lightning::sign::SignerProvider, crate::lightning::chain::chaininterface::FeeEstimator, crate::lightning::routing::router::Router, crate::lightning::util::logger::Logger, >;
937
938 /// A lightning node's channel state machine and payment management logic, which facilitates
939 /// sending, forwarding, and receiving payments through lightning channels.
940 ///
941 /// [`ChannelManager`] is parameterized by a number of components to achieve this.
942 /// - [`chain::Watch`] (typically [`ChainMonitor`]) for on-chain monitoring and enforcement of each
943 ///   channel
944 /// - [`BroadcasterInterface`] for broadcasting transactions related to opening, funding, and
945 ///   closing channels
946 /// - [`EntropySource`] for providing random data needed for cryptographic operations
947 /// - [`NodeSigner`] for cryptographic operations scoped to the node
948 /// - [`SignerProvider`] for providing signers whose operations are scoped to individual channels
949 /// - [`FeeEstimator`] to determine transaction fee rates needed to have a transaction mined in a
950 ///   timely manner
951 /// - [`Router`] for finding payment paths when initiating and retrying payments
952 /// - [`Logger`] for logging operational information of varying degrees
953 ///
954 /// Additionally, it implements the following traits:
955 /// - [`ChannelMessageHandler`] to handle off-chain channel activity from peers
956 /// - [`MessageSendEventsProvider`] to similarly send such messages to peers
957 /// - [`OffersMessageHandler`] for BOLT 12 message handling and sending
958 /// - [`EventsProvider`] to generate user-actionable [`Event`]s
959 /// - [`chain::Listen`] and [`chain::Confirm`] for notification of on-chain activity
960 ///
961 /// Thus, [`ChannelManager`] is typically used to parameterize a [`MessageHandler`] and an
962 /// [`OnionMessenger`]. The latter is required to support BOLT 12 functionality.
963 ///
964 /// # `ChannelManager` vs `ChannelMonitor`
965 ///
966 /// It's important to distinguish between the *off-chain* management and *on-chain* enforcement of
967 /// lightning channels. [`ChannelManager`] exchanges messages with peers to manage the off-chain
968 /// state of each channel. During this process, it generates a [`ChannelMonitor`] for each channel
969 /// and a [`ChannelMonitorUpdate`] for each relevant change, notifying its parameterized
970 /// [`chain::Watch`] of them.
971 ///
972 /// An implementation of [`chain::Watch`], such as [`ChainMonitor`], is responsible for aggregating
973 /// these [`ChannelMonitor`]s and applying any [`ChannelMonitorUpdate`]s to them. It then monitors
974 /// for any pertinent on-chain activity, enforcing claims as needed.
975 ///
976 /// This division of off-chain management and on-chain enforcement allows for interesting node
977 /// setups. For instance, on-chain enforcement could be moved to a separate host or have added
978 /// redundancy, possibly as a watchtower. See [`chain::Watch`] for the relevant interface.
979 ///
980 /// # Initialization
981 ///
982 /// Use [`ChannelManager::new`] with the most recent [`BlockHash`] when creating a fresh instance.
983 /// Otherwise, if restarting, construct [`ChannelManagerReadArgs`] with the necessary parameters and
984 /// references to any deserialized [`ChannelMonitor`]s that were previously persisted. Use this to
985 /// deserialize the [`ChannelManager`] and feed it any new chain data since it was last online, as
986 /// detailed in the [`ChannelManagerReadArgs`] documentation.
987 ///
988 /// ```
989 /// use bitcoin::BlockHash;
990 /// use bitcoin::network::constants::Network;
991 /// use lightning::chain::BestBlock;
992 /// # use lightning::chain::channelmonitor::ChannelMonitor;
993 /// use lightning::ln::channelmanager::{ChainParameters, ChannelManager, ChannelManagerReadArgs};
994 /// # use lightning::routing::gossip::NetworkGraph;
995 /// use lightning::util::config::UserConfig;
996 /// use lightning::util::ser::ReadableArgs;
997 ///
998 /// # fn read_channel_monitors() -> Vec<ChannelMonitor<lightning::sign::InMemorySigner>> { vec![] }
999 /// # fn example<
1000 /// #     'a,
1001 /// #     L: lightning::util::logger::Logger,
1002 /// #     ES: lightning::sign::EntropySource,
1003 /// #     S: for <'b> lightning::routing::scoring::LockableScore<'b, ScoreLookUp = SL>,
1004 /// #     SL: lightning::routing::scoring::ScoreLookUp<ScoreParams = SP>,
1005 /// #     SP: Sized,
1006 /// #     R: lightning::io::Read,
1007 /// # >(
1008 /// #     fee_estimator: &dyn lightning::chain::chaininterface::FeeEstimator,
1009 /// #     chain_monitor: &dyn lightning::chain::Watch<lightning::sign::InMemorySigner>,
1010 /// #     tx_broadcaster: &dyn lightning::chain::chaininterface::BroadcasterInterface,
1011 /// #     router: &lightning::routing::router::DefaultRouter<&NetworkGraph<&'a L>, &'a L, &ES, &S, SP, SL>,
1012 /// #     logger: &L,
1013 /// #     entropy_source: &ES,
1014 /// #     node_signer: &dyn lightning::sign::NodeSigner,
1015 /// #     signer_provider: &lightning::sign::DynSignerProvider,
1016 /// #     best_block: lightning::chain::BestBlock,
1017 /// #     current_timestamp: u32,
1018 /// #     mut reader: R,
1019 /// # ) -> Result<(), lightning::ln::msgs::DecodeError> {
1020 /// // Fresh start with no channels
1021 /// let params = ChainParameters {
1022 ///     network: Network::Bitcoin,
1023 ///     best_block,
1024 /// };
1025 /// let default_config = UserConfig::default();
1026 /// let channel_manager = ChannelManager::new(
1027 ///     fee_estimator, chain_monitor, tx_broadcaster, router, logger, entropy_source, node_signer,
1028 ///     signer_provider, default_config, params, current_timestamp
1029 /// );
1030 ///
1031 /// // Restart from deserialized data
1032 /// let mut channel_monitors = read_channel_monitors();
1033 /// let args = ChannelManagerReadArgs::new(
1034 ///     entropy_source, node_signer, signer_provider, fee_estimator, chain_monitor, tx_broadcaster,
1035 ///     router, logger, default_config, channel_monitors.iter_mut().collect()
1036 /// );
1037 /// let (block_hash, channel_manager) =
1038 ///     <(BlockHash, ChannelManager<_, _, _, _, _, _, _, _>)>::read(&mut reader, args)?;
1039 ///
1040 /// // Update the ChannelManager and ChannelMonitors with the latest chain data
1041 /// // ...
1042 ///
1043 /// // Move the monitors to the ChannelManager's chain::Watch parameter
1044 /// for monitor in channel_monitors {
1045 ///     chain_monitor.watch_channel(monitor.get_funding_txo().0, monitor);
1046 /// }
1047 /// # Ok(())
1048 /// # }
1049 /// ```
1050 ///
1051 /// # Operation
1052 ///
1053 /// The following is required for [`ChannelManager`] to function properly:
1054 /// - Handle messages from peers using its [`ChannelMessageHandler`] implementation (typically
1055 ///   called by [`PeerManager::read_event`] when processing network I/O)
1056 /// - Send messages to peers obtained via its [`MessageSendEventsProvider`] implementation
1057 ///   (typically initiated when [`PeerManager::process_events`] is called)
1058 /// - Feed on-chain activity using either its [`chain::Listen`] or [`chain::Confirm`] implementation
1059 ///   as documented by those traits
1060 /// - Perform any periodic channel and payment checks by calling [`timer_tick_occurred`] roughly
1061 ///   every minute
1062 /// - Persist to disk whenever [`get_and_clear_needs_persistence`] returns `true` using a
1063 ///   [`Persister`] such as a [`KVStore`] implementation
1064 /// - Handle [`Event`]s obtained via its [`EventsProvider`] implementation
1065 ///
1066 /// The [`Future`] returned by [`get_event_or_persistence_needed_future`] is useful in determining
1067 /// when the last two requirements need to be checked.
1068 ///
1069 /// The [`lightning-block-sync`] and [`lightning-transaction-sync`] crates provide utilities that
1070 /// simplify feeding in on-chain activity using the [`chain::Listen`] and [`chain::Confirm`] traits,
1071 /// respectively. The remaining requirements can be met using the [`lightning-background-processor`]
1072 /// crate. For languages other than Rust, the availability of similar utilities may vary.
1073 ///
1074 /// # Channels
1075 ///
1076 /// [`ChannelManager`]'s primary function involves managing a channel state. Without channels,
1077 /// payments can't be sent. Use [`list_channels`] or [`list_usable_channels`] for a snapshot of the
1078 /// currently open channels.
1079 ///
1080 /// ```
1081 /// # use lightning::ln::channelmanager::AChannelManager;
1082 /// #
1083 /// # fn example<T: AChannelManager>(channel_manager: T) {
1084 /// # let channel_manager = channel_manager.get_cm();
1085 /// let channels = channel_manager.list_usable_channels();
1086 /// for details in channels {
1087 ///     println!(\"{:?}\", details);
1088 /// }
1089 /// # }
1090 /// ```
1091 ///
1092 /// Each channel is identified using a [`ChannelId`], which will change throughout the channel's
1093 /// life cycle. Additionally, channels are assigned a `user_channel_id`, which is given in
1094 /// [`Event`]s associated with the channel and serves as a fixed identifier but is otherwise unused
1095 /// by [`ChannelManager`].
1096 ///
1097 /// ## Opening Channels
1098 ///
1099 /// To an open a channel with a peer, call [`create_channel`]. This will initiate the process of
1100 /// opening an outbound channel, which requires self-funding when handling
1101 /// [`Event::FundingGenerationReady`].
1102 ///
1103 /// ```
1104 /// # use bitcoin::{ScriptBuf, Transaction};
1105 /// # use bitcoin::secp256k1::PublicKey;
1106 /// # use lightning::ln::channelmanager::AChannelManager;
1107 /// # use lightning::events::{Event, EventsProvider};
1108 /// #
1109 /// # trait Wallet {
1110 /// #     fn create_funding_transaction(
1111 /// #         &self, _amount_sats: u64, _output_script: ScriptBuf
1112 /// #     ) -> Transaction;
1113 /// # }
1114 /// #
1115 /// # fn example<T: AChannelManager, W: Wallet>(channel_manager: T, wallet: W, peer_id: PublicKey) {
1116 /// # let channel_manager = channel_manager.get_cm();
1117 /// let value_sats = 1_000_000;
1118 /// let push_msats = 10_000_000;
1119 /// match channel_manager.create_channel(peer_id, value_sats, push_msats, 42, None, None) {
1120 ///     Ok(channel_id) => println!(\"Opening channel {}\", channel_id),
1121 ///     Err(e) => println!(\"Error opening channel: {:?}\", e),
1122 /// }
1123 ///
1124 /// // On the event processing thread once the peer has responded
1125 /// channel_manager.process_pending_events(&|event| match event {
1126 ///     Event::FundingGenerationReady {
1127 ///         temporary_channel_id, counterparty_node_id, channel_value_satoshis, output_script,
1128 ///         user_channel_id, ..
1129 ///     } => {
1130 ///         assert_eq!(user_channel_id, 42);
1131 ///         let funding_transaction = wallet.create_funding_transaction(
1132 ///             channel_value_satoshis, output_script
1133 ///         );
1134 ///         match channel_manager.funding_transaction_generated(
1135 ///             &temporary_channel_id, &counterparty_node_id, funding_transaction
1136 ///         ) {
1137 ///             Ok(()) => println!(\"Funding channel {}\", temporary_channel_id),
1138 ///             Err(e) => println!(\"Error funding channel {}: {:?}\", temporary_channel_id, e),
1139 ///         }
1140 ///     },
1141 ///     Event::ChannelPending { channel_id, user_channel_id, former_temporary_channel_id, .. } => {
1142 ///         assert_eq!(user_channel_id, 42);
1143 ///         println!(
1144 ///             \"Channel {} now {} pending (funding transaction has been broadcasted)\", channel_id,
1145 ///             former_temporary_channel_id.unwrap()
1146 ///         );
1147 ///     },
1148 ///     Event::ChannelReady { channel_id, user_channel_id, .. } => {
1149 ///         assert_eq!(user_channel_id, 42);
1150 ///         println!(\"Channel {} ready\", channel_id);
1151 ///     },
1152 ///     // ...
1153 /// #     _ => {},
1154 /// });
1155 /// # }
1156 /// ```
1157 ///
1158 /// ## Accepting Channels
1159 ///
1160 /// Inbound channels are initiated by peers and are automatically accepted unless [`ChannelManager`]
1161 /// has [`UserConfig::manually_accept_inbound_channels`] set. In that case, the channel may be
1162 /// either accepted or rejected when handling [`Event::OpenChannelRequest`].
1163 ///
1164 /// ```
1165 /// # use bitcoin::secp256k1::PublicKey;
1166 /// # use lightning::ln::channelmanager::AChannelManager;
1167 /// # use lightning::events::{Event, EventsProvider};
1168 /// #
1169 /// # fn is_trusted(counterparty_node_id: PublicKey) -> bool {
1170 /// #     // ...
1171 /// #     unimplemented!()
1172 /// # }
1173 /// #
1174 /// # fn example<T: AChannelManager>(channel_manager: T) {
1175 /// # let channel_manager = channel_manager.get_cm();
1176 /// channel_manager.process_pending_events(&|event| match event {
1177 ///     Event::OpenChannelRequest { temporary_channel_id, counterparty_node_id, ..  } => {
1178 ///         if !is_trusted(counterparty_node_id) {
1179 ///             match channel_manager.force_close_without_broadcasting_txn(
1180 ///                 &temporary_channel_id, &counterparty_node_id
1181 ///             ) {
1182 ///                 Ok(()) => println!(\"Rejecting channel {}\", temporary_channel_id),
1183 ///                 Err(e) => println!(\"Error rejecting channel {}: {:?}\", temporary_channel_id, e),
1184 ///             }
1185 ///             return;
1186 ///         }
1187 ///
1188 ///         let user_channel_id = 43;
1189 ///         match channel_manager.accept_inbound_channel(
1190 ///             &temporary_channel_id, &counterparty_node_id, user_channel_id
1191 ///         ) {
1192 ///             Ok(()) => println!(\"Accepting channel {}\", temporary_channel_id),
1193 ///             Err(e) => println!(\"Error accepting channel {}: {:?}\", temporary_channel_id, e),
1194 ///         }
1195 ///     },
1196 ///     // ...
1197 /// #     _ => {},
1198 /// });
1199 /// # }
1200 /// ```
1201 ///
1202 /// ## Closing Channels
1203 ///
1204 /// There are two ways to close a channel: either cooperatively using [`close_channel`] or
1205 /// unilaterally using [`force_close_broadcasting_latest_txn`]. The former is ideal as it makes for
1206 /// lower fees and immediate access to funds. However, the latter may be necessary if the
1207 /// counterparty isn't behaving properly or has gone offline. [`Event::ChannelClosed`] is generated
1208 /// once the channel has been closed successfully.
1209 ///
1210 /// ```
1211 /// # use bitcoin::secp256k1::PublicKey;
1212 /// # use lightning::ln::types::ChannelId;
1213 /// # use lightning::ln::channelmanager::AChannelManager;
1214 /// # use lightning::events::{Event, EventsProvider};
1215 /// #
1216 /// # fn example<T: AChannelManager>(
1217 /// #     channel_manager: T, channel_id: ChannelId, counterparty_node_id: PublicKey
1218 /// # ) {
1219 /// # let channel_manager = channel_manager.get_cm();
1220 /// match channel_manager.close_channel(&channel_id, &counterparty_node_id) {
1221 ///     Ok(()) => println!(\"Closing channel {}\", channel_id),
1222 ///     Err(e) => println!(\"Error closing channel {}: {:?}\", channel_id, e),
1223 /// }
1224 ///
1225 /// // On the event processing thread
1226 /// channel_manager.process_pending_events(&|event| match event {
1227 ///     Event::ChannelClosed { channel_id, user_channel_id, ..  } => {
1228 ///         assert_eq!(user_channel_id, 42);
1229 ///         println!(\"Channel {} closed\", channel_id);
1230 ///     },
1231 ///     // ...
1232 /// #     _ => {},
1233 /// });
1234 /// # }
1235 /// ```
1236 ///
1237 /// # Payments
1238 ///
1239 /// [`ChannelManager`] is responsible for sending, forwarding, and receiving payments through its
1240 /// channels. A payment is typically initiated from a [BOLT 11] invoice or a [BOLT 12] offer, though
1241 /// spontaneous (i.e., keysend) payments are also possible. Incoming payments don't require
1242 /// maintaining any additional state as [`ChannelManager`] can reconstruct the [`PaymentPreimage`]
1243 /// from the [`PaymentSecret`]. Sending payments, however, require tracking in order to retry failed
1244 /// HTLCs.
1245 ///
1246 /// After a payment is initiated, it will appear in [`list_recent_payments`] until a short time
1247 /// after either an [`Event::PaymentSent`] or [`Event::PaymentFailed`] is handled. Failed HTLCs
1248 /// for a payment will be retried according to the payment's [`Retry`] strategy or until
1249 /// [`abandon_payment`] is called.
1250 ///
1251 /// ## BOLT 11 Invoices
1252 ///
1253 /// The [`lightning-invoice`] crate is useful for creating BOLT 11 invoices. Specifically, use the
1254 /// functions in its `utils` module for constructing invoices that are compatible with
1255 /// [`ChannelManager`]. These functions serve as a convenience for building invoices with the
1256 /// [`PaymentHash`] and [`PaymentSecret`] returned from [`create_inbound_payment`]. To provide your
1257 /// own [`PaymentHash`], use [`create_inbound_payment_for_hash`] or the corresponding functions in
1258 /// the [`lightning-invoice`] `utils` module.
1259 ///
1260 /// [`ChannelManager`] generates an [`Event::PaymentClaimable`] once the full payment has been
1261 /// received. Call [`claim_funds`] to release the [`PaymentPreimage`], which in turn will result in
1262 /// an [`Event::PaymentClaimed`].
1263 ///
1264 /// ```
1265 /// # use lightning::events::{Event, EventsProvider, PaymentPurpose};
1266 /// # use lightning::ln::channelmanager::AChannelManager;
1267 /// #
1268 /// # fn example<T: AChannelManager>(channel_manager: T) {
1269 /// # let channel_manager = channel_manager.get_cm();
1270 /// // Or use utils::create_invoice_from_channelmanager
1271 /// let known_payment_hash = match channel_manager.create_inbound_payment(
1272 ///     Some(10_000_000), 3600, None
1273 /// ) {
1274 ///     Ok((payment_hash, _payment_secret)) => {
1275 ///         println!(\"Creating inbound payment {}\", payment_hash);
1276 ///         payment_hash
1277 ///     },
1278 ///     Err(()) => panic!(\"Error creating inbound payment\"),
1279 /// };
1280 ///
1281 /// // On the event processing thread
1282 /// channel_manager.process_pending_events(&|event| match event {
1283 ///     Event::PaymentClaimable { payment_hash, purpose, .. } => match purpose {
1284 ///         PaymentPurpose::Bolt11InvoicePayment { payment_preimage: Some(payment_preimage), .. } => {
1285 ///             assert_eq!(payment_hash, known_payment_hash);
1286 ///             println!(\"Claiming payment {}\", payment_hash);
1287 ///             channel_manager.claim_funds(payment_preimage);
1288 ///         },
1289 ///         PaymentPurpose::Bolt11InvoicePayment { payment_preimage: None, .. } => {
1290 ///             println!(\"Unknown payment hash: {}\", payment_hash);
1291 ///         },
1292 ///         PaymentPurpose::SpontaneousPayment(payment_preimage) => {
1293 ///             assert_ne!(payment_hash, known_payment_hash);
1294 ///             println!(\"Claiming spontaneous payment {}\", payment_hash);
1295 ///             channel_manager.claim_funds(payment_preimage);
1296 ///         },
1297 ///         // ...
1298 /// #         _ => {},
1299 ///     },
1300 ///     Event::PaymentClaimed { payment_hash, amount_msat, .. } => {
1301 ///         assert_eq!(payment_hash, known_payment_hash);
1302 ///         println!(\"Claimed {} msats\", amount_msat);
1303 ///     },
1304 ///     // ...
1305 /// #     _ => {},
1306 /// });
1307 /// # }
1308 /// ```
1309 ///
1310 /// For paying an invoice, [`lightning-invoice`] provides a `payment` module with convenience
1311 /// functions for use with [`send_payment`].
1312 ///
1313 /// ```
1314 /// # use lightning::events::{Event, EventsProvider};
1315 /// # use lightning::ln::types::PaymentHash;
1316 /// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, RecipientOnionFields, Retry};
1317 /// # use lightning::routing::router::RouteParameters;
1318 /// #
1319 /// # fn example<T: AChannelManager>(
1320 /// #     channel_manager: T, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields,
1321 /// #     route_params: RouteParameters, retry: Retry
1322 /// # ) {
1323 /// # let channel_manager = channel_manager.get_cm();
1324 /// // let (payment_hash, recipient_onion, route_params) =
1325 /// //     payment::payment_parameters_from_invoice(&invoice);
1326 /// let payment_id = PaymentId([42; 32]);
1327 /// match channel_manager.send_payment(
1328 ///     payment_hash, recipient_onion, payment_id, route_params, retry
1329 /// ) {
1330 ///     Ok(()) => println!(\"Sending payment with hash {}\", payment_hash),
1331 ///     Err(e) => println!(\"Failed sending payment with hash {}: {:?}\", payment_hash, e),
1332 /// }
1333 ///
1334 /// let expected_payment_id = payment_id;
1335 /// let expected_payment_hash = payment_hash;
1336 /// assert!(
1337 ///     channel_manager.list_recent_payments().iter().find(|details| matches!(
1338 ///         details,
1339 ///         RecentPaymentDetails::Pending {
1340 ///             payment_id: expected_payment_id,
1341 ///             payment_hash: expected_payment_hash,
1342 ///             ..
1343 ///         }
1344 ///     )).is_some()
1345 /// );
1346 ///
1347 /// // On the event processing thread
1348 /// channel_manager.process_pending_events(&|event| match event {
1349 ///     Event::PaymentSent { payment_hash, .. } => println!(\"Paid {}\", payment_hash),
1350 ///     Event::PaymentFailed { payment_hash, .. } => println!(\"Failed paying {}\", payment_hash),
1351 ///     // ...
1352 /// #     _ => {},
1353 /// });
1354 /// # }
1355 /// ```
1356 ///
1357 /// ## BOLT 12 Offers
1358 ///
1359 /// The [`offers`] module is useful for creating BOLT 12 offers. An [`Offer`] is a precursor to a
1360 /// [`Bolt12Invoice`], which must first be requested by the payer. The interchange of these messages
1361 /// as defined in the specification is handled by [`ChannelManager`] and its implementation of
1362 /// [`OffersMessageHandler`]. However, this only works with an [`Offer`] created using a builder
1363 /// returned by [`create_offer_builder`]. With this approach, BOLT 12 offers and invoices are
1364 /// stateless just as BOLT 11 invoices are.
1365 ///
1366 /// ```
1367 /// # use lightning::events::{Event, EventsProvider, PaymentPurpose};
1368 /// # use lightning::ln::channelmanager::AChannelManager;
1369 /// # use lightning::offers::parse::Bolt12SemanticError;
1370 /// #
1371 /// # fn example<T: AChannelManager>(channel_manager: T) -> Result<(), Bolt12SemanticError> {
1372 /// # let channel_manager = channel_manager.get_cm();
1373 /// let offer = channel_manager
1374 ///     .create_offer_builder()?
1375 /// # ;
1376 /// # // Needed for compiling for c_bindings
1377 /// # let builder: lightning::offers::offer::OfferBuilder<_, _> = offer.into();
1378 /// # let offer = builder
1379 ///     .description(\"coffee\".to_string())
1380 ///     .amount_msats(10_000_000)
1381 ///     .build()?;
1382 /// let bech32_offer = offer.to_string();
1383 ///
1384 /// // On the event processing thread
1385 /// channel_manager.process_pending_events(&|event| match event {
1386 ///     Event::PaymentClaimable { payment_hash, purpose, .. } => match purpose {
1387 ///         PaymentPurpose::Bolt12OfferPayment { payment_preimage: Some(payment_preimage), .. } => {
1388 ///             println!(\"Claiming payment {}\", payment_hash);
1389 ///             channel_manager.claim_funds(payment_preimage);
1390 ///         },
1391 ///         PaymentPurpose::Bolt12OfferPayment { payment_preimage: None, .. } => {
1392 ///             println!(\"Unknown payment hash: {}\", payment_hash);
1393 ///         },
1394 ///         // ...
1395 /// #         _ => {},
1396 ///     },
1397 ///     Event::PaymentClaimed { payment_hash, amount_msat, .. } => {
1398 ///         println!(\"Claimed {} msats\", amount_msat);
1399 ///     },
1400 ///     // ...
1401 /// #     _ => {},
1402 /// });
1403 /// # Ok(())
1404 /// # }
1405 /// ```
1406 ///
1407 /// Use [`pay_for_offer`] to initiated payment, which sends an [`InvoiceRequest`] for an [`Offer`]
1408 /// and pays the [`Bolt12Invoice`] response. In addition to success and failure events,
1409 /// [`ChannelManager`] may also generate an [`Event::InvoiceRequestFailed`].
1410 ///
1411 /// ```
1412 /// # use lightning::events::{Event, EventsProvider};
1413 /// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, Retry};
1414 /// # use lightning::offers::offer::Offer;
1415 /// #
1416 /// # fn example<T: AChannelManager>(
1417 /// #     channel_manager: T, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
1418 /// #     payer_note: Option<String>, retry: Retry, max_total_routing_fee_msat: Option<u64>
1419 /// # ) {
1420 /// # let channel_manager = channel_manager.get_cm();
1421 /// let payment_id = PaymentId([42; 32]);
1422 /// match channel_manager.pay_for_offer(
1423 ///     offer, quantity, amount_msats, payer_note, payment_id, retry, max_total_routing_fee_msat
1424 /// ) {
1425 ///     Ok(()) => println!(\"Requesting invoice for offer\"),
1426 ///     Err(e) => println!(\"Unable to request invoice for offer: {:?}\", e),
1427 /// }
1428 ///
1429 /// // First the payment will be waiting on an invoice
1430 /// let expected_payment_id = payment_id;
1431 /// assert!(
1432 ///     channel_manager.list_recent_payments().iter().find(|details| matches!(
1433 ///         details,
1434 ///         RecentPaymentDetails::AwaitingInvoice { payment_id: expected_payment_id }
1435 ///     )).is_some()
1436 /// );
1437 ///
1438 /// // Once the invoice is received, a payment will be sent
1439 /// assert!(
1440 ///     channel_manager.list_recent_payments().iter().find(|details| matches!(
1441 ///         details,
1442 ///         RecentPaymentDetails::Pending { payment_id: expected_payment_id, ..  }
1443 ///     )).is_some()
1444 /// );
1445 ///
1446 /// // On the event processing thread
1447 /// channel_manager.process_pending_events(&|event| match event {
1448 ///     Event::PaymentSent { payment_id: Some(payment_id), .. } => println!(\"Paid {}\", payment_id),
1449 ///     Event::PaymentFailed { payment_id, .. } => println!(\"Failed paying {}\", payment_id),
1450 ///     Event::InvoiceRequestFailed { payment_id, .. } => println!(\"Failed paying {}\", payment_id),
1451 ///     // ...
1452 /// #     _ => {},
1453 /// });
1454 /// # }
1455 /// ```
1456 ///
1457 /// ## BOLT 12 Refunds
1458 ///
1459 /// A [`Refund`] is a request for an invoice to be paid. Like *paying* for an [`Offer`], *creating*
1460 /// a [`Refund`] involves maintaining state since it represents a future outbound payment.
1461 /// Therefore, use [`create_refund_builder`] when creating one, otherwise [`ChannelManager`] will
1462 /// refuse to pay any corresponding [`Bolt12Invoice`] that it receives.
1463 ///
1464 /// ```
1465 /// # use core::time::Duration;
1466 /// # use lightning::events::{Event, EventsProvider};
1467 /// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, Retry};
1468 /// # use lightning::offers::parse::Bolt12SemanticError;
1469 /// #
1470 /// # fn example<T: AChannelManager>(
1471 /// #     channel_manager: T, amount_msats: u64, absolute_expiry: Duration, retry: Retry,
1472 /// #     max_total_routing_fee_msat: Option<u64>
1473 /// # ) -> Result<(), Bolt12SemanticError> {
1474 /// # let channel_manager = channel_manager.get_cm();
1475 /// let payment_id = PaymentId([42; 32]);
1476 /// let refund = channel_manager
1477 ///     .create_refund_builder(
1478 ///         amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat
1479 ///     )?
1480 /// # ;
1481 /// # // Needed for compiling for c_bindings
1482 /// # let builder: lightning::offers::refund::RefundBuilder<_> = refund.into();
1483 /// # let refund = builder
1484 ///     .description(\"coffee\".to_string())
1485 ///     .payer_note(\"refund for order 1234\".to_string())
1486 ///     .build()?;
1487 /// let bech32_refund = refund.to_string();
1488 ///
1489 /// // First the payment will be waiting on an invoice
1490 /// let expected_payment_id = payment_id;
1491 /// assert!(
1492 ///     channel_manager.list_recent_payments().iter().find(|details| matches!(
1493 ///         details,
1494 ///         RecentPaymentDetails::AwaitingInvoice { payment_id: expected_payment_id }
1495 ///     )).is_some()
1496 /// );
1497 ///
1498 /// // Once the invoice is received, a payment will be sent
1499 /// assert!(
1500 ///     channel_manager.list_recent_payments().iter().find(|details| matches!(
1501 ///         details,
1502 ///         RecentPaymentDetails::Pending { payment_id: expected_payment_id, ..  }
1503 ///     )).is_some()
1504 /// );
1505 ///
1506 /// // On the event processing thread
1507 /// channel_manager.process_pending_events(&|event| match event {
1508 ///     Event::PaymentSent { payment_id: Some(payment_id), .. } => println!(\"Paid {}\", payment_id),
1509 ///     Event::PaymentFailed { payment_id, .. } => println!(\"Failed paying {}\", payment_id),
1510 ///     // ...
1511 /// #     _ => {},
1512 /// });
1513 /// # Ok(())
1514 /// # }
1515 /// ```
1516 ///
1517 /// Use [`request_refund_payment`] to send a [`Bolt12Invoice`] for receiving the refund. Similar to
1518 /// *creating* an [`Offer`], this is stateless as it represents an inbound payment.
1519 ///
1520 /// ```
1521 /// # use lightning::events::{Event, EventsProvider, PaymentPurpose};
1522 /// # use lightning::ln::channelmanager::AChannelManager;
1523 /// # use lightning::offers::refund::Refund;
1524 /// #
1525 /// # fn example<T: AChannelManager>(channel_manager: T, refund: &Refund) {
1526 /// # let channel_manager = channel_manager.get_cm();
1527 /// let known_payment_hash = match channel_manager.request_refund_payment(refund) {
1528 ///     Ok(invoice) => {
1529 ///         let payment_hash = invoice.payment_hash();
1530 ///         println!(\"Requesting refund payment {}\", payment_hash);
1531 ///         payment_hash
1532 ///     },
1533 ///     Err(e) => panic!(\"Unable to request payment for refund: {:?}\", e),
1534 /// };
1535 ///
1536 /// // On the event processing thread
1537 /// channel_manager.process_pending_events(&|event| match event {
1538 ///     Event::PaymentClaimable { payment_hash, purpose, .. } => match purpose {
1539 ///     \tPaymentPurpose::Bolt12RefundPayment { payment_preimage: Some(payment_preimage), .. } => {
1540 ///             assert_eq!(payment_hash, known_payment_hash);
1541 ///             println!(\"Claiming payment {}\", payment_hash);
1542 ///             channel_manager.claim_funds(payment_preimage);
1543 ///         },
1544 ///     \tPaymentPurpose::Bolt12RefundPayment { payment_preimage: None, .. } => {
1545 ///             println!(\"Unknown payment hash: {}\", payment_hash);
1546 ///     \t},
1547 ///         // ...
1548 /// #         _ => {},
1549 ///     },
1550 ///     Event::PaymentClaimed { payment_hash, amount_msat, .. } => {
1551 ///         assert_eq!(payment_hash, known_payment_hash);
1552 ///         println!(\"Claimed {} msats\", amount_msat);
1553 ///     },
1554 ///     // ...
1555 /// #     _ => {},
1556 /// });
1557 /// # }
1558 /// ```
1559 ///
1560 /// # Persistence
1561 ///
1562 /// Implements [`Writeable`] to write out all channel state to disk. Implies [`peer_disconnected`] for
1563 /// all peers during write/read (though does not modify this instance, only the instance being
1564 /// serialized). This will result in any channels which have not yet exchanged [`funding_created`] (i.e.,
1565 /// called [`funding_transaction_generated`] for outbound channels) being closed.
1566 ///
1567 /// Note that you can be a bit lazier about writing out `ChannelManager` than you can be with
1568 /// [`ChannelMonitor`]. With [`ChannelMonitor`] you MUST durably write each
1569 /// [`ChannelMonitorUpdate`] before returning from
1570 /// [`chain::Watch::watch_channel`]/[`update_channel`] or before completing async writes. With
1571 /// `ChannelManager`s, writing updates happens out-of-band (and will prevent any other
1572 /// `ChannelManager` operations from occurring during the serialization process). If the
1573 /// deserialized version is out-of-date compared to the [`ChannelMonitor`] passed by reference to
1574 /// [`read`], those channels will be force-closed based on the `ChannelMonitor` state and no funds
1575 /// will be lost (modulo on-chain transaction fees).
1576 ///
1577 /// Note that the deserializer is only implemented for `(`[`BlockHash`]`, `[`ChannelManager`]`)`, which
1578 /// tells you the last block hash which was connected. You should get the best block tip before using the manager.
1579 /// See [`chain::Listen`] and [`chain::Confirm`] for more details.
1580 ///
1581 /// # `ChannelUpdate` Messages
1582 ///
1583 /// Note that `ChannelManager` is responsible for tracking liveness of its channels and generating
1584 /// [`ChannelUpdate`] messages informing peers that the channel is temporarily disabled. To avoid
1585 /// spam due to quick disconnection/reconnection, updates are not sent until the channel has been
1586 /// offline for a full minute. In order to track this, you must call
1587 /// [`timer_tick_occurred`] roughly once per minute, though it doesn't have to be perfect.
1588 ///
1589 /// # DoS Mitigation
1590 ///
1591 /// To avoid trivial DoS issues, `ChannelManager` limits the number of inbound connections and
1592 /// inbound channels without confirmed funding transactions. This may result in nodes which we do
1593 /// not have a channel with being unable to connect to us or open new channels with us if we have
1594 /// many peers with unfunded channels.
1595 ///
1596 /// Because it is an indication of trust, inbound channels which we've accepted as 0conf are
1597 /// exempted from the count of unfunded channels. Similarly, outbound channels and connections are
1598 /// never limited. Please ensure you limit the count of such channels yourself.
1599 ///
1600 /// # Type Aliases
1601 ///
1602 /// Rather than using a plain `ChannelManager`, it is preferable to use either a [`SimpleArcChannelManager`]
1603 /// a [`SimpleRefChannelManager`], for conciseness. See their documentation for more details, but
1604 /// essentially you should default to using a [`SimpleRefChannelManager`], and use a
1605 /// [`SimpleArcChannelManager`] when you require a `ChannelManager` with a static lifetime, such as when
1606 /// you're using lightning-net-tokio.
1607 ///
1608 /// [`ChainMonitor`]: crate::chain::chainmonitor::ChainMonitor
1609 /// [`MessageHandler`]: crate::ln::peer_handler::MessageHandler
1610 /// [`OnionMessenger`]: crate::onion_message::messenger::OnionMessenger
1611 /// [`PeerManager::read_event`]: crate::ln::peer_handler::PeerManager::read_event
1612 /// [`PeerManager::process_events`]: crate::ln::peer_handler::PeerManager::process_events
1613 /// [`timer_tick_occurred`]: Self::timer_tick_occurred
1614 /// [`get_and_clear_needs_persistence`]: Self::get_and_clear_needs_persistence
1615 /// [`Persister`]: crate::util::persist::Persister
1616 /// [`KVStore`]: crate::util::persist::KVStore
1617 /// [`get_event_or_persistence_needed_future`]: Self::get_event_or_persistence_needed_future
1618 /// [`lightning-block-sync`]: https://docs.rs/lightning_block_sync/latest/lightning_block_sync
1619 /// [`lightning-transaction-sync`]: https://docs.rs/lightning_transaction_sync/latest/lightning_transaction_sync
1620 /// [`lightning-background-processor`]: https://docs.rs/lightning_background_processor/lightning_background_processor
1621 /// [`list_channels`]: Self::list_channels
1622 /// [`list_usable_channels`]: Self::list_usable_channels
1623 /// [`create_channel`]: Self::create_channel
1624 /// [`close_channel`]: Self::force_close_broadcasting_latest_txn
1625 /// [`force_close_broadcasting_latest_txn`]: Self::force_close_broadcasting_latest_txn
1626 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
1627 /// [BOLT 12]: https://github.com/rustyrussell/lightning-rfc/blob/guilt/offers/12-offer-encoding.md
1628 /// [`list_recent_payments`]: Self::list_recent_payments
1629 /// [`abandon_payment`]: Self::abandon_payment
1630 /// [`lightning-invoice`]: https://docs.rs/lightning_invoice/latest/lightning_invoice
1631 /// [`create_inbound_payment`]: Self::create_inbound_payment
1632 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1633 /// [`claim_funds`]: Self::claim_funds
1634 /// [`send_payment`]: Self::send_payment
1635 /// [`offers`]: crate::offers
1636 /// [`create_offer_builder`]: Self::create_offer_builder
1637 /// [`pay_for_offer`]: Self::pay_for_offer
1638 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
1639 /// [`create_refund_builder`]: Self::create_refund_builder
1640 /// [`request_refund_payment`]: Self::request_refund_payment
1641 /// [`peer_disconnected`]: msgs::ChannelMessageHandler::peer_disconnected
1642 /// [`funding_created`]: msgs::FundingCreated
1643 /// [`funding_transaction_generated`]: Self::funding_transaction_generated
1644 /// [`BlockHash`]: bitcoin::hash_types::BlockHash
1645 /// [`update_channel`]: chain::Watch::update_channel
1646 /// [`ChannelUpdate`]: msgs::ChannelUpdate
1647 /// [`read`]: ReadableArgs::read
1648 #[must_use]
1649 #[repr(C)]
1650 pub struct ChannelManager {
1651         /// A pointer to the opaque Rust object.
1652
1653         /// Nearly everywhere, inner must be non-null, however in places where
1654         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1655         pub inner: *mut nativeChannelManager,
1656         /// Indicates that this is the only struct which contains the same pointer.
1657
1658         /// Rust functions which take ownership of an object provided via an argument require
1659         /// this to be true and invalidate the object pointed to by inner.
1660         pub is_owned: bool,
1661 }
1662
1663 impl Drop for ChannelManager {
1664         fn drop(&mut self) {
1665                 if self.is_owned && !<*mut nativeChannelManager>::is_null(self.inner) {
1666                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1667                 }
1668         }
1669 }
1670 /// Frees any resources used by the ChannelManager, if is_owned is set and inner is non-NULL.
1671 #[no_mangle]
1672 pub extern "C" fn ChannelManager_free(this_obj: ChannelManager) { }
1673 #[allow(unused)]
1674 /// Used only if an object of this type is returned as a trait impl by a method
1675 pub(crate) extern "C" fn ChannelManager_free_void(this_ptr: *mut c_void) {
1676         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelManager) };
1677 }
1678 #[allow(unused)]
1679 impl ChannelManager {
1680         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManager {
1681                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1682         }
1683         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManager {
1684                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1685         }
1686         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1687         pub(crate) fn take_inner(mut self) -> *mut nativeChannelManager {
1688                 assert!(self.is_owned);
1689                 let ret = ObjOps::untweak_ptr(self.inner);
1690                 self.inner = core::ptr::null_mut();
1691                 ret
1692         }
1693 }
1694
1695 use lightning::ln::channelmanager::ChainParameters as nativeChainParametersImport;
1696 pub(crate) type nativeChainParameters = nativeChainParametersImport;
1697
1698 /// Chain-related parameters used to construct a new `ChannelManager`.
1699 ///
1700 /// Typically, the block-specific parameters are derived from the best block hash for the network,
1701 /// as a newly constructed `ChannelManager` will not have created any channels yet. These parameters
1702 /// are not needed when deserializing a previously constructed `ChannelManager`.
1703 #[must_use]
1704 #[repr(C)]
1705 pub struct ChainParameters {
1706         /// A pointer to the opaque Rust object.
1707
1708         /// Nearly everywhere, inner must be non-null, however in places where
1709         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1710         pub inner: *mut nativeChainParameters,
1711         /// Indicates that this is the only struct which contains the same pointer.
1712
1713         /// Rust functions which take ownership of an object provided via an argument require
1714         /// this to be true and invalidate the object pointed to by inner.
1715         pub is_owned: bool,
1716 }
1717
1718 impl Drop for ChainParameters {
1719         fn drop(&mut self) {
1720                 if self.is_owned && !<*mut nativeChainParameters>::is_null(self.inner) {
1721                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1722                 }
1723         }
1724 }
1725 /// Frees any resources used by the ChainParameters, if is_owned is set and inner is non-NULL.
1726 #[no_mangle]
1727 pub extern "C" fn ChainParameters_free(this_obj: ChainParameters) { }
1728 #[allow(unused)]
1729 /// Used only if an object of this type is returned as a trait impl by a method
1730 pub(crate) extern "C" fn ChainParameters_free_void(this_ptr: *mut c_void) {
1731         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChainParameters) };
1732 }
1733 #[allow(unused)]
1734 impl ChainParameters {
1735         pub(crate) fn get_native_ref(&self) -> &'static nativeChainParameters {
1736                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1737         }
1738         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChainParameters {
1739                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1740         }
1741         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1742         pub(crate) fn take_inner(mut self) -> *mut nativeChainParameters {
1743                 assert!(self.is_owned);
1744                 let ret = ObjOps::untweak_ptr(self.inner);
1745                 self.inner = core::ptr::null_mut();
1746                 ret
1747         }
1748 }
1749 /// The network for determining the `chain_hash` in Lightning messages.
1750 #[no_mangle]
1751 pub extern "C" fn ChainParameters_get_network(this_ptr: &ChainParameters) -> crate::bitcoin::network::Network {
1752         let mut inner_val = &mut this_ptr.get_native_mut_ref().network;
1753         crate::bitcoin::network::Network::from_bitcoin(inner_val)
1754 }
1755 /// The network for determining the `chain_hash` in Lightning messages.
1756 #[no_mangle]
1757 pub extern "C" fn ChainParameters_set_network(this_ptr: &mut ChainParameters, mut val: crate::bitcoin::network::Network) {
1758         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.network = val.into_bitcoin();
1759 }
1760 /// The hash and height of the latest block successfully connected.
1761 ///
1762 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
1763 #[no_mangle]
1764 pub extern "C" fn ChainParameters_get_best_block(this_ptr: &ChainParameters) -> crate::lightning::chain::BestBlock {
1765         let mut inner_val = &mut this_ptr.get_native_mut_ref().best_block;
1766         crate::lightning::chain::BestBlock { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::chain::BestBlock<>) as *mut _) }, is_owned: false }
1767 }
1768 /// The hash and height of the latest block successfully connected.
1769 ///
1770 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
1771 #[no_mangle]
1772 pub extern "C" fn ChainParameters_set_best_block(this_ptr: &mut ChainParameters, mut val: crate::lightning::chain::BestBlock) {
1773         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.best_block = *unsafe { Box::from_raw(val.take_inner()) };
1774 }
1775 /// Constructs a new ChainParameters given each field
1776 #[must_use]
1777 #[no_mangle]
1778 pub extern "C" fn ChainParameters_new(mut network_arg: crate::bitcoin::network::Network, mut best_block_arg: crate::lightning::chain::BestBlock) -> ChainParameters {
1779         ChainParameters { inner: ObjOps::heap_alloc(nativeChainParameters {
1780                 network: network_arg.into_bitcoin(),
1781                 best_block: *unsafe { Box::from_raw(best_block_arg.take_inner()) },
1782         }), is_owned: true }
1783 }
1784 impl Clone for ChainParameters {
1785         fn clone(&self) -> Self {
1786                 Self {
1787                         inner: if <*mut nativeChainParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
1788                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1789                         is_owned: true,
1790                 }
1791         }
1792 }
1793 #[allow(unused)]
1794 /// Used only if an object of this type is returned as a trait impl by a method
1795 pub(crate) extern "C" fn ChainParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
1796         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChainParameters)).clone() })) as *mut c_void
1797 }
1798 #[no_mangle]
1799 /// Creates a copy of the ChainParameters
1800 pub extern "C" fn ChainParameters_clone(orig: &ChainParameters) -> ChainParameters {
1801         orig.clone()
1802 }
1803 /// The amount of time in blocks we require our counterparty wait to claim their money (ie time
1804 /// between when we, or our watchtower, must check for them having broadcast a theft transaction).
1805 ///
1806 /// This can be increased (but not decreased) through [`ChannelHandshakeConfig::our_to_self_delay`]
1807 ///
1808 /// [`ChannelHandshakeConfig::our_to_self_delay`]: crate::util::config::ChannelHandshakeConfig::our_to_self_delay
1809
1810 #[no_mangle]
1811 pub static BREAKDOWN_TIMEOUT: u16 = lightning::ln::channelmanager::BREAKDOWN_TIMEOUT;
1812 /// The minimum number of blocks between an inbound HTLC's CLTV and the corresponding outbound
1813 /// HTLC's CLTV. The current default represents roughly seven hours of blocks at six blocks/hour.
1814 ///
1815 /// This can be increased (but not decreased) through [`ChannelConfig::cltv_expiry_delta`]
1816 ///
1817 /// [`ChannelConfig::cltv_expiry_delta`]: crate::util::config::ChannelConfig::cltv_expiry_delta
1818
1819 #[no_mangle]
1820 pub static MIN_CLTV_EXPIRY_DELTA: u16 = lightning::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA;
1821 /// Minimum CLTV difference between the current block height and received inbound payments.
1822 /// Invoices generated for payment to us must set their `min_final_cltv_expiry_delta` field to at least
1823 /// this value.
1824
1825 #[no_mangle]
1826 pub static MIN_FINAL_CLTV_EXPIRY_DELTA: u16 = lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA;
1827
1828 use lightning::ln::channelmanager::CounterpartyForwardingInfo as nativeCounterpartyForwardingInfoImport;
1829 pub(crate) type nativeCounterpartyForwardingInfo = nativeCounterpartyForwardingInfoImport;
1830
1831 /// Information needed for constructing an invoice route hint for this channel.
1832 #[must_use]
1833 #[repr(C)]
1834 pub struct CounterpartyForwardingInfo {
1835         /// A pointer to the opaque Rust object.
1836
1837         /// Nearly everywhere, inner must be non-null, however in places where
1838         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1839         pub inner: *mut nativeCounterpartyForwardingInfo,
1840         /// Indicates that this is the only struct which contains the same pointer.
1841
1842         /// Rust functions which take ownership of an object provided via an argument require
1843         /// this to be true and invalidate the object pointed to by inner.
1844         pub is_owned: bool,
1845 }
1846
1847 impl Drop for CounterpartyForwardingInfo {
1848         fn drop(&mut self) {
1849                 if self.is_owned && !<*mut nativeCounterpartyForwardingInfo>::is_null(self.inner) {
1850                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1851                 }
1852         }
1853 }
1854 /// Frees any resources used by the CounterpartyForwardingInfo, if is_owned is set and inner is non-NULL.
1855 #[no_mangle]
1856 pub extern "C" fn CounterpartyForwardingInfo_free(this_obj: CounterpartyForwardingInfo) { }
1857 #[allow(unused)]
1858 /// Used only if an object of this type is returned as a trait impl by a method
1859 pub(crate) extern "C" fn CounterpartyForwardingInfo_free_void(this_ptr: *mut c_void) {
1860         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeCounterpartyForwardingInfo) };
1861 }
1862 #[allow(unused)]
1863 impl CounterpartyForwardingInfo {
1864         pub(crate) fn get_native_ref(&self) -> &'static nativeCounterpartyForwardingInfo {
1865                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1866         }
1867         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCounterpartyForwardingInfo {
1868                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1869         }
1870         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1871         pub(crate) fn take_inner(mut self) -> *mut nativeCounterpartyForwardingInfo {
1872                 assert!(self.is_owned);
1873                 let ret = ObjOps::untweak_ptr(self.inner);
1874                 self.inner = core::ptr::null_mut();
1875                 ret
1876         }
1877 }
1878 /// Base routing fee in millisatoshis.
1879 #[no_mangle]
1880 pub extern "C" fn CounterpartyForwardingInfo_get_fee_base_msat(this_ptr: &CounterpartyForwardingInfo) -> u32 {
1881         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_base_msat;
1882         *inner_val
1883 }
1884 /// Base routing fee in millisatoshis.
1885 #[no_mangle]
1886 pub extern "C" fn CounterpartyForwardingInfo_set_fee_base_msat(this_ptr: &mut CounterpartyForwardingInfo, mut val: u32) {
1887         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_base_msat = val;
1888 }
1889 /// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
1890 #[no_mangle]
1891 pub extern "C" fn CounterpartyForwardingInfo_get_fee_proportional_millionths(this_ptr: &CounterpartyForwardingInfo) -> u32 {
1892         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_proportional_millionths;
1893         *inner_val
1894 }
1895 /// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
1896 #[no_mangle]
1897 pub extern "C" fn CounterpartyForwardingInfo_set_fee_proportional_millionths(this_ptr: &mut CounterpartyForwardingInfo, mut val: u32) {
1898         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_proportional_millionths = val;
1899 }
1900 /// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
1901 /// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
1902 /// `cltv_expiry_delta` for more details.
1903 #[no_mangle]
1904 pub extern "C" fn CounterpartyForwardingInfo_get_cltv_expiry_delta(this_ptr: &CounterpartyForwardingInfo) -> u16 {
1905         let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
1906         *inner_val
1907 }
1908 /// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
1909 /// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
1910 /// `cltv_expiry_delta` for more details.
1911 #[no_mangle]
1912 pub extern "C" fn CounterpartyForwardingInfo_set_cltv_expiry_delta(this_ptr: &mut CounterpartyForwardingInfo, mut val: u16) {
1913         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
1914 }
1915 /// Constructs a new CounterpartyForwardingInfo given each field
1916 #[must_use]
1917 #[no_mangle]
1918 pub extern "C" fn CounterpartyForwardingInfo_new(mut fee_base_msat_arg: u32, mut fee_proportional_millionths_arg: u32, mut cltv_expiry_delta_arg: u16) -> CounterpartyForwardingInfo {
1919         CounterpartyForwardingInfo { inner: ObjOps::heap_alloc(nativeCounterpartyForwardingInfo {
1920                 fee_base_msat: fee_base_msat_arg,
1921                 fee_proportional_millionths: fee_proportional_millionths_arg,
1922                 cltv_expiry_delta: cltv_expiry_delta_arg,
1923         }), is_owned: true }
1924 }
1925 impl Clone for CounterpartyForwardingInfo {
1926         fn clone(&self) -> Self {
1927                 Self {
1928                         inner: if <*mut nativeCounterpartyForwardingInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1929                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1930                         is_owned: true,
1931                 }
1932         }
1933 }
1934 #[allow(unused)]
1935 /// Used only if an object of this type is returned as a trait impl by a method
1936 pub(crate) extern "C" fn CounterpartyForwardingInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1937         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeCounterpartyForwardingInfo)).clone() })) as *mut c_void
1938 }
1939 #[no_mangle]
1940 /// Creates a copy of the CounterpartyForwardingInfo
1941 pub extern "C" fn CounterpartyForwardingInfo_clone(orig: &CounterpartyForwardingInfo) -> CounterpartyForwardingInfo {
1942         orig.clone()
1943 }
1944 /// Get a string which allows debug introspection of a CounterpartyForwardingInfo object
1945 pub extern "C" fn CounterpartyForwardingInfo_debug_str_void(o: *const c_void) -> Str {
1946         alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channelmanager::CounterpartyForwardingInfo }).into()}
1947
1948 use lightning::ln::channelmanager::ChannelCounterparty as nativeChannelCounterpartyImport;
1949 pub(crate) type nativeChannelCounterparty = nativeChannelCounterpartyImport;
1950
1951 /// Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
1952 /// to better separate parameters.
1953 #[must_use]
1954 #[repr(C)]
1955 pub struct ChannelCounterparty {
1956         /// A pointer to the opaque Rust object.
1957
1958         /// Nearly everywhere, inner must be non-null, however in places where
1959         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1960         pub inner: *mut nativeChannelCounterparty,
1961         /// Indicates that this is the only struct which contains the same pointer.
1962
1963         /// Rust functions which take ownership of an object provided via an argument require
1964         /// this to be true and invalidate the object pointed to by inner.
1965         pub is_owned: bool,
1966 }
1967
1968 impl Drop for ChannelCounterparty {
1969         fn drop(&mut self) {
1970                 if self.is_owned && !<*mut nativeChannelCounterparty>::is_null(self.inner) {
1971                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1972                 }
1973         }
1974 }
1975 /// Frees any resources used by the ChannelCounterparty, if is_owned is set and inner is non-NULL.
1976 #[no_mangle]
1977 pub extern "C" fn ChannelCounterparty_free(this_obj: ChannelCounterparty) { }
1978 #[allow(unused)]
1979 /// Used only if an object of this type is returned as a trait impl by a method
1980 pub(crate) extern "C" fn ChannelCounterparty_free_void(this_ptr: *mut c_void) {
1981         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelCounterparty) };
1982 }
1983 #[allow(unused)]
1984 impl ChannelCounterparty {
1985         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelCounterparty {
1986                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1987         }
1988         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelCounterparty {
1989                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1990         }
1991         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1992         pub(crate) fn take_inner(mut self) -> *mut nativeChannelCounterparty {
1993                 assert!(self.is_owned);
1994                 let ret = ObjOps::untweak_ptr(self.inner);
1995                 self.inner = core::ptr::null_mut();
1996                 ret
1997         }
1998 }
1999 /// The node_id of our counterparty
2000 #[no_mangle]
2001 pub extern "C" fn ChannelCounterparty_get_node_id(this_ptr: &ChannelCounterparty) -> crate::c_types::PublicKey {
2002         let mut inner_val = &mut this_ptr.get_native_mut_ref().node_id;
2003         crate::c_types::PublicKey::from_rust(&inner_val)
2004 }
2005 /// The node_id of our counterparty
2006 #[no_mangle]
2007 pub extern "C" fn ChannelCounterparty_set_node_id(this_ptr: &mut ChannelCounterparty, mut val: crate::c_types::PublicKey) {
2008         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_id = val.into_rust();
2009 }
2010 /// The Features the channel counterparty provided upon last connection.
2011 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
2012 /// many routing-relevant features are present in the init context.
2013 #[no_mangle]
2014 pub extern "C" fn ChannelCounterparty_get_features(this_ptr: &ChannelCounterparty) -> crate::lightning::ln::features::InitFeatures {
2015         let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
2016         crate::lightning::ln::features::InitFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::features::InitFeatures<>) as *mut _) }, is_owned: false }
2017 }
2018 /// The Features the channel counterparty provided upon last connection.
2019 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
2020 /// many routing-relevant features are present in the init context.
2021 #[no_mangle]
2022 pub extern "C" fn ChannelCounterparty_set_features(this_ptr: &mut ChannelCounterparty, mut val: crate::lightning::ln::features::InitFeatures) {
2023         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
2024 }
2025 /// The value, in satoshis, that must always be held in the channel for our counterparty. This
2026 /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
2027 /// claiming at least this value on chain.
2028 ///
2029 /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
2030 ///
2031 /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
2032 #[no_mangle]
2033 pub extern "C" fn ChannelCounterparty_get_unspendable_punishment_reserve(this_ptr: &ChannelCounterparty) -> u64 {
2034         let mut inner_val = &mut this_ptr.get_native_mut_ref().unspendable_punishment_reserve;
2035         *inner_val
2036 }
2037 /// The value, in satoshis, that must always be held in the channel for our counterparty. This
2038 /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
2039 /// claiming at least this value on chain.
2040 ///
2041 /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
2042 ///
2043 /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
2044 #[no_mangle]
2045 pub extern "C" fn ChannelCounterparty_set_unspendable_punishment_reserve(this_ptr: &mut ChannelCounterparty, mut val: u64) {
2046         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = val;
2047 }
2048 /// Information on the fees and requirements that the counterparty requires when forwarding
2049 /// payments to us through this channel.
2050 ///
2051 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2052 #[no_mangle]
2053 pub extern "C" fn ChannelCounterparty_get_forwarding_info(this_ptr: &ChannelCounterparty) -> crate::lightning::ln::channelmanager::CounterpartyForwardingInfo {
2054         let mut inner_val = &mut this_ptr.get_native_mut_ref().forwarding_info;
2055         let mut local_inner_val = crate::lightning::ln::channelmanager::CounterpartyForwardingInfo { 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::channelmanager::CounterpartyForwardingInfo<>) as *mut _ }, is_owned: false };
2056         local_inner_val
2057 }
2058 /// Information on the fees and requirements that the counterparty requires when forwarding
2059 /// payments to us through this channel.
2060 ///
2061 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
2062 #[no_mangle]
2063 pub extern "C" fn ChannelCounterparty_set_forwarding_info(this_ptr: &mut ChannelCounterparty, mut val: crate::lightning::ln::channelmanager::CounterpartyForwardingInfo) {
2064         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
2065         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.forwarding_info = local_val;
2066 }
2067 /// The smallest value HTLC (in msat) the remote peer will accept, for this channel. This field
2068 /// is only `None` before we have received either the `OpenChannel` or `AcceptChannel` message
2069 /// from the remote peer, or for `ChannelCounterparty` objects serialized prior to LDK 0.0.107.
2070 #[no_mangle]
2071 pub extern "C" fn ChannelCounterparty_get_outbound_htlc_minimum_msat(this_ptr: &ChannelCounterparty) -> crate::c_types::derived::COption_u64Z {
2072         let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_htlc_minimum_msat;
2073         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) };
2074         local_inner_val
2075 }
2076 /// The smallest value HTLC (in msat) the remote peer will accept, for this channel. This field
2077 /// is only `None` before we have received either the `OpenChannel` or `AcceptChannel` message
2078 /// from the remote peer, or for `ChannelCounterparty` objects serialized prior to LDK 0.0.107.
2079 #[no_mangle]
2080 pub extern "C" fn ChannelCounterparty_set_outbound_htlc_minimum_msat(this_ptr: &mut ChannelCounterparty, mut val: crate::c_types::derived::COption_u64Z) {
2081         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2082         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_htlc_minimum_msat = local_val;
2083 }
2084 /// The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
2085 #[no_mangle]
2086 pub extern "C" fn ChannelCounterparty_get_outbound_htlc_maximum_msat(this_ptr: &ChannelCounterparty) -> crate::c_types::derived::COption_u64Z {
2087         let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_htlc_maximum_msat;
2088         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) };
2089         local_inner_val
2090 }
2091 /// The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
2092 #[no_mangle]
2093 pub extern "C" fn ChannelCounterparty_set_outbound_htlc_maximum_msat(this_ptr: &mut ChannelCounterparty, mut val: crate::c_types::derived::COption_u64Z) {
2094         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2095         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_htlc_maximum_msat = local_val;
2096 }
2097 /// Constructs a new ChannelCounterparty given each field
2098 ///
2099 /// Note that forwarding_info_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
2100 #[must_use]
2101 #[no_mangle]
2102 pub extern "C" fn ChannelCounterparty_new(mut node_id_arg: crate::c_types::PublicKey, mut features_arg: crate::lightning::ln::features::InitFeatures, mut unspendable_punishment_reserve_arg: u64, mut forwarding_info_arg: crate::lightning::ln::channelmanager::CounterpartyForwardingInfo, mut outbound_htlc_minimum_msat_arg: crate::c_types::derived::COption_u64Z, mut outbound_htlc_maximum_msat_arg: crate::c_types::derived::COption_u64Z) -> ChannelCounterparty {
2103         let mut local_forwarding_info_arg = if forwarding_info_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(forwarding_info_arg.take_inner()) } }) };
2104         let mut local_outbound_htlc_minimum_msat_arg = if outbound_htlc_minimum_msat_arg.is_some() { Some( { outbound_htlc_minimum_msat_arg.take() }) } else { None };
2105         let mut local_outbound_htlc_maximum_msat_arg = if outbound_htlc_maximum_msat_arg.is_some() { Some( { outbound_htlc_maximum_msat_arg.take() }) } else { None };
2106         ChannelCounterparty { inner: ObjOps::heap_alloc(nativeChannelCounterparty {
2107                 node_id: node_id_arg.into_rust(),
2108                 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
2109                 unspendable_punishment_reserve: unspendable_punishment_reserve_arg,
2110                 forwarding_info: local_forwarding_info_arg,
2111                 outbound_htlc_minimum_msat: local_outbound_htlc_minimum_msat_arg,
2112                 outbound_htlc_maximum_msat: local_outbound_htlc_maximum_msat_arg,
2113         }), is_owned: true }
2114 }
2115 impl Clone for ChannelCounterparty {
2116         fn clone(&self) -> Self {
2117                 Self {
2118                         inner: if <*mut nativeChannelCounterparty>::is_null(self.inner) { core::ptr::null_mut() } else {
2119                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2120                         is_owned: true,
2121                 }
2122         }
2123 }
2124 #[allow(unused)]
2125 /// Used only if an object of this type is returned as a trait impl by a method
2126 pub(crate) extern "C" fn ChannelCounterparty_clone_void(this_ptr: *const c_void) -> *mut c_void {
2127         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelCounterparty)).clone() })) as *mut c_void
2128 }
2129 #[no_mangle]
2130 /// Creates a copy of the ChannelCounterparty
2131 pub extern "C" fn ChannelCounterparty_clone(orig: &ChannelCounterparty) -> ChannelCounterparty {
2132         orig.clone()
2133 }
2134 /// Get a string which allows debug introspection of a ChannelCounterparty object
2135 pub extern "C" fn ChannelCounterparty_debug_str_void(o: *const c_void) -> Str {
2136         alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channelmanager::ChannelCounterparty }).into()}
2137
2138 use lightning::ln::channelmanager::ChannelDetails as nativeChannelDetailsImport;
2139 pub(crate) type nativeChannelDetails = nativeChannelDetailsImport;
2140
2141 /// Details of a channel, as returned by [`ChannelManager::list_channels`] and [`ChannelManager::list_usable_channels`]
2142 #[must_use]
2143 #[repr(C)]
2144 pub struct ChannelDetails {
2145         /// A pointer to the opaque Rust object.
2146
2147         /// Nearly everywhere, inner must be non-null, however in places where
2148         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2149         pub inner: *mut nativeChannelDetails,
2150         /// Indicates that this is the only struct which contains the same pointer.
2151
2152         /// Rust functions which take ownership of an object provided via an argument require
2153         /// this to be true and invalidate the object pointed to by inner.
2154         pub is_owned: bool,
2155 }
2156
2157 impl Drop for ChannelDetails {
2158         fn drop(&mut self) {
2159                 if self.is_owned && !<*mut nativeChannelDetails>::is_null(self.inner) {
2160                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2161                 }
2162         }
2163 }
2164 /// Frees any resources used by the ChannelDetails, if is_owned is set and inner is non-NULL.
2165 #[no_mangle]
2166 pub extern "C" fn ChannelDetails_free(this_obj: ChannelDetails) { }
2167 #[allow(unused)]
2168 /// Used only if an object of this type is returned as a trait impl by a method
2169 pub(crate) extern "C" fn ChannelDetails_free_void(this_ptr: *mut c_void) {
2170         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelDetails) };
2171 }
2172 #[allow(unused)]
2173 impl ChannelDetails {
2174         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelDetails {
2175                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2176         }
2177         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelDetails {
2178                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2179         }
2180         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2181         pub(crate) fn take_inner(mut self) -> *mut nativeChannelDetails {
2182                 assert!(self.is_owned);
2183                 let ret = ObjOps::untweak_ptr(self.inner);
2184                 self.inner = core::ptr::null_mut();
2185                 ret
2186         }
2187 }
2188 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
2189 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
2190 /// Note that this means this value is *not* persistent - it can change once during the
2191 /// lifetime of the channel.
2192 #[no_mangle]
2193 pub extern "C" fn ChannelDetails_get_channel_id(this_ptr: &ChannelDetails) -> crate::lightning::ln::types::ChannelId {
2194         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id;
2195         crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false }
2196 }
2197 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
2198 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
2199 /// Note that this means this value is *not* persistent - it can change once during the
2200 /// lifetime of the channel.
2201 #[no_mangle]
2202 pub extern "C" fn ChannelDetails_set_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::lightning::ln::types::ChannelId) {
2203         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) };
2204 }
2205 /// Parameters which apply to our counterparty. See individual fields for more information.
2206 #[no_mangle]
2207 pub extern "C" fn ChannelDetails_get_counterparty(this_ptr: &ChannelDetails) -> crate::lightning::ln::channelmanager::ChannelCounterparty {
2208         let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty;
2209         crate::lightning::ln::channelmanager::ChannelCounterparty { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::channelmanager::ChannelCounterparty<>) as *mut _) }, is_owned: false }
2210 }
2211 /// Parameters which apply to our counterparty. See individual fields for more information.
2212 #[no_mangle]
2213 pub extern "C" fn ChannelDetails_set_counterparty(this_ptr: &mut ChannelDetails, mut val: crate::lightning::ln::channelmanager::ChannelCounterparty) {
2214         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty = *unsafe { Box::from_raw(val.take_inner()) };
2215 }
2216 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
2217 /// our counterparty already.
2218 ///
2219 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2220 #[no_mangle]
2221 pub extern "C" fn ChannelDetails_get_funding_txo(this_ptr: &ChannelDetails) -> crate::lightning::chain::transaction::OutPoint {
2222         let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_txo;
2223         let mut local_inner_val = crate::lightning::chain::transaction::OutPoint { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::chain::transaction::OutPoint<>) as *mut _ }, is_owned: false };
2224         local_inner_val
2225 }
2226 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
2227 /// our counterparty already.
2228 ///
2229 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
2230 #[no_mangle]
2231 pub extern "C" fn ChannelDetails_set_funding_txo(this_ptr: &mut ChannelDetails, mut val: crate::lightning::chain::transaction::OutPoint) {
2232         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
2233         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_txo = local_val;
2234 }
2235 /// The features which this channel operates with. See individual features for more info.
2236 ///
2237 /// `None` until negotiation completes and the channel type is finalized.
2238 ///
2239 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2240 #[no_mangle]
2241 pub extern "C" fn ChannelDetails_get_channel_type(this_ptr: &ChannelDetails) -> crate::lightning::ln::features::ChannelTypeFeatures {
2242         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_type;
2243         let mut local_inner_val = crate::lightning::ln::features::ChannelTypeFeatures { 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::features::ChannelTypeFeatures<>) as *mut _ }, is_owned: false };
2244         local_inner_val
2245 }
2246 /// The features which this channel operates with. See individual features for more info.
2247 ///
2248 /// `None` until negotiation completes and the channel type is finalized.
2249 ///
2250 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
2251 #[no_mangle]
2252 pub extern "C" fn ChannelDetails_set_channel_type(this_ptr: &mut ChannelDetails, mut val: crate::lightning::ln::features::ChannelTypeFeatures) {
2253         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
2254         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_type = local_val;
2255 }
2256 /// The position of the funding transaction in the chain. None if the funding transaction has
2257 /// not yet been confirmed and the channel fully opened.
2258 ///
2259 /// Note that if [`inbound_scid_alias`] is set, it must be used for invoices and inbound
2260 /// payments instead of this. See [`get_inbound_payment_scid`].
2261 ///
2262 /// For channels with [`confirmations_required`] set to `Some(0)`, [`outbound_scid_alias`] may
2263 /// be used in place of this in outbound routes. See [`get_outbound_payment_scid`].
2264 ///
2265 /// [`inbound_scid_alias`]: Self::inbound_scid_alias
2266 /// [`outbound_scid_alias`]: Self::outbound_scid_alias
2267 /// [`get_inbound_payment_scid`]: Self::get_inbound_payment_scid
2268 /// [`get_outbound_payment_scid`]: Self::get_outbound_payment_scid
2269 /// [`confirmations_required`]: Self::confirmations_required
2270 #[no_mangle]
2271 pub extern "C" fn ChannelDetails_get_short_channel_id(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
2272         let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
2273         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) };
2274         local_inner_val
2275 }
2276 /// The position of the funding transaction in the chain. None if the funding transaction has
2277 /// not yet been confirmed and the channel fully opened.
2278 ///
2279 /// Note that if [`inbound_scid_alias`] is set, it must be used for invoices and inbound
2280 /// payments instead of this. See [`get_inbound_payment_scid`].
2281 ///
2282 /// For channels with [`confirmations_required`] set to `Some(0)`, [`outbound_scid_alias`] may
2283 /// be used in place of this in outbound routes. See [`get_outbound_payment_scid`].
2284 ///
2285 /// [`inbound_scid_alias`]: Self::inbound_scid_alias
2286 /// [`outbound_scid_alias`]: Self::outbound_scid_alias
2287 /// [`get_inbound_payment_scid`]: Self::get_inbound_payment_scid
2288 /// [`get_outbound_payment_scid`]: Self::get_outbound_payment_scid
2289 /// [`confirmations_required`]: Self::confirmations_required
2290 #[no_mangle]
2291 pub extern "C" fn ChannelDetails_set_short_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
2292         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2293         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = local_val;
2294 }
2295 /// An optional [`short_channel_id`] alias for this channel, randomly generated by us and
2296 /// usable in place of [`short_channel_id`] to reference the channel in outbound routes when
2297 /// the channel has not yet been confirmed (as long as [`confirmations_required`] is
2298 /// `Some(0)`).
2299 ///
2300 /// This will be `None` as long as the channel is not available for routing outbound payments.
2301 ///
2302 /// [`short_channel_id`]: Self::short_channel_id
2303 /// [`confirmations_required`]: Self::confirmations_required
2304 #[no_mangle]
2305 pub extern "C" fn ChannelDetails_get_outbound_scid_alias(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
2306         let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_scid_alias;
2307         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) };
2308         local_inner_val
2309 }
2310 /// An optional [`short_channel_id`] alias for this channel, randomly generated by us and
2311 /// usable in place of [`short_channel_id`] to reference the channel in outbound routes when
2312 /// the channel has not yet been confirmed (as long as [`confirmations_required`] is
2313 /// `Some(0)`).
2314 ///
2315 /// This will be `None` as long as the channel is not available for routing outbound payments.
2316 ///
2317 /// [`short_channel_id`]: Self::short_channel_id
2318 /// [`confirmations_required`]: Self::confirmations_required
2319 #[no_mangle]
2320 pub extern "C" fn ChannelDetails_set_outbound_scid_alias(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
2321         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2322         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_scid_alias = local_val;
2323 }
2324 /// An optional [`short_channel_id`] alias for this channel, randomly generated by our
2325 /// counterparty and usable in place of [`short_channel_id`] in invoice route hints. Our
2326 /// counterparty will recognize the alias provided here in place of the [`short_channel_id`]
2327 /// when they see a payment to be routed to us.
2328 ///
2329 /// Our counterparty may choose to rotate this value at any time, though will always recognize
2330 /// previous values for inbound payment forwarding.
2331 ///
2332 /// [`short_channel_id`]: Self::short_channel_id
2333 #[no_mangle]
2334 pub extern "C" fn ChannelDetails_get_inbound_scid_alias(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
2335         let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_scid_alias;
2336         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) };
2337         local_inner_val
2338 }
2339 /// An optional [`short_channel_id`] alias for this channel, randomly generated by our
2340 /// counterparty and usable in place of [`short_channel_id`] in invoice route hints. Our
2341 /// counterparty will recognize the alias provided here in place of the [`short_channel_id`]
2342 /// when they see a payment to be routed to us.
2343 ///
2344 /// Our counterparty may choose to rotate this value at any time, though will always recognize
2345 /// previous values for inbound payment forwarding.
2346 ///
2347 /// [`short_channel_id`]: Self::short_channel_id
2348 #[no_mangle]
2349 pub extern "C" fn ChannelDetails_set_inbound_scid_alias(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
2350         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2351         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_scid_alias = local_val;
2352 }
2353 /// The value, in satoshis, of this channel as appears in the funding output
2354 #[no_mangle]
2355 pub extern "C" fn ChannelDetails_get_channel_value_satoshis(this_ptr: &ChannelDetails) -> u64 {
2356         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
2357         *inner_val
2358 }
2359 /// The value, in satoshis, of this channel as appears in the funding output
2360 #[no_mangle]
2361 pub extern "C" fn ChannelDetails_set_channel_value_satoshis(this_ptr: &mut ChannelDetails, mut val: u64) {
2362         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
2363 }
2364 /// The value, in satoshis, that must always be held in the channel for us. This value ensures
2365 /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
2366 /// this value on chain.
2367 ///
2368 /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
2369 ///
2370 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
2371 ///
2372 /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
2373 #[no_mangle]
2374 pub extern "C" fn ChannelDetails_get_unspendable_punishment_reserve(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
2375         let mut inner_val = &mut this_ptr.get_native_mut_ref().unspendable_punishment_reserve;
2376         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) };
2377         local_inner_val
2378 }
2379 /// The value, in satoshis, that must always be held in the channel for us. This value ensures
2380 /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
2381 /// this value on chain.
2382 ///
2383 /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
2384 ///
2385 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
2386 ///
2387 /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
2388 #[no_mangle]
2389 pub extern "C" fn ChannelDetails_set_unspendable_punishment_reserve(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
2390         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2391         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = local_val;
2392 }
2393 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
2394 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
2395 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
2396 /// `user_channel_id` will be randomized for an inbound channel.  This may be zero for objects
2397 /// serialized with LDK versions prior to 0.0.113.
2398 ///
2399 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
2400 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
2401 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
2402 #[no_mangle]
2403 pub extern "C" fn ChannelDetails_get_user_channel_id(this_ptr: &ChannelDetails) -> crate::c_types::U128 {
2404         let mut inner_val = &mut this_ptr.get_native_mut_ref().user_channel_id;
2405         inner_val.into()
2406 }
2407 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
2408 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
2409 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
2410 /// `user_channel_id` will be randomized for an inbound channel.  This may be zero for objects
2411 /// serialized with LDK versions prior to 0.0.113.
2412 ///
2413 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
2414 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
2415 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
2416 #[no_mangle]
2417 pub extern "C" fn ChannelDetails_set_user_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::U128) {
2418         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.user_channel_id = val.into();
2419 }
2420 /// The currently negotiated fee rate denominated in satoshi per 1000 weight units,
2421 /// which is applied to commitment and HTLC transactions.
2422 ///
2423 /// This value will be `None` for objects serialized with LDK versions prior to 0.0.115.
2424 #[no_mangle]
2425 pub extern "C" fn ChannelDetails_get_feerate_sat_per_1000_weight(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u32Z {
2426         let mut inner_val = &mut this_ptr.get_native_mut_ref().feerate_sat_per_1000_weight;
2427         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u32Z::None } else { crate::c_types::derived::COption_u32Z::Some( { inner_val.unwrap() }) };
2428         local_inner_val
2429 }
2430 /// The currently negotiated fee rate denominated in satoshi per 1000 weight units,
2431 /// which is applied to commitment and HTLC transactions.
2432 ///
2433 /// This value will be `None` for objects serialized with LDK versions prior to 0.0.115.
2434 #[no_mangle]
2435 pub extern "C" fn ChannelDetails_set_feerate_sat_per_1000_weight(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u32Z) {
2436         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2437         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.feerate_sat_per_1000_weight = local_val;
2438 }
2439 /// Our total balance.  This is the amount we would get if we close the channel.
2440 /// This value is not exact. Due to various in-flight changes and feerate changes, exactly this
2441 /// amount is not likely to be recoverable on close.
2442 ///
2443 /// This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose
2444 /// balance is not available for inclusion in new outbound HTLCs). This further does not include
2445 /// any pending outgoing HTLCs which are awaiting some other resolution to be sent.
2446 /// This does not consider any on-chain fees.
2447 ///
2448 /// See also [`ChannelDetails::outbound_capacity_msat`]
2449 #[no_mangle]
2450 pub extern "C" fn ChannelDetails_get_balance_msat(this_ptr: &ChannelDetails) -> u64 {
2451         let mut inner_val = &mut this_ptr.get_native_mut_ref().balance_msat;
2452         *inner_val
2453 }
2454 /// Our total balance.  This is the amount we would get if we close the channel.
2455 /// This value is not exact. Due to various in-flight changes and feerate changes, exactly this
2456 /// amount is not likely to be recoverable on close.
2457 ///
2458 /// This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose
2459 /// balance is not available for inclusion in new outbound HTLCs). This further does not include
2460 /// any pending outgoing HTLCs which are awaiting some other resolution to be sent.
2461 /// This does not consider any on-chain fees.
2462 ///
2463 /// See also [`ChannelDetails::outbound_capacity_msat`]
2464 #[no_mangle]
2465 pub extern "C" fn ChannelDetails_set_balance_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
2466         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.balance_msat = val;
2467 }
2468 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
2469 /// any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
2470 /// available for inclusion in new outbound HTLCs). This further does not include any pending
2471 /// outgoing HTLCs which are awaiting some other resolution to be sent.
2472 ///
2473 /// See also [`ChannelDetails::balance_msat`]
2474 ///
2475 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
2476 /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
2477 /// should be able to spend nearly this amount.
2478 #[no_mangle]
2479 pub extern "C" fn ChannelDetails_get_outbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
2480         let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_capacity_msat;
2481         *inner_val
2482 }
2483 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
2484 /// any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
2485 /// available for inclusion in new outbound HTLCs). This further does not include any pending
2486 /// outgoing HTLCs which are awaiting some other resolution to be sent.
2487 ///
2488 /// See also [`ChannelDetails::balance_msat`]
2489 ///
2490 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
2491 /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
2492 /// should be able to spend nearly this amount.
2493 #[no_mangle]
2494 pub extern "C" fn ChannelDetails_set_outbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
2495         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_capacity_msat = val;
2496 }
2497 /// The available outbound capacity for sending a single HTLC to the remote peer. This is
2498 /// similar to [`ChannelDetails::outbound_capacity_msat`] but it may be further restricted by
2499 /// the current state and per-HTLC limit(s). This is intended for use when routing, allowing us
2500 /// to use a limit as close as possible to the HTLC limit we can currently send.
2501 ///
2502 /// See also [`ChannelDetails::next_outbound_htlc_minimum_msat`],
2503 /// [`ChannelDetails::balance_msat`], and [`ChannelDetails::outbound_capacity_msat`].
2504 #[no_mangle]
2505 pub extern "C" fn ChannelDetails_get_next_outbound_htlc_limit_msat(this_ptr: &ChannelDetails) -> u64 {
2506         let mut inner_val = &mut this_ptr.get_native_mut_ref().next_outbound_htlc_limit_msat;
2507         *inner_val
2508 }
2509 /// The available outbound capacity for sending a single HTLC to the remote peer. This is
2510 /// similar to [`ChannelDetails::outbound_capacity_msat`] but it may be further restricted by
2511 /// the current state and per-HTLC limit(s). This is intended for use when routing, allowing us
2512 /// to use a limit as close as possible to the HTLC limit we can currently send.
2513 ///
2514 /// See also [`ChannelDetails::next_outbound_htlc_minimum_msat`],
2515 /// [`ChannelDetails::balance_msat`], and [`ChannelDetails::outbound_capacity_msat`].
2516 #[no_mangle]
2517 pub extern "C" fn ChannelDetails_set_next_outbound_htlc_limit_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
2518         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.next_outbound_htlc_limit_msat = val;
2519 }
2520 /// The minimum value for sending a single HTLC to the remote peer. This is the equivalent of
2521 /// [`ChannelDetails::next_outbound_htlc_limit_msat`] but represents a lower-bound, rather than
2522 /// an upper-bound. This is intended for use when routing, allowing us to ensure we pick a
2523 /// route which is valid.
2524 #[no_mangle]
2525 pub extern "C" fn ChannelDetails_get_next_outbound_htlc_minimum_msat(this_ptr: &ChannelDetails) -> u64 {
2526         let mut inner_val = &mut this_ptr.get_native_mut_ref().next_outbound_htlc_minimum_msat;
2527         *inner_val
2528 }
2529 /// The minimum value for sending a single HTLC to the remote peer. This is the equivalent of
2530 /// [`ChannelDetails::next_outbound_htlc_limit_msat`] but represents a lower-bound, rather than
2531 /// an upper-bound. This is intended for use when routing, allowing us to ensure we pick a
2532 /// route which is valid.
2533 #[no_mangle]
2534 pub extern "C" fn ChannelDetails_set_next_outbound_htlc_minimum_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
2535         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.next_outbound_htlc_minimum_msat = val;
2536 }
2537 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
2538 /// include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
2539 /// available for inclusion in new inbound HTLCs).
2540 /// Note that there are some corner cases not fully handled here, so the actual available
2541 /// inbound capacity may be slightly higher than this.
2542 ///
2543 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
2544 /// counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
2545 /// However, our counterparty should be able to spend nearly this amount.
2546 #[no_mangle]
2547 pub extern "C" fn ChannelDetails_get_inbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
2548         let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_capacity_msat;
2549         *inner_val
2550 }
2551 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
2552 /// include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
2553 /// available for inclusion in new inbound HTLCs).
2554 /// Note that there are some corner cases not fully handled here, so the actual available
2555 /// inbound capacity may be slightly higher than this.
2556 ///
2557 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
2558 /// counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
2559 /// However, our counterparty should be able to spend nearly this amount.
2560 #[no_mangle]
2561 pub extern "C" fn ChannelDetails_set_inbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
2562         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_capacity_msat = val;
2563 }
2564 /// The number of required confirmations on the funding transaction before the funding will be
2565 /// considered \"locked\". This number is selected by the channel fundee (i.e. us if
2566 /// [`is_outbound`] is *not* set), and can be selected for inbound channels with
2567 /// [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
2568 /// [`ChannelHandshakeLimits::max_minimum_depth`].
2569 ///
2570 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
2571 ///
2572 /// [`is_outbound`]: ChannelDetails::is_outbound
2573 /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
2574 /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
2575 #[no_mangle]
2576 pub extern "C" fn ChannelDetails_get_confirmations_required(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u32Z {
2577         let mut inner_val = &mut this_ptr.get_native_mut_ref().confirmations_required;
2578         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u32Z::None } else { crate::c_types::derived::COption_u32Z::Some( { inner_val.unwrap() }) };
2579         local_inner_val
2580 }
2581 /// The number of required confirmations on the funding transaction before the funding will be
2582 /// considered \"locked\". This number is selected by the channel fundee (i.e. us if
2583 /// [`is_outbound`] is *not* set), and can be selected for inbound channels with
2584 /// [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
2585 /// [`ChannelHandshakeLimits::max_minimum_depth`].
2586 ///
2587 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
2588 ///
2589 /// [`is_outbound`]: ChannelDetails::is_outbound
2590 /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
2591 /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
2592 #[no_mangle]
2593 pub extern "C" fn ChannelDetails_set_confirmations_required(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u32Z) {
2594         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2595         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.confirmations_required = local_val;
2596 }
2597 /// The current number of confirmations on the funding transaction.
2598 ///
2599 /// This value will be `None` for objects serialized with LDK versions prior to 0.0.113.
2600 #[no_mangle]
2601 pub extern "C" fn ChannelDetails_get_confirmations(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u32Z {
2602         let mut inner_val = &mut this_ptr.get_native_mut_ref().confirmations;
2603         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u32Z::None } else { crate::c_types::derived::COption_u32Z::Some( { inner_val.unwrap() }) };
2604         local_inner_val
2605 }
2606 /// The current number of confirmations on the funding transaction.
2607 ///
2608 /// This value will be `None` for objects serialized with LDK versions prior to 0.0.113.
2609 #[no_mangle]
2610 pub extern "C" fn ChannelDetails_set_confirmations(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u32Z) {
2611         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2612         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.confirmations = local_val;
2613 }
2614 /// The number of blocks (after our commitment transaction confirms) that we will need to wait
2615 /// until we can claim our funds after we force-close the channel. During this time our
2616 /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
2617 /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any
2618 /// time to claim our non-HTLC-encumbered funds.
2619 ///
2620 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
2621 #[no_mangle]
2622 pub extern "C" fn ChannelDetails_get_force_close_spend_delay(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u16Z {
2623         let mut inner_val = &mut this_ptr.get_native_mut_ref().force_close_spend_delay;
2624         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u16Z::None } else { crate::c_types::derived::COption_u16Z::Some( { inner_val.unwrap() }) };
2625         local_inner_val
2626 }
2627 /// The number of blocks (after our commitment transaction confirms) that we will need to wait
2628 /// until we can claim our funds after we force-close the channel. During this time our
2629 /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
2630 /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any
2631 /// time to claim our non-HTLC-encumbered funds.
2632 ///
2633 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
2634 #[no_mangle]
2635 pub extern "C" fn ChannelDetails_set_force_close_spend_delay(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u16Z) {
2636         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2637         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.force_close_spend_delay = local_val;
2638 }
2639 /// True if the channel was initiated (and thus funded) by us.
2640 #[no_mangle]
2641 pub extern "C" fn ChannelDetails_get_is_outbound(this_ptr: &ChannelDetails) -> bool {
2642         let mut inner_val = &mut this_ptr.get_native_mut_ref().is_outbound;
2643         *inner_val
2644 }
2645 /// True if the channel was initiated (and thus funded) by us.
2646 #[no_mangle]
2647 pub extern "C" fn ChannelDetails_set_is_outbound(this_ptr: &mut ChannelDetails, mut val: bool) {
2648         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_outbound = val;
2649 }
2650 /// True if the channel is confirmed, channel_ready messages have been exchanged, and the
2651 /// channel is not currently being shut down. `channel_ready` message exchange implies the
2652 /// required confirmation count has been reached (and we were connected to the peer at some
2653 /// point after the funding transaction received enough confirmations). The required
2654 /// confirmation count is provided in [`confirmations_required`].
2655 ///
2656 /// [`confirmations_required`]: ChannelDetails::confirmations_required
2657 #[no_mangle]
2658 pub extern "C" fn ChannelDetails_get_is_channel_ready(this_ptr: &ChannelDetails) -> bool {
2659         let mut inner_val = &mut this_ptr.get_native_mut_ref().is_channel_ready;
2660         *inner_val
2661 }
2662 /// True if the channel is confirmed, channel_ready messages have been exchanged, and the
2663 /// channel is not currently being shut down. `channel_ready` message exchange implies the
2664 /// required confirmation count has been reached (and we were connected to the peer at some
2665 /// point after the funding transaction received enough confirmations). The required
2666 /// confirmation count is provided in [`confirmations_required`].
2667 ///
2668 /// [`confirmations_required`]: ChannelDetails::confirmations_required
2669 #[no_mangle]
2670 pub extern "C" fn ChannelDetails_set_is_channel_ready(this_ptr: &mut ChannelDetails, mut val: bool) {
2671         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_channel_ready = val;
2672 }
2673 /// The stage of the channel's shutdown.
2674 /// `None` for `ChannelDetails` serialized on LDK versions prior to 0.0.116.
2675 ///
2676 /// Returns a copy of the field.
2677 #[no_mangle]
2678 pub extern "C" fn ChannelDetails_get_channel_shutdown_state(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_ChannelShutdownStateZ {
2679         let mut inner_val = this_ptr.get_native_mut_ref().channel_shutdown_state.clone();
2680         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_ChannelShutdownStateZ::None } else { crate::c_types::derived::COption_ChannelShutdownStateZ::Some( { crate::lightning::ln::channelmanager::ChannelShutdownState::native_into(inner_val.unwrap()) }) };
2681         local_inner_val
2682 }
2683 /// The stage of the channel's shutdown.
2684 /// `None` for `ChannelDetails` serialized on LDK versions prior to 0.0.116.
2685 #[no_mangle]
2686 pub extern "C" fn ChannelDetails_set_channel_shutdown_state(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_ChannelShutdownStateZ) {
2687         let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { { val_opt.take() }.into_native() }})} };
2688         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_shutdown_state = local_val;
2689 }
2690 /// True if the channel is (a) confirmed and channel_ready messages have been exchanged, (b)
2691 /// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
2692 ///
2693 /// This is a strict superset of `is_channel_ready`.
2694 #[no_mangle]
2695 pub extern "C" fn ChannelDetails_get_is_usable(this_ptr: &ChannelDetails) -> bool {
2696         let mut inner_val = &mut this_ptr.get_native_mut_ref().is_usable;
2697         *inner_val
2698 }
2699 /// True if the channel is (a) confirmed and channel_ready messages have been exchanged, (b)
2700 /// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
2701 ///
2702 /// This is a strict superset of `is_channel_ready`.
2703 #[no_mangle]
2704 pub extern "C" fn ChannelDetails_set_is_usable(this_ptr: &mut ChannelDetails, mut val: bool) {
2705         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_usable = val;
2706 }
2707 /// True if this channel is (or will be) publicly-announced.
2708 #[no_mangle]
2709 pub extern "C" fn ChannelDetails_get_is_public(this_ptr: &ChannelDetails) -> bool {
2710         let mut inner_val = &mut this_ptr.get_native_mut_ref().is_public;
2711         *inner_val
2712 }
2713 /// True if this channel is (or will be) publicly-announced.
2714 #[no_mangle]
2715 pub extern "C" fn ChannelDetails_set_is_public(this_ptr: &mut ChannelDetails, mut val: bool) {
2716         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_public = val;
2717 }
2718 /// The smallest value HTLC (in msat) we will accept, for this channel. This field
2719 /// is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.107
2720 #[no_mangle]
2721 pub extern "C" fn ChannelDetails_get_inbound_htlc_minimum_msat(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
2722         let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_htlc_minimum_msat;
2723         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) };
2724         local_inner_val
2725 }
2726 /// The smallest value HTLC (in msat) we will accept, for this channel. This field
2727 /// is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.107
2728 #[no_mangle]
2729 pub extern "C" fn ChannelDetails_set_inbound_htlc_minimum_msat(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
2730         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2731         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_htlc_minimum_msat = local_val;
2732 }
2733 /// The largest value HTLC (in msat) we currently will accept, for this channel.
2734 #[no_mangle]
2735 pub extern "C" fn ChannelDetails_get_inbound_htlc_maximum_msat(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
2736         let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_htlc_maximum_msat;
2737         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) };
2738         local_inner_val
2739 }
2740 /// The largest value HTLC (in msat) we currently will accept, for this channel.
2741 #[no_mangle]
2742 pub extern "C" fn ChannelDetails_set_inbound_htlc_maximum_msat(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
2743         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2744         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_htlc_maximum_msat = local_val;
2745 }
2746 /// Set of configurable parameters that affect channel operation.
2747 ///
2748 /// This field is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.109.
2749 ///
2750 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2751 #[no_mangle]
2752 pub extern "C" fn ChannelDetails_get_config(this_ptr: &ChannelDetails) -> crate::lightning::util::config::ChannelConfig {
2753         let mut inner_val = &mut this_ptr.get_native_mut_ref().config;
2754         let mut local_inner_val = crate::lightning::util::config::ChannelConfig { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::util::config::ChannelConfig<>) as *mut _ }, is_owned: false };
2755         local_inner_val
2756 }
2757 /// Set of configurable parameters that affect channel operation.
2758 ///
2759 /// This field is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.109.
2760 ///
2761 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
2762 #[no_mangle]
2763 pub extern "C" fn ChannelDetails_set_config(this_ptr: &mut ChannelDetails, mut val: crate::lightning::util::config::ChannelConfig) {
2764         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
2765         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.config = local_val;
2766 }
2767 impl Clone for ChannelDetails {
2768         fn clone(&self) -> Self {
2769                 Self {
2770                         inner: if <*mut nativeChannelDetails>::is_null(self.inner) { core::ptr::null_mut() } else {
2771                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2772                         is_owned: true,
2773                 }
2774         }
2775 }
2776 #[allow(unused)]
2777 /// Used only if an object of this type is returned as a trait impl by a method
2778 pub(crate) extern "C" fn ChannelDetails_clone_void(this_ptr: *const c_void) -> *mut c_void {
2779         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelDetails)).clone() })) as *mut c_void
2780 }
2781 #[no_mangle]
2782 /// Creates a copy of the ChannelDetails
2783 pub extern "C" fn ChannelDetails_clone(orig: &ChannelDetails) -> ChannelDetails {
2784         orig.clone()
2785 }
2786 /// Get a string which allows debug introspection of a ChannelDetails object
2787 pub extern "C" fn ChannelDetails_debug_str_void(o: *const c_void) -> Str {
2788         alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channelmanager::ChannelDetails }).into()}
2789 /// Gets the current SCID which should be used to identify this channel for inbound payments.
2790 /// This should be used for providing invoice hints or in any other context where our
2791 /// counterparty will forward a payment to us.
2792 ///
2793 /// This is either the [`ChannelDetails::inbound_scid_alias`], if set, or the
2794 /// [`ChannelDetails::short_channel_id`]. See those for more information.
2795 #[must_use]
2796 #[no_mangle]
2797 pub extern "C" fn ChannelDetails_get_inbound_payment_scid(this_arg: &crate::lightning::ln::channelmanager::ChannelDetails) -> crate::c_types::derived::COption_u64Z {
2798         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_inbound_payment_scid();
2799         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { ret.unwrap() }) };
2800         local_ret
2801 }
2802
2803 /// Gets the current SCID which should be used to identify this channel for outbound payments.
2804 /// This should be used in [`Route`]s to describe the first hop or in other contexts where
2805 /// we're sending or forwarding a payment outbound over this channel.
2806 ///
2807 /// This is either the [`ChannelDetails::short_channel_id`], if set, or the
2808 /// [`ChannelDetails::outbound_scid_alias`]. See those for more information.
2809 #[must_use]
2810 #[no_mangle]
2811 pub extern "C" fn ChannelDetails_get_outbound_payment_scid(this_arg: &crate::lightning::ln::channelmanager::ChannelDetails) -> crate::c_types::derived::COption_u64Z {
2812         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_outbound_payment_scid();
2813         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { ret.unwrap() }) };
2814         local_ret
2815 }
2816
2817 /// Further information on the details of the channel shutdown.
2818 /// Upon channels being forced closed (i.e. commitment transaction confirmation detected
2819 /// by `ChainMonitor`), ChannelShutdownState will be set to `ShutdownComplete` or
2820 /// the channel will be removed shortly.
2821 /// Also note, that in normal operation, peers could disconnect at any of these states
2822 /// and require peer re-connection before making progress onto other states
2823 #[derive(Clone)]
2824 #[must_use]
2825 #[repr(C)]
2826 pub enum ChannelShutdownState {
2827         /// Channel has not sent or received a shutdown message.
2828         NotShuttingDown,
2829         /// Local node has sent a shutdown message for this channel.
2830         ShutdownInitiated,
2831         /// Shutdown message exchanges have concluded and the channels are in the midst of
2832         /// resolving all existing open HTLCs before closing can continue.
2833         ResolvingHTLCs,
2834         /// All HTLCs have been resolved, nodes are currently negotiating channel close onchain fee rates.
2835         NegotiatingClosingFee,
2836         /// We've successfully negotiated a closing_signed dance. At this point `ChannelManager` is about
2837         /// to drop the channel.
2838         ShutdownComplete,
2839 }
2840 use lightning::ln::channelmanager::ChannelShutdownState as ChannelShutdownStateImport;
2841 pub(crate) type nativeChannelShutdownState = ChannelShutdownStateImport;
2842
2843 impl ChannelShutdownState {
2844         #[allow(unused)]
2845         pub(crate) fn to_native(&self) -> nativeChannelShutdownState {
2846                 match self {
2847                         ChannelShutdownState::NotShuttingDown => nativeChannelShutdownState::NotShuttingDown,
2848                         ChannelShutdownState::ShutdownInitiated => nativeChannelShutdownState::ShutdownInitiated,
2849                         ChannelShutdownState::ResolvingHTLCs => nativeChannelShutdownState::ResolvingHTLCs,
2850                         ChannelShutdownState::NegotiatingClosingFee => nativeChannelShutdownState::NegotiatingClosingFee,
2851                         ChannelShutdownState::ShutdownComplete => nativeChannelShutdownState::ShutdownComplete,
2852                 }
2853         }
2854         #[allow(unused)]
2855         pub(crate) fn into_native(self) -> nativeChannelShutdownState {
2856                 match self {
2857                         ChannelShutdownState::NotShuttingDown => nativeChannelShutdownState::NotShuttingDown,
2858                         ChannelShutdownState::ShutdownInitiated => nativeChannelShutdownState::ShutdownInitiated,
2859                         ChannelShutdownState::ResolvingHTLCs => nativeChannelShutdownState::ResolvingHTLCs,
2860                         ChannelShutdownState::NegotiatingClosingFee => nativeChannelShutdownState::NegotiatingClosingFee,
2861                         ChannelShutdownState::ShutdownComplete => nativeChannelShutdownState::ShutdownComplete,
2862                 }
2863         }
2864         #[allow(unused)]
2865         pub(crate) fn from_native(native: &ChannelShutdownStateImport) -> Self {
2866                 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeChannelShutdownState) };
2867                 match native {
2868                         nativeChannelShutdownState::NotShuttingDown => ChannelShutdownState::NotShuttingDown,
2869                         nativeChannelShutdownState::ShutdownInitiated => ChannelShutdownState::ShutdownInitiated,
2870                         nativeChannelShutdownState::ResolvingHTLCs => ChannelShutdownState::ResolvingHTLCs,
2871                         nativeChannelShutdownState::NegotiatingClosingFee => ChannelShutdownState::NegotiatingClosingFee,
2872                         nativeChannelShutdownState::ShutdownComplete => ChannelShutdownState::ShutdownComplete,
2873                 }
2874         }
2875         #[allow(unused)]
2876         pub(crate) fn native_into(native: nativeChannelShutdownState) -> Self {
2877                 match native {
2878                         nativeChannelShutdownState::NotShuttingDown => ChannelShutdownState::NotShuttingDown,
2879                         nativeChannelShutdownState::ShutdownInitiated => ChannelShutdownState::ShutdownInitiated,
2880                         nativeChannelShutdownState::ResolvingHTLCs => ChannelShutdownState::ResolvingHTLCs,
2881                         nativeChannelShutdownState::NegotiatingClosingFee => ChannelShutdownState::NegotiatingClosingFee,
2882                         nativeChannelShutdownState::ShutdownComplete => ChannelShutdownState::ShutdownComplete,
2883                 }
2884         }
2885 }
2886 /// Creates a copy of the ChannelShutdownState
2887 #[no_mangle]
2888 pub extern "C" fn ChannelShutdownState_clone(orig: &ChannelShutdownState) -> ChannelShutdownState {
2889         orig.clone()
2890 }
2891 #[allow(unused)]
2892 /// Used only if an object of this type is returned as a trait impl by a method
2893 pub(crate) extern "C" fn ChannelShutdownState_clone_void(this_ptr: *const c_void) -> *mut c_void {
2894         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const ChannelShutdownState)).clone() })) as *mut c_void
2895 }
2896 #[allow(unused)]
2897 /// Used only if an object of this type is returned as a trait impl by a method
2898 pub(crate) extern "C" fn ChannelShutdownState_free_void(this_ptr: *mut c_void) {
2899         let _ = unsafe { Box::from_raw(this_ptr as *mut ChannelShutdownState) };
2900 }
2901 #[no_mangle]
2902 /// Utility method to constructs a new NotShuttingDown-variant ChannelShutdownState
2903 pub extern "C" fn ChannelShutdownState_not_shutting_down() -> ChannelShutdownState {
2904         ChannelShutdownState::NotShuttingDown}
2905 #[no_mangle]
2906 /// Utility method to constructs a new ShutdownInitiated-variant ChannelShutdownState
2907 pub extern "C" fn ChannelShutdownState_shutdown_initiated() -> ChannelShutdownState {
2908         ChannelShutdownState::ShutdownInitiated}
2909 #[no_mangle]
2910 /// Utility method to constructs a new ResolvingHTLCs-variant ChannelShutdownState
2911 pub extern "C" fn ChannelShutdownState_resolving_htlcs() -> ChannelShutdownState {
2912         ChannelShutdownState::ResolvingHTLCs}
2913 #[no_mangle]
2914 /// Utility method to constructs a new NegotiatingClosingFee-variant ChannelShutdownState
2915 pub extern "C" fn ChannelShutdownState_negotiating_closing_fee() -> ChannelShutdownState {
2916         ChannelShutdownState::NegotiatingClosingFee}
2917 #[no_mangle]
2918 /// Utility method to constructs a new ShutdownComplete-variant ChannelShutdownState
2919 pub extern "C" fn ChannelShutdownState_shutdown_complete() -> ChannelShutdownState {
2920         ChannelShutdownState::ShutdownComplete}
2921 /// Get a string which allows debug introspection of a ChannelShutdownState object
2922 pub extern "C" fn ChannelShutdownState_debug_str_void(o: *const c_void) -> Str {
2923         alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channelmanager::ChannelShutdownState }).into()}
2924 /// Checks if two ChannelShutdownStates contain equal inner contents.
2925 /// This ignores pointers and is_owned flags and looks at the values in fields.
2926 #[no_mangle]
2927 pub extern "C" fn ChannelShutdownState_eq(a: &ChannelShutdownState, b: &ChannelShutdownState) -> bool {
2928         if &a.to_native() == &b.to_native() { true } else { false }
2929 }
2930 /// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
2931 /// These include payments that have yet to find a successful path, or have unresolved HTLCs.
2932 #[derive(Clone)]
2933 #[must_use]
2934 #[repr(C)]
2935 pub enum RecentPaymentDetails {
2936         /// When an invoice was requested and thus a payment has not yet been sent.
2937         AwaitingInvoice {
2938                 /// A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify
2939                 /// a payment and ensure idempotency in LDK.
2940                 payment_id: crate::c_types::ThirtyTwoBytes,
2941         },
2942         /// When a payment is still being sent and awaiting successful delivery.
2943         Pending {
2944                 /// A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify
2945                 /// a payment and ensure idempotency in LDK.
2946                 payment_id: crate::c_types::ThirtyTwoBytes,
2947                 /// Hash of the payment that is currently being sent but has yet to be fulfilled or
2948                 /// abandoned.
2949                 payment_hash: crate::c_types::ThirtyTwoBytes,
2950                 /// Total amount (in msat, excluding fees) across all paths for this payment,
2951                 /// not just the amount currently inflight.
2952                 total_msat: u64,
2953         },
2954         /// When a pending payment is fulfilled, we continue tracking it until all pending HTLCs have
2955         /// been resolved. Upon receiving [`Event::PaymentSent`], we delay for a few minutes before the
2956         /// payment is removed from tracking.
2957         Fulfilled {
2958                 /// A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify
2959                 /// a payment and ensure idempotency in LDK.
2960                 payment_id: crate::c_types::ThirtyTwoBytes,
2961                 /// Hash of the payment that was claimed. `None` for serializations of [`ChannelManager`]
2962                 /// made before LDK version 0.0.104.
2963                 payment_hash: crate::c_types::derived::COption_ThirtyTwoBytesZ,
2964         },
2965         /// After a payment's retries are exhausted per the provided [`Retry`], or it is explicitly
2966         /// abandoned via [`ChannelManager::abandon_payment`], it is marked as abandoned until all
2967         /// pending HTLCs for this payment resolve and an [`Event::PaymentFailed`] is generated.
2968         Abandoned {
2969                 /// A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify
2970                 /// a payment and ensure idempotency in LDK.
2971                 payment_id: crate::c_types::ThirtyTwoBytes,
2972                 /// Hash of the payment that we have given up trying to send.
2973                 payment_hash: crate::c_types::ThirtyTwoBytes,
2974         },
2975 }
2976 use lightning::ln::channelmanager::RecentPaymentDetails as RecentPaymentDetailsImport;
2977 pub(crate) type nativeRecentPaymentDetails = RecentPaymentDetailsImport;
2978
2979 impl RecentPaymentDetails {
2980         #[allow(unused)]
2981         pub(crate) fn to_native(&self) -> nativeRecentPaymentDetails {
2982                 match self {
2983                         RecentPaymentDetails::AwaitingInvoice {ref payment_id, } => {
2984                                 let mut payment_id_nonref = Clone::clone(payment_id);
2985                                 nativeRecentPaymentDetails::AwaitingInvoice {
2986                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
2987                                 }
2988                         },
2989                         RecentPaymentDetails::Pending {ref payment_id, ref payment_hash, ref total_msat, } => {
2990                                 let mut payment_id_nonref = Clone::clone(payment_id);
2991                                 let mut payment_hash_nonref = Clone::clone(payment_hash);
2992                                 let mut total_msat_nonref = Clone::clone(total_msat);
2993                                 nativeRecentPaymentDetails::Pending {
2994                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
2995                                         payment_hash: ::lightning::ln::types::PaymentHash(payment_hash_nonref.data),
2996                                         total_msat: total_msat_nonref,
2997                                 }
2998                         },
2999                         RecentPaymentDetails::Fulfilled {ref payment_id, ref payment_hash, } => {
3000                                 let mut payment_id_nonref = Clone::clone(payment_id);
3001                                 let mut payment_hash_nonref = Clone::clone(payment_hash);
3002                                 let mut local_payment_hash_nonref = { /*payment_hash_nonref*/ let payment_hash_nonref_opt = payment_hash_nonref; if payment_hash_nonref_opt.is_none() { None } else { Some({ { ::lightning::ln::types::PaymentHash({ payment_hash_nonref_opt.take() }.data) }})} };
3003                                 nativeRecentPaymentDetails::Fulfilled {
3004                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
3005                                         payment_hash: local_payment_hash_nonref,
3006                                 }
3007                         },
3008                         RecentPaymentDetails::Abandoned {ref payment_id, ref payment_hash, } => {
3009                                 let mut payment_id_nonref = Clone::clone(payment_id);
3010                                 let mut payment_hash_nonref = Clone::clone(payment_hash);
3011                                 nativeRecentPaymentDetails::Abandoned {
3012                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
3013                                         payment_hash: ::lightning::ln::types::PaymentHash(payment_hash_nonref.data),
3014                                 }
3015                         },
3016                 }
3017         }
3018         #[allow(unused)]
3019         pub(crate) fn into_native(self) -> nativeRecentPaymentDetails {
3020                 match self {
3021                         RecentPaymentDetails::AwaitingInvoice {mut payment_id, } => {
3022                                 nativeRecentPaymentDetails::AwaitingInvoice {
3023                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
3024                                 }
3025                         },
3026                         RecentPaymentDetails::Pending {mut payment_id, mut payment_hash, mut total_msat, } => {
3027                                 nativeRecentPaymentDetails::Pending {
3028                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
3029                                         payment_hash: ::lightning::ln::types::PaymentHash(payment_hash.data),
3030                                         total_msat: total_msat,
3031                                 }
3032                         },
3033                         RecentPaymentDetails::Fulfilled {mut payment_id, mut payment_hash, } => {
3034                                 let mut local_payment_hash = { /*payment_hash*/ let payment_hash_opt = payment_hash; if payment_hash_opt.is_none() { None } else { Some({ { ::lightning::ln::types::PaymentHash({ payment_hash_opt.take() }.data) }})} };
3035                                 nativeRecentPaymentDetails::Fulfilled {
3036                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
3037                                         payment_hash: local_payment_hash,
3038                                 }
3039                         },
3040                         RecentPaymentDetails::Abandoned {mut payment_id, mut payment_hash, } => {
3041                                 nativeRecentPaymentDetails::Abandoned {
3042                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
3043                                         payment_hash: ::lightning::ln::types::PaymentHash(payment_hash.data),
3044                                 }
3045                         },
3046                 }
3047         }
3048         #[allow(unused)]
3049         pub(crate) fn from_native(native: &RecentPaymentDetailsImport) -> Self {
3050                 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeRecentPaymentDetails) };
3051                 match native {
3052                         nativeRecentPaymentDetails::AwaitingInvoice {ref payment_id, } => {
3053                                 let mut payment_id_nonref = Clone::clone(payment_id);
3054                                 RecentPaymentDetails::AwaitingInvoice {
3055                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
3056                                 }
3057                         },
3058                         nativeRecentPaymentDetails::Pending {ref payment_id, ref payment_hash, ref total_msat, } => {
3059                                 let mut payment_id_nonref = Clone::clone(payment_id);
3060                                 let mut payment_hash_nonref = Clone::clone(payment_hash);
3061                                 let mut total_msat_nonref = Clone::clone(total_msat);
3062                                 RecentPaymentDetails::Pending {
3063                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
3064                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
3065                                         total_msat: total_msat_nonref,
3066                                 }
3067                         },
3068                         nativeRecentPaymentDetails::Fulfilled {ref payment_id, ref payment_hash, } => {
3069                                 let mut payment_id_nonref = Clone::clone(payment_id);
3070                                 let mut payment_hash_nonref = Clone::clone(payment_hash);
3071                                 let mut local_payment_hash_nonref = if payment_hash_nonref.is_none() { crate::c_types::derived::COption_ThirtyTwoBytesZ::None } else { crate::c_types::derived::COption_ThirtyTwoBytesZ::Some( { crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.unwrap().0 } }) };
3072                                 RecentPaymentDetails::Fulfilled {
3073                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
3074                                         payment_hash: local_payment_hash_nonref,
3075                                 }
3076                         },
3077                         nativeRecentPaymentDetails::Abandoned {ref payment_id, ref payment_hash, } => {
3078                                 let mut payment_id_nonref = Clone::clone(payment_id);
3079                                 let mut payment_hash_nonref = Clone::clone(payment_hash);
3080                                 RecentPaymentDetails::Abandoned {
3081                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
3082                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
3083                                 }
3084                         },
3085                 }
3086         }
3087         #[allow(unused)]
3088         pub(crate) fn native_into(native: nativeRecentPaymentDetails) -> Self {
3089                 match native {
3090                         nativeRecentPaymentDetails::AwaitingInvoice {mut payment_id, } => {
3091                                 RecentPaymentDetails::AwaitingInvoice {
3092                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
3093                                 }
3094                         },
3095                         nativeRecentPaymentDetails::Pending {mut payment_id, mut payment_hash, mut total_msat, } => {
3096                                 RecentPaymentDetails::Pending {
3097                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
3098                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
3099                                         total_msat: total_msat,
3100                                 }
3101                         },
3102                         nativeRecentPaymentDetails::Fulfilled {mut payment_id, mut payment_hash, } => {
3103                                 let mut local_payment_hash = if payment_hash.is_none() { crate::c_types::derived::COption_ThirtyTwoBytesZ::None } else { crate::c_types::derived::COption_ThirtyTwoBytesZ::Some( { crate::c_types::ThirtyTwoBytes { data: payment_hash.unwrap().0 } }) };
3104                                 RecentPaymentDetails::Fulfilled {
3105                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
3106                                         payment_hash: local_payment_hash,
3107                                 }
3108                         },
3109                         nativeRecentPaymentDetails::Abandoned {mut payment_id, mut payment_hash, } => {
3110                                 RecentPaymentDetails::Abandoned {
3111                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
3112                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
3113                                 }
3114                         },
3115                 }
3116         }
3117 }
3118 /// Frees any resources used by the RecentPaymentDetails
3119 #[no_mangle]
3120 pub extern "C" fn RecentPaymentDetails_free(this_ptr: RecentPaymentDetails) { }
3121 /// Creates a copy of the RecentPaymentDetails
3122 #[no_mangle]
3123 pub extern "C" fn RecentPaymentDetails_clone(orig: &RecentPaymentDetails) -> RecentPaymentDetails {
3124         orig.clone()
3125 }
3126 #[allow(unused)]
3127 /// Used only if an object of this type is returned as a trait impl by a method
3128 pub(crate) extern "C" fn RecentPaymentDetails_clone_void(this_ptr: *const c_void) -> *mut c_void {
3129         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const RecentPaymentDetails)).clone() })) as *mut c_void
3130 }
3131 #[allow(unused)]
3132 /// Used only if an object of this type is returned as a trait impl by a method
3133 pub(crate) extern "C" fn RecentPaymentDetails_free_void(this_ptr: *mut c_void) {
3134         let _ = unsafe { Box::from_raw(this_ptr as *mut RecentPaymentDetails) };
3135 }
3136 #[no_mangle]
3137 /// Utility method to constructs a new AwaitingInvoice-variant RecentPaymentDetails
3138 pub extern "C" fn RecentPaymentDetails_awaiting_invoice(payment_id: crate::c_types::ThirtyTwoBytes) -> RecentPaymentDetails {
3139         RecentPaymentDetails::AwaitingInvoice {
3140                 payment_id,
3141         }
3142 }
3143 #[no_mangle]
3144 /// Utility method to constructs a new Pending-variant RecentPaymentDetails
3145 pub extern "C" fn RecentPaymentDetails_pending(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, total_msat: u64) -> RecentPaymentDetails {
3146         RecentPaymentDetails::Pending {
3147                 payment_id,
3148                 payment_hash,
3149                 total_msat,
3150         }
3151 }
3152 #[no_mangle]
3153 /// Utility method to constructs a new Fulfilled-variant RecentPaymentDetails
3154 pub extern "C" fn RecentPaymentDetails_fulfilled(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::derived::COption_ThirtyTwoBytesZ) -> RecentPaymentDetails {
3155         RecentPaymentDetails::Fulfilled {
3156                 payment_id,
3157                 payment_hash,
3158         }
3159 }
3160 #[no_mangle]
3161 /// Utility method to constructs a new Abandoned-variant RecentPaymentDetails
3162 pub extern "C" fn RecentPaymentDetails_abandoned(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes) -> RecentPaymentDetails {
3163         RecentPaymentDetails::Abandoned {
3164                 payment_id,
3165                 payment_hash,
3166         }
3167 }
3168 /// Get a string which allows debug introspection of a RecentPaymentDetails object
3169 pub extern "C" fn RecentPaymentDetails_debug_str_void(o: *const c_void) -> Str {
3170         alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channelmanager::RecentPaymentDetails }).into()}
3171
3172 use lightning::ln::channelmanager::PhantomRouteHints as nativePhantomRouteHintsImport;
3173 pub(crate) type nativePhantomRouteHints = nativePhantomRouteHintsImport;
3174
3175 /// Route hints used in constructing invoices for [phantom node payents].
3176 ///
3177 /// [phantom node payments]: crate::sign::PhantomKeysManager
3178 #[must_use]
3179 #[repr(C)]
3180 pub struct PhantomRouteHints {
3181         /// A pointer to the opaque Rust object.
3182
3183         /// Nearly everywhere, inner must be non-null, however in places where
3184         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
3185         pub inner: *mut nativePhantomRouteHints,
3186         /// Indicates that this is the only struct which contains the same pointer.
3187
3188         /// Rust functions which take ownership of an object provided via an argument require
3189         /// this to be true and invalidate the object pointed to by inner.
3190         pub is_owned: bool,
3191 }
3192
3193 impl Drop for PhantomRouteHints {
3194         fn drop(&mut self) {
3195                 if self.is_owned && !<*mut nativePhantomRouteHints>::is_null(self.inner) {
3196                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
3197                 }
3198         }
3199 }
3200 /// Frees any resources used by the PhantomRouteHints, if is_owned is set and inner is non-NULL.
3201 #[no_mangle]
3202 pub extern "C" fn PhantomRouteHints_free(this_obj: PhantomRouteHints) { }
3203 #[allow(unused)]
3204 /// Used only if an object of this type is returned as a trait impl by a method
3205 pub(crate) extern "C" fn PhantomRouteHints_free_void(this_ptr: *mut c_void) {
3206         let _ = unsafe { Box::from_raw(this_ptr as *mut nativePhantomRouteHints) };
3207 }
3208 #[allow(unused)]
3209 impl PhantomRouteHints {
3210         pub(crate) fn get_native_ref(&self) -> &'static nativePhantomRouteHints {
3211                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
3212         }
3213         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePhantomRouteHints {
3214                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
3215         }
3216         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
3217         pub(crate) fn take_inner(mut self) -> *mut nativePhantomRouteHints {
3218                 assert!(self.is_owned);
3219                 let ret = ObjOps::untweak_ptr(self.inner);
3220                 self.inner = core::ptr::null_mut();
3221                 ret
3222         }
3223 }
3224 /// The list of channels to be included in the invoice route hints.
3225 #[no_mangle]
3226 pub extern "C" fn PhantomRouteHints_get_channels(this_ptr: &PhantomRouteHints) -> crate::c_types::derived::CVec_ChannelDetailsZ {
3227         let mut inner_val = &mut this_ptr.get_native_mut_ref().channels;
3228         let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::ln::channelmanager::ChannelDetails<>) as *mut _) }, is_owned: false } }); };
3229         local_inner_val.into()
3230 }
3231 /// The list of channels to be included in the invoice route hints.
3232 #[no_mangle]
3233 pub extern "C" fn PhantomRouteHints_set_channels(this_ptr: &mut PhantomRouteHints, mut val: crate::c_types::derived::CVec_ChannelDetailsZ) {
3234         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
3235         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val;
3236 }
3237 /// A fake scid used for representing the phantom node's fake channel in generating the invoice
3238 /// route hints.
3239 #[no_mangle]
3240 pub extern "C" fn PhantomRouteHints_get_phantom_scid(this_ptr: &PhantomRouteHints) -> u64 {
3241         let mut inner_val = &mut this_ptr.get_native_mut_ref().phantom_scid;
3242         *inner_val
3243 }
3244 /// A fake scid used for representing the phantom node's fake channel in generating the invoice
3245 /// route hints.
3246 #[no_mangle]
3247 pub extern "C" fn PhantomRouteHints_set_phantom_scid(this_ptr: &mut PhantomRouteHints, mut val: u64) {
3248         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.phantom_scid = val;
3249 }
3250 /// The pubkey of the real backing node that would ultimately receive the payment.
3251 #[no_mangle]
3252 pub extern "C" fn PhantomRouteHints_get_real_node_pubkey(this_ptr: &PhantomRouteHints) -> crate::c_types::PublicKey {
3253         let mut inner_val = &mut this_ptr.get_native_mut_ref().real_node_pubkey;
3254         crate::c_types::PublicKey::from_rust(&inner_val)
3255 }
3256 /// The pubkey of the real backing node that would ultimately receive the payment.
3257 #[no_mangle]
3258 pub extern "C" fn PhantomRouteHints_set_real_node_pubkey(this_ptr: &mut PhantomRouteHints, mut val: crate::c_types::PublicKey) {
3259         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.real_node_pubkey = val.into_rust();
3260 }
3261 /// Constructs a new PhantomRouteHints given each field
3262 #[must_use]
3263 #[no_mangle]
3264 pub extern "C" fn PhantomRouteHints_new(mut channels_arg: crate::c_types::derived::CVec_ChannelDetailsZ, mut phantom_scid_arg: u64, mut real_node_pubkey_arg: crate::c_types::PublicKey) -> PhantomRouteHints {
3265         let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
3266         PhantomRouteHints { inner: ObjOps::heap_alloc(nativePhantomRouteHints {
3267                 channels: local_channels_arg,
3268                 phantom_scid: phantom_scid_arg,
3269                 real_node_pubkey: real_node_pubkey_arg.into_rust(),
3270         }), is_owned: true }
3271 }
3272 impl Clone for PhantomRouteHints {
3273         fn clone(&self) -> Self {
3274                 Self {
3275                         inner: if <*mut nativePhantomRouteHints>::is_null(self.inner) { core::ptr::null_mut() } else {
3276                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
3277                         is_owned: true,
3278                 }
3279         }
3280 }
3281 #[allow(unused)]
3282 /// Used only if an object of this type is returned as a trait impl by a method
3283 pub(crate) extern "C" fn PhantomRouteHints_clone_void(this_ptr: *const c_void) -> *mut c_void {
3284         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePhantomRouteHints)).clone() })) as *mut c_void
3285 }
3286 #[no_mangle]
3287 /// Creates a copy of the PhantomRouteHints
3288 pub extern "C" fn PhantomRouteHints_clone(orig: &PhantomRouteHints) -> PhantomRouteHints {
3289         orig.clone()
3290 }
3291 /// Constructs a new `ChannelManager` to hold several channels and route between them.
3292 ///
3293 /// The current time or latest block header time can be provided as the `current_timestamp`.
3294 ///
3295 /// This is the main \"logic hub\" for all channel-related actions, and implements
3296 /// [`ChannelMessageHandler`].
3297 ///
3298 /// Non-proportional fees are fixed according to our risk using the provided fee estimator.
3299 ///
3300 /// Users need to notify the new `ChannelManager` when a new block is connected or
3301 /// disconnected using its [`block_connected`] and [`block_disconnected`] methods, starting
3302 /// from after [`params.best_block.block_hash`]. See [`chain::Listen`] and [`chain::Confirm`] for
3303 /// more details.
3304 ///
3305 /// [`block_connected`]: chain::Listen::block_connected
3306 /// [`block_disconnected`]: chain::Listen::block_disconnected
3307 /// [`params.best_block.block_hash`]: chain::BestBlock::block_hash
3308 #[must_use]
3309 #[no_mangle]
3310 pub extern "C" fn ChannelManager_new(mut fee_est: crate::lightning::chain::chaininterface::FeeEstimator, mut chain_monitor: crate::lightning::chain::Watch, mut tx_broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut router: crate::lightning::routing::router::Router, mut logger: crate::lightning::util::logger::Logger, mut entropy_source: crate::lightning::sign::EntropySource, mut node_signer: crate::lightning::sign::NodeSigner, mut signer_provider: crate::lightning::sign::SignerProvider, mut config: crate::lightning::util::config::UserConfig, mut params: crate::lightning::ln::channelmanager::ChainParameters, mut current_timestamp: u32) -> crate::lightning::ln::channelmanager::ChannelManager {
3311         let mut ret = lightning::ln::channelmanager::ChannelManager::new(fee_est, chain_monitor, tx_broadcaster, router, logger, entropy_source, node_signer, signer_provider, *unsafe { Box::from_raw(config.take_inner()) }, *unsafe { Box::from_raw(params.take_inner()) }, current_timestamp);
3312         crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
3313 }
3314
3315 /// Gets the current configuration applied to all new channels.
3316 #[must_use]
3317 #[no_mangle]
3318 pub extern "C" fn ChannelManager_get_current_default_configuration(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::util::config::UserConfig {
3319         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_current_default_configuration();
3320         crate::lightning::util::config::UserConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::util::config::UserConfig<>) as *mut _) }, is_owned: false }
3321 }
3322
3323 /// Creates a new outbound channel to the given remote node and with the given value.
3324 ///
3325 /// `user_channel_id` will be provided back as in
3326 /// [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
3327 /// correspond with which `create_channel` call. Note that the `user_channel_id` defaults to a
3328 /// randomized value for inbound channels. `user_channel_id` has no meaning inside of LDK, it
3329 /// is simply copied to events and otherwise ignored.
3330 ///
3331 /// Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is
3332 /// greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`.
3333 ///
3334 /// Raises [`APIError::ChannelUnavailable`] if the channel cannot be opened due to failing to
3335 /// generate a shutdown scriptpubkey or destination script set by
3336 /// [`SignerProvider::get_shutdown_scriptpubkey`] or [`SignerProvider::get_destination_script`].
3337 ///
3338 /// Note that we do not check if you are currently connected to the given peer. If no
3339 /// connection is available, the outbound `open_channel` message may fail to send, resulting in
3340 /// the channel eventually being silently forgotten (dropped on reload).
3341 ///
3342 /// If `temporary_channel_id` is specified, it will be used as the temporary channel ID of the
3343 /// channel. Otherwise, a random one will be generated for you.
3344 ///
3345 /// Returns the new Channel's temporary `channel_id`. This ID will appear as
3346 /// [`Event::FundingGenerationReady::temporary_channel_id`] and in
3347 /// [`ChannelDetails::channel_id`] until after
3348 /// [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
3349 /// one derived from the funding transaction's TXID. If the counterparty rejects the channel
3350 /// immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
3351 ///
3352 /// [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
3353 /// [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
3354 /// [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
3355 ///
3356 /// Note that temporary_channel_id (or a relevant inner pointer) may be NULL or all-0s to represent None
3357 /// Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
3358 #[must_use]
3359 #[no_mangle]
3360 pub extern "C" fn ChannelManager_create_channel(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut their_network_key: crate::c_types::PublicKey, mut channel_value_satoshis: u64, mut push_msat: u64, mut user_channel_id: crate::c_types::U128, mut temporary_channel_id: crate::lightning::ln::types::ChannelId, mut override_config: crate::lightning::util::config::UserConfig) -> crate::c_types::derived::CResult_ChannelIdAPIErrorZ {
3361         let mut local_temporary_channel_id = if temporary_channel_id.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(temporary_channel_id.take_inner()) } }) };
3362         let mut local_override_config = if override_config.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(override_config.take_inner()) } }) };
3363         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_channel(their_network_key.into_rust(), channel_value_satoshis, push_msat, user_channel_id.into(), local_temporary_channel_id, local_override_config);
3364         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::types::ChannelId { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
3365         local_ret
3366 }
3367
3368 /// Gets the list of open channels, in random order. See [`ChannelDetails`] field documentation for
3369 /// more information.
3370 #[must_use]
3371 #[no_mangle]
3372 pub extern "C" fn ChannelManager_list_channels(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
3373         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_channels();
3374         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
3375         local_ret.into()
3376 }
3377
3378 /// Gets the list of usable channels, in random order. Useful as an argument to
3379 /// [`Router::find_route`] to ensure non-announced channels are used.
3380 ///
3381 /// These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
3382 /// documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
3383 /// are.
3384 #[must_use]
3385 #[no_mangle]
3386 pub extern "C" fn ChannelManager_list_usable_channels(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
3387         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_usable_channels();
3388         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
3389         local_ret.into()
3390 }
3391
3392 /// Gets the list of channels we have with a given counterparty, in random order.
3393 #[must_use]
3394 #[no_mangle]
3395 pub extern "C" fn ChannelManager_list_channels_with_counterparty(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut counterparty_node_id: crate::c_types::PublicKey) -> crate::c_types::derived::CVec_ChannelDetailsZ {
3396         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_channels_with_counterparty(&counterparty_node_id.into_rust());
3397         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
3398         local_ret.into()
3399 }
3400
3401 /// Returns in an undefined order recent payments that -- if not fulfilled -- have yet to find a
3402 /// successful path, or have unresolved HTLCs.
3403 ///
3404 /// This can be useful for payments that may have been prepared, but ultimately not sent, as a
3405 /// result of a crash. If such a payment exists, is not listed here, and an
3406 /// [`Event::PaymentSent`] has not been received, you may consider resending the payment.
3407 ///
3408 /// [`Event::PaymentSent`]: events::Event::PaymentSent
3409 #[must_use]
3410 #[no_mangle]
3411 pub extern "C" fn ChannelManager_list_recent_payments(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_RecentPaymentDetailsZ {
3412         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_recent_payments();
3413         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::channelmanager::RecentPaymentDetails::native_into(item) }); };
3414         local_ret.into()
3415 }
3416
3417 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
3418 /// will be accepted on the given channel, and after additional timeout/the closing of all
3419 /// pending HTLCs, the channel will be closed on chain.
3420 ///
3421 ///  * If we are the channel initiator, we will pay between our [`ChannelCloseMinimum`] and
3422 ///    [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`NonAnchorChannelFee`]
3423 ///    fee estimate.
3424 ///  * If our counterparty is the channel initiator, we will require a channel closing
3425 ///    transaction feerate of at least our [`ChannelCloseMinimum`] feerate or the feerate which
3426 ///    would appear on a force-closure transaction, whichever is lower. We will allow our
3427 ///    counterparty to pay as much fee as they'd like, however.
3428 ///
3429 /// May generate a [`SendShutdown`] message event on success, which should be relayed.
3430 ///
3431 /// Raises [`APIError::ChannelUnavailable`] if the channel cannot be closed due to failing to
3432 /// generate a shutdown scriptpubkey or destination script set by
3433 /// [`SignerProvider::get_shutdown_scriptpubkey`]. A force-closure may be needed to close the
3434 /// channel.
3435 ///
3436 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
3437 /// [`ChannelCloseMinimum`]: crate::chain::chaininterface::ConfirmationTarget::ChannelCloseMinimum
3438 /// [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee
3439 /// [`SendShutdown`]: crate::events::MessageSendEvent::SendShutdown
3440 #[must_use]
3441 #[no_mangle]
3442 pub extern "C" fn ChannelManager_close_channel(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, channel_id: &crate::lightning::ln::types::ChannelId, mut counterparty_node_id: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
3443         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel(channel_id.get_native_ref(), &counterparty_node_id.into_rust());
3444         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
3445         local_ret
3446 }
3447
3448 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
3449 /// will be accepted on the given channel, and after additional timeout/the closing of all
3450 /// pending HTLCs, the channel will be closed on chain.
3451 ///
3452 /// `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
3453 /// the channel being closed or not:
3454 ///  * If we are the channel initiator, we will pay at least this feerate on the closing
3455 ///    transaction. The upper-bound is set by
3456 ///    [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`NonAnchorChannelFee`]
3457 ///    fee estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
3458 ///  * If our counterparty is the channel initiator, we will refuse to accept a channel closure
3459 ///    transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
3460 ///    will appear on a force-closure transaction, whichever is lower).
3461 ///
3462 /// The `shutdown_script` provided  will be used as the `scriptPubKey` for the closing transaction.
3463 /// Will fail if a shutdown script has already been set for this channel by
3464 /// ['ChannelHandshakeConfig::commit_upfront_shutdown_pubkey`]. The given shutdown script must
3465 /// also be compatible with our and the counterparty's features.
3466 ///
3467 /// May generate a [`SendShutdown`] message event on success, which should be relayed.
3468 ///
3469 /// Raises [`APIError::ChannelUnavailable`] if the channel cannot be closed due to failing to
3470 /// generate a shutdown scriptpubkey or destination script set by
3471 /// [`SignerProvider::get_shutdown_scriptpubkey`]. A force-closure may be needed to close the
3472 /// channel.
3473 ///
3474 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
3475 /// [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee
3476 /// [`SendShutdown`]: crate::events::MessageSendEvent::SendShutdown
3477 ///
3478 /// Note that shutdown_script (or a relevant inner pointer) may be NULL or all-0s to represent None
3479 #[must_use]
3480 #[no_mangle]
3481 pub extern "C" fn ChannelManager_close_channel_with_feerate_and_script(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, channel_id: &crate::lightning::ln::types::ChannelId, mut counterparty_node_id: crate::c_types::PublicKey, mut target_feerate_sats_per_1000_weight: crate::c_types::derived::COption_u32Z, mut shutdown_script: crate::lightning::ln::script::ShutdownScript) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
3482         let mut local_target_feerate_sats_per_1000_weight = if target_feerate_sats_per_1000_weight.is_some() { Some( { target_feerate_sats_per_1000_weight.take() }) } else { None };
3483         let mut local_shutdown_script = if shutdown_script.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(shutdown_script.take_inner()) } }) };
3484         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel_with_feerate_and_script(channel_id.get_native_ref(), &counterparty_node_id.into_rust(), local_target_feerate_sats_per_1000_weight, local_shutdown_script);
3485         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
3486         local_ret
3487 }
3488
3489 /// Force closes a channel, immediately broadcasting the latest local transaction(s) and
3490 /// rejecting new HTLCs on the given channel. Fails if `channel_id` is unknown to
3491 /// the manager, or if the `counterparty_node_id` isn't the counterparty of the corresponding
3492 /// channel.
3493 #[must_use]
3494 #[no_mangle]
3495 pub extern "C" fn ChannelManager_force_close_broadcasting_latest_txn(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, channel_id: &crate::lightning::ln::types::ChannelId, mut counterparty_node_id: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
3496         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_broadcasting_latest_txn(channel_id.get_native_ref(), &counterparty_node_id.into_rust());
3497         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
3498         local_ret
3499 }
3500
3501 /// Force closes a channel, rejecting new HTLCs on the given channel but skips broadcasting
3502 /// the latest local transaction(s). Fails if `channel_id` is unknown to the manager, or if the
3503 /// `counterparty_node_id` isn't the counterparty of the corresponding channel.
3504 ///
3505 /// You can always broadcast the latest local transaction(s) via
3506 /// [`ChannelMonitor::broadcast_latest_holder_commitment_txn`].
3507 #[must_use]
3508 #[no_mangle]
3509 pub extern "C" fn ChannelManager_force_close_without_broadcasting_txn(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, channel_id: &crate::lightning::ln::types::ChannelId, mut counterparty_node_id: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
3510         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_without_broadcasting_txn(channel_id.get_native_ref(), &counterparty_node_id.into_rust());
3511         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
3512         local_ret
3513 }
3514
3515 /// Force close all channels, immediately broadcasting the latest local commitment transaction
3516 /// for each to the chain and rejecting new HTLCs on each.
3517 #[no_mangle]
3518 pub extern "C" fn ChannelManager_force_close_all_channels_broadcasting_latest_txn(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
3519         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_all_channels_broadcasting_latest_txn()
3520 }
3521
3522 /// Force close all channels rejecting new HTLCs on each but without broadcasting the latest
3523 /// local transaction(s).
3524 #[no_mangle]
3525 pub extern "C" fn ChannelManager_force_close_all_channels_without_broadcasting_txn(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
3526         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_all_channels_without_broadcasting_txn()
3527 }
3528
3529 /// Sends a payment along a given route.
3530 ///
3531 /// Value parameters are provided via the last hop in route, see documentation for [`RouteHop`]
3532 /// fields for more info.
3533 ///
3534 /// May generate [`UpdateHTLCs`] message(s) event on success, which should be relayed (e.g. via
3535 /// [`PeerManager::process_events`]).
3536 ///
3537 /// # Avoiding Duplicate Payments
3538 ///
3539 /// If a pending payment is currently in-flight with the same [`PaymentId`] provided, this
3540 /// method will error with an [`APIError::InvalidRoute`]. Note, however, that once a payment
3541 /// is no longer pending (either via [`ChannelManager::abandon_payment`], or handling of an
3542 /// [`Event::PaymentSent`] or [`Event::PaymentFailed`]) LDK will not stop you from sending a
3543 /// second payment with the same [`PaymentId`].
3544 ///
3545 /// Thus, in order to ensure duplicate payments are not sent, you should implement your own
3546 /// tracking of payments, including state to indicate once a payment has completed. Because you
3547 /// should also ensure that [`PaymentHash`]es are not re-used, for simplicity, you should
3548 /// consider using the [`PaymentHash`] as the key for tracking payments. In that case, the
3549 /// [`PaymentId`] should be a copy of the [`PaymentHash`] bytes.
3550 ///
3551 /// Additionally, in the scenario where we begin the process of sending a payment, but crash
3552 /// before `send_payment` returns (or prior to [`ChannelMonitorUpdate`] persistence if you're
3553 /// using [`ChannelMonitorUpdateStatus::InProgress`]), the payment may be lost on restart. See
3554 /// [`ChannelManager::list_recent_payments`] for more information.
3555 ///
3556 /// # Possible Error States on [`PaymentSendFailure`]
3557 ///
3558 /// Each path may have a different return value, and [`PaymentSendFailure`] may return a `Vec` with
3559 /// each entry matching the corresponding-index entry in the route paths, see
3560 /// [`PaymentSendFailure`] for more info.
3561 ///
3562 /// In general, a path may raise:
3563 ///  * [`APIError::InvalidRoute`] when an invalid route or forwarding parameter (cltv_delta, fee,
3564 ///    node public key) is specified.
3565 ///  * [`APIError::ChannelUnavailable`] if the next-hop channel is not available as it has been
3566 ///    closed, doesn't exist, or the peer is currently disconnected.
3567 ///  * [`APIError::MonitorUpdateInProgress`] if a new monitor update failure prevented sending the
3568 ///    relevant updates.
3569 ///
3570 /// Note that depending on the type of the [`PaymentSendFailure`] the HTLC may have been
3571 /// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
3572 /// different route unless you intend to pay twice!
3573 ///
3574 /// [`RouteHop`]: crate::routing::router::RouteHop
3575 /// [`Event::PaymentSent`]: events::Event::PaymentSent
3576 /// [`Event::PaymentFailed`]: events::Event::PaymentFailed
3577 /// [`UpdateHTLCs`]: events::MessageSendEvent::UpdateHTLCs
3578 /// [`PeerManager::process_events`]: crate::ln::peer_handler::PeerManager::process_events
3579 /// [`ChannelMonitorUpdateStatus::InProgress`]: crate::chain::ChannelMonitorUpdateStatus::InProgress
3580 #[must_use]
3581 #[no_mangle]
3582 pub extern "C" fn ChannelManager_send_payment_with_route(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut recipient_onion: crate::lightning::ln::outbound_payment::RecipientOnionFields, mut payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_NonePaymentSendFailureZ {
3583         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_payment_with_route(route.get_native_ref(), ::lightning::ln::types::PaymentHash(payment_hash.data), *unsafe { Box::from_raw(recipient_onion.take_inner()) }, ::lightning::ln::channelmanager::PaymentId(payment_id.data));
3584         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::outbound_payment::PaymentSendFailure::native_into(e) }).into() };
3585         local_ret
3586 }
3587
3588 /// Similar to [`ChannelManager::send_payment_with_route`], but will automatically find a route based on
3589 /// `route_params` and retry failed payment paths based on `retry_strategy`.
3590 #[must_use]
3591 #[no_mangle]
3592 pub extern "C" fn ChannelManager_send_payment(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut recipient_onion: crate::lightning::ln::outbound_payment::RecipientOnionFields, mut payment_id: crate::c_types::ThirtyTwoBytes, mut route_params: crate::lightning::routing::router::RouteParameters, mut retry_strategy: crate::lightning::ln::outbound_payment::Retry) -> crate::c_types::derived::CResult_NoneRetryableSendFailureZ {
3593         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_payment(::lightning::ln::types::PaymentHash(payment_hash.data), *unsafe { Box::from_raw(recipient_onion.take_inner()) }, ::lightning::ln::channelmanager::PaymentId(payment_id.data), *unsafe { Box::from_raw(route_params.take_inner()) }, retry_strategy.into_native());
3594         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::outbound_payment::RetryableSendFailure::native_into(e) }).into() };
3595         local_ret
3596 }
3597
3598 /// Signals that no further attempts for the given payment should occur. Useful if you have a
3599 /// pending outbound payment with retries remaining, but wish to stop retrying the payment before
3600 /// retries are exhausted.
3601 ///
3602 /// # Event Generation
3603 ///
3604 /// If no [`Event::PaymentFailed`] event had been generated before, one will be generated as soon
3605 /// as there are no remaining pending HTLCs for this payment.
3606 ///
3607 /// Note that calling this method does *not* prevent a payment from succeeding. You must still
3608 /// wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to
3609 /// determine the ultimate status of a payment.
3610 ///
3611 /// # Requested Invoices
3612 ///
3613 /// In the case of paying a [`Bolt12Invoice`] via [`ChannelManager::pay_for_offer`], abandoning
3614 /// the payment prior to receiving the invoice will result in an [`Event::InvoiceRequestFailed`]
3615 /// and prevent any attempts at paying it once received. The other events may only be generated
3616 /// once the invoice has been received.
3617 ///
3618 /// # Restart Behavior
3619 ///
3620 /// If an [`Event::PaymentFailed`] is generated and we restart without first persisting the
3621 /// [`ChannelManager`], another [`Event::PaymentFailed`] may be generated; likewise for
3622 /// [`Event::InvoiceRequestFailed`].
3623 ///
3624 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
3625 #[no_mangle]
3626 pub extern "C" fn ChannelManager_abandon_payment(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_id: crate::c_types::ThirtyTwoBytes) {
3627         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.abandon_payment(::lightning::ln::channelmanager::PaymentId(payment_id.data))
3628 }
3629
3630 /// Send a spontaneous payment, which is a payment that does not require the recipient to have
3631 /// generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
3632 /// the preimage, it must be a cryptographically secure random value that no intermediate node
3633 /// would be able to guess -- otherwise, an intermediate node may claim the payment and it will
3634 /// never reach the recipient.
3635 ///
3636 /// See [`send_payment`] documentation for more details on the return value of this function
3637 /// and idempotency guarantees provided by the [`PaymentId`] key.
3638 ///
3639 /// Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
3640 /// [`send_payment`] for more information about the risks of duplicate preimage usage.
3641 ///
3642 /// [`send_payment`]: Self::send_payment
3643 #[must_use]
3644 #[no_mangle]
3645 pub extern "C" fn ChannelManager_send_spontaneous_payment(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_preimage: crate::c_types::derived::COption_ThirtyTwoBytesZ, mut recipient_onion: crate::lightning::ln::outbound_payment::RecipientOnionFields, mut payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_ThirtyTwoBytesPaymentSendFailureZ {
3646         let mut local_payment_preimage = { /*payment_preimage*/ let payment_preimage_opt = payment_preimage; if payment_preimage_opt.is_none() { None } else { Some({ { ::lightning::ln::types::PaymentPreimage({ payment_preimage_opt.take() }.data) }})} };
3647         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_spontaneous_payment(route.get_native_ref(), local_payment_preimage, *unsafe { Box::from_raw(recipient_onion.take_inner()) }, ::lightning::ln::channelmanager::PaymentId(payment_id.data));
3648         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ThirtyTwoBytes { data: o.0 } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::outbound_payment::PaymentSendFailure::native_into(e) }).into() };
3649         local_ret
3650 }
3651
3652 /// Similar to [`ChannelManager::send_spontaneous_payment`], but will automatically find a route
3653 /// based on `route_params` and retry failed payment paths based on `retry_strategy`.
3654 ///
3655 /// See [`PaymentParameters::for_keysend`] for help in constructing `route_params` for spontaneous
3656 /// payments.
3657 ///
3658 /// [`PaymentParameters::for_keysend`]: crate::routing::router::PaymentParameters::for_keysend
3659 #[must_use]
3660 #[no_mangle]
3661 pub extern "C" fn ChannelManager_send_spontaneous_payment_with_retry(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_preimage: crate::c_types::derived::COption_ThirtyTwoBytesZ, mut recipient_onion: crate::lightning::ln::outbound_payment::RecipientOnionFields, mut payment_id: crate::c_types::ThirtyTwoBytes, mut route_params: crate::lightning::routing::router::RouteParameters, mut retry_strategy: crate::lightning::ln::outbound_payment::Retry) -> crate::c_types::derived::CResult_ThirtyTwoBytesRetryableSendFailureZ {
3662         let mut local_payment_preimage = { /*payment_preimage*/ let payment_preimage_opt = payment_preimage; if payment_preimage_opt.is_none() { None } else { Some({ { ::lightning::ln::types::PaymentPreimage({ payment_preimage_opt.take() }.data) }})} };
3663         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_spontaneous_payment_with_retry(local_payment_preimage, *unsafe { Box::from_raw(recipient_onion.take_inner()) }, ::lightning::ln::channelmanager::PaymentId(payment_id.data), *unsafe { Box::from_raw(route_params.take_inner()) }, retry_strategy.into_native());
3664         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ThirtyTwoBytes { data: o.0 } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::outbound_payment::RetryableSendFailure::native_into(e) }).into() };
3665         local_ret
3666 }
3667
3668 /// Send a payment that is probing the given route for liquidity. We calculate the
3669 /// [`PaymentHash`] of probes based on a static secret and a random [`PaymentId`], which allows
3670 /// us to easily discern them from real payments.
3671 #[must_use]
3672 #[no_mangle]
3673 pub extern "C" fn ChannelManager_send_probe(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut path: crate::lightning::routing::router::Path) -> crate::c_types::derived::CResult_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZPaymentSendFailureZ {
3674         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_probe(*unsafe { Box::from_raw(path.take_inner()) });
3675         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.0 }, crate::c_types::ThirtyTwoBytes { data: orig_ret_0_1.0 }).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::outbound_payment::PaymentSendFailure::native_into(e) }).into() };
3676         local_ret
3677 }
3678
3679 /// Sends payment probes over all paths of a route that would be used to pay the given
3680 /// amount to the given `node_id`.
3681 ///
3682 /// See [`ChannelManager::send_preflight_probes`] for more information.
3683 #[must_use]
3684 #[no_mangle]
3685 pub extern "C" fn ChannelManager_send_spontaneous_preflight_probes(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut node_id: crate::c_types::PublicKey, mut amount_msat: u64, mut final_cltv_expiry_delta: u32, mut liquidity_limit_multiplier: crate::c_types::derived::COption_u64Z) -> crate::c_types::derived::CResult_CVec_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZZProbeSendFailureZ {
3686         let mut local_liquidity_limit_multiplier = if liquidity_limit_multiplier.is_some() { Some( { liquidity_limit_multiplier.take() }) } else { None };
3687         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_spontaneous_preflight_probes(node_id.into_rust(), amount_msat, final_cltv_expiry_delta, local_liquidity_limit_multiplier);
3688         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for mut item in o.drain(..) { local_ret_0.push( { let (mut orig_ret_0_0_0, mut orig_ret_0_0_1) = item; let mut local_ret_0_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0_0.0 }, crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0_1.0 }).into(); local_ret_0_0 }); }; local_ret_0.into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::outbound_payment::ProbeSendFailure::native_into(e) }).into() };
3689         local_ret
3690 }
3691
3692 /// Sends payment probes over all paths of a route that would be used to pay a route found
3693 /// according to the given [`RouteParameters`].
3694 ///
3695 /// This may be used to send \"pre-flight\" probes, i.e., to train our scorer before conducting
3696 /// the actual payment. Note this is only useful if there likely is sufficient time for the
3697 /// probe to settle before sending out the actual payment, e.g., when waiting for user
3698 /// confirmation in a wallet UI.
3699 ///
3700 /// Otherwise, there is a chance the probe could take up some liquidity needed to complete the
3701 /// actual payment. Users should therefore be cautious and might avoid sending probes if
3702 /// liquidity is scarce and/or they don't expect the probe to return before they send the
3703 /// payment. To mitigate this issue, channels with available liquidity less than the required
3704 /// amount times the given `liquidity_limit_multiplier` won't be used to send pre-flight
3705 /// probes. If `None` is given as `liquidity_limit_multiplier`, it defaults to `3`.
3706 #[must_use]
3707 #[no_mangle]
3708 pub extern "C" fn ChannelManager_send_preflight_probes(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut route_params: crate::lightning::routing::router::RouteParameters, mut liquidity_limit_multiplier: crate::c_types::derived::COption_u64Z) -> crate::c_types::derived::CResult_CVec_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZZProbeSendFailureZ {
3709         let mut local_liquidity_limit_multiplier = if liquidity_limit_multiplier.is_some() { Some( { liquidity_limit_multiplier.take() }) } else { None };
3710         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_preflight_probes(*unsafe { Box::from_raw(route_params.take_inner()) }, local_liquidity_limit_multiplier);
3711         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for mut item in o.drain(..) { local_ret_0.push( { let (mut orig_ret_0_0_0, mut orig_ret_0_0_1) = item; let mut local_ret_0_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0_0.0 }, crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0_1.0 }).into(); local_ret_0_0 }); }; local_ret_0.into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::outbound_payment::ProbeSendFailure::native_into(e) }).into() };
3712         local_ret
3713 }
3714
3715 /// Call this upon creation of a funding transaction for the given channel.
3716 ///
3717 /// Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
3718 /// or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
3719 ///
3720 /// Returns [`APIError::APIMisuseError`] if the funding transaction is not final for propagation
3721 /// across the p2p network.
3722 ///
3723 /// Returns [`APIError::ChannelUnavailable`] if a funding transaction has already been provided
3724 /// for the channel or if the channel has been closed as indicated by [`Event::ChannelClosed`].
3725 ///
3726 /// May panic if the output found in the funding transaction is duplicative with some other
3727 /// channel (note that this should be trivially prevented by using unique funding transaction
3728 /// keys per-channel).
3729 ///
3730 /// Do NOT broadcast the funding transaction yourself. When we have safely received our
3731 /// counterparty's signature the funding transaction will automatically be broadcast via the
3732 /// [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
3733 ///
3734 /// Note that this includes RBF or similar transaction replacement strategies - lightning does
3735 /// not currently support replacing a funding transaction on an existing channel. Instead,
3736 /// create a new channel with a conflicting funding transaction.
3737 ///
3738 /// Note to keep the miner incentives aligned in moving the blockchain forward, we recommend
3739 /// the wallet software generating the funding transaction to apply anti-fee sniping as
3740 /// implemented by Bitcoin Core wallet. See <https://bitcoinops.org/en/topics/fee-sniping/>
3741 /// for more details.
3742 ///
3743 /// [`Event::FundingGenerationReady`]: crate::events::Event::FundingGenerationReady
3744 /// [`Event::ChannelClosed`]: crate::events::Event::ChannelClosed
3745 #[must_use]
3746 #[no_mangle]
3747 pub extern "C" fn ChannelManager_funding_transaction_generated(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, temporary_channel_id: &crate::lightning::ln::types::ChannelId, mut counterparty_node_id: crate::c_types::PublicKey, mut funding_transaction: crate::c_types::Transaction) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
3748         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_transaction_generated(temporary_channel_id.get_native_ref(), &counterparty_node_id.into_rust(), funding_transaction.into_bitcoin());
3749         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
3750         local_ret
3751 }
3752
3753 /// Call this upon creation of a batch funding transaction for the given channels.
3754 ///
3755 /// Return values are identical to [`Self::funding_transaction_generated`], respective to
3756 /// each individual channel and transaction output.
3757 ///
3758 /// Do NOT broadcast the funding transaction yourself. This batch funding transaction
3759 /// will only be broadcast when we have safely received and persisted the counterparty's
3760 /// signature for each channel.
3761 ///
3762 /// If there is an error, all channels in the batch are to be considered closed.
3763 #[must_use]
3764 #[no_mangle]
3765 pub extern "C" fn ChannelManager_batch_funding_transaction_generated(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut temporary_channels: crate::c_types::derived::CVec_C2Tuple_ChannelIdPublicKeyZZ, mut funding_transaction: crate::c_types::Transaction) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
3766         let mut local_temporary_channels = Vec::new(); for mut item in temporary_channels.into_rust().drain(..) { local_temporary_channels.push( { let (mut orig_temporary_channels_0_0, mut orig_temporary_channels_0_1) = item.to_rust(); let mut local_temporary_channels_0 = (*unsafe { Box::from_raw(orig_temporary_channels_0_0.take_inner()) }, orig_temporary_channels_0_1.into_rust()); local_temporary_channels_0 }); };
3767         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.batch_funding_transaction_generated(&local_temporary_channels.iter().map(|(a, b)| (a, b)).collect::<Vec<_>>()[..], funding_transaction.into_bitcoin());
3768         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
3769         local_ret
3770 }
3771
3772 /// Atomically applies partial updates to the [`ChannelConfig`] of the given channels.
3773 ///
3774 /// Once the updates are applied, each eligible channel (advertised with a known short channel
3775 /// ID and a change in [`forwarding_fee_proportional_millionths`], [`forwarding_fee_base_msat`],
3776 /// or [`cltv_expiry_delta`]) has a [`BroadcastChannelUpdate`] event message generated
3777 /// containing the new [`ChannelUpdate`] message which should be broadcast to the network.
3778 ///
3779 /// Returns [`ChannelUnavailable`] when a channel is not found or an incorrect
3780 /// `counterparty_node_id` is provided.
3781 ///
3782 /// Returns [`APIMisuseError`] when a [`cltv_expiry_delta`] update is to be applied with a value
3783 /// below [`MIN_CLTV_EXPIRY_DELTA`].
3784 ///
3785 /// If an error is returned, none of the updates should be considered applied.
3786 ///
3787 /// [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
3788 /// [`forwarding_fee_base_msat`]: ChannelConfig::forwarding_fee_base_msat
3789 /// [`cltv_expiry_delta`]: ChannelConfig::cltv_expiry_delta
3790 /// [`BroadcastChannelUpdate`]: events::MessageSendEvent::BroadcastChannelUpdate
3791 /// [`ChannelUpdate`]: msgs::ChannelUpdate
3792 /// [`ChannelUnavailable`]: APIError::ChannelUnavailable
3793 /// [`APIMisuseError`]: APIError::APIMisuseError
3794 #[must_use]
3795 #[no_mangle]
3796 pub extern "C" fn ChannelManager_update_partial_channel_config(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut counterparty_node_id: crate::c_types::PublicKey, mut channel_ids: crate::c_types::derived::CVec_ChannelIdZ, config_update: &crate::lightning::util::config::ChannelConfigUpdate) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
3797         let mut local_channel_ids = Vec::new(); for mut item in channel_ids.into_rust().drain(..) { local_channel_ids.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
3798         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_partial_channel_config(&counterparty_node_id.into_rust(), local_channel_ids, config_update.get_native_ref());
3799         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
3800         local_ret
3801 }
3802
3803 /// Atomically updates the [`ChannelConfig`] for the given channels.
3804 ///
3805 /// Once the updates are applied, each eligible channel (advertised with a known short channel
3806 /// ID and a change in [`forwarding_fee_proportional_millionths`], [`forwarding_fee_base_msat`],
3807 /// or [`cltv_expiry_delta`]) has a [`BroadcastChannelUpdate`] event message generated
3808 /// containing the new [`ChannelUpdate`] message which should be broadcast to the network.
3809 ///
3810 /// Returns [`ChannelUnavailable`] when a channel is not found or an incorrect
3811 /// `counterparty_node_id` is provided.
3812 ///
3813 /// Returns [`APIMisuseError`] when a [`cltv_expiry_delta`] update is to be applied with a value
3814 /// below [`MIN_CLTV_EXPIRY_DELTA`].
3815 ///
3816 /// If an error is returned, none of the updates should be considered applied.
3817 ///
3818 /// [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
3819 /// [`forwarding_fee_base_msat`]: ChannelConfig::forwarding_fee_base_msat
3820 /// [`cltv_expiry_delta`]: ChannelConfig::cltv_expiry_delta
3821 /// [`BroadcastChannelUpdate`]: events::MessageSendEvent::BroadcastChannelUpdate
3822 /// [`ChannelUpdate`]: msgs::ChannelUpdate
3823 /// [`ChannelUnavailable`]: APIError::ChannelUnavailable
3824 /// [`APIMisuseError`]: APIError::APIMisuseError
3825 #[must_use]
3826 #[no_mangle]
3827 pub extern "C" fn ChannelManager_update_channel_config(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut counterparty_node_id: crate::c_types::PublicKey, mut channel_ids: crate::c_types::derived::CVec_ChannelIdZ, config: &crate::lightning::util::config::ChannelConfig) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
3828         let mut local_channel_ids = Vec::new(); for mut item in channel_ids.into_rust().drain(..) { local_channel_ids.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
3829         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_config(&counterparty_node_id.into_rust(), local_channel_ids, config.get_native_ref());
3830         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
3831         local_ret
3832 }
3833
3834 /// Attempts to forward an intercepted HTLC over the provided channel id and with the provided
3835 /// amount to forward. Should only be called in response to an [`HTLCIntercepted`] event.
3836 ///
3837 /// Intercepted HTLCs can be useful for Lightning Service Providers (LSPs) to open a just-in-time
3838 /// channel to a receiving node if the node lacks sufficient inbound liquidity.
3839 ///
3840 /// To make use of intercepted HTLCs, set [`UserConfig::accept_intercept_htlcs`] and use
3841 /// [`ChannelManager::get_intercept_scid`] to generate short channel id(s) to put in the
3842 /// receiver's invoice route hints. These route hints will signal to LDK to generate an
3843 /// [`HTLCIntercepted`] event when it receives the forwarded HTLC, and this method or
3844 /// [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to the event.
3845 ///
3846 /// Note that LDK does not enforce fee requirements in `amt_to_forward_msat`, and will not stop
3847 /// you from forwarding more than you received. See
3848 /// [`HTLCIntercepted::expected_outbound_amount_msat`] for more on forwarding a different amount
3849 /// than expected.
3850 ///
3851 /// Errors if the event was not handled in time, in which case the HTLC was automatically failed
3852 /// backwards.
3853 ///
3854 /// [`UserConfig::accept_intercept_htlcs`]: crate::util::config::UserConfig::accept_intercept_htlcs
3855 /// [`HTLCIntercepted`]: events::Event::HTLCIntercepted
3856 /// [`HTLCIntercepted::expected_outbound_amount_msat`]: events::Event::HTLCIntercepted::expected_outbound_amount_msat
3857 #[must_use]
3858 #[no_mangle]
3859 pub extern "C" fn ChannelManager_forward_intercepted_htlc(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut intercept_id: crate::c_types::ThirtyTwoBytes, next_hop_channel_id: &crate::lightning::ln::types::ChannelId, mut next_node_id: crate::c_types::PublicKey, mut amt_to_forward_msat: u64) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
3860         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.forward_intercepted_htlc(::lightning::ln::channelmanager::InterceptId(intercept_id.data), next_hop_channel_id.get_native_ref(), next_node_id.into_rust(), amt_to_forward_msat);
3861         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
3862         local_ret
3863 }
3864
3865 /// Fails the intercepted HTLC indicated by intercept_id. Should only be called in response to
3866 /// an [`HTLCIntercepted`] event. See [`ChannelManager::forward_intercepted_htlc`].
3867 ///
3868 /// Errors if the event was not handled in time, in which case the HTLC was automatically failed
3869 /// backwards.
3870 ///
3871 /// [`HTLCIntercepted`]: events::Event::HTLCIntercepted
3872 #[must_use]
3873 #[no_mangle]
3874 pub extern "C" fn ChannelManager_fail_intercepted_htlc(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut intercept_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
3875         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_intercepted_htlc(::lightning::ln::channelmanager::InterceptId(intercept_id.data));
3876         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
3877         local_ret
3878 }
3879
3880 /// Processes HTLCs which are pending waiting on random forward delay.
3881 ///
3882 /// Should only really ever be called in response to a PendingHTLCsForwardable event.
3883 /// Will likely generate further events.
3884 #[no_mangle]
3885 pub extern "C" fn ChannelManager_process_pending_htlc_forwards(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
3886         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_pending_htlc_forwards()
3887 }
3888
3889 /// Performs actions which should happen on startup and roughly once per minute thereafter.
3890 ///
3891 /// This currently includes:
3892 ///  * Increasing or decreasing the on-chain feerate estimates for our outbound channels,
3893 ///  * Broadcasting [`ChannelUpdate`] messages if we've been disconnected from our peer for more
3894 ///    than a minute, informing the network that they should no longer attempt to route over
3895 ///    the channel.
3896 ///  * Expiring a channel's previous [`ChannelConfig`] if necessary to only allow forwarding HTLCs
3897 ///    with the current [`ChannelConfig`].
3898 ///  * Removing peers which have disconnected but and no longer have any channels.
3899 ///  * Force-closing and removing channels which have not completed establishment in a timely manner.
3900 ///  * Forgetting about stale outbound payments, either those that have already been fulfilled
3901 ///    or those awaiting an invoice that hasn't been delivered in the necessary amount of time.
3902 ///    The latter is determined using the system clock in `std` and the highest seen block time
3903 ///    minus two hours in `no-std`.
3904 ///
3905 /// Note that this may cause reentrancy through [`chain::Watch::update_channel`] calls or feerate
3906 /// estimate fetches.
3907 ///
3908 /// [`ChannelUpdate`]: msgs::ChannelUpdate
3909 /// [`ChannelConfig`]: crate::util::config::ChannelConfig
3910 #[no_mangle]
3911 pub extern "C" fn ChannelManager_timer_tick_occurred(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
3912         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timer_tick_occurred()
3913 }
3914
3915 /// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
3916 /// after a PaymentClaimable event, failing the HTLC back to its origin and freeing resources
3917 /// along the path (including in our own channel on which we received it).
3918 ///
3919 /// Note that in some cases around unclean shutdown, it is possible the payment may have
3920 /// already been claimed by you via [`ChannelManager::claim_funds`] prior to you seeing (a
3921 /// second copy of) the [`events::Event::PaymentClaimable`] event. Alternatively, the payment
3922 /// may have already been failed automatically by LDK if it was nearing its expiration time.
3923 ///
3924 /// While LDK will never claim a payment automatically on your behalf (i.e. without you calling
3925 /// [`ChannelManager::claim_funds`]), you should still monitor for
3926 /// [`events::Event::PaymentClaimed`] events even for payments you intend to fail, especially on
3927 /// startup during which time claims that were in-progress at shutdown may be replayed.
3928 #[no_mangle]
3929 pub extern "C" fn ChannelManager_fail_htlc_backwards(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, payment_hash: *const [u8; 32]) {
3930         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_htlc_backwards(&::lightning::ln::types::PaymentHash(unsafe { *payment_hash }))
3931 }
3932
3933 /// This is a variant of [`ChannelManager::fail_htlc_backwards`] that allows you to specify the
3934 /// reason for the failure.
3935 ///
3936 /// See [`FailureCode`] for valid failure codes.
3937 #[no_mangle]
3938 pub extern "C" fn ChannelManager_fail_htlc_backwards_with_reason(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, payment_hash: *const [u8; 32], mut failure_code: crate::lightning::ln::channelmanager::FailureCode) {
3939         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_htlc_backwards_with_reason(&::lightning::ln::types::PaymentHash(unsafe { *payment_hash }), failure_code.into_native())
3940 }
3941
3942 /// Provides a payment preimage in response to [`Event::PaymentClaimable`], generating any
3943 /// [`MessageSendEvent`]s needed to claim the payment.
3944 ///
3945 /// This method is guaranteed to ensure the payment has been claimed but only if the current
3946 /// height is strictly below [`Event::PaymentClaimable::claim_deadline`]. To avoid race
3947 /// conditions, you should wait for an [`Event::PaymentClaimed`] before considering the payment
3948 /// successful. It will generally be available in the next [`process_pending_events`] call.
3949 ///
3950 /// Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
3951 /// [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentClaimable`
3952 /// event matches your expectation. If you fail to do so and call this method, you may provide
3953 /// the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
3954 ///
3955 /// This function will fail the payment if it has custom TLVs with even type numbers, as we
3956 /// will assume they are unknown. If you intend to accept even custom TLVs, you should use
3957 /// [`claim_funds_with_known_custom_tlvs`].
3958 ///
3959 /// [`Event::PaymentClaimable`]: crate::events::Event::PaymentClaimable
3960 /// [`Event::PaymentClaimable::claim_deadline`]: crate::events::Event::PaymentClaimable::claim_deadline
3961 /// [`Event::PaymentClaimed`]: crate::events::Event::PaymentClaimed
3962 /// [`process_pending_events`]: EventsProvider::process_pending_events
3963 /// [`create_inbound_payment`]: Self::create_inbound_payment
3964 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
3965 /// [`claim_funds_with_known_custom_tlvs`]: Self::claim_funds_with_known_custom_tlvs
3966 #[no_mangle]
3967 pub extern "C" fn ChannelManager_claim_funds(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_preimage: crate::c_types::ThirtyTwoBytes) {
3968         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.claim_funds(::lightning::ln::types::PaymentPreimage(payment_preimage.data))
3969 }
3970
3971 /// This is a variant of [`claim_funds`] that allows accepting a payment with custom TLVs with
3972 /// even type numbers.
3973 ///
3974 /// # Note
3975 ///
3976 /// You MUST check you've understood all even TLVs before using this to
3977 /// claim, otherwise you may unintentionally agree to some protocol you do not understand.
3978 ///
3979 /// [`claim_funds`]: Self::claim_funds
3980 #[no_mangle]
3981 pub extern "C" fn ChannelManager_claim_funds_with_known_custom_tlvs(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_preimage: crate::c_types::ThirtyTwoBytes) {
3982         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.claim_funds_with_known_custom_tlvs(::lightning::ln::types::PaymentPreimage(payment_preimage.data))
3983 }
3984
3985 /// Gets the node_id held by this ChannelManager
3986 #[must_use]
3987 #[no_mangle]
3988 pub extern "C" fn ChannelManager_get_our_node_id(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::PublicKey {
3989         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_our_node_id();
3990         crate::c_types::PublicKey::from_rust(&ret)
3991 }
3992
3993 /// Accepts a request to open a channel after a [`Event::OpenChannelRequest`].
3994 ///
3995 /// The `temporary_channel_id` parameter indicates which inbound channel should be accepted,
3996 /// and the `counterparty_node_id` parameter is the id of the peer which has requested to open
3997 /// the channel.
3998 ///
3999 /// The `user_channel_id` parameter will be provided back in
4000 /// [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
4001 /// with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
4002 ///
4003 /// Note that this method will return an error and reject the channel, if it requires support
4004 /// for zero confirmations. Instead, `accept_inbound_channel_from_trusted_peer_0conf` must be
4005 /// used to accept such channels.
4006 ///
4007 /// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
4008 /// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
4009 #[must_use]
4010 #[no_mangle]
4011 pub extern "C" fn ChannelManager_accept_inbound_channel(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, temporary_channel_id: &crate::lightning::ln::types::ChannelId, mut counterparty_node_id: crate::c_types::PublicKey, mut user_channel_id: crate::c_types::U128) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
4012         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.accept_inbound_channel(temporary_channel_id.get_native_ref(), &counterparty_node_id.into_rust(), user_channel_id.into());
4013         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
4014         local_ret
4015 }
4016
4017 /// Accepts a request to open a channel after a [`events::Event::OpenChannelRequest`], treating
4018 /// it as confirmed immediately.
4019 ///
4020 /// The `user_channel_id` parameter will be provided back in
4021 /// [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
4022 /// with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
4023 ///
4024 /// Unlike [`ChannelManager::accept_inbound_channel`], this method accepts the incoming channel
4025 /// and (if the counterparty agrees), enables forwarding of payments immediately.
4026 ///
4027 /// This fully trusts that the counterparty has honestly and correctly constructed the funding
4028 /// transaction and blindly assumes that it will eventually confirm.
4029 ///
4030 /// If it does not confirm before we decide to close the channel, or if the funding transaction
4031 /// does not pay to the correct script the correct amount, *you will lose funds*.
4032 ///
4033 /// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
4034 /// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
4035 #[must_use]
4036 #[no_mangle]
4037 pub extern "C" fn ChannelManager_accept_inbound_channel_from_trusted_peer_0conf(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, temporary_channel_id: &crate::lightning::ln::types::ChannelId, mut counterparty_node_id: crate::c_types::PublicKey, mut user_channel_id: crate::c_types::U128) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
4038         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.accept_inbound_channel_from_trusted_peer_0conf(temporary_channel_id.get_native_ref(), &counterparty_node_id.into_rust(), user_channel_id.into());
4039         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
4040         local_ret
4041 }
4042
4043 /// Creates an [`OfferBuilder`] such that the [`Offer`] it builds is recognized by the
4044 /// [`ChannelManager`] when handling [`InvoiceRequest`] messages for the offer. The offer will
4045 /// not have an expiration unless otherwise set on the builder.
4046 ///
4047 /// # Privacy
4048 ///
4049 /// Uses [`MessageRouter::create_blinded_paths`] to construct a [`BlindedPath`] for the offer.
4050 /// However, if one is not found, uses a one-hop [`BlindedPath`] with
4051 /// [`ChannelManager::get_our_node_id`] as the introduction node instead. In the latter case,
4052 /// the node must be announced, otherwise, there is no way to find a path to the introduction in
4053 /// order to send the [`InvoiceRequest`].
4054 ///
4055 /// Also, uses a derived signing pubkey in the offer for recipient privacy.
4056 ///
4057 /// # Limitations
4058 ///
4059 /// Requires a direct connection to the introduction node in the responding [`InvoiceRequest`]'s
4060 /// reply path.
4061 ///
4062 /// # Errors
4063 ///
4064 /// Errors if the parameterized [`Router`] is unable to create a blinded path for the offer.
4065 ///
4066 /// [`Offer`]: crate::offers::offer::Offer
4067 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
4068 #[must_use]
4069 #[no_mangle]
4070 pub extern "C" fn ChannelManager_create_offer_builder(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CResult_OfferWithDerivedMetadataBuilderBolt12SemanticErrorZ {
4071         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_offer_builder();
4072         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::offers::offer::OfferWithDerivedMetadataBuilder { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::offers::parse::Bolt12SemanticError::native_into(e) }).into() };
4073         local_ret
4074 }
4075
4076 /// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the
4077 /// [`ChannelManager`] when handling [`Bolt12Invoice`] messages for the refund.
4078 ///
4079 /// # Payment
4080 ///
4081 /// The provided `payment_id` is used to ensure that only one invoice is paid for the refund.
4082 /// See [Avoiding Duplicate Payments] for other requirements once the payment has been sent.
4083 ///
4084 /// The builder will have the provided expiration set. Any changes to the expiration on the
4085 /// returned builder will not be honored by [`ChannelManager`]. For `no-std`, the highest seen
4086 /// block time minus two hours is used for the current time when determining if the refund has
4087 /// expired.
4088 ///
4089 /// To revoke the refund, use [`ChannelManager::abandon_payment`] prior to receiving the
4090 /// invoice. If abandoned, or an invoice isn't received before expiration, the payment will fail
4091 /// with an [`Event::InvoiceRequestFailed`].
4092 ///
4093 /// If `max_total_routing_fee_msat` is not specified, The default from
4094 /// [`RouteParameters::from_payment_params_and_value`] is applied.
4095 ///
4096 /// # Privacy
4097 ///
4098 /// Uses [`MessageRouter::create_blinded_paths`] to construct a [`BlindedPath`] for the refund.
4099 /// However, if one is not found, uses a one-hop [`BlindedPath`] with
4100 /// [`ChannelManager::get_our_node_id`] as the introduction node instead. In the latter case,
4101 /// the node must be announced, otherwise, there is no way to find a path to the introduction in
4102 /// order to send the [`Bolt12Invoice`].
4103 ///
4104 /// Also, uses a derived payer id in the refund for payer privacy.
4105 ///
4106 /// # Limitations
4107 ///
4108 /// Requires a direct connection to an introduction node in the responding
4109 /// [`Bolt12Invoice::payment_paths`].
4110 ///
4111 /// # Errors
4112 ///
4113 /// Errors if:
4114 /// - a duplicate `payment_id` is provided given the caveats in the aforementioned link,
4115 /// - `amount_msats` is invalid, or
4116 /// - the parameterized [`Router`] is unable to create a blinded path for the refund.
4117 ///
4118 /// [`Refund`]: crate::offers::refund::Refund
4119 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
4120 /// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
4121 /// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
4122 #[must_use]
4123 #[no_mangle]
4124 pub extern "C" fn ChannelManager_create_refund_builder(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut amount_msats: u64, mut absolute_expiry: u64, mut payment_id: crate::c_types::ThirtyTwoBytes, mut retry_strategy: crate::lightning::ln::outbound_payment::Retry, mut max_total_routing_fee_msat: crate::c_types::derived::COption_u64Z) -> crate::c_types::derived::CResult_RefundMaybeWithDerivedMetadataBuilderBolt12SemanticErrorZ {
4125         let mut local_max_total_routing_fee_msat = if max_total_routing_fee_msat.is_some() { Some( { max_total_routing_fee_msat.take() }) } else { None };
4126         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_refund_builder(amount_msats, core::time::Duration::from_secs(absolute_expiry), ::lightning::ln::channelmanager::PaymentId(payment_id.data), retry_strategy.into_native(), local_max_total_routing_fee_msat);
4127         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::offers::refund::RefundMaybeWithDerivedMetadataBuilder { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::offers::parse::Bolt12SemanticError::native_into(e) }).into() };
4128         local_ret
4129 }
4130
4131 /// Pays for an [`Offer`] using the given parameters by creating an [`InvoiceRequest`] and
4132 /// enqueuing it to be sent via an onion message. [`ChannelManager`] will pay the actual
4133 /// [`Bolt12Invoice`] once it is received.
4134 ///
4135 /// Uses [`InvoiceRequestBuilder`] such that the [`InvoiceRequest`] it builds is recognized by
4136 /// the [`ChannelManager`] when handling a [`Bolt12Invoice`] message in response to the request.
4137 /// The optional parameters are used in the builder, if `Some`:
4138 /// - `quantity` for [`InvoiceRequest::quantity`] which must be set if
4139 ///   [`Offer::expects_quantity`] is `true`.
4140 /// - `amount_msats` if overpaying what is required for the given `quantity` is desired, and
4141 /// - `payer_note` for [`InvoiceRequest::payer_note`].
4142 ///
4143 /// If `max_total_routing_fee_msat` is not specified, The default from
4144 /// [`RouteParameters::from_payment_params_and_value`] is applied.
4145 ///
4146 /// # Payment
4147 ///
4148 /// The provided `payment_id` is used to ensure that only one invoice is paid for the request
4149 /// when received. See [Avoiding Duplicate Payments] for other requirements once the payment has
4150 /// been sent.
4151 ///
4152 /// To revoke the request, use [`ChannelManager::abandon_payment`] prior to receiving the
4153 /// invoice. If abandoned, or an invoice isn't received in a reasonable amount of time, the
4154 /// payment will fail with an [`Event::InvoiceRequestFailed`].
4155 ///
4156 /// # Privacy
4157 ///
4158 /// Uses a one-hop [`BlindedPath`] for the reply path with [`ChannelManager::get_our_node_id`]
4159 /// as the introduction node and a derived payer id for payer privacy. As such, currently, the
4160 /// node must be announced. Otherwise, there is no way to find a path to the introduction node
4161 /// in order to send the [`Bolt12Invoice`].
4162 ///
4163 /// # Limitations
4164 ///
4165 /// Requires a direct connection to an introduction node in [`Offer::paths`] or to
4166 /// [`Offer::signing_pubkey`], if empty. A similar restriction applies to the responding
4167 /// [`Bolt12Invoice::payment_paths`].
4168 ///
4169 /// # Errors
4170 ///
4171 /// Errors if:
4172 /// - a duplicate `payment_id` is provided given the caveats in the aforementioned link,
4173 /// - the provided parameters are invalid for the offer,
4174 /// - the offer is for an unsupported chain, or
4175 /// - the parameterized [`Router`] is unable to create a blinded reply path for the invoice
4176 ///   request.
4177 ///
4178 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
4179 /// [`InvoiceRequest::quantity`]: crate::offers::invoice_request::InvoiceRequest::quantity
4180 /// [`InvoiceRequest::payer_note`]: crate::offers::invoice_request::InvoiceRequest::payer_note
4181 /// [`InvoiceRequestBuilder`]: crate::offers::invoice_request::InvoiceRequestBuilder
4182 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
4183 /// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
4184 /// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
4185 #[must_use]
4186 #[no_mangle]
4187 pub extern "C" fn ChannelManager_pay_for_offer(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, offer: &crate::lightning::offers::offer::Offer, mut quantity: crate::c_types::derived::COption_u64Z, mut amount_msats: crate::c_types::derived::COption_u64Z, mut payer_note: crate::c_types::derived::COption_StrZ, mut payment_id: crate::c_types::ThirtyTwoBytes, mut retry_strategy: crate::lightning::ln::outbound_payment::Retry, mut max_total_routing_fee_msat: crate::c_types::derived::COption_u64Z) -> crate::c_types::derived::CResult_NoneBolt12SemanticErrorZ {
4188         let mut local_quantity = if quantity.is_some() { Some( { quantity.take() }) } else { None };
4189         let mut local_amount_msats = if amount_msats.is_some() { Some( { amount_msats.take() }) } else { None };
4190         let mut local_payer_note = { /*payer_note*/ let payer_note_opt = payer_note; if payer_note_opt.is_none() { None } else { Some({ { { payer_note_opt.take() }.into_string() }})} };
4191         let mut local_max_total_routing_fee_msat = if max_total_routing_fee_msat.is_some() { Some( { max_total_routing_fee_msat.take() }) } else { None };
4192         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.pay_for_offer(offer.get_native_ref(), local_quantity, local_amount_msats, local_payer_note, ::lightning::ln::channelmanager::PaymentId(payment_id.data), retry_strategy.into_native(), local_max_total_routing_fee_msat);
4193         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::offers::parse::Bolt12SemanticError::native_into(e) }).into() };
4194         local_ret
4195 }
4196
4197 /// Creates a [`Bolt12Invoice`] for a [`Refund`] and enqueues it to be sent via an onion
4198 /// message.
4199 ///
4200 /// The resulting invoice uses a [`PaymentHash`] recognized by the [`ChannelManager`] and a
4201 /// [`BlindedPath`] containing the [`PaymentSecret`] needed to reconstruct the corresponding
4202 /// [`PaymentPreimage`]. It is returned purely for informational purposes.
4203 ///
4204 /// # Limitations
4205 ///
4206 /// Requires a direct connection to an introduction node in [`Refund::paths`] or to
4207 /// [`Refund::payer_id`], if empty. This request is best effort; an invoice will be sent to each
4208 /// node meeting the aforementioned criteria, but there's no guarantee that they will be
4209 /// received and no retries will be made.
4210 ///
4211 /// # Errors
4212 ///
4213 /// Errors if:
4214 /// - the refund is for an unsupported chain, or
4215 /// - the parameterized [`Router`] is unable to create a blinded payment path or reply path for
4216 ///   the invoice.
4217 ///
4218 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
4219 #[must_use]
4220 #[no_mangle]
4221 pub extern "C" fn ChannelManager_request_refund_payment(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, refund: &crate::lightning::offers::refund::Refund) -> crate::c_types::derived::CResult_Bolt12InvoiceBolt12SemanticErrorZ {
4222         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.request_refund_payment(refund.get_native_ref());
4223         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::offers::invoice::Bolt12Invoice { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::offers::parse::Bolt12SemanticError::native_into(e) }).into() };
4224         local_ret
4225 }
4226
4227 /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
4228 /// to pay us.
4229 ///
4230 /// This differs from [`create_inbound_payment_for_hash`] only in that it generates the
4231 /// [`PaymentHash`] and [`PaymentPreimage`] for you.
4232 ///
4233 /// The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentClaimable`] event, which
4234 /// will have the [`PaymentClaimable::purpose`] return `Some` for [`PaymentPurpose::preimage`]. That
4235 /// should then be passed directly to [`claim_funds`].
4236 ///
4237 /// See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
4238 ///
4239 /// Note that a malicious eavesdropper can intuit whether an inbound payment was created by
4240 /// `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
4241 ///
4242 /// # Note
4243 ///
4244 /// If you register an inbound payment with this method, then serialize the `ChannelManager`, then
4245 /// deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
4246 ///
4247 /// Errors if `min_value_msat` is greater than total bitcoin supply.
4248 ///
4249 /// If `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
4250 /// on versions of LDK prior to 0.0.114.
4251 ///
4252 /// [`claim_funds`]: Self::claim_funds
4253 /// [`PaymentClaimable`]: events::Event::PaymentClaimable
4254 /// [`PaymentClaimable::purpose`]: events::Event::PaymentClaimable::purpose
4255 /// [`PaymentPurpose::preimage`]: events::PaymentPurpose::preimage
4256 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
4257 #[must_use]
4258 #[no_mangle]
4259 pub extern "C" fn ChannelManager_create_inbound_payment(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32, mut min_final_cltv_expiry_delta: crate::c_types::derived::COption_u16Z) -> crate::c_types::derived::CResult_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ {
4260         let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
4261         let mut local_min_final_cltv_expiry_delta = if min_final_cltv_expiry_delta.is_some() { Some( { min_final_cltv_expiry_delta.take() }) } else { None };
4262         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment(local_min_value_msat, invoice_expiry_delta_secs, local_min_final_cltv_expiry_delta);
4263         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.0 }, crate::c_types::ThirtyTwoBytes { data: orig_ret_0_1.0 }).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
4264         local_ret
4265 }
4266
4267 /// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
4268 /// stored external to LDK.
4269 ///
4270 /// A [`PaymentClaimable`] event will only be generated if the [`PaymentSecret`] matches a
4271 /// payment secret fetched via this method or [`create_inbound_payment`], and which is at least
4272 /// the `min_value_msat` provided here, if one is provided.
4273 ///
4274 /// The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) should be globally unique, though
4275 /// note that LDK will not stop you from registering duplicate payment hashes for inbound
4276 /// payments.
4277 ///
4278 /// `min_value_msat` should be set if the invoice being generated contains a value. Any payment
4279 /// received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
4280 /// before a [`PaymentClaimable`] event will be generated, ensuring that we do not provide the
4281 /// sender \"proof-of-payment\" unless they have paid the required amount.
4282 ///
4283 /// `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
4284 /// in excess of the current time. This should roughly match the expiry time set in the invoice.
4285 /// After this many seconds, we will remove the inbound payment, resulting in any attempts to
4286 /// pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
4287 /// invoices when no timeout is set.
4288 ///
4289 /// Note that we use block header time to time-out pending inbound payments (with some margin
4290 /// to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
4291 /// accept a payment and generate a [`PaymentClaimable`] event for some time after the expiry.
4292 /// If you need exact expiry semantics, you should enforce them upon receipt of
4293 /// [`PaymentClaimable`].
4294 ///
4295 /// Note that invoices generated for inbound payments should have their `min_final_cltv_expiry_delta`
4296 /// set to at least [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
4297 ///
4298 /// Note that a malicious eavesdropper can intuit whether an inbound payment was created by
4299 /// `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
4300 ///
4301 /// # Note
4302 ///
4303 /// If you register an inbound payment with this method, then serialize the `ChannelManager`, then
4304 /// deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
4305 ///
4306 /// Errors if `min_value_msat` is greater than total bitcoin supply.
4307 ///
4308 /// If `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
4309 /// on versions of LDK prior to 0.0.114.
4310 ///
4311 /// [`create_inbound_payment`]: Self::create_inbound_payment
4312 /// [`PaymentClaimable`]: events::Event::PaymentClaimable
4313 #[must_use]
4314 #[no_mangle]
4315 pub extern "C" fn ChannelManager_create_inbound_payment_for_hash(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32, mut min_final_cltv_expiry: crate::c_types::derived::COption_u16Z) -> crate::c_types::derived::CResult_ThirtyTwoBytesNoneZ {
4316         let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
4317         let mut local_min_final_cltv_expiry = if min_final_cltv_expiry.is_some() { Some( { min_final_cltv_expiry.take() }) } else { None };
4318         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment_for_hash(::lightning::ln::types::PaymentHash(payment_hash.data), local_min_value_msat, invoice_expiry_delta_secs, local_min_final_cltv_expiry);
4319         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ThirtyTwoBytes { data: o.0 } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
4320         local_ret
4321 }
4322
4323 /// Gets an LDK-generated payment preimage from a payment hash and payment secret that were
4324 /// previously returned from [`create_inbound_payment`].
4325 ///
4326 /// [`create_inbound_payment`]: Self::create_inbound_payment
4327 #[must_use]
4328 #[no_mangle]
4329 pub extern "C" fn ChannelManager_get_payment_preimage(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut payment_secret: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_ThirtyTwoBytesAPIErrorZ {
4330         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_payment_preimage(::lightning::ln::types::PaymentHash(payment_hash.data), ::lightning::ln::types::PaymentSecret(payment_secret.data));
4331         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ThirtyTwoBytes { data: o.0 } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
4332         local_ret
4333 }
4334
4335 /// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
4336 /// are used when constructing the phantom invoice's route hints.
4337 ///
4338 /// [phantom node payments]: crate::sign::PhantomKeysManager
4339 #[must_use]
4340 #[no_mangle]
4341 pub extern "C" fn ChannelManager_get_phantom_scid(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> u64 {
4342         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_phantom_scid();
4343         ret
4344 }
4345
4346 /// Gets route hints for use in receiving [phantom node payments].
4347 ///
4348 /// [phantom node payments]: crate::sign::PhantomKeysManager
4349 #[must_use]
4350 #[no_mangle]
4351 pub extern "C" fn ChannelManager_get_phantom_route_hints(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::ln::channelmanager::PhantomRouteHints {
4352         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_phantom_route_hints();
4353         crate::lightning::ln::channelmanager::PhantomRouteHints { inner: ObjOps::heap_alloc(ret), is_owned: true }
4354 }
4355
4356 /// Gets a fake short channel id for use in receiving intercepted payments. These fake scids are
4357 /// used when constructing the route hints for HTLCs intended to be intercepted. See
4358 /// [`ChannelManager::forward_intercepted_htlc`].
4359 ///
4360 /// Note that this method is not guaranteed to return unique values, you may need to call it a few
4361 /// times to get a unique scid.
4362 #[must_use]
4363 #[no_mangle]
4364 pub extern "C" fn ChannelManager_get_intercept_scid(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> u64 {
4365         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_intercept_scid();
4366         ret
4367 }
4368
4369 /// Gets inflight HTLC information by processing pending outbound payments that are in
4370 /// our channels. May be used during pathfinding to account for in-use channel liquidity.
4371 #[must_use]
4372 #[no_mangle]
4373 pub extern "C" fn ChannelManager_compute_inflight_htlcs(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::routing::router::InFlightHtlcs {
4374         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.compute_inflight_htlcs();
4375         crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(ret), is_owned: true }
4376 }
4377
4378 impl From<nativeChannelManager> for crate::lightning::events::MessageSendEventsProvider {
4379         fn from(obj: nativeChannelManager) -> Self {
4380                 let rust_obj = crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
4381                 let mut ret = ChannelManager_as_MessageSendEventsProvider(&rust_obj);
4382                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
4383                 core::mem::forget(rust_obj);
4384                 ret.free = Some(ChannelManager_free_void);
4385                 ret
4386         }
4387 }
4388 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
4389 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
4390 #[no_mangle]
4391 pub extern "C" fn ChannelManager_as_MessageSendEventsProvider(this_arg: &ChannelManager) -> crate::lightning::events::MessageSendEventsProvider {
4392         crate::lightning::events::MessageSendEventsProvider {
4393                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
4394                 free: None,
4395                 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
4396         }
4397 }
4398
4399 #[must_use]
4400 extern "C" fn ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
4401         let mut ret = <nativeChannelManager as lightning::events::MessageSendEventsProvider>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
4402         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::events::MessageSendEvent::native_into(item) }); };
4403         local_ret.into()
4404 }
4405
4406 impl From<nativeChannelManager> for crate::lightning::events::EventsProvider {
4407         fn from(obj: nativeChannelManager) -> Self {
4408                 let rust_obj = crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
4409                 let mut ret = ChannelManager_as_EventsProvider(&rust_obj);
4410                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
4411                 core::mem::forget(rust_obj);
4412                 ret.free = Some(ChannelManager_free_void);
4413                 ret
4414         }
4415 }
4416 /// Constructs a new EventsProvider which calls the relevant methods on this_arg.
4417 /// This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
4418 #[no_mangle]
4419 pub extern "C" fn ChannelManager_as_EventsProvider(this_arg: &ChannelManager) -> crate::lightning::events::EventsProvider {
4420         crate::lightning::events::EventsProvider {
4421                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
4422                 free: None,
4423                 process_pending_events: ChannelManager_EventsProvider_process_pending_events,
4424         }
4425 }
4426
4427 extern "C" fn ChannelManager_EventsProvider_process_pending_events(this_arg: *const c_void, mut handler: crate::lightning::events::EventHandler) {
4428         <nativeChannelManager as lightning::events::EventsProvider>::process_pending_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, handler)
4429 }
4430
4431 impl From<nativeChannelManager> for crate::lightning::chain::Listen {
4432         fn from(obj: nativeChannelManager) -> Self {
4433                 let rust_obj = crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
4434                 let mut ret = ChannelManager_as_Listen(&rust_obj);
4435                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
4436                 core::mem::forget(rust_obj);
4437                 ret.free = Some(ChannelManager_free_void);
4438                 ret
4439         }
4440 }
4441 /// Constructs a new Listen which calls the relevant methods on this_arg.
4442 /// This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
4443 #[no_mangle]
4444 pub extern "C" fn ChannelManager_as_Listen(this_arg: &ChannelManager) -> crate::lightning::chain::Listen {
4445         crate::lightning::chain::Listen {
4446                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
4447                 free: None,
4448                 filtered_block_connected: ChannelManager_Listen_filtered_block_connected,
4449                 block_connected: ChannelManager_Listen_block_connected,
4450                 block_disconnected: ChannelManager_Listen_block_disconnected,
4451         }
4452 }
4453
4454 extern "C" fn ChannelManager_Listen_filtered_block_connected(this_arg: *const c_void, header: *const [u8; 80], mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, mut height: u32) {
4455         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 }); };
4456         <nativeChannelManager as lightning::chain::Listen>::filtered_block_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), &local_txdata.iter().map(|(a, b)| (*a, b)).collect::<Vec<_>>()[..], height)
4457 }
4458 extern "C" fn ChannelManager_Listen_block_connected(this_arg: *const c_void, mut block: crate::c_types::u8slice, mut height: u32) {
4459         <nativeChannelManager as lightning::chain::Listen>::block_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height)
4460 }
4461 extern "C" fn ChannelManager_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
4462         <nativeChannelManager as lightning::chain::Listen>::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
4463 }
4464
4465 impl From<nativeChannelManager> for crate::lightning::chain::Confirm {
4466         fn from(obj: nativeChannelManager) -> Self {
4467                 let rust_obj = crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
4468                 let mut ret = ChannelManager_as_Confirm(&rust_obj);
4469                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
4470                 core::mem::forget(rust_obj);
4471                 ret.free = Some(ChannelManager_free_void);
4472                 ret
4473         }
4474 }
4475 /// Constructs a new Confirm which calls the relevant methods on this_arg.
4476 /// This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
4477 #[no_mangle]
4478 pub extern "C" fn ChannelManager_as_Confirm(this_arg: &ChannelManager) -> crate::lightning::chain::Confirm {
4479         crate::lightning::chain::Confirm {
4480                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
4481                 free: None,
4482                 transactions_confirmed: ChannelManager_Confirm_transactions_confirmed,
4483                 transaction_unconfirmed: ChannelManager_Confirm_transaction_unconfirmed,
4484                 best_block_updated: ChannelManager_Confirm_best_block_updated,
4485                 get_relevant_txids: ChannelManager_Confirm_get_relevant_txids,
4486         }
4487 }
4488
4489 extern "C" fn ChannelManager_Confirm_transactions_confirmed(this_arg: *const c_void, header: *const [u8; 80], mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, mut height: u32) {
4490         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 }); };
4491         <nativeChannelManager as lightning::chain::Confirm>::transactions_confirmed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), &local_txdata.iter().map(|(a, b)| (*a, b)).collect::<Vec<_>>()[..], height)
4492 }
4493 extern "C" fn ChannelManager_Confirm_transaction_unconfirmed(this_arg: *const c_void, txid: *const [u8; 32]) {
4494         <nativeChannelManager as lightning::chain::Confirm>::transaction_unconfirmed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap())
4495 }
4496 extern "C" fn ChannelManager_Confirm_best_block_updated(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
4497         <nativeChannelManager as lightning::chain::Confirm>::best_block_updated(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
4498 }
4499 #[must_use]
4500 extern "C" fn ChannelManager_Confirm_get_relevant_txids(this_arg: *const c_void) -> crate::c_types::derived::CVec_C3Tuple_ThirtyTwoBytesu32COption_ThirtyTwoBytesZZZ {
4501         let mut ret = <nativeChannelManager as lightning::chain::Confirm>::get_relevant_txids(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
4502         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 }); };
4503         local_ret.into()
4504 }
4505
4506 /// Gets a [`Future`] that completes when this [`ChannelManager`] may need to be persisted or
4507 /// may have events that need processing.
4508 ///
4509 /// In order to check if this [`ChannelManager`] needs persisting, call
4510 /// [`Self::get_and_clear_needs_persistence`].
4511 ///
4512 /// Note that callbacks registered on the [`Future`] MUST NOT call back into this
4513 /// [`ChannelManager`] and should instead register actions to be taken later.
4514 #[must_use]
4515 #[no_mangle]
4516 pub extern "C" fn ChannelManager_get_event_or_persistence_needed_future(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::util::wakers::Future {
4517         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_event_or_persistence_needed_future();
4518         crate::lightning::util::wakers::Future { inner: ObjOps::heap_alloc(ret), is_owned: true }
4519 }
4520
4521 /// Returns true if this [`ChannelManager`] needs to be persisted.
4522 ///
4523 /// See [`Self::get_event_or_persistence_needed_future`] for retrieving a [`Future`] that
4524 /// indicates this should be checked.
4525 #[must_use]
4526 #[no_mangle]
4527 pub extern "C" fn ChannelManager_get_and_clear_needs_persistence(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> bool {
4528         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_and_clear_needs_persistence();
4529         ret
4530 }
4531
4532 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
4533 /// [`chain::Confirm`] interfaces.
4534 #[must_use]
4535 #[no_mangle]
4536 pub extern "C" fn ChannelManager_current_best_block(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::chain::BestBlock {
4537         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
4538         crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
4539 }
4540
4541 /// Fetches the set of [`NodeFeatures`] flags that are provided by or required by
4542 /// [`ChannelManager`].
4543 #[must_use]
4544 #[no_mangle]
4545 pub extern "C" fn ChannelManager_node_features(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::ln::features::NodeFeatures {
4546         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.node_features();
4547         crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
4548 }
4549
4550 /// Fetches the set of [`ChannelFeatures`] flags that are provided by or required by
4551 /// [`ChannelManager`].
4552 #[must_use]
4553 #[no_mangle]
4554 pub extern "C" fn ChannelManager_channel_features(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::ln::features::ChannelFeatures {
4555         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_features();
4556         crate::lightning::ln::features::ChannelFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
4557 }
4558
4559 /// Fetches the set of [`ChannelTypeFeatures`] flags that are provided by or required by
4560 /// [`ChannelManager`].
4561 #[must_use]
4562 #[no_mangle]
4563 pub extern "C" fn ChannelManager_channel_type_features(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::ln::features::ChannelTypeFeatures {
4564         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_type_features();
4565         crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
4566 }
4567
4568 /// Fetches the set of [`InitFeatures`] flags that are provided by or required by
4569 /// [`ChannelManager`].
4570 #[must_use]
4571 #[no_mangle]
4572 pub extern "C" fn ChannelManager_init_features(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::ln::features::InitFeatures {
4573         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.init_features();
4574         crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
4575 }
4576
4577 impl From<nativeChannelManager> for crate::lightning::ln::msgs::ChannelMessageHandler {
4578         fn from(obj: nativeChannelManager) -> Self {
4579                 let rust_obj = crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
4580                 let mut ret = ChannelManager_as_ChannelMessageHandler(&rust_obj);
4581                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
4582                 core::mem::forget(rust_obj);
4583                 ret.free = Some(ChannelManager_free_void);
4584                 ret
4585         }
4586 }
4587 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
4588 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
4589 #[no_mangle]
4590 pub extern "C" fn ChannelManager_as_ChannelMessageHandler(this_arg: &ChannelManager) -> crate::lightning::ln::msgs::ChannelMessageHandler {
4591         crate::lightning::ln::msgs::ChannelMessageHandler {
4592                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
4593                 free: None,
4594                 handle_open_channel: ChannelManager_ChannelMessageHandler_handle_open_channel,
4595                 handle_open_channel_v2: ChannelManager_ChannelMessageHandler_handle_open_channel_v2,
4596                 handle_accept_channel: ChannelManager_ChannelMessageHandler_handle_accept_channel,
4597                 handle_accept_channel_v2: ChannelManager_ChannelMessageHandler_handle_accept_channel_v2,
4598                 handle_funding_created: ChannelManager_ChannelMessageHandler_handle_funding_created,
4599                 handle_funding_signed: ChannelManager_ChannelMessageHandler_handle_funding_signed,
4600                 handle_channel_ready: ChannelManager_ChannelMessageHandler_handle_channel_ready,
4601                 handle_shutdown: ChannelManager_ChannelMessageHandler_handle_shutdown,
4602                 handle_closing_signed: ChannelManager_ChannelMessageHandler_handle_closing_signed,
4603                 handle_stfu: ChannelManager_ChannelMessageHandler_handle_stfu,
4604                 handle_tx_add_input: ChannelManager_ChannelMessageHandler_handle_tx_add_input,
4605                 handle_tx_add_output: ChannelManager_ChannelMessageHandler_handle_tx_add_output,
4606                 handle_tx_remove_input: ChannelManager_ChannelMessageHandler_handle_tx_remove_input,
4607                 handle_tx_remove_output: ChannelManager_ChannelMessageHandler_handle_tx_remove_output,
4608                 handle_tx_complete: ChannelManager_ChannelMessageHandler_handle_tx_complete,
4609                 handle_tx_signatures: ChannelManager_ChannelMessageHandler_handle_tx_signatures,
4610                 handle_tx_init_rbf: ChannelManager_ChannelMessageHandler_handle_tx_init_rbf,
4611                 handle_tx_ack_rbf: ChannelManager_ChannelMessageHandler_handle_tx_ack_rbf,
4612                 handle_tx_abort: ChannelManager_ChannelMessageHandler_handle_tx_abort,
4613                 handle_update_add_htlc: ChannelManager_ChannelMessageHandler_handle_update_add_htlc,
4614                 handle_update_fulfill_htlc: ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc,
4615                 handle_update_fail_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_htlc,
4616                 handle_update_fail_malformed_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_malformed_htlc,
4617                 handle_commitment_signed: ChannelManager_ChannelMessageHandler_handle_commitment_signed,
4618                 handle_revoke_and_ack: ChannelManager_ChannelMessageHandler_handle_revoke_and_ack,
4619                 handle_update_fee: ChannelManager_ChannelMessageHandler_handle_update_fee,
4620                 handle_announcement_signatures: ChannelManager_ChannelMessageHandler_handle_announcement_signatures,
4621                 peer_disconnected: ChannelManager_ChannelMessageHandler_peer_disconnected,
4622                 peer_connected: ChannelManager_ChannelMessageHandler_peer_connected,
4623                 handle_channel_reestablish: ChannelManager_ChannelMessageHandler_handle_channel_reestablish,
4624                 handle_channel_update: ChannelManager_ChannelMessageHandler_handle_channel_update,
4625                 handle_error: ChannelManager_ChannelMessageHandler_handle_error,
4626                 provided_node_features: ChannelManager_ChannelMessageHandler_provided_node_features,
4627                 provided_init_features: ChannelManager_ChannelMessageHandler_provided_init_features,
4628                 get_chain_hashes: ChannelManager_ChannelMessageHandler_get_chain_hashes,
4629                 MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider {
4630                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
4631                         free: None,
4632                         get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
4633                 },
4634         }
4635 }
4636
4637 extern "C" fn ChannelManager_ChannelMessageHandler_handle_open_channel(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::OpenChannel) {
4638         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_open_channel(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4639 }
4640 extern "C" fn ChannelManager_ChannelMessageHandler_handle_open_channel_v2(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::OpenChannelV2) {
4641         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_open_channel_v2(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4642 }
4643 extern "C" fn ChannelManager_ChannelMessageHandler_handle_accept_channel(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::AcceptChannel) {
4644         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_accept_channel(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4645 }
4646 extern "C" fn ChannelManager_ChannelMessageHandler_handle_accept_channel_v2(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::AcceptChannelV2) {
4647         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_accept_channel_v2(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4648 }
4649 extern "C" fn ChannelManager_ChannelMessageHandler_handle_funding_created(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::FundingCreated) {
4650         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_funding_created(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4651 }
4652 extern "C" fn ChannelManager_ChannelMessageHandler_handle_funding_signed(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::FundingSigned) {
4653         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_funding_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4654 }
4655 extern "C" fn ChannelManager_ChannelMessageHandler_handle_channel_ready(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ChannelReady) {
4656         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_channel_ready(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4657 }
4658 extern "C" fn ChannelManager_ChannelMessageHandler_handle_shutdown(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::Shutdown) {
4659         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_shutdown(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4660 }
4661 extern "C" fn ChannelManager_ChannelMessageHandler_handle_closing_signed(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ClosingSigned) {
4662         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_closing_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4663 }
4664 extern "C" fn ChannelManager_ChannelMessageHandler_handle_stfu(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::Stfu) {
4665         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_stfu(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4666 }
4667 extern "C" fn ChannelManager_ChannelMessageHandler_handle_tx_add_input(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxAddInput) {
4668         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_tx_add_input(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4669 }
4670 extern "C" fn ChannelManager_ChannelMessageHandler_handle_tx_add_output(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxAddOutput) {
4671         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_tx_add_output(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4672 }
4673 extern "C" fn ChannelManager_ChannelMessageHandler_handle_tx_remove_input(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxRemoveInput) {
4674         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_tx_remove_input(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4675 }
4676 extern "C" fn ChannelManager_ChannelMessageHandler_handle_tx_remove_output(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxRemoveOutput) {
4677         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_tx_remove_output(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4678 }
4679 extern "C" fn ChannelManager_ChannelMessageHandler_handle_tx_complete(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxComplete) {
4680         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_tx_complete(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4681 }
4682 extern "C" fn ChannelManager_ChannelMessageHandler_handle_tx_signatures(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxSignatures) {
4683         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_tx_signatures(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4684 }
4685 extern "C" fn ChannelManager_ChannelMessageHandler_handle_tx_init_rbf(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxInitRbf) {
4686         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_tx_init_rbf(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4687 }
4688 extern "C" fn ChannelManager_ChannelMessageHandler_handle_tx_ack_rbf(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxAckRbf) {
4689         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_tx_ack_rbf(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4690 }
4691 extern "C" fn ChannelManager_ChannelMessageHandler_handle_tx_abort(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxAbort) {
4692         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_tx_abort(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4693 }
4694 extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_add_htlc(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateAddHTLC) {
4695         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_update_add_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4696 }
4697 extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateFulfillHTLC) {
4698         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_update_fulfill_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4699 }
4700 extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_fail_htlc(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateFailHTLC) {
4701         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_update_fail_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4702 }
4703 extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_fail_malformed_htlc(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateFailMalformedHTLC) {
4704         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_update_fail_malformed_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4705 }
4706 extern "C" fn ChannelManager_ChannelMessageHandler_handle_commitment_signed(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::CommitmentSigned) {
4707         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_commitment_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4708 }
4709 extern "C" fn ChannelManager_ChannelMessageHandler_handle_revoke_and_ack(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::RevokeAndACK) {
4710         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_revoke_and_ack(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4711 }
4712 extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_fee(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateFee) {
4713         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_update_fee(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4714 }
4715 extern "C" fn ChannelManager_ChannelMessageHandler_handle_announcement_signatures(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::AnnouncementSignatures) {
4716         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_announcement_signatures(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4717 }
4718 extern "C" fn ChannelManager_ChannelMessageHandler_peer_disconnected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) {
4719         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust())
4720 }
4721 #[must_use]
4722 extern "C" fn ChannelManager_ChannelMessageHandler_peer_connected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::Init, mut inbound: bool) -> crate::c_types::derived::CResult_NoneNoneZ {
4723         let mut ret = <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::peer_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref(), inbound);
4724         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() };
4725         local_ret
4726 }
4727 extern "C" fn ChannelManager_ChannelMessageHandler_handle_channel_reestablish(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ChannelReestablish) {
4728         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_channel_reestablish(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4729 }
4730 extern "C" fn ChannelManager_ChannelMessageHandler_handle_channel_update(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ChannelUpdate) {
4731         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4732 }
4733 extern "C" fn ChannelManager_ChannelMessageHandler_handle_error(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ErrorMessage) {
4734         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::handle_error(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4735 }
4736 #[must_use]
4737 extern "C" fn ChannelManager_ChannelMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
4738         let mut ret = <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
4739         crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
4740 }
4741 #[must_use]
4742 extern "C" fn ChannelManager_ChannelMessageHandler_provided_init_features(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures {
4743         let mut ret = <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust());
4744         crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
4745 }
4746 #[must_use]
4747 extern "C" fn ChannelManager_ChannelMessageHandler_get_chain_hashes(this_arg: *const c_void) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ {
4748         let mut ret = <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler>::get_chain_hashes(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
4749         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::None } else { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::Some( { let mut local_ret_0 = Vec::new(); for mut item in ret.unwrap().drain(..) { local_ret_0.push( { crate::c_types::ThirtyTwoBytes { data: *item.as_ref() } }); }; local_ret_0.into() }) };
4750         local_ret
4751 }
4752
4753 impl From<nativeChannelManager> for crate::lightning::onion_message::offers::OffersMessageHandler {
4754         fn from(obj: nativeChannelManager) -> Self {
4755                 let rust_obj = crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
4756                 let mut ret = ChannelManager_as_OffersMessageHandler(&rust_obj);
4757                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
4758                 core::mem::forget(rust_obj);
4759                 ret.free = Some(ChannelManager_free_void);
4760                 ret
4761         }
4762 }
4763 /// Constructs a new OffersMessageHandler which calls the relevant methods on this_arg.
4764 /// This copies the `inner` pointer in this_arg and thus the returned OffersMessageHandler must be freed before this_arg is
4765 #[no_mangle]
4766 pub extern "C" fn ChannelManager_as_OffersMessageHandler(this_arg: &ChannelManager) -> crate::lightning::onion_message::offers::OffersMessageHandler {
4767         crate::lightning::onion_message::offers::OffersMessageHandler {
4768                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
4769                 free: None,
4770                 handle_message: ChannelManager_OffersMessageHandler_handle_message,
4771                 release_pending_messages: ChannelManager_OffersMessageHandler_release_pending_messages,
4772         }
4773 }
4774
4775 #[must_use]
4776 extern "C" fn ChannelManager_OffersMessageHandler_handle_message(this_arg: *const c_void, mut message: crate::lightning::onion_message::offers::OffersMessage) -> crate::c_types::derived::COption_OffersMessageZ {
4777         let mut ret = <nativeChannelManager as lightning::onion_message::offers::OffersMessageHandler>::handle_message(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, message.into_native());
4778         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_OffersMessageZ::None } else { crate::c_types::derived::COption_OffersMessageZ::Some( { crate::lightning::onion_message::offers::OffersMessage::native_into(ret.unwrap()) }) };
4779         local_ret
4780 }
4781 #[must_use]
4782 extern "C" fn ChannelManager_OffersMessageHandler_release_pending_messages(this_arg: *const c_void) -> crate::c_types::derived::CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ {
4783         let mut ret = <nativeChannelManager as lightning::onion_message::offers::OffersMessageHandler>::release_pending_messages(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
4784         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 = crate::lightning::blinded_path::BlindedPath { inner: if orig_ret_0_2.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((orig_ret_0_2.unwrap())) } }, is_owned: true }; let mut local_ret_0 = (crate::lightning::onion_message::offers::OffersMessage::native_into(orig_ret_0_0), crate::lightning::onion_message::messenger::Destination::native_into(orig_ret_0_1), local_orig_ret_0_2).into(); local_ret_0 }); };
4785         local_ret.into()
4786 }
4787
4788 impl From<nativeChannelManager> for crate::lightning::blinded_path::NodeIdLookUp {
4789         fn from(obj: nativeChannelManager) -> Self {
4790                 let rust_obj = crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
4791                 let mut ret = ChannelManager_as_NodeIdLookUp(&rust_obj);
4792                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
4793                 core::mem::forget(rust_obj);
4794                 ret.free = Some(ChannelManager_free_void);
4795                 ret
4796         }
4797 }
4798 /// Constructs a new NodeIdLookUp which calls the relevant methods on this_arg.
4799 /// This copies the `inner` pointer in this_arg and thus the returned NodeIdLookUp must be freed before this_arg is
4800 #[no_mangle]
4801 pub extern "C" fn ChannelManager_as_NodeIdLookUp(this_arg: &ChannelManager) -> crate::lightning::blinded_path::NodeIdLookUp {
4802         crate::lightning::blinded_path::NodeIdLookUp {
4803                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
4804                 free: None,
4805                 next_node_id: ChannelManager_NodeIdLookUp_next_node_id,
4806         }
4807 }
4808
4809 #[must_use]
4810 extern "C" fn ChannelManager_NodeIdLookUp_next_node_id(this_arg: *const c_void, mut short_channel_id: u64) -> crate::c_types::PublicKey {
4811         let mut ret = <nativeChannelManager as lightning::blinded_path::NodeIdLookUp>::next_node_id(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, short_channel_id);
4812         let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else {  { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
4813         local_ret
4814 }
4815
4816 /// Fetches the set of [`InitFeatures`] flags that are provided by or required by
4817 /// [`ChannelManager`].
4818 #[no_mangle]
4819 pub extern "C" fn provided_init_features(config: &crate::lightning::util::config::UserConfig) -> crate::lightning::ln::features::InitFeatures {
4820         let mut ret = lightning::ln::channelmanager::provided_init_features(config.get_native_ref());
4821         crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
4822 }
4823
4824 #[no_mangle]
4825 /// Serialize the CounterpartyForwardingInfo object into a byte array which can be read by CounterpartyForwardingInfo_read
4826 pub extern "C" fn CounterpartyForwardingInfo_write(obj: &crate::lightning::ln::channelmanager::CounterpartyForwardingInfo) -> crate::c_types::derived::CVec_u8Z {
4827         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
4828 }
4829 #[allow(unused)]
4830 pub(crate) extern "C" fn CounterpartyForwardingInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
4831         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCounterpartyForwardingInfo) })
4832 }
4833 #[no_mangle]
4834 /// Read a CounterpartyForwardingInfo from a byte array, created by CounterpartyForwardingInfo_write
4835 pub extern "C" fn CounterpartyForwardingInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CounterpartyForwardingInfoDecodeErrorZ {
4836         let res: Result<lightning::ln::channelmanager::CounterpartyForwardingInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
4837         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channelmanager::CounterpartyForwardingInfo { 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() };
4838         local_res
4839 }
4840 #[no_mangle]
4841 /// Serialize the ChannelCounterparty object into a byte array which can be read by ChannelCounterparty_read
4842 pub extern "C" fn ChannelCounterparty_write(obj: &crate::lightning::ln::channelmanager::ChannelCounterparty) -> crate::c_types::derived::CVec_u8Z {
4843         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
4844 }
4845 #[allow(unused)]
4846 pub(crate) extern "C" fn ChannelCounterparty_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
4847         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelCounterparty) })
4848 }
4849 #[no_mangle]
4850 /// Read a ChannelCounterparty from a byte array, created by ChannelCounterparty_write
4851 pub extern "C" fn ChannelCounterparty_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelCounterpartyDecodeErrorZ {
4852         let res: Result<lightning::ln::channelmanager::ChannelCounterparty, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
4853         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channelmanager::ChannelCounterparty { 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() };
4854         local_res
4855 }
4856 #[no_mangle]
4857 /// Serialize the ChannelDetails object into a byte array which can be read by ChannelDetails_read
4858 pub extern "C" fn ChannelDetails_write(obj: &crate::lightning::ln::channelmanager::ChannelDetails) -> crate::c_types::derived::CVec_u8Z {
4859         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
4860 }
4861 #[allow(unused)]
4862 pub(crate) extern "C" fn ChannelDetails_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
4863         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelDetails) })
4864 }
4865 #[no_mangle]
4866 /// Read a ChannelDetails from a byte array, created by ChannelDetails_write
4867 pub extern "C" fn ChannelDetails_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelDetailsDecodeErrorZ {
4868         let res: Result<lightning::ln::channelmanager::ChannelDetails, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
4869         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channelmanager::ChannelDetails { 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() };
4870         local_res
4871 }
4872 #[no_mangle]
4873 /// Serialize the PhantomRouteHints object into a byte array which can be read by PhantomRouteHints_read
4874 pub extern "C" fn PhantomRouteHints_write(obj: &crate::lightning::ln::channelmanager::PhantomRouteHints) -> crate::c_types::derived::CVec_u8Z {
4875         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
4876 }
4877 #[allow(unused)]
4878 pub(crate) extern "C" fn PhantomRouteHints_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
4879         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePhantomRouteHints) })
4880 }
4881 #[no_mangle]
4882 /// Read a PhantomRouteHints from a byte array, created by PhantomRouteHints_write
4883 pub extern "C" fn PhantomRouteHints_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PhantomRouteHintsDecodeErrorZ {
4884         let res: Result<lightning::ln::channelmanager::PhantomRouteHints, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
4885         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channelmanager::PhantomRouteHints { 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() };
4886         local_res
4887 }
4888 #[no_mangle]
4889 /// Serialize the BlindedForward object into a byte array which can be read by BlindedForward_read
4890 pub extern "C" fn BlindedForward_write(obj: &crate::lightning::ln::channelmanager::BlindedForward) -> crate::c_types::derived::CVec_u8Z {
4891         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
4892 }
4893 #[allow(unused)]
4894 pub(crate) extern "C" fn BlindedForward_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
4895         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBlindedForward) })
4896 }
4897 #[no_mangle]
4898 /// Read a BlindedForward from a byte array, created by BlindedForward_write
4899 pub extern "C" fn BlindedForward_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BlindedForwardDecodeErrorZ {
4900         let res: Result<lightning::ln::channelmanager::BlindedForward, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
4901         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channelmanager::BlindedForward { 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() };
4902         local_res
4903 }
4904 #[no_mangle]
4905 /// Serialize the PendingHTLCRouting object into a byte array which can be read by PendingHTLCRouting_read
4906 pub extern "C" fn PendingHTLCRouting_write(obj: &crate::lightning::ln::channelmanager::PendingHTLCRouting) -> crate::c_types::derived::CVec_u8Z {
4907         crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
4908 }
4909 #[allow(unused)]
4910 pub(crate) extern "C" fn PendingHTLCRouting_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
4911         PendingHTLCRouting_write(unsafe { &*(obj as *const PendingHTLCRouting) })
4912 }
4913 #[no_mangle]
4914 /// Read a PendingHTLCRouting from a byte array, created by PendingHTLCRouting_write
4915 pub extern "C" fn PendingHTLCRouting_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PendingHTLCRoutingDecodeErrorZ {
4916         let res: Result<lightning::ln::channelmanager::PendingHTLCRouting, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
4917         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channelmanager::PendingHTLCRouting::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
4918         local_res
4919 }
4920 #[no_mangle]
4921 /// Serialize the PendingHTLCInfo object into a byte array which can be read by PendingHTLCInfo_read
4922 pub extern "C" fn PendingHTLCInfo_write(obj: &crate::lightning::ln::channelmanager::PendingHTLCInfo) -> crate::c_types::derived::CVec_u8Z {
4923         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
4924 }
4925 #[allow(unused)]
4926 pub(crate) extern "C" fn PendingHTLCInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
4927         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePendingHTLCInfo) })
4928 }
4929 #[no_mangle]
4930 /// Read a PendingHTLCInfo from a byte array, created by PendingHTLCInfo_write
4931 pub extern "C" fn PendingHTLCInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PendingHTLCInfoDecodeErrorZ {
4932         let res: Result<lightning::ln::channelmanager::PendingHTLCInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
4933         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channelmanager::PendingHTLCInfo { 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() };
4934         local_res
4935 }
4936 #[no_mangle]
4937 /// Serialize the BlindedFailure object into a byte array which can be read by BlindedFailure_read
4938 pub extern "C" fn BlindedFailure_write(obj: &crate::lightning::ln::channelmanager::BlindedFailure) -> crate::c_types::derived::CVec_u8Z {
4939         crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
4940 }
4941 #[allow(unused)]
4942 pub(crate) extern "C" fn BlindedFailure_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
4943         BlindedFailure_write(unsafe { &*(obj as *const BlindedFailure) })
4944 }
4945 #[no_mangle]
4946 /// Read a BlindedFailure from a byte array, created by BlindedFailure_write
4947 pub extern "C" fn BlindedFailure_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BlindedFailureDecodeErrorZ {
4948         let res: Result<lightning::ln::channelmanager::BlindedFailure, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
4949         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channelmanager::BlindedFailure::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
4950         local_res
4951 }
4952 #[no_mangle]
4953 /// Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
4954 pub extern "C" fn ChannelManager_write(obj: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_u8Z {
4955         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
4956 }
4957 #[allow(unused)]
4958 pub(crate) extern "C" fn ChannelManager_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
4959         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelManager) })
4960 }
4961 #[no_mangle]
4962 /// Serialize the ChannelShutdownState object into a byte array which can be read by ChannelShutdownState_read
4963 pub extern "C" fn ChannelShutdownState_write(obj: &crate::lightning::ln::channelmanager::ChannelShutdownState) -> crate::c_types::derived::CVec_u8Z {
4964         crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
4965 }
4966 #[allow(unused)]
4967 pub(crate) extern "C" fn ChannelShutdownState_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
4968         ChannelShutdownState_write(unsafe { &*(obj as *const ChannelShutdownState) })
4969 }
4970 #[no_mangle]
4971 /// Read a ChannelShutdownState from a byte array, created by ChannelShutdownState_write
4972 pub extern "C" fn ChannelShutdownState_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelShutdownStateDecodeErrorZ {
4973         let res: Result<lightning::ln::channelmanager::ChannelShutdownState, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
4974         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channelmanager::ChannelShutdownState::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
4975         local_res
4976 }
4977
4978 use lightning::ln::channelmanager::ChannelManagerReadArgs as nativeChannelManagerReadArgsImport;
4979 pub(crate) type nativeChannelManagerReadArgs = nativeChannelManagerReadArgsImport<'static, crate::lightning::chain::Watch, crate::lightning::chain::chaininterface::BroadcasterInterface, crate::lightning::sign::EntropySource, crate::lightning::sign::NodeSigner, crate::lightning::sign::SignerProvider, crate::lightning::chain::chaininterface::FeeEstimator, crate::lightning::routing::router::Router, crate::lightning::util::logger::Logger, >;
4980
4981 /// Arguments for the creation of a ChannelManager that are not deserialized.
4982 ///
4983 /// At a high-level, the process for deserializing a ChannelManager and resuming normal operation
4984 /// is:
4985 /// 1) Deserialize all stored [`ChannelMonitor`]s.
4986 /// 2) Deserialize the [`ChannelManager`] by filling in this struct and calling:
4987 ///    `<(BlockHash, ChannelManager)>::read(reader, args)`
4988 ///    This may result in closing some channels if the [`ChannelMonitor`] is newer than the stored
4989 ///    [`ChannelManager`] state to ensure no loss of funds. Thus, transactions may be broadcasted.
4990 /// 3) If you are not fetching full blocks, register all relevant [`ChannelMonitor`] outpoints the
4991 ///    same way you would handle a [`chain::Filter`] call using
4992 ///    [`ChannelMonitor::get_outputs_to_watch`] and [`ChannelMonitor::get_funding_txo`].
4993 /// 4) Reconnect blocks on your [`ChannelMonitor`]s.
4994 /// 5) Disconnect/connect blocks on the [`ChannelManager`].
4995 /// 6) Re-persist the [`ChannelMonitor`]s to ensure the latest state is on disk.
4996 ///    Note that if you're using a [`ChainMonitor`] for your [`chain::Watch`] implementation, you
4997 ///    will likely accomplish this as a side-effect of calling [`chain::Watch::watch_channel`] in
4998 ///    the next step.
4999 /// 7) Move the [`ChannelMonitor`]s into your local [`chain::Watch`]. If you're using a
5000 ///    [`ChainMonitor`], this is done by calling [`chain::Watch::watch_channel`].
5001 ///
5002 /// Note that the ordering of #4-7 is not of importance, however all four must occur before you
5003 /// call any other methods on the newly-deserialized [`ChannelManager`].
5004 ///
5005 /// Note that because some channels may be closed during deserialization, it is critical that you
5006 /// always deserialize only the latest version of a ChannelManager and ChannelMonitors available to
5007 /// you. If you deserialize an old ChannelManager (during which force-closure transactions may be
5008 /// broadcast), and then later deserialize a newer version of the same ChannelManager (which will
5009 /// not force-close the same channels but consider them live), you may end up revoking a state for
5010 /// which you've already broadcasted the transaction.
5011 ///
5012 /// [`ChainMonitor`]: crate::chain::chainmonitor::ChainMonitor
5013 #[must_use]
5014 #[repr(C)]
5015 pub struct ChannelManagerReadArgs {
5016         /// A pointer to the opaque Rust object.
5017
5018         /// Nearly everywhere, inner must be non-null, however in places where
5019         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
5020         pub inner: *mut nativeChannelManagerReadArgs,
5021         /// Indicates that this is the only struct which contains the same pointer.
5022
5023         /// Rust functions which take ownership of an object provided via an argument require
5024         /// this to be true and invalidate the object pointed to by inner.
5025         pub is_owned: bool,
5026 }
5027
5028 impl Drop for ChannelManagerReadArgs {
5029         fn drop(&mut self) {
5030                 if self.is_owned && !<*mut nativeChannelManagerReadArgs>::is_null(self.inner) {
5031                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
5032                 }
5033         }
5034 }
5035 /// Frees any resources used by the ChannelManagerReadArgs, if is_owned is set and inner is non-NULL.
5036 #[no_mangle]
5037 pub extern "C" fn ChannelManagerReadArgs_free(this_obj: ChannelManagerReadArgs) { }
5038 #[allow(unused)]
5039 /// Used only if an object of this type is returned as a trait impl by a method
5040 pub(crate) extern "C" fn ChannelManagerReadArgs_free_void(this_ptr: *mut c_void) {
5041         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelManagerReadArgs) };
5042 }
5043 #[allow(unused)]
5044 impl ChannelManagerReadArgs {
5045         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManagerReadArgs {
5046                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
5047         }
5048         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManagerReadArgs {
5049                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
5050         }
5051         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
5052         pub(crate) fn take_inner(mut self) -> *mut nativeChannelManagerReadArgs {
5053                 assert!(self.is_owned);
5054                 let ret = ObjOps::untweak_ptr(self.inner);
5055                 self.inner = core::ptr::null_mut();
5056                 ret
5057         }
5058 }
5059 /// A cryptographically secure source of entropy.
5060 #[no_mangle]
5061 pub extern "C" fn ChannelManagerReadArgs_get_entropy_source(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::sign::EntropySource {
5062         let mut inner_val = &mut this_ptr.get_native_mut_ref().entropy_source;
5063         inner_val
5064 }
5065 /// A cryptographically secure source of entropy.
5066 #[no_mangle]
5067 pub extern "C" fn ChannelManagerReadArgs_set_entropy_source(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::sign::EntropySource) {
5068         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.entropy_source = val;
5069 }
5070 /// A signer that is able to perform node-scoped cryptographic operations.
5071 #[no_mangle]
5072 pub extern "C" fn ChannelManagerReadArgs_get_node_signer(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::sign::NodeSigner {
5073         let mut inner_val = &mut this_ptr.get_native_mut_ref().node_signer;
5074         inner_val
5075 }
5076 /// A signer that is able to perform node-scoped cryptographic operations.
5077 #[no_mangle]
5078 pub extern "C" fn ChannelManagerReadArgs_set_node_signer(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::sign::NodeSigner) {
5079         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_signer = val;
5080 }
5081 /// The keys provider which will give us relevant keys. Some keys will be loaded during
5082 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
5083 /// signing data.
5084 #[no_mangle]
5085 pub extern "C" fn ChannelManagerReadArgs_get_signer_provider(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::sign::SignerProvider {
5086         let mut inner_val = &mut this_ptr.get_native_mut_ref().signer_provider;
5087         inner_val
5088 }
5089 /// The keys provider which will give us relevant keys. Some keys will be loaded during
5090 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
5091 /// signing data.
5092 #[no_mangle]
5093 pub extern "C" fn ChannelManagerReadArgs_set_signer_provider(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::sign::SignerProvider) {
5094         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.signer_provider = val;
5095 }
5096 /// The fee_estimator for use in the ChannelManager in the future.
5097 ///
5098 /// No calls to the FeeEstimator will be made during deserialization.
5099 #[no_mangle]
5100 pub extern "C" fn ChannelManagerReadArgs_get_fee_estimator(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::FeeEstimator {
5101         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_estimator;
5102         inner_val
5103 }
5104 /// The fee_estimator for use in the ChannelManager in the future.
5105 ///
5106 /// No calls to the FeeEstimator will be made during deserialization.
5107 #[no_mangle]
5108 pub extern "C" fn ChannelManagerReadArgs_set_fee_estimator(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::FeeEstimator) {
5109         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_estimator = val;
5110 }
5111 /// The chain::Watch for use in the ChannelManager in the future.
5112 ///
5113 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
5114 /// you have deserialized ChannelMonitors separately and will add them to your
5115 /// chain::Watch after deserializing this ChannelManager.
5116 #[no_mangle]
5117 pub extern "C" fn ChannelManagerReadArgs_get_chain_monitor(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::Watch {
5118         let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_monitor;
5119         inner_val
5120 }
5121 /// The chain::Watch for use in the ChannelManager in the future.
5122 ///
5123 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
5124 /// you have deserialized ChannelMonitors separately and will add them to your
5125 /// chain::Watch after deserializing this ChannelManager.
5126 #[no_mangle]
5127 pub extern "C" fn ChannelManagerReadArgs_set_chain_monitor(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::Watch) {
5128         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_monitor = val;
5129 }
5130 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
5131 /// used to broadcast the latest local commitment transactions of channels which must be
5132 /// force-closed during deserialization.
5133 #[no_mangle]
5134 pub extern "C" fn ChannelManagerReadArgs_get_tx_broadcaster(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::BroadcasterInterface {
5135         let mut inner_val = &mut this_ptr.get_native_mut_ref().tx_broadcaster;
5136         inner_val
5137 }
5138 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
5139 /// used to broadcast the latest local commitment transactions of channels which must be
5140 /// force-closed during deserialization.
5141 #[no_mangle]
5142 pub extern "C" fn ChannelManagerReadArgs_set_tx_broadcaster(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::BroadcasterInterface) {
5143         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.tx_broadcaster = val;
5144 }
5145 /// The router which will be used in the ChannelManager in the future for finding routes
5146 /// on-the-fly for trampoline payments. Absent in private nodes that don't support forwarding.
5147 ///
5148 /// No calls to the router will be made during deserialization.
5149 #[no_mangle]
5150 pub extern "C" fn ChannelManagerReadArgs_get_router(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::routing::router::Router {
5151         let mut inner_val = &mut this_ptr.get_native_mut_ref().router;
5152         inner_val
5153 }
5154 /// The router which will be used in the ChannelManager in the future for finding routes
5155 /// on-the-fly for trampoline payments. Absent in private nodes that don't support forwarding.
5156 ///
5157 /// No calls to the router will be made during deserialization.
5158 #[no_mangle]
5159 pub extern "C" fn ChannelManagerReadArgs_set_router(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::routing::router::Router) {
5160         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.router = val;
5161 }
5162 /// The Logger for use in the ChannelManager and which may be used to log information during
5163 /// deserialization.
5164 #[no_mangle]
5165 pub extern "C" fn ChannelManagerReadArgs_get_logger(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::util::logger::Logger {
5166         let mut inner_val = &mut this_ptr.get_native_mut_ref().logger;
5167         inner_val
5168 }
5169 /// The Logger for use in the ChannelManager and which may be used to log information during
5170 /// deserialization.
5171 #[no_mangle]
5172 pub extern "C" fn ChannelManagerReadArgs_set_logger(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::logger::Logger) {
5173         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.logger = val;
5174 }
5175 /// Default settings used for new channels. Any existing channels will continue to use the
5176 /// runtime settings which were stored when the ChannelManager was serialized.
5177 #[no_mangle]
5178 pub extern "C" fn ChannelManagerReadArgs_get_default_config(this_ptr: &ChannelManagerReadArgs) -> crate::lightning::util::config::UserConfig {
5179         let mut inner_val = &mut this_ptr.get_native_mut_ref().default_config;
5180         crate::lightning::util::config::UserConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::util::config::UserConfig<>) as *mut _) }, is_owned: false }
5181 }
5182 /// Default settings used for new channels. Any existing channels will continue to use the
5183 /// runtime settings which were stored when the ChannelManager was serialized.
5184 #[no_mangle]
5185 pub extern "C" fn ChannelManagerReadArgs_set_default_config(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::config::UserConfig) {
5186         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.default_config = *unsafe { Box::from_raw(val.take_inner()) };
5187 }
5188 /// Simple utility function to create a ChannelManagerReadArgs which creates the monitor
5189 /// HashMap for you. This is primarily useful for C bindings where it is not practical to
5190 /// populate a HashMap directly from C.
5191 #[must_use]
5192 #[no_mangle]
5193 pub extern "C" fn ChannelManagerReadArgs_new(mut entropy_source: crate::lightning::sign::EntropySource, mut node_signer: crate::lightning::sign::NodeSigner, mut signer_provider: crate::lightning::sign::SignerProvider, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, mut chain_monitor: crate::lightning::chain::Watch, mut tx_broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut router: crate::lightning::routing::router::Router, mut logger: crate::lightning::util::logger::Logger, mut default_config: crate::lightning::util::config::UserConfig, mut channel_monitors: crate::c_types::derived::CVec_ChannelMonitorZ) -> crate::lightning::ln::channelmanager::ChannelManagerReadArgs {
5194         let mut local_channel_monitors = Vec::new(); for mut item in channel_monitors.into_rust().drain(..) { local_channel_monitors.push( { item.get_native_mut_ref() }); };
5195         let mut ret = lightning::ln::channelmanager::ChannelManagerReadArgs::new(entropy_source, node_signer, signer_provider, fee_estimator, chain_monitor, tx_broadcaster, router, logger, *unsafe { Box::from_raw(default_config.take_inner()) }, local_channel_monitors);
5196         crate::lightning::ln::channelmanager::ChannelManagerReadArgs { inner: ObjOps::heap_alloc(ret), is_owned: true }
5197 }
5198
5199 #[no_mangle]
5200 /// Read a C2Tuple_ThirtyTwoBytesChannelManagerZ from a byte array, created by C2Tuple_ThirtyTwoBytesChannelManagerZ_write
5201 pub extern "C" fn C2Tuple_ThirtyTwoBytesChannelManagerZ_read(ser: crate::c_types::u8slice, arg: crate::lightning::ln::channelmanager::ChannelManagerReadArgs) -> crate::c_types::derived::CResult_C2Tuple_ThirtyTwoBytesChannelManagerZDecodeErrorZ {
5202         let arg_conv = *unsafe { Box::from_raw(arg.take_inner()) };
5203         let res: Result<(bitcoin::hash_types::BlockHash, lightning::ln::channelmanager::ChannelManager<crate::lightning::chain::Watch, crate::lightning::chain::chaininterface::BroadcasterInterface, crate::lightning::sign::EntropySource, crate::lightning::sign::NodeSigner, crate::lightning::sign::SignerProvider, crate::lightning::chain::chaininterface::FeeEstimator, crate::lightning::routing::router::Router, crate::lightning::util::logger::Logger>), lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
5204         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::ln::channelmanager::ChannelManager { 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() };
5205         local_res
5206 }