1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! The top-level channel management and payment tracking stuff lives here.
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).
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).
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};
28 /// Information about where a received HTLC('s onion) has indicated the HTLC should go.
32 pub enum PendingHTLCRouting {
33 /// An HTLC which should be forwarded on to another node.
35 /// The onion which should be included in the forwarded HTLC, telling the next hop what to
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.
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.
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,
49 /// The onion indicates that this is a payment for an invoice (supposedly) generated by us.
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.
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.
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 /// CLTV expiry of the received HTLC.
66 /// Used to track when we should expire pending HTLCs that go unclaimed.
67 incoming_cltv_expiry: u32,
68 /// If the onion had forwarding instructions to one of our phantom node SCIDs, this will
69 /// provide the onion shared secret used to decrypt the next level of forwarding
72 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
73 phantom_shared_secret: crate::c_types::ThirtyTwoBytes,
74 /// Custom TLVs which were set by the sender.
76 /// For HTLCs received by LDK, this will ultimately be exposed in
77 /// [`Event::PaymentClaimable::onion_fields`] as
78 /// [`RecipientOnionFields::custom_tlvs`].
79 custom_tlvs: crate::c_types::derived::CVec_C2Tuple_u64CVec_u8ZZZ,
80 /// Set if this HTLC is the final hop in a multi-hop blinded path.
81 requires_blinded_error: bool,
83 /// The onion indicates that this is for payment to us but which contains the preimage for
84 /// claiming included, and is unrelated to any invoice we'd previously generated (aka a
85 /// \"keysend\" or \"spontaneous\" payment).
87 /// Information about the amount the sender intended to pay and possibly a token to
88 /// associate MPP parts of a larger payment.
90 /// This will only be filled in if receiving MPP keysend payments is enabled, and it being
91 /// present will cause deserialization to fail on versions of LDK prior to 0.0.116.
93 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
94 payment_data: crate::lightning::ln::msgs::FinalOnionHopData,
95 /// Preimage for this onion payment. This preimage is provided by the sender and will be
96 /// used to settle the spontaneous payment.
97 payment_preimage: crate::c_types::ThirtyTwoBytes,
98 /// Additional data which we (allegedly) instructed the sender to include in the onion.
100 /// For HTLCs received by LDK, this will ultimately bubble back up as
101 /// [`RecipientOnionFields::payment_metadata`].
102 payment_metadata: crate::c_types::derived::COption_CVec_u8ZZ,
103 /// CLTV expiry of the received HTLC.
105 /// Used to track when we should expire pending HTLCs that go unclaimed.
106 incoming_cltv_expiry: u32,
107 /// Custom TLVs which were set by the sender.
109 /// For HTLCs received by LDK, these will ultimately bubble back up as
110 /// [`RecipientOnionFields::custom_tlvs`].
111 custom_tlvs: crate::c_types::derived::CVec_C2Tuple_u64CVec_u8ZZZ,
114 use lightning::ln::channelmanager::PendingHTLCRouting as PendingHTLCRoutingImport;
115 pub(crate) type nativePendingHTLCRouting = PendingHTLCRoutingImport;
117 impl PendingHTLCRouting {
119 pub(crate) fn to_native(&self) -> nativePendingHTLCRouting {
121 PendingHTLCRouting::Forward {ref onion_packet, ref short_channel_id, ref blinded, } => {
122 let mut onion_packet_nonref = Clone::clone(onion_packet);
123 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
124 let mut blinded_nonref = Clone::clone(blinded);
125 let mut local_blinded_nonref = if blinded_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(blinded_nonref.take_inner()) } }) };
126 nativePendingHTLCRouting::Forward {
127 onion_packet: *unsafe { Box::from_raw(onion_packet_nonref.take_inner()) },
128 short_channel_id: short_channel_id_nonref,
129 blinded: local_blinded_nonref,
132 PendingHTLCRouting::Receive {ref payment_data, ref payment_metadata, ref incoming_cltv_expiry, ref phantom_shared_secret, ref custom_tlvs, ref requires_blinded_error, } => {
133 let mut payment_data_nonref = Clone::clone(payment_data);
134 let mut payment_metadata_nonref = Clone::clone(payment_metadata);
135 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 }})} };
136 let mut incoming_cltv_expiry_nonref = Clone::clone(incoming_cltv_expiry);
137 let mut phantom_shared_secret_nonref = Clone::clone(phantom_shared_secret);
138 let mut local_phantom_shared_secret_nonref = if phantom_shared_secret_nonref.data == [0; 32] { None } else { Some( { phantom_shared_secret_nonref.data }) };
139 let mut custom_tlvs_nonref = Clone::clone(custom_tlvs);
140 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 }); };
141 let mut requires_blinded_error_nonref = Clone::clone(requires_blinded_error);
142 nativePendingHTLCRouting::Receive {
143 payment_data: *unsafe { Box::from_raw(payment_data_nonref.take_inner()) },
144 payment_metadata: local_payment_metadata_nonref,
145 incoming_cltv_expiry: incoming_cltv_expiry_nonref,
146 phantom_shared_secret: local_phantom_shared_secret_nonref,
147 custom_tlvs: local_custom_tlvs_nonref,
148 requires_blinded_error: requires_blinded_error_nonref,
151 PendingHTLCRouting::ReceiveKeysend {ref payment_data, ref payment_preimage, ref payment_metadata, ref incoming_cltv_expiry, ref custom_tlvs, } => {
152 let mut payment_data_nonref = Clone::clone(payment_data);
153 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()) } }) };
154 let mut payment_preimage_nonref = Clone::clone(payment_preimage);
155 let mut payment_metadata_nonref = Clone::clone(payment_metadata);
156 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 }})} };
157 let mut incoming_cltv_expiry_nonref = Clone::clone(incoming_cltv_expiry);
158 let mut custom_tlvs_nonref = Clone::clone(custom_tlvs);
159 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 }); };
160 nativePendingHTLCRouting::ReceiveKeysend {
161 payment_data: local_payment_data_nonref,
162 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
163 payment_metadata: local_payment_metadata_nonref,
164 incoming_cltv_expiry: incoming_cltv_expiry_nonref,
165 custom_tlvs: local_custom_tlvs_nonref,
171 pub(crate) fn into_native(self) -> nativePendingHTLCRouting {
173 PendingHTLCRouting::Forward {mut onion_packet, mut short_channel_id, mut blinded, } => {
174 let mut local_blinded = if blinded.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(blinded.take_inner()) } }) };
175 nativePendingHTLCRouting::Forward {
176 onion_packet: *unsafe { Box::from_raw(onion_packet.take_inner()) },
177 short_channel_id: short_channel_id,
178 blinded: local_blinded,
181 PendingHTLCRouting::Receive {mut payment_data, mut payment_metadata, mut incoming_cltv_expiry, mut phantom_shared_secret, mut custom_tlvs, mut requires_blinded_error, } => {
182 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 }})} };
183 let mut local_phantom_shared_secret = if phantom_shared_secret.data == [0; 32] { None } else { Some( { phantom_shared_secret.data }) };
184 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 }); };
185 nativePendingHTLCRouting::Receive {
186 payment_data: *unsafe { Box::from_raw(payment_data.take_inner()) },
187 payment_metadata: local_payment_metadata,
188 incoming_cltv_expiry: incoming_cltv_expiry,
189 phantom_shared_secret: local_phantom_shared_secret,
190 custom_tlvs: local_custom_tlvs,
191 requires_blinded_error: requires_blinded_error,
194 PendingHTLCRouting::ReceiveKeysend {mut payment_data, mut payment_preimage, mut payment_metadata, mut incoming_cltv_expiry, mut custom_tlvs, } => {
195 let mut local_payment_data = if payment_data.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(payment_data.take_inner()) } }) };
196 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 }})} };
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::ReceiveKeysend {
199 payment_data: local_payment_data,
200 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
201 payment_metadata: local_payment_metadata,
202 incoming_cltv_expiry: incoming_cltv_expiry,
203 custom_tlvs: local_custom_tlvs,
209 pub(crate) fn from_native(native: &PendingHTLCRoutingImport) -> Self {
210 let native = unsafe { &*(native as *const _ as *const c_void as *const nativePendingHTLCRouting) };
212 nativePendingHTLCRouting::Forward {ref onion_packet, ref short_channel_id, ref blinded, } => {
213 let mut onion_packet_nonref = Clone::clone(onion_packet);
214 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
215 let mut blinded_nonref = Clone::clone(blinded);
216 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 };
217 PendingHTLCRouting::Forward {
218 onion_packet: crate::lightning::ln::msgs::OnionPacket { inner: ObjOps::heap_alloc(onion_packet_nonref), is_owned: true },
219 short_channel_id: short_channel_id_nonref,
220 blinded: local_blinded_nonref,
223 nativePendingHTLCRouting::Receive {ref payment_data, ref payment_metadata, ref incoming_cltv_expiry, ref phantom_shared_secret, ref custom_tlvs, ref requires_blinded_error, } => {
224 let mut payment_data_nonref = Clone::clone(payment_data);
225 let mut payment_metadata_nonref = Clone::clone(payment_metadata);
226 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() }) };
227 let mut incoming_cltv_expiry_nonref = Clone::clone(incoming_cltv_expiry);
228 let mut phantom_shared_secret_nonref = Clone::clone(phantom_shared_secret);
229 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()) } } };
230 let mut custom_tlvs_nonref = Clone::clone(custom_tlvs);
231 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 }); };
232 let mut requires_blinded_error_nonref = Clone::clone(requires_blinded_error);
233 PendingHTLCRouting::Receive {
234 payment_data: crate::lightning::ln::msgs::FinalOnionHopData { inner: ObjOps::heap_alloc(payment_data_nonref), is_owned: true },
235 payment_metadata: local_payment_metadata_nonref,
236 incoming_cltv_expiry: incoming_cltv_expiry_nonref,
237 phantom_shared_secret: local_phantom_shared_secret_nonref,
238 custom_tlvs: local_custom_tlvs_nonref.into(),
239 requires_blinded_error: requires_blinded_error_nonref,
242 nativePendingHTLCRouting::ReceiveKeysend {ref payment_data, ref payment_preimage, ref payment_metadata, ref incoming_cltv_expiry, ref custom_tlvs, } => {
243 let mut payment_data_nonref = Clone::clone(payment_data);
244 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 };
245 let mut payment_preimage_nonref = Clone::clone(payment_preimage);
246 let mut payment_metadata_nonref = Clone::clone(payment_metadata);
247 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() }) };
248 let mut incoming_cltv_expiry_nonref = Clone::clone(incoming_cltv_expiry);
249 let mut custom_tlvs_nonref = Clone::clone(custom_tlvs);
250 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 }); };
251 PendingHTLCRouting::ReceiveKeysend {
252 payment_data: local_payment_data_nonref,
253 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
254 payment_metadata: local_payment_metadata_nonref,
255 incoming_cltv_expiry: incoming_cltv_expiry_nonref,
256 custom_tlvs: local_custom_tlvs_nonref.into(),
262 pub(crate) fn native_into(native: nativePendingHTLCRouting) -> Self {
264 nativePendingHTLCRouting::Forward {mut onion_packet, mut short_channel_id, mut blinded, } => {
265 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 };
266 PendingHTLCRouting::Forward {
267 onion_packet: crate::lightning::ln::msgs::OnionPacket { inner: ObjOps::heap_alloc(onion_packet), is_owned: true },
268 short_channel_id: short_channel_id,
269 blinded: local_blinded,
272 nativePendingHTLCRouting::Receive {mut payment_data, mut payment_metadata, mut incoming_cltv_expiry, mut phantom_shared_secret, mut custom_tlvs, mut requires_blinded_error, } => {
273 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() }) };
274 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()) } } };
275 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 }); };
276 PendingHTLCRouting::Receive {
277 payment_data: crate::lightning::ln::msgs::FinalOnionHopData { inner: ObjOps::heap_alloc(payment_data), is_owned: true },
278 payment_metadata: local_payment_metadata,
279 incoming_cltv_expiry: incoming_cltv_expiry,
280 phantom_shared_secret: local_phantom_shared_secret,
281 custom_tlvs: local_custom_tlvs.into(),
282 requires_blinded_error: requires_blinded_error,
285 nativePendingHTLCRouting::ReceiveKeysend {mut payment_data, mut payment_preimage, mut payment_metadata, mut incoming_cltv_expiry, mut custom_tlvs, } => {
286 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 };
287 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() }) };
288 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 }); };
289 PendingHTLCRouting::ReceiveKeysend {
290 payment_data: local_payment_data,
291 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
292 payment_metadata: local_payment_metadata,
293 incoming_cltv_expiry: incoming_cltv_expiry,
294 custom_tlvs: local_custom_tlvs.into(),
300 /// Frees any resources used by the PendingHTLCRouting
302 pub extern "C" fn PendingHTLCRouting_free(this_ptr: PendingHTLCRouting) { }
303 /// Creates a copy of the PendingHTLCRouting
305 pub extern "C" fn PendingHTLCRouting_clone(orig: &PendingHTLCRouting) -> PendingHTLCRouting {
309 /// Used only if an object of this type is returned as a trait impl by a method
310 pub(crate) extern "C" fn PendingHTLCRouting_clone_void(this_ptr: *const c_void) -> *mut c_void {
311 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const PendingHTLCRouting)).clone() })) as *mut c_void
314 /// Used only if an object of this type is returned as a trait impl by a method
315 pub(crate) extern "C" fn PendingHTLCRouting_free_void(this_ptr: *mut c_void) {
316 let _ = unsafe { Box::from_raw(this_ptr as *mut PendingHTLCRouting) };
319 /// Utility method to constructs a new Forward-variant PendingHTLCRouting
320 pub extern "C" fn PendingHTLCRouting_forward(onion_packet: crate::lightning::ln::msgs::OnionPacket, short_channel_id: u64, blinded: crate::lightning::ln::channelmanager::BlindedForward) -> PendingHTLCRouting {
321 PendingHTLCRouting::Forward {
328 /// Utility method to constructs a new Receive-variant PendingHTLCRouting
329 pub extern "C" fn PendingHTLCRouting_receive(payment_data: crate::lightning::ln::msgs::FinalOnionHopData, payment_metadata: crate::c_types::derived::COption_CVec_u8ZZ, 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 {
330 PendingHTLCRouting::Receive {
333 incoming_cltv_expiry,
334 phantom_shared_secret,
336 requires_blinded_error,
340 /// Utility method to constructs a new ReceiveKeysend-variant PendingHTLCRouting
341 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) -> PendingHTLCRouting {
342 PendingHTLCRouting::ReceiveKeysend {
346 incoming_cltv_expiry,
351 use lightning::ln::channelmanager::BlindedForward as nativeBlindedForwardImport;
352 pub(crate) type nativeBlindedForward = nativeBlindedForwardImport;
354 /// Information used to forward or fail this HTLC that is being forwarded within a blinded path.
357 pub struct BlindedForward {
358 /// A pointer to the opaque Rust object.
360 /// Nearly everywhere, inner must be non-null, however in places where
361 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
362 pub inner: *mut nativeBlindedForward,
363 /// Indicates that this is the only struct which contains the same pointer.
365 /// Rust functions which take ownership of an object provided via an argument require
366 /// this to be true and invalidate the object pointed to by inner.
370 impl Drop for BlindedForward {
372 if self.is_owned && !<*mut nativeBlindedForward>::is_null(self.inner) {
373 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
377 /// Frees any resources used by the BlindedForward, if is_owned is set and inner is non-NULL.
379 pub extern "C" fn BlindedForward_free(this_obj: BlindedForward) { }
381 /// Used only if an object of this type is returned as a trait impl by a method
382 pub(crate) extern "C" fn BlindedForward_free_void(this_ptr: *mut c_void) {
383 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBlindedForward) };
386 impl BlindedForward {
387 pub(crate) fn get_native_ref(&self) -> &'static nativeBlindedForward {
388 unsafe { &*ObjOps::untweak_ptr(self.inner) }
390 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBlindedForward {
391 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
393 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
394 pub(crate) fn take_inner(mut self) -> *mut nativeBlindedForward {
395 assert!(self.is_owned);
396 let ret = ObjOps::untweak_ptr(self.inner);
397 self.inner = core::ptr::null_mut();
401 /// The `blinding_point` that was set in the inbound [`msgs::UpdateAddHTLC`], or in the inbound
402 /// onion payload if we're the introduction node. Useful for calculating the next hop's
403 /// [`msgs::UpdateAddHTLC::blinding_point`].
405 pub extern "C" fn BlindedForward_get_inbound_blinding_point(this_ptr: &BlindedForward) -> crate::c_types::PublicKey {
406 let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_blinding_point;
407 crate::c_types::PublicKey::from_rust(&inner_val)
409 /// The `blinding_point` that was set in the inbound [`msgs::UpdateAddHTLC`], or in the inbound
410 /// onion payload if we're the introduction node. Useful for calculating the next hop's
411 /// [`msgs::UpdateAddHTLC::blinding_point`].
413 pub extern "C" fn BlindedForward_set_inbound_blinding_point(this_ptr: &mut BlindedForward, mut val: crate::c_types::PublicKey) {
414 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_blinding_point = val.into_rust();
416 /// If needed, this determines how this HTLC should be failed backwards, based on whether we are
417 /// the introduction node.
419 pub extern "C" fn BlindedForward_get_failure(this_ptr: &BlindedForward) -> crate::lightning::ln::channelmanager::BlindedFailure {
420 let mut inner_val = &mut this_ptr.get_native_mut_ref().failure;
421 crate::lightning::ln::channelmanager::BlindedFailure::from_native(inner_val)
423 /// If needed, this determines how this HTLC should be failed backwards, based on whether we are
424 /// the introduction node.
426 pub extern "C" fn BlindedForward_set_failure(this_ptr: &mut BlindedForward, mut val: crate::lightning::ln::channelmanager::BlindedFailure) {
427 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.failure = val.into_native();
429 /// Constructs a new BlindedForward given each field
432 pub extern "C" fn BlindedForward_new(mut inbound_blinding_point_arg: crate::c_types::PublicKey, mut failure_arg: crate::lightning::ln::channelmanager::BlindedFailure) -> BlindedForward {
433 BlindedForward { inner: ObjOps::heap_alloc(nativeBlindedForward {
434 inbound_blinding_point: inbound_blinding_point_arg.into_rust(),
435 failure: failure_arg.into_native(),
438 impl Clone for BlindedForward {
439 fn clone(&self) -> Self {
441 inner: if <*mut nativeBlindedForward>::is_null(self.inner) { core::ptr::null_mut() } else {
442 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
448 /// Used only if an object of this type is returned as a trait impl by a method
449 pub(crate) extern "C" fn BlindedForward_clone_void(this_ptr: *const c_void) -> *mut c_void {
450 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBlindedForward)).clone() })) as *mut c_void
453 /// Creates a copy of the BlindedForward
454 pub extern "C" fn BlindedForward_clone(orig: &BlindedForward) -> BlindedForward {
457 /// Get a string which allows debug introspection of a BlindedForward object
458 pub extern "C" fn BlindedForward_debug_str_void(o: *const c_void) -> Str {
459 alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channelmanager::BlindedForward }).into()}
460 /// Generates a non-cryptographic 64-bit hash of the BlindedForward.
462 pub extern "C" fn BlindedForward_hash(o: &BlindedForward) -> u64 {
463 if o.inner.is_null() { return 0; }
464 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
466 let mut hasher = core::hash::SipHasher::new();
467 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
468 core::hash::Hasher::finish(&hasher)
470 /// Checks if two BlindedForwards contain equal inner contents.
471 /// This ignores pointers and is_owned flags and looks at the values in fields.
472 /// Two objects with NULL inner values will be considered "equal" here.
474 pub extern "C" fn BlindedForward_eq(a: &BlindedForward, b: &BlindedForward) -> bool {
475 if a.inner == b.inner { return true; }
476 if a.inner.is_null() || b.inner.is_null() { return false; }
477 if a.get_native_ref() == b.get_native_ref() { true } else { false }
480 use lightning::ln::channelmanager::PendingHTLCInfo as nativePendingHTLCInfoImport;
481 pub(crate) type nativePendingHTLCInfo = nativePendingHTLCInfoImport;
483 /// Information about an incoming HTLC, including the [`PendingHTLCRouting`] describing where it
487 pub struct PendingHTLCInfo {
488 /// A pointer to the opaque Rust object.
490 /// Nearly everywhere, inner must be non-null, however in places where
491 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
492 pub inner: *mut nativePendingHTLCInfo,
493 /// Indicates that this is the only struct which contains the same pointer.
495 /// Rust functions which take ownership of an object provided via an argument require
496 /// this to be true and invalidate the object pointed to by inner.
500 impl Drop for PendingHTLCInfo {
502 if self.is_owned && !<*mut nativePendingHTLCInfo>::is_null(self.inner) {
503 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
507 /// Frees any resources used by the PendingHTLCInfo, if is_owned is set and inner is non-NULL.
509 pub extern "C" fn PendingHTLCInfo_free(this_obj: PendingHTLCInfo) { }
511 /// Used only if an object of this type is returned as a trait impl by a method
512 pub(crate) extern "C" fn PendingHTLCInfo_free_void(this_ptr: *mut c_void) {
513 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePendingHTLCInfo) };
516 impl PendingHTLCInfo {
517 pub(crate) fn get_native_ref(&self) -> &'static nativePendingHTLCInfo {
518 unsafe { &*ObjOps::untweak_ptr(self.inner) }
520 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePendingHTLCInfo {
521 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
523 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
524 pub(crate) fn take_inner(mut self) -> *mut nativePendingHTLCInfo {
525 assert!(self.is_owned);
526 let ret = ObjOps::untweak_ptr(self.inner);
527 self.inner = core::ptr::null_mut();
531 /// Further routing details based on whether the HTLC is being forwarded or received.
533 pub extern "C" fn PendingHTLCInfo_get_routing(this_ptr: &PendingHTLCInfo) -> crate::lightning::ln::channelmanager::PendingHTLCRouting {
534 let mut inner_val = &mut this_ptr.get_native_mut_ref().routing;
535 crate::lightning::ln::channelmanager::PendingHTLCRouting::from_native(inner_val)
537 /// Further routing details based on whether the HTLC is being forwarded or received.
539 pub extern "C" fn PendingHTLCInfo_set_routing(this_ptr: &mut PendingHTLCInfo, mut val: crate::lightning::ln::channelmanager::PendingHTLCRouting) {
540 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.routing = val.into_native();
542 /// The onion shared secret we build with the sender used to decrypt the onion.
544 /// This is later used to encrypt failure packets in the event that the HTLC is failed.
546 pub extern "C" fn PendingHTLCInfo_get_incoming_shared_secret(this_ptr: &PendingHTLCInfo) -> *const [u8; 32] {
547 let mut inner_val = &mut this_ptr.get_native_mut_ref().incoming_shared_secret;
550 /// The onion shared secret we build with the sender used to decrypt the onion.
552 /// This is later used to encrypt failure packets in the event that the HTLC is failed.
554 pub extern "C" fn PendingHTLCInfo_set_incoming_shared_secret(this_ptr: &mut PendingHTLCInfo, mut val: crate::c_types::ThirtyTwoBytes) {
555 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.incoming_shared_secret = val.data;
557 /// Hash of the payment preimage, to lock the payment until the receiver releases the preimage.
559 pub extern "C" fn PendingHTLCInfo_get_payment_hash(this_ptr: &PendingHTLCInfo) -> *const [u8; 32] {
560 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_hash;
563 /// Hash of the payment preimage, to lock the payment until the receiver releases the preimage.
565 pub extern "C" fn PendingHTLCInfo_set_payment_hash(this_ptr: &mut PendingHTLCInfo, mut val: crate::c_types::ThirtyTwoBytes) {
566 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_hash = ::lightning::ln::PaymentHash(val.data);
568 /// Amount received in the incoming HTLC.
570 /// This field was added in LDK 0.0.113 and will be `None` for objects written by prior
573 pub extern "C" fn PendingHTLCInfo_get_incoming_amt_msat(this_ptr: &PendingHTLCInfo) -> crate::c_types::derived::COption_u64Z {
574 let mut inner_val = &mut this_ptr.get_native_mut_ref().incoming_amt_msat;
575 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() }) };
578 /// Amount received in the incoming HTLC.
580 /// This field was added in LDK 0.0.113 and will be `None` for objects written by prior
583 pub extern "C" fn PendingHTLCInfo_set_incoming_amt_msat(this_ptr: &mut PendingHTLCInfo, mut val: crate::c_types::derived::COption_u64Z) {
584 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
585 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.incoming_amt_msat = local_val;
587 /// The amount the sender indicated should be forwarded on to the next hop or amount the sender
588 /// intended for us to receive for received payments.
590 /// If the received amount is less than this for received payments, an intermediary hop has
591 /// attempted to steal some of our funds and we should fail the HTLC (the sender should retry
592 /// it along another path).
594 /// Because nodes can take less than their required fees, and because senders may wish to
595 /// improve their own privacy, this amount may be less than [`Self::incoming_amt_msat`] for
596 /// received payments. In such cases, recipients must handle this HTLC as if it had received
597 /// [`Self::outgoing_amt_msat`].
599 pub extern "C" fn PendingHTLCInfo_get_outgoing_amt_msat(this_ptr: &PendingHTLCInfo) -> u64 {
600 let mut inner_val = &mut this_ptr.get_native_mut_ref().outgoing_amt_msat;
603 /// The amount the sender indicated should be forwarded on to the next hop or amount the sender
604 /// intended for us to receive for received payments.
606 /// If the received amount is less than this for received payments, an intermediary hop has
607 /// attempted to steal some of our funds and we should fail the HTLC (the sender should retry
608 /// it along another path).
610 /// Because nodes can take less than their required fees, and because senders may wish to
611 /// improve their own privacy, this amount may be less than [`Self::incoming_amt_msat`] for
612 /// received payments. In such cases, recipients must handle this HTLC as if it had received
613 /// [`Self::outgoing_amt_msat`].
615 pub extern "C" fn PendingHTLCInfo_set_outgoing_amt_msat(this_ptr: &mut PendingHTLCInfo, mut val: u64) {
616 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outgoing_amt_msat = val;
618 /// The CLTV the sender has indicated we should set on the forwarded HTLC (or has indicated
619 /// should have been set on the received HTLC for received payments).
621 pub extern "C" fn PendingHTLCInfo_get_outgoing_cltv_value(this_ptr: &PendingHTLCInfo) -> u32 {
622 let mut inner_val = &mut this_ptr.get_native_mut_ref().outgoing_cltv_value;
625 /// The CLTV the sender has indicated we should set on the forwarded HTLC (or has indicated
626 /// should have been set on the received HTLC for received payments).
628 pub extern "C" fn PendingHTLCInfo_set_outgoing_cltv_value(this_ptr: &mut PendingHTLCInfo, mut val: u32) {
629 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outgoing_cltv_value = val;
631 /// The fee taken for this HTLC in addition to the standard protocol HTLC fees.
633 /// If this is a payment for forwarding, this is the fee we are taking before forwarding the
636 /// If this is a received payment, this is the fee that our counterparty took.
638 /// This is used to allow LSPs to take fees as a part of payments, without the sender having to
641 pub extern "C" fn PendingHTLCInfo_get_skimmed_fee_msat(this_ptr: &PendingHTLCInfo) -> crate::c_types::derived::COption_u64Z {
642 let mut inner_val = &mut this_ptr.get_native_mut_ref().skimmed_fee_msat;
643 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() }) };
646 /// The fee taken for this HTLC in addition to the standard protocol HTLC fees.
648 /// If this is a payment for forwarding, this is the fee we are taking before forwarding the
651 /// If this is a received payment, this is the fee that our counterparty took.
653 /// This is used to allow LSPs to take fees as a part of payments, without the sender having to
656 pub extern "C" fn PendingHTLCInfo_set_skimmed_fee_msat(this_ptr: &mut PendingHTLCInfo, mut val: crate::c_types::derived::COption_u64Z) {
657 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
658 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.skimmed_fee_msat = local_val;
660 /// Constructs a new PendingHTLCInfo given each field
663 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 {
664 let mut local_incoming_amt_msat_arg = if incoming_amt_msat_arg.is_some() { Some( { incoming_amt_msat_arg.take() }) } else { None };
665 let mut local_skimmed_fee_msat_arg = if skimmed_fee_msat_arg.is_some() { Some( { skimmed_fee_msat_arg.take() }) } else { None };
666 PendingHTLCInfo { inner: ObjOps::heap_alloc(nativePendingHTLCInfo {
667 routing: routing_arg.into_native(),
668 incoming_shared_secret: incoming_shared_secret_arg.data,
669 payment_hash: ::lightning::ln::PaymentHash(payment_hash_arg.data),
670 incoming_amt_msat: local_incoming_amt_msat_arg,
671 outgoing_amt_msat: outgoing_amt_msat_arg,
672 outgoing_cltv_value: outgoing_cltv_value_arg,
673 skimmed_fee_msat: local_skimmed_fee_msat_arg,
676 impl Clone for PendingHTLCInfo {
677 fn clone(&self) -> Self {
679 inner: if <*mut nativePendingHTLCInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
680 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
686 /// Used only if an object of this type is returned as a trait impl by a method
687 pub(crate) extern "C" fn PendingHTLCInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
688 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePendingHTLCInfo)).clone() })) as *mut c_void
691 /// Creates a copy of the PendingHTLCInfo
692 pub extern "C" fn PendingHTLCInfo_clone(orig: &PendingHTLCInfo) -> PendingHTLCInfo {
695 /// Whether this blinded HTLC is being failed backwards by the introduction node or a blinded node,
696 /// which determines the failure message that should be used.
700 pub enum BlindedFailure {
701 /// This HTLC is being failed backwards by the introduction node, and thus should be failed with
702 /// [`msgs::UpdateFailHTLC`] and error code `0x8000|0x4000|24`.
703 FromIntroductionNode,
704 /// This HTLC is being failed backwards by a blinded node within the path, and thus should be
705 /// failed with [`msgs::UpdateFailMalformedHTLC`] and error code `0x8000|0x4000|24`.
708 use lightning::ln::channelmanager::BlindedFailure as BlindedFailureImport;
709 pub(crate) type nativeBlindedFailure = BlindedFailureImport;
711 impl BlindedFailure {
713 pub(crate) fn to_native(&self) -> nativeBlindedFailure {
715 BlindedFailure::FromIntroductionNode => nativeBlindedFailure::FromIntroductionNode,
716 BlindedFailure::FromBlindedNode => nativeBlindedFailure::FromBlindedNode,
720 pub(crate) fn into_native(self) -> nativeBlindedFailure {
722 BlindedFailure::FromIntroductionNode => nativeBlindedFailure::FromIntroductionNode,
723 BlindedFailure::FromBlindedNode => nativeBlindedFailure::FromBlindedNode,
727 pub(crate) fn from_native(native: &BlindedFailureImport) -> Self {
728 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeBlindedFailure) };
730 nativeBlindedFailure::FromIntroductionNode => BlindedFailure::FromIntroductionNode,
731 nativeBlindedFailure::FromBlindedNode => BlindedFailure::FromBlindedNode,
735 pub(crate) fn native_into(native: nativeBlindedFailure) -> Self {
737 nativeBlindedFailure::FromIntroductionNode => BlindedFailure::FromIntroductionNode,
738 nativeBlindedFailure::FromBlindedNode => BlindedFailure::FromBlindedNode,
742 /// Creates a copy of the BlindedFailure
744 pub extern "C" fn BlindedFailure_clone(orig: &BlindedFailure) -> BlindedFailure {
748 /// Used only if an object of this type is returned as a trait impl by a method
749 pub(crate) extern "C" fn BlindedFailure_clone_void(this_ptr: *const c_void) -> *mut c_void {
750 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const BlindedFailure)).clone() })) as *mut c_void
753 /// Used only if an object of this type is returned as a trait impl by a method
754 pub(crate) extern "C" fn BlindedFailure_free_void(this_ptr: *mut c_void) {
755 let _ = unsafe { Box::from_raw(this_ptr as *mut BlindedFailure) };
758 /// Utility method to constructs a new FromIntroductionNode-variant BlindedFailure
759 pub extern "C" fn BlindedFailure_from_introduction_node() -> BlindedFailure {
760 BlindedFailure::FromIntroductionNode}
762 /// Utility method to constructs a new FromBlindedNode-variant BlindedFailure
763 pub extern "C" fn BlindedFailure_from_blinded_node() -> BlindedFailure {
764 BlindedFailure::FromBlindedNode}
765 /// Get a string which allows debug introspection of a BlindedFailure object
766 pub extern "C" fn BlindedFailure_debug_str_void(o: *const c_void) -> Str {
767 alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channelmanager::BlindedFailure }).into()}
768 /// Generates a non-cryptographic 64-bit hash of the BlindedFailure.
770 pub extern "C" fn BlindedFailure_hash(o: &BlindedFailure) -> u64 {
771 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
773 let mut hasher = core::hash::SipHasher::new();
774 core::hash::Hash::hash(&o.to_native(), &mut hasher);
775 core::hash::Hasher::finish(&hasher)
777 /// Checks if two BlindedFailures contain equal inner contents.
778 /// This ignores pointers and is_owned flags and looks at the values in fields.
780 pub extern "C" fn BlindedFailure_eq(a: &BlindedFailure, b: &BlindedFailure) -> bool {
781 if &a.to_native() == &b.to_native() { true } else { false }
783 /// This enum is used to specify which error data to send to peers when failing back an HTLC
784 /// using [`ChannelManager::fail_htlc_backwards_with_reason`].
786 /// For more info on failure codes, see <https://github.com/lightning/bolts/blob/master/04-onion-routing.md#failure-messages>.
790 pub enum FailureCode {
791 /// We had a temporary error processing the payment. Useful if no other error codes fit
792 /// and you want to indicate that the payer may want to retry.
793 TemporaryNodeFailure,
794 /// We have a required feature which was not in this onion. For example, you may require
795 /// some additional metadata that was not provided with this payment.
796 RequiredNodeFeatureMissing,
797 /// You may wish to use this when a `payment_preimage` is unknown, or the CLTV expiry of
798 /// the HTLC is too close to the current block height for safe handling.
799 /// Using this failure code in [`ChannelManager::fail_htlc_backwards_with_reason`] is
800 /// equivalent to calling [`ChannelManager::fail_htlc_backwards`].
801 IncorrectOrUnknownPaymentDetails,
802 /// We failed to process the payload after the onion was decrypted. You may wish to
803 /// use this when receiving custom HTLC TLVs with even type numbers that you don't recognize.
805 /// If available, the tuple data may include the type number and byte offset in the
806 /// decrypted byte stream where the failure occurred.
808 crate::c_types::derived::COption_C2Tuple_u64u16ZZ),
810 use lightning::ln::channelmanager::FailureCode as FailureCodeImport;
811 pub(crate) type nativeFailureCode = FailureCodeImport;
815 pub(crate) fn to_native(&self) -> nativeFailureCode {
817 FailureCode::TemporaryNodeFailure => nativeFailureCode::TemporaryNodeFailure,
818 FailureCode::RequiredNodeFeatureMissing => nativeFailureCode::RequiredNodeFeatureMissing,
819 FailureCode::IncorrectOrUnknownPaymentDetails => nativeFailureCode::IncorrectOrUnknownPaymentDetails,
820 FailureCode::InvalidOnionPayload (ref a, ) => {
821 let mut a_nonref = Clone::clone(a);
822 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 };
823 nativeFailureCode::InvalidOnionPayload (
830 pub(crate) fn into_native(self) -> nativeFailureCode {
832 FailureCode::TemporaryNodeFailure => nativeFailureCode::TemporaryNodeFailure,
833 FailureCode::RequiredNodeFeatureMissing => nativeFailureCode::RequiredNodeFeatureMissing,
834 FailureCode::IncorrectOrUnknownPaymentDetails => nativeFailureCode::IncorrectOrUnknownPaymentDetails,
835 FailureCode::InvalidOnionPayload (mut a, ) => {
836 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 };
837 nativeFailureCode::InvalidOnionPayload (
844 pub(crate) fn from_native(native: &FailureCodeImport) -> Self {
845 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeFailureCode) };
847 nativeFailureCode::TemporaryNodeFailure => FailureCode::TemporaryNodeFailure,
848 nativeFailureCode::RequiredNodeFeatureMissing => FailureCode::RequiredNodeFeatureMissing,
849 nativeFailureCode::IncorrectOrUnknownPaymentDetails => FailureCode::IncorrectOrUnknownPaymentDetails,
850 nativeFailureCode::InvalidOnionPayload (ref a, ) => {
851 let mut a_nonref = Clone::clone(a);
852 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 }) };
853 FailureCode::InvalidOnionPayload (
860 pub(crate) fn native_into(native: nativeFailureCode) -> Self {
862 nativeFailureCode::TemporaryNodeFailure => FailureCode::TemporaryNodeFailure,
863 nativeFailureCode::RequiredNodeFeatureMissing => FailureCode::RequiredNodeFeatureMissing,
864 nativeFailureCode::IncorrectOrUnknownPaymentDetails => FailureCode::IncorrectOrUnknownPaymentDetails,
865 nativeFailureCode::InvalidOnionPayload (mut a, ) => {
866 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 }) };
867 FailureCode::InvalidOnionPayload (
874 /// Frees any resources used by the FailureCode
876 pub extern "C" fn FailureCode_free(this_ptr: FailureCode) { }
877 /// Creates a copy of the FailureCode
879 pub extern "C" fn FailureCode_clone(orig: &FailureCode) -> FailureCode {
883 /// Used only if an object of this type is returned as a trait impl by a method
884 pub(crate) extern "C" fn FailureCode_clone_void(this_ptr: *const c_void) -> *mut c_void {
885 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const FailureCode)).clone() })) as *mut c_void
888 /// Used only if an object of this type is returned as a trait impl by a method
889 pub(crate) extern "C" fn FailureCode_free_void(this_ptr: *mut c_void) {
890 let _ = unsafe { Box::from_raw(this_ptr as *mut FailureCode) };
893 /// Utility method to constructs a new TemporaryNodeFailure-variant FailureCode
894 pub extern "C" fn FailureCode_temporary_node_failure() -> FailureCode {
895 FailureCode::TemporaryNodeFailure}
897 /// Utility method to constructs a new RequiredNodeFeatureMissing-variant FailureCode
898 pub extern "C" fn FailureCode_required_node_feature_missing() -> FailureCode {
899 FailureCode::RequiredNodeFeatureMissing}
901 /// Utility method to constructs a new IncorrectOrUnknownPaymentDetails-variant FailureCode
902 pub extern "C" fn FailureCode_incorrect_or_unknown_payment_details() -> FailureCode {
903 FailureCode::IncorrectOrUnknownPaymentDetails}
905 /// Utility method to constructs a new InvalidOnionPayload-variant FailureCode
906 pub extern "C" fn FailureCode_invalid_onion_payload(a: crate::c_types::derived::COption_C2Tuple_u64u16ZZ) -> FailureCode {
907 FailureCode::InvalidOnionPayload(a, )
910 use lightning::ln::channelmanager::ChannelManager as nativeChannelManagerImport;
911 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>;
913 /// Manager which keeps track of a number of channels and sends messages to the appropriate
914 /// channel, also tracking HTLC preimages and forwarding onion packets appropriately.
916 /// Implements [`ChannelMessageHandler`], handling the multi-channel parts and passing things through
917 /// to individual Channels.
919 /// Implements [`Writeable`] to write out all channel state to disk. Implies [`peer_disconnected`] for
920 /// all peers during write/read (though does not modify this instance, only the instance being
921 /// serialized). This will result in any channels which have not yet exchanged [`funding_created`] (i.e.,
922 /// called [`funding_transaction_generated`] for outbound channels) being closed.
924 /// Note that you can be a bit lazier about writing out `ChannelManager` than you can be with
925 /// [`ChannelMonitor`]. With [`ChannelMonitor`] you MUST durably write each
926 /// [`ChannelMonitorUpdate`] before returning from
927 /// [`chain::Watch::watch_channel`]/[`update_channel`] or before completing async writes. With
928 /// `ChannelManager`s, writing updates happens out-of-band (and will prevent any other
929 /// `ChannelManager` operations from occurring during the serialization process). If the
930 /// deserialized version is out-of-date compared to the [`ChannelMonitor`] passed by reference to
931 /// [`read`], those channels will be force-closed based on the `ChannelMonitor` state and no funds
932 /// will be lost (modulo on-chain transaction fees).
934 /// Note that the deserializer is only implemented for `(`[`BlockHash`]`, `[`ChannelManager`]`)`, which
935 /// tells you the last block hash which was connected. You should get the best block tip before using the manager.
936 /// See [`chain::Listen`] and [`chain::Confirm`] for more details.
938 /// Note that `ChannelManager` is responsible for tracking liveness of its channels and generating
939 /// [`ChannelUpdate`] messages informing peers that the channel is temporarily disabled. To avoid
940 /// spam due to quick disconnection/reconnection, updates are not sent until the channel has been
941 /// offline for a full minute. In order to track this, you must call
942 /// [`timer_tick_occurred`] roughly once per minute, though it doesn't have to be perfect.
944 /// To avoid trivial DoS issues, `ChannelManager` limits the number of inbound connections and
945 /// inbound channels without confirmed funding transactions. This may result in nodes which we do
946 /// not have a channel with being unable to connect to us or open new channels with us if we have
947 /// many peers with unfunded channels.
949 /// Because it is an indication of trust, inbound channels which we've accepted as 0conf are
950 /// exempted from the count of unfunded channels. Similarly, outbound channels and connections are
951 /// never limited. Please ensure you limit the count of such channels yourself.
953 /// Rather than using a plain `ChannelManager`, it is preferable to use either a [`SimpleArcChannelManager`]
954 /// a [`SimpleRefChannelManager`], for conciseness. See their documentation for more details, but
955 /// essentially you should default to using a [`SimpleRefChannelManager`], and use a
956 /// [`SimpleArcChannelManager`] when you require a `ChannelManager` with a static lifetime, such as when
957 /// you're using lightning-net-tokio.
959 /// [`peer_disconnected`]: msgs::ChannelMessageHandler::peer_disconnected
960 /// [`funding_created`]: msgs::FundingCreated
961 /// [`funding_transaction_generated`]: Self::funding_transaction_generated
962 /// [`BlockHash`]: bitcoin::hash_types::BlockHash
963 /// [`update_channel`]: chain::Watch::update_channel
964 /// [`ChannelUpdate`]: msgs::ChannelUpdate
965 /// [`timer_tick_occurred`]: Self::timer_tick_occurred
966 /// [`read`]: ReadableArgs::read
969 pub struct ChannelManager {
970 /// A pointer to the opaque Rust object.
972 /// Nearly everywhere, inner must be non-null, however in places where
973 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
974 pub inner: *mut nativeChannelManager,
975 /// Indicates that this is the only struct which contains the same pointer.
977 /// Rust functions which take ownership of an object provided via an argument require
978 /// this to be true and invalidate the object pointed to by inner.
982 impl Drop for ChannelManager {
984 if self.is_owned && !<*mut nativeChannelManager>::is_null(self.inner) {
985 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
989 /// Frees any resources used by the ChannelManager, if is_owned is set and inner is non-NULL.
991 pub extern "C" fn ChannelManager_free(this_obj: ChannelManager) { }
993 /// Used only if an object of this type is returned as a trait impl by a method
994 pub(crate) extern "C" fn ChannelManager_free_void(this_ptr: *mut c_void) {
995 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelManager) };
998 impl ChannelManager {
999 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManager {
1000 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1002 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManager {
1003 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1005 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1006 pub(crate) fn take_inner(mut self) -> *mut nativeChannelManager {
1007 assert!(self.is_owned);
1008 let ret = ObjOps::untweak_ptr(self.inner);
1009 self.inner = core::ptr::null_mut();
1014 use lightning::ln::channelmanager::ChainParameters as nativeChainParametersImport;
1015 pub(crate) type nativeChainParameters = nativeChainParametersImport;
1017 /// Chain-related parameters used to construct a new `ChannelManager`.
1019 /// Typically, the block-specific parameters are derived from the best block hash for the network,
1020 /// as a newly constructed `ChannelManager` will not have created any channels yet. These parameters
1021 /// are not needed when deserializing a previously constructed `ChannelManager`.
1024 pub struct ChainParameters {
1025 /// A pointer to the opaque Rust object.
1027 /// Nearly everywhere, inner must be non-null, however in places where
1028 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1029 pub inner: *mut nativeChainParameters,
1030 /// Indicates that this is the only struct which contains the same pointer.
1032 /// Rust functions which take ownership of an object provided via an argument require
1033 /// this to be true and invalidate the object pointed to by inner.
1037 impl Drop for ChainParameters {
1038 fn drop(&mut self) {
1039 if self.is_owned && !<*mut nativeChainParameters>::is_null(self.inner) {
1040 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1044 /// Frees any resources used by the ChainParameters, if is_owned is set and inner is non-NULL.
1046 pub extern "C" fn ChainParameters_free(this_obj: ChainParameters) { }
1048 /// Used only if an object of this type is returned as a trait impl by a method
1049 pub(crate) extern "C" fn ChainParameters_free_void(this_ptr: *mut c_void) {
1050 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChainParameters) };
1053 impl ChainParameters {
1054 pub(crate) fn get_native_ref(&self) -> &'static nativeChainParameters {
1055 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1057 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChainParameters {
1058 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1060 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1061 pub(crate) fn take_inner(mut self) -> *mut nativeChainParameters {
1062 assert!(self.is_owned);
1063 let ret = ObjOps::untweak_ptr(self.inner);
1064 self.inner = core::ptr::null_mut();
1068 /// The network for determining the `chain_hash` in Lightning messages.
1070 pub extern "C" fn ChainParameters_get_network(this_ptr: &ChainParameters) -> crate::bitcoin::network::Network {
1071 let mut inner_val = &mut this_ptr.get_native_mut_ref().network;
1072 crate::bitcoin::network::Network::from_bitcoin(inner_val)
1074 /// The network for determining the `chain_hash` in Lightning messages.
1076 pub extern "C" fn ChainParameters_set_network(this_ptr: &mut ChainParameters, mut val: crate::bitcoin::network::Network) {
1077 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.network = val.into_bitcoin();
1079 /// The hash and height of the latest block successfully connected.
1081 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
1083 pub extern "C" fn ChainParameters_get_best_block(this_ptr: &ChainParameters) -> crate::lightning::chain::BestBlock {
1084 let mut inner_val = &mut this_ptr.get_native_mut_ref().best_block;
1085 crate::lightning::chain::BestBlock { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::chain::BestBlock<>) as *mut _) }, is_owned: false }
1087 /// The hash and height of the latest block successfully connected.
1089 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
1091 pub extern "C" fn ChainParameters_set_best_block(this_ptr: &mut ChainParameters, mut val: crate::lightning::chain::BestBlock) {
1092 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.best_block = *unsafe { Box::from_raw(val.take_inner()) };
1094 /// Constructs a new ChainParameters given each field
1097 pub extern "C" fn ChainParameters_new(mut network_arg: crate::bitcoin::network::Network, mut best_block_arg: crate::lightning::chain::BestBlock) -> ChainParameters {
1098 ChainParameters { inner: ObjOps::heap_alloc(nativeChainParameters {
1099 network: network_arg.into_bitcoin(),
1100 best_block: *unsafe { Box::from_raw(best_block_arg.take_inner()) },
1101 }), is_owned: true }
1103 impl Clone for ChainParameters {
1104 fn clone(&self) -> Self {
1106 inner: if <*mut nativeChainParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
1107 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1113 /// Used only if an object of this type is returned as a trait impl by a method
1114 pub(crate) extern "C" fn ChainParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
1115 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChainParameters)).clone() })) as *mut c_void
1118 /// Creates a copy of the ChainParameters
1119 pub extern "C" fn ChainParameters_clone(orig: &ChainParameters) -> ChainParameters {
1122 /// The amount of time in blocks we require our counterparty wait to claim their money (ie time
1123 /// between when we, or our watchtower, must check for them having broadcast a theft transaction).
1125 /// This can be increased (but not decreased) through [`ChannelHandshakeConfig::our_to_self_delay`]
1127 /// [`ChannelHandshakeConfig::our_to_self_delay`]: crate::util::config::ChannelHandshakeConfig::our_to_self_delay
1130 pub static BREAKDOWN_TIMEOUT: u16 = lightning::ln::channelmanager::BREAKDOWN_TIMEOUT;
1131 /// The minimum number of blocks between an inbound HTLC's CLTV and the corresponding outbound
1132 /// HTLC's CLTV. The current default represents roughly seven hours of blocks at six blocks/hour.
1134 /// This can be increased (but not decreased) through [`ChannelConfig::cltv_expiry_delta`]
1136 /// [`ChannelConfig::cltv_expiry_delta`]: crate::util::config::ChannelConfig::cltv_expiry_delta
1139 pub static MIN_CLTV_EXPIRY_DELTA: u16 = lightning::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA;
1140 /// Minimum CLTV difference between the current block height and received inbound payments.
1141 /// Invoices generated for payment to us must set their `min_final_cltv_expiry_delta` field to at least
1145 pub static MIN_FINAL_CLTV_EXPIRY_DELTA: u16 = lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA;
1147 use lightning::ln::channelmanager::CounterpartyForwardingInfo as nativeCounterpartyForwardingInfoImport;
1148 pub(crate) type nativeCounterpartyForwardingInfo = nativeCounterpartyForwardingInfoImport;
1150 /// Information needed for constructing an invoice route hint for this channel.
1153 pub struct CounterpartyForwardingInfo {
1154 /// A pointer to the opaque Rust object.
1156 /// Nearly everywhere, inner must be non-null, however in places where
1157 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1158 pub inner: *mut nativeCounterpartyForwardingInfo,
1159 /// Indicates that this is the only struct which contains the same pointer.
1161 /// Rust functions which take ownership of an object provided via an argument require
1162 /// this to be true and invalidate the object pointed to by inner.
1166 impl Drop for CounterpartyForwardingInfo {
1167 fn drop(&mut self) {
1168 if self.is_owned && !<*mut nativeCounterpartyForwardingInfo>::is_null(self.inner) {
1169 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1173 /// Frees any resources used by the CounterpartyForwardingInfo, if is_owned is set and inner is non-NULL.
1175 pub extern "C" fn CounterpartyForwardingInfo_free(this_obj: CounterpartyForwardingInfo) { }
1177 /// Used only if an object of this type is returned as a trait impl by a method
1178 pub(crate) extern "C" fn CounterpartyForwardingInfo_free_void(this_ptr: *mut c_void) {
1179 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeCounterpartyForwardingInfo) };
1182 impl CounterpartyForwardingInfo {
1183 pub(crate) fn get_native_ref(&self) -> &'static nativeCounterpartyForwardingInfo {
1184 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1186 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCounterpartyForwardingInfo {
1187 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1189 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1190 pub(crate) fn take_inner(mut self) -> *mut nativeCounterpartyForwardingInfo {
1191 assert!(self.is_owned);
1192 let ret = ObjOps::untweak_ptr(self.inner);
1193 self.inner = core::ptr::null_mut();
1197 /// Base routing fee in millisatoshis.
1199 pub extern "C" fn CounterpartyForwardingInfo_get_fee_base_msat(this_ptr: &CounterpartyForwardingInfo) -> u32 {
1200 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_base_msat;
1203 /// Base routing fee in millisatoshis.
1205 pub extern "C" fn CounterpartyForwardingInfo_set_fee_base_msat(this_ptr: &mut CounterpartyForwardingInfo, mut val: u32) {
1206 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_base_msat = val;
1208 /// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
1210 pub extern "C" fn CounterpartyForwardingInfo_get_fee_proportional_millionths(this_ptr: &CounterpartyForwardingInfo) -> u32 {
1211 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_proportional_millionths;
1214 /// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
1216 pub extern "C" fn CounterpartyForwardingInfo_set_fee_proportional_millionths(this_ptr: &mut CounterpartyForwardingInfo, mut val: u32) {
1217 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_proportional_millionths = val;
1219 /// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
1220 /// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
1221 /// `cltv_expiry_delta` for more details.
1223 pub extern "C" fn CounterpartyForwardingInfo_get_cltv_expiry_delta(this_ptr: &CounterpartyForwardingInfo) -> u16 {
1224 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
1227 /// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
1228 /// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
1229 /// `cltv_expiry_delta` for more details.
1231 pub extern "C" fn CounterpartyForwardingInfo_set_cltv_expiry_delta(this_ptr: &mut CounterpartyForwardingInfo, mut val: u16) {
1232 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
1234 /// Constructs a new CounterpartyForwardingInfo given each field
1237 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 {
1238 CounterpartyForwardingInfo { inner: ObjOps::heap_alloc(nativeCounterpartyForwardingInfo {
1239 fee_base_msat: fee_base_msat_arg,
1240 fee_proportional_millionths: fee_proportional_millionths_arg,
1241 cltv_expiry_delta: cltv_expiry_delta_arg,
1242 }), is_owned: true }
1244 impl Clone for CounterpartyForwardingInfo {
1245 fn clone(&self) -> Self {
1247 inner: if <*mut nativeCounterpartyForwardingInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1248 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1254 /// Used only if an object of this type is returned as a trait impl by a method
1255 pub(crate) extern "C" fn CounterpartyForwardingInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1256 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeCounterpartyForwardingInfo)).clone() })) as *mut c_void
1259 /// Creates a copy of the CounterpartyForwardingInfo
1260 pub extern "C" fn CounterpartyForwardingInfo_clone(orig: &CounterpartyForwardingInfo) -> CounterpartyForwardingInfo {
1263 /// Get a string which allows debug introspection of a CounterpartyForwardingInfo object
1264 pub extern "C" fn CounterpartyForwardingInfo_debug_str_void(o: *const c_void) -> Str {
1265 alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channelmanager::CounterpartyForwardingInfo }).into()}
1267 use lightning::ln::channelmanager::ChannelCounterparty as nativeChannelCounterpartyImport;
1268 pub(crate) type nativeChannelCounterparty = nativeChannelCounterpartyImport;
1270 /// Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
1271 /// to better separate parameters.
1274 pub struct ChannelCounterparty {
1275 /// A pointer to the opaque Rust object.
1277 /// Nearly everywhere, inner must be non-null, however in places where
1278 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1279 pub inner: *mut nativeChannelCounterparty,
1280 /// Indicates that this is the only struct which contains the same pointer.
1282 /// Rust functions which take ownership of an object provided via an argument require
1283 /// this to be true and invalidate the object pointed to by inner.
1287 impl Drop for ChannelCounterparty {
1288 fn drop(&mut self) {
1289 if self.is_owned && !<*mut nativeChannelCounterparty>::is_null(self.inner) {
1290 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1294 /// Frees any resources used by the ChannelCounterparty, if is_owned is set and inner is non-NULL.
1296 pub extern "C" fn ChannelCounterparty_free(this_obj: ChannelCounterparty) { }
1298 /// Used only if an object of this type is returned as a trait impl by a method
1299 pub(crate) extern "C" fn ChannelCounterparty_free_void(this_ptr: *mut c_void) {
1300 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelCounterparty) };
1303 impl ChannelCounterparty {
1304 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelCounterparty {
1305 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1307 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelCounterparty {
1308 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1310 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1311 pub(crate) fn take_inner(mut self) -> *mut nativeChannelCounterparty {
1312 assert!(self.is_owned);
1313 let ret = ObjOps::untweak_ptr(self.inner);
1314 self.inner = core::ptr::null_mut();
1318 /// The node_id of our counterparty
1320 pub extern "C" fn ChannelCounterparty_get_node_id(this_ptr: &ChannelCounterparty) -> crate::c_types::PublicKey {
1321 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_id;
1322 crate::c_types::PublicKey::from_rust(&inner_val)
1324 /// The node_id of our counterparty
1326 pub extern "C" fn ChannelCounterparty_set_node_id(this_ptr: &mut ChannelCounterparty, mut val: crate::c_types::PublicKey) {
1327 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_id = val.into_rust();
1329 /// The Features the channel counterparty provided upon last connection.
1330 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
1331 /// many routing-relevant features are present in the init context.
1333 pub extern "C" fn ChannelCounterparty_get_features(this_ptr: &ChannelCounterparty) -> crate::lightning::ln::features::InitFeatures {
1334 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
1335 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 }
1337 /// The Features the channel counterparty provided upon last connection.
1338 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
1339 /// many routing-relevant features are present in the init context.
1341 pub extern "C" fn ChannelCounterparty_set_features(this_ptr: &mut ChannelCounterparty, mut val: crate::lightning::ln::features::InitFeatures) {
1342 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
1344 /// The value, in satoshis, that must always be held in the channel for our counterparty. This
1345 /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
1346 /// claiming at least this value on chain.
1348 /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
1350 /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
1352 pub extern "C" fn ChannelCounterparty_get_unspendable_punishment_reserve(this_ptr: &ChannelCounterparty) -> u64 {
1353 let mut inner_val = &mut this_ptr.get_native_mut_ref().unspendable_punishment_reserve;
1356 /// The value, in satoshis, that must always be held in the channel for our counterparty. This
1357 /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
1358 /// claiming at least this value on chain.
1360 /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
1362 /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
1364 pub extern "C" fn ChannelCounterparty_set_unspendable_punishment_reserve(this_ptr: &mut ChannelCounterparty, mut val: u64) {
1365 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = val;
1367 /// Information on the fees and requirements that the counterparty requires when forwarding
1368 /// payments to us through this channel.
1370 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1372 pub extern "C" fn ChannelCounterparty_get_forwarding_info(this_ptr: &ChannelCounterparty) -> crate::lightning::ln::channelmanager::CounterpartyForwardingInfo {
1373 let mut inner_val = &mut this_ptr.get_native_mut_ref().forwarding_info;
1374 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 };
1377 /// Information on the fees and requirements that the counterparty requires when forwarding
1378 /// payments to us through this channel.
1380 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1382 pub extern "C" fn ChannelCounterparty_set_forwarding_info(this_ptr: &mut ChannelCounterparty, mut val: crate::lightning::ln::channelmanager::CounterpartyForwardingInfo) {
1383 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1384 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.forwarding_info = local_val;
1386 /// The smallest value HTLC (in msat) the remote peer will accept, for this channel. This field
1387 /// is only `None` before we have received either the `OpenChannel` or `AcceptChannel` message
1388 /// from the remote peer, or for `ChannelCounterparty` objects serialized prior to LDK 0.0.107.
1390 pub extern "C" fn ChannelCounterparty_get_outbound_htlc_minimum_msat(this_ptr: &ChannelCounterparty) -> crate::c_types::derived::COption_u64Z {
1391 let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_htlc_minimum_msat;
1392 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() }) };
1395 /// The smallest value HTLC (in msat) the remote peer will accept, for this channel. This field
1396 /// is only `None` before we have received either the `OpenChannel` or `AcceptChannel` message
1397 /// from the remote peer, or for `ChannelCounterparty` objects serialized prior to LDK 0.0.107.
1399 pub extern "C" fn ChannelCounterparty_set_outbound_htlc_minimum_msat(this_ptr: &mut ChannelCounterparty, mut val: crate::c_types::derived::COption_u64Z) {
1400 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1401 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_htlc_minimum_msat = local_val;
1403 /// The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
1405 pub extern "C" fn ChannelCounterparty_get_outbound_htlc_maximum_msat(this_ptr: &ChannelCounterparty) -> crate::c_types::derived::COption_u64Z {
1406 let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_htlc_maximum_msat;
1407 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() }) };
1410 /// The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
1412 pub extern "C" fn ChannelCounterparty_set_outbound_htlc_maximum_msat(this_ptr: &mut ChannelCounterparty, mut val: crate::c_types::derived::COption_u64Z) {
1413 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1414 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_htlc_maximum_msat = local_val;
1416 /// Constructs a new ChannelCounterparty given each field
1418 /// Note that forwarding_info_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
1421 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 {
1422 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()) } }) };
1423 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 };
1424 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 };
1425 ChannelCounterparty { inner: ObjOps::heap_alloc(nativeChannelCounterparty {
1426 node_id: node_id_arg.into_rust(),
1427 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
1428 unspendable_punishment_reserve: unspendable_punishment_reserve_arg,
1429 forwarding_info: local_forwarding_info_arg,
1430 outbound_htlc_minimum_msat: local_outbound_htlc_minimum_msat_arg,
1431 outbound_htlc_maximum_msat: local_outbound_htlc_maximum_msat_arg,
1432 }), is_owned: true }
1434 impl Clone for ChannelCounterparty {
1435 fn clone(&self) -> Self {
1437 inner: if <*mut nativeChannelCounterparty>::is_null(self.inner) { core::ptr::null_mut() } else {
1438 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1444 /// Used only if an object of this type is returned as a trait impl by a method
1445 pub(crate) extern "C" fn ChannelCounterparty_clone_void(this_ptr: *const c_void) -> *mut c_void {
1446 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelCounterparty)).clone() })) as *mut c_void
1449 /// Creates a copy of the ChannelCounterparty
1450 pub extern "C" fn ChannelCounterparty_clone(orig: &ChannelCounterparty) -> ChannelCounterparty {
1453 /// Get a string which allows debug introspection of a ChannelCounterparty object
1454 pub extern "C" fn ChannelCounterparty_debug_str_void(o: *const c_void) -> Str {
1455 alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channelmanager::ChannelCounterparty }).into()}
1457 use lightning::ln::channelmanager::ChannelDetails as nativeChannelDetailsImport;
1458 pub(crate) type nativeChannelDetails = nativeChannelDetailsImport;
1460 /// Details of a channel, as returned by [`ChannelManager::list_channels`] and [`ChannelManager::list_usable_channels`]
1463 pub struct ChannelDetails {
1464 /// A pointer to the opaque Rust object.
1466 /// Nearly everywhere, inner must be non-null, however in places where
1467 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1468 pub inner: *mut nativeChannelDetails,
1469 /// Indicates that this is the only struct which contains the same pointer.
1471 /// Rust functions which take ownership of an object provided via an argument require
1472 /// this to be true and invalidate the object pointed to by inner.
1476 impl Drop for ChannelDetails {
1477 fn drop(&mut self) {
1478 if self.is_owned && !<*mut nativeChannelDetails>::is_null(self.inner) {
1479 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1483 /// Frees any resources used by the ChannelDetails, if is_owned is set and inner is non-NULL.
1485 pub extern "C" fn ChannelDetails_free(this_obj: ChannelDetails) { }
1487 /// Used only if an object of this type is returned as a trait impl by a method
1488 pub(crate) extern "C" fn ChannelDetails_free_void(this_ptr: *mut c_void) {
1489 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelDetails) };
1492 impl ChannelDetails {
1493 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelDetails {
1494 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1496 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelDetails {
1497 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1499 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1500 pub(crate) fn take_inner(mut self) -> *mut nativeChannelDetails {
1501 assert!(self.is_owned);
1502 let ret = ObjOps::untweak_ptr(self.inner);
1503 self.inner = core::ptr::null_mut();
1507 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
1508 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
1509 /// Note that this means this value is *not* persistent - it can change once during the
1510 /// lifetime of the channel.
1512 pub extern "C" fn ChannelDetails_get_channel_id(this_ptr: &ChannelDetails) -> *const [u8; 32] {
1513 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id;
1516 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
1517 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
1518 /// Note that this means this value is *not* persistent - it can change once during the
1519 /// lifetime of the channel.
1521 pub extern "C" fn ChannelDetails_set_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::ThirtyTwoBytes) {
1522 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data);
1524 /// Parameters which apply to our counterparty. See individual fields for more information.
1526 pub extern "C" fn ChannelDetails_get_counterparty(this_ptr: &ChannelDetails) -> crate::lightning::ln::channelmanager::ChannelCounterparty {
1527 let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty;
1528 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 }
1530 /// Parameters which apply to our counterparty. See individual fields for more information.
1532 pub extern "C" fn ChannelDetails_set_counterparty(this_ptr: &mut ChannelDetails, mut val: crate::lightning::ln::channelmanager::ChannelCounterparty) {
1533 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty = *unsafe { Box::from_raw(val.take_inner()) };
1535 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
1536 /// our counterparty already.
1538 /// Note that, if this has been set, `channel_id` will be equivalent to
1539 /// `funding_txo.unwrap().to_channel_id()`.
1541 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1543 pub extern "C" fn ChannelDetails_get_funding_txo(this_ptr: &ChannelDetails) -> crate::lightning::chain::transaction::OutPoint {
1544 let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_txo;
1545 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 };
1548 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
1549 /// our counterparty already.
1551 /// Note that, if this has been set, `channel_id` will be equivalent to
1552 /// `funding_txo.unwrap().to_channel_id()`.
1554 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1556 pub extern "C" fn ChannelDetails_set_funding_txo(this_ptr: &mut ChannelDetails, mut val: crate::lightning::chain::transaction::OutPoint) {
1557 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1558 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_txo = local_val;
1560 /// The features which this channel operates with. See individual features for more info.
1562 /// `None` until negotiation completes and the channel type is finalized.
1564 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1566 pub extern "C" fn ChannelDetails_get_channel_type(this_ptr: &ChannelDetails) -> crate::lightning::ln::features::ChannelTypeFeatures {
1567 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_type;
1568 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 };
1571 /// The features which this channel operates with. See individual features for more info.
1573 /// `None` until negotiation completes and the channel type is finalized.
1575 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1577 pub extern "C" fn ChannelDetails_set_channel_type(this_ptr: &mut ChannelDetails, mut val: crate::lightning::ln::features::ChannelTypeFeatures) {
1578 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1579 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_type = local_val;
1581 /// The position of the funding transaction in the chain. None if the funding transaction has
1582 /// not yet been confirmed and the channel fully opened.
1584 /// Note that if [`inbound_scid_alias`] is set, it must be used for invoices and inbound
1585 /// payments instead of this. See [`get_inbound_payment_scid`].
1587 /// For channels with [`confirmations_required`] set to `Some(0)`, [`outbound_scid_alias`] may
1588 /// be used in place of this in outbound routes. See [`get_outbound_payment_scid`].
1590 /// [`inbound_scid_alias`]: Self::inbound_scid_alias
1591 /// [`outbound_scid_alias`]: Self::outbound_scid_alias
1592 /// [`get_inbound_payment_scid`]: Self::get_inbound_payment_scid
1593 /// [`get_outbound_payment_scid`]: Self::get_outbound_payment_scid
1594 /// [`confirmations_required`]: Self::confirmations_required
1596 pub extern "C" fn ChannelDetails_get_short_channel_id(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
1597 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
1598 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() }) };
1601 /// The position of the funding transaction in the chain. None if the funding transaction has
1602 /// not yet been confirmed and the channel fully opened.
1604 /// Note that if [`inbound_scid_alias`] is set, it must be used for invoices and inbound
1605 /// payments instead of this. See [`get_inbound_payment_scid`].
1607 /// For channels with [`confirmations_required`] set to `Some(0)`, [`outbound_scid_alias`] may
1608 /// be used in place of this in outbound routes. See [`get_outbound_payment_scid`].
1610 /// [`inbound_scid_alias`]: Self::inbound_scid_alias
1611 /// [`outbound_scid_alias`]: Self::outbound_scid_alias
1612 /// [`get_inbound_payment_scid`]: Self::get_inbound_payment_scid
1613 /// [`get_outbound_payment_scid`]: Self::get_outbound_payment_scid
1614 /// [`confirmations_required`]: Self::confirmations_required
1616 pub extern "C" fn ChannelDetails_set_short_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
1617 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1618 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = local_val;
1620 /// An optional [`short_channel_id`] alias for this channel, randomly generated by us and
1621 /// usable in place of [`short_channel_id`] to reference the channel in outbound routes when
1622 /// the channel has not yet been confirmed (as long as [`confirmations_required`] is
1625 /// This will be `None` as long as the channel is not available for routing outbound payments.
1627 /// [`short_channel_id`]: Self::short_channel_id
1628 /// [`confirmations_required`]: Self::confirmations_required
1630 pub extern "C" fn ChannelDetails_get_outbound_scid_alias(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
1631 let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_scid_alias;
1632 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() }) };
1635 /// An optional [`short_channel_id`] alias for this channel, randomly generated by us and
1636 /// usable in place of [`short_channel_id`] to reference the channel in outbound routes when
1637 /// the channel has not yet been confirmed (as long as [`confirmations_required`] is
1640 /// This will be `None` as long as the channel is not available for routing outbound payments.
1642 /// [`short_channel_id`]: Self::short_channel_id
1643 /// [`confirmations_required`]: Self::confirmations_required
1645 pub extern "C" fn ChannelDetails_set_outbound_scid_alias(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
1646 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1647 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_scid_alias = local_val;
1649 /// An optional [`short_channel_id`] alias for this channel, randomly generated by our
1650 /// counterparty and usable in place of [`short_channel_id`] in invoice route hints. Our
1651 /// counterparty will recognize the alias provided here in place of the [`short_channel_id`]
1652 /// when they see a payment to be routed to us.
1654 /// Our counterparty may choose to rotate this value at any time, though will always recognize
1655 /// previous values for inbound payment forwarding.
1657 /// [`short_channel_id`]: Self::short_channel_id
1659 pub extern "C" fn ChannelDetails_get_inbound_scid_alias(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
1660 let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_scid_alias;
1661 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() }) };
1664 /// An optional [`short_channel_id`] alias for this channel, randomly generated by our
1665 /// counterparty and usable in place of [`short_channel_id`] in invoice route hints. Our
1666 /// counterparty will recognize the alias provided here in place of the [`short_channel_id`]
1667 /// when they see a payment to be routed to us.
1669 /// Our counterparty may choose to rotate this value at any time, though will always recognize
1670 /// previous values for inbound payment forwarding.
1672 /// [`short_channel_id`]: Self::short_channel_id
1674 pub extern "C" fn ChannelDetails_set_inbound_scid_alias(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
1675 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1676 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_scid_alias = local_val;
1678 /// The value, in satoshis, of this channel as appears in the funding output
1680 pub extern "C" fn ChannelDetails_get_channel_value_satoshis(this_ptr: &ChannelDetails) -> u64 {
1681 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
1684 /// The value, in satoshis, of this channel as appears in the funding output
1686 pub extern "C" fn ChannelDetails_set_channel_value_satoshis(this_ptr: &mut ChannelDetails, mut val: u64) {
1687 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
1689 /// The value, in satoshis, that must always be held in the channel for us. This value ensures
1690 /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
1691 /// this value on chain.
1693 /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
1695 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
1697 /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
1699 pub extern "C" fn ChannelDetails_get_unspendable_punishment_reserve(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
1700 let mut inner_val = &mut this_ptr.get_native_mut_ref().unspendable_punishment_reserve;
1701 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() }) };
1704 /// The value, in satoshis, that must always be held in the channel for us. This value ensures
1705 /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
1706 /// this value on chain.
1708 /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
1710 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
1712 /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
1714 pub extern "C" fn ChannelDetails_set_unspendable_punishment_reserve(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
1715 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1716 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = local_val;
1718 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
1719 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
1720 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
1721 /// `user_channel_id` will be randomized for an inbound channel. This may be zero for objects
1722 /// serialized with LDK versions prior to 0.0.113.
1724 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
1725 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1726 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
1728 pub extern "C" fn ChannelDetails_get_user_channel_id(this_ptr: &ChannelDetails) -> crate::c_types::U128 {
1729 let mut inner_val = &mut this_ptr.get_native_mut_ref().user_channel_id;
1732 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
1733 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
1734 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
1735 /// `user_channel_id` will be randomized for an inbound channel. This may be zero for objects
1736 /// serialized with LDK versions prior to 0.0.113.
1738 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
1739 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1740 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
1742 pub extern "C" fn ChannelDetails_set_user_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::U128) {
1743 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.user_channel_id = val.into();
1745 /// The currently negotiated fee rate denominated in satoshi per 1000 weight units,
1746 /// which is applied to commitment and HTLC transactions.
1748 /// This value will be `None` for objects serialized with LDK versions prior to 0.0.115.
1750 pub extern "C" fn ChannelDetails_get_feerate_sat_per_1000_weight(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u32Z {
1751 let mut inner_val = &mut this_ptr.get_native_mut_ref().feerate_sat_per_1000_weight;
1752 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() }) };
1755 /// The currently negotiated fee rate denominated in satoshi per 1000 weight units,
1756 /// which is applied to commitment and HTLC transactions.
1758 /// This value will be `None` for objects serialized with LDK versions prior to 0.0.115.
1760 pub extern "C" fn ChannelDetails_set_feerate_sat_per_1000_weight(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u32Z) {
1761 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1762 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.feerate_sat_per_1000_weight = local_val;
1764 /// Our total balance. This is the amount we would get if we close the channel.
1765 /// This value is not exact. Due to various in-flight changes and feerate changes, exactly this
1766 /// amount is not likely to be recoverable on close.
1768 /// This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose
1769 /// balance is not available for inclusion in new outbound HTLCs). This further does not include
1770 /// any pending outgoing HTLCs which are awaiting some other resolution to be sent.
1771 /// This does not consider any on-chain fees.
1773 /// See also [`ChannelDetails::outbound_capacity_msat`]
1775 pub extern "C" fn ChannelDetails_get_balance_msat(this_ptr: &ChannelDetails) -> u64 {
1776 let mut inner_val = &mut this_ptr.get_native_mut_ref().balance_msat;
1779 /// Our total balance. This is the amount we would get if we close the channel.
1780 /// This value is not exact. Due to various in-flight changes and feerate changes, exactly this
1781 /// amount is not likely to be recoverable on close.
1783 /// This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose
1784 /// balance is not available for inclusion in new outbound HTLCs). This further does not include
1785 /// any pending outgoing HTLCs which are awaiting some other resolution to be sent.
1786 /// This does not consider any on-chain fees.
1788 /// See also [`ChannelDetails::outbound_capacity_msat`]
1790 pub extern "C" fn ChannelDetails_set_balance_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
1791 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.balance_msat = val;
1793 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
1794 /// any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
1795 /// available for inclusion in new outbound HTLCs). This further does not include any pending
1796 /// outgoing HTLCs which are awaiting some other resolution to be sent.
1798 /// See also [`ChannelDetails::balance_msat`]
1800 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
1801 /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
1802 /// should be able to spend nearly this amount.
1804 pub extern "C" fn ChannelDetails_get_outbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
1805 let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_capacity_msat;
1808 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
1809 /// any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
1810 /// available for inclusion in new outbound HTLCs). This further does not include any pending
1811 /// outgoing HTLCs which are awaiting some other resolution to be sent.
1813 /// See also [`ChannelDetails::balance_msat`]
1815 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
1816 /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
1817 /// should be able to spend nearly this amount.
1819 pub extern "C" fn ChannelDetails_set_outbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
1820 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_capacity_msat = val;
1822 /// The available outbound capacity for sending a single HTLC to the remote peer. This is
1823 /// similar to [`ChannelDetails::outbound_capacity_msat`] but it may be further restricted by
1824 /// the current state and per-HTLC limit(s). This is intended for use when routing, allowing us
1825 /// to use a limit as close as possible to the HTLC limit we can currently send.
1827 /// See also [`ChannelDetails::next_outbound_htlc_minimum_msat`],
1828 /// [`ChannelDetails::balance_msat`], and [`ChannelDetails::outbound_capacity_msat`].
1830 pub extern "C" fn ChannelDetails_get_next_outbound_htlc_limit_msat(this_ptr: &ChannelDetails) -> u64 {
1831 let mut inner_val = &mut this_ptr.get_native_mut_ref().next_outbound_htlc_limit_msat;
1834 /// The available outbound capacity for sending a single HTLC to the remote peer. This is
1835 /// similar to [`ChannelDetails::outbound_capacity_msat`] but it may be further restricted by
1836 /// the current state and per-HTLC limit(s). This is intended for use when routing, allowing us
1837 /// to use a limit as close as possible to the HTLC limit we can currently send.
1839 /// See also [`ChannelDetails::next_outbound_htlc_minimum_msat`],
1840 /// [`ChannelDetails::balance_msat`], and [`ChannelDetails::outbound_capacity_msat`].
1842 pub extern "C" fn ChannelDetails_set_next_outbound_htlc_limit_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
1843 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.next_outbound_htlc_limit_msat = val;
1845 /// The minimum value for sending a single HTLC to the remote peer. This is the equivalent of
1846 /// [`ChannelDetails::next_outbound_htlc_limit_msat`] but represents a lower-bound, rather than
1847 /// an upper-bound. This is intended for use when routing, allowing us to ensure we pick a
1848 /// route which is valid.
1850 pub extern "C" fn ChannelDetails_get_next_outbound_htlc_minimum_msat(this_ptr: &ChannelDetails) -> u64 {
1851 let mut inner_val = &mut this_ptr.get_native_mut_ref().next_outbound_htlc_minimum_msat;
1854 /// The minimum value for sending a single HTLC to the remote peer. This is the equivalent of
1855 /// [`ChannelDetails::next_outbound_htlc_limit_msat`] but represents a lower-bound, rather than
1856 /// an upper-bound. This is intended for use when routing, allowing us to ensure we pick a
1857 /// route which is valid.
1859 pub extern "C" fn ChannelDetails_set_next_outbound_htlc_minimum_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
1860 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.next_outbound_htlc_minimum_msat = val;
1862 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
1863 /// include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
1864 /// available for inclusion in new inbound HTLCs).
1865 /// Note that there are some corner cases not fully handled here, so the actual available
1866 /// inbound capacity may be slightly higher than this.
1868 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
1869 /// counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
1870 /// However, our counterparty should be able to spend nearly this amount.
1872 pub extern "C" fn ChannelDetails_get_inbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
1873 let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_capacity_msat;
1876 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
1877 /// include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
1878 /// available for inclusion in new inbound HTLCs).
1879 /// Note that there are some corner cases not fully handled here, so the actual available
1880 /// inbound capacity may be slightly higher than this.
1882 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
1883 /// counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
1884 /// However, our counterparty should be able to spend nearly this amount.
1886 pub extern "C" fn ChannelDetails_set_inbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
1887 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_capacity_msat = val;
1889 /// The number of required confirmations on the funding transaction before the funding will be
1890 /// considered \"locked\". This number is selected by the channel fundee (i.e. us if
1891 /// [`is_outbound`] is *not* set), and can be selected for inbound channels with
1892 /// [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
1893 /// [`ChannelHandshakeLimits::max_minimum_depth`].
1895 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
1897 /// [`is_outbound`]: ChannelDetails::is_outbound
1898 /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
1899 /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
1901 pub extern "C" fn ChannelDetails_get_confirmations_required(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u32Z {
1902 let mut inner_val = &mut this_ptr.get_native_mut_ref().confirmations_required;
1903 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() }) };
1906 /// The number of required confirmations on the funding transaction before the funding will be
1907 /// considered \"locked\". This number is selected by the channel fundee (i.e. us if
1908 /// [`is_outbound`] is *not* set), and can be selected for inbound channels with
1909 /// [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
1910 /// [`ChannelHandshakeLimits::max_minimum_depth`].
1912 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
1914 /// [`is_outbound`]: ChannelDetails::is_outbound
1915 /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
1916 /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
1918 pub extern "C" fn ChannelDetails_set_confirmations_required(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u32Z) {
1919 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1920 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.confirmations_required = local_val;
1922 /// The current number of confirmations on the funding transaction.
1924 /// This value will be `None` for objects serialized with LDK versions prior to 0.0.113.
1926 pub extern "C" fn ChannelDetails_get_confirmations(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u32Z {
1927 let mut inner_val = &mut this_ptr.get_native_mut_ref().confirmations;
1928 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() }) };
1931 /// The current number of confirmations on the funding transaction.
1933 /// This value will be `None` for objects serialized with LDK versions prior to 0.0.113.
1935 pub extern "C" fn ChannelDetails_set_confirmations(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u32Z) {
1936 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1937 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.confirmations = local_val;
1939 /// The number of blocks (after our commitment transaction confirms) that we will need to wait
1940 /// until we can claim our funds after we force-close the channel. During this time our
1941 /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
1942 /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any
1943 /// time to claim our non-HTLC-encumbered funds.
1945 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
1947 pub extern "C" fn ChannelDetails_get_force_close_spend_delay(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u16Z {
1948 let mut inner_val = &mut this_ptr.get_native_mut_ref().force_close_spend_delay;
1949 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() }) };
1952 /// The number of blocks (after our commitment transaction confirms) that we will need to wait
1953 /// until we can claim our funds after we force-close the channel. During this time our
1954 /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
1955 /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any
1956 /// time to claim our non-HTLC-encumbered funds.
1958 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
1960 pub extern "C" fn ChannelDetails_set_force_close_spend_delay(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u16Z) {
1961 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1962 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.force_close_spend_delay = local_val;
1964 /// True if the channel was initiated (and thus funded) by us.
1966 pub extern "C" fn ChannelDetails_get_is_outbound(this_ptr: &ChannelDetails) -> bool {
1967 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_outbound;
1970 /// True if the channel was initiated (and thus funded) by us.
1972 pub extern "C" fn ChannelDetails_set_is_outbound(this_ptr: &mut ChannelDetails, mut val: bool) {
1973 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_outbound = val;
1975 /// True if the channel is confirmed, channel_ready messages have been exchanged, and the
1976 /// channel is not currently being shut down. `channel_ready` message exchange implies the
1977 /// required confirmation count has been reached (and we were connected to the peer at some
1978 /// point after the funding transaction received enough confirmations). The required
1979 /// confirmation count is provided in [`confirmations_required`].
1981 /// [`confirmations_required`]: ChannelDetails::confirmations_required
1983 pub extern "C" fn ChannelDetails_get_is_channel_ready(this_ptr: &ChannelDetails) -> bool {
1984 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_channel_ready;
1987 /// True if the channel is confirmed, channel_ready messages have been exchanged, and the
1988 /// channel is not currently being shut down. `channel_ready` message exchange implies the
1989 /// required confirmation count has been reached (and we were connected to the peer at some
1990 /// point after the funding transaction received enough confirmations). The required
1991 /// confirmation count is provided in [`confirmations_required`].
1993 /// [`confirmations_required`]: ChannelDetails::confirmations_required
1995 pub extern "C" fn ChannelDetails_set_is_channel_ready(this_ptr: &mut ChannelDetails, mut val: bool) {
1996 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_channel_ready = val;
1998 /// The stage of the channel's shutdown.
1999 /// `None` for `ChannelDetails` serialized on LDK versions prior to 0.0.116.
2001 /// Returns a copy of the field.
2003 pub extern "C" fn ChannelDetails_get_channel_shutdown_state(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_ChannelShutdownStateZ {
2004 let mut inner_val = this_ptr.get_native_mut_ref().channel_shutdown_state.clone();
2005 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()) }) };
2008 /// The stage of the channel's shutdown.
2009 /// `None` for `ChannelDetails` serialized on LDK versions prior to 0.0.116.
2011 pub extern "C" fn ChannelDetails_set_channel_shutdown_state(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_ChannelShutdownStateZ) {
2012 let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { { val_opt.take() }.into_native() }})} };
2013 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_shutdown_state = local_val;
2015 /// True if the channel is (a) confirmed and channel_ready messages have been exchanged, (b)
2016 /// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
2018 /// This is a strict superset of `is_channel_ready`.
2020 pub extern "C" fn ChannelDetails_get_is_usable(this_ptr: &ChannelDetails) -> bool {
2021 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_usable;
2024 /// True if the channel is (a) confirmed and channel_ready messages have been exchanged, (b)
2025 /// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
2027 /// This is a strict superset of `is_channel_ready`.
2029 pub extern "C" fn ChannelDetails_set_is_usable(this_ptr: &mut ChannelDetails, mut val: bool) {
2030 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_usable = val;
2032 /// True if this channel is (or will be) publicly-announced.
2034 pub extern "C" fn ChannelDetails_get_is_public(this_ptr: &ChannelDetails) -> bool {
2035 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_public;
2038 /// True if this channel is (or will be) publicly-announced.
2040 pub extern "C" fn ChannelDetails_set_is_public(this_ptr: &mut ChannelDetails, mut val: bool) {
2041 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_public = val;
2043 /// The smallest value HTLC (in msat) we will accept, for this channel. This field
2044 /// is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.107
2046 pub extern "C" fn ChannelDetails_get_inbound_htlc_minimum_msat(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
2047 let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_htlc_minimum_msat;
2048 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() }) };
2051 /// The smallest value HTLC (in msat) we will accept, for this channel. This field
2052 /// is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.107
2054 pub extern "C" fn ChannelDetails_set_inbound_htlc_minimum_msat(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
2055 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2056 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_htlc_minimum_msat = local_val;
2058 /// The largest value HTLC (in msat) we currently will accept, for this channel.
2060 pub extern "C" fn ChannelDetails_get_inbound_htlc_maximum_msat(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
2061 let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_htlc_maximum_msat;
2062 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() }) };
2065 /// The largest value HTLC (in msat) we currently will accept, for this channel.
2067 pub extern "C" fn ChannelDetails_set_inbound_htlc_maximum_msat(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
2068 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2069 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_htlc_maximum_msat = local_val;
2071 /// Set of configurable parameters that affect channel operation.
2073 /// This field is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.109.
2075 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2077 pub extern "C" fn ChannelDetails_get_config(this_ptr: &ChannelDetails) -> crate::lightning::util::config::ChannelConfig {
2078 let mut inner_val = &mut this_ptr.get_native_mut_ref().config;
2079 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 };
2082 /// Set of configurable parameters that affect channel operation.
2084 /// This field is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.109.
2086 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
2088 pub extern "C" fn ChannelDetails_set_config(this_ptr: &mut ChannelDetails, mut val: crate::lightning::util::config::ChannelConfig) {
2089 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
2090 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.config = local_val;
2092 /// Constructs a new ChannelDetails given each field
2094 /// Note that funding_txo_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
2095 /// Note that channel_type_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
2096 /// Note that config_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
2099 pub extern "C" fn ChannelDetails_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut counterparty_arg: crate::lightning::ln::channelmanager::ChannelCounterparty, mut funding_txo_arg: crate::lightning::chain::transaction::OutPoint, mut channel_type_arg: crate::lightning::ln::features::ChannelTypeFeatures, mut short_channel_id_arg: crate::c_types::derived::COption_u64Z, mut outbound_scid_alias_arg: crate::c_types::derived::COption_u64Z, mut inbound_scid_alias_arg: crate::c_types::derived::COption_u64Z, mut channel_value_satoshis_arg: u64, mut unspendable_punishment_reserve_arg: crate::c_types::derived::COption_u64Z, mut user_channel_id_arg: crate::c_types::U128, mut feerate_sat_per_1000_weight_arg: crate::c_types::derived::COption_u32Z, mut balance_msat_arg: u64, mut outbound_capacity_msat_arg: u64, mut next_outbound_htlc_limit_msat_arg: u64, mut next_outbound_htlc_minimum_msat_arg: u64, mut inbound_capacity_msat_arg: u64, mut confirmations_required_arg: crate::c_types::derived::COption_u32Z, mut confirmations_arg: crate::c_types::derived::COption_u32Z, mut force_close_spend_delay_arg: crate::c_types::derived::COption_u16Z, mut is_outbound_arg: bool, mut is_channel_ready_arg: bool, mut channel_shutdown_state_arg: crate::c_types::derived::COption_ChannelShutdownStateZ, mut is_usable_arg: bool, mut is_public_arg: bool, mut inbound_htlc_minimum_msat_arg: crate::c_types::derived::COption_u64Z, mut inbound_htlc_maximum_msat_arg: crate::c_types::derived::COption_u64Z, mut config_arg: crate::lightning::util::config::ChannelConfig) -> ChannelDetails {
2100 let mut local_funding_txo_arg = if funding_txo_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(funding_txo_arg.take_inner()) } }) };
2101 let mut local_channel_type_arg = if channel_type_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(channel_type_arg.take_inner()) } }) };
2102 let mut local_short_channel_id_arg = if short_channel_id_arg.is_some() { Some( { short_channel_id_arg.take() }) } else { None };
2103 let mut local_outbound_scid_alias_arg = if outbound_scid_alias_arg.is_some() { Some( { outbound_scid_alias_arg.take() }) } else { None };
2104 let mut local_inbound_scid_alias_arg = if inbound_scid_alias_arg.is_some() { Some( { inbound_scid_alias_arg.take() }) } else { None };
2105 let mut local_unspendable_punishment_reserve_arg = if unspendable_punishment_reserve_arg.is_some() { Some( { unspendable_punishment_reserve_arg.take() }) } else { None };
2106 let mut local_feerate_sat_per_1000_weight_arg = if feerate_sat_per_1000_weight_arg.is_some() { Some( { feerate_sat_per_1000_weight_arg.take() }) } else { None };
2107 let mut local_confirmations_required_arg = if confirmations_required_arg.is_some() { Some( { confirmations_required_arg.take() }) } else { None };
2108 let mut local_confirmations_arg = if confirmations_arg.is_some() { Some( { confirmations_arg.take() }) } else { None };
2109 let mut local_force_close_spend_delay_arg = if force_close_spend_delay_arg.is_some() { Some( { force_close_spend_delay_arg.take() }) } else { None };
2110 let mut local_channel_shutdown_state_arg = { /*channel_shutdown_state_arg*/ let channel_shutdown_state_arg_opt = channel_shutdown_state_arg; if channel_shutdown_state_arg_opt.is_none() { None } else { Some({ { { channel_shutdown_state_arg_opt.take() }.into_native() }})} };
2111 let mut local_inbound_htlc_minimum_msat_arg = if inbound_htlc_minimum_msat_arg.is_some() { Some( { inbound_htlc_minimum_msat_arg.take() }) } else { None };
2112 let mut local_inbound_htlc_maximum_msat_arg = if inbound_htlc_maximum_msat_arg.is_some() { Some( { inbound_htlc_maximum_msat_arg.take() }) } else { None };
2113 let mut local_config_arg = if config_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(config_arg.take_inner()) } }) };
2114 ChannelDetails { inner: ObjOps::heap_alloc(nativeChannelDetails {
2115 channel_id: ::lightning::ln::ChannelId(channel_id_arg.data),
2116 counterparty: *unsafe { Box::from_raw(counterparty_arg.take_inner()) },
2117 funding_txo: local_funding_txo_arg,
2118 channel_type: local_channel_type_arg,
2119 short_channel_id: local_short_channel_id_arg,
2120 outbound_scid_alias: local_outbound_scid_alias_arg,
2121 inbound_scid_alias: local_inbound_scid_alias_arg,
2122 channel_value_satoshis: channel_value_satoshis_arg,
2123 unspendable_punishment_reserve: local_unspendable_punishment_reserve_arg,
2124 user_channel_id: user_channel_id_arg.into(),
2125 feerate_sat_per_1000_weight: local_feerate_sat_per_1000_weight_arg,
2126 balance_msat: balance_msat_arg,
2127 outbound_capacity_msat: outbound_capacity_msat_arg,
2128 next_outbound_htlc_limit_msat: next_outbound_htlc_limit_msat_arg,
2129 next_outbound_htlc_minimum_msat: next_outbound_htlc_minimum_msat_arg,
2130 inbound_capacity_msat: inbound_capacity_msat_arg,
2131 confirmations_required: local_confirmations_required_arg,
2132 confirmations: local_confirmations_arg,
2133 force_close_spend_delay: local_force_close_spend_delay_arg,
2134 is_outbound: is_outbound_arg,
2135 is_channel_ready: is_channel_ready_arg,
2136 channel_shutdown_state: local_channel_shutdown_state_arg,
2137 is_usable: is_usable_arg,
2138 is_public: is_public_arg,
2139 inbound_htlc_minimum_msat: local_inbound_htlc_minimum_msat_arg,
2140 inbound_htlc_maximum_msat: local_inbound_htlc_maximum_msat_arg,
2141 config: local_config_arg,
2142 }), is_owned: true }
2144 impl Clone for ChannelDetails {
2145 fn clone(&self) -> Self {
2147 inner: if <*mut nativeChannelDetails>::is_null(self.inner) { core::ptr::null_mut() } else {
2148 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2154 /// Used only if an object of this type is returned as a trait impl by a method
2155 pub(crate) extern "C" fn ChannelDetails_clone_void(this_ptr: *const c_void) -> *mut c_void {
2156 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelDetails)).clone() })) as *mut c_void
2159 /// Creates a copy of the ChannelDetails
2160 pub extern "C" fn ChannelDetails_clone(orig: &ChannelDetails) -> ChannelDetails {
2163 /// Get a string which allows debug introspection of a ChannelDetails object
2164 pub extern "C" fn ChannelDetails_debug_str_void(o: *const c_void) -> Str {
2165 alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channelmanager::ChannelDetails }).into()}
2166 /// Gets the current SCID which should be used to identify this channel for inbound payments.
2167 /// This should be used for providing invoice hints or in any other context where our
2168 /// counterparty will forward a payment to us.
2170 /// This is either the [`ChannelDetails::inbound_scid_alias`], if set, or the
2171 /// [`ChannelDetails::short_channel_id`]. See those for more information.
2174 pub extern "C" fn ChannelDetails_get_inbound_payment_scid(this_arg: &crate::lightning::ln::channelmanager::ChannelDetails) -> crate::c_types::derived::COption_u64Z {
2175 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_inbound_payment_scid();
2176 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() }) };
2180 /// Gets the current SCID which should be used to identify this channel for outbound payments.
2181 /// This should be used in [`Route`]s to describe the first hop or in other contexts where
2182 /// we're sending or forwarding a payment outbound over this channel.
2184 /// This is either the [`ChannelDetails::short_channel_id`], if set, or the
2185 /// [`ChannelDetails::outbound_scid_alias`]. See those for more information.
2188 pub extern "C" fn ChannelDetails_get_outbound_payment_scid(this_arg: &crate::lightning::ln::channelmanager::ChannelDetails) -> crate::c_types::derived::COption_u64Z {
2189 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_outbound_payment_scid();
2190 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() }) };
2194 /// Further information on the details of the channel shutdown.
2195 /// Upon channels being forced closed (i.e. commitment transaction confirmation detected
2196 /// by `ChainMonitor`), ChannelShutdownState will be set to `ShutdownComplete` or
2197 /// the channel will be removed shortly.
2198 /// Also note, that in normal operation, peers could disconnect at any of these states
2199 /// and require peer re-connection before making progress onto other states
2203 pub enum ChannelShutdownState {
2204 /// Channel has not sent or received a shutdown message.
2206 /// Local node has sent a shutdown message for this channel.
2208 /// Shutdown message exchanges have concluded and the channels are in the midst of
2209 /// resolving all existing open HTLCs before closing can continue.
2211 /// All HTLCs have been resolved, nodes are currently negotiating channel close onchain fee rates.
2212 NegotiatingClosingFee,
2213 /// We've successfully negotiated a closing_signed dance. At this point `ChannelManager` is about
2214 /// to drop the channel.
2217 use lightning::ln::channelmanager::ChannelShutdownState as ChannelShutdownStateImport;
2218 pub(crate) type nativeChannelShutdownState = ChannelShutdownStateImport;
2220 impl ChannelShutdownState {
2222 pub(crate) fn to_native(&self) -> nativeChannelShutdownState {
2224 ChannelShutdownState::NotShuttingDown => nativeChannelShutdownState::NotShuttingDown,
2225 ChannelShutdownState::ShutdownInitiated => nativeChannelShutdownState::ShutdownInitiated,
2226 ChannelShutdownState::ResolvingHTLCs => nativeChannelShutdownState::ResolvingHTLCs,
2227 ChannelShutdownState::NegotiatingClosingFee => nativeChannelShutdownState::NegotiatingClosingFee,
2228 ChannelShutdownState::ShutdownComplete => nativeChannelShutdownState::ShutdownComplete,
2232 pub(crate) fn into_native(self) -> nativeChannelShutdownState {
2234 ChannelShutdownState::NotShuttingDown => nativeChannelShutdownState::NotShuttingDown,
2235 ChannelShutdownState::ShutdownInitiated => nativeChannelShutdownState::ShutdownInitiated,
2236 ChannelShutdownState::ResolvingHTLCs => nativeChannelShutdownState::ResolvingHTLCs,
2237 ChannelShutdownState::NegotiatingClosingFee => nativeChannelShutdownState::NegotiatingClosingFee,
2238 ChannelShutdownState::ShutdownComplete => nativeChannelShutdownState::ShutdownComplete,
2242 pub(crate) fn from_native(native: &ChannelShutdownStateImport) -> Self {
2243 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeChannelShutdownState) };
2245 nativeChannelShutdownState::NotShuttingDown => ChannelShutdownState::NotShuttingDown,
2246 nativeChannelShutdownState::ShutdownInitiated => ChannelShutdownState::ShutdownInitiated,
2247 nativeChannelShutdownState::ResolvingHTLCs => ChannelShutdownState::ResolvingHTLCs,
2248 nativeChannelShutdownState::NegotiatingClosingFee => ChannelShutdownState::NegotiatingClosingFee,
2249 nativeChannelShutdownState::ShutdownComplete => ChannelShutdownState::ShutdownComplete,
2253 pub(crate) fn native_into(native: nativeChannelShutdownState) -> Self {
2255 nativeChannelShutdownState::NotShuttingDown => ChannelShutdownState::NotShuttingDown,
2256 nativeChannelShutdownState::ShutdownInitiated => ChannelShutdownState::ShutdownInitiated,
2257 nativeChannelShutdownState::ResolvingHTLCs => ChannelShutdownState::ResolvingHTLCs,
2258 nativeChannelShutdownState::NegotiatingClosingFee => ChannelShutdownState::NegotiatingClosingFee,
2259 nativeChannelShutdownState::ShutdownComplete => ChannelShutdownState::ShutdownComplete,
2263 /// Creates a copy of the ChannelShutdownState
2265 pub extern "C" fn ChannelShutdownState_clone(orig: &ChannelShutdownState) -> ChannelShutdownState {
2269 /// Used only if an object of this type is returned as a trait impl by a method
2270 pub(crate) extern "C" fn ChannelShutdownState_clone_void(this_ptr: *const c_void) -> *mut c_void {
2271 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const ChannelShutdownState)).clone() })) as *mut c_void
2274 /// Used only if an object of this type is returned as a trait impl by a method
2275 pub(crate) extern "C" fn ChannelShutdownState_free_void(this_ptr: *mut c_void) {
2276 let _ = unsafe { Box::from_raw(this_ptr as *mut ChannelShutdownState) };
2279 /// Utility method to constructs a new NotShuttingDown-variant ChannelShutdownState
2280 pub extern "C" fn ChannelShutdownState_not_shutting_down() -> ChannelShutdownState {
2281 ChannelShutdownState::NotShuttingDown}
2283 /// Utility method to constructs a new ShutdownInitiated-variant ChannelShutdownState
2284 pub extern "C" fn ChannelShutdownState_shutdown_initiated() -> ChannelShutdownState {
2285 ChannelShutdownState::ShutdownInitiated}
2287 /// Utility method to constructs a new ResolvingHTLCs-variant ChannelShutdownState
2288 pub extern "C" fn ChannelShutdownState_resolving_htlcs() -> ChannelShutdownState {
2289 ChannelShutdownState::ResolvingHTLCs}
2291 /// Utility method to constructs a new NegotiatingClosingFee-variant ChannelShutdownState
2292 pub extern "C" fn ChannelShutdownState_negotiating_closing_fee() -> ChannelShutdownState {
2293 ChannelShutdownState::NegotiatingClosingFee}
2295 /// Utility method to constructs a new ShutdownComplete-variant ChannelShutdownState
2296 pub extern "C" fn ChannelShutdownState_shutdown_complete() -> ChannelShutdownState {
2297 ChannelShutdownState::ShutdownComplete}
2298 /// Get a string which allows debug introspection of a ChannelShutdownState object
2299 pub extern "C" fn ChannelShutdownState_debug_str_void(o: *const c_void) -> Str {
2300 alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channelmanager::ChannelShutdownState }).into()}
2301 /// Checks if two ChannelShutdownStates contain equal inner contents.
2302 /// This ignores pointers and is_owned flags and looks at the values in fields.
2304 pub extern "C" fn ChannelShutdownState_eq(a: &ChannelShutdownState, b: &ChannelShutdownState) -> bool {
2305 if &a.to_native() == &b.to_native() { true } else { false }
2307 /// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
2308 /// These include payments that have yet to find a successful path, or have unresolved HTLCs.
2312 pub enum RecentPaymentDetails {
2313 /// When an invoice was requested and thus a payment has not yet been sent.
2315 /// A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify
2316 /// a payment and ensure idempotency in LDK.
2317 payment_id: crate::c_types::ThirtyTwoBytes,
2319 /// When a payment is still being sent and awaiting successful delivery.
2321 /// A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify
2322 /// a payment and ensure idempotency in LDK.
2323 payment_id: crate::c_types::ThirtyTwoBytes,
2324 /// Hash of the payment that is currently being sent but has yet to be fulfilled or
2326 payment_hash: crate::c_types::ThirtyTwoBytes,
2327 /// Total amount (in msat, excluding fees) across all paths for this payment,
2328 /// not just the amount currently inflight.
2331 /// When a pending payment is fulfilled, we continue tracking it until all pending HTLCs have
2332 /// been resolved. Upon receiving [`Event::PaymentSent`], we delay for a few minutes before the
2333 /// payment is removed from tracking.
2335 /// A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify
2336 /// a payment and ensure idempotency in LDK.
2337 payment_id: crate::c_types::ThirtyTwoBytes,
2338 /// Hash of the payment that was claimed. `None` for serializations of [`ChannelManager`]
2339 /// made before LDK version 0.0.104.
2340 payment_hash: crate::c_types::derived::COption_ThirtyTwoBytesZ,
2342 /// After a payment's retries are exhausted per the provided [`Retry`], or it is explicitly
2343 /// abandoned via [`ChannelManager::abandon_payment`], it is marked as abandoned until all
2344 /// pending HTLCs for this payment resolve and an [`Event::PaymentFailed`] is generated.
2346 /// A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify
2347 /// a payment and ensure idempotency in LDK.
2348 payment_id: crate::c_types::ThirtyTwoBytes,
2349 /// Hash of the payment that we have given up trying to send.
2350 payment_hash: crate::c_types::ThirtyTwoBytes,
2353 use lightning::ln::channelmanager::RecentPaymentDetails as RecentPaymentDetailsImport;
2354 pub(crate) type nativeRecentPaymentDetails = RecentPaymentDetailsImport;
2356 impl RecentPaymentDetails {
2358 pub(crate) fn to_native(&self) -> nativeRecentPaymentDetails {
2360 RecentPaymentDetails::AwaitingInvoice {ref payment_id, } => {
2361 let mut payment_id_nonref = Clone::clone(payment_id);
2362 nativeRecentPaymentDetails::AwaitingInvoice {
2363 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
2366 RecentPaymentDetails::Pending {ref payment_id, ref payment_hash, ref total_msat, } => {
2367 let mut payment_id_nonref = Clone::clone(payment_id);
2368 let mut payment_hash_nonref = Clone::clone(payment_hash);
2369 let mut total_msat_nonref = Clone::clone(total_msat);
2370 nativeRecentPaymentDetails::Pending {
2371 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
2372 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
2373 total_msat: total_msat_nonref,
2376 RecentPaymentDetails::Fulfilled {ref payment_id, ref payment_hash, } => {
2377 let mut payment_id_nonref = Clone::clone(payment_id);
2378 let mut payment_hash_nonref = Clone::clone(payment_hash);
2379 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::PaymentHash({ payment_hash_nonref_opt.take() }.data) }})} };
2380 nativeRecentPaymentDetails::Fulfilled {
2381 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
2382 payment_hash: local_payment_hash_nonref,
2385 RecentPaymentDetails::Abandoned {ref payment_id, ref payment_hash, } => {
2386 let mut payment_id_nonref = Clone::clone(payment_id);
2387 let mut payment_hash_nonref = Clone::clone(payment_hash);
2388 nativeRecentPaymentDetails::Abandoned {
2389 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
2390 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
2396 pub(crate) fn into_native(self) -> nativeRecentPaymentDetails {
2398 RecentPaymentDetails::AwaitingInvoice {mut payment_id, } => {
2399 nativeRecentPaymentDetails::AwaitingInvoice {
2400 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
2403 RecentPaymentDetails::Pending {mut payment_id, mut payment_hash, mut total_msat, } => {
2404 nativeRecentPaymentDetails::Pending {
2405 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
2406 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
2407 total_msat: total_msat,
2410 RecentPaymentDetails::Fulfilled {mut payment_id, mut payment_hash, } => {
2411 let mut local_payment_hash = { /*payment_hash*/ let payment_hash_opt = payment_hash; if payment_hash_opt.is_none() { None } else { Some({ { ::lightning::ln::PaymentHash({ payment_hash_opt.take() }.data) }})} };
2412 nativeRecentPaymentDetails::Fulfilled {
2413 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
2414 payment_hash: local_payment_hash,
2417 RecentPaymentDetails::Abandoned {mut payment_id, mut payment_hash, } => {
2418 nativeRecentPaymentDetails::Abandoned {
2419 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
2420 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
2426 pub(crate) fn from_native(native: &RecentPaymentDetailsImport) -> Self {
2427 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeRecentPaymentDetails) };
2429 nativeRecentPaymentDetails::AwaitingInvoice {ref payment_id, } => {
2430 let mut payment_id_nonref = Clone::clone(payment_id);
2431 RecentPaymentDetails::AwaitingInvoice {
2432 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
2435 nativeRecentPaymentDetails::Pending {ref payment_id, ref payment_hash, ref total_msat, } => {
2436 let mut payment_id_nonref = Clone::clone(payment_id);
2437 let mut payment_hash_nonref = Clone::clone(payment_hash);
2438 let mut total_msat_nonref = Clone::clone(total_msat);
2439 RecentPaymentDetails::Pending {
2440 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
2441 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
2442 total_msat: total_msat_nonref,
2445 nativeRecentPaymentDetails::Fulfilled {ref payment_id, ref payment_hash, } => {
2446 let mut payment_id_nonref = Clone::clone(payment_id);
2447 let mut payment_hash_nonref = Clone::clone(payment_hash);
2448 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 } }) };
2449 RecentPaymentDetails::Fulfilled {
2450 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
2451 payment_hash: local_payment_hash_nonref,
2454 nativeRecentPaymentDetails::Abandoned {ref payment_id, ref payment_hash, } => {
2455 let mut payment_id_nonref = Clone::clone(payment_id);
2456 let mut payment_hash_nonref = Clone::clone(payment_hash);
2457 RecentPaymentDetails::Abandoned {
2458 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
2459 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
2465 pub(crate) fn native_into(native: nativeRecentPaymentDetails) -> Self {
2467 nativeRecentPaymentDetails::AwaitingInvoice {mut payment_id, } => {
2468 RecentPaymentDetails::AwaitingInvoice {
2469 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
2472 nativeRecentPaymentDetails::Pending {mut payment_id, mut payment_hash, mut total_msat, } => {
2473 RecentPaymentDetails::Pending {
2474 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
2475 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
2476 total_msat: total_msat,
2479 nativeRecentPaymentDetails::Fulfilled {mut payment_id, mut payment_hash, } => {
2480 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 } }) };
2481 RecentPaymentDetails::Fulfilled {
2482 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
2483 payment_hash: local_payment_hash,
2486 nativeRecentPaymentDetails::Abandoned {mut payment_id, mut payment_hash, } => {
2487 RecentPaymentDetails::Abandoned {
2488 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
2489 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
2495 /// Frees any resources used by the RecentPaymentDetails
2497 pub extern "C" fn RecentPaymentDetails_free(this_ptr: RecentPaymentDetails) { }
2498 /// Creates a copy of the RecentPaymentDetails
2500 pub extern "C" fn RecentPaymentDetails_clone(orig: &RecentPaymentDetails) -> RecentPaymentDetails {
2504 /// Used only if an object of this type is returned as a trait impl by a method
2505 pub(crate) extern "C" fn RecentPaymentDetails_clone_void(this_ptr: *const c_void) -> *mut c_void {
2506 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const RecentPaymentDetails)).clone() })) as *mut c_void
2509 /// Used only if an object of this type is returned as a trait impl by a method
2510 pub(crate) extern "C" fn RecentPaymentDetails_free_void(this_ptr: *mut c_void) {
2511 let _ = unsafe { Box::from_raw(this_ptr as *mut RecentPaymentDetails) };
2514 /// Utility method to constructs a new AwaitingInvoice-variant RecentPaymentDetails
2515 pub extern "C" fn RecentPaymentDetails_awaiting_invoice(payment_id: crate::c_types::ThirtyTwoBytes) -> RecentPaymentDetails {
2516 RecentPaymentDetails::AwaitingInvoice {
2521 /// Utility method to constructs a new Pending-variant RecentPaymentDetails
2522 pub extern "C" fn RecentPaymentDetails_pending(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, total_msat: u64) -> RecentPaymentDetails {
2523 RecentPaymentDetails::Pending {
2530 /// Utility method to constructs a new Fulfilled-variant RecentPaymentDetails
2531 pub extern "C" fn RecentPaymentDetails_fulfilled(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::derived::COption_ThirtyTwoBytesZ) -> RecentPaymentDetails {
2532 RecentPaymentDetails::Fulfilled {
2538 /// Utility method to constructs a new Abandoned-variant RecentPaymentDetails
2539 pub extern "C" fn RecentPaymentDetails_abandoned(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes) -> RecentPaymentDetails {
2540 RecentPaymentDetails::Abandoned {
2545 /// Get a string which allows debug introspection of a RecentPaymentDetails object
2546 pub extern "C" fn RecentPaymentDetails_debug_str_void(o: *const c_void) -> Str {
2547 alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channelmanager::RecentPaymentDetails }).into()}
2549 use lightning::ln::channelmanager::PhantomRouteHints as nativePhantomRouteHintsImport;
2550 pub(crate) type nativePhantomRouteHints = nativePhantomRouteHintsImport;
2552 /// Route hints used in constructing invoices for [phantom node payents].
2554 /// [phantom node payments]: crate::sign::PhantomKeysManager
2557 pub struct PhantomRouteHints {
2558 /// A pointer to the opaque Rust object.
2560 /// Nearly everywhere, inner must be non-null, however in places where
2561 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2562 pub inner: *mut nativePhantomRouteHints,
2563 /// Indicates that this is the only struct which contains the same pointer.
2565 /// Rust functions which take ownership of an object provided via an argument require
2566 /// this to be true and invalidate the object pointed to by inner.
2570 impl Drop for PhantomRouteHints {
2571 fn drop(&mut self) {
2572 if self.is_owned && !<*mut nativePhantomRouteHints>::is_null(self.inner) {
2573 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2577 /// Frees any resources used by the PhantomRouteHints, if is_owned is set and inner is non-NULL.
2579 pub extern "C" fn PhantomRouteHints_free(this_obj: PhantomRouteHints) { }
2581 /// Used only if an object of this type is returned as a trait impl by a method
2582 pub(crate) extern "C" fn PhantomRouteHints_free_void(this_ptr: *mut c_void) {
2583 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePhantomRouteHints) };
2586 impl PhantomRouteHints {
2587 pub(crate) fn get_native_ref(&self) -> &'static nativePhantomRouteHints {
2588 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2590 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePhantomRouteHints {
2591 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2593 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2594 pub(crate) fn take_inner(mut self) -> *mut nativePhantomRouteHints {
2595 assert!(self.is_owned);
2596 let ret = ObjOps::untweak_ptr(self.inner);
2597 self.inner = core::ptr::null_mut();
2601 /// The list of channels to be included in the invoice route hints.
2603 pub extern "C" fn PhantomRouteHints_get_channels(this_ptr: &PhantomRouteHints) -> crate::c_types::derived::CVec_ChannelDetailsZ {
2604 let mut inner_val = &mut this_ptr.get_native_mut_ref().channels;
2605 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 } }); };
2606 local_inner_val.into()
2608 /// The list of channels to be included in the invoice route hints.
2610 pub extern "C" fn PhantomRouteHints_set_channels(this_ptr: &mut PhantomRouteHints, mut val: crate::c_types::derived::CVec_ChannelDetailsZ) {
2611 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
2612 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val;
2614 /// A fake scid used for representing the phantom node's fake channel in generating the invoice
2617 pub extern "C" fn PhantomRouteHints_get_phantom_scid(this_ptr: &PhantomRouteHints) -> u64 {
2618 let mut inner_val = &mut this_ptr.get_native_mut_ref().phantom_scid;
2621 /// A fake scid used for representing the phantom node's fake channel in generating the invoice
2624 pub extern "C" fn PhantomRouteHints_set_phantom_scid(this_ptr: &mut PhantomRouteHints, mut val: u64) {
2625 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.phantom_scid = val;
2627 /// The pubkey of the real backing node that would ultimately receive the payment.
2629 pub extern "C" fn PhantomRouteHints_get_real_node_pubkey(this_ptr: &PhantomRouteHints) -> crate::c_types::PublicKey {
2630 let mut inner_val = &mut this_ptr.get_native_mut_ref().real_node_pubkey;
2631 crate::c_types::PublicKey::from_rust(&inner_val)
2633 /// The pubkey of the real backing node that would ultimately receive the payment.
2635 pub extern "C" fn PhantomRouteHints_set_real_node_pubkey(this_ptr: &mut PhantomRouteHints, mut val: crate::c_types::PublicKey) {
2636 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.real_node_pubkey = val.into_rust();
2638 /// Constructs a new PhantomRouteHints given each field
2641 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 {
2642 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()) } }); };
2643 PhantomRouteHints { inner: ObjOps::heap_alloc(nativePhantomRouteHints {
2644 channels: local_channels_arg,
2645 phantom_scid: phantom_scid_arg,
2646 real_node_pubkey: real_node_pubkey_arg.into_rust(),
2647 }), is_owned: true }
2649 impl Clone for PhantomRouteHints {
2650 fn clone(&self) -> Self {
2652 inner: if <*mut nativePhantomRouteHints>::is_null(self.inner) { core::ptr::null_mut() } else {
2653 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2659 /// Used only if an object of this type is returned as a trait impl by a method
2660 pub(crate) extern "C" fn PhantomRouteHints_clone_void(this_ptr: *const c_void) -> *mut c_void {
2661 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePhantomRouteHints)).clone() })) as *mut c_void
2664 /// Creates a copy of the PhantomRouteHints
2665 pub extern "C" fn PhantomRouteHints_clone(orig: &PhantomRouteHints) -> PhantomRouteHints {
2668 /// Constructs a new `ChannelManager` to hold several channels and route between them.
2670 /// The current time or latest block header time can be provided as the `current_timestamp`.
2672 /// This is the main \"logic hub\" for all channel-related actions, and implements
2673 /// [`ChannelMessageHandler`].
2675 /// Non-proportional fees are fixed according to our risk using the provided fee estimator.
2677 /// Users need to notify the new `ChannelManager` when a new block is connected or
2678 /// disconnected using its [`block_connected`] and [`block_disconnected`] methods, starting
2679 /// from after [`params.best_block.block_hash`]. See [`chain::Listen`] and [`chain::Confirm`] for
2682 /// [`block_connected`]: chain::Listen::block_connected
2683 /// [`block_disconnected`]: chain::Listen::block_disconnected
2684 /// [`params.best_block.block_hash`]: chain::BestBlock::block_hash
2687 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 {
2688 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);
2689 crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
2692 /// Gets the current configuration applied to all new channels.
2695 pub extern "C" fn ChannelManager_get_current_default_configuration(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::util::config::UserConfig {
2696 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_current_default_configuration();
2697 crate::lightning::util::config::UserConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::util::config::UserConfig<>) as *mut _) }, is_owned: false }
2700 /// Creates a new outbound channel to the given remote node and with the given value.
2702 /// `user_channel_id` will be provided back as in
2703 /// [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
2704 /// correspond with which `create_channel` call. Note that the `user_channel_id` defaults to a
2705 /// randomized value for inbound channels. `user_channel_id` has no meaning inside of LDK, it
2706 /// is simply copied to events and otherwise ignored.
2708 /// Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is
2709 /// greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`.
2711 /// Raises [`APIError::ChannelUnavailable`] if the channel cannot be opened due to failing to
2712 /// generate a shutdown scriptpubkey or destination script set by
2713 /// [`SignerProvider::get_shutdown_scriptpubkey`] or [`SignerProvider::get_destination_script`].
2715 /// Note that we do not check if you are currently connected to the given peer. If no
2716 /// connection is available, the outbound `open_channel` message may fail to send, resulting in
2717 /// the channel eventually being silently forgotten (dropped on reload).
2719 /// If `temporary_channel_id` is specified, it will be used as the temporary channel ID of the
2720 /// channel. Otherwise, a random one will be generated for you.
2722 /// Returns the new Channel's temporary `channel_id`. This ID will appear as
2723 /// [`Event::FundingGenerationReady::temporary_channel_id`] and in
2724 /// [`ChannelDetails::channel_id`] until after
2725 /// [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
2726 /// one derived from the funding transaction's TXID. If the counterparty rejects the channel
2727 /// immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
2729 /// [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
2730 /// [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
2731 /// [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
2733 /// Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
2736 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::c_types::derived::COption_ThirtyTwoBytesZ, mut override_config: crate::lightning::util::config::UserConfig) -> crate::c_types::derived::CResult_ThirtyTwoBytesAPIErrorZ {
2737 let mut local_temporary_channel_id = { /*temporary_channel_id*/ let temporary_channel_id_opt = temporary_channel_id; if temporary_channel_id_opt.is_none() { None } else { Some({ { ::lightning::ln::ChannelId({ temporary_channel_id_opt.take() }.data) }})} };
2738 let mut local_override_config = if override_config.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(override_config.take_inner()) } }) };
2739 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);
2740 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() };
2744 /// Gets the list of open channels, in random order. See [`ChannelDetails`] field documentation for
2745 /// more information.
2748 pub extern "C" fn ChannelManager_list_channels(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
2749 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_channels();
2750 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 } }); };
2754 /// Gets the list of usable channels, in random order. Useful as an argument to
2755 /// [`Router::find_route`] to ensure non-announced channels are used.
2757 /// These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
2758 /// documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
2762 pub extern "C" fn ChannelManager_list_usable_channels(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
2763 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_usable_channels();
2764 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 } }); };
2768 /// Gets the list of channels we have with a given counterparty, in random order.
2771 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 {
2772 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_channels_with_counterparty(&counterparty_node_id.into_rust());
2773 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 } }); };
2777 /// Returns in an undefined order recent payments that -- if not fulfilled -- have yet to find a
2778 /// successful path, or have unresolved HTLCs.
2780 /// This can be useful for payments that may have been prepared, but ultimately not sent, as a
2781 /// result of a crash. If such a payment exists, is not listed here, and an
2782 /// [`Event::PaymentSent`] has not been received, you may consider resending the payment.
2784 /// [`Event::PaymentSent`]: events::Event::PaymentSent
2787 pub extern "C" fn ChannelManager_list_recent_payments(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_RecentPaymentDetailsZ {
2788 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_recent_payments();
2789 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::channelmanager::RecentPaymentDetails::native_into(item) }); };
2793 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
2794 /// will be accepted on the given channel, and after additional timeout/the closing of all
2795 /// pending HTLCs, the channel will be closed on chain.
2797 /// * If we are the channel initiator, we will pay between our [`ChannelCloseMinimum`] and
2798 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`NonAnchorChannelFee`]
2800 /// * If our counterparty is the channel initiator, we will require a channel closing
2801 /// transaction feerate of at least our [`ChannelCloseMinimum`] feerate or the feerate which
2802 /// would appear on a force-closure transaction, whichever is lower. We will allow our
2803 /// counterparty to pay as much fee as they'd like, however.
2805 /// May generate a [`SendShutdown`] message event on success, which should be relayed.
2807 /// Raises [`APIError::ChannelUnavailable`] if the channel cannot be closed due to failing to
2808 /// generate a shutdown scriptpubkey or destination script set by
2809 /// [`SignerProvider::get_shutdown_scriptpubkey`]. A force-closure may be needed to close the
2812 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
2813 /// [`ChannelCloseMinimum`]: crate::chain::chaininterface::ConfirmationTarget::ChannelCloseMinimum
2814 /// [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee
2815 /// [`SendShutdown`]: crate::events::MessageSendEvent::SendShutdown
2818 pub extern "C" fn ChannelManager_close_channel(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, channel_id: *const [u8; 32], mut counterparty_node_id: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
2819 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel(&::lightning::ln::ChannelId(unsafe { *channel_id }), &counterparty_node_id.into_rust());
2820 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() };
2824 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
2825 /// will be accepted on the given channel, and after additional timeout/the closing of all
2826 /// pending HTLCs, the channel will be closed on chain.
2828 /// `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
2829 /// the channel being closed or not:
2830 /// * If we are the channel initiator, we will pay at least this feerate on the closing
2831 /// transaction. The upper-bound is set by
2832 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`NonAnchorChannelFee`]
2833 /// fee estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
2834 /// * If our counterparty is the channel initiator, we will refuse to accept a channel closure
2835 /// transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
2836 /// will appear on a force-closure transaction, whichever is lower).
2838 /// The `shutdown_script` provided will be used as the `scriptPubKey` for the closing transaction.
2839 /// Will fail if a shutdown script has already been set for this channel by
2840 /// ['ChannelHandshakeConfig::commit_upfront_shutdown_pubkey`]. The given shutdown script must
2841 /// also be compatible with our and the counterparty's features.
2843 /// May generate a [`SendShutdown`] message event on success, which should be relayed.
2845 /// Raises [`APIError::ChannelUnavailable`] if the channel cannot be closed due to failing to
2846 /// generate a shutdown scriptpubkey or destination script set by
2847 /// [`SignerProvider::get_shutdown_scriptpubkey`]. A force-closure may be needed to close the
2850 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
2851 /// [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee
2852 /// [`SendShutdown`]: crate::events::MessageSendEvent::SendShutdown
2854 /// Note that shutdown_script (or a relevant inner pointer) may be NULL or all-0s to represent None
2857 pub extern "C" fn ChannelManager_close_channel_with_feerate_and_script(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, channel_id: *const [u8; 32], 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 {
2858 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 };
2859 let mut local_shutdown_script = if shutdown_script.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(shutdown_script.take_inner()) } }) };
2860 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel_with_feerate_and_script(&::lightning::ln::ChannelId(unsafe { *channel_id }), &counterparty_node_id.into_rust(), local_target_feerate_sats_per_1000_weight, local_shutdown_script);
2861 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() };
2865 /// Force closes a channel, immediately broadcasting the latest local transaction(s) and
2866 /// rejecting new HTLCs on the given channel. Fails if `channel_id` is unknown to
2867 /// the manager, or if the `counterparty_node_id` isn't the counterparty of the corresponding
2871 pub extern "C" fn ChannelManager_force_close_broadcasting_latest_txn(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, channel_id: *const [u8; 32], mut counterparty_node_id: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
2872 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_broadcasting_latest_txn(&::lightning::ln::ChannelId(unsafe { *channel_id }), &counterparty_node_id.into_rust());
2873 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() };
2877 /// Force closes a channel, rejecting new HTLCs on the given channel but skips broadcasting
2878 /// the latest local transaction(s). Fails if `channel_id` is unknown to the manager, or if the
2879 /// `counterparty_node_id` isn't the counterparty of the corresponding channel.
2881 /// You can always get the latest local transaction(s) to broadcast from
2882 /// [`ChannelMonitor::get_latest_holder_commitment_txn`].
2885 pub extern "C" fn ChannelManager_force_close_without_broadcasting_txn(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, channel_id: *const [u8; 32], mut counterparty_node_id: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
2886 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_without_broadcasting_txn(&::lightning::ln::ChannelId(unsafe { *channel_id }), &counterparty_node_id.into_rust());
2887 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() };
2891 /// Force close all channels, immediately broadcasting the latest local commitment transaction
2892 /// for each to the chain and rejecting new HTLCs on each.
2894 pub extern "C" fn ChannelManager_force_close_all_channels_broadcasting_latest_txn(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
2895 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_all_channels_broadcasting_latest_txn()
2898 /// Force close all channels rejecting new HTLCs on each but without broadcasting the latest
2899 /// local transaction(s).
2901 pub extern "C" fn ChannelManager_force_close_all_channels_without_broadcasting_txn(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
2902 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_all_channels_without_broadcasting_txn()
2905 /// Sends a payment along a given route.
2907 /// Value parameters are provided via the last hop in route, see documentation for [`RouteHop`]
2908 /// fields for more info.
2910 /// May generate [`UpdateHTLCs`] message(s) event on success, which should be relayed (e.g. via
2911 /// [`PeerManager::process_events`]).
2913 /// # Avoiding Duplicate Payments
2915 /// If a pending payment is currently in-flight with the same [`PaymentId`] provided, this
2916 /// method will error with an [`APIError::InvalidRoute`]. Note, however, that once a payment
2917 /// is no longer pending (either via [`ChannelManager::abandon_payment`], or handling of an
2918 /// [`Event::PaymentSent`] or [`Event::PaymentFailed`]) LDK will not stop you from sending a
2919 /// second payment with the same [`PaymentId`].
2921 /// Thus, in order to ensure duplicate payments are not sent, you should implement your own
2922 /// tracking of payments, including state to indicate once a payment has completed. Because you
2923 /// should also ensure that [`PaymentHash`]es are not re-used, for simplicity, you should
2924 /// consider using the [`PaymentHash`] as the key for tracking payments. In that case, the
2925 /// [`PaymentId`] should be a copy of the [`PaymentHash`] bytes.
2927 /// Additionally, in the scenario where we begin the process of sending a payment, but crash
2928 /// before `send_payment` returns (or prior to [`ChannelMonitorUpdate`] persistence if you're
2929 /// using [`ChannelMonitorUpdateStatus::InProgress`]), the payment may be lost on restart. See
2930 /// [`ChannelManager::list_recent_payments`] for more information.
2932 /// # Possible Error States on [`PaymentSendFailure`]
2934 /// Each path may have a different return value, and [`PaymentSendFailure`] may return a `Vec` with
2935 /// each entry matching the corresponding-index entry in the route paths, see
2936 /// [`PaymentSendFailure`] for more info.
2938 /// In general, a path may raise:
2939 /// * [`APIError::InvalidRoute`] when an invalid route or forwarding parameter (cltv_delta, fee,
2940 /// node public key) is specified.
2941 /// * [`APIError::ChannelUnavailable`] if the next-hop channel is not available as it has been
2942 /// closed, doesn't exist, or the peer is currently disconnected.
2943 /// * [`APIError::MonitorUpdateInProgress`] if a new monitor update failure prevented sending the
2944 /// relevant updates.
2946 /// Note that depending on the type of the [`PaymentSendFailure`] the HTLC may have been
2947 /// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
2948 /// different route unless you intend to pay twice!
2950 /// [`RouteHop`]: crate::routing::router::RouteHop
2951 /// [`Event::PaymentSent`]: events::Event::PaymentSent
2952 /// [`Event::PaymentFailed`]: events::Event::PaymentFailed
2953 /// [`UpdateHTLCs`]: events::MessageSendEvent::UpdateHTLCs
2954 /// [`PeerManager::process_events`]: crate::ln::peer_handler::PeerManager::process_events
2955 /// [`ChannelMonitorUpdateStatus::InProgress`]: crate::chain::ChannelMonitorUpdateStatus::InProgress
2958 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 {
2959 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_payment_with_route(route.get_native_ref(), ::lightning::ln::PaymentHash(payment_hash.data), *unsafe { Box::from_raw(recipient_onion.take_inner()) }, ::lightning::ln::channelmanager::PaymentId(payment_id.data));
2960 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() };
2964 /// Similar to [`ChannelManager::send_payment_with_route`], but will automatically find a route based on
2965 /// `route_params` and retry failed payment paths based on `retry_strategy`.
2968 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 {
2969 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_payment(::lightning::ln::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());
2970 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() };
2974 /// Signals that no further attempts for the given payment should occur. Useful if you have a
2975 /// pending outbound payment with retries remaining, but wish to stop retrying the payment before
2976 /// retries are exhausted.
2978 /// # Event Generation
2980 /// If no [`Event::PaymentFailed`] event had been generated before, one will be generated as soon
2981 /// as there are no remaining pending HTLCs for this payment.
2983 /// Note that calling this method does *not* prevent a payment from succeeding. You must still
2984 /// wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to
2985 /// determine the ultimate status of a payment.
2987 /// # Requested Invoices
2989 /// In the case of paying a [`Bolt12Invoice`] via [`ChannelManager::pay_for_offer`], abandoning
2990 /// the payment prior to receiving the invoice will result in an [`Event::InvoiceRequestFailed`]
2991 /// and prevent any attempts at paying it once received. The other events may only be generated
2992 /// once the invoice has been received.
2994 /// # Restart Behavior
2996 /// If an [`Event::PaymentFailed`] is generated and we restart without first persisting the
2997 /// [`ChannelManager`], another [`Event::PaymentFailed`] may be generated; likewise for
2998 /// [`Event::InvoiceRequestFailed`].
3000 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
3002 pub extern "C" fn ChannelManager_abandon_payment(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_id: crate::c_types::ThirtyTwoBytes) {
3003 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.abandon_payment(::lightning::ln::channelmanager::PaymentId(payment_id.data))
3006 /// Send a spontaneous payment, which is a payment that does not require the recipient to have
3007 /// generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
3008 /// the preimage, it must be a cryptographically secure random value that no intermediate node
3009 /// would be able to guess -- otherwise, an intermediate node may claim the payment and it will
3010 /// never reach the recipient.
3012 /// See [`send_payment`] documentation for more details on the return value of this function
3013 /// and idempotency guarantees provided by the [`PaymentId`] key.
3015 /// Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
3016 /// [`send_payment`] for more information about the risks of duplicate preimage usage.
3018 /// [`send_payment`]: Self::send_payment
3021 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 {
3022 let mut local_payment_preimage = { /*payment_preimage*/ let payment_preimage_opt = payment_preimage; if payment_preimage_opt.is_none() { None } else { Some({ { ::lightning::ln::PaymentPreimage({ payment_preimage_opt.take() }.data) }})} };
3023 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));
3024 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() };
3028 /// Similar to [`ChannelManager::send_spontaneous_payment`], but will automatically find a route
3029 /// based on `route_params` and retry failed payment paths based on `retry_strategy`.
3031 /// See [`PaymentParameters::for_keysend`] for help in constructing `route_params` for spontaneous
3034 /// [`PaymentParameters::for_keysend`]: crate::routing::router::PaymentParameters::for_keysend
3037 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 {
3038 let mut local_payment_preimage = { /*payment_preimage*/ let payment_preimage_opt = payment_preimage; if payment_preimage_opt.is_none() { None } else { Some({ { ::lightning::ln::PaymentPreimage({ payment_preimage_opt.take() }.data) }})} };
3039 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());
3040 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() };
3044 /// Send a payment that is probing the given route for liquidity. We calculate the
3045 /// [`PaymentHash`] of probes based on a static secret and a random [`PaymentId`], which allows
3046 /// us to easily discern them from real payments.
3049 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 {
3050 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_probe(*unsafe { Box::from_raw(path.take_inner()) });
3051 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() };
3055 /// Sends payment probes over all paths of a route that would be used to pay the given
3056 /// amount to the given `node_id`.
3058 /// See [`ChannelManager::send_preflight_probes`] for more information.
3061 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 {
3062 let mut local_liquidity_limit_multiplier = if liquidity_limit_multiplier.is_some() { Some( { liquidity_limit_multiplier.take() }) } else { None };
3063 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);
3064 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() };
3068 /// Sends payment probes over all paths of a route that would be used to pay a route found
3069 /// according to the given [`RouteParameters`].
3071 /// This may be used to send \"pre-flight\" probes, i.e., to train our scorer before conducting
3072 /// the actual payment. Note this is only useful if there likely is sufficient time for the
3073 /// probe to settle before sending out the actual payment, e.g., when waiting for user
3074 /// confirmation in a wallet UI.
3076 /// Otherwise, there is a chance the probe could take up some liquidity needed to complete the
3077 /// actual payment. Users should therefore be cautious and might avoid sending probes if
3078 /// liquidity is scarce and/or they don't expect the probe to return before they send the
3079 /// payment. To mitigate this issue, channels with available liquidity less than the required
3080 /// amount times the given `liquidity_limit_multiplier` won't be used to send pre-flight
3081 /// probes. If `None` is given as `liquidity_limit_multiplier`, it defaults to `3`.
3084 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 {
3085 let mut local_liquidity_limit_multiplier = if liquidity_limit_multiplier.is_some() { Some( { liquidity_limit_multiplier.take() }) } else { None };
3086 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);
3087 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() };
3091 /// Call this upon creation of a funding transaction for the given channel.
3093 /// Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
3094 /// or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
3096 /// Returns [`APIError::APIMisuseError`] if the funding transaction is not final for propagation
3097 /// across the p2p network.
3099 /// Returns [`APIError::ChannelUnavailable`] if a funding transaction has already been provided
3100 /// for the channel or if the channel has been closed as indicated by [`Event::ChannelClosed`].
3102 /// May panic if the output found in the funding transaction is duplicative with some other
3103 /// channel (note that this should be trivially prevented by using unique funding transaction
3104 /// keys per-channel).
3106 /// Do NOT broadcast the funding transaction yourself. When we have safely received our
3107 /// counterparty's signature the funding transaction will automatically be broadcast via the
3108 /// [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
3110 /// Note that this includes RBF or similar transaction replacement strategies - lightning does
3111 /// not currently support replacing a funding transaction on an existing channel. Instead,
3112 /// create a new channel with a conflicting funding transaction.
3114 /// Note to keep the miner incentives aligned in moving the blockchain forward, we recommend
3115 /// the wallet software generating the funding transaction to apply anti-fee sniping as
3116 /// implemented by Bitcoin Core wallet. See <https://bitcoinops.org/en/topics/fee-sniping/>
3117 /// for more details.
3119 /// [`Event::FundingGenerationReady`]: crate::events::Event::FundingGenerationReady
3120 /// [`Event::ChannelClosed`]: crate::events::Event::ChannelClosed
3123 pub extern "C" fn ChannelManager_funding_transaction_generated(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, temporary_channel_id: *const [u8; 32], mut counterparty_node_id: crate::c_types::PublicKey, mut funding_transaction: crate::c_types::Transaction) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
3124 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_transaction_generated(&::lightning::ln::ChannelId(unsafe { *temporary_channel_id }), &counterparty_node_id.into_rust(), funding_transaction.into_bitcoin());
3125 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() };
3129 /// Call this upon creation of a batch funding transaction for the given channels.
3131 /// Return values are identical to [`Self::funding_transaction_generated`], respective to
3132 /// each individual channel and transaction output.
3134 /// Do NOT broadcast the funding transaction yourself. This batch funding transaction
3135 /// will only be broadcast when we have safely received and persisted the counterparty's
3136 /// signature for each channel.
3138 /// If there is an error, all channels in the batch are to be considered closed.
3141 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_ThirtyTwoBytesPublicKeyZZ, mut funding_transaction: crate::c_types::Transaction) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
3142 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 = (::lightning::ln::ChannelId(orig_temporary_channels_0_0.data), orig_temporary_channels_0_1.into_rust()); local_temporary_channels_0 }); };
3143 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());
3144 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() };
3148 /// Atomically applies partial updates to the [`ChannelConfig`] of the given channels.
3150 /// Once the updates are applied, each eligible channel (advertised with a known short channel
3151 /// ID and a change in [`forwarding_fee_proportional_millionths`], [`forwarding_fee_base_msat`],
3152 /// or [`cltv_expiry_delta`]) has a [`BroadcastChannelUpdate`] event message generated
3153 /// containing the new [`ChannelUpdate`] message which should be broadcast to the network.
3155 /// Returns [`ChannelUnavailable`] when a channel is not found or an incorrect
3156 /// `counterparty_node_id` is provided.
3158 /// Returns [`APIMisuseError`] when a [`cltv_expiry_delta`] update is to be applied with a value
3159 /// below [`MIN_CLTV_EXPIRY_DELTA`].
3161 /// If an error is returned, none of the updates should be considered applied.
3163 /// [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
3164 /// [`forwarding_fee_base_msat`]: ChannelConfig::forwarding_fee_base_msat
3165 /// [`cltv_expiry_delta`]: ChannelConfig::cltv_expiry_delta
3166 /// [`BroadcastChannelUpdate`]: events::MessageSendEvent::BroadcastChannelUpdate
3167 /// [`ChannelUpdate`]: msgs::ChannelUpdate
3168 /// [`ChannelUnavailable`]: APIError::ChannelUnavailable
3169 /// [`APIMisuseError`]: APIError::APIMisuseError
3172 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_ThirtyTwoBytesZ, config_update: &crate::lightning::util::config::ChannelConfigUpdate) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
3173 let mut local_channel_ids = Vec::new(); for mut item in channel_ids.into_rust().drain(..) { local_channel_ids.push( { ::lightning::ln::ChannelId(item.data) }); };
3174 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());
3175 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() };
3179 /// Atomically updates the [`ChannelConfig`] for the given channels.
3181 /// Once the updates are applied, each eligible channel (advertised with a known short channel
3182 /// ID and a change in [`forwarding_fee_proportional_millionths`], [`forwarding_fee_base_msat`],
3183 /// or [`cltv_expiry_delta`]) has a [`BroadcastChannelUpdate`] event message generated
3184 /// containing the new [`ChannelUpdate`] message which should be broadcast to the network.
3186 /// Returns [`ChannelUnavailable`] when a channel is not found or an incorrect
3187 /// `counterparty_node_id` is provided.
3189 /// Returns [`APIMisuseError`] when a [`cltv_expiry_delta`] update is to be applied with a value
3190 /// below [`MIN_CLTV_EXPIRY_DELTA`].
3192 /// If an error is returned, none of the updates should be considered applied.
3194 /// [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
3195 /// [`forwarding_fee_base_msat`]: ChannelConfig::forwarding_fee_base_msat
3196 /// [`cltv_expiry_delta`]: ChannelConfig::cltv_expiry_delta
3197 /// [`BroadcastChannelUpdate`]: events::MessageSendEvent::BroadcastChannelUpdate
3198 /// [`ChannelUpdate`]: msgs::ChannelUpdate
3199 /// [`ChannelUnavailable`]: APIError::ChannelUnavailable
3200 /// [`APIMisuseError`]: APIError::APIMisuseError
3203 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_ThirtyTwoBytesZ, config: &crate::lightning::util::config::ChannelConfig) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
3204 let mut local_channel_ids = Vec::new(); for mut item in channel_ids.into_rust().drain(..) { local_channel_ids.push( { ::lightning::ln::ChannelId(item.data) }); };
3205 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());
3206 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() };
3210 /// Attempts to forward an intercepted HTLC over the provided channel id and with the provided
3211 /// amount to forward. Should only be called in response to an [`HTLCIntercepted`] event.
3213 /// Intercepted HTLCs can be useful for Lightning Service Providers (LSPs) to open a just-in-time
3214 /// channel to a receiving node if the node lacks sufficient inbound liquidity.
3216 /// To make use of intercepted HTLCs, set [`UserConfig::accept_intercept_htlcs`] and use
3217 /// [`ChannelManager::get_intercept_scid`] to generate short channel id(s) to put in the
3218 /// receiver's invoice route hints. These route hints will signal to LDK to generate an
3219 /// [`HTLCIntercepted`] event when it receives the forwarded HTLC, and this method or
3220 /// [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to the event.
3222 /// Note that LDK does not enforce fee requirements in `amt_to_forward_msat`, and will not stop
3223 /// you from forwarding more than you received. See
3224 /// [`HTLCIntercepted::expected_outbound_amount_msat`] for more on forwarding a different amount
3227 /// Errors if the event was not handled in time, in which case the HTLC was automatically failed
3230 /// [`UserConfig::accept_intercept_htlcs`]: crate::util::config::UserConfig::accept_intercept_htlcs
3231 /// [`HTLCIntercepted`]: events::Event::HTLCIntercepted
3232 /// [`HTLCIntercepted::expected_outbound_amount_msat`]: events::Event::HTLCIntercepted::expected_outbound_amount_msat
3235 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: *const [u8; 32], mut next_node_id: crate::c_types::PublicKey, mut amt_to_forward_msat: u64) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
3236 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.forward_intercepted_htlc(::lightning::ln::channelmanager::InterceptId(intercept_id.data), &::lightning::ln::ChannelId(unsafe { *next_hop_channel_id }), next_node_id.into_rust(), amt_to_forward_msat);
3237 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() };
3241 /// Fails the intercepted HTLC indicated by intercept_id. Should only be called in response to
3242 /// an [`HTLCIntercepted`] event. See [`ChannelManager::forward_intercepted_htlc`].
3244 /// Errors if the event was not handled in time, in which case the HTLC was automatically failed
3247 /// [`HTLCIntercepted`]: events::Event::HTLCIntercepted
3250 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 {
3251 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_intercepted_htlc(::lightning::ln::channelmanager::InterceptId(intercept_id.data));
3252 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() };
3256 /// Processes HTLCs which are pending waiting on random forward delay.
3258 /// Should only really ever be called in response to a PendingHTLCsForwardable event.
3259 /// Will likely generate further events.
3261 pub extern "C" fn ChannelManager_process_pending_htlc_forwards(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
3262 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_pending_htlc_forwards()
3265 /// Performs actions which should happen on startup and roughly once per minute thereafter.
3267 /// This currently includes:
3268 /// * Increasing or decreasing the on-chain feerate estimates for our outbound channels,
3269 /// * Broadcasting [`ChannelUpdate`] messages if we've been disconnected from our peer for more
3270 /// than a minute, informing the network that they should no longer attempt to route over
3272 /// * Expiring a channel's previous [`ChannelConfig`] if necessary to only allow forwarding HTLCs
3273 /// with the current [`ChannelConfig`].
3274 /// * Removing peers which have disconnected but and no longer have any channels.
3275 /// * Force-closing and removing channels which have not completed establishment in a timely manner.
3276 /// * Forgetting about stale outbound payments, either those that have already been fulfilled
3277 /// or those awaiting an invoice that hasn't been delivered in the necessary amount of time.
3278 /// The latter is determined using the system clock in `std` and the highest seen block time
3279 /// minus two hours in `no-std`.
3281 /// Note that this may cause reentrancy through [`chain::Watch::update_channel`] calls or feerate
3282 /// estimate fetches.
3284 /// [`ChannelUpdate`]: msgs::ChannelUpdate
3285 /// [`ChannelConfig`]: crate::util::config::ChannelConfig
3287 pub extern "C" fn ChannelManager_timer_tick_occurred(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
3288 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timer_tick_occurred()
3291 /// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
3292 /// after a PaymentClaimable event, failing the HTLC back to its origin and freeing resources
3293 /// along the path (including in our own channel on which we received it).
3295 /// Note that in some cases around unclean shutdown, it is possible the payment may have
3296 /// already been claimed by you via [`ChannelManager::claim_funds`] prior to you seeing (a
3297 /// second copy of) the [`events::Event::PaymentClaimable`] event. Alternatively, the payment
3298 /// may have already been failed automatically by LDK if it was nearing its expiration time.
3300 /// While LDK will never claim a payment automatically on your behalf (i.e. without you calling
3301 /// [`ChannelManager::claim_funds`]), you should still monitor for
3302 /// [`events::Event::PaymentClaimed`] events even for payments you intend to fail, especially on
3303 /// startup during which time claims that were in-progress at shutdown may be replayed.
3305 pub extern "C" fn ChannelManager_fail_htlc_backwards(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, payment_hash: *const [u8; 32]) {
3306 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_htlc_backwards(&::lightning::ln::PaymentHash(unsafe { *payment_hash }))
3309 /// This is a variant of [`ChannelManager::fail_htlc_backwards`] that allows you to specify the
3310 /// reason for the failure.
3312 /// See [`FailureCode`] for valid failure codes.
3314 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) {
3315 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_htlc_backwards_with_reason(&::lightning::ln::PaymentHash(unsafe { *payment_hash }), failure_code.into_native())
3318 /// Provides a payment preimage in response to [`Event::PaymentClaimable`], generating any
3319 /// [`MessageSendEvent`]s needed to claim the payment.
3321 /// This method is guaranteed to ensure the payment has been claimed but only if the current
3322 /// height is strictly below [`Event::PaymentClaimable::claim_deadline`]. To avoid race
3323 /// conditions, you should wait for an [`Event::PaymentClaimed`] before considering the payment
3324 /// successful. It will generally be available in the next [`process_pending_events`] call.
3326 /// Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
3327 /// [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentClaimable`
3328 /// event matches your expectation. If you fail to do so and call this method, you may provide
3329 /// the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
3331 /// This function will fail the payment if it has custom TLVs with even type numbers, as we
3332 /// will assume they are unknown. If you intend to accept even custom TLVs, you should use
3333 /// [`claim_funds_with_known_custom_tlvs`].
3335 /// [`Event::PaymentClaimable`]: crate::events::Event::PaymentClaimable
3336 /// [`Event::PaymentClaimable::claim_deadline`]: crate::events::Event::PaymentClaimable::claim_deadline
3337 /// [`Event::PaymentClaimed`]: crate::events::Event::PaymentClaimed
3338 /// [`process_pending_events`]: EventsProvider::process_pending_events
3339 /// [`create_inbound_payment`]: Self::create_inbound_payment
3340 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
3341 /// [`claim_funds_with_known_custom_tlvs`]: Self::claim_funds_with_known_custom_tlvs
3343 pub extern "C" fn ChannelManager_claim_funds(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_preimage: crate::c_types::ThirtyTwoBytes) {
3344 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.claim_funds(::lightning::ln::PaymentPreimage(payment_preimage.data))
3347 /// This is a variant of [`claim_funds`] that allows accepting a payment with custom TLVs with
3348 /// even type numbers.
3352 /// You MUST check you've understood all even TLVs before using this to
3353 /// claim, otherwise you may unintentionally agree to some protocol you do not understand.
3355 /// [`claim_funds`]: Self::claim_funds
3357 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) {
3358 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.claim_funds_with_known_custom_tlvs(::lightning::ln::PaymentPreimage(payment_preimage.data))
3361 /// Gets the node_id held by this ChannelManager
3364 pub extern "C" fn ChannelManager_get_our_node_id(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::PublicKey {
3365 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_our_node_id();
3366 crate::c_types::PublicKey::from_rust(&ret)
3369 /// Accepts a request to open a channel after a [`Event::OpenChannelRequest`].
3371 /// The `temporary_channel_id` parameter indicates which inbound channel should be accepted,
3372 /// and the `counterparty_node_id` parameter is the id of the peer which has requested to open
3375 /// The `user_channel_id` parameter will be provided back in
3376 /// [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
3377 /// with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
3379 /// Note that this method will return an error and reject the channel, if it requires support
3380 /// for zero confirmations. Instead, `accept_inbound_channel_from_trusted_peer_0conf` must be
3381 /// used to accept such channels.
3383 /// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
3384 /// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
3387 pub extern "C" fn ChannelManager_accept_inbound_channel(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, temporary_channel_id: *const [u8; 32], mut counterparty_node_id: crate::c_types::PublicKey, mut user_channel_id: crate::c_types::U128) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
3388 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.accept_inbound_channel(&::lightning::ln::ChannelId(unsafe { *temporary_channel_id }), &counterparty_node_id.into_rust(), user_channel_id.into());
3389 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() };
3393 /// Accepts a request to open a channel after a [`events::Event::OpenChannelRequest`], treating
3394 /// it as confirmed immediately.
3396 /// The `user_channel_id` parameter will be provided back in
3397 /// [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
3398 /// with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
3400 /// Unlike [`ChannelManager::accept_inbound_channel`], this method accepts the incoming channel
3401 /// and (if the counterparty agrees), enables forwarding of payments immediately.
3403 /// This fully trusts that the counterparty has honestly and correctly constructed the funding
3404 /// transaction and blindly assumes that it will eventually confirm.
3406 /// If it does not confirm before we decide to close the channel, or if the funding transaction
3407 /// does not pay to the correct script the correct amount, *you will lose funds*.
3409 /// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
3410 /// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
3413 pub extern "C" fn ChannelManager_accept_inbound_channel_from_trusted_peer_0conf(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, temporary_channel_id: *const [u8; 32], mut counterparty_node_id: crate::c_types::PublicKey, mut user_channel_id: crate::c_types::U128) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
3414 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.accept_inbound_channel_from_trusted_peer_0conf(&::lightning::ln::ChannelId(unsafe { *temporary_channel_id }), &counterparty_node_id.into_rust(), user_channel_id.into());
3415 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() };
3419 /// Pays for an [`Offer`] using the given parameters by creating an [`InvoiceRequest`] and
3420 /// enqueuing it to be sent via an onion message. [`ChannelManager`] will pay the actual
3421 /// [`Bolt12Invoice`] once it is received.
3423 /// Uses [`InvoiceRequestBuilder`] such that the [`InvoiceRequest`] it builds is recognized by
3424 /// the [`ChannelManager`] when handling a [`Bolt12Invoice`] message in response to the request.
3425 /// The optional parameters are used in the builder, if `Some`:
3426 /// - `quantity` for [`InvoiceRequest::quantity`] which must be set if
3427 /// [`Offer::expects_quantity`] is `true`.
3428 /// - `amount_msats` if overpaying what is required for the given `quantity` is desired, and
3429 /// - `payer_note` for [`InvoiceRequest::payer_note`].
3431 /// If `max_total_routing_fee_msat` is not specified, The default from
3432 /// [`RouteParameters::from_payment_params_and_value`] is applied.
3436 /// The provided `payment_id` is used to ensure that only one invoice is paid for the request
3437 /// when received. See [Avoiding Duplicate Payments] for other requirements once the payment has
3440 /// To revoke the request, use [`ChannelManager::abandon_payment`] prior to receiving the
3441 /// invoice. If abandoned, or an invoice isn't received in a reasonable amount of time, the
3442 /// payment will fail with an [`Event::InvoiceRequestFailed`].
3446 /// Uses a one-hop [`BlindedPath`] for the reply path with [`ChannelManager::get_our_node_id`]
3447 /// as the introduction node and a derived payer id for payer privacy. As such, currently, the
3448 /// node must be announced. Otherwise, there is no way to find a path to the introduction node
3449 /// in order to send the [`Bolt12Invoice`].
3453 /// Requires a direct connection to an introduction node in [`Offer::paths`] or to
3454 /// [`Offer::signing_pubkey`], if empty. A similar restriction applies to the responding
3455 /// [`Bolt12Invoice::payment_paths`].
3460 /// - a duplicate `payment_id` is provided given the caveats in the aforementioned link,
3461 /// - the provided parameters are invalid for the offer,
3462 /// - the parameterized [`Router`] is unable to create a blinded reply path for the invoice
3465 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
3466 /// [`InvoiceRequest::quantity`]: crate::offers::invoice_request::InvoiceRequest::quantity
3467 /// [`InvoiceRequest::payer_note`]: crate::offers::invoice_request::InvoiceRequest::payer_note
3468 /// [`InvoiceRequestBuilder`]: crate::offers::invoice_request::InvoiceRequestBuilder
3469 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
3470 /// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
3471 /// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
3474 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 {
3475 let mut local_quantity = if quantity.is_some() { Some( { quantity.take() }) } else { None };
3476 let mut local_amount_msats = if amount_msats.is_some() { Some( { amount_msats.take() }) } else { None };
3477 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() }})} };
3478 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 };
3479 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);
3480 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() };
3484 /// Creates a [`Bolt12Invoice`] for a [`Refund`] and enqueues it to be sent via an onion
3487 /// The resulting invoice uses a [`PaymentHash`] recognized by the [`ChannelManager`] and a
3488 /// [`BlindedPath`] containing the [`PaymentSecret`] needed to reconstruct the corresponding
3489 /// [`PaymentPreimage`].
3493 /// Requires a direct connection to an introduction node in [`Refund::paths`] or to
3494 /// [`Refund::payer_id`], if empty. This request is best effort; an invoice will be sent to each
3495 /// node meeting the aforementioned criteria, but there's no guarantee that they will be
3496 /// received and no retries will be made.
3500 /// Errors if the parameterized [`Router`] is unable to create a blinded payment path or reply
3501 /// path for the invoice.
3503 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
3506 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_NoneBolt12SemanticErrorZ {
3507 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.request_refund_payment(refund.get_native_ref());
3508 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() };
3512 /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
3515 /// This differs from [`create_inbound_payment_for_hash`] only in that it generates the
3516 /// [`PaymentHash`] and [`PaymentPreimage`] for you.
3518 /// The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentClaimable`], which
3519 /// will have the [`PaymentClaimable::purpose`] be [`PaymentPurpose::InvoicePayment`] with
3520 /// its [`PaymentPurpose::InvoicePayment::payment_preimage`] field filled in. That should then be
3521 /// passed directly to [`claim_funds`].
3523 /// See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
3525 /// Note that a malicious eavesdropper can intuit whether an inbound payment was created by
3526 /// `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
3530 /// If you register an inbound payment with this method, then serialize the `ChannelManager`, then
3531 /// deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
3533 /// Errors if `min_value_msat` is greater than total bitcoin supply.
3535 /// If `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
3536 /// on versions of LDK prior to 0.0.114.
3538 /// [`claim_funds`]: Self::claim_funds
3539 /// [`PaymentClaimable`]: events::Event::PaymentClaimable
3540 /// [`PaymentClaimable::purpose`]: events::Event::PaymentClaimable::purpose
3541 /// [`PaymentPurpose::InvoicePayment`]: events::PaymentPurpose::InvoicePayment
3542 /// [`PaymentPurpose::InvoicePayment::payment_preimage`]: events::PaymentPurpose::InvoicePayment::payment_preimage
3543 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
3546 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 {
3547 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
3548 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 };
3549 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);
3550 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() };
3554 /// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
3555 /// stored external to LDK.
3557 /// A [`PaymentClaimable`] event will only be generated if the [`PaymentSecret`] matches a
3558 /// payment secret fetched via this method or [`create_inbound_payment`], and which is at least
3559 /// the `min_value_msat` provided here, if one is provided.
3561 /// The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) should be globally unique, though
3562 /// note that LDK will not stop you from registering duplicate payment hashes for inbound
3565 /// `min_value_msat` should be set if the invoice being generated contains a value. Any payment
3566 /// received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
3567 /// before a [`PaymentClaimable`] event will be generated, ensuring that we do not provide the
3568 /// sender \"proof-of-payment\" unless they have paid the required amount.
3570 /// `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
3571 /// in excess of the current time. This should roughly match the expiry time set in the invoice.
3572 /// After this many seconds, we will remove the inbound payment, resulting in any attempts to
3573 /// pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
3574 /// invoices when no timeout is set.
3576 /// Note that we use block header time to time-out pending inbound payments (with some margin
3577 /// to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
3578 /// accept a payment and generate a [`PaymentClaimable`] event for some time after the expiry.
3579 /// If you need exact expiry semantics, you should enforce them upon receipt of
3580 /// [`PaymentClaimable`].
3582 /// Note that invoices generated for inbound payments should have their `min_final_cltv_expiry_delta`
3583 /// set to at least [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
3585 /// Note that a malicious eavesdropper can intuit whether an inbound payment was created by
3586 /// `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
3590 /// If you register an inbound payment with this method, then serialize the `ChannelManager`, then
3591 /// deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
3593 /// Errors if `min_value_msat` is greater than total bitcoin supply.
3595 /// If `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
3596 /// on versions of LDK prior to 0.0.114.
3598 /// [`create_inbound_payment`]: Self::create_inbound_payment
3599 /// [`PaymentClaimable`]: events::Event::PaymentClaimable
3602 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 {
3603 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
3604 let mut local_min_final_cltv_expiry = if min_final_cltv_expiry.is_some() { Some( { min_final_cltv_expiry.take() }) } else { None };
3605 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment_for_hash(::lightning::ln::PaymentHash(payment_hash.data), local_min_value_msat, invoice_expiry_delta_secs, local_min_final_cltv_expiry);
3606 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() };
3610 /// Gets an LDK-generated payment preimage from a payment hash and payment secret that were
3611 /// previously returned from [`create_inbound_payment`].
3613 /// [`create_inbound_payment`]: Self::create_inbound_payment
3616 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 {
3617 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_payment_preimage(::lightning::ln::PaymentHash(payment_hash.data), ::lightning::ln::PaymentSecret(payment_secret.data));
3618 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() };
3622 /// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
3623 /// are used when constructing the phantom invoice's route hints.
3625 /// [phantom node payments]: crate::sign::PhantomKeysManager
3628 pub extern "C" fn ChannelManager_get_phantom_scid(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> u64 {
3629 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_phantom_scid();
3633 /// Gets route hints for use in receiving [phantom node payments].
3635 /// [phantom node payments]: crate::sign::PhantomKeysManager
3638 pub extern "C" fn ChannelManager_get_phantom_route_hints(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::ln::channelmanager::PhantomRouteHints {
3639 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_phantom_route_hints();
3640 crate::lightning::ln::channelmanager::PhantomRouteHints { inner: ObjOps::heap_alloc(ret), is_owned: true }
3643 /// Gets a fake short channel id for use in receiving intercepted payments. These fake scids are
3644 /// used when constructing the route hints for HTLCs intended to be intercepted. See
3645 /// [`ChannelManager::forward_intercepted_htlc`].
3647 /// Note that this method is not guaranteed to return unique values, you may need to call it a few
3648 /// times to get a unique scid.
3651 pub extern "C" fn ChannelManager_get_intercept_scid(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> u64 {
3652 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_intercept_scid();
3656 /// Gets inflight HTLC information by processing pending outbound payments that are in
3657 /// our channels. May be used during pathfinding to account for in-use channel liquidity.
3660 pub extern "C" fn ChannelManager_compute_inflight_htlcs(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::routing::router::InFlightHtlcs {
3661 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.compute_inflight_htlcs();
3662 crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(ret), is_owned: true }
3665 impl From<nativeChannelManager> for crate::lightning::events::MessageSendEventsProvider {
3666 fn from(obj: nativeChannelManager) -> Self {
3667 let rust_obj = crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
3668 let mut ret = ChannelManager_as_MessageSendEventsProvider(&rust_obj);
3669 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
3670 core::mem::forget(rust_obj);
3671 ret.free = Some(ChannelManager_free_void);
3675 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
3676 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
3678 pub extern "C" fn ChannelManager_as_MessageSendEventsProvider(this_arg: &ChannelManager) -> crate::lightning::events::MessageSendEventsProvider {
3679 crate::lightning::events::MessageSendEventsProvider {
3680 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
3682 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
3687 extern "C" fn ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
3688 let mut ret = <nativeChannelManager as lightning::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
3689 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::events::MessageSendEvent::native_into(item) }); };
3693 impl From<nativeChannelManager> for crate::lightning::events::EventsProvider {
3694 fn from(obj: nativeChannelManager) -> Self {
3695 let rust_obj = crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
3696 let mut ret = ChannelManager_as_EventsProvider(&rust_obj);
3697 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
3698 core::mem::forget(rust_obj);
3699 ret.free = Some(ChannelManager_free_void);
3703 /// Constructs a new EventsProvider which calls the relevant methods on this_arg.
3704 /// This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
3706 pub extern "C" fn ChannelManager_as_EventsProvider(this_arg: &ChannelManager) -> crate::lightning::events::EventsProvider {
3707 crate::lightning::events::EventsProvider {
3708 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
3710 process_pending_events: ChannelManager_EventsProvider_process_pending_events,
3714 extern "C" fn ChannelManager_EventsProvider_process_pending_events(this_arg: *const c_void, mut handler: crate::lightning::events::EventHandler) {
3715 <nativeChannelManager as lightning::events::EventsProvider<>>::process_pending_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, handler)
3718 impl From<nativeChannelManager> for crate::lightning::chain::Listen {
3719 fn from(obj: nativeChannelManager) -> Self {
3720 let rust_obj = crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
3721 let mut ret = ChannelManager_as_Listen(&rust_obj);
3722 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
3723 core::mem::forget(rust_obj);
3724 ret.free = Some(ChannelManager_free_void);
3728 /// Constructs a new Listen which calls the relevant methods on this_arg.
3729 /// This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
3731 pub extern "C" fn ChannelManager_as_Listen(this_arg: &ChannelManager) -> crate::lightning::chain::Listen {
3732 crate::lightning::chain::Listen {
3733 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
3735 filtered_block_connected: ChannelManager_Listen_filtered_block_connected,
3736 block_connected: ChannelManager_Listen_block_connected,
3737 block_disconnected: ChannelManager_Listen_block_disconnected,
3741 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) {
3742 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 }); };
3743 <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)
3745 extern "C" fn ChannelManager_Listen_block_connected(this_arg: *const c_void, mut block: crate::c_types::u8slice, mut height: u32) {
3746 <nativeChannelManager as lightning::chain::Listen<>>::block_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height)
3748 extern "C" fn ChannelManager_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
3749 <nativeChannelManager as lightning::chain::Listen<>>::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
3752 impl From<nativeChannelManager> for crate::lightning::chain::Confirm {
3753 fn from(obj: nativeChannelManager) -> Self {
3754 let rust_obj = crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
3755 let mut ret = ChannelManager_as_Confirm(&rust_obj);
3756 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
3757 core::mem::forget(rust_obj);
3758 ret.free = Some(ChannelManager_free_void);
3762 /// Constructs a new Confirm which calls the relevant methods on this_arg.
3763 /// This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
3765 pub extern "C" fn ChannelManager_as_Confirm(this_arg: &ChannelManager) -> crate::lightning::chain::Confirm {
3766 crate::lightning::chain::Confirm {
3767 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
3769 transactions_confirmed: ChannelManager_Confirm_transactions_confirmed,
3770 transaction_unconfirmed: ChannelManager_Confirm_transaction_unconfirmed,
3771 best_block_updated: ChannelManager_Confirm_best_block_updated,
3772 get_relevant_txids: ChannelManager_Confirm_get_relevant_txids,
3776 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) {
3777 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 }); };
3778 <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)
3780 extern "C" fn ChannelManager_Confirm_transaction_unconfirmed(this_arg: *const c_void, txid: *const [u8; 32]) {
3781 <nativeChannelManager as lightning::chain::Confirm<>>::transaction_unconfirmed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap())
3783 extern "C" fn ChannelManager_Confirm_best_block_updated(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
3784 <nativeChannelManager as lightning::chain::Confirm<>>::best_block_updated(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
3787 extern "C" fn ChannelManager_Confirm_get_relevant_txids(this_arg: *const c_void) -> crate::c_types::derived::CVec_C3Tuple_ThirtyTwoBytesu32COption_ThirtyTwoBytesZZZ {
3788 let mut ret = <nativeChannelManager as lightning::chain::Confirm<>>::get_relevant_txids(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
3789 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 }); };
3793 /// Gets a [`Future`] that completes when this [`ChannelManager`] may need to be persisted or
3794 /// may have events that need processing.
3796 /// In order to check if this [`ChannelManager`] needs persisting, call
3797 /// [`Self::get_and_clear_needs_persistence`].
3799 /// Note that callbacks registered on the [`Future`] MUST NOT call back into this
3800 /// [`ChannelManager`] and should instead register actions to be taken later.
3803 pub extern "C" fn ChannelManager_get_event_or_persistence_needed_future(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::util::wakers::Future {
3804 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_event_or_persistence_needed_future();
3805 crate::lightning::util::wakers::Future { inner: ObjOps::heap_alloc(ret), is_owned: true }
3808 /// Returns true if this [`ChannelManager`] needs to be persisted.
3811 pub extern "C" fn ChannelManager_get_and_clear_needs_persistence(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> bool {
3812 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_and_clear_needs_persistence();
3816 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
3817 /// [`chain::Confirm`] interfaces.
3820 pub extern "C" fn ChannelManager_current_best_block(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::chain::BestBlock {
3821 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
3822 crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
3825 /// Fetches the set of [`NodeFeatures`] flags that are provided by or required by
3826 /// [`ChannelManager`].
3829 pub extern "C" fn ChannelManager_node_features(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::ln::features::NodeFeatures {
3830 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.node_features();
3831 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
3834 /// Fetches the set of [`ChannelFeatures`] flags that are provided by or required by
3835 /// [`ChannelManager`].
3838 pub extern "C" fn ChannelManager_channel_features(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::ln::features::ChannelFeatures {
3839 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_features();
3840 crate::lightning::ln::features::ChannelFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
3843 /// Fetches the set of [`ChannelTypeFeatures`] flags that are provided by or required by
3844 /// [`ChannelManager`].
3847 pub extern "C" fn ChannelManager_channel_type_features(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::ln::features::ChannelTypeFeatures {
3848 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_type_features();
3849 crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
3852 /// Fetches the set of [`InitFeatures`] flags that are provided by or required by
3853 /// [`ChannelManager`].
3856 pub extern "C" fn ChannelManager_init_features(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::ln::features::InitFeatures {
3857 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.init_features();
3858 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
3861 impl From<nativeChannelManager> for crate::lightning::ln::msgs::ChannelMessageHandler {
3862 fn from(obj: nativeChannelManager) -> Self {
3863 let rust_obj = crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
3864 let mut ret = ChannelManager_as_ChannelMessageHandler(&rust_obj);
3865 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
3866 core::mem::forget(rust_obj);
3867 ret.free = Some(ChannelManager_free_void);
3871 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
3872 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
3874 pub extern "C" fn ChannelManager_as_ChannelMessageHandler(this_arg: &ChannelManager) -> crate::lightning::ln::msgs::ChannelMessageHandler {
3875 crate::lightning::ln::msgs::ChannelMessageHandler {
3876 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
3878 handle_open_channel: ChannelManager_ChannelMessageHandler_handle_open_channel,
3879 handle_open_channel_v2: ChannelManager_ChannelMessageHandler_handle_open_channel_v2,
3880 handle_accept_channel: ChannelManager_ChannelMessageHandler_handle_accept_channel,
3881 handle_accept_channel_v2: ChannelManager_ChannelMessageHandler_handle_accept_channel_v2,
3882 handle_funding_created: ChannelManager_ChannelMessageHandler_handle_funding_created,
3883 handle_funding_signed: ChannelManager_ChannelMessageHandler_handle_funding_signed,
3884 handle_channel_ready: ChannelManager_ChannelMessageHandler_handle_channel_ready,
3885 handle_shutdown: ChannelManager_ChannelMessageHandler_handle_shutdown,
3886 handle_closing_signed: ChannelManager_ChannelMessageHandler_handle_closing_signed,
3887 handle_stfu: ChannelManager_ChannelMessageHandler_handle_stfu,
3888 handle_splice: ChannelManager_ChannelMessageHandler_handle_splice,
3889 handle_splice_ack: ChannelManager_ChannelMessageHandler_handle_splice_ack,
3890 handle_splice_locked: ChannelManager_ChannelMessageHandler_handle_splice_locked,
3891 handle_tx_add_input: ChannelManager_ChannelMessageHandler_handle_tx_add_input,
3892 handle_tx_add_output: ChannelManager_ChannelMessageHandler_handle_tx_add_output,
3893 handle_tx_remove_input: ChannelManager_ChannelMessageHandler_handle_tx_remove_input,
3894 handle_tx_remove_output: ChannelManager_ChannelMessageHandler_handle_tx_remove_output,
3895 handle_tx_complete: ChannelManager_ChannelMessageHandler_handle_tx_complete,
3896 handle_tx_signatures: ChannelManager_ChannelMessageHandler_handle_tx_signatures,
3897 handle_tx_init_rbf: ChannelManager_ChannelMessageHandler_handle_tx_init_rbf,
3898 handle_tx_ack_rbf: ChannelManager_ChannelMessageHandler_handle_tx_ack_rbf,
3899 handle_tx_abort: ChannelManager_ChannelMessageHandler_handle_tx_abort,
3900 handle_update_add_htlc: ChannelManager_ChannelMessageHandler_handle_update_add_htlc,
3901 handle_update_fulfill_htlc: ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc,
3902 handle_update_fail_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_htlc,
3903 handle_update_fail_malformed_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_malformed_htlc,
3904 handle_commitment_signed: ChannelManager_ChannelMessageHandler_handle_commitment_signed,
3905 handle_revoke_and_ack: ChannelManager_ChannelMessageHandler_handle_revoke_and_ack,
3906 handle_update_fee: ChannelManager_ChannelMessageHandler_handle_update_fee,
3907 handle_announcement_signatures: ChannelManager_ChannelMessageHandler_handle_announcement_signatures,
3908 peer_disconnected: ChannelManager_ChannelMessageHandler_peer_disconnected,
3909 peer_connected: ChannelManager_ChannelMessageHandler_peer_connected,
3910 handle_channel_reestablish: ChannelManager_ChannelMessageHandler_handle_channel_reestablish,
3911 handle_channel_update: ChannelManager_ChannelMessageHandler_handle_channel_update,
3912 handle_error: ChannelManager_ChannelMessageHandler_handle_error,
3913 provided_node_features: ChannelManager_ChannelMessageHandler_provided_node_features,
3914 provided_init_features: ChannelManager_ChannelMessageHandler_provided_init_features,
3915 get_chain_hashes: ChannelManager_ChannelMessageHandler_get_chain_hashes,
3916 MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider {
3917 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
3919 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
3924 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) {
3925 <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())
3927 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) {
3928 <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())
3930 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) {
3931 <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())
3933 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) {
3934 <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())
3936 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) {
3937 <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())
3939 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) {
3940 <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())
3942 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) {
3943 <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())
3945 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) {
3946 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_shutdown(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
3948 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) {
3949 <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())
3951 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) {
3952 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_stfu(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
3954 extern "C" fn ChannelManager_ChannelMessageHandler_handle_splice(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::Splice) {
3955 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_splice(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
3957 extern "C" fn ChannelManager_ChannelMessageHandler_handle_splice_ack(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::SpliceAck) {
3958 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_splice_ack(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
3960 extern "C" fn ChannelManager_ChannelMessageHandler_handle_splice_locked(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::SpliceLocked) {
3961 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_splice_locked(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
3963 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) {
3964 <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())
3966 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) {
3967 <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())
3969 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) {
3970 <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())
3972 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) {
3973 <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())
3975 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) {
3976 <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())
3978 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) {
3979 <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())
3981 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) {
3982 <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())
3984 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) {
3985 <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())
3987 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) {
3988 <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())
3990 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) {
3991 <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())
3993 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) {
3994 <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())
3996 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) {
3997 <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())
3999 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) {
4000 <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())
4002 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) {
4003 <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())
4005 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) {
4006 <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())
4008 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) {
4009 <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())
4011 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) {
4012 <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())
4014 extern "C" fn ChannelManager_ChannelMessageHandler_peer_disconnected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) {
4015 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust())
4018 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 {
4019 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);
4020 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() };
4023 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) {
4024 <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())
4026 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) {
4027 <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())
4029 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) {
4030 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
4033 extern "C" fn ChannelManager_ChannelMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
4034 let mut ret = <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
4035 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
4038 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 {
4039 let mut ret = <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust());
4040 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
4043 extern "C" fn ChannelManager_ChannelMessageHandler_get_chain_hashes(this_arg: *const c_void) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ {
4044 let mut ret = <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::get_chain_hashes(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
4045 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() }) };
4049 impl From<nativeChannelManager> for crate::lightning::onion_message::offers::OffersMessageHandler {
4050 fn from(obj: nativeChannelManager) -> Self {
4051 let rust_obj = crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
4052 let mut ret = ChannelManager_as_OffersMessageHandler(&rust_obj);
4053 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
4054 core::mem::forget(rust_obj);
4055 ret.free = Some(ChannelManager_free_void);
4059 /// Constructs a new OffersMessageHandler which calls the relevant methods on this_arg.
4060 /// This copies the `inner` pointer in this_arg and thus the returned OffersMessageHandler must be freed before this_arg is
4062 pub extern "C" fn ChannelManager_as_OffersMessageHandler(this_arg: &ChannelManager) -> crate::lightning::onion_message::offers::OffersMessageHandler {
4063 crate::lightning::onion_message::offers::OffersMessageHandler {
4064 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
4066 handle_message: ChannelManager_OffersMessageHandler_handle_message,
4067 release_pending_messages: ChannelManager_OffersMessageHandler_release_pending_messages,
4072 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 {
4073 let mut ret = <nativeChannelManager as lightning::onion_message::offers::OffersMessageHandler<>>::handle_message(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, message.into_native());
4074 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()) }) };
4078 extern "C" fn ChannelManager_OffersMessageHandler_release_pending_messages(this_arg: *const c_void) -> crate::c_types::derived::CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ {
4079 let mut ret = <nativeChannelManager as lightning::onion_message::offers::OffersMessageHandler<>>::release_pending_messages(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
4080 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 }); };
4084 /// Fetches the set of [`InitFeatures`] flags that are provided by or required by
4085 /// [`ChannelManager`].
4087 pub extern "C" fn provided_init_features(config: &crate::lightning::util::config::UserConfig) -> crate::lightning::ln::features::InitFeatures {
4088 let mut ret = lightning::ln::channelmanager::provided_init_features(config.get_native_ref());
4089 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
4093 /// Serialize the CounterpartyForwardingInfo object into a byte array which can be read by CounterpartyForwardingInfo_read
4094 pub extern "C" fn CounterpartyForwardingInfo_write(obj: &crate::lightning::ln::channelmanager::CounterpartyForwardingInfo) -> crate::c_types::derived::CVec_u8Z {
4095 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
4098 pub(crate) extern "C" fn CounterpartyForwardingInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
4099 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCounterpartyForwardingInfo) })
4102 /// Read a CounterpartyForwardingInfo from a byte array, created by CounterpartyForwardingInfo_write
4103 pub extern "C" fn CounterpartyForwardingInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CounterpartyForwardingInfoDecodeErrorZ {
4104 let res: Result<lightning::ln::channelmanager::CounterpartyForwardingInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
4105 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() };
4109 /// Serialize the ChannelCounterparty object into a byte array which can be read by ChannelCounterparty_read
4110 pub extern "C" fn ChannelCounterparty_write(obj: &crate::lightning::ln::channelmanager::ChannelCounterparty) -> crate::c_types::derived::CVec_u8Z {
4111 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
4114 pub(crate) extern "C" fn ChannelCounterparty_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
4115 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelCounterparty) })
4118 /// Read a ChannelCounterparty from a byte array, created by ChannelCounterparty_write
4119 pub extern "C" fn ChannelCounterparty_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelCounterpartyDecodeErrorZ {
4120 let res: Result<lightning::ln::channelmanager::ChannelCounterparty, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
4121 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() };
4125 /// Serialize the ChannelDetails object into a byte array which can be read by ChannelDetails_read
4126 pub extern "C" fn ChannelDetails_write(obj: &crate::lightning::ln::channelmanager::ChannelDetails) -> crate::c_types::derived::CVec_u8Z {
4127 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
4130 pub(crate) extern "C" fn ChannelDetails_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
4131 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelDetails) })
4134 /// Read a ChannelDetails from a byte array, created by ChannelDetails_write
4135 pub extern "C" fn ChannelDetails_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelDetailsDecodeErrorZ {
4136 let res: Result<lightning::ln::channelmanager::ChannelDetails, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
4137 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() };
4141 /// Serialize the PhantomRouteHints object into a byte array which can be read by PhantomRouteHints_read
4142 pub extern "C" fn PhantomRouteHints_write(obj: &crate::lightning::ln::channelmanager::PhantomRouteHints) -> crate::c_types::derived::CVec_u8Z {
4143 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
4146 pub(crate) extern "C" fn PhantomRouteHints_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
4147 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePhantomRouteHints) })
4150 /// Read a PhantomRouteHints from a byte array, created by PhantomRouteHints_write
4151 pub extern "C" fn PhantomRouteHints_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PhantomRouteHintsDecodeErrorZ {
4152 let res: Result<lightning::ln::channelmanager::PhantomRouteHints, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
4153 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() };
4157 /// Serialize the BlindedForward object into a byte array which can be read by BlindedForward_read
4158 pub extern "C" fn BlindedForward_write(obj: &crate::lightning::ln::channelmanager::BlindedForward) -> crate::c_types::derived::CVec_u8Z {
4159 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
4162 pub(crate) extern "C" fn BlindedForward_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
4163 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBlindedForward) })
4166 /// Read a BlindedForward from a byte array, created by BlindedForward_write
4167 pub extern "C" fn BlindedForward_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BlindedForwardDecodeErrorZ {
4168 let res: Result<lightning::ln::channelmanager::BlindedForward, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
4169 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() };
4173 /// Serialize the PendingHTLCRouting object into a byte array which can be read by PendingHTLCRouting_read
4174 pub extern "C" fn PendingHTLCRouting_write(obj: &crate::lightning::ln::channelmanager::PendingHTLCRouting) -> crate::c_types::derived::CVec_u8Z {
4175 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
4178 pub(crate) extern "C" fn PendingHTLCRouting_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
4179 PendingHTLCRouting_write(unsafe { &*(obj as *const PendingHTLCRouting) })
4182 /// Read a PendingHTLCRouting from a byte array, created by PendingHTLCRouting_write
4183 pub extern "C" fn PendingHTLCRouting_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PendingHTLCRoutingDecodeErrorZ {
4184 let res: Result<lightning::ln::channelmanager::PendingHTLCRouting, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
4185 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() };
4189 /// Serialize the PendingHTLCInfo object into a byte array which can be read by PendingHTLCInfo_read
4190 pub extern "C" fn PendingHTLCInfo_write(obj: &crate::lightning::ln::channelmanager::PendingHTLCInfo) -> crate::c_types::derived::CVec_u8Z {
4191 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
4194 pub(crate) extern "C" fn PendingHTLCInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
4195 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePendingHTLCInfo) })
4198 /// Read a PendingHTLCInfo from a byte array, created by PendingHTLCInfo_write
4199 pub extern "C" fn PendingHTLCInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PendingHTLCInfoDecodeErrorZ {
4200 let res: Result<lightning::ln::channelmanager::PendingHTLCInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
4201 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() };
4205 /// Serialize the BlindedFailure object into a byte array which can be read by BlindedFailure_read
4206 pub extern "C" fn BlindedFailure_write(obj: &crate::lightning::ln::channelmanager::BlindedFailure) -> crate::c_types::derived::CVec_u8Z {
4207 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
4210 pub(crate) extern "C" fn BlindedFailure_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
4211 BlindedFailure_write(unsafe { &*(obj as *const BlindedFailure) })
4214 /// Read a BlindedFailure from a byte array, created by BlindedFailure_write
4215 pub extern "C" fn BlindedFailure_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BlindedFailureDecodeErrorZ {
4216 let res: Result<lightning::ln::channelmanager::BlindedFailure, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
4217 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() };
4221 /// Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
4222 pub extern "C" fn ChannelManager_write(obj: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_u8Z {
4223 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
4226 pub(crate) extern "C" fn ChannelManager_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
4227 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelManager) })
4230 /// Serialize the ChannelShutdownState object into a byte array which can be read by ChannelShutdownState_read
4231 pub extern "C" fn ChannelShutdownState_write(obj: &crate::lightning::ln::channelmanager::ChannelShutdownState) -> crate::c_types::derived::CVec_u8Z {
4232 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
4235 pub(crate) extern "C" fn ChannelShutdownState_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
4236 ChannelShutdownState_write(unsafe { &*(obj as *const ChannelShutdownState) })
4239 /// Read a ChannelShutdownState from a byte array, created by ChannelShutdownState_write
4240 pub extern "C" fn ChannelShutdownState_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelShutdownStateDecodeErrorZ {
4241 let res: Result<lightning::ln::channelmanager::ChannelShutdownState, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
4242 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() };
4246 use lightning::ln::channelmanager::ChannelManagerReadArgs as nativeChannelManagerReadArgsImport;
4247 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>;
4249 /// Arguments for the creation of a ChannelManager that are not deserialized.
4251 /// At a high-level, the process for deserializing a ChannelManager and resuming normal operation
4253 /// 1) Deserialize all stored [`ChannelMonitor`]s.
4254 /// 2) Deserialize the [`ChannelManager`] by filling in this struct and calling:
4255 /// `<(BlockHash, ChannelManager)>::read(reader, args)`
4256 /// This may result in closing some channels if the [`ChannelMonitor`] is newer than the stored
4257 /// [`ChannelManager`] state to ensure no loss of funds. Thus, transactions may be broadcasted.
4258 /// 3) If you are not fetching full blocks, register all relevant [`ChannelMonitor`] outpoints the
4259 /// same way you would handle a [`chain::Filter`] call using
4260 /// [`ChannelMonitor::get_outputs_to_watch`] and [`ChannelMonitor::get_funding_txo`].
4261 /// 4) Reconnect blocks on your [`ChannelMonitor`]s.
4262 /// 5) Disconnect/connect blocks on the [`ChannelManager`].
4263 /// 6) Re-persist the [`ChannelMonitor`]s to ensure the latest state is on disk.
4264 /// Note that if you're using a [`ChainMonitor`] for your [`chain::Watch`] implementation, you
4265 /// will likely accomplish this as a side-effect of calling [`chain::Watch::watch_channel`] in
4267 /// 7) Move the [`ChannelMonitor`]s into your local [`chain::Watch`]. If you're using a
4268 /// [`ChainMonitor`], this is done by calling [`chain::Watch::watch_channel`].
4270 /// Note that the ordering of #4-7 is not of importance, however all four must occur before you
4271 /// call any other methods on the newly-deserialized [`ChannelManager`].
4273 /// Note that because some channels may be closed during deserialization, it is critical that you
4274 /// always deserialize only the latest version of a ChannelManager and ChannelMonitors available to
4275 /// you. If you deserialize an old ChannelManager (during which force-closure transactions may be
4276 /// broadcast), and then later deserialize a newer version of the same ChannelManager (which will
4277 /// not force-close the same channels but consider them live), you may end up revoking a state for
4278 /// which you've already broadcasted the transaction.
4280 /// [`ChainMonitor`]: crate::chain::chainmonitor::ChainMonitor
4283 pub struct ChannelManagerReadArgs {
4284 /// A pointer to the opaque Rust object.
4286 /// Nearly everywhere, inner must be non-null, however in places where
4287 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
4288 pub inner: *mut nativeChannelManagerReadArgs,
4289 /// Indicates that this is the only struct which contains the same pointer.
4291 /// Rust functions which take ownership of an object provided via an argument require
4292 /// this to be true and invalidate the object pointed to by inner.
4296 impl Drop for ChannelManagerReadArgs {
4297 fn drop(&mut self) {
4298 if self.is_owned && !<*mut nativeChannelManagerReadArgs>::is_null(self.inner) {
4299 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
4303 /// Frees any resources used by the ChannelManagerReadArgs, if is_owned is set and inner is non-NULL.
4305 pub extern "C" fn ChannelManagerReadArgs_free(this_obj: ChannelManagerReadArgs) { }
4307 /// Used only if an object of this type is returned as a trait impl by a method
4308 pub(crate) extern "C" fn ChannelManagerReadArgs_free_void(this_ptr: *mut c_void) {
4309 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelManagerReadArgs) };
4312 impl ChannelManagerReadArgs {
4313 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManagerReadArgs {
4314 unsafe { &*ObjOps::untweak_ptr(self.inner) }
4316 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManagerReadArgs {
4317 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
4319 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
4320 pub(crate) fn take_inner(mut self) -> *mut nativeChannelManagerReadArgs {
4321 assert!(self.is_owned);
4322 let ret = ObjOps::untweak_ptr(self.inner);
4323 self.inner = core::ptr::null_mut();
4327 /// A cryptographically secure source of entropy.
4329 pub extern "C" fn ChannelManagerReadArgs_get_entropy_source(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::sign::EntropySource {
4330 let mut inner_val = &mut this_ptr.get_native_mut_ref().entropy_source;
4333 /// A cryptographically secure source of entropy.
4335 pub extern "C" fn ChannelManagerReadArgs_set_entropy_source(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::sign::EntropySource) {
4336 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.entropy_source = val;
4338 /// A signer that is able to perform node-scoped cryptographic operations.
4340 pub extern "C" fn ChannelManagerReadArgs_get_node_signer(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::sign::NodeSigner {
4341 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_signer;
4344 /// A signer that is able to perform node-scoped cryptographic operations.
4346 pub extern "C" fn ChannelManagerReadArgs_set_node_signer(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::sign::NodeSigner) {
4347 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_signer = val;
4349 /// The keys provider which will give us relevant keys. Some keys will be loaded during
4350 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
4353 pub extern "C" fn ChannelManagerReadArgs_get_signer_provider(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::sign::SignerProvider {
4354 let mut inner_val = &mut this_ptr.get_native_mut_ref().signer_provider;
4357 /// The keys provider which will give us relevant keys. Some keys will be loaded during
4358 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
4361 pub extern "C" fn ChannelManagerReadArgs_set_signer_provider(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::sign::SignerProvider) {
4362 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.signer_provider = val;
4364 /// The fee_estimator for use in the ChannelManager in the future.
4366 /// No calls to the FeeEstimator will be made during deserialization.
4368 pub extern "C" fn ChannelManagerReadArgs_get_fee_estimator(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::FeeEstimator {
4369 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_estimator;
4372 /// The fee_estimator for use in the ChannelManager in the future.
4374 /// No calls to the FeeEstimator will be made during deserialization.
4376 pub extern "C" fn ChannelManagerReadArgs_set_fee_estimator(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::FeeEstimator) {
4377 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_estimator = val;
4379 /// The chain::Watch for use in the ChannelManager in the future.
4381 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
4382 /// you have deserialized ChannelMonitors separately and will add them to your
4383 /// chain::Watch after deserializing this ChannelManager.
4385 pub extern "C" fn ChannelManagerReadArgs_get_chain_monitor(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::Watch {
4386 let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_monitor;
4389 /// The chain::Watch for use in the ChannelManager in the future.
4391 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
4392 /// you have deserialized ChannelMonitors separately and will add them to your
4393 /// chain::Watch after deserializing this ChannelManager.
4395 pub extern "C" fn ChannelManagerReadArgs_set_chain_monitor(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::Watch) {
4396 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_monitor = val;
4398 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
4399 /// used to broadcast the latest local commitment transactions of channels which must be
4400 /// force-closed during deserialization.
4402 pub extern "C" fn ChannelManagerReadArgs_get_tx_broadcaster(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::BroadcasterInterface {
4403 let mut inner_val = &mut this_ptr.get_native_mut_ref().tx_broadcaster;
4406 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
4407 /// used to broadcast the latest local commitment transactions of channels which must be
4408 /// force-closed during deserialization.
4410 pub extern "C" fn ChannelManagerReadArgs_set_tx_broadcaster(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::BroadcasterInterface) {
4411 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.tx_broadcaster = val;
4413 /// The router which will be used in the ChannelManager in the future for finding routes
4414 /// on-the-fly for trampoline payments. Absent in private nodes that don't support forwarding.
4416 /// No calls to the router will be made during deserialization.
4418 pub extern "C" fn ChannelManagerReadArgs_get_router(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::routing::router::Router {
4419 let mut inner_val = &mut this_ptr.get_native_mut_ref().router;
4422 /// The router which will be used in the ChannelManager in the future for finding routes
4423 /// on-the-fly for trampoline payments. Absent in private nodes that don't support forwarding.
4425 /// No calls to the router will be made during deserialization.
4427 pub extern "C" fn ChannelManagerReadArgs_set_router(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::routing::router::Router) {
4428 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.router = val;
4430 /// The Logger for use in the ChannelManager and which may be used to log information during
4431 /// deserialization.
4433 pub extern "C" fn ChannelManagerReadArgs_get_logger(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::util::logger::Logger {
4434 let mut inner_val = &mut this_ptr.get_native_mut_ref().logger;
4437 /// The Logger for use in the ChannelManager and which may be used to log information during
4438 /// deserialization.
4440 pub extern "C" fn ChannelManagerReadArgs_set_logger(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::logger::Logger) {
4441 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.logger = val;
4443 /// Default settings used for new channels. Any existing channels will continue to use the
4444 /// runtime settings which were stored when the ChannelManager was serialized.
4446 pub extern "C" fn ChannelManagerReadArgs_get_default_config(this_ptr: &ChannelManagerReadArgs) -> crate::lightning::util::config::UserConfig {
4447 let mut inner_val = &mut this_ptr.get_native_mut_ref().default_config;
4448 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 }
4450 /// Default settings used for new channels. Any existing channels will continue to use the
4451 /// runtime settings which were stored when the ChannelManager was serialized.
4453 pub extern "C" fn ChannelManagerReadArgs_set_default_config(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::config::UserConfig) {
4454 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.default_config = *unsafe { Box::from_raw(val.take_inner()) };
4456 /// Simple utility function to create a ChannelManagerReadArgs which creates the monitor
4457 /// HashMap for you. This is primarily useful for C bindings where it is not practical to
4458 /// populate a HashMap directly from C.
4461 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 {
4462 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() }); };
4463 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);
4464 crate::lightning::ln::channelmanager::ChannelManagerReadArgs { inner: ObjOps::heap_alloc(ret), is_owned: true }
4468 /// Read a C2Tuple_ThirtyTwoBytesChannelManagerZ from a byte array, created by C2Tuple_ThirtyTwoBytesChannelManagerZ_write
4469 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 {
4470 let arg_conv = *unsafe { Box::from_raw(arg.take_inner()) };
4471 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);
4472 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() };