051661db62d85ce7b8e8d188294b7e2aa202edd5
[ldk-c-bindings] / lightning-c-bindings / src / lightning / ln / channelmanager.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
8
9 //! The top-level channel management and payment tracking stuff lives here.
10 //!
11 //! The [`ChannelManager`] is the main chunk of logic implementing the lightning protocol and is
12 //! responsible for tracking which channels are open, HTLCs are in flight and reestablishing those
13 //! upon reconnect to the relevant peer(s).
14 //!
15 //! It does not manage routing logic (see [`Router`] for that) nor does it manage constructing
16 //! on-chain transactions (it only monitors the chain to watch for any force-closes that might
17 //! imply it needs to fail HTLCs/payments/channels it manages).
18
19 use alloc::str::FromStr;
20 use core::ffi::c_void;
21 use core::convert::Infallible;
22 use bitcoin::hashes::Hash;
23 use crate::c_types::*;
24 #[cfg(feature="no-std")]
25 use alloc::{vec::Vec, boxed::Box};
26
27 /// This enum is used to specify which error data to send to peers when failing back an HTLC
28 /// using [`ChannelManager::fail_htlc_backwards_with_reason`].
29 ///
30 /// For more info on failure codes, see <https://github.com/lightning/bolts/blob/master/04-onion-routing.md#failure-messages>.
31 #[derive(Clone)]
32 #[must_use]
33 #[repr(C)]
34 pub enum FailureCode {
35         /// We had a temporary error processing the payment. Useful if no other error codes fit
36         /// and you want to indicate that the payer may want to retry.
37         TemporaryNodeFailure,
38         /// We have a required feature which was not in this onion. For example, you may require
39         /// some additional metadata that was not provided with this payment.
40         RequiredNodeFeatureMissing,
41         /// You may wish to use this when a `payment_preimage` is unknown, or the CLTV expiry of
42         /// the HTLC is too close to the current block height for safe handling.
43         /// Using this failure code in [`ChannelManager::fail_htlc_backwards_with_reason`] is
44         /// equivalent to calling [`ChannelManager::fail_htlc_backwards`].
45         IncorrectOrUnknownPaymentDetails,
46 }
47 use lightning::ln::channelmanager::FailureCode as FailureCodeImport;
48 pub(crate) type nativeFailureCode = FailureCodeImport;
49
50 impl FailureCode {
51         #[allow(unused)]
52         pub(crate) fn to_native(&self) -> nativeFailureCode {
53                 match self {
54                         FailureCode::TemporaryNodeFailure => nativeFailureCode::TemporaryNodeFailure,
55                         FailureCode::RequiredNodeFeatureMissing => nativeFailureCode::RequiredNodeFeatureMissing,
56                         FailureCode::IncorrectOrUnknownPaymentDetails => nativeFailureCode::IncorrectOrUnknownPaymentDetails,
57                 }
58         }
59         #[allow(unused)]
60         pub(crate) fn into_native(self) -> nativeFailureCode {
61                 match self {
62                         FailureCode::TemporaryNodeFailure => nativeFailureCode::TemporaryNodeFailure,
63                         FailureCode::RequiredNodeFeatureMissing => nativeFailureCode::RequiredNodeFeatureMissing,
64                         FailureCode::IncorrectOrUnknownPaymentDetails => nativeFailureCode::IncorrectOrUnknownPaymentDetails,
65                 }
66         }
67         #[allow(unused)]
68         pub(crate) fn from_native(native: &nativeFailureCode) -> Self {
69                 match native {
70                         nativeFailureCode::TemporaryNodeFailure => FailureCode::TemporaryNodeFailure,
71                         nativeFailureCode::RequiredNodeFeatureMissing => FailureCode::RequiredNodeFeatureMissing,
72                         nativeFailureCode::IncorrectOrUnknownPaymentDetails => FailureCode::IncorrectOrUnknownPaymentDetails,
73                 }
74         }
75         #[allow(unused)]
76         pub(crate) fn native_into(native: nativeFailureCode) -> Self {
77                 match native {
78                         nativeFailureCode::TemporaryNodeFailure => FailureCode::TemporaryNodeFailure,
79                         nativeFailureCode::RequiredNodeFeatureMissing => FailureCode::RequiredNodeFeatureMissing,
80                         nativeFailureCode::IncorrectOrUnknownPaymentDetails => FailureCode::IncorrectOrUnknownPaymentDetails,
81                 }
82         }
83 }
84 /// Creates a copy of the FailureCode
85 #[no_mangle]
86 pub extern "C" fn FailureCode_clone(orig: &FailureCode) -> FailureCode {
87         orig.clone()
88 }
89 #[no_mangle]
90 /// Utility method to constructs a new TemporaryNodeFailure-variant FailureCode
91 pub extern "C" fn FailureCode_temporary_node_failure() -> FailureCode {
92         FailureCode::TemporaryNodeFailure}
93 #[no_mangle]
94 /// Utility method to constructs a new RequiredNodeFeatureMissing-variant FailureCode
95 pub extern "C" fn FailureCode_required_node_feature_missing() -> FailureCode {
96         FailureCode::RequiredNodeFeatureMissing}
97 #[no_mangle]
98 /// Utility method to constructs a new IncorrectOrUnknownPaymentDetails-variant FailureCode
99 pub extern "C" fn FailureCode_incorrect_or_unknown_payment_details() -> FailureCode {
100         FailureCode::IncorrectOrUnknownPaymentDetails}
101
102 use lightning::ln::channelmanager::ChannelManager as nativeChannelManagerImport;
103 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>;
104
105 /// Manager which keeps track of a number of channels and sends messages to the appropriate
106 /// channel, also tracking HTLC preimages and forwarding onion packets appropriately.
107 ///
108 /// Implements [`ChannelMessageHandler`], handling the multi-channel parts and passing things through
109 /// to individual Channels.
110 ///
111 /// Implements [`Writeable`] to write out all channel state to disk. Implies [`peer_disconnected`] for
112 /// all peers during write/read (though does not modify this instance, only the instance being
113 /// serialized). This will result in any channels which have not yet exchanged [`funding_created`] (i.e.,
114 /// called [`funding_transaction_generated`] for outbound channels) being closed.
115 ///
116 /// Note that you can be a bit lazier about writing out `ChannelManager` than you can be with
117 /// [`ChannelMonitor`]. With [`ChannelMonitor`] you MUST write each monitor update out to disk before
118 /// returning from [`chain::Watch::watch_channel`]/[`update_channel`], with ChannelManagers, writing updates
119 /// happens out-of-band (and will prevent any other `ChannelManager` operations from occurring during
120 /// the serialization process). If the deserialized version is out-of-date compared to the
121 /// [`ChannelMonitor`] passed by reference to [`read`], those channels will be force-closed based on the
122 /// `ChannelMonitor` state and no funds will be lost (mod on-chain transaction fees).
123 ///
124 /// Note that the deserializer is only implemented for `(`[`BlockHash`]`, `[`ChannelManager`]`)`, which
125 /// tells you the last block hash which was connected. You should get the best block tip before using the manager.
126 /// See [`chain::Listen`] and [`chain::Confirm`] for more details.
127 ///
128 /// Note that `ChannelManager` is responsible for tracking liveness of its channels and generating
129 /// [`ChannelUpdate`] messages informing peers that the channel is temporarily disabled. To avoid
130 /// spam due to quick disconnection/reconnection, updates are not sent until the channel has been
131 /// offline for a full minute. In order to track this, you must call
132 /// [`timer_tick_occurred`] roughly once per minute, though it doesn't have to be perfect.
133 ///
134 /// To avoid trivial DoS issues, `ChannelManager` limits the number of inbound connections and
135 /// inbound channels without confirmed funding transactions. This may result in nodes which we do
136 /// not have a channel with being unable to connect to us or open new channels with us if we have
137 /// many peers with unfunded channels.
138 ///
139 /// Because it is an indication of trust, inbound channels which we've accepted as 0conf are
140 /// exempted from the count of unfunded channels. Similarly, outbound channels and connections are
141 /// never limited. Please ensure you limit the count of such channels yourself.
142 ///
143 /// Rather than using a plain `ChannelManager`, it is preferable to use either a [`SimpleArcChannelManager`]
144 /// a [`SimpleRefChannelManager`], for conciseness. See their documentation for more details, but
145 /// essentially you should default to using a [`SimpleRefChannelManager`], and use a
146 /// [`SimpleArcChannelManager`] when you require a `ChannelManager` with a static lifetime, such as when
147 /// you're using lightning-net-tokio.
148 ///
149 /// [`peer_disconnected`]: msgs::ChannelMessageHandler::peer_disconnected
150 /// [`funding_created`]: msgs::FundingCreated
151 /// [`funding_transaction_generated`]: Self::funding_transaction_generated
152 /// [`BlockHash`]: bitcoin::hash_types::BlockHash
153 /// [`update_channel`]: chain::Watch::update_channel
154 /// [`ChannelUpdate`]: msgs::ChannelUpdate
155 /// [`timer_tick_occurred`]: Self::timer_tick_occurred
156 /// [`read`]: ReadableArgs::read
157 #[must_use]
158 #[repr(C)]
159 pub struct ChannelManager {
160         /// A pointer to the opaque Rust object.
161
162         /// Nearly everywhere, inner must be non-null, however in places where
163         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
164         pub inner: *mut nativeChannelManager,
165         /// Indicates that this is the only struct which contains the same pointer.
166
167         /// Rust functions which take ownership of an object provided via an argument require
168         /// this to be true and invalidate the object pointed to by inner.
169         pub is_owned: bool,
170 }
171
172 impl Drop for ChannelManager {
173         fn drop(&mut self) {
174                 if self.is_owned && !<*mut nativeChannelManager>::is_null(self.inner) {
175                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
176                 }
177         }
178 }
179 /// Frees any resources used by the ChannelManager, if is_owned is set and inner is non-NULL.
180 #[no_mangle]
181 pub extern "C" fn ChannelManager_free(this_obj: ChannelManager) { }
182 #[allow(unused)]
183 /// Used only if an object of this type is returned as a trait impl by a method
184 pub(crate) extern "C" fn ChannelManager_free_void(this_ptr: *mut c_void) {
185         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelManager) };
186 }
187 #[allow(unused)]
188 impl ChannelManager {
189         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManager {
190                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
191         }
192         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManager {
193                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
194         }
195         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
196         pub(crate) fn take_inner(mut self) -> *mut nativeChannelManager {
197                 assert!(self.is_owned);
198                 let ret = ObjOps::untweak_ptr(self.inner);
199                 self.inner = core::ptr::null_mut();
200                 ret
201         }
202 }
203
204 use lightning::ln::channelmanager::ChainParameters as nativeChainParametersImport;
205 pub(crate) type nativeChainParameters = nativeChainParametersImport;
206
207 /// Chain-related parameters used to construct a new `ChannelManager`.
208 ///
209 /// Typically, the block-specific parameters are derived from the best block hash for the network,
210 /// as a newly constructed `ChannelManager` will not have created any channels yet. These parameters
211 /// are not needed when deserializing a previously constructed `ChannelManager`.
212 #[must_use]
213 #[repr(C)]
214 pub struct ChainParameters {
215         /// A pointer to the opaque Rust object.
216
217         /// Nearly everywhere, inner must be non-null, however in places where
218         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
219         pub inner: *mut nativeChainParameters,
220         /// Indicates that this is the only struct which contains the same pointer.
221
222         /// Rust functions which take ownership of an object provided via an argument require
223         /// this to be true and invalidate the object pointed to by inner.
224         pub is_owned: bool,
225 }
226
227 impl Drop for ChainParameters {
228         fn drop(&mut self) {
229                 if self.is_owned && !<*mut nativeChainParameters>::is_null(self.inner) {
230                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
231                 }
232         }
233 }
234 /// Frees any resources used by the ChainParameters, if is_owned is set and inner is non-NULL.
235 #[no_mangle]
236 pub extern "C" fn ChainParameters_free(this_obj: ChainParameters) { }
237 #[allow(unused)]
238 /// Used only if an object of this type is returned as a trait impl by a method
239 pub(crate) extern "C" fn ChainParameters_free_void(this_ptr: *mut c_void) {
240         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChainParameters) };
241 }
242 #[allow(unused)]
243 impl ChainParameters {
244         pub(crate) fn get_native_ref(&self) -> &'static nativeChainParameters {
245                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
246         }
247         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChainParameters {
248                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
249         }
250         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
251         pub(crate) fn take_inner(mut self) -> *mut nativeChainParameters {
252                 assert!(self.is_owned);
253                 let ret = ObjOps::untweak_ptr(self.inner);
254                 self.inner = core::ptr::null_mut();
255                 ret
256         }
257 }
258 /// The network for determining the `chain_hash` in Lightning messages.
259 #[no_mangle]
260 pub extern "C" fn ChainParameters_get_network(this_ptr: &ChainParameters) -> crate::bitcoin::network::Network {
261         let mut inner_val = &mut this_ptr.get_native_mut_ref().network;
262         crate::bitcoin::network::Network::from_bitcoin(inner_val)
263 }
264 /// The network for determining the `chain_hash` in Lightning messages.
265 #[no_mangle]
266 pub extern "C" fn ChainParameters_set_network(this_ptr: &mut ChainParameters, mut val: crate::bitcoin::network::Network) {
267         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.network = val.into_bitcoin();
268 }
269 /// The hash and height of the latest block successfully connected.
270 ///
271 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
272 #[no_mangle]
273 pub extern "C" fn ChainParameters_get_best_block(this_ptr: &ChainParameters) -> crate::lightning::chain::BestBlock {
274         let mut inner_val = &mut this_ptr.get_native_mut_ref().best_block;
275         crate::lightning::chain::BestBlock { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::chain::BestBlock<>) as *mut _) }, is_owned: false }
276 }
277 /// The hash and height of the latest block successfully connected.
278 ///
279 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
280 #[no_mangle]
281 pub extern "C" fn ChainParameters_set_best_block(this_ptr: &mut ChainParameters, mut val: crate::lightning::chain::BestBlock) {
282         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.best_block = *unsafe { Box::from_raw(val.take_inner()) };
283 }
284 /// Constructs a new ChainParameters given each field
285 #[must_use]
286 #[no_mangle]
287 pub extern "C" fn ChainParameters_new(mut network_arg: crate::bitcoin::network::Network, mut best_block_arg: crate::lightning::chain::BestBlock) -> ChainParameters {
288         ChainParameters { inner: ObjOps::heap_alloc(nativeChainParameters {
289                 network: network_arg.into_bitcoin(),
290                 best_block: *unsafe { Box::from_raw(best_block_arg.take_inner()) },
291         }), is_owned: true }
292 }
293 impl Clone for ChainParameters {
294         fn clone(&self) -> Self {
295                 Self {
296                         inner: if <*mut nativeChainParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
297                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
298                         is_owned: true,
299                 }
300         }
301 }
302 #[allow(unused)]
303 /// Used only if an object of this type is returned as a trait impl by a method
304 pub(crate) extern "C" fn ChainParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
305         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChainParameters)).clone() })) as *mut c_void
306 }
307 #[no_mangle]
308 /// Creates a copy of the ChainParameters
309 pub extern "C" fn ChainParameters_clone(orig: &ChainParameters) -> ChainParameters {
310         orig.clone()
311 }
312 /// The amount of time in blocks we require our counterparty wait to claim their money (ie time
313 /// between when we, or our watchtower, must check for them having broadcast a theft transaction).
314 ///
315 /// This can be increased (but not decreased) through [`ChannelHandshakeConfig::our_to_self_delay`]
316 ///
317 /// [`ChannelHandshakeConfig::our_to_self_delay`]: crate::util::config::ChannelHandshakeConfig::our_to_self_delay
318
319 #[no_mangle]
320 pub static BREAKDOWN_TIMEOUT: u16 = lightning::ln::channelmanager::BREAKDOWN_TIMEOUT;
321 /// The minimum number of blocks between an inbound HTLC's CLTV and the corresponding outbound
322 /// HTLC's CLTV. The current default represents roughly seven hours of blocks at six blocks/hour.
323 ///
324 /// This can be increased (but not decreased) through [`ChannelConfig::cltv_expiry_delta`]
325 ///
326 /// [`ChannelConfig::cltv_expiry_delta`]: crate::util::config::ChannelConfig::cltv_expiry_delta
327
328 #[no_mangle]
329 pub static MIN_CLTV_EXPIRY_DELTA: u16 = lightning::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA;
330 /// Minimum CLTV difference between the current block height and received inbound payments.
331 /// Invoices generated for payment to us must set their `min_final_cltv_expiry_delta` field to at least
332 /// this value.
333
334 #[no_mangle]
335 pub static MIN_FINAL_CLTV_EXPIRY_DELTA: u16 = lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA;
336
337 use lightning::ln::channelmanager::CounterpartyForwardingInfo as nativeCounterpartyForwardingInfoImport;
338 pub(crate) type nativeCounterpartyForwardingInfo = nativeCounterpartyForwardingInfoImport;
339
340 /// Information needed for constructing an invoice route hint for this channel.
341 #[must_use]
342 #[repr(C)]
343 pub struct CounterpartyForwardingInfo {
344         /// A pointer to the opaque Rust object.
345
346         /// Nearly everywhere, inner must be non-null, however in places where
347         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
348         pub inner: *mut nativeCounterpartyForwardingInfo,
349         /// Indicates that this is the only struct which contains the same pointer.
350
351         /// Rust functions which take ownership of an object provided via an argument require
352         /// this to be true and invalidate the object pointed to by inner.
353         pub is_owned: bool,
354 }
355
356 impl Drop for CounterpartyForwardingInfo {
357         fn drop(&mut self) {
358                 if self.is_owned && !<*mut nativeCounterpartyForwardingInfo>::is_null(self.inner) {
359                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
360                 }
361         }
362 }
363 /// Frees any resources used by the CounterpartyForwardingInfo, if is_owned is set and inner is non-NULL.
364 #[no_mangle]
365 pub extern "C" fn CounterpartyForwardingInfo_free(this_obj: CounterpartyForwardingInfo) { }
366 #[allow(unused)]
367 /// Used only if an object of this type is returned as a trait impl by a method
368 pub(crate) extern "C" fn CounterpartyForwardingInfo_free_void(this_ptr: *mut c_void) {
369         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeCounterpartyForwardingInfo) };
370 }
371 #[allow(unused)]
372 impl CounterpartyForwardingInfo {
373         pub(crate) fn get_native_ref(&self) -> &'static nativeCounterpartyForwardingInfo {
374                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
375         }
376         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCounterpartyForwardingInfo {
377                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
378         }
379         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
380         pub(crate) fn take_inner(mut self) -> *mut nativeCounterpartyForwardingInfo {
381                 assert!(self.is_owned);
382                 let ret = ObjOps::untweak_ptr(self.inner);
383                 self.inner = core::ptr::null_mut();
384                 ret
385         }
386 }
387 /// Base routing fee in millisatoshis.
388 #[no_mangle]
389 pub extern "C" fn CounterpartyForwardingInfo_get_fee_base_msat(this_ptr: &CounterpartyForwardingInfo) -> u32 {
390         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_base_msat;
391         *inner_val
392 }
393 /// Base routing fee in millisatoshis.
394 #[no_mangle]
395 pub extern "C" fn CounterpartyForwardingInfo_set_fee_base_msat(this_ptr: &mut CounterpartyForwardingInfo, mut val: u32) {
396         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_base_msat = val;
397 }
398 /// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
399 #[no_mangle]
400 pub extern "C" fn CounterpartyForwardingInfo_get_fee_proportional_millionths(this_ptr: &CounterpartyForwardingInfo) -> u32 {
401         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_proportional_millionths;
402         *inner_val
403 }
404 /// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
405 #[no_mangle]
406 pub extern "C" fn CounterpartyForwardingInfo_set_fee_proportional_millionths(this_ptr: &mut CounterpartyForwardingInfo, mut val: u32) {
407         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_proportional_millionths = val;
408 }
409 /// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
410 /// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
411 /// `cltv_expiry_delta` for more details.
412 #[no_mangle]
413 pub extern "C" fn CounterpartyForwardingInfo_get_cltv_expiry_delta(this_ptr: &CounterpartyForwardingInfo) -> u16 {
414         let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
415         *inner_val
416 }
417 /// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
418 /// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
419 /// `cltv_expiry_delta` for more details.
420 #[no_mangle]
421 pub extern "C" fn CounterpartyForwardingInfo_set_cltv_expiry_delta(this_ptr: &mut CounterpartyForwardingInfo, mut val: u16) {
422         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
423 }
424 /// Constructs a new CounterpartyForwardingInfo given each field
425 #[must_use]
426 #[no_mangle]
427 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 {
428         CounterpartyForwardingInfo { inner: ObjOps::heap_alloc(nativeCounterpartyForwardingInfo {
429                 fee_base_msat: fee_base_msat_arg,
430                 fee_proportional_millionths: fee_proportional_millionths_arg,
431                 cltv_expiry_delta: cltv_expiry_delta_arg,
432         }), is_owned: true }
433 }
434 impl Clone for CounterpartyForwardingInfo {
435         fn clone(&self) -> Self {
436                 Self {
437                         inner: if <*mut nativeCounterpartyForwardingInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
438                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
439                         is_owned: true,
440                 }
441         }
442 }
443 #[allow(unused)]
444 /// Used only if an object of this type is returned as a trait impl by a method
445 pub(crate) extern "C" fn CounterpartyForwardingInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
446         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCounterpartyForwardingInfo)).clone() })) as *mut c_void
447 }
448 #[no_mangle]
449 /// Creates a copy of the CounterpartyForwardingInfo
450 pub extern "C" fn CounterpartyForwardingInfo_clone(orig: &CounterpartyForwardingInfo) -> CounterpartyForwardingInfo {
451         orig.clone()
452 }
453
454 use lightning::ln::channelmanager::ChannelCounterparty as nativeChannelCounterpartyImport;
455 pub(crate) type nativeChannelCounterparty = nativeChannelCounterpartyImport;
456
457 /// Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
458 /// to better separate parameters.
459 #[must_use]
460 #[repr(C)]
461 pub struct ChannelCounterparty {
462         /// A pointer to the opaque Rust object.
463
464         /// Nearly everywhere, inner must be non-null, however in places where
465         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
466         pub inner: *mut nativeChannelCounterparty,
467         /// Indicates that this is the only struct which contains the same pointer.
468
469         /// Rust functions which take ownership of an object provided via an argument require
470         /// this to be true and invalidate the object pointed to by inner.
471         pub is_owned: bool,
472 }
473
474 impl Drop for ChannelCounterparty {
475         fn drop(&mut self) {
476                 if self.is_owned && !<*mut nativeChannelCounterparty>::is_null(self.inner) {
477                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
478                 }
479         }
480 }
481 /// Frees any resources used by the ChannelCounterparty, if is_owned is set and inner is non-NULL.
482 #[no_mangle]
483 pub extern "C" fn ChannelCounterparty_free(this_obj: ChannelCounterparty) { }
484 #[allow(unused)]
485 /// Used only if an object of this type is returned as a trait impl by a method
486 pub(crate) extern "C" fn ChannelCounterparty_free_void(this_ptr: *mut c_void) {
487         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelCounterparty) };
488 }
489 #[allow(unused)]
490 impl ChannelCounterparty {
491         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelCounterparty {
492                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
493         }
494         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelCounterparty {
495                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
496         }
497         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
498         pub(crate) fn take_inner(mut self) -> *mut nativeChannelCounterparty {
499                 assert!(self.is_owned);
500                 let ret = ObjOps::untweak_ptr(self.inner);
501                 self.inner = core::ptr::null_mut();
502                 ret
503         }
504 }
505 /// The node_id of our counterparty
506 #[no_mangle]
507 pub extern "C" fn ChannelCounterparty_get_node_id(this_ptr: &ChannelCounterparty) -> crate::c_types::PublicKey {
508         let mut inner_val = &mut this_ptr.get_native_mut_ref().node_id;
509         crate::c_types::PublicKey::from_rust(&inner_val)
510 }
511 /// The node_id of our counterparty
512 #[no_mangle]
513 pub extern "C" fn ChannelCounterparty_set_node_id(this_ptr: &mut ChannelCounterparty, mut val: crate::c_types::PublicKey) {
514         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_id = val.into_rust();
515 }
516 /// The Features the channel counterparty provided upon last connection.
517 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
518 /// many routing-relevant features are present in the init context.
519 #[no_mangle]
520 pub extern "C" fn ChannelCounterparty_get_features(this_ptr: &ChannelCounterparty) -> crate::lightning::ln::features::InitFeatures {
521         let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
522         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 }
523 }
524 /// The Features the channel counterparty provided upon last connection.
525 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
526 /// many routing-relevant features are present in the init context.
527 #[no_mangle]
528 pub extern "C" fn ChannelCounterparty_set_features(this_ptr: &mut ChannelCounterparty, mut val: crate::lightning::ln::features::InitFeatures) {
529         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
530 }
531 /// The value, in satoshis, that must always be held in the channel for our counterparty. This
532 /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
533 /// claiming at least this value on chain.
534 ///
535 /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
536 ///
537 /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
538 #[no_mangle]
539 pub extern "C" fn ChannelCounterparty_get_unspendable_punishment_reserve(this_ptr: &ChannelCounterparty) -> u64 {
540         let mut inner_val = &mut this_ptr.get_native_mut_ref().unspendable_punishment_reserve;
541         *inner_val
542 }
543 /// The value, in satoshis, that must always be held in the channel for our counterparty. This
544 /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
545 /// claiming at least this value on chain.
546 ///
547 /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
548 ///
549 /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
550 #[no_mangle]
551 pub extern "C" fn ChannelCounterparty_set_unspendable_punishment_reserve(this_ptr: &mut ChannelCounterparty, mut val: u64) {
552         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = val;
553 }
554 /// Information on the fees and requirements that the counterparty requires when forwarding
555 /// payments to us through this channel.
556 ///
557 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
558 #[no_mangle]
559 pub extern "C" fn ChannelCounterparty_get_forwarding_info(this_ptr: &ChannelCounterparty) -> crate::lightning::ln::channelmanager::CounterpartyForwardingInfo {
560         let mut inner_val = &mut this_ptr.get_native_mut_ref().forwarding_info;
561         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 };
562         local_inner_val
563 }
564 /// Information on the fees and requirements that the counterparty requires when forwarding
565 /// payments to us through this channel.
566 ///
567 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
568 #[no_mangle]
569 pub extern "C" fn ChannelCounterparty_set_forwarding_info(this_ptr: &mut ChannelCounterparty, mut val: crate::lightning::ln::channelmanager::CounterpartyForwardingInfo) {
570         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
571         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.forwarding_info = local_val;
572 }
573 /// The smallest value HTLC (in msat) the remote peer will accept, for this channel. This field
574 /// is only `None` before we have received either the `OpenChannel` or `AcceptChannel` message
575 /// from the remote peer, or for `ChannelCounterparty` objects serialized prior to LDK 0.0.107.
576 #[no_mangle]
577 pub extern "C" fn ChannelCounterparty_get_outbound_htlc_minimum_msat(this_ptr: &ChannelCounterparty) -> crate::c_types::derived::COption_u64Z {
578         let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_htlc_minimum_msat;
579         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() }) };
580         local_inner_val
581 }
582 /// The smallest value HTLC (in msat) the remote peer will accept, for this channel. This field
583 /// is only `None` before we have received either the `OpenChannel` or `AcceptChannel` message
584 /// from the remote peer, or for `ChannelCounterparty` objects serialized prior to LDK 0.0.107.
585 #[no_mangle]
586 pub extern "C" fn ChannelCounterparty_set_outbound_htlc_minimum_msat(this_ptr: &mut ChannelCounterparty, mut val: crate::c_types::derived::COption_u64Z) {
587         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
588         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_htlc_minimum_msat = local_val;
589 }
590 /// The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
591 #[no_mangle]
592 pub extern "C" fn ChannelCounterparty_get_outbound_htlc_maximum_msat(this_ptr: &ChannelCounterparty) -> crate::c_types::derived::COption_u64Z {
593         let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_htlc_maximum_msat;
594         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() }) };
595         local_inner_val
596 }
597 /// The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
598 #[no_mangle]
599 pub extern "C" fn ChannelCounterparty_set_outbound_htlc_maximum_msat(this_ptr: &mut ChannelCounterparty, mut val: crate::c_types::derived::COption_u64Z) {
600         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
601         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_htlc_maximum_msat = local_val;
602 }
603 /// Constructs a new ChannelCounterparty given each field
604 #[must_use]
605 #[no_mangle]
606 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 {
607         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()) } }) };
608         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 };
609         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 };
610         ChannelCounterparty { inner: ObjOps::heap_alloc(nativeChannelCounterparty {
611                 node_id: node_id_arg.into_rust(),
612                 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
613                 unspendable_punishment_reserve: unspendable_punishment_reserve_arg,
614                 forwarding_info: local_forwarding_info_arg,
615                 outbound_htlc_minimum_msat: local_outbound_htlc_minimum_msat_arg,
616                 outbound_htlc_maximum_msat: local_outbound_htlc_maximum_msat_arg,
617         }), is_owned: true }
618 }
619 impl Clone for ChannelCounterparty {
620         fn clone(&self) -> Self {
621                 Self {
622                         inner: if <*mut nativeChannelCounterparty>::is_null(self.inner) { core::ptr::null_mut() } else {
623                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
624                         is_owned: true,
625                 }
626         }
627 }
628 #[allow(unused)]
629 /// Used only if an object of this type is returned as a trait impl by a method
630 pub(crate) extern "C" fn ChannelCounterparty_clone_void(this_ptr: *const c_void) -> *mut c_void {
631         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelCounterparty)).clone() })) as *mut c_void
632 }
633 #[no_mangle]
634 /// Creates a copy of the ChannelCounterparty
635 pub extern "C" fn ChannelCounterparty_clone(orig: &ChannelCounterparty) -> ChannelCounterparty {
636         orig.clone()
637 }
638
639 use lightning::ln::channelmanager::ChannelDetails as nativeChannelDetailsImport;
640 pub(crate) type nativeChannelDetails = nativeChannelDetailsImport;
641
642 /// Details of a channel, as returned by [`ChannelManager::list_channels`] and [`ChannelManager::list_usable_channels`]
643 #[must_use]
644 #[repr(C)]
645 pub struct ChannelDetails {
646         /// A pointer to the opaque Rust object.
647
648         /// Nearly everywhere, inner must be non-null, however in places where
649         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
650         pub inner: *mut nativeChannelDetails,
651         /// Indicates that this is the only struct which contains the same pointer.
652
653         /// Rust functions which take ownership of an object provided via an argument require
654         /// this to be true and invalidate the object pointed to by inner.
655         pub is_owned: bool,
656 }
657
658 impl Drop for ChannelDetails {
659         fn drop(&mut self) {
660                 if self.is_owned && !<*mut nativeChannelDetails>::is_null(self.inner) {
661                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
662                 }
663         }
664 }
665 /// Frees any resources used by the ChannelDetails, if is_owned is set and inner is non-NULL.
666 #[no_mangle]
667 pub extern "C" fn ChannelDetails_free(this_obj: ChannelDetails) { }
668 #[allow(unused)]
669 /// Used only if an object of this type is returned as a trait impl by a method
670 pub(crate) extern "C" fn ChannelDetails_free_void(this_ptr: *mut c_void) {
671         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelDetails) };
672 }
673 #[allow(unused)]
674 impl ChannelDetails {
675         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelDetails {
676                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
677         }
678         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelDetails {
679                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
680         }
681         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
682         pub(crate) fn take_inner(mut self) -> *mut nativeChannelDetails {
683                 assert!(self.is_owned);
684                 let ret = ObjOps::untweak_ptr(self.inner);
685                 self.inner = core::ptr::null_mut();
686                 ret
687         }
688 }
689 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
690 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
691 /// Note that this means this value is *not* persistent - it can change once during the
692 /// lifetime of the channel.
693 #[no_mangle]
694 pub extern "C" fn ChannelDetails_get_channel_id(this_ptr: &ChannelDetails) -> *const [u8; 32] {
695         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id;
696         inner_val
697 }
698 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
699 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
700 /// Note that this means this value is *not* persistent - it can change once during the
701 /// lifetime of the channel.
702 #[no_mangle]
703 pub extern "C" fn ChannelDetails_set_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::ThirtyTwoBytes) {
704         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = val.data;
705 }
706 /// Parameters which apply to our counterparty. See individual fields for more information.
707 #[no_mangle]
708 pub extern "C" fn ChannelDetails_get_counterparty(this_ptr: &ChannelDetails) -> crate::lightning::ln::channelmanager::ChannelCounterparty {
709         let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty;
710         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 }
711 }
712 /// Parameters which apply to our counterparty. See individual fields for more information.
713 #[no_mangle]
714 pub extern "C" fn ChannelDetails_set_counterparty(this_ptr: &mut ChannelDetails, mut val: crate::lightning::ln::channelmanager::ChannelCounterparty) {
715         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty = *unsafe { Box::from_raw(val.take_inner()) };
716 }
717 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
718 /// our counterparty already.
719 ///
720 /// Note that, if this has been set, `channel_id` will be equivalent to
721 /// `funding_txo.unwrap().to_channel_id()`.
722 ///
723 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
724 #[no_mangle]
725 pub extern "C" fn ChannelDetails_get_funding_txo(this_ptr: &ChannelDetails) -> crate::lightning::chain::transaction::OutPoint {
726         let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_txo;
727         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 };
728         local_inner_val
729 }
730 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
731 /// our counterparty already.
732 ///
733 /// Note that, if this has been set, `channel_id` will be equivalent to
734 /// `funding_txo.unwrap().to_channel_id()`.
735 ///
736 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
737 #[no_mangle]
738 pub extern "C" fn ChannelDetails_set_funding_txo(this_ptr: &mut ChannelDetails, mut val: crate::lightning::chain::transaction::OutPoint) {
739         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
740         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_txo = local_val;
741 }
742 /// The features which this channel operates with. See individual features for more info.
743 ///
744 /// `None` until negotiation completes and the channel type is finalized.
745 ///
746 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
747 #[no_mangle]
748 pub extern "C" fn ChannelDetails_get_channel_type(this_ptr: &ChannelDetails) -> crate::lightning::ln::features::ChannelTypeFeatures {
749         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_type;
750         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 };
751         local_inner_val
752 }
753 /// The features which this channel operates with. See individual features for more info.
754 ///
755 /// `None` until negotiation completes and the channel type is finalized.
756 ///
757 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
758 #[no_mangle]
759 pub extern "C" fn ChannelDetails_set_channel_type(this_ptr: &mut ChannelDetails, mut val: crate::lightning::ln::features::ChannelTypeFeatures) {
760         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
761         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_type = local_val;
762 }
763 /// The position of the funding transaction in the chain. None if the funding transaction has
764 /// not yet been confirmed and the channel fully opened.
765 ///
766 /// Note that if [`inbound_scid_alias`] is set, it must be used for invoices and inbound
767 /// payments instead of this. See [`get_inbound_payment_scid`].
768 ///
769 /// For channels with [`confirmations_required`] set to `Some(0)`, [`outbound_scid_alias`] may
770 /// be used in place of this in outbound routes. See [`get_outbound_payment_scid`].
771 ///
772 /// [`inbound_scid_alias`]: Self::inbound_scid_alias
773 /// [`outbound_scid_alias`]: Self::outbound_scid_alias
774 /// [`get_inbound_payment_scid`]: Self::get_inbound_payment_scid
775 /// [`get_outbound_payment_scid`]: Self::get_outbound_payment_scid
776 /// [`confirmations_required`]: Self::confirmations_required
777 #[no_mangle]
778 pub extern "C" fn ChannelDetails_get_short_channel_id(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
779         let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
780         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() }) };
781         local_inner_val
782 }
783 /// The position of the funding transaction in the chain. None if the funding transaction has
784 /// not yet been confirmed and the channel fully opened.
785 ///
786 /// Note that if [`inbound_scid_alias`] is set, it must be used for invoices and inbound
787 /// payments instead of this. See [`get_inbound_payment_scid`].
788 ///
789 /// For channels with [`confirmations_required`] set to `Some(0)`, [`outbound_scid_alias`] may
790 /// be used in place of this in outbound routes. See [`get_outbound_payment_scid`].
791 ///
792 /// [`inbound_scid_alias`]: Self::inbound_scid_alias
793 /// [`outbound_scid_alias`]: Self::outbound_scid_alias
794 /// [`get_inbound_payment_scid`]: Self::get_inbound_payment_scid
795 /// [`get_outbound_payment_scid`]: Self::get_outbound_payment_scid
796 /// [`confirmations_required`]: Self::confirmations_required
797 #[no_mangle]
798 pub extern "C" fn ChannelDetails_set_short_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
799         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
800         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = local_val;
801 }
802 /// An optional [`short_channel_id`] alias for this channel, randomly generated by us and
803 /// usable in place of [`short_channel_id`] to reference the channel in outbound routes when
804 /// the channel has not yet been confirmed (as long as [`confirmations_required`] is
805 /// `Some(0)`).
806 ///
807 /// This will be `None` as long as the channel is not available for routing outbound payments.
808 ///
809 /// [`short_channel_id`]: Self::short_channel_id
810 /// [`confirmations_required`]: Self::confirmations_required
811 #[no_mangle]
812 pub extern "C" fn ChannelDetails_get_outbound_scid_alias(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
813         let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_scid_alias;
814         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() }) };
815         local_inner_val
816 }
817 /// An optional [`short_channel_id`] alias for this channel, randomly generated by us and
818 /// usable in place of [`short_channel_id`] to reference the channel in outbound routes when
819 /// the channel has not yet been confirmed (as long as [`confirmations_required`] is
820 /// `Some(0)`).
821 ///
822 /// This will be `None` as long as the channel is not available for routing outbound payments.
823 ///
824 /// [`short_channel_id`]: Self::short_channel_id
825 /// [`confirmations_required`]: Self::confirmations_required
826 #[no_mangle]
827 pub extern "C" fn ChannelDetails_set_outbound_scid_alias(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
828         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
829         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_scid_alias = local_val;
830 }
831 /// An optional [`short_channel_id`] alias for this channel, randomly generated by our
832 /// counterparty and usable in place of [`short_channel_id`] in invoice route hints. Our
833 /// counterparty will recognize the alias provided here in place of the [`short_channel_id`]
834 /// when they see a payment to be routed to us.
835 ///
836 /// Our counterparty may choose to rotate this value at any time, though will always recognize
837 /// previous values for inbound payment forwarding.
838 ///
839 /// [`short_channel_id`]: Self::short_channel_id
840 #[no_mangle]
841 pub extern "C" fn ChannelDetails_get_inbound_scid_alias(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
842         let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_scid_alias;
843         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() }) };
844         local_inner_val
845 }
846 /// An optional [`short_channel_id`] alias for this channel, randomly generated by our
847 /// counterparty and usable in place of [`short_channel_id`] in invoice route hints. Our
848 /// counterparty will recognize the alias provided here in place of the [`short_channel_id`]
849 /// when they see a payment to be routed to us.
850 ///
851 /// Our counterparty may choose to rotate this value at any time, though will always recognize
852 /// previous values for inbound payment forwarding.
853 ///
854 /// [`short_channel_id`]: Self::short_channel_id
855 #[no_mangle]
856 pub extern "C" fn ChannelDetails_set_inbound_scid_alias(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
857         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
858         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_scid_alias = local_val;
859 }
860 /// The value, in satoshis, of this channel as appears in the funding output
861 #[no_mangle]
862 pub extern "C" fn ChannelDetails_get_channel_value_satoshis(this_ptr: &ChannelDetails) -> u64 {
863         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
864         *inner_val
865 }
866 /// The value, in satoshis, of this channel as appears in the funding output
867 #[no_mangle]
868 pub extern "C" fn ChannelDetails_set_channel_value_satoshis(this_ptr: &mut ChannelDetails, mut val: u64) {
869         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
870 }
871 /// The value, in satoshis, that must always be held in the channel for us. This value ensures
872 /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
873 /// this value on chain.
874 ///
875 /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
876 ///
877 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
878 ///
879 /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
880 #[no_mangle]
881 pub extern "C" fn ChannelDetails_get_unspendable_punishment_reserve(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
882         let mut inner_val = &mut this_ptr.get_native_mut_ref().unspendable_punishment_reserve;
883         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() }) };
884         local_inner_val
885 }
886 /// The value, in satoshis, that must always be held in the channel for us. This value ensures
887 /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
888 /// this value on chain.
889 ///
890 /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
891 ///
892 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
893 ///
894 /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
895 #[no_mangle]
896 pub extern "C" fn ChannelDetails_set_unspendable_punishment_reserve(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
897         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
898         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = local_val;
899 }
900 /// The `user_channel_id` passed in to create_channel, or a random value if the channel was
901 /// inbound. This may be zero for inbound channels serialized with LDK versions prior to
902 /// 0.0.113.
903 #[no_mangle]
904 pub extern "C" fn ChannelDetails_get_user_channel_id(this_ptr: &ChannelDetails) -> crate::c_types::U128 {
905         let mut inner_val = &mut this_ptr.get_native_mut_ref().user_channel_id;
906         inner_val.into()
907 }
908 /// The `user_channel_id` passed in to create_channel, or a random value if the channel was
909 /// inbound. This may be zero for inbound channels serialized with LDK versions prior to
910 /// 0.0.113.
911 #[no_mangle]
912 pub extern "C" fn ChannelDetails_set_user_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::U128) {
913         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.user_channel_id = val.into();
914 }
915 /// The currently negotiated fee rate denominated in satoshi per 1000 weight units,
916 /// which is applied to commitment and HTLC transactions.
917 ///
918 /// This value will be `None` for objects serialized with LDK versions prior to 0.0.115.
919 #[no_mangle]
920 pub extern "C" fn ChannelDetails_get_feerate_sat_per_1000_weight(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u32Z {
921         let mut inner_val = &mut this_ptr.get_native_mut_ref().feerate_sat_per_1000_weight;
922         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() }) };
923         local_inner_val
924 }
925 /// The currently negotiated fee rate denominated in satoshi per 1000 weight units,
926 /// which is applied to commitment and HTLC transactions.
927 ///
928 /// This value will be `None` for objects serialized with LDK versions prior to 0.0.115.
929 #[no_mangle]
930 pub extern "C" fn ChannelDetails_set_feerate_sat_per_1000_weight(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u32Z) {
931         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
932         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.feerate_sat_per_1000_weight = local_val;
933 }
934 /// Our total balance.  This is the amount we would get if we close the channel.
935 /// This value is not exact. Due to various in-flight changes and feerate changes, exactly this
936 /// amount is not likely to be recoverable on close.
937 ///
938 /// This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose
939 /// balance is not available for inclusion in new outbound HTLCs). This further does not include
940 /// any pending outgoing HTLCs which are awaiting some other resolution to be sent.
941 /// This does not consider any on-chain fees.
942 ///
943 /// See also [`ChannelDetails::outbound_capacity_msat`]
944 #[no_mangle]
945 pub extern "C" fn ChannelDetails_get_balance_msat(this_ptr: &ChannelDetails) -> u64 {
946         let mut inner_val = &mut this_ptr.get_native_mut_ref().balance_msat;
947         *inner_val
948 }
949 /// Our total balance.  This is the amount we would get if we close the channel.
950 /// This value is not exact. Due to various in-flight changes and feerate changes, exactly this
951 /// amount is not likely to be recoverable on close.
952 ///
953 /// This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose
954 /// balance is not available for inclusion in new outbound HTLCs). This further does not include
955 /// any pending outgoing HTLCs which are awaiting some other resolution to be sent.
956 /// This does not consider any on-chain fees.
957 ///
958 /// See also [`ChannelDetails::outbound_capacity_msat`]
959 #[no_mangle]
960 pub extern "C" fn ChannelDetails_set_balance_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
961         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.balance_msat = val;
962 }
963 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
964 /// any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
965 /// available for inclusion in new outbound HTLCs). This further does not include any pending
966 /// outgoing HTLCs which are awaiting some other resolution to be sent.
967 ///
968 /// See also [`ChannelDetails::balance_msat`]
969 ///
970 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
971 /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
972 /// should be able to spend nearly this amount.
973 #[no_mangle]
974 pub extern "C" fn ChannelDetails_get_outbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
975         let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_capacity_msat;
976         *inner_val
977 }
978 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
979 /// any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
980 /// available for inclusion in new outbound HTLCs). This further does not include any pending
981 /// outgoing HTLCs which are awaiting some other resolution to be sent.
982 ///
983 /// See also [`ChannelDetails::balance_msat`]
984 ///
985 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
986 /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
987 /// should be able to spend nearly this amount.
988 #[no_mangle]
989 pub extern "C" fn ChannelDetails_set_outbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
990         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_capacity_msat = val;
991 }
992 /// The available outbound capacity for sending a single HTLC to the remote peer. This is
993 /// similar to [`ChannelDetails::outbound_capacity_msat`] but it may be further restricted by
994 /// the current state and per-HTLC limit(s). This is intended for use when routing, allowing us
995 /// to use a limit as close as possible to the HTLC limit we can currently send.
996 ///
997 /// See also [`ChannelDetails::next_outbound_htlc_minimum_msat`],
998 /// [`ChannelDetails::balance_msat`], and [`ChannelDetails::outbound_capacity_msat`].
999 #[no_mangle]
1000 pub extern "C" fn ChannelDetails_get_next_outbound_htlc_limit_msat(this_ptr: &ChannelDetails) -> u64 {
1001         let mut inner_val = &mut this_ptr.get_native_mut_ref().next_outbound_htlc_limit_msat;
1002         *inner_val
1003 }
1004 /// The available outbound capacity for sending a single HTLC to the remote peer. This is
1005 /// similar to [`ChannelDetails::outbound_capacity_msat`] but it may be further restricted by
1006 /// the current state and per-HTLC limit(s). This is intended for use when routing, allowing us
1007 /// to use a limit as close as possible to the HTLC limit we can currently send.
1008 ///
1009 /// See also [`ChannelDetails::next_outbound_htlc_minimum_msat`],
1010 /// [`ChannelDetails::balance_msat`], and [`ChannelDetails::outbound_capacity_msat`].
1011 #[no_mangle]
1012 pub extern "C" fn ChannelDetails_set_next_outbound_htlc_limit_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
1013         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.next_outbound_htlc_limit_msat = val;
1014 }
1015 /// The minimum value for sending a single HTLC to the remote peer. This is the equivalent of
1016 /// [`ChannelDetails::next_outbound_htlc_limit_msat`] but represents a lower-bound, rather than
1017 /// an upper-bound. This is intended for use when routing, allowing us to ensure we pick a
1018 /// route which is valid.
1019 #[no_mangle]
1020 pub extern "C" fn ChannelDetails_get_next_outbound_htlc_minimum_msat(this_ptr: &ChannelDetails) -> u64 {
1021         let mut inner_val = &mut this_ptr.get_native_mut_ref().next_outbound_htlc_minimum_msat;
1022         *inner_val
1023 }
1024 /// The minimum value for sending a single HTLC to the remote peer. This is the equivalent of
1025 /// [`ChannelDetails::next_outbound_htlc_limit_msat`] but represents a lower-bound, rather than
1026 /// an upper-bound. This is intended for use when routing, allowing us to ensure we pick a
1027 /// route which is valid.
1028 #[no_mangle]
1029 pub extern "C" fn ChannelDetails_set_next_outbound_htlc_minimum_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
1030         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.next_outbound_htlc_minimum_msat = val;
1031 }
1032 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
1033 /// include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
1034 /// available for inclusion in new inbound HTLCs).
1035 /// Note that there are some corner cases not fully handled here, so the actual available
1036 /// inbound capacity may be slightly higher than this.
1037 ///
1038 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
1039 /// counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
1040 /// However, our counterparty should be able to spend nearly this amount.
1041 #[no_mangle]
1042 pub extern "C" fn ChannelDetails_get_inbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
1043         let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_capacity_msat;
1044         *inner_val
1045 }
1046 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
1047 /// include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
1048 /// available for inclusion in new inbound HTLCs).
1049 /// Note that there are some corner cases not fully handled here, so the actual available
1050 /// inbound capacity may be slightly higher than this.
1051 ///
1052 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
1053 /// counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
1054 /// However, our counterparty should be able to spend nearly this amount.
1055 #[no_mangle]
1056 pub extern "C" fn ChannelDetails_set_inbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
1057         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_capacity_msat = val;
1058 }
1059 /// The number of required confirmations on the funding transaction before the funding will be
1060 /// considered \"locked\". This number is selected by the channel fundee (i.e. us if
1061 /// [`is_outbound`] is *not* set), and can be selected for inbound channels with
1062 /// [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
1063 /// [`ChannelHandshakeLimits::max_minimum_depth`].
1064 ///
1065 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
1066 ///
1067 /// [`is_outbound`]: ChannelDetails::is_outbound
1068 /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
1069 /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
1070 #[no_mangle]
1071 pub extern "C" fn ChannelDetails_get_confirmations_required(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u32Z {
1072         let mut inner_val = &mut this_ptr.get_native_mut_ref().confirmations_required;
1073         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() }) };
1074         local_inner_val
1075 }
1076 /// The number of required confirmations on the funding transaction before the funding will be
1077 /// considered \"locked\". This number is selected by the channel fundee (i.e. us if
1078 /// [`is_outbound`] is *not* set), and can be selected for inbound channels with
1079 /// [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
1080 /// [`ChannelHandshakeLimits::max_minimum_depth`].
1081 ///
1082 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
1083 ///
1084 /// [`is_outbound`]: ChannelDetails::is_outbound
1085 /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
1086 /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
1087 #[no_mangle]
1088 pub extern "C" fn ChannelDetails_set_confirmations_required(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u32Z) {
1089         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1090         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.confirmations_required = local_val;
1091 }
1092 /// The current number of confirmations on the funding transaction.
1093 ///
1094 /// This value will be `None` for objects serialized with LDK versions prior to 0.0.113.
1095 #[no_mangle]
1096 pub extern "C" fn ChannelDetails_get_confirmations(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u32Z {
1097         let mut inner_val = &mut this_ptr.get_native_mut_ref().confirmations;
1098         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() }) };
1099         local_inner_val
1100 }
1101 /// The current number of confirmations on the funding transaction.
1102 ///
1103 /// This value will be `None` for objects serialized with LDK versions prior to 0.0.113.
1104 #[no_mangle]
1105 pub extern "C" fn ChannelDetails_set_confirmations(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u32Z) {
1106         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1107         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.confirmations = local_val;
1108 }
1109 /// The number of blocks (after our commitment transaction confirms) that we will need to wait
1110 /// until we can claim our funds after we force-close the channel. During this time our
1111 /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
1112 /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any
1113 /// time to claim our non-HTLC-encumbered funds.
1114 ///
1115 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
1116 #[no_mangle]
1117 pub extern "C" fn ChannelDetails_get_force_close_spend_delay(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u16Z {
1118         let mut inner_val = &mut this_ptr.get_native_mut_ref().force_close_spend_delay;
1119         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() }) };
1120         local_inner_val
1121 }
1122 /// The number of blocks (after our commitment transaction confirms) that we will need to wait
1123 /// until we can claim our funds after we force-close the channel. During this time our
1124 /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
1125 /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any
1126 /// time to claim our non-HTLC-encumbered funds.
1127 ///
1128 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
1129 #[no_mangle]
1130 pub extern "C" fn ChannelDetails_set_force_close_spend_delay(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u16Z) {
1131         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1132         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.force_close_spend_delay = local_val;
1133 }
1134 /// True if the channel was initiated (and thus funded) by us.
1135 #[no_mangle]
1136 pub extern "C" fn ChannelDetails_get_is_outbound(this_ptr: &ChannelDetails) -> bool {
1137         let mut inner_val = &mut this_ptr.get_native_mut_ref().is_outbound;
1138         *inner_val
1139 }
1140 /// True if the channel was initiated (and thus funded) by us.
1141 #[no_mangle]
1142 pub extern "C" fn ChannelDetails_set_is_outbound(this_ptr: &mut ChannelDetails, mut val: bool) {
1143         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_outbound = val;
1144 }
1145 /// True if the channel is confirmed, channel_ready messages have been exchanged, and the
1146 /// channel is not currently being shut down. `channel_ready` message exchange implies the
1147 /// required confirmation count has been reached (and we were connected to the peer at some
1148 /// point after the funding transaction received enough confirmations). The required
1149 /// confirmation count is provided in [`confirmations_required`].
1150 ///
1151 /// [`confirmations_required`]: ChannelDetails::confirmations_required
1152 #[no_mangle]
1153 pub extern "C" fn ChannelDetails_get_is_channel_ready(this_ptr: &ChannelDetails) -> bool {
1154         let mut inner_val = &mut this_ptr.get_native_mut_ref().is_channel_ready;
1155         *inner_val
1156 }
1157 /// True if the channel is confirmed, channel_ready messages have been exchanged, and the
1158 /// channel is not currently being shut down. `channel_ready` message exchange implies the
1159 /// required confirmation count has been reached (and we were connected to the peer at some
1160 /// point after the funding transaction received enough confirmations). The required
1161 /// confirmation count is provided in [`confirmations_required`].
1162 ///
1163 /// [`confirmations_required`]: ChannelDetails::confirmations_required
1164 #[no_mangle]
1165 pub extern "C" fn ChannelDetails_set_is_channel_ready(this_ptr: &mut ChannelDetails, mut val: bool) {
1166         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_channel_ready = val;
1167 }
1168 /// The stage of the channel's shutdown.
1169 /// `None` for `ChannelDetails` serialized on LDK versions prior to 0.0.116.
1170 ///
1171 /// Returns a copy of the field.
1172 #[no_mangle]
1173 pub extern "C" fn ChannelDetails_get_channel_shutdown_state(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_ChannelShutdownStateZ {
1174         let mut inner_val = this_ptr.get_native_mut_ref().channel_shutdown_state.clone();
1175         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()) }) };
1176         local_inner_val
1177 }
1178 /// The stage of the channel's shutdown.
1179 /// `None` for `ChannelDetails` serialized on LDK versions prior to 0.0.116.
1180 #[no_mangle]
1181 pub extern "C" fn ChannelDetails_set_channel_shutdown_state(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_ChannelShutdownStateZ) {
1182         let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { { val_opt.take() }.into_native() }})} };
1183         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_shutdown_state = local_val;
1184 }
1185 /// True if the channel is (a) confirmed and channel_ready messages have been exchanged, (b)
1186 /// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
1187 ///
1188 /// This is a strict superset of `is_channel_ready`.
1189 #[no_mangle]
1190 pub extern "C" fn ChannelDetails_get_is_usable(this_ptr: &ChannelDetails) -> bool {
1191         let mut inner_val = &mut this_ptr.get_native_mut_ref().is_usable;
1192         *inner_val
1193 }
1194 /// True if the channel is (a) confirmed and channel_ready messages have been exchanged, (b)
1195 /// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
1196 ///
1197 /// This is a strict superset of `is_channel_ready`.
1198 #[no_mangle]
1199 pub extern "C" fn ChannelDetails_set_is_usable(this_ptr: &mut ChannelDetails, mut val: bool) {
1200         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_usable = val;
1201 }
1202 /// True if this channel is (or will be) publicly-announced.
1203 #[no_mangle]
1204 pub extern "C" fn ChannelDetails_get_is_public(this_ptr: &ChannelDetails) -> bool {
1205         let mut inner_val = &mut this_ptr.get_native_mut_ref().is_public;
1206         *inner_val
1207 }
1208 /// True if this channel is (or will be) publicly-announced.
1209 #[no_mangle]
1210 pub extern "C" fn ChannelDetails_set_is_public(this_ptr: &mut ChannelDetails, mut val: bool) {
1211         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_public = val;
1212 }
1213 /// The smallest value HTLC (in msat) we will accept, for this channel. This field
1214 /// is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.107
1215 #[no_mangle]
1216 pub extern "C" fn ChannelDetails_get_inbound_htlc_minimum_msat(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
1217         let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_htlc_minimum_msat;
1218         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() }) };
1219         local_inner_val
1220 }
1221 /// The smallest value HTLC (in msat) we will accept, for this channel. This field
1222 /// is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.107
1223 #[no_mangle]
1224 pub extern "C" fn ChannelDetails_set_inbound_htlc_minimum_msat(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
1225         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1226         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_htlc_minimum_msat = local_val;
1227 }
1228 /// The largest value HTLC (in msat) we currently will accept, for this channel.
1229 #[no_mangle]
1230 pub extern "C" fn ChannelDetails_get_inbound_htlc_maximum_msat(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
1231         let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_htlc_maximum_msat;
1232         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() }) };
1233         local_inner_val
1234 }
1235 /// The largest value HTLC (in msat) we currently will accept, for this channel.
1236 #[no_mangle]
1237 pub extern "C" fn ChannelDetails_set_inbound_htlc_maximum_msat(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
1238         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1239         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_htlc_maximum_msat = local_val;
1240 }
1241 /// Set of configurable parameters that affect channel operation.
1242 ///
1243 /// This field is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.109.
1244 ///
1245 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1246 #[no_mangle]
1247 pub extern "C" fn ChannelDetails_get_config(this_ptr: &ChannelDetails) -> crate::lightning::util::config::ChannelConfig {
1248         let mut inner_val = &mut this_ptr.get_native_mut_ref().config;
1249         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 };
1250         local_inner_val
1251 }
1252 /// Set of configurable parameters that affect channel operation.
1253 ///
1254 /// This field is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.109.
1255 ///
1256 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1257 #[no_mangle]
1258 pub extern "C" fn ChannelDetails_set_config(this_ptr: &mut ChannelDetails, mut val: crate::lightning::util::config::ChannelConfig) {
1259         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1260         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.config = local_val;
1261 }
1262 /// Constructs a new ChannelDetails given each field
1263 #[must_use]
1264 #[no_mangle]
1265 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 {
1266         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()) } }) };
1267         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()) } }) };
1268         let mut local_short_channel_id_arg = if short_channel_id_arg.is_some() { Some( { short_channel_id_arg.take() }) } else { None };
1269         let mut local_outbound_scid_alias_arg = if outbound_scid_alias_arg.is_some() { Some( { outbound_scid_alias_arg.take() }) } else { None };
1270         let mut local_inbound_scid_alias_arg = if inbound_scid_alias_arg.is_some() { Some( { inbound_scid_alias_arg.take() }) } else { None };
1271         let mut local_unspendable_punishment_reserve_arg = if unspendable_punishment_reserve_arg.is_some() { Some( { unspendable_punishment_reserve_arg.take() }) } else { None };
1272         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 };
1273         let mut local_confirmations_required_arg = if confirmations_required_arg.is_some() { Some( { confirmations_required_arg.take() }) } else { None };
1274         let mut local_confirmations_arg = if confirmations_arg.is_some() { Some( { confirmations_arg.take() }) } else { None };
1275         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 };
1276         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() }})} };
1277         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 };
1278         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 };
1279         let mut local_config_arg = if config_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(config_arg.take_inner()) } }) };
1280         ChannelDetails { inner: ObjOps::heap_alloc(nativeChannelDetails {
1281                 channel_id: channel_id_arg.data,
1282                 counterparty: *unsafe { Box::from_raw(counterparty_arg.take_inner()) },
1283                 funding_txo: local_funding_txo_arg,
1284                 channel_type: local_channel_type_arg,
1285                 short_channel_id: local_short_channel_id_arg,
1286                 outbound_scid_alias: local_outbound_scid_alias_arg,
1287                 inbound_scid_alias: local_inbound_scid_alias_arg,
1288                 channel_value_satoshis: channel_value_satoshis_arg,
1289                 unspendable_punishment_reserve: local_unspendable_punishment_reserve_arg,
1290                 user_channel_id: user_channel_id_arg.into(),
1291                 feerate_sat_per_1000_weight: local_feerate_sat_per_1000_weight_arg,
1292                 balance_msat: balance_msat_arg,
1293                 outbound_capacity_msat: outbound_capacity_msat_arg,
1294                 next_outbound_htlc_limit_msat: next_outbound_htlc_limit_msat_arg,
1295                 next_outbound_htlc_minimum_msat: next_outbound_htlc_minimum_msat_arg,
1296                 inbound_capacity_msat: inbound_capacity_msat_arg,
1297                 confirmations_required: local_confirmations_required_arg,
1298                 confirmations: local_confirmations_arg,
1299                 force_close_spend_delay: local_force_close_spend_delay_arg,
1300                 is_outbound: is_outbound_arg,
1301                 is_channel_ready: is_channel_ready_arg,
1302                 channel_shutdown_state: local_channel_shutdown_state_arg,
1303                 is_usable: is_usable_arg,
1304                 is_public: is_public_arg,
1305                 inbound_htlc_minimum_msat: local_inbound_htlc_minimum_msat_arg,
1306                 inbound_htlc_maximum_msat: local_inbound_htlc_maximum_msat_arg,
1307                 config: local_config_arg,
1308         }), is_owned: true }
1309 }
1310 impl Clone for ChannelDetails {
1311         fn clone(&self) -> Self {
1312                 Self {
1313                         inner: if <*mut nativeChannelDetails>::is_null(self.inner) { core::ptr::null_mut() } else {
1314                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1315                         is_owned: true,
1316                 }
1317         }
1318 }
1319 #[allow(unused)]
1320 /// Used only if an object of this type is returned as a trait impl by a method
1321 pub(crate) extern "C" fn ChannelDetails_clone_void(this_ptr: *const c_void) -> *mut c_void {
1322         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelDetails)).clone() })) as *mut c_void
1323 }
1324 #[no_mangle]
1325 /// Creates a copy of the ChannelDetails
1326 pub extern "C" fn ChannelDetails_clone(orig: &ChannelDetails) -> ChannelDetails {
1327         orig.clone()
1328 }
1329 /// Gets the current SCID which should be used to identify this channel for inbound payments.
1330 /// This should be used for providing invoice hints or in any other context where our
1331 /// counterparty will forward a payment to us.
1332 ///
1333 /// This is either the [`ChannelDetails::inbound_scid_alias`], if set, or the
1334 /// [`ChannelDetails::short_channel_id`]. See those for more information.
1335 #[must_use]
1336 #[no_mangle]
1337 pub extern "C" fn ChannelDetails_get_inbound_payment_scid(this_arg: &crate::lightning::ln::channelmanager::ChannelDetails) -> crate::c_types::derived::COption_u64Z {
1338         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_inbound_payment_scid();
1339         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() }) };
1340         local_ret
1341 }
1342
1343 /// Gets the current SCID which should be used to identify this channel for outbound payments.
1344 /// This should be used in [`Route`]s to describe the first hop or in other contexts where
1345 /// we're sending or forwarding a payment outbound over this channel.
1346 ///
1347 /// This is either the [`ChannelDetails::short_channel_id`], if set, or the
1348 /// [`ChannelDetails::outbound_scid_alias`]. See those for more information.
1349 #[must_use]
1350 #[no_mangle]
1351 pub extern "C" fn ChannelDetails_get_outbound_payment_scid(this_arg: &crate::lightning::ln::channelmanager::ChannelDetails) -> crate::c_types::derived::COption_u64Z {
1352         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_outbound_payment_scid();
1353         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() }) };
1354         local_ret
1355 }
1356
1357 /// Further information on the details of the channel shutdown.
1358 /// Upon channels being forced closed (i.e. commitment transaction confirmation detected
1359 /// by `ChainMonitor`), ChannelShutdownState will be set to `ShutdownComplete` or
1360 /// the channel will be removed shortly.
1361 /// Also note, that in normal operation, peers could disconnect at any of these states
1362 /// and require peer re-connection before making progress onto other states
1363 #[derive(Clone)]
1364 #[must_use]
1365 #[repr(C)]
1366 pub enum ChannelShutdownState {
1367         /// Channel has not sent or received a shutdown message.
1368         NotShuttingDown,
1369         /// Local node has sent a shutdown message for this channel.
1370         ShutdownInitiated,
1371         /// Shutdown message exchanges have concluded and the channels are in the midst of
1372         /// resolving all existing open HTLCs before closing can continue.
1373         ResolvingHTLCs,
1374         /// All HTLCs have been resolved, nodes are currently negotiating channel close onchain fee rates.
1375         NegotiatingClosingFee,
1376         /// We've successfully negotiated a closing_signed dance. At this point `ChannelManager` is about
1377         /// to drop the channel.
1378         ShutdownComplete,
1379 }
1380 use lightning::ln::channelmanager::ChannelShutdownState as ChannelShutdownStateImport;
1381 pub(crate) type nativeChannelShutdownState = ChannelShutdownStateImport;
1382
1383 impl ChannelShutdownState {
1384         #[allow(unused)]
1385         pub(crate) fn to_native(&self) -> nativeChannelShutdownState {
1386                 match self {
1387                         ChannelShutdownState::NotShuttingDown => nativeChannelShutdownState::NotShuttingDown,
1388                         ChannelShutdownState::ShutdownInitiated => nativeChannelShutdownState::ShutdownInitiated,
1389                         ChannelShutdownState::ResolvingHTLCs => nativeChannelShutdownState::ResolvingHTLCs,
1390                         ChannelShutdownState::NegotiatingClosingFee => nativeChannelShutdownState::NegotiatingClosingFee,
1391                         ChannelShutdownState::ShutdownComplete => nativeChannelShutdownState::ShutdownComplete,
1392                 }
1393         }
1394         #[allow(unused)]
1395         pub(crate) fn into_native(self) -> nativeChannelShutdownState {
1396                 match self {
1397                         ChannelShutdownState::NotShuttingDown => nativeChannelShutdownState::NotShuttingDown,
1398                         ChannelShutdownState::ShutdownInitiated => nativeChannelShutdownState::ShutdownInitiated,
1399                         ChannelShutdownState::ResolvingHTLCs => nativeChannelShutdownState::ResolvingHTLCs,
1400                         ChannelShutdownState::NegotiatingClosingFee => nativeChannelShutdownState::NegotiatingClosingFee,
1401                         ChannelShutdownState::ShutdownComplete => nativeChannelShutdownState::ShutdownComplete,
1402                 }
1403         }
1404         #[allow(unused)]
1405         pub(crate) fn from_native(native: &nativeChannelShutdownState) -> Self {
1406                 match native {
1407                         nativeChannelShutdownState::NotShuttingDown => ChannelShutdownState::NotShuttingDown,
1408                         nativeChannelShutdownState::ShutdownInitiated => ChannelShutdownState::ShutdownInitiated,
1409                         nativeChannelShutdownState::ResolvingHTLCs => ChannelShutdownState::ResolvingHTLCs,
1410                         nativeChannelShutdownState::NegotiatingClosingFee => ChannelShutdownState::NegotiatingClosingFee,
1411                         nativeChannelShutdownState::ShutdownComplete => ChannelShutdownState::ShutdownComplete,
1412                 }
1413         }
1414         #[allow(unused)]
1415         pub(crate) fn native_into(native: nativeChannelShutdownState) -> Self {
1416                 match native {
1417                         nativeChannelShutdownState::NotShuttingDown => ChannelShutdownState::NotShuttingDown,
1418                         nativeChannelShutdownState::ShutdownInitiated => ChannelShutdownState::ShutdownInitiated,
1419                         nativeChannelShutdownState::ResolvingHTLCs => ChannelShutdownState::ResolvingHTLCs,
1420                         nativeChannelShutdownState::NegotiatingClosingFee => ChannelShutdownState::NegotiatingClosingFee,
1421                         nativeChannelShutdownState::ShutdownComplete => ChannelShutdownState::ShutdownComplete,
1422                 }
1423         }
1424 }
1425 /// Creates a copy of the ChannelShutdownState
1426 #[no_mangle]
1427 pub extern "C" fn ChannelShutdownState_clone(orig: &ChannelShutdownState) -> ChannelShutdownState {
1428         orig.clone()
1429 }
1430 #[no_mangle]
1431 /// Utility method to constructs a new NotShuttingDown-variant ChannelShutdownState
1432 pub extern "C" fn ChannelShutdownState_not_shutting_down() -> ChannelShutdownState {
1433         ChannelShutdownState::NotShuttingDown}
1434 #[no_mangle]
1435 /// Utility method to constructs a new ShutdownInitiated-variant ChannelShutdownState
1436 pub extern "C" fn ChannelShutdownState_shutdown_initiated() -> ChannelShutdownState {
1437         ChannelShutdownState::ShutdownInitiated}
1438 #[no_mangle]
1439 /// Utility method to constructs a new ResolvingHTLCs-variant ChannelShutdownState
1440 pub extern "C" fn ChannelShutdownState_resolving_htlcs() -> ChannelShutdownState {
1441         ChannelShutdownState::ResolvingHTLCs}
1442 #[no_mangle]
1443 /// Utility method to constructs a new NegotiatingClosingFee-variant ChannelShutdownState
1444 pub extern "C" fn ChannelShutdownState_negotiating_closing_fee() -> ChannelShutdownState {
1445         ChannelShutdownState::NegotiatingClosingFee}
1446 #[no_mangle]
1447 /// Utility method to constructs a new ShutdownComplete-variant ChannelShutdownState
1448 pub extern "C" fn ChannelShutdownState_shutdown_complete() -> ChannelShutdownState {
1449         ChannelShutdownState::ShutdownComplete}
1450 /// Checks if two ChannelShutdownStates contain equal inner contents.
1451 /// This ignores pointers and is_owned flags and looks at the values in fields.
1452 #[no_mangle]
1453 pub extern "C" fn ChannelShutdownState_eq(a: &ChannelShutdownState, b: &ChannelShutdownState) -> bool {
1454         if &a.to_native() == &b.to_native() { true } else { false }
1455 }
1456 /// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
1457 /// These include payments that have yet to find a successful path, or have unresolved HTLCs.
1458 #[derive(Clone)]
1459 #[must_use]
1460 #[repr(C)]
1461 pub enum RecentPaymentDetails {
1462         /// When a payment is still being sent and awaiting successful delivery.
1463         Pending {
1464                 /// Hash of the payment that is currently being sent but has yet to be fulfilled or
1465                 /// abandoned.
1466                 payment_hash: crate::c_types::ThirtyTwoBytes,
1467                 /// Total amount (in msat, excluding fees) across all paths for this payment,
1468                 /// not just the amount currently inflight.
1469                 total_msat: u64,
1470         },
1471         /// When a pending payment is fulfilled, we continue tracking it until all pending HTLCs have
1472         /// been resolved. Upon receiving [`Event::PaymentSent`], we delay for a few minutes before the
1473         /// payment is removed from tracking.
1474         Fulfilled {
1475                 /// Hash of the payment that was claimed. `None` for serializations of [`ChannelManager`]
1476                 /// made before LDK version 0.0.104.
1477                 payment_hash: crate::c_types::derived::COption_PaymentHashZ,
1478         },
1479         /// After a payment's retries are exhausted per the provided [`Retry`], or it is explicitly
1480         /// abandoned via [`ChannelManager::abandon_payment`], it is marked as abandoned until all
1481         /// pending HTLCs for this payment resolve and an [`Event::PaymentFailed`] is generated.
1482         Abandoned {
1483                 /// Hash of the payment that we have given up trying to send.
1484                 payment_hash: crate::c_types::ThirtyTwoBytes,
1485         },
1486 }
1487 use lightning::ln::channelmanager::RecentPaymentDetails as RecentPaymentDetailsImport;
1488 pub(crate) type nativeRecentPaymentDetails = RecentPaymentDetailsImport;
1489
1490 impl RecentPaymentDetails {
1491         #[allow(unused)]
1492         pub(crate) fn to_native(&self) -> nativeRecentPaymentDetails {
1493                 match self {
1494                         RecentPaymentDetails::Pending {ref payment_hash, ref total_msat, } => {
1495                                 let mut payment_hash_nonref = Clone::clone(payment_hash);
1496                                 let mut total_msat_nonref = Clone::clone(total_msat);
1497                                 nativeRecentPaymentDetails::Pending {
1498                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1499                                         total_msat: total_msat_nonref,
1500                                 }
1501                         },
1502                         RecentPaymentDetails::Fulfilled {ref payment_hash, } => {
1503                                 let mut payment_hash_nonref = Clone::clone(payment_hash);
1504                                 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) }})} };
1505                                 nativeRecentPaymentDetails::Fulfilled {
1506                                         payment_hash: local_payment_hash_nonref,
1507                                 }
1508                         },
1509                         RecentPaymentDetails::Abandoned {ref payment_hash, } => {
1510                                 let mut payment_hash_nonref = Clone::clone(payment_hash);
1511                                 nativeRecentPaymentDetails::Abandoned {
1512                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1513                                 }
1514                         },
1515                 }
1516         }
1517         #[allow(unused)]
1518         pub(crate) fn into_native(self) -> nativeRecentPaymentDetails {
1519                 match self {
1520                         RecentPaymentDetails::Pending {mut payment_hash, mut total_msat, } => {
1521                                 nativeRecentPaymentDetails::Pending {
1522                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1523                                         total_msat: total_msat,
1524                                 }
1525                         },
1526                         RecentPaymentDetails::Fulfilled {mut payment_hash, } => {
1527                                 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) }})} };
1528                                 nativeRecentPaymentDetails::Fulfilled {
1529                                         payment_hash: local_payment_hash,
1530                                 }
1531                         },
1532                         RecentPaymentDetails::Abandoned {mut payment_hash, } => {
1533                                 nativeRecentPaymentDetails::Abandoned {
1534                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1535                                 }
1536                         },
1537                 }
1538         }
1539         #[allow(unused)]
1540         pub(crate) fn from_native(native: &nativeRecentPaymentDetails) -> Self {
1541                 match native {
1542                         nativeRecentPaymentDetails::Pending {ref payment_hash, ref total_msat, } => {
1543                                 let mut payment_hash_nonref = Clone::clone(payment_hash);
1544                                 let mut total_msat_nonref = Clone::clone(total_msat);
1545                                 RecentPaymentDetails::Pending {
1546                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1547                                         total_msat: total_msat_nonref,
1548                                 }
1549                         },
1550                         nativeRecentPaymentDetails::Fulfilled {ref payment_hash, } => {
1551                                 let mut payment_hash_nonref = Clone::clone(payment_hash);
1552                                 let mut local_payment_hash_nonref = if payment_hash_nonref.is_none() { crate::c_types::derived::COption_PaymentHashZ::None } else { crate::c_types::derived::COption_PaymentHashZ::Some( { crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.unwrap().0 } }) };
1553                                 RecentPaymentDetails::Fulfilled {
1554                                         payment_hash: local_payment_hash_nonref,
1555                                 }
1556                         },
1557                         nativeRecentPaymentDetails::Abandoned {ref payment_hash, } => {
1558                                 let mut payment_hash_nonref = Clone::clone(payment_hash);
1559                                 RecentPaymentDetails::Abandoned {
1560                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1561                                 }
1562                         },
1563                 }
1564         }
1565         #[allow(unused)]
1566         pub(crate) fn native_into(native: nativeRecentPaymentDetails) -> Self {
1567                 match native {
1568                         nativeRecentPaymentDetails::Pending {mut payment_hash, mut total_msat, } => {
1569                                 RecentPaymentDetails::Pending {
1570                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1571                                         total_msat: total_msat,
1572                                 }
1573                         },
1574                         nativeRecentPaymentDetails::Fulfilled {mut payment_hash, } => {
1575                                 let mut local_payment_hash = if payment_hash.is_none() { crate::c_types::derived::COption_PaymentHashZ::None } else { crate::c_types::derived::COption_PaymentHashZ::Some( { crate::c_types::ThirtyTwoBytes { data: payment_hash.unwrap().0 } }) };
1576                                 RecentPaymentDetails::Fulfilled {
1577                                         payment_hash: local_payment_hash,
1578                                 }
1579                         },
1580                         nativeRecentPaymentDetails::Abandoned {mut payment_hash, } => {
1581                                 RecentPaymentDetails::Abandoned {
1582                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1583                                 }
1584                         },
1585                 }
1586         }
1587 }
1588 /// Frees any resources used by the RecentPaymentDetails
1589 #[no_mangle]
1590 pub extern "C" fn RecentPaymentDetails_free(this_ptr: RecentPaymentDetails) { }
1591 /// Creates a copy of the RecentPaymentDetails
1592 #[no_mangle]
1593 pub extern "C" fn RecentPaymentDetails_clone(orig: &RecentPaymentDetails) -> RecentPaymentDetails {
1594         orig.clone()
1595 }
1596 #[no_mangle]
1597 /// Utility method to constructs a new Pending-variant RecentPaymentDetails
1598 pub extern "C" fn RecentPaymentDetails_pending(payment_hash: crate::c_types::ThirtyTwoBytes, total_msat: u64) -> RecentPaymentDetails {
1599         RecentPaymentDetails::Pending {
1600                 payment_hash,
1601                 total_msat,
1602         }
1603 }
1604 #[no_mangle]
1605 /// Utility method to constructs a new Fulfilled-variant RecentPaymentDetails
1606 pub extern "C" fn RecentPaymentDetails_fulfilled(payment_hash: crate::c_types::derived::COption_PaymentHashZ) -> RecentPaymentDetails {
1607         RecentPaymentDetails::Fulfilled {
1608                 payment_hash,
1609         }
1610 }
1611 #[no_mangle]
1612 /// Utility method to constructs a new Abandoned-variant RecentPaymentDetails
1613 pub extern "C" fn RecentPaymentDetails_abandoned(payment_hash: crate::c_types::ThirtyTwoBytes) -> RecentPaymentDetails {
1614         RecentPaymentDetails::Abandoned {
1615                 payment_hash,
1616         }
1617 }
1618
1619 use lightning::ln::channelmanager::PhantomRouteHints as nativePhantomRouteHintsImport;
1620 pub(crate) type nativePhantomRouteHints = nativePhantomRouteHintsImport;
1621
1622 /// Route hints used in constructing invoices for [phantom node payents].
1623 ///
1624 /// [phantom node payments]: crate::sign::PhantomKeysManager
1625 #[must_use]
1626 #[repr(C)]
1627 pub struct PhantomRouteHints {
1628         /// A pointer to the opaque Rust object.
1629
1630         /// Nearly everywhere, inner must be non-null, however in places where
1631         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1632         pub inner: *mut nativePhantomRouteHints,
1633         /// Indicates that this is the only struct which contains the same pointer.
1634
1635         /// Rust functions which take ownership of an object provided via an argument require
1636         /// this to be true and invalidate the object pointed to by inner.
1637         pub is_owned: bool,
1638 }
1639
1640 impl Drop for PhantomRouteHints {
1641         fn drop(&mut self) {
1642                 if self.is_owned && !<*mut nativePhantomRouteHints>::is_null(self.inner) {
1643                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1644                 }
1645         }
1646 }
1647 /// Frees any resources used by the PhantomRouteHints, if is_owned is set and inner is non-NULL.
1648 #[no_mangle]
1649 pub extern "C" fn PhantomRouteHints_free(this_obj: PhantomRouteHints) { }
1650 #[allow(unused)]
1651 /// Used only if an object of this type is returned as a trait impl by a method
1652 pub(crate) extern "C" fn PhantomRouteHints_free_void(this_ptr: *mut c_void) {
1653         let _ = unsafe { Box::from_raw(this_ptr as *mut nativePhantomRouteHints) };
1654 }
1655 #[allow(unused)]
1656 impl PhantomRouteHints {
1657         pub(crate) fn get_native_ref(&self) -> &'static nativePhantomRouteHints {
1658                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1659         }
1660         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePhantomRouteHints {
1661                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1662         }
1663         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1664         pub(crate) fn take_inner(mut self) -> *mut nativePhantomRouteHints {
1665                 assert!(self.is_owned);
1666                 let ret = ObjOps::untweak_ptr(self.inner);
1667                 self.inner = core::ptr::null_mut();
1668                 ret
1669         }
1670 }
1671 /// The list of channels to be included in the invoice route hints.
1672 #[no_mangle]
1673 pub extern "C" fn PhantomRouteHints_get_channels(this_ptr: &PhantomRouteHints) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1674         let mut inner_val = &mut this_ptr.get_native_mut_ref().channels;
1675         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 } }); };
1676         local_inner_val.into()
1677 }
1678 /// The list of channels to be included in the invoice route hints.
1679 #[no_mangle]
1680 pub extern "C" fn PhantomRouteHints_set_channels(this_ptr: &mut PhantomRouteHints, mut val: crate::c_types::derived::CVec_ChannelDetailsZ) {
1681         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1682         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val;
1683 }
1684 /// A fake scid used for representing the phantom node's fake channel in generating the invoice
1685 /// route hints.
1686 #[no_mangle]
1687 pub extern "C" fn PhantomRouteHints_get_phantom_scid(this_ptr: &PhantomRouteHints) -> u64 {
1688         let mut inner_val = &mut this_ptr.get_native_mut_ref().phantom_scid;
1689         *inner_val
1690 }
1691 /// A fake scid used for representing the phantom node's fake channel in generating the invoice
1692 /// route hints.
1693 #[no_mangle]
1694 pub extern "C" fn PhantomRouteHints_set_phantom_scid(this_ptr: &mut PhantomRouteHints, mut val: u64) {
1695         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.phantom_scid = val;
1696 }
1697 /// The pubkey of the real backing node that would ultimately receive the payment.
1698 #[no_mangle]
1699 pub extern "C" fn PhantomRouteHints_get_real_node_pubkey(this_ptr: &PhantomRouteHints) -> crate::c_types::PublicKey {
1700         let mut inner_val = &mut this_ptr.get_native_mut_ref().real_node_pubkey;
1701         crate::c_types::PublicKey::from_rust(&inner_val)
1702 }
1703 /// The pubkey of the real backing node that would ultimately receive the payment.
1704 #[no_mangle]
1705 pub extern "C" fn PhantomRouteHints_set_real_node_pubkey(this_ptr: &mut PhantomRouteHints, mut val: crate::c_types::PublicKey) {
1706         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.real_node_pubkey = val.into_rust();
1707 }
1708 /// Constructs a new PhantomRouteHints given each field
1709 #[must_use]
1710 #[no_mangle]
1711 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 {
1712         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()) } }); };
1713         PhantomRouteHints { inner: ObjOps::heap_alloc(nativePhantomRouteHints {
1714                 channels: local_channels_arg,
1715                 phantom_scid: phantom_scid_arg,
1716                 real_node_pubkey: real_node_pubkey_arg.into_rust(),
1717         }), is_owned: true }
1718 }
1719 impl Clone for PhantomRouteHints {
1720         fn clone(&self) -> Self {
1721                 Self {
1722                         inner: if <*mut nativePhantomRouteHints>::is_null(self.inner) { core::ptr::null_mut() } else {
1723                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1724                         is_owned: true,
1725                 }
1726         }
1727 }
1728 #[allow(unused)]
1729 /// Used only if an object of this type is returned as a trait impl by a method
1730 pub(crate) extern "C" fn PhantomRouteHints_clone_void(this_ptr: *const c_void) -> *mut c_void {
1731         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePhantomRouteHints)).clone() })) as *mut c_void
1732 }
1733 #[no_mangle]
1734 /// Creates a copy of the PhantomRouteHints
1735 pub extern "C" fn PhantomRouteHints_clone(orig: &PhantomRouteHints) -> PhantomRouteHints {
1736         orig.clone()
1737 }
1738 /// Constructs a new `ChannelManager` to hold several channels and route between them.
1739 ///
1740 /// The current time or latest block header time can be provided as the `current_timestamp`.
1741 ///
1742 /// This is the main \"logic hub\" for all channel-related actions, and implements
1743 /// [`ChannelMessageHandler`].
1744 ///
1745 /// Non-proportional fees are fixed according to our risk using the provided fee estimator.
1746 ///
1747 /// Users need to notify the new `ChannelManager` when a new block is connected or
1748 /// disconnected using its [`block_connected`] and [`block_disconnected`] methods, starting
1749 /// from after [`params.best_block.block_hash`]. See [`chain::Listen`] and [`chain::Confirm`] for
1750 /// more details.
1751 ///
1752 /// [`block_connected`]: chain::Listen::block_connected
1753 /// [`block_disconnected`]: chain::Listen::block_disconnected
1754 /// [`params.best_block.block_hash`]: chain::BestBlock::block_hash
1755 #[must_use]
1756 #[no_mangle]
1757 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 {
1758         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);
1759         crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
1760 }
1761
1762 /// Gets the current configuration applied to all new channels.
1763 #[must_use]
1764 #[no_mangle]
1765 pub extern "C" fn ChannelManager_get_current_default_configuration(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::util::config::UserConfig {
1766         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_current_default_configuration();
1767         crate::lightning::util::config::UserConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::util::config::UserConfig<>) as *mut _) }, is_owned: false }
1768 }
1769
1770 /// Creates a new outbound channel to the given remote node and with the given value.
1771 ///
1772 /// `user_channel_id` will be provided back as in
1773 /// [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
1774 /// correspond with which `create_channel` call. Note that the `user_channel_id` defaults to a
1775 /// randomized value for inbound channels. `user_channel_id` has no meaning inside of LDK, it
1776 /// is simply copied to events and otherwise ignored.
1777 ///
1778 /// Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is
1779 /// greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`.
1780 ///
1781 /// Raises [`APIError::ChannelUnavailable`] if the channel cannot be opened due to failing to
1782 /// generate a shutdown scriptpubkey or destination script set by
1783 /// [`SignerProvider::get_shutdown_scriptpubkey`] or [`SignerProvider::get_destination_script`].
1784 ///
1785 /// Note that we do not check if you are currently connected to the given peer. If no
1786 /// connection is available, the outbound `open_channel` message may fail to send, resulting in
1787 /// the channel eventually being silently forgotten (dropped on reload).
1788 ///
1789 /// Returns the new Channel's temporary `channel_id`. This ID will appear as
1790 /// [`Event::FundingGenerationReady::temporary_channel_id`] and in
1791 /// [`ChannelDetails::channel_id`] until after
1792 /// [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
1793 /// one derived from the funding transaction's TXID. If the counterparty rejects the channel
1794 /// immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
1795 ///
1796 /// [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
1797 /// [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
1798 /// [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
1799 ///
1800 /// Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
1801 #[must_use]
1802 #[no_mangle]
1803 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 override_config: crate::lightning::util::config::UserConfig) -> crate::c_types::derived::CResult__u832APIErrorZ {
1804         let mut local_override_config = if override_config.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(override_config.take_inner()) } }) };
1805         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_override_config);
1806         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ThirtyTwoBytes { data: o } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
1807         local_ret
1808 }
1809
1810 /// Gets the list of open channels, in random order. See [`ChannelDetails`] field documentation for
1811 /// more information.
1812 #[must_use]
1813 #[no_mangle]
1814 pub extern "C" fn ChannelManager_list_channels(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1815         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_channels();
1816         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 } }); };
1817         local_ret.into()
1818 }
1819
1820 /// Gets the list of usable channels, in random order. Useful as an argument to
1821 /// [`Router::find_route`] to ensure non-announced channels are used.
1822 ///
1823 /// These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
1824 /// documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
1825 /// are.
1826 #[must_use]
1827 #[no_mangle]
1828 pub extern "C" fn ChannelManager_list_usable_channels(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1829         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_usable_channels();
1830         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 } }); };
1831         local_ret.into()
1832 }
1833
1834 /// Gets the list of channels we have with a given counterparty, in random order.
1835 #[must_use]
1836 #[no_mangle]
1837 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 {
1838         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_channels_with_counterparty(&counterparty_node_id.into_rust());
1839         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 } }); };
1840         local_ret.into()
1841 }
1842
1843 /// Returns in an undefined order recent payments that -- if not fulfilled -- have yet to find a
1844 /// successful path, or have unresolved HTLCs.
1845 ///
1846 /// This can be useful for payments that may have been prepared, but ultimately not sent, as a
1847 /// result of a crash. If such a payment exists, is not listed here, and an
1848 /// [`Event::PaymentSent`] has not been received, you may consider resending the payment.
1849 ///
1850 /// [`Event::PaymentSent`]: events::Event::PaymentSent
1851 #[must_use]
1852 #[no_mangle]
1853 pub extern "C" fn ChannelManager_list_recent_payments(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_RecentPaymentDetailsZ {
1854         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_recent_payments();
1855         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::channelmanager::RecentPaymentDetails::native_into(item) }); };
1856         local_ret.into()
1857 }
1858
1859 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
1860 /// will be accepted on the given channel, and after additional timeout/the closing of all
1861 /// pending HTLCs, the channel will be closed on chain.
1862 ///
1863 ///  * If we are the channel initiator, we will pay between our [`Background`] and
1864 ///    [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
1865 ///    estimate.
1866 ///  * If our counterparty is the channel initiator, we will require a channel closing
1867 ///    transaction feerate of at least our [`Background`] feerate or the feerate which
1868 ///    would appear on a force-closure transaction, whichever is lower. We will allow our
1869 ///    counterparty to pay as much fee as they'd like, however.
1870 ///
1871 /// May generate a [`SendShutdown`] message event on success, which should be relayed.
1872 ///
1873 /// Raises [`APIError::ChannelUnavailable`] if the channel cannot be closed due to failing to
1874 /// generate a shutdown scriptpubkey or destination script set by
1875 /// [`SignerProvider::get_shutdown_scriptpubkey`]. A force-closure may be needed to close the
1876 /// channel.
1877 ///
1878 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
1879 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1880 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1881 /// [`SendShutdown`]: crate::events::MessageSendEvent::SendShutdown
1882 #[must_use]
1883 #[no_mangle]
1884 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 {
1885         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel(unsafe { &*channel_id}, &counterparty_node_id.into_rust());
1886         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() };
1887         local_ret
1888 }
1889
1890 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
1891 /// will be accepted on the given channel, and after additional timeout/the closing of all
1892 /// pending HTLCs, the channel will be closed on chain.
1893 ///
1894 /// `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
1895 /// the channel being closed or not:
1896 ///  * If we are the channel initiator, we will pay at least this feerate on the closing
1897 ///    transaction. The upper-bound is set by
1898 ///    [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
1899 ///    estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
1900 ///  * If our counterparty is the channel initiator, we will refuse to accept a channel closure
1901 ///    transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
1902 ///    will appear on a force-closure transaction, whichever is lower).
1903 ///
1904 /// The `shutdown_script` provided  will be used as the `scriptPubKey` for the closing transaction.
1905 /// Will fail if a shutdown script has already been set for this channel by
1906 /// ['ChannelHandshakeConfig::commit_upfront_shutdown_pubkey`]. The given shutdown script must
1907 /// also be compatible with our and the counterparty's features.
1908 ///
1909 /// May generate a [`SendShutdown`] message event on success, which should be relayed.
1910 ///
1911 /// Raises [`APIError::ChannelUnavailable`] if the channel cannot be closed due to failing to
1912 /// generate a shutdown scriptpubkey or destination script set by
1913 /// [`SignerProvider::get_shutdown_scriptpubkey`]. A force-closure may be needed to close the
1914 /// channel.
1915 ///
1916 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
1917 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1918 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1919 /// [`SendShutdown`]: crate::events::MessageSendEvent::SendShutdown
1920 ///
1921 /// Note that shutdown_script (or a relevant inner pointer) may be NULL or all-0s to represent None
1922 #[must_use]
1923 #[no_mangle]
1924 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 {
1925         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 };
1926         let mut local_shutdown_script = if shutdown_script.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(shutdown_script.take_inner()) } }) };
1927         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel_with_feerate_and_script(unsafe { &*channel_id}, &counterparty_node_id.into_rust(), local_target_feerate_sats_per_1000_weight, local_shutdown_script);
1928         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() };
1929         local_ret
1930 }
1931
1932 /// Force closes a channel, immediately broadcasting the latest local transaction(s) and
1933 /// rejecting new HTLCs on the given channel. Fails if `channel_id` is unknown to
1934 /// the manager, or if the `counterparty_node_id` isn't the counterparty of the corresponding
1935 /// channel.
1936 #[must_use]
1937 #[no_mangle]
1938 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 {
1939         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_broadcasting_latest_txn(unsafe { &*channel_id}, &counterparty_node_id.into_rust());
1940         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() };
1941         local_ret
1942 }
1943
1944 /// Force closes a channel, rejecting new HTLCs on the given channel but skips broadcasting
1945 /// the latest local transaction(s). Fails if `channel_id` is unknown to the manager, or if the
1946 /// `counterparty_node_id` isn't the counterparty of the corresponding channel.
1947 ///
1948 /// You can always get the latest local transaction(s) to broadcast from
1949 /// [`ChannelMonitor::get_latest_holder_commitment_txn`].
1950 #[must_use]
1951 #[no_mangle]
1952 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 {
1953         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_without_broadcasting_txn(unsafe { &*channel_id}, &counterparty_node_id.into_rust());
1954         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() };
1955         local_ret
1956 }
1957
1958 /// Force close all channels, immediately broadcasting the latest local commitment transaction
1959 /// for each to the chain and rejecting new HTLCs on each.
1960 #[no_mangle]
1961 pub extern "C" fn ChannelManager_force_close_all_channels_broadcasting_latest_txn(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
1962         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_all_channels_broadcasting_latest_txn()
1963 }
1964
1965 /// Force close all channels rejecting new HTLCs on each but without broadcasting the latest
1966 /// local transaction(s).
1967 #[no_mangle]
1968 pub extern "C" fn ChannelManager_force_close_all_channels_without_broadcasting_txn(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
1969         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_all_channels_without_broadcasting_txn()
1970 }
1971
1972 /// Sends a payment along a given route.
1973 ///
1974 /// Value parameters are provided via the last hop in route, see documentation for [`RouteHop`]
1975 /// fields for more info.
1976 ///
1977 /// May generate [`UpdateHTLCs`] message(s) event on success, which should be relayed (e.g. via
1978 /// [`PeerManager::process_events`]).
1979 ///
1980 /// # Avoiding Duplicate Payments
1981 ///
1982 /// If a pending payment is currently in-flight with the same [`PaymentId`] provided, this
1983 /// method will error with an [`APIError::InvalidRoute`]. Note, however, that once a payment
1984 /// is no longer pending (either via [`ChannelManager::abandon_payment`], or handling of an
1985 /// [`Event::PaymentSent`] or [`Event::PaymentFailed`]) LDK will not stop you from sending a
1986 /// second payment with the same [`PaymentId`].
1987 ///
1988 /// Thus, in order to ensure duplicate payments are not sent, you should implement your own
1989 /// tracking of payments, including state to indicate once a payment has completed. Because you
1990 /// should also ensure that [`PaymentHash`]es are not re-used, for simplicity, you should
1991 /// consider using the [`PaymentHash`] as the key for tracking payments. In that case, the
1992 /// [`PaymentId`] should be a copy of the [`PaymentHash`] bytes.
1993 ///
1994 /// Additionally, in the scenario where we begin the process of sending a payment, but crash
1995 /// before `send_payment` returns (or prior to [`ChannelMonitorUpdate`] persistence if you're
1996 /// using [`ChannelMonitorUpdateStatus::InProgress`]), the payment may be lost on restart. See
1997 /// [`ChannelManager::list_recent_payments`] for more information.
1998 ///
1999 /// # Possible Error States on [`PaymentSendFailure`]
2000 ///
2001 /// Each path may have a different return value, and [`PaymentSendFailure`] may return a `Vec` with
2002 /// each entry matching the corresponding-index entry in the route paths, see
2003 /// [`PaymentSendFailure`] for more info.
2004 ///
2005 /// In general, a path may raise:
2006 ///  * [`APIError::InvalidRoute`] when an invalid route or forwarding parameter (cltv_delta, fee,
2007 ///    node public key) is specified.
2008 ///  * [`APIError::ChannelUnavailable`] if the next-hop channel is not available for updates
2009 ///    (including due to previous monitor update failure or new permanent monitor update
2010 ///    failure).
2011 ///  * [`APIError::MonitorUpdateInProgress`] if a new monitor update failure prevented sending the
2012 ///    relevant updates.
2013 ///
2014 /// Note that depending on the type of the [`PaymentSendFailure`] the HTLC may have been
2015 /// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
2016 /// different route unless you intend to pay twice!
2017 ///
2018 /// [`RouteHop`]: crate::routing::router::RouteHop
2019 /// [`Event::PaymentSent`]: events::Event::PaymentSent
2020 /// [`Event::PaymentFailed`]: events::Event::PaymentFailed
2021 /// [`UpdateHTLCs`]: events::MessageSendEvent::UpdateHTLCs
2022 /// [`PeerManager::process_events`]: crate::ln::peer_handler::PeerManager::process_events
2023 /// [`ChannelMonitorUpdateStatus::InProgress`]: crate::chain::ChannelMonitorUpdateStatus::InProgress
2024 #[must_use]
2025 #[no_mangle]
2026 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 {
2027         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));
2028         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() };
2029         local_ret
2030 }
2031
2032 /// Similar to [`ChannelManager::send_payment_with_route`], but will automatically find a route based on
2033 /// `route_params` and retry failed payment paths based on `retry_strategy`.
2034 #[must_use]
2035 #[no_mangle]
2036 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 {
2037         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());
2038         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() };
2039         local_ret
2040 }
2041
2042 /// Signals that no further retries for the given payment should occur. Useful if you have a
2043 /// pending outbound payment with retries remaining, but wish to stop retrying the payment before
2044 /// retries are exhausted.
2045 ///
2046 /// If no [`Event::PaymentFailed`] event had been generated before, one will be generated as soon
2047 /// as there are no remaining pending HTLCs for this payment.
2048 ///
2049 /// Note that calling this method does *not* prevent a payment from succeeding. You must still
2050 /// wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to
2051 /// determine the ultimate status of a payment.
2052 ///
2053 /// If an [`Event::PaymentFailed`] event is generated and we restart without this
2054 /// [`ChannelManager`] having been persisted, another [`Event::PaymentFailed`] may be generated.
2055 ///
2056 /// [`Event::PaymentFailed`]: events::Event::PaymentFailed
2057 /// [`Event::PaymentSent`]: events::Event::PaymentSent
2058 #[no_mangle]
2059 pub extern "C" fn ChannelManager_abandon_payment(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_id: crate::c_types::ThirtyTwoBytes) {
2060         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.abandon_payment(::lightning::ln::channelmanager::PaymentId(payment_id.data))
2061 }
2062
2063 /// Send a spontaneous payment, which is a payment that does not require the recipient to have
2064 /// generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
2065 /// the preimage, it must be a cryptographically secure random value that no intermediate node
2066 /// would be able to guess -- otherwise, an intermediate node may claim the payment and it will
2067 /// never reach the recipient.
2068 ///
2069 /// See [`send_payment`] documentation for more details on the return value of this function
2070 /// and idempotency guarantees provided by the [`PaymentId`] key.
2071 ///
2072 /// Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
2073 /// [`send_payment`] for more information about the risks of duplicate preimage usage.
2074 ///
2075 /// [`send_payment`]: Self::send_payment
2076 #[must_use]
2077 #[no_mangle]
2078 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_PaymentPreimageZ, mut recipient_onion: crate::lightning::ln::outbound_payment::RecipientOnionFields, mut payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_PaymentHashPaymentSendFailureZ {
2079         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) }})} };
2080         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));
2081         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() };
2082         local_ret
2083 }
2084
2085 /// Similar to [`ChannelManager::send_spontaneous_payment`], but will automatically find a route
2086 /// based on `route_params` and retry failed payment paths based on `retry_strategy`.
2087 ///
2088 /// See [`PaymentParameters::for_keysend`] for help in constructing `route_params` for spontaneous
2089 /// payments.
2090 ///
2091 /// [`PaymentParameters::for_keysend`]: crate::routing::router::PaymentParameters::for_keysend
2092 #[must_use]
2093 #[no_mangle]
2094 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_PaymentPreimageZ, 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_PaymentHashRetryableSendFailureZ {
2095         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) }})} };
2096         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());
2097         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() };
2098         local_ret
2099 }
2100
2101 /// Send a payment that is probing the given route for liquidity. We calculate the
2102 /// [`PaymentHash`] of probes based on a static secret and a random [`PaymentId`], which allows
2103 /// us to easily discern them from real payments.
2104 #[must_use]
2105 #[no_mangle]
2106 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_PaymentHashPaymentIdZPaymentSendFailureZ {
2107         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_probe(*unsafe { Box::from_raw(path.take_inner()) });
2108         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() };
2109         local_ret
2110 }
2111
2112 /// Call this upon creation of a funding transaction for the given channel.
2113 ///
2114 /// Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
2115 /// or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
2116 ///
2117 /// Returns [`APIError::APIMisuseError`] if the funding transaction is not final for propagation
2118 /// across the p2p network.
2119 ///
2120 /// Returns [`APIError::ChannelUnavailable`] if a funding transaction has already been provided
2121 /// for the channel or if the channel has been closed as indicated by [`Event::ChannelClosed`].
2122 ///
2123 /// May panic if the output found in the funding transaction is duplicative with some other
2124 /// channel (note that this should be trivially prevented by using unique funding transaction
2125 /// keys per-channel).
2126 ///
2127 /// Do NOT broadcast the funding transaction yourself. When we have safely received our
2128 /// counterparty's signature the funding transaction will automatically be broadcast via the
2129 /// [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
2130 ///
2131 /// Note that this includes RBF or similar transaction replacement strategies - lightning does
2132 /// not currently support replacing a funding transaction on an existing channel. Instead,
2133 /// create a new channel with a conflicting funding transaction.
2134 ///
2135 /// Note to keep the miner incentives aligned in moving the blockchain forward, we recommend
2136 /// the wallet software generating the funding transaction to apply anti-fee sniping as
2137 /// implemented by Bitcoin Core wallet. See <https://bitcoinops.org/en/topics/fee-sniping/>
2138 /// for more details.
2139 ///
2140 /// [`Event::FundingGenerationReady`]: crate::events::Event::FundingGenerationReady
2141 /// [`Event::ChannelClosed`]: crate::events::Event::ChannelClosed
2142 #[must_use]
2143 #[no_mangle]
2144 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 {
2145         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_transaction_generated(unsafe { &*temporary_channel_id}, &counterparty_node_id.into_rust(), funding_transaction.into_bitcoin());
2146         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() };
2147         local_ret
2148 }
2149
2150 /// Atomically applies partial updates to the [`ChannelConfig`] of the given channels.
2151 ///
2152 /// Once the updates are applied, each eligible channel (advertised with a known short channel
2153 /// ID and a change in [`forwarding_fee_proportional_millionths`], [`forwarding_fee_base_msat`],
2154 /// or [`cltv_expiry_delta`]) has a [`BroadcastChannelUpdate`] event message generated
2155 /// containing the new [`ChannelUpdate`] message which should be broadcast to the network.
2156 ///
2157 /// Returns [`ChannelUnavailable`] when a channel is not found or an incorrect
2158 /// `counterparty_node_id` is provided.
2159 ///
2160 /// Returns [`APIMisuseError`] when a [`cltv_expiry_delta`] update is to be applied with a value
2161 /// below [`MIN_CLTV_EXPIRY_DELTA`].
2162 ///
2163 /// If an error is returned, none of the updates should be considered applied.
2164 ///
2165 /// [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
2166 /// [`forwarding_fee_base_msat`]: ChannelConfig::forwarding_fee_base_msat
2167 /// [`cltv_expiry_delta`]: ChannelConfig::cltv_expiry_delta
2168 /// [`BroadcastChannelUpdate`]: events::MessageSendEvent::BroadcastChannelUpdate
2169 /// [`ChannelUpdate`]: msgs::ChannelUpdate
2170 /// [`ChannelUnavailable`]: APIError::ChannelUnavailable
2171 /// [`APIMisuseError`]: APIError::APIMisuseError
2172 #[must_use]
2173 #[no_mangle]
2174 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 {
2175         let mut local_channel_ids = Vec::new(); for mut item in channel_ids.into_rust().drain(..) { local_channel_ids.push( { item.data }); };
2176         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_partial_channel_config(&counterparty_node_id.into_rust(), &local_channel_ids.iter().map(|a| *a).collect::<Vec<_>>()[..], config_update.get_native_ref());
2177         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() };
2178         local_ret
2179 }
2180
2181 /// Atomically updates the [`ChannelConfig`] for the given channels.
2182 ///
2183 /// Once the updates are applied, each eligible channel (advertised with a known short channel
2184 /// ID and a change in [`forwarding_fee_proportional_millionths`], [`forwarding_fee_base_msat`],
2185 /// or [`cltv_expiry_delta`]) has a [`BroadcastChannelUpdate`] event message generated
2186 /// containing the new [`ChannelUpdate`] message which should be broadcast to the network.
2187 ///
2188 /// Returns [`ChannelUnavailable`] when a channel is not found or an incorrect
2189 /// `counterparty_node_id` is provided.
2190 ///
2191 /// Returns [`APIMisuseError`] when a [`cltv_expiry_delta`] update is to be applied with a value
2192 /// below [`MIN_CLTV_EXPIRY_DELTA`].
2193 ///
2194 /// If an error is returned, none of the updates should be considered applied.
2195 ///
2196 /// [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
2197 /// [`forwarding_fee_base_msat`]: ChannelConfig::forwarding_fee_base_msat
2198 /// [`cltv_expiry_delta`]: ChannelConfig::cltv_expiry_delta
2199 /// [`BroadcastChannelUpdate`]: events::MessageSendEvent::BroadcastChannelUpdate
2200 /// [`ChannelUpdate`]: msgs::ChannelUpdate
2201 /// [`ChannelUnavailable`]: APIError::ChannelUnavailable
2202 /// [`APIMisuseError`]: APIError::APIMisuseError
2203 #[must_use]
2204 #[no_mangle]
2205 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 {
2206         let mut local_channel_ids = Vec::new(); for mut item in channel_ids.into_rust().drain(..) { local_channel_ids.push( { item.data }); };
2207         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_config(&counterparty_node_id.into_rust(), &local_channel_ids.iter().map(|a| *a).collect::<Vec<_>>()[..], config.get_native_ref());
2208         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() };
2209         local_ret
2210 }
2211
2212 /// Attempts to forward an intercepted HTLC over the provided channel id and with the provided
2213 /// amount to forward. Should only be called in response to an [`HTLCIntercepted`] event.
2214 ///
2215 /// Intercepted HTLCs can be useful for Lightning Service Providers (LSPs) to open a just-in-time
2216 /// channel to a receiving node if the node lacks sufficient inbound liquidity.
2217 ///
2218 /// To make use of intercepted HTLCs, set [`UserConfig::accept_intercept_htlcs`] and use
2219 /// [`ChannelManager::get_intercept_scid`] to generate short channel id(s) to put in the
2220 /// receiver's invoice route hints. These route hints will signal to LDK to generate an
2221 /// [`HTLCIntercepted`] event when it receives the forwarded HTLC, and this method or
2222 /// [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to the event.
2223 ///
2224 /// Note that LDK does not enforce fee requirements in `amt_to_forward_msat`, and will not stop
2225 /// you from forwarding more than you received. See
2226 /// [`HTLCIntercepted::expected_outbound_amount_msat`] for more on forwarding a different amount
2227 /// than expected.
2228 ///
2229 /// Errors if the event was not handled in time, in which case the HTLC was automatically failed
2230 /// backwards.
2231 ///
2232 /// [`UserConfig::accept_intercept_htlcs`]: crate::util::config::UserConfig::accept_intercept_htlcs
2233 /// [`HTLCIntercepted`]: events::Event::HTLCIntercepted
2234 /// [`HTLCIntercepted::expected_outbound_amount_msat`]: events::Event::HTLCIntercepted::expected_outbound_amount_msat
2235 #[must_use]
2236 #[no_mangle]
2237 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 {
2238         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.forward_intercepted_htlc(::lightning::ln::channelmanager::InterceptId(intercept_id.data), unsafe { &*next_hop_channel_id}, next_node_id.into_rust(), amt_to_forward_msat);
2239         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() };
2240         local_ret
2241 }
2242
2243 /// Fails the intercepted HTLC indicated by intercept_id. Should only be called in response to
2244 /// an [`HTLCIntercepted`] event. See [`ChannelManager::forward_intercepted_htlc`].
2245 ///
2246 /// Errors if the event was not handled in time, in which case the HTLC was automatically failed
2247 /// backwards.
2248 ///
2249 /// [`HTLCIntercepted`]: events::Event::HTLCIntercepted
2250 #[must_use]
2251 #[no_mangle]
2252 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 {
2253         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_intercepted_htlc(::lightning::ln::channelmanager::InterceptId(intercept_id.data));
2254         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() };
2255         local_ret
2256 }
2257
2258 /// Processes HTLCs which are pending waiting on random forward delay.
2259 ///
2260 /// Should only really ever be called in response to a PendingHTLCsForwardable event.
2261 /// Will likely generate further events.
2262 #[no_mangle]
2263 pub extern "C" fn ChannelManager_process_pending_htlc_forwards(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
2264         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_pending_htlc_forwards()
2265 }
2266
2267 /// Performs actions which should happen on startup and roughly once per minute thereafter.
2268 ///
2269 /// This currently includes:
2270 ///  * Increasing or decreasing the on-chain feerate estimates for our outbound channels,
2271 ///  * Broadcasting [`ChannelUpdate`] messages if we've been disconnected from our peer for more
2272 ///    than a minute, informing the network that they should no longer attempt to route over
2273 ///    the channel.
2274 ///  * Expiring a channel's previous [`ChannelConfig`] if necessary to only allow forwarding HTLCs
2275 ///    with the current [`ChannelConfig`].
2276 ///  * Removing peers which have disconnected but and no longer have any channels.
2277 ///  * Force-closing and removing channels which have not completed establishment in a timely manner.
2278 ///
2279 /// Note that this may cause reentrancy through [`chain::Watch::update_channel`] calls or feerate
2280 /// estimate fetches.
2281 ///
2282 /// [`ChannelUpdate`]: msgs::ChannelUpdate
2283 /// [`ChannelConfig`]: crate::util::config::ChannelConfig
2284 #[no_mangle]
2285 pub extern "C" fn ChannelManager_timer_tick_occurred(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
2286         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timer_tick_occurred()
2287 }
2288
2289 /// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
2290 /// after a PaymentClaimable event, failing the HTLC back to its origin and freeing resources
2291 /// along the path (including in our own channel on which we received it).
2292 ///
2293 /// Note that in some cases around unclean shutdown, it is possible the payment may have
2294 /// already been claimed by you via [`ChannelManager::claim_funds`] prior to you seeing (a
2295 /// second copy of) the [`events::Event::PaymentClaimable`] event. Alternatively, the payment
2296 /// may have already been failed automatically by LDK if it was nearing its expiration time.
2297 ///
2298 /// While LDK will never claim a payment automatically on your behalf (i.e. without you calling
2299 /// [`ChannelManager::claim_funds`]), you should still monitor for
2300 /// [`events::Event::PaymentClaimed`] events even for payments you intend to fail, especially on
2301 /// startup during which time claims that were in-progress at shutdown may be replayed.
2302 #[no_mangle]
2303 pub extern "C" fn ChannelManager_fail_htlc_backwards(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, payment_hash: *const [u8; 32]) {
2304         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_htlc_backwards(&::lightning::ln::PaymentHash(unsafe { *payment_hash }))
2305 }
2306
2307 /// This is a variant of [`ChannelManager::fail_htlc_backwards`] that allows you to specify the
2308 /// reason for the failure.
2309 ///
2310 /// See [`FailureCode`] for valid failure codes.
2311 #[no_mangle]
2312 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) {
2313         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_htlc_backwards_with_reason(&::lightning::ln::PaymentHash(unsafe { *payment_hash }), failure_code.into_native())
2314 }
2315
2316 /// Provides a payment preimage in response to [`Event::PaymentClaimable`], generating any
2317 /// [`MessageSendEvent`]s needed to claim the payment.
2318 ///
2319 /// This method is guaranteed to ensure the payment has been claimed but only if the current
2320 /// height is strictly below [`Event::PaymentClaimable::claim_deadline`]. To avoid race
2321 /// conditions, you should wait for an [`Event::PaymentClaimed`] before considering the payment
2322 /// successful. It will generally be available in the next [`process_pending_events`] call.
2323 ///
2324 /// Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
2325 /// [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentClaimable`
2326 /// event matches your expectation. If you fail to do so and call this method, you may provide
2327 /// the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
2328 ///
2329 /// [`Event::PaymentClaimable`]: crate::events::Event::PaymentClaimable
2330 /// [`Event::PaymentClaimable::claim_deadline`]: crate::events::Event::PaymentClaimable::claim_deadline
2331 /// [`Event::PaymentClaimed`]: crate::events::Event::PaymentClaimed
2332 /// [`process_pending_events`]: EventsProvider::process_pending_events
2333 /// [`create_inbound_payment`]: Self::create_inbound_payment
2334 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
2335 #[no_mangle]
2336 pub extern "C" fn ChannelManager_claim_funds(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_preimage: crate::c_types::ThirtyTwoBytes) {
2337         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.claim_funds(::lightning::ln::PaymentPreimage(payment_preimage.data))
2338 }
2339
2340 /// Gets the node_id held by this ChannelManager
2341 #[must_use]
2342 #[no_mangle]
2343 pub extern "C" fn ChannelManager_get_our_node_id(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::PublicKey {
2344         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_our_node_id();
2345         crate::c_types::PublicKey::from_rust(&ret)
2346 }
2347
2348 /// Accepts a request to open a channel after a [`Event::OpenChannelRequest`].
2349 ///
2350 /// The `temporary_channel_id` parameter indicates which inbound channel should be accepted,
2351 /// and the `counterparty_node_id` parameter is the id of the peer which has requested to open
2352 /// the channel.
2353 ///
2354 /// The `user_channel_id` parameter will be provided back in
2355 /// [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
2356 /// with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
2357 ///
2358 /// Note that this method will return an error and reject the channel, if it requires support
2359 /// for zero confirmations. Instead, `accept_inbound_channel_from_trusted_peer_0conf` must be
2360 /// used to accept such channels.
2361 ///
2362 /// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
2363 /// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
2364 #[must_use]
2365 #[no_mangle]
2366 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 {
2367         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.accept_inbound_channel(unsafe { &*temporary_channel_id}, &counterparty_node_id.into_rust(), user_channel_id.into());
2368         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() };
2369         local_ret
2370 }
2371
2372 /// Accepts a request to open a channel after a [`events::Event::OpenChannelRequest`], treating
2373 /// it as confirmed immediately.
2374 ///
2375 /// The `user_channel_id` parameter will be provided back in
2376 /// [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
2377 /// with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
2378 ///
2379 /// Unlike [`ChannelManager::accept_inbound_channel`], this method accepts the incoming channel
2380 /// and (if the counterparty agrees), enables forwarding of payments immediately.
2381 ///
2382 /// This fully trusts that the counterparty has honestly and correctly constructed the funding
2383 /// transaction and blindly assumes that it will eventually confirm.
2384 ///
2385 /// If it does not confirm before we decide to close the channel, or if the funding transaction
2386 /// does not pay to the correct script the correct amount, *you will lose funds*.
2387 ///
2388 /// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
2389 /// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
2390 #[must_use]
2391 #[no_mangle]
2392 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 {
2393         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.accept_inbound_channel_from_trusted_peer_0conf(unsafe { &*temporary_channel_id}, &counterparty_node_id.into_rust(), user_channel_id.into());
2394         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() };
2395         local_ret
2396 }
2397
2398 /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
2399 /// to pay us.
2400 ///
2401 /// This differs from [`create_inbound_payment_for_hash`] only in that it generates the
2402 /// [`PaymentHash`] and [`PaymentPreimage`] for you.
2403 ///
2404 /// The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentClaimable`], which
2405 /// will have the [`PaymentClaimable::purpose`] be [`PaymentPurpose::InvoicePayment`] with
2406 /// its [`PaymentPurpose::InvoicePayment::payment_preimage`] field filled in. That should then be
2407 /// passed directly to [`claim_funds`].
2408 ///
2409 /// See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
2410 ///
2411 /// Note that a malicious eavesdropper can intuit whether an inbound payment was created by
2412 /// `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
2413 ///
2414 /// # Note
2415 ///
2416 /// If you register an inbound payment with this method, then serialize the `ChannelManager`, then
2417 /// deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
2418 ///
2419 /// Errors if `min_value_msat` is greater than total bitcoin supply.
2420 ///
2421 /// If `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
2422 /// on versions of LDK prior to 0.0.114.
2423 ///
2424 /// [`claim_funds`]: Self::claim_funds
2425 /// [`PaymentClaimable`]: events::Event::PaymentClaimable
2426 /// [`PaymentClaimable::purpose`]: events::Event::PaymentClaimable::purpose
2427 /// [`PaymentPurpose::InvoicePayment`]: events::PaymentPurpose::InvoicePayment
2428 /// [`PaymentPurpose::InvoicePayment::payment_preimage`]: events::PaymentPurpose::InvoicePayment::payment_preimage
2429 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
2430 #[must_use]
2431 #[no_mangle]
2432 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_PaymentHashPaymentSecretZNoneZ {
2433         let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
2434         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 };
2435         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);
2436         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() };
2437         local_ret
2438 }
2439
2440 /// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
2441 /// stored external to LDK.
2442 ///
2443 /// A [`PaymentClaimable`] event will only be generated if the [`PaymentSecret`] matches a
2444 /// payment secret fetched via this method or [`create_inbound_payment`], and which is at least
2445 /// the `min_value_msat` provided here, if one is provided.
2446 ///
2447 /// The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) should be globally unique, though
2448 /// note that LDK will not stop you from registering duplicate payment hashes for inbound
2449 /// payments.
2450 ///
2451 /// `min_value_msat` should be set if the invoice being generated contains a value. Any payment
2452 /// received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
2453 /// before a [`PaymentClaimable`] event will be generated, ensuring that we do not provide the
2454 /// sender \"proof-of-payment\" unless they have paid the required amount.
2455 ///
2456 /// `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
2457 /// in excess of the current time. This should roughly match the expiry time set in the invoice.
2458 /// After this many seconds, we will remove the inbound payment, resulting in any attempts to
2459 /// pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
2460 /// invoices when no timeout is set.
2461 ///
2462 /// Note that we use block header time to time-out pending inbound payments (with some margin
2463 /// to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
2464 /// accept a payment and generate a [`PaymentClaimable`] event for some time after the expiry.
2465 /// If you need exact expiry semantics, you should enforce them upon receipt of
2466 /// [`PaymentClaimable`].
2467 ///
2468 /// Note that invoices generated for inbound payments should have their `min_final_cltv_expiry_delta`
2469 /// set to at least [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
2470 ///
2471 /// Note that a malicious eavesdropper can intuit whether an inbound payment was created by
2472 /// `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
2473 ///
2474 /// # Note
2475 ///
2476 /// If you register an inbound payment with this method, then serialize the `ChannelManager`, then
2477 /// deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
2478 ///
2479 /// Errors if `min_value_msat` is greater than total bitcoin supply.
2480 ///
2481 /// If `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
2482 /// on versions of LDK prior to 0.0.114.
2483 ///
2484 /// [`create_inbound_payment`]: Self::create_inbound_payment
2485 /// [`PaymentClaimable`]: events::Event::PaymentClaimable
2486 #[must_use]
2487 #[no_mangle]
2488 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_PaymentSecretNoneZ {
2489         let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
2490         let mut local_min_final_cltv_expiry = if min_final_cltv_expiry.is_some() { Some( { min_final_cltv_expiry.take() }) } else { None };
2491         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);
2492         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() };
2493         local_ret
2494 }
2495
2496 /// Gets an LDK-generated payment preimage from a payment hash and payment secret that were
2497 /// previously returned from [`create_inbound_payment`].
2498 ///
2499 /// [`create_inbound_payment`]: Self::create_inbound_payment
2500 #[must_use]
2501 #[no_mangle]
2502 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_PaymentPreimageAPIErrorZ {
2503         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));
2504         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() };
2505         local_ret
2506 }
2507
2508 /// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
2509 /// are used when constructing the phantom invoice's route hints.
2510 ///
2511 /// [phantom node payments]: crate::sign::PhantomKeysManager
2512 #[must_use]
2513 #[no_mangle]
2514 pub extern "C" fn ChannelManager_get_phantom_scid(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> u64 {
2515         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_phantom_scid();
2516         ret
2517 }
2518
2519 /// Gets route hints for use in receiving [phantom node payments].
2520 ///
2521 /// [phantom node payments]: crate::sign::PhantomKeysManager
2522 #[must_use]
2523 #[no_mangle]
2524 pub extern "C" fn ChannelManager_get_phantom_route_hints(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::ln::channelmanager::PhantomRouteHints {
2525         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_phantom_route_hints();
2526         crate::lightning::ln::channelmanager::PhantomRouteHints { inner: ObjOps::heap_alloc(ret), is_owned: true }
2527 }
2528
2529 /// Gets a fake short channel id for use in receiving intercepted payments. These fake scids are
2530 /// used when constructing the route hints for HTLCs intended to be intercepted. See
2531 /// [`ChannelManager::forward_intercepted_htlc`].
2532 ///
2533 /// Note that this method is not guaranteed to return unique values, you may need to call it a few
2534 /// times to get a unique scid.
2535 #[must_use]
2536 #[no_mangle]
2537 pub extern "C" fn ChannelManager_get_intercept_scid(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> u64 {
2538         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_intercept_scid();
2539         ret
2540 }
2541
2542 /// Gets inflight HTLC information by processing pending outbound payments that are in
2543 /// our channels. May be used during pathfinding to account for in-use channel liquidity.
2544 #[must_use]
2545 #[no_mangle]
2546 pub extern "C" fn ChannelManager_compute_inflight_htlcs(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::routing::router::InFlightHtlcs {
2547         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.compute_inflight_htlcs();
2548         crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(ret), is_owned: true }
2549 }
2550
2551 impl From<nativeChannelManager> for crate::lightning::events::MessageSendEventsProvider {
2552         fn from(obj: nativeChannelManager) -> Self {
2553                 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2554                 let mut ret = ChannelManager_as_MessageSendEventsProvider(&rust_obj);
2555                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
2556                 rust_obj.inner = core::ptr::null_mut();
2557                 ret.free = Some(ChannelManager_free_void);
2558                 ret
2559         }
2560 }
2561 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
2562 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
2563 #[no_mangle]
2564 pub extern "C" fn ChannelManager_as_MessageSendEventsProvider(this_arg: &ChannelManager) -> crate::lightning::events::MessageSendEventsProvider {
2565         crate::lightning::events::MessageSendEventsProvider {
2566                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2567                 free: None,
2568                 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
2569         }
2570 }
2571
2572 #[must_use]
2573 extern "C" fn ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
2574         let mut ret = <nativeChannelManager as lightning::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
2575         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::events::MessageSendEvent::native_into(item) }); };
2576         local_ret.into()
2577 }
2578
2579 impl From<nativeChannelManager> for crate::lightning::events::EventsProvider {
2580         fn from(obj: nativeChannelManager) -> Self {
2581                 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2582                 let mut ret = ChannelManager_as_EventsProvider(&rust_obj);
2583                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
2584                 rust_obj.inner = core::ptr::null_mut();
2585                 ret.free = Some(ChannelManager_free_void);
2586                 ret
2587         }
2588 }
2589 /// Constructs a new EventsProvider which calls the relevant methods on this_arg.
2590 /// This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
2591 #[no_mangle]
2592 pub extern "C" fn ChannelManager_as_EventsProvider(this_arg: &ChannelManager) -> crate::lightning::events::EventsProvider {
2593         crate::lightning::events::EventsProvider {
2594                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2595                 free: None,
2596                 process_pending_events: ChannelManager_EventsProvider_process_pending_events,
2597         }
2598 }
2599
2600 extern "C" fn ChannelManager_EventsProvider_process_pending_events(this_arg: *const c_void, mut handler: crate::lightning::events::EventHandler) {
2601         <nativeChannelManager as lightning::events::EventsProvider<>>::process_pending_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, handler)
2602 }
2603
2604 impl From<nativeChannelManager> for crate::lightning::chain::Listen {
2605         fn from(obj: nativeChannelManager) -> Self {
2606                 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2607                 let mut ret = ChannelManager_as_Listen(&rust_obj);
2608                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
2609                 rust_obj.inner = core::ptr::null_mut();
2610                 ret.free = Some(ChannelManager_free_void);
2611                 ret
2612         }
2613 }
2614 /// Constructs a new Listen which calls the relevant methods on this_arg.
2615 /// This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
2616 #[no_mangle]
2617 pub extern "C" fn ChannelManager_as_Listen(this_arg: &ChannelManager) -> crate::lightning::chain::Listen {
2618         crate::lightning::chain::Listen {
2619                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2620                 free: None,
2621                 filtered_block_connected: ChannelManager_Listen_filtered_block_connected,
2622                 block_connected: ChannelManager_Listen_block_connected,
2623                 block_disconnected: ChannelManager_Listen_block_disconnected,
2624         }
2625 }
2626
2627 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) {
2628         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 }); };
2629         <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)
2630 }
2631 extern "C" fn ChannelManager_Listen_block_connected(this_arg: *const c_void, mut block: crate::c_types::u8slice, mut height: u32) {
2632         <nativeChannelManager as lightning::chain::Listen<>>::block_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height)
2633 }
2634 extern "C" fn ChannelManager_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
2635         <nativeChannelManager as lightning::chain::Listen<>>::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
2636 }
2637
2638 impl From<nativeChannelManager> for crate::lightning::chain::Confirm {
2639         fn from(obj: nativeChannelManager) -> Self {
2640                 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2641                 let mut ret = ChannelManager_as_Confirm(&rust_obj);
2642                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
2643                 rust_obj.inner = core::ptr::null_mut();
2644                 ret.free = Some(ChannelManager_free_void);
2645                 ret
2646         }
2647 }
2648 /// Constructs a new Confirm which calls the relevant methods on this_arg.
2649 /// This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
2650 #[no_mangle]
2651 pub extern "C" fn ChannelManager_as_Confirm(this_arg: &ChannelManager) -> crate::lightning::chain::Confirm {
2652         crate::lightning::chain::Confirm {
2653                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2654                 free: None,
2655                 transactions_confirmed: ChannelManager_Confirm_transactions_confirmed,
2656                 transaction_unconfirmed: ChannelManager_Confirm_transaction_unconfirmed,
2657                 best_block_updated: ChannelManager_Confirm_best_block_updated,
2658                 get_relevant_txids: ChannelManager_Confirm_get_relevant_txids,
2659         }
2660 }
2661
2662 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) {
2663         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 }); };
2664         <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)
2665 }
2666 extern "C" fn ChannelManager_Confirm_transaction_unconfirmed(this_arg: *const c_void, txid: *const [u8; 32]) {
2667         <nativeChannelManager as lightning::chain::Confirm<>>::transaction_unconfirmed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap())
2668 }
2669 extern "C" fn ChannelManager_Confirm_best_block_updated(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
2670         <nativeChannelManager as lightning::chain::Confirm<>>::best_block_updated(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
2671 }
2672 #[must_use]
2673 extern "C" fn ChannelManager_Confirm_get_relevant_txids(this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_TxidCOption_BlockHashZZZ {
2674         let mut ret = <nativeChannelManager as lightning::chain::Confirm<>>::get_relevant_txids(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
2675         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = if orig_ret_0_1.is_none() { crate::c_types::derived::COption_BlockHashZ::None } else { crate::c_types::derived::COption_BlockHashZ::Some( { crate::c_types::ThirtyTwoBytes { data: orig_ret_0_1.unwrap().into_inner() } }) }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.into_inner() }, local_orig_ret_0_1).into(); local_ret_0 }); };
2676         local_ret.into()
2677 }
2678
2679 /// Gets a [`Future`] that completes when this [`ChannelManager`] needs to be persisted.
2680 ///
2681 /// Note that callbacks registered on the [`Future`] MUST NOT call back into this
2682 /// [`ChannelManager`] and should instead register actions to be taken later.
2683 ///
2684 #[must_use]
2685 #[no_mangle]
2686 pub extern "C" fn ChannelManager_get_persistable_update_future(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::util::wakers::Future {
2687         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_persistable_update_future();
2688         crate::lightning::util::wakers::Future { inner: ObjOps::heap_alloc(ret), is_owned: true }
2689 }
2690
2691 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
2692 /// [`chain::Confirm`] interfaces.
2693 #[must_use]
2694 #[no_mangle]
2695 pub extern "C" fn ChannelManager_current_best_block(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::chain::BestBlock {
2696         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
2697         crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
2698 }
2699
2700 /// Fetches the set of [`NodeFeatures`] flags which are provided by or required by
2701 /// [`ChannelManager`].
2702 #[must_use]
2703 #[no_mangle]
2704 pub extern "C" fn ChannelManager_node_features(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::ln::features::NodeFeatures {
2705         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.node_features();
2706         crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
2707 }
2708
2709 /// Fetches the set of [`ChannelFeatures`] flags which are provided by or required by
2710 /// [`ChannelManager`].
2711 #[must_use]
2712 #[no_mangle]
2713 pub extern "C" fn ChannelManager_channel_features(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::ln::features::ChannelFeatures {
2714         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_features();
2715         crate::lightning::ln::features::ChannelFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
2716 }
2717
2718 /// Fetches the set of [`ChannelTypeFeatures`] flags which are provided by or required by
2719 /// [`ChannelManager`].
2720 #[must_use]
2721 #[no_mangle]
2722 pub extern "C" fn ChannelManager_channel_type_features(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::ln::features::ChannelTypeFeatures {
2723         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_type_features();
2724         crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
2725 }
2726
2727 /// Fetches the set of [`InitFeatures`] flags which are provided by or required by
2728 /// [`ChannelManager`].
2729 #[must_use]
2730 #[no_mangle]
2731 pub extern "C" fn ChannelManager_init_features(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::ln::features::InitFeatures {
2732         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.init_features();
2733         crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
2734 }
2735
2736 impl From<nativeChannelManager> for crate::lightning::ln::msgs::ChannelMessageHandler {
2737         fn from(obj: nativeChannelManager) -> Self {
2738                 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2739                 let mut ret = ChannelManager_as_ChannelMessageHandler(&rust_obj);
2740                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
2741                 rust_obj.inner = core::ptr::null_mut();
2742                 ret.free = Some(ChannelManager_free_void);
2743                 ret
2744         }
2745 }
2746 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
2747 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
2748 #[no_mangle]
2749 pub extern "C" fn ChannelManager_as_ChannelMessageHandler(this_arg: &ChannelManager) -> crate::lightning::ln::msgs::ChannelMessageHandler {
2750         crate::lightning::ln::msgs::ChannelMessageHandler {
2751                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2752                 free: None,
2753                 handle_open_channel: ChannelManager_ChannelMessageHandler_handle_open_channel,
2754                 handle_open_channel_v2: ChannelManager_ChannelMessageHandler_handle_open_channel_v2,
2755                 handle_accept_channel: ChannelManager_ChannelMessageHandler_handle_accept_channel,
2756                 handle_accept_channel_v2: ChannelManager_ChannelMessageHandler_handle_accept_channel_v2,
2757                 handle_funding_created: ChannelManager_ChannelMessageHandler_handle_funding_created,
2758                 handle_funding_signed: ChannelManager_ChannelMessageHandler_handle_funding_signed,
2759                 handle_channel_ready: ChannelManager_ChannelMessageHandler_handle_channel_ready,
2760                 handle_shutdown: ChannelManager_ChannelMessageHandler_handle_shutdown,
2761                 handle_closing_signed: ChannelManager_ChannelMessageHandler_handle_closing_signed,
2762                 handle_tx_add_input: ChannelManager_ChannelMessageHandler_handle_tx_add_input,
2763                 handle_tx_add_output: ChannelManager_ChannelMessageHandler_handle_tx_add_output,
2764                 handle_tx_remove_input: ChannelManager_ChannelMessageHandler_handle_tx_remove_input,
2765                 handle_tx_remove_output: ChannelManager_ChannelMessageHandler_handle_tx_remove_output,
2766                 handle_tx_complete: ChannelManager_ChannelMessageHandler_handle_tx_complete,
2767                 handle_tx_signatures: ChannelManager_ChannelMessageHandler_handle_tx_signatures,
2768                 handle_tx_init_rbf: ChannelManager_ChannelMessageHandler_handle_tx_init_rbf,
2769                 handle_tx_ack_rbf: ChannelManager_ChannelMessageHandler_handle_tx_ack_rbf,
2770                 handle_tx_abort: ChannelManager_ChannelMessageHandler_handle_tx_abort,
2771                 handle_update_add_htlc: ChannelManager_ChannelMessageHandler_handle_update_add_htlc,
2772                 handle_update_fulfill_htlc: ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc,
2773                 handle_update_fail_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_htlc,
2774                 handle_update_fail_malformed_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_malformed_htlc,
2775                 handle_commitment_signed: ChannelManager_ChannelMessageHandler_handle_commitment_signed,
2776                 handle_revoke_and_ack: ChannelManager_ChannelMessageHandler_handle_revoke_and_ack,
2777                 handle_update_fee: ChannelManager_ChannelMessageHandler_handle_update_fee,
2778                 handle_announcement_signatures: ChannelManager_ChannelMessageHandler_handle_announcement_signatures,
2779                 peer_disconnected: ChannelManager_ChannelMessageHandler_peer_disconnected,
2780                 peer_connected: ChannelManager_ChannelMessageHandler_peer_connected,
2781                 handle_channel_reestablish: ChannelManager_ChannelMessageHandler_handle_channel_reestablish,
2782                 handle_channel_update: ChannelManager_ChannelMessageHandler_handle_channel_update,
2783                 handle_error: ChannelManager_ChannelMessageHandler_handle_error,
2784                 provided_node_features: ChannelManager_ChannelMessageHandler_provided_node_features,
2785                 provided_init_features: ChannelManager_ChannelMessageHandler_provided_init_features,
2786                 get_genesis_hashes: ChannelManager_ChannelMessageHandler_get_genesis_hashes,
2787                 MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider {
2788                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2789                         free: None,
2790                         get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
2791                 },
2792         }
2793 }
2794
2795 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) {
2796         <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())
2797 }
2798 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) {
2799         <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())
2800 }
2801 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) {
2802         <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())
2803 }
2804 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) {
2805         <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())
2806 }
2807 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) {
2808         <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())
2809 }
2810 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) {
2811         <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())
2812 }
2813 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) {
2814         <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())
2815 }
2816 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) {
2817         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_shutdown(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
2818 }
2819 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) {
2820         <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())
2821 }
2822 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) {
2823         <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())
2824 }
2825 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) {
2826         <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())
2827 }
2828 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) {
2829         <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())
2830 }
2831 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) {
2832         <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())
2833 }
2834 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) {
2835         <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())
2836 }
2837 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) {
2838         <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())
2839 }
2840 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) {
2841         <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())
2842 }
2843 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) {
2844         <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())
2845 }
2846 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) {
2847         <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())
2848 }
2849 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) {
2850         <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())
2851 }
2852 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) {
2853         <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())
2854 }
2855 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) {
2856         <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())
2857 }
2858 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) {
2859         <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())
2860 }
2861 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) {
2862         <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())
2863 }
2864 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) {
2865         <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())
2866 }
2867 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) {
2868         <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())
2869 }
2870 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) {
2871         <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())
2872 }
2873 extern "C" fn ChannelManager_ChannelMessageHandler_peer_disconnected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) {
2874         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust())
2875 }
2876 #[must_use]
2877 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 {
2878         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);
2879         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() };
2880         local_ret
2881 }
2882 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) {
2883         <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())
2884 }
2885 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) {
2886         <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())
2887 }
2888 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) {
2889         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust(), msg.get_native_ref())
2890 }
2891 #[must_use]
2892 extern "C" fn ChannelManager_ChannelMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
2893         let mut ret = <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
2894         crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
2895 }
2896 #[must_use]
2897 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 {
2898         let mut ret = <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &their_node_id.into_rust());
2899         crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
2900 }
2901 #[must_use]
2902 extern "C" fn ChannelManager_ChannelMessageHandler_get_genesis_hashes(this_arg: *const c_void) -> crate::c_types::derived::COption_CVec_ChainHashZZ {
2903         let mut ret = <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::get_genesis_hashes(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
2904         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_ChainHashZZ::None } else { crate::c_types::derived::COption_CVec_ChainHashZZ::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.to_bytes() } }); }; local_ret_0.into() }) };
2905         local_ret
2906 }
2907
2908 /// Fetches the set of [`InitFeatures`] flags which are provided by or required by
2909 /// [`ChannelManager`].
2910 #[no_mangle]
2911 pub extern "C" fn provided_init_features(config: &crate::lightning::util::config::UserConfig) -> crate::lightning::ln::features::InitFeatures {
2912         let mut ret = lightning::ln::channelmanager::provided_init_features(config.get_native_ref());
2913         crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
2914 }
2915
2916 #[no_mangle]
2917 /// Serialize the CounterpartyForwardingInfo object into a byte array which can be read by CounterpartyForwardingInfo_read
2918 pub extern "C" fn CounterpartyForwardingInfo_write(obj: &crate::lightning::ln::channelmanager::CounterpartyForwardingInfo) -> crate::c_types::derived::CVec_u8Z {
2919         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2920 }
2921 #[no_mangle]
2922 pub(crate) extern "C" fn CounterpartyForwardingInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2923         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCounterpartyForwardingInfo) })
2924 }
2925 #[no_mangle]
2926 /// Read a CounterpartyForwardingInfo from a byte array, created by CounterpartyForwardingInfo_write
2927 pub extern "C" fn CounterpartyForwardingInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CounterpartyForwardingInfoDecodeErrorZ {
2928         let res: Result<lightning::ln::channelmanager::CounterpartyForwardingInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2929         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() };
2930         local_res
2931 }
2932 #[no_mangle]
2933 /// Serialize the ChannelCounterparty object into a byte array which can be read by ChannelCounterparty_read
2934 pub extern "C" fn ChannelCounterparty_write(obj: &crate::lightning::ln::channelmanager::ChannelCounterparty) -> crate::c_types::derived::CVec_u8Z {
2935         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2936 }
2937 #[no_mangle]
2938 pub(crate) extern "C" fn ChannelCounterparty_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2939         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelCounterparty) })
2940 }
2941 #[no_mangle]
2942 /// Read a ChannelCounterparty from a byte array, created by ChannelCounterparty_write
2943 pub extern "C" fn ChannelCounterparty_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelCounterpartyDecodeErrorZ {
2944         let res: Result<lightning::ln::channelmanager::ChannelCounterparty, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2945         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() };
2946         local_res
2947 }
2948 #[no_mangle]
2949 /// Serialize the ChannelDetails object into a byte array which can be read by ChannelDetails_read
2950 pub extern "C" fn ChannelDetails_write(obj: &crate::lightning::ln::channelmanager::ChannelDetails) -> crate::c_types::derived::CVec_u8Z {
2951         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2952 }
2953 #[no_mangle]
2954 pub(crate) extern "C" fn ChannelDetails_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2955         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelDetails) })
2956 }
2957 #[no_mangle]
2958 /// Read a ChannelDetails from a byte array, created by ChannelDetails_write
2959 pub extern "C" fn ChannelDetails_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelDetailsDecodeErrorZ {
2960         let res: Result<lightning::ln::channelmanager::ChannelDetails, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2961         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() };
2962         local_res
2963 }
2964 #[no_mangle]
2965 /// Serialize the PhantomRouteHints object into a byte array which can be read by PhantomRouteHints_read
2966 pub extern "C" fn PhantomRouteHints_write(obj: &crate::lightning::ln::channelmanager::PhantomRouteHints) -> crate::c_types::derived::CVec_u8Z {
2967         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2968 }
2969 #[no_mangle]
2970 pub(crate) extern "C" fn PhantomRouteHints_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2971         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePhantomRouteHints) })
2972 }
2973 #[no_mangle]
2974 /// Read a PhantomRouteHints from a byte array, created by PhantomRouteHints_write
2975 pub extern "C" fn PhantomRouteHints_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PhantomRouteHintsDecodeErrorZ {
2976         let res: Result<lightning::ln::channelmanager::PhantomRouteHints, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2977         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() };
2978         local_res
2979 }
2980 #[no_mangle]
2981 /// Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
2982 pub extern "C" fn ChannelManager_write(obj: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_u8Z {
2983         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2984 }
2985 #[no_mangle]
2986 pub(crate) extern "C" fn ChannelManager_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2987         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelManager) })
2988 }
2989 #[no_mangle]
2990 /// Serialize the ChannelShutdownState object into a byte array which can be read by ChannelShutdownState_read
2991 pub extern "C" fn ChannelShutdownState_write(obj: &crate::lightning::ln::channelmanager::ChannelShutdownState) -> crate::c_types::derived::CVec_u8Z {
2992         crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
2993 }
2994 #[no_mangle]
2995 /// Read a ChannelShutdownState from a byte array, created by ChannelShutdownState_write
2996 pub extern "C" fn ChannelShutdownState_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelShutdownStateDecodeErrorZ {
2997         let res: Result<lightning::ln::channelmanager::ChannelShutdownState, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2998         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() };
2999         local_res
3000 }
3001
3002 use lightning::ln::channelmanager::ChannelManagerReadArgs as nativeChannelManagerReadArgsImport;
3003 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>;
3004
3005 /// Arguments for the creation of a ChannelManager that are not deserialized.
3006 ///
3007 /// At a high-level, the process for deserializing a ChannelManager and resuming normal operation
3008 /// is:
3009 /// 1) Deserialize all stored [`ChannelMonitor`]s.
3010 /// 2) Deserialize the [`ChannelManager`] by filling in this struct and calling:
3011 ///    `<(BlockHash, ChannelManager)>::read(reader, args)`
3012 ///    This may result in closing some channels if the [`ChannelMonitor`] is newer than the stored
3013 ///    [`ChannelManager`] state to ensure no loss of funds. Thus, transactions may be broadcasted.
3014 /// 3) If you are not fetching full blocks, register all relevant [`ChannelMonitor`] outpoints the
3015 ///    same way you would handle a [`chain::Filter`] call using
3016 ///    [`ChannelMonitor::get_outputs_to_watch`] and [`ChannelMonitor::get_funding_txo`].
3017 /// 4) Reconnect blocks on your [`ChannelMonitor`]s.
3018 /// 5) Disconnect/connect blocks on the [`ChannelManager`].
3019 /// 6) Re-persist the [`ChannelMonitor`]s to ensure the latest state is on disk.
3020 ///    Note that if you're using a [`ChainMonitor`] for your [`chain::Watch`] implementation, you
3021 ///    will likely accomplish this as a side-effect of calling [`chain::Watch::watch_channel`] in
3022 ///    the next step.
3023 /// 7) Move the [`ChannelMonitor`]s into your local [`chain::Watch`]. If you're using a
3024 ///    [`ChainMonitor`], this is done by calling [`chain::Watch::watch_channel`].
3025 ///
3026 /// Note that the ordering of #4-7 is not of importance, however all four must occur before you
3027 /// call any other methods on the newly-deserialized [`ChannelManager`].
3028 ///
3029 /// Note that because some channels may be closed during deserialization, it is critical that you
3030 /// always deserialize only the latest version of a ChannelManager and ChannelMonitors available to
3031 /// you. If you deserialize an old ChannelManager (during which force-closure transactions may be
3032 /// broadcast), and then later deserialize a newer version of the same ChannelManager (which will
3033 /// not force-close the same channels but consider them live), you may end up revoking a state for
3034 /// which you've already broadcasted the transaction.
3035 ///
3036 /// [`ChainMonitor`]: crate::chain::chainmonitor::ChainMonitor
3037 #[must_use]
3038 #[repr(C)]
3039 pub struct ChannelManagerReadArgs {
3040         /// A pointer to the opaque Rust object.
3041
3042         /// Nearly everywhere, inner must be non-null, however in places where
3043         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
3044         pub inner: *mut nativeChannelManagerReadArgs,
3045         /// Indicates that this is the only struct which contains the same pointer.
3046
3047         /// Rust functions which take ownership of an object provided via an argument require
3048         /// this to be true and invalidate the object pointed to by inner.
3049         pub is_owned: bool,
3050 }
3051
3052 impl Drop for ChannelManagerReadArgs {
3053         fn drop(&mut self) {
3054                 if self.is_owned && !<*mut nativeChannelManagerReadArgs>::is_null(self.inner) {
3055                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
3056                 }
3057         }
3058 }
3059 /// Frees any resources used by the ChannelManagerReadArgs, if is_owned is set and inner is non-NULL.
3060 #[no_mangle]
3061 pub extern "C" fn ChannelManagerReadArgs_free(this_obj: ChannelManagerReadArgs) { }
3062 #[allow(unused)]
3063 /// Used only if an object of this type is returned as a trait impl by a method
3064 pub(crate) extern "C" fn ChannelManagerReadArgs_free_void(this_ptr: *mut c_void) {
3065         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelManagerReadArgs) };
3066 }
3067 #[allow(unused)]
3068 impl ChannelManagerReadArgs {
3069         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManagerReadArgs {
3070                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
3071         }
3072         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManagerReadArgs {
3073                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
3074         }
3075         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
3076         pub(crate) fn take_inner(mut self) -> *mut nativeChannelManagerReadArgs {
3077                 assert!(self.is_owned);
3078                 let ret = ObjOps::untweak_ptr(self.inner);
3079                 self.inner = core::ptr::null_mut();
3080                 ret
3081         }
3082 }
3083 /// A cryptographically secure source of entropy.
3084 #[no_mangle]
3085 pub extern "C" fn ChannelManagerReadArgs_get_entropy_source(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::sign::EntropySource {
3086         let mut inner_val = &mut this_ptr.get_native_mut_ref().entropy_source;
3087         inner_val
3088 }
3089 /// A cryptographically secure source of entropy.
3090 #[no_mangle]
3091 pub extern "C" fn ChannelManagerReadArgs_set_entropy_source(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::sign::EntropySource) {
3092         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.entropy_source = val;
3093 }
3094 /// A signer that is able to perform node-scoped cryptographic operations.
3095 #[no_mangle]
3096 pub extern "C" fn ChannelManagerReadArgs_get_node_signer(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::sign::NodeSigner {
3097         let mut inner_val = &mut this_ptr.get_native_mut_ref().node_signer;
3098         inner_val
3099 }
3100 /// A signer that is able to perform node-scoped cryptographic operations.
3101 #[no_mangle]
3102 pub extern "C" fn ChannelManagerReadArgs_set_node_signer(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::sign::NodeSigner) {
3103         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_signer = val;
3104 }
3105 /// The keys provider which will give us relevant keys. Some keys will be loaded during
3106 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
3107 /// signing data.
3108 #[no_mangle]
3109 pub extern "C" fn ChannelManagerReadArgs_get_signer_provider(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::sign::SignerProvider {
3110         let mut inner_val = &mut this_ptr.get_native_mut_ref().signer_provider;
3111         inner_val
3112 }
3113 /// The keys provider which will give us relevant keys. Some keys will be loaded during
3114 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
3115 /// signing data.
3116 #[no_mangle]
3117 pub extern "C" fn ChannelManagerReadArgs_set_signer_provider(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::sign::SignerProvider) {
3118         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.signer_provider = val;
3119 }
3120 /// The fee_estimator for use in the ChannelManager in the future.
3121 ///
3122 /// No calls to the FeeEstimator will be made during deserialization.
3123 #[no_mangle]
3124 pub extern "C" fn ChannelManagerReadArgs_get_fee_estimator(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::FeeEstimator {
3125         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_estimator;
3126         inner_val
3127 }
3128 /// The fee_estimator for use in the ChannelManager in the future.
3129 ///
3130 /// No calls to the FeeEstimator will be made during deserialization.
3131 #[no_mangle]
3132 pub extern "C" fn ChannelManagerReadArgs_set_fee_estimator(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::FeeEstimator) {
3133         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_estimator = val;
3134 }
3135 /// The chain::Watch for use in the ChannelManager in the future.
3136 ///
3137 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
3138 /// you have deserialized ChannelMonitors separately and will add them to your
3139 /// chain::Watch after deserializing this ChannelManager.
3140 #[no_mangle]
3141 pub extern "C" fn ChannelManagerReadArgs_get_chain_monitor(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::Watch {
3142         let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_monitor;
3143         inner_val
3144 }
3145 /// The chain::Watch for use in the ChannelManager in the future.
3146 ///
3147 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
3148 /// you have deserialized ChannelMonitors separately and will add them to your
3149 /// chain::Watch after deserializing this ChannelManager.
3150 #[no_mangle]
3151 pub extern "C" fn ChannelManagerReadArgs_set_chain_monitor(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::Watch) {
3152         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_monitor = val;
3153 }
3154 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
3155 /// used to broadcast the latest local commitment transactions of channels which must be
3156 /// force-closed during deserialization.
3157 #[no_mangle]
3158 pub extern "C" fn ChannelManagerReadArgs_get_tx_broadcaster(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::BroadcasterInterface {
3159         let mut inner_val = &mut this_ptr.get_native_mut_ref().tx_broadcaster;
3160         inner_val
3161 }
3162 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
3163 /// used to broadcast the latest local commitment transactions of channels which must be
3164 /// force-closed during deserialization.
3165 #[no_mangle]
3166 pub extern "C" fn ChannelManagerReadArgs_set_tx_broadcaster(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::BroadcasterInterface) {
3167         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.tx_broadcaster = val;
3168 }
3169 /// The router which will be used in the ChannelManager in the future for finding routes
3170 /// on-the-fly for trampoline payments. Absent in private nodes that don't support forwarding.
3171 ///
3172 /// No calls to the router will be made during deserialization.
3173 #[no_mangle]
3174 pub extern "C" fn ChannelManagerReadArgs_get_router(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::routing::router::Router {
3175         let mut inner_val = &mut this_ptr.get_native_mut_ref().router;
3176         inner_val
3177 }
3178 /// The router which will be used in the ChannelManager in the future for finding routes
3179 /// on-the-fly for trampoline payments. Absent in private nodes that don't support forwarding.
3180 ///
3181 /// No calls to the router will be made during deserialization.
3182 #[no_mangle]
3183 pub extern "C" fn ChannelManagerReadArgs_set_router(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::routing::router::Router) {
3184         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.router = val;
3185 }
3186 /// The Logger for use in the ChannelManager and which may be used to log information during
3187 /// deserialization.
3188 #[no_mangle]
3189 pub extern "C" fn ChannelManagerReadArgs_get_logger(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::util::logger::Logger {
3190         let mut inner_val = &mut this_ptr.get_native_mut_ref().logger;
3191         inner_val
3192 }
3193 /// The Logger for use in the ChannelManager and which may be used to log information during
3194 /// deserialization.
3195 #[no_mangle]
3196 pub extern "C" fn ChannelManagerReadArgs_set_logger(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::logger::Logger) {
3197         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.logger = val;
3198 }
3199 /// Default settings used for new channels. Any existing channels will continue to use the
3200 /// runtime settings which were stored when the ChannelManager was serialized.
3201 #[no_mangle]
3202 pub extern "C" fn ChannelManagerReadArgs_get_default_config(this_ptr: &ChannelManagerReadArgs) -> crate::lightning::util::config::UserConfig {
3203         let mut inner_val = &mut this_ptr.get_native_mut_ref().default_config;
3204         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 }
3205 }
3206 /// Default settings used for new channels. Any existing channels will continue to use the
3207 /// runtime settings which were stored when the ChannelManager was serialized.
3208 #[no_mangle]
3209 pub extern "C" fn ChannelManagerReadArgs_set_default_config(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::config::UserConfig) {
3210         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.default_config = *unsafe { Box::from_raw(val.take_inner()) };
3211 }
3212 /// Simple utility function to create a ChannelManagerReadArgs which creates the monitor
3213 /// HashMap for you. This is primarily useful for C bindings where it is not practical to
3214 /// populate a HashMap directly from C.
3215 #[must_use]
3216 #[no_mangle]
3217 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 {
3218         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() }); };
3219         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);
3220         crate::lightning::ln::channelmanager::ChannelManagerReadArgs { inner: ObjOps::heap_alloc(ret), is_owned: true }
3221 }
3222
3223 #[no_mangle]
3224 /// Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_write
3225 pub extern "C" fn C2Tuple_BlockHashChannelManagerZ_read(ser: crate::c_types::u8slice, arg: crate::lightning::ln::channelmanager::ChannelManagerReadArgs) -> crate::c_types::derived::CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ {
3226         let arg_conv = *unsafe { Box::from_raw(arg.take_inner()) };
3227         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);
3228         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_res_0_0, mut orig_res_0_1) = o; let mut local_res_0 = (crate::c_types::ThirtyTwoBytes { data: orig_res_0_0.into_inner() }, crate::lightning::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() };
3229         local_res
3230 }