Update auto-generated bindings
[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 [`find_route`] 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 //! [`find_route`]: crate::routing::router::find_route
20
21 use alloc::str::FromStr;
22 use core::ffi::c_void;
23 use core::convert::Infallible;
24 use bitcoin::hashes::Hash;
25 use crate::c_types::*;
26 #[cfg(feature="no-std")]
27 use alloc::{vec::Vec, boxed::Box};
28
29
30 use lightning::ln::channelmanager::ChannelManager as nativeChannelManagerImport;
31 pub(crate) type nativeChannelManager = nativeChannelManagerImport<crate::lightning::chain::keysinterface::Sign, crate::lightning::chain::Watch, crate::lightning::chain::chaininterface::BroadcasterInterface, crate::lightning::chain::keysinterface::KeysInterface, crate::lightning::chain::chaininterface::FeeEstimator, crate::lightning::util::logger::Logger>;
32
33 /// Manager which keeps track of a number of channels and sends messages to the appropriate
34 /// channel, also tracking HTLC preimages and forwarding onion packets appropriately.
35 ///
36 /// Implements ChannelMessageHandler, handling the multi-channel parts and passing things through
37 /// to individual Channels.
38 ///
39 /// Implements Writeable to write out all channel state to disk. Implies peer_disconnected() for
40 /// all peers during write/read (though does not modify this instance, only the instance being
41 /// serialized). This will result in any channels which have not yet exchanged funding_created (ie
42 /// called funding_transaction_generated for outbound channels).
43 ///
44 /// Note that you can be a bit lazier about writing out ChannelManager than you can be with
45 /// ChannelMonitors. With ChannelMonitors you MUST write each monitor update out to disk before
46 /// returning from chain::Watch::watch_/update_channel, with ChannelManagers, writing updates
47 /// happens out-of-band (and will prevent any other ChannelManager operations from occurring during
48 /// the serialization process). If the deserialized version is out-of-date compared to the
49 /// ChannelMonitors passed by reference to read(), those channels will be force-closed based on the
50 /// ChannelMonitor state and no funds will be lost (mod on-chain transaction fees).
51 ///
52 /// Note that the deserializer is only implemented for (BlockHash, ChannelManager), which
53 /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
54 /// the \"reorg path\" (ie call block_disconnected() until you get to a common block and then call
55 /// block_connected() to step towards your best block) upon deserialization before using the
56 /// object!
57 ///
58 /// Note that ChannelManager is responsible for tracking liveness of its channels and generating
59 /// ChannelUpdate messages informing peers that the channel is temporarily disabled. To avoid
60 /// spam due to quick disconnection/reconnection, updates are not sent until the channel has been
61 /// offline for a full minute. In order to track this, you must call
62 /// timer_tick_occurred roughly once per minute, though it doesn't have to be perfect.
63 ///
64 /// Rather than using a plain ChannelManager, it is preferable to use either a SimpleArcChannelManager
65 /// a SimpleRefChannelManager, for conciseness. See their documentation for more details, but
66 /// essentially you should default to using a SimpleRefChannelManager, and use a
67 /// SimpleArcChannelManager when you require a ChannelManager with a static lifetime, such as when
68 /// you're using lightning-net-tokio.
69 #[must_use]
70 #[repr(C)]
71 pub struct ChannelManager {
72         /// A pointer to the opaque Rust object.
73
74         /// Nearly everywhere, inner must be non-null, however in places where
75         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
76         pub inner: *mut nativeChannelManager,
77         /// Indicates that this is the only struct which contains the same pointer.
78
79         /// Rust functions which take ownership of an object provided via an argument require
80         /// this to be true and invalidate the object pointed to by inner.
81         pub is_owned: bool,
82 }
83
84 impl Drop for ChannelManager {
85         fn drop(&mut self) {
86                 if self.is_owned && !<*mut nativeChannelManager>::is_null(self.inner) {
87                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
88                 }
89         }
90 }
91 /// Frees any resources used by the ChannelManager, if is_owned is set and inner is non-NULL.
92 #[no_mangle]
93 pub extern "C" fn ChannelManager_free(this_obj: ChannelManager) { }
94 #[allow(unused)]
95 /// Used only if an object of this type is returned as a trait impl by a method
96 pub(crate) extern "C" fn ChannelManager_free_void(this_ptr: *mut c_void) {
97         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManager); }
98 }
99 #[allow(unused)]
100 impl ChannelManager {
101         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManager {
102                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
103         }
104         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManager {
105                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
106         }
107         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
108         pub(crate) fn take_inner(mut self) -> *mut nativeChannelManager {
109                 assert!(self.is_owned);
110                 let ret = ObjOps::untweak_ptr(self.inner);
111                 self.inner = core::ptr::null_mut();
112                 ret
113         }
114 }
115
116 use lightning::ln::channelmanager::ChainParameters as nativeChainParametersImport;
117 pub(crate) type nativeChainParameters = nativeChainParametersImport;
118
119 /// Chain-related parameters used to construct a new `ChannelManager`.
120 ///
121 /// Typically, the block-specific parameters are derived from the best block hash for the network,
122 /// as a newly constructed `ChannelManager` will not have created any channels yet. These parameters
123 /// are not needed when deserializing a previously constructed `ChannelManager`.
124 #[must_use]
125 #[repr(C)]
126 pub struct ChainParameters {
127         /// A pointer to the opaque Rust object.
128
129         /// Nearly everywhere, inner must be non-null, however in places where
130         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
131         pub inner: *mut nativeChainParameters,
132         /// Indicates that this is the only struct which contains the same pointer.
133
134         /// Rust functions which take ownership of an object provided via an argument require
135         /// this to be true and invalidate the object pointed to by inner.
136         pub is_owned: bool,
137 }
138
139 impl Drop for ChainParameters {
140         fn drop(&mut self) {
141                 if self.is_owned && !<*mut nativeChainParameters>::is_null(self.inner) {
142                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
143                 }
144         }
145 }
146 /// Frees any resources used by the ChainParameters, if is_owned is set and inner is non-NULL.
147 #[no_mangle]
148 pub extern "C" fn ChainParameters_free(this_obj: ChainParameters) { }
149 #[allow(unused)]
150 /// Used only if an object of this type is returned as a trait impl by a method
151 pub(crate) extern "C" fn ChainParameters_free_void(this_ptr: *mut c_void) {
152         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChainParameters); }
153 }
154 #[allow(unused)]
155 impl ChainParameters {
156         pub(crate) fn get_native_ref(&self) -> &'static nativeChainParameters {
157                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
158         }
159         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChainParameters {
160                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
161         }
162         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
163         pub(crate) fn take_inner(mut self) -> *mut nativeChainParameters {
164                 assert!(self.is_owned);
165                 let ret = ObjOps::untweak_ptr(self.inner);
166                 self.inner = core::ptr::null_mut();
167                 ret
168         }
169 }
170 /// The network for determining the `chain_hash` in Lightning messages.
171 #[no_mangle]
172 pub extern "C" fn ChainParameters_get_network(this_ptr: &ChainParameters) -> crate::bitcoin::network::Network {
173         let mut inner_val = &mut this_ptr.get_native_mut_ref().network;
174         crate::bitcoin::network::Network::from_bitcoin(inner_val)
175 }
176 /// The network for determining the `chain_hash` in Lightning messages.
177 #[no_mangle]
178 pub extern "C" fn ChainParameters_set_network(this_ptr: &mut ChainParameters, mut val: crate::bitcoin::network::Network) {
179         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.network = val.into_bitcoin();
180 }
181 /// The hash and height of the latest block successfully connected.
182 ///
183 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
184 #[no_mangle]
185 pub extern "C" fn ChainParameters_get_best_block(this_ptr: &ChainParameters) -> crate::lightning::chain::BestBlock {
186         let mut inner_val = &mut this_ptr.get_native_mut_ref().best_block;
187         crate::lightning::chain::BestBlock { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::chain::BestBlock<>) as *mut _) }, is_owned: false }
188 }
189 /// The hash and height of the latest block successfully connected.
190 ///
191 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
192 #[no_mangle]
193 pub extern "C" fn ChainParameters_set_best_block(this_ptr: &mut ChainParameters, mut val: crate::lightning::chain::BestBlock) {
194         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.best_block = *unsafe { Box::from_raw(val.take_inner()) };
195 }
196 /// Constructs a new ChainParameters given each field
197 #[must_use]
198 #[no_mangle]
199 pub extern "C" fn ChainParameters_new(mut network_arg: crate::bitcoin::network::Network, mut best_block_arg: crate::lightning::chain::BestBlock) -> ChainParameters {
200         ChainParameters { inner: ObjOps::heap_alloc(nativeChainParameters {
201                 network: network_arg.into_bitcoin(),
202                 best_block: *unsafe { Box::from_raw(best_block_arg.take_inner()) },
203         }), is_owned: true }
204 }
205 impl Clone for ChainParameters {
206         fn clone(&self) -> Self {
207                 Self {
208                         inner: if <*mut nativeChainParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
209                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
210                         is_owned: true,
211                 }
212         }
213 }
214 #[allow(unused)]
215 /// Used only if an object of this type is returned as a trait impl by a method
216 pub(crate) extern "C" fn ChainParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
217         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChainParameters)).clone() })) as *mut c_void
218 }
219 #[no_mangle]
220 /// Creates a copy of the ChainParameters
221 pub extern "C" fn ChainParameters_clone(orig: &ChainParameters) -> ChainParameters {
222         orig.clone()
223 }
224 /// The amount of time in blocks we require our counterparty wait to claim their money (ie time
225 /// between when we, or our watchtower, must check for them having broadcast a theft transaction).
226 ///
227 /// This can be increased (but not decreased) through [`ChannelHandshakeConfig::our_to_self_delay`]
228 ///
229 /// [`ChannelHandshakeConfig::our_to_self_delay`]: crate::util::config::ChannelHandshakeConfig::our_to_self_delay
230
231 #[no_mangle]
232 pub static BREAKDOWN_TIMEOUT: u16 = lightning::ln::channelmanager::BREAKDOWN_TIMEOUT;
233 /// The minimum number of blocks between an inbound HTLC's CLTV and the corresponding outbound
234 /// HTLC's CLTV. The current default represents roughly seven hours of blocks at six blocks/hour.
235 ///
236 /// This can be increased (but not decreased) through [`ChannelConfig::cltv_expiry_delta`]
237 ///
238 /// [`ChannelConfig::cltv_expiry_delta`]: crate::util::config::ChannelConfig::cltv_expiry_delta
239
240 #[no_mangle]
241 pub static MIN_CLTV_EXPIRY_DELTA: u16 = lightning::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA;
242 /// Minimum CLTV difference between the current block height and received inbound payments.
243 /// Invoices generated for payment to us must set their `min_final_cltv_expiry` field to at least
244 /// this value.
245
246 #[no_mangle]
247 pub static MIN_FINAL_CLTV_EXPIRY: u32 = lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY;
248
249 use lightning::ln::channelmanager::CounterpartyForwardingInfo as nativeCounterpartyForwardingInfoImport;
250 pub(crate) type nativeCounterpartyForwardingInfo = nativeCounterpartyForwardingInfoImport;
251
252 /// Information needed for constructing an invoice route hint for this channel.
253 #[must_use]
254 #[repr(C)]
255 pub struct CounterpartyForwardingInfo {
256         /// A pointer to the opaque Rust object.
257
258         /// Nearly everywhere, inner must be non-null, however in places where
259         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
260         pub inner: *mut nativeCounterpartyForwardingInfo,
261         /// Indicates that this is the only struct which contains the same pointer.
262
263         /// Rust functions which take ownership of an object provided via an argument require
264         /// this to be true and invalidate the object pointed to by inner.
265         pub is_owned: bool,
266 }
267
268 impl Drop for CounterpartyForwardingInfo {
269         fn drop(&mut self) {
270                 if self.is_owned && !<*mut nativeCounterpartyForwardingInfo>::is_null(self.inner) {
271                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
272                 }
273         }
274 }
275 /// Frees any resources used by the CounterpartyForwardingInfo, if is_owned is set and inner is non-NULL.
276 #[no_mangle]
277 pub extern "C" fn CounterpartyForwardingInfo_free(this_obj: CounterpartyForwardingInfo) { }
278 #[allow(unused)]
279 /// Used only if an object of this type is returned as a trait impl by a method
280 pub(crate) extern "C" fn CounterpartyForwardingInfo_free_void(this_ptr: *mut c_void) {
281         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCounterpartyForwardingInfo); }
282 }
283 #[allow(unused)]
284 impl CounterpartyForwardingInfo {
285         pub(crate) fn get_native_ref(&self) -> &'static nativeCounterpartyForwardingInfo {
286                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
287         }
288         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCounterpartyForwardingInfo {
289                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
290         }
291         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
292         pub(crate) fn take_inner(mut self) -> *mut nativeCounterpartyForwardingInfo {
293                 assert!(self.is_owned);
294                 let ret = ObjOps::untweak_ptr(self.inner);
295                 self.inner = core::ptr::null_mut();
296                 ret
297         }
298 }
299 /// Base routing fee in millisatoshis.
300 #[no_mangle]
301 pub extern "C" fn CounterpartyForwardingInfo_get_fee_base_msat(this_ptr: &CounterpartyForwardingInfo) -> u32 {
302         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_base_msat;
303         *inner_val
304 }
305 /// Base routing fee in millisatoshis.
306 #[no_mangle]
307 pub extern "C" fn CounterpartyForwardingInfo_set_fee_base_msat(this_ptr: &mut CounterpartyForwardingInfo, mut val: u32) {
308         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_base_msat = val;
309 }
310 /// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
311 #[no_mangle]
312 pub extern "C" fn CounterpartyForwardingInfo_get_fee_proportional_millionths(this_ptr: &CounterpartyForwardingInfo) -> u32 {
313         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_proportional_millionths;
314         *inner_val
315 }
316 /// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
317 #[no_mangle]
318 pub extern "C" fn CounterpartyForwardingInfo_set_fee_proportional_millionths(this_ptr: &mut CounterpartyForwardingInfo, mut val: u32) {
319         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_proportional_millionths = val;
320 }
321 /// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
322 /// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
323 /// `cltv_expiry_delta` for more details.
324 #[no_mangle]
325 pub extern "C" fn CounterpartyForwardingInfo_get_cltv_expiry_delta(this_ptr: &CounterpartyForwardingInfo) -> u16 {
326         let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
327         *inner_val
328 }
329 /// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
330 /// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
331 /// `cltv_expiry_delta` for more details.
332 #[no_mangle]
333 pub extern "C" fn CounterpartyForwardingInfo_set_cltv_expiry_delta(this_ptr: &mut CounterpartyForwardingInfo, mut val: u16) {
334         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
335 }
336 /// Constructs a new CounterpartyForwardingInfo given each field
337 #[must_use]
338 #[no_mangle]
339 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 {
340         CounterpartyForwardingInfo { inner: ObjOps::heap_alloc(nativeCounterpartyForwardingInfo {
341                 fee_base_msat: fee_base_msat_arg,
342                 fee_proportional_millionths: fee_proportional_millionths_arg,
343                 cltv_expiry_delta: cltv_expiry_delta_arg,
344         }), is_owned: true }
345 }
346 impl Clone for CounterpartyForwardingInfo {
347         fn clone(&self) -> Self {
348                 Self {
349                         inner: if <*mut nativeCounterpartyForwardingInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
350                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
351                         is_owned: true,
352                 }
353         }
354 }
355 #[allow(unused)]
356 /// Used only if an object of this type is returned as a trait impl by a method
357 pub(crate) extern "C" fn CounterpartyForwardingInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
358         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCounterpartyForwardingInfo)).clone() })) as *mut c_void
359 }
360 #[no_mangle]
361 /// Creates a copy of the CounterpartyForwardingInfo
362 pub extern "C" fn CounterpartyForwardingInfo_clone(orig: &CounterpartyForwardingInfo) -> CounterpartyForwardingInfo {
363         orig.clone()
364 }
365
366 use lightning::ln::channelmanager::ChannelCounterparty as nativeChannelCounterpartyImport;
367 pub(crate) type nativeChannelCounterparty = nativeChannelCounterpartyImport;
368
369 /// Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
370 /// to better separate parameters.
371 #[must_use]
372 #[repr(C)]
373 pub struct ChannelCounterparty {
374         /// A pointer to the opaque Rust object.
375
376         /// Nearly everywhere, inner must be non-null, however in places where
377         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
378         pub inner: *mut nativeChannelCounterparty,
379         /// Indicates that this is the only struct which contains the same pointer.
380
381         /// Rust functions which take ownership of an object provided via an argument require
382         /// this to be true and invalidate the object pointed to by inner.
383         pub is_owned: bool,
384 }
385
386 impl Drop for ChannelCounterparty {
387         fn drop(&mut self) {
388                 if self.is_owned && !<*mut nativeChannelCounterparty>::is_null(self.inner) {
389                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
390                 }
391         }
392 }
393 /// Frees any resources used by the ChannelCounterparty, if is_owned is set and inner is non-NULL.
394 #[no_mangle]
395 pub extern "C" fn ChannelCounterparty_free(this_obj: ChannelCounterparty) { }
396 #[allow(unused)]
397 /// Used only if an object of this type is returned as a trait impl by a method
398 pub(crate) extern "C" fn ChannelCounterparty_free_void(this_ptr: *mut c_void) {
399         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelCounterparty); }
400 }
401 #[allow(unused)]
402 impl ChannelCounterparty {
403         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelCounterparty {
404                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
405         }
406         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelCounterparty {
407                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
408         }
409         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
410         pub(crate) fn take_inner(mut self) -> *mut nativeChannelCounterparty {
411                 assert!(self.is_owned);
412                 let ret = ObjOps::untweak_ptr(self.inner);
413                 self.inner = core::ptr::null_mut();
414                 ret
415         }
416 }
417 /// The node_id of our counterparty
418 #[no_mangle]
419 pub extern "C" fn ChannelCounterparty_get_node_id(this_ptr: &ChannelCounterparty) -> crate::c_types::PublicKey {
420         let mut inner_val = &mut this_ptr.get_native_mut_ref().node_id;
421         crate::c_types::PublicKey::from_rust(&inner_val)
422 }
423 /// The node_id of our counterparty
424 #[no_mangle]
425 pub extern "C" fn ChannelCounterparty_set_node_id(this_ptr: &mut ChannelCounterparty, mut val: crate::c_types::PublicKey) {
426         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_id = val.into_rust();
427 }
428 /// The Features the channel counterparty provided upon last connection.
429 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
430 /// many routing-relevant features are present in the init context.
431 #[no_mangle]
432 pub extern "C" fn ChannelCounterparty_get_features(this_ptr: &ChannelCounterparty) -> crate::lightning::ln::features::InitFeatures {
433         let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
434         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 }
435 }
436 /// The Features the channel counterparty provided upon last connection.
437 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
438 /// many routing-relevant features are present in the init context.
439 #[no_mangle]
440 pub extern "C" fn ChannelCounterparty_set_features(this_ptr: &mut ChannelCounterparty, mut val: crate::lightning::ln::features::InitFeatures) {
441         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
442 }
443 /// The value, in satoshis, that must always be held in the channel for our counterparty. This
444 /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
445 /// claiming at least this value on chain.
446 ///
447 /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
448 ///
449 /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
450 #[no_mangle]
451 pub extern "C" fn ChannelCounterparty_get_unspendable_punishment_reserve(this_ptr: &ChannelCounterparty) -> u64 {
452         let mut inner_val = &mut this_ptr.get_native_mut_ref().unspendable_punishment_reserve;
453         *inner_val
454 }
455 /// The value, in satoshis, that must always be held in the channel for our counterparty. This
456 /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
457 /// claiming at least this value on chain.
458 ///
459 /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
460 ///
461 /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
462 #[no_mangle]
463 pub extern "C" fn ChannelCounterparty_set_unspendable_punishment_reserve(this_ptr: &mut ChannelCounterparty, mut val: u64) {
464         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = val;
465 }
466 /// Information on the fees and requirements that the counterparty requires when forwarding
467 /// payments to us through this channel.
468 ///
469 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
470 #[no_mangle]
471 pub extern "C" fn ChannelCounterparty_get_forwarding_info(this_ptr: &ChannelCounterparty) -> crate::lightning::ln::channelmanager::CounterpartyForwardingInfo {
472         let mut inner_val = &mut this_ptr.get_native_mut_ref().forwarding_info;
473         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 };
474         local_inner_val
475 }
476 /// Information on the fees and requirements that the counterparty requires when forwarding
477 /// payments to us through this channel.
478 ///
479 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
480 #[no_mangle]
481 pub extern "C" fn ChannelCounterparty_set_forwarding_info(this_ptr: &mut ChannelCounterparty, mut val: crate::lightning::ln::channelmanager::CounterpartyForwardingInfo) {
482         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
483         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.forwarding_info = local_val;
484 }
485 /// The smallest value HTLC (in msat) the remote peer will accept, for this channel. This field
486 /// is only `None` before we have received either the `OpenChannel` or `AcceptChannel` message
487 /// from the remote peer, or for `ChannelCounterparty` objects serialized prior to LDK 0.0.107.
488 #[no_mangle]
489 pub extern "C" fn ChannelCounterparty_get_outbound_htlc_minimum_msat(this_ptr: &ChannelCounterparty) -> crate::c_types::derived::COption_u64Z {
490         let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_htlc_minimum_msat;
491         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() }) };
492         local_inner_val
493 }
494 /// The smallest value HTLC (in msat) the remote peer will accept, for this channel. This field
495 /// is only `None` before we have received either the `OpenChannel` or `AcceptChannel` message
496 /// from the remote peer, or for `ChannelCounterparty` objects serialized prior to LDK 0.0.107.
497 #[no_mangle]
498 pub extern "C" fn ChannelCounterparty_set_outbound_htlc_minimum_msat(this_ptr: &mut ChannelCounterparty, mut val: crate::c_types::derived::COption_u64Z) {
499         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
500         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_htlc_minimum_msat = local_val;
501 }
502 /// The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
503 #[no_mangle]
504 pub extern "C" fn ChannelCounterparty_get_outbound_htlc_maximum_msat(this_ptr: &ChannelCounterparty) -> crate::c_types::derived::COption_u64Z {
505         let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_htlc_maximum_msat;
506         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() }) };
507         local_inner_val
508 }
509 /// The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
510 #[no_mangle]
511 pub extern "C" fn ChannelCounterparty_set_outbound_htlc_maximum_msat(this_ptr: &mut ChannelCounterparty, mut val: crate::c_types::derived::COption_u64Z) {
512         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
513         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_htlc_maximum_msat = local_val;
514 }
515 /// Constructs a new ChannelCounterparty given each field
516 #[must_use]
517 #[no_mangle]
518 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 {
519         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()) } }) };
520         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 };
521         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 };
522         ChannelCounterparty { inner: ObjOps::heap_alloc(nativeChannelCounterparty {
523                 node_id: node_id_arg.into_rust(),
524                 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
525                 unspendable_punishment_reserve: unspendable_punishment_reserve_arg,
526                 forwarding_info: local_forwarding_info_arg,
527                 outbound_htlc_minimum_msat: local_outbound_htlc_minimum_msat_arg,
528                 outbound_htlc_maximum_msat: local_outbound_htlc_maximum_msat_arg,
529         }), is_owned: true }
530 }
531 impl Clone for ChannelCounterparty {
532         fn clone(&self) -> Self {
533                 Self {
534                         inner: if <*mut nativeChannelCounterparty>::is_null(self.inner) { core::ptr::null_mut() } else {
535                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
536                         is_owned: true,
537                 }
538         }
539 }
540 #[allow(unused)]
541 /// Used only if an object of this type is returned as a trait impl by a method
542 pub(crate) extern "C" fn ChannelCounterparty_clone_void(this_ptr: *const c_void) -> *mut c_void {
543         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelCounterparty)).clone() })) as *mut c_void
544 }
545 #[no_mangle]
546 /// Creates a copy of the ChannelCounterparty
547 pub extern "C" fn ChannelCounterparty_clone(orig: &ChannelCounterparty) -> ChannelCounterparty {
548         orig.clone()
549 }
550
551 use lightning::ln::channelmanager::ChannelDetails as nativeChannelDetailsImport;
552 pub(crate) type nativeChannelDetails = nativeChannelDetailsImport;
553
554 /// Details of a channel, as returned by ChannelManager::list_channels and ChannelManager::list_usable_channels
555 #[must_use]
556 #[repr(C)]
557 pub struct ChannelDetails {
558         /// A pointer to the opaque Rust object.
559
560         /// Nearly everywhere, inner must be non-null, however in places where
561         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
562         pub inner: *mut nativeChannelDetails,
563         /// Indicates that this is the only struct which contains the same pointer.
564
565         /// Rust functions which take ownership of an object provided via an argument require
566         /// this to be true and invalidate the object pointed to by inner.
567         pub is_owned: bool,
568 }
569
570 impl Drop for ChannelDetails {
571         fn drop(&mut self) {
572                 if self.is_owned && !<*mut nativeChannelDetails>::is_null(self.inner) {
573                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
574                 }
575         }
576 }
577 /// Frees any resources used by the ChannelDetails, if is_owned is set and inner is non-NULL.
578 #[no_mangle]
579 pub extern "C" fn ChannelDetails_free(this_obj: ChannelDetails) { }
580 #[allow(unused)]
581 /// Used only if an object of this type is returned as a trait impl by a method
582 pub(crate) extern "C" fn ChannelDetails_free_void(this_ptr: *mut c_void) {
583         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelDetails); }
584 }
585 #[allow(unused)]
586 impl ChannelDetails {
587         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelDetails {
588                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
589         }
590         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelDetails {
591                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
592         }
593         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
594         pub(crate) fn take_inner(mut self) -> *mut nativeChannelDetails {
595                 assert!(self.is_owned);
596                 let ret = ObjOps::untweak_ptr(self.inner);
597                 self.inner = core::ptr::null_mut();
598                 ret
599         }
600 }
601 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
602 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
603 /// Note that this means this value is *not* persistent - it can change once during the
604 /// lifetime of the channel.
605 #[no_mangle]
606 pub extern "C" fn ChannelDetails_get_channel_id(this_ptr: &ChannelDetails) -> *const [u8; 32] {
607         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id;
608         inner_val
609 }
610 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
611 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
612 /// Note that this means this value is *not* persistent - it can change once during the
613 /// lifetime of the channel.
614 #[no_mangle]
615 pub extern "C" fn ChannelDetails_set_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::ThirtyTwoBytes) {
616         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = val.data;
617 }
618 /// Parameters which apply to our counterparty. See individual fields for more information.
619 #[no_mangle]
620 pub extern "C" fn ChannelDetails_get_counterparty(this_ptr: &ChannelDetails) -> crate::lightning::ln::channelmanager::ChannelCounterparty {
621         let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty;
622         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 }
623 }
624 /// Parameters which apply to our counterparty. See individual fields for more information.
625 #[no_mangle]
626 pub extern "C" fn ChannelDetails_set_counterparty(this_ptr: &mut ChannelDetails, mut val: crate::lightning::ln::channelmanager::ChannelCounterparty) {
627         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty = *unsafe { Box::from_raw(val.take_inner()) };
628 }
629 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
630 /// our counterparty already.
631 ///
632 /// Note that, if this has been set, `channel_id` will be equivalent to
633 /// `funding_txo.unwrap().to_channel_id()`.
634 ///
635 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
636 #[no_mangle]
637 pub extern "C" fn ChannelDetails_get_funding_txo(this_ptr: &ChannelDetails) -> crate::lightning::chain::transaction::OutPoint {
638         let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_txo;
639         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 };
640         local_inner_val
641 }
642 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
643 /// our counterparty already.
644 ///
645 /// Note that, if this has been set, `channel_id` will be equivalent to
646 /// `funding_txo.unwrap().to_channel_id()`.
647 ///
648 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
649 #[no_mangle]
650 pub extern "C" fn ChannelDetails_set_funding_txo(this_ptr: &mut ChannelDetails, mut val: crate::lightning::chain::transaction::OutPoint) {
651         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
652         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_txo = local_val;
653 }
654 /// The features which this channel operates with. See individual features for more info.
655 ///
656 /// `None` until negotiation completes and the channel type is finalized.
657 ///
658 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
659 #[no_mangle]
660 pub extern "C" fn ChannelDetails_get_channel_type(this_ptr: &ChannelDetails) -> crate::lightning::ln::features::ChannelTypeFeatures {
661         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_type;
662         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 };
663         local_inner_val
664 }
665 /// The features which this channel operates with. See individual features for more info.
666 ///
667 /// `None` until negotiation completes and the channel type is finalized.
668 ///
669 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
670 #[no_mangle]
671 pub extern "C" fn ChannelDetails_set_channel_type(this_ptr: &mut ChannelDetails, mut val: crate::lightning::ln::features::ChannelTypeFeatures) {
672         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
673         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_type = local_val;
674 }
675 /// The position of the funding transaction in the chain. None if the funding transaction has
676 /// not yet been confirmed and the channel fully opened.
677 ///
678 /// Note that if [`inbound_scid_alias`] is set, it must be used for invoices and inbound
679 /// payments instead of this. See [`get_inbound_payment_scid`].
680 ///
681 /// For channels with [`confirmations_required`] set to `Some(0)`, [`outbound_scid_alias`] may
682 /// be used in place of this in outbound routes. See [`get_outbound_payment_scid`].
683 ///
684 /// [`inbound_scid_alias`]: Self::inbound_scid_alias
685 /// [`outbound_scid_alias`]: Self::outbound_scid_alias
686 /// [`get_inbound_payment_scid`]: Self::get_inbound_payment_scid
687 /// [`get_outbound_payment_scid`]: Self::get_outbound_payment_scid
688 /// [`confirmations_required`]: Self::confirmations_required
689 #[no_mangle]
690 pub extern "C" fn ChannelDetails_get_short_channel_id(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
691         let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
692         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() }) };
693         local_inner_val
694 }
695 /// The position of the funding transaction in the chain. None if the funding transaction has
696 /// not yet been confirmed and the channel fully opened.
697 ///
698 /// Note that if [`inbound_scid_alias`] is set, it must be used for invoices and inbound
699 /// payments instead of this. See [`get_inbound_payment_scid`].
700 ///
701 /// For channels with [`confirmations_required`] set to `Some(0)`, [`outbound_scid_alias`] may
702 /// be used in place of this in outbound routes. See [`get_outbound_payment_scid`].
703 ///
704 /// [`inbound_scid_alias`]: Self::inbound_scid_alias
705 /// [`outbound_scid_alias`]: Self::outbound_scid_alias
706 /// [`get_inbound_payment_scid`]: Self::get_inbound_payment_scid
707 /// [`get_outbound_payment_scid`]: Self::get_outbound_payment_scid
708 /// [`confirmations_required`]: Self::confirmations_required
709 #[no_mangle]
710 pub extern "C" fn ChannelDetails_set_short_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
711         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
712         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = local_val;
713 }
714 /// An optional [`short_channel_id`] alias for this channel, randomly generated by us and
715 /// usable in place of [`short_channel_id`] to reference the channel in outbound routes when
716 /// the channel has not yet been confirmed (as long as [`confirmations_required`] is
717 /// `Some(0)`).
718 ///
719 /// This will be `None` as long as the channel is not available for routing outbound payments.
720 ///
721 /// [`short_channel_id`]: Self::short_channel_id
722 /// [`confirmations_required`]: Self::confirmations_required
723 #[no_mangle]
724 pub extern "C" fn ChannelDetails_get_outbound_scid_alias(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
725         let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_scid_alias;
726         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() }) };
727         local_inner_val
728 }
729 /// An optional [`short_channel_id`] alias for this channel, randomly generated by us and
730 /// usable in place of [`short_channel_id`] to reference the channel in outbound routes when
731 /// the channel has not yet been confirmed (as long as [`confirmations_required`] is
732 /// `Some(0)`).
733 ///
734 /// This will be `None` as long as the channel is not available for routing outbound payments.
735 ///
736 /// [`short_channel_id`]: Self::short_channel_id
737 /// [`confirmations_required`]: Self::confirmations_required
738 #[no_mangle]
739 pub extern "C" fn ChannelDetails_set_outbound_scid_alias(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
740         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
741         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_scid_alias = local_val;
742 }
743 /// An optional [`short_channel_id`] alias for this channel, randomly generated by our
744 /// counterparty and usable in place of [`short_channel_id`] in invoice route hints. Our
745 /// counterparty will recognize the alias provided here in place of the [`short_channel_id`]
746 /// when they see a payment to be routed to us.
747 ///
748 /// Our counterparty may choose to rotate this value at any time, though will always recognize
749 /// previous values for inbound payment forwarding.
750 ///
751 /// [`short_channel_id`]: Self::short_channel_id
752 #[no_mangle]
753 pub extern "C" fn ChannelDetails_get_inbound_scid_alias(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
754         let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_scid_alias;
755         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() }) };
756         local_inner_val
757 }
758 /// An optional [`short_channel_id`] alias for this channel, randomly generated by our
759 /// counterparty and usable in place of [`short_channel_id`] in invoice route hints. Our
760 /// counterparty will recognize the alias provided here in place of the [`short_channel_id`]
761 /// when they see a payment to be routed to us.
762 ///
763 /// Our counterparty may choose to rotate this value at any time, though will always recognize
764 /// previous values for inbound payment forwarding.
765 ///
766 /// [`short_channel_id`]: Self::short_channel_id
767 #[no_mangle]
768 pub extern "C" fn ChannelDetails_set_inbound_scid_alias(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
769         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
770         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_scid_alias = local_val;
771 }
772 /// The value, in satoshis, of this channel as appears in the funding output
773 #[no_mangle]
774 pub extern "C" fn ChannelDetails_get_channel_value_satoshis(this_ptr: &ChannelDetails) -> u64 {
775         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
776         *inner_val
777 }
778 /// The value, in satoshis, of this channel as appears in the funding output
779 #[no_mangle]
780 pub extern "C" fn ChannelDetails_set_channel_value_satoshis(this_ptr: &mut ChannelDetails, mut val: u64) {
781         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
782 }
783 /// The value, in satoshis, that must always be held in the channel for us. This value ensures
784 /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
785 /// this value on chain.
786 ///
787 /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
788 ///
789 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
790 ///
791 /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
792 #[no_mangle]
793 pub extern "C" fn ChannelDetails_get_unspendable_punishment_reserve(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
794         let mut inner_val = &mut this_ptr.get_native_mut_ref().unspendable_punishment_reserve;
795         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() }) };
796         local_inner_val
797 }
798 /// The value, in satoshis, that must always be held in the channel for us. This value ensures
799 /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
800 /// this value on chain.
801 ///
802 /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
803 ///
804 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
805 ///
806 /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
807 #[no_mangle]
808 pub extern "C" fn ChannelDetails_set_unspendable_punishment_reserve(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
809         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
810         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = local_val;
811 }
812 /// The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound.
813 #[no_mangle]
814 pub extern "C" fn ChannelDetails_get_user_channel_id(this_ptr: &ChannelDetails) -> u64 {
815         let mut inner_val = &mut this_ptr.get_native_mut_ref().user_channel_id;
816         *inner_val
817 }
818 /// The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound.
819 #[no_mangle]
820 pub extern "C" fn ChannelDetails_set_user_channel_id(this_ptr: &mut ChannelDetails, mut val: u64) {
821         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.user_channel_id = val;
822 }
823 /// Our total balance.  This is the amount we would get if we close the channel.
824 /// This value is not exact. Due to various in-flight changes and feerate changes, exactly this
825 /// amount is not likely to be recoverable on close.
826 ///
827 /// This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose
828 /// balance is not available for inclusion in new outbound HTLCs). This further does not include
829 /// any pending outgoing HTLCs which are awaiting some other resolution to be sent.
830 /// This does not consider any on-chain fees.
831 ///
832 /// See also [`ChannelDetails::outbound_capacity_msat`]
833 #[no_mangle]
834 pub extern "C" fn ChannelDetails_get_balance_msat(this_ptr: &ChannelDetails) -> u64 {
835         let mut inner_val = &mut this_ptr.get_native_mut_ref().balance_msat;
836         *inner_val
837 }
838 /// Our total balance.  This is the amount we would get if we close the channel.
839 /// This value is not exact. Due to various in-flight changes and feerate changes, exactly this
840 /// amount is not likely to be recoverable on close.
841 ///
842 /// This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose
843 /// balance is not available for inclusion in new outbound HTLCs). This further does not include
844 /// any pending outgoing HTLCs which are awaiting some other resolution to be sent.
845 /// This does not consider any on-chain fees.
846 ///
847 /// See also [`ChannelDetails::outbound_capacity_msat`]
848 #[no_mangle]
849 pub extern "C" fn ChannelDetails_set_balance_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
850         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.balance_msat = val;
851 }
852 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
853 /// any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
854 /// available for inclusion in new outbound HTLCs). This further does not include any pending
855 /// outgoing HTLCs which are awaiting some other resolution to be sent.
856 ///
857 /// See also [`ChannelDetails::balance_msat`]
858 ///
859 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
860 /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
861 /// should be able to spend nearly this amount.
862 #[no_mangle]
863 pub extern "C" fn ChannelDetails_get_outbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
864         let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_capacity_msat;
865         *inner_val
866 }
867 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
868 /// any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
869 /// available for inclusion in new outbound HTLCs). This further does not include any pending
870 /// outgoing HTLCs which are awaiting some other resolution to be sent.
871 ///
872 /// See also [`ChannelDetails::balance_msat`]
873 ///
874 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
875 /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
876 /// should be able to spend nearly this amount.
877 #[no_mangle]
878 pub extern "C" fn ChannelDetails_set_outbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
879         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_capacity_msat = val;
880 }
881 /// The available outbound capacity for sending a single HTLC to the remote peer. This is
882 /// similar to [`ChannelDetails::outbound_capacity_msat`] but it may be further restricted by
883 /// the current state and per-HTLC limit(s). This is intended for use when routing, allowing us
884 /// to use a limit as close as possible to the HTLC limit we can currently send.
885 ///
886 /// See also [`ChannelDetails::balance_msat`] and [`ChannelDetails::outbound_capacity_msat`].
887 #[no_mangle]
888 pub extern "C" fn ChannelDetails_get_next_outbound_htlc_limit_msat(this_ptr: &ChannelDetails) -> u64 {
889         let mut inner_val = &mut this_ptr.get_native_mut_ref().next_outbound_htlc_limit_msat;
890         *inner_val
891 }
892 /// The available outbound capacity for sending a single HTLC to the remote peer. This is
893 /// similar to [`ChannelDetails::outbound_capacity_msat`] but it may be further restricted by
894 /// the current state and per-HTLC limit(s). This is intended for use when routing, allowing us
895 /// to use a limit as close as possible to the HTLC limit we can currently send.
896 ///
897 /// See also [`ChannelDetails::balance_msat`] and [`ChannelDetails::outbound_capacity_msat`].
898 #[no_mangle]
899 pub extern "C" fn ChannelDetails_set_next_outbound_htlc_limit_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
900         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.next_outbound_htlc_limit_msat = val;
901 }
902 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
903 /// include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
904 /// available for inclusion in new inbound HTLCs).
905 /// Note that there are some corner cases not fully handled here, so the actual available
906 /// inbound capacity may be slightly higher than this.
907 ///
908 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
909 /// counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
910 /// However, our counterparty should be able to spend nearly this amount.
911 #[no_mangle]
912 pub extern "C" fn ChannelDetails_get_inbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
913         let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_capacity_msat;
914         *inner_val
915 }
916 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
917 /// include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
918 /// available for inclusion in new inbound HTLCs).
919 /// Note that there are some corner cases not fully handled here, so the actual available
920 /// inbound capacity may be slightly higher than this.
921 ///
922 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
923 /// counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
924 /// However, our counterparty should be able to spend nearly this amount.
925 #[no_mangle]
926 pub extern "C" fn ChannelDetails_set_inbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
927         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_capacity_msat = val;
928 }
929 /// The number of required confirmations on the funding transaction before the funding will be
930 /// considered \"locked\". This number is selected by the channel fundee (i.e. us if
931 /// [`is_outbound`] is *not* set), and can be selected for inbound channels with
932 /// [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
933 /// [`ChannelHandshakeLimits::max_minimum_depth`].
934 ///
935 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
936 ///
937 /// [`is_outbound`]: ChannelDetails::is_outbound
938 /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
939 /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
940 #[no_mangle]
941 pub extern "C" fn ChannelDetails_get_confirmations_required(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u32Z {
942         let mut inner_val = &mut this_ptr.get_native_mut_ref().confirmations_required;
943         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() }) };
944         local_inner_val
945 }
946 /// The number of required confirmations on the funding transaction before the funding will be
947 /// considered \"locked\". This number is selected by the channel fundee (i.e. us if
948 /// [`is_outbound`] is *not* set), and can be selected for inbound channels with
949 /// [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
950 /// [`ChannelHandshakeLimits::max_minimum_depth`].
951 ///
952 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
953 ///
954 /// [`is_outbound`]: ChannelDetails::is_outbound
955 /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
956 /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
957 #[no_mangle]
958 pub extern "C" fn ChannelDetails_set_confirmations_required(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u32Z) {
959         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
960         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.confirmations_required = local_val;
961 }
962 /// The number of blocks (after our commitment transaction confirms) that we will need to wait
963 /// until we can claim our funds after we force-close the channel. During this time our
964 /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
965 /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any
966 /// time to claim our non-HTLC-encumbered funds.
967 ///
968 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
969 #[no_mangle]
970 pub extern "C" fn ChannelDetails_get_force_close_spend_delay(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u16Z {
971         let mut inner_val = &mut this_ptr.get_native_mut_ref().force_close_spend_delay;
972         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() }) };
973         local_inner_val
974 }
975 /// The number of blocks (after our commitment transaction confirms) that we will need to wait
976 /// until we can claim our funds after we force-close the channel. During this time our
977 /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
978 /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any
979 /// time to claim our non-HTLC-encumbered funds.
980 ///
981 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
982 #[no_mangle]
983 pub extern "C" fn ChannelDetails_set_force_close_spend_delay(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u16Z) {
984         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
985         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.force_close_spend_delay = local_val;
986 }
987 /// True if the channel was initiated (and thus funded) by us.
988 #[no_mangle]
989 pub extern "C" fn ChannelDetails_get_is_outbound(this_ptr: &ChannelDetails) -> bool {
990         let mut inner_val = &mut this_ptr.get_native_mut_ref().is_outbound;
991         *inner_val
992 }
993 /// True if the channel was initiated (and thus funded) by us.
994 #[no_mangle]
995 pub extern "C" fn ChannelDetails_set_is_outbound(this_ptr: &mut ChannelDetails, mut val: bool) {
996         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_outbound = val;
997 }
998 /// True if the channel is confirmed, channel_ready messages have been exchanged, and the
999 /// channel is not currently being shut down. `channel_ready` message exchange implies the
1000 /// required confirmation count has been reached (and we were connected to the peer at some
1001 /// point after the funding transaction received enough confirmations). The required
1002 /// confirmation count is provided in [`confirmations_required`].
1003 ///
1004 /// [`confirmations_required`]: ChannelDetails::confirmations_required
1005 #[no_mangle]
1006 pub extern "C" fn ChannelDetails_get_is_channel_ready(this_ptr: &ChannelDetails) -> bool {
1007         let mut inner_val = &mut this_ptr.get_native_mut_ref().is_channel_ready;
1008         *inner_val
1009 }
1010 /// True if the channel is confirmed, channel_ready messages have been exchanged, and the
1011 /// channel is not currently being shut down. `channel_ready` message exchange implies the
1012 /// required confirmation count has been reached (and we were connected to the peer at some
1013 /// point after the funding transaction received enough confirmations). The required
1014 /// confirmation count is provided in [`confirmations_required`].
1015 ///
1016 /// [`confirmations_required`]: ChannelDetails::confirmations_required
1017 #[no_mangle]
1018 pub extern "C" fn ChannelDetails_set_is_channel_ready(this_ptr: &mut ChannelDetails, mut val: bool) {
1019         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_channel_ready = val;
1020 }
1021 /// True if the channel is (a) confirmed and channel_ready messages have been exchanged, (b)
1022 /// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
1023 ///
1024 /// This is a strict superset of `is_channel_ready`.
1025 #[no_mangle]
1026 pub extern "C" fn ChannelDetails_get_is_usable(this_ptr: &ChannelDetails) -> bool {
1027         let mut inner_val = &mut this_ptr.get_native_mut_ref().is_usable;
1028         *inner_val
1029 }
1030 /// True if the channel is (a) confirmed and channel_ready messages have been exchanged, (b)
1031 /// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
1032 ///
1033 /// This is a strict superset of `is_channel_ready`.
1034 #[no_mangle]
1035 pub extern "C" fn ChannelDetails_set_is_usable(this_ptr: &mut ChannelDetails, mut val: bool) {
1036         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_usable = val;
1037 }
1038 /// True if this channel is (or will be) publicly-announced.
1039 #[no_mangle]
1040 pub extern "C" fn ChannelDetails_get_is_public(this_ptr: &ChannelDetails) -> bool {
1041         let mut inner_val = &mut this_ptr.get_native_mut_ref().is_public;
1042         *inner_val
1043 }
1044 /// True if this channel is (or will be) publicly-announced.
1045 #[no_mangle]
1046 pub extern "C" fn ChannelDetails_set_is_public(this_ptr: &mut ChannelDetails, mut val: bool) {
1047         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_public = val;
1048 }
1049 /// The smallest value HTLC (in msat) we will accept, for this channel. This field
1050 /// is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.107
1051 #[no_mangle]
1052 pub extern "C" fn ChannelDetails_get_inbound_htlc_minimum_msat(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
1053         let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_htlc_minimum_msat;
1054         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() }) };
1055         local_inner_val
1056 }
1057 /// The smallest value HTLC (in msat) we will accept, for this channel. This field
1058 /// is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.107
1059 #[no_mangle]
1060 pub extern "C" fn ChannelDetails_set_inbound_htlc_minimum_msat(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
1061         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1062         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_htlc_minimum_msat = local_val;
1063 }
1064 /// The largest value HTLC (in msat) we currently will accept, for this channel.
1065 #[no_mangle]
1066 pub extern "C" fn ChannelDetails_get_inbound_htlc_maximum_msat(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
1067         let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_htlc_maximum_msat;
1068         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() }) };
1069         local_inner_val
1070 }
1071 /// The largest value HTLC (in msat) we currently will accept, for this channel.
1072 #[no_mangle]
1073 pub extern "C" fn ChannelDetails_set_inbound_htlc_maximum_msat(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
1074         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1075         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_htlc_maximum_msat = local_val;
1076 }
1077 /// Constructs a new ChannelDetails given each field
1078 #[must_use]
1079 #[no_mangle]
1080 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: u64, mut balance_msat_arg: u64, mut outbound_capacity_msat_arg: u64, mut next_outbound_htlc_limit_msat_arg: u64, mut inbound_capacity_msat_arg: u64, mut confirmations_required_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 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) -> ChannelDetails {
1081         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()) } }) };
1082         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()) } }) };
1083         let mut local_short_channel_id_arg = if short_channel_id_arg.is_some() { Some( { short_channel_id_arg.take() }) } else { None };
1084         let mut local_outbound_scid_alias_arg = if outbound_scid_alias_arg.is_some() { Some( { outbound_scid_alias_arg.take() }) } else { None };
1085         let mut local_inbound_scid_alias_arg = if inbound_scid_alias_arg.is_some() { Some( { inbound_scid_alias_arg.take() }) } else { None };
1086         let mut local_unspendable_punishment_reserve_arg = if unspendable_punishment_reserve_arg.is_some() { Some( { unspendable_punishment_reserve_arg.take() }) } else { None };
1087         let mut local_confirmations_required_arg = if confirmations_required_arg.is_some() { Some( { confirmations_required_arg.take() }) } else { None };
1088         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 };
1089         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 };
1090         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 };
1091         ChannelDetails { inner: ObjOps::heap_alloc(nativeChannelDetails {
1092                 channel_id: channel_id_arg.data,
1093                 counterparty: *unsafe { Box::from_raw(counterparty_arg.take_inner()) },
1094                 funding_txo: local_funding_txo_arg,
1095                 channel_type: local_channel_type_arg,
1096                 short_channel_id: local_short_channel_id_arg,
1097                 outbound_scid_alias: local_outbound_scid_alias_arg,
1098                 inbound_scid_alias: local_inbound_scid_alias_arg,
1099                 channel_value_satoshis: channel_value_satoshis_arg,
1100                 unspendable_punishment_reserve: local_unspendable_punishment_reserve_arg,
1101                 user_channel_id: user_channel_id_arg,
1102                 balance_msat: balance_msat_arg,
1103                 outbound_capacity_msat: outbound_capacity_msat_arg,
1104                 next_outbound_htlc_limit_msat: next_outbound_htlc_limit_msat_arg,
1105                 inbound_capacity_msat: inbound_capacity_msat_arg,
1106                 confirmations_required: local_confirmations_required_arg,
1107                 force_close_spend_delay: local_force_close_spend_delay_arg,
1108                 is_outbound: is_outbound_arg,
1109                 is_channel_ready: is_channel_ready_arg,
1110                 is_usable: is_usable_arg,
1111                 is_public: is_public_arg,
1112                 inbound_htlc_minimum_msat: local_inbound_htlc_minimum_msat_arg,
1113                 inbound_htlc_maximum_msat: local_inbound_htlc_maximum_msat_arg,
1114         }), is_owned: true }
1115 }
1116 impl Clone for ChannelDetails {
1117         fn clone(&self) -> Self {
1118                 Self {
1119                         inner: if <*mut nativeChannelDetails>::is_null(self.inner) { core::ptr::null_mut() } else {
1120                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1121                         is_owned: true,
1122                 }
1123         }
1124 }
1125 #[allow(unused)]
1126 /// Used only if an object of this type is returned as a trait impl by a method
1127 pub(crate) extern "C" fn ChannelDetails_clone_void(this_ptr: *const c_void) -> *mut c_void {
1128         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelDetails)).clone() })) as *mut c_void
1129 }
1130 #[no_mangle]
1131 /// Creates a copy of the ChannelDetails
1132 pub extern "C" fn ChannelDetails_clone(orig: &ChannelDetails) -> ChannelDetails {
1133         orig.clone()
1134 }
1135 /// Gets the current SCID which should be used to identify this channel for inbound payments.
1136 /// This should be used for providing invoice hints or in any other context where our
1137 /// counterparty will forward a payment to us.
1138 ///
1139 /// This is either the [`ChannelDetails::inbound_scid_alias`], if set, or the
1140 /// [`ChannelDetails::short_channel_id`]. See those for more information.
1141 #[must_use]
1142 #[no_mangle]
1143 pub extern "C" fn ChannelDetails_get_inbound_payment_scid(this_arg: &crate::lightning::ln::channelmanager::ChannelDetails) -> crate::c_types::derived::COption_u64Z {
1144         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_inbound_payment_scid();
1145         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() }) };
1146         local_ret
1147 }
1148
1149 /// Gets the current SCID which should be used to identify this channel for outbound payments.
1150 /// This should be used in [`Route`]s to describe the first hop or in other contexts where
1151 /// we're sending or forwarding a payment outbound over this channel.
1152 ///
1153 /// This is either the [`ChannelDetails::short_channel_id`], if set, or the
1154 /// [`ChannelDetails::outbound_scid_alias`]. See those for more information.
1155 #[must_use]
1156 #[no_mangle]
1157 pub extern "C" fn ChannelDetails_get_outbound_payment_scid(this_arg: &crate::lightning::ln::channelmanager::ChannelDetails) -> crate::c_types::derived::COption_u64Z {
1158         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_outbound_payment_scid();
1159         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() }) };
1160         local_ret
1161 }
1162
1163 /// If a payment fails to send, it can be in one of several states. This enum is returned as the
1164 /// Err() type describing which state the payment is in, see the description of individual enum
1165 /// states for more.
1166 #[derive(Clone)]
1167 #[must_use]
1168 #[repr(C)]
1169 pub enum PaymentSendFailure {
1170         /// A parameter which was passed to send_payment was invalid, preventing us from attempting to
1171         /// send the payment at all. No channel state has been changed or messages sent to peers, and
1172         /// once you've changed the parameter at error, you can freely retry the payment in full.
1173         ParameterError(crate::lightning::util::errors::APIError),
1174         /// A parameter in a single path which was passed to send_payment was invalid, preventing us
1175         /// from attempting to send the payment at all. No channel state has been changed or messages
1176         /// sent to peers, and once you've changed the parameter at error, you can freely retry the
1177         /// payment in full.
1178         ///
1179         /// The results here are ordered the same as the paths in the route object which was passed to
1180         /// send_payment.
1181         PathParameterError(crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ),
1182         /// All paths which were attempted failed to send, with no channel state change taking place.
1183         /// You can freely retry the payment in full (though you probably want to do so over different
1184         /// paths than the ones selected).
1185         AllFailedRetrySafe(crate::c_types::derived::CVec_APIErrorZ),
1186         /// Some paths which were attempted failed to send, though possibly not all. At least some
1187         /// paths have irrevocably committed to the HTLC and retrying the payment in full would result
1188         /// in over-/re-payment.
1189         ///
1190         /// The results here are ordered the same as the paths in the route object which was passed to
1191         /// send_payment, and any Errs which are not APIError::MonitorUpdateFailed can be safely
1192         /// retried (though there is currently no API with which to do so).
1193         ///
1194         /// Any entries which contain Err(APIError::MonitorUpdateFailed) or Ok(()) MUST NOT be retried
1195         /// as they will result in over-/re-payment. These HTLCs all either successfully sent (in the
1196         /// case of Ok(())) or will send once channel_monitor_updated is called on the next-hop channel
1197         /// with the latest update_id.
1198         PartialFailure {
1199                 /// The errors themselves, in the same order as the route hops.
1200                 results: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ,
1201                 /// If some paths failed without irrevocably committing to the new HTLC(s), this will
1202                 /// contain a [`RouteParameters`] object which can be used to calculate a new route that
1203                 /// will pay all remaining unpaid balance.
1204                 ///
1205                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1206                 failed_paths_retry: crate::lightning::routing::router::RouteParameters,
1207                 /// The payment id for the payment, which is now at least partially pending.
1208                 payment_id: crate::c_types::ThirtyTwoBytes,
1209         },
1210 }
1211 use lightning::ln::channelmanager::PaymentSendFailure as PaymentSendFailureImport;
1212 pub(crate) type nativePaymentSendFailure = PaymentSendFailureImport;
1213
1214 impl PaymentSendFailure {
1215         #[allow(unused)]
1216         pub(crate) fn to_native(&self) -> nativePaymentSendFailure {
1217                 match self {
1218                         PaymentSendFailure::ParameterError (ref a, ) => {
1219                                 let mut a_nonref = (*a).clone();
1220                                 nativePaymentSendFailure::ParameterError (
1221                                         a_nonref.into_native(),
1222                                 )
1223                         },
1224                         PaymentSendFailure::PathParameterError (ref a, ) => {
1225                                 let mut a_nonref = (*a).clone();
1226                                 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { let mut local_a_nonref_0 = match item.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.err)) }).into_native() })}; local_a_nonref_0 }); };
1227                                 nativePaymentSendFailure::PathParameterError (
1228                                         local_a_nonref,
1229                                 )
1230                         },
1231                         PaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
1232                                 let mut a_nonref = (*a).clone();
1233                                 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { item.into_native() }); };
1234                                 nativePaymentSendFailure::AllFailedRetrySafe (
1235                                         local_a_nonref,
1236                                 )
1237                         },
1238                         PaymentSendFailure::PartialFailure {ref results, ref failed_paths_retry, ref payment_id, } => {
1239                                 let mut results_nonref = (*results).clone();
1240                                 let mut local_results_nonref = Vec::new(); for mut item in results_nonref.into_rust().drain(..) { local_results_nonref.push( { let mut local_results_nonref_0 = match item.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.err)) }).into_native() })}; local_results_nonref_0 }); };
1241                                 let mut failed_paths_retry_nonref = (*failed_paths_retry).clone();
1242                                 let mut local_failed_paths_retry_nonref = if failed_paths_retry_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(failed_paths_retry_nonref.take_inner()) } }) };
1243                                 let mut payment_id_nonref = (*payment_id).clone();
1244                                 nativePaymentSendFailure::PartialFailure {
1245                                         results: local_results_nonref,
1246                                         failed_paths_retry: local_failed_paths_retry_nonref,
1247                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1248                                 }
1249                         },
1250                 }
1251         }
1252         #[allow(unused)]
1253         pub(crate) fn into_native(self) -> nativePaymentSendFailure {
1254                 match self {
1255                         PaymentSendFailure::ParameterError (mut a, ) => {
1256                                 nativePaymentSendFailure::ParameterError (
1257                                         a.into_native(),
1258                                 )
1259                         },
1260                         PaymentSendFailure::PathParameterError (mut a, ) => {
1261                                 let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { let mut local_a_0 = match item.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.err)) }).into_native() })}; local_a_0 }); };
1262                                 nativePaymentSendFailure::PathParameterError (
1263                                         local_a,
1264                                 )
1265                         },
1266                         PaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
1267                                 let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { item.into_native() }); };
1268                                 nativePaymentSendFailure::AllFailedRetrySafe (
1269                                         local_a,
1270                                 )
1271                         },
1272                         PaymentSendFailure::PartialFailure {mut results, mut failed_paths_retry, mut payment_id, } => {
1273                                 let mut local_results = Vec::new(); for mut item in results.into_rust().drain(..) { local_results.push( { let mut local_results_0 = match item.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.err)) }).into_native() })}; local_results_0 }); };
1274                                 let mut local_failed_paths_retry = if failed_paths_retry.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(failed_paths_retry.take_inner()) } }) };
1275                                 nativePaymentSendFailure::PartialFailure {
1276                                         results: local_results,
1277                                         failed_paths_retry: local_failed_paths_retry,
1278                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1279                                 }
1280                         },
1281                 }
1282         }
1283         #[allow(unused)]
1284         pub(crate) fn from_native(native: &nativePaymentSendFailure) -> Self {
1285                 match native {
1286                         nativePaymentSendFailure::ParameterError (ref a, ) => {
1287                                 let mut a_nonref = (*a).clone();
1288                                 PaymentSendFailure::ParameterError (
1289                                         crate::lightning::util::errors::APIError::native_into(a_nonref),
1290                                 )
1291                         },
1292                         nativePaymentSendFailure::PathParameterError (ref a, ) => {
1293                                 let mut a_nonref = (*a).clone();
1294                                 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.drain(..) { local_a_nonref.push( { let mut local_a_nonref_0 = match item { 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() }; local_a_nonref_0 }); };
1295                                 PaymentSendFailure::PathParameterError (
1296                                         local_a_nonref.into(),
1297                                 )
1298                         },
1299                         nativePaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
1300                                 let mut a_nonref = (*a).clone();
1301                                 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.drain(..) { local_a_nonref.push( { crate::lightning::util::errors::APIError::native_into(item) }); };
1302                                 PaymentSendFailure::AllFailedRetrySafe (
1303                                         local_a_nonref.into(),
1304                                 )
1305                         },
1306                         nativePaymentSendFailure::PartialFailure {ref results, ref failed_paths_retry, ref payment_id, } => {
1307                                 let mut results_nonref = (*results).clone();
1308                                 let mut local_results_nonref = Vec::new(); for mut item in results_nonref.drain(..) { local_results_nonref.push( { let mut local_results_nonref_0 = match item { 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() }; local_results_nonref_0 }); };
1309                                 let mut failed_paths_retry_nonref = (*failed_paths_retry).clone();
1310                                 let mut local_failed_paths_retry_nonref = crate::lightning::routing::router::RouteParameters { inner: if failed_paths_retry_nonref.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((failed_paths_retry_nonref.unwrap())) } }, is_owned: true };
1311                                 let mut payment_id_nonref = (*payment_id).clone();
1312                                 PaymentSendFailure::PartialFailure {
1313                                         results: local_results_nonref.into(),
1314                                         failed_paths_retry: local_failed_paths_retry_nonref,
1315                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1316                                 }
1317                         },
1318                 }
1319         }
1320         #[allow(unused)]
1321         pub(crate) fn native_into(native: nativePaymentSendFailure) -> Self {
1322                 match native {
1323                         nativePaymentSendFailure::ParameterError (mut a, ) => {
1324                                 PaymentSendFailure::ParameterError (
1325                                         crate::lightning::util::errors::APIError::native_into(a),
1326                                 )
1327                         },
1328                         nativePaymentSendFailure::PathParameterError (mut a, ) => {
1329                                 let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { let mut local_a_0 = match item { 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() }; local_a_0 }); };
1330                                 PaymentSendFailure::PathParameterError (
1331                                         local_a.into(),
1332                                 )
1333                         },
1334                         nativePaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
1335                                 let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { crate::lightning::util::errors::APIError::native_into(item) }); };
1336                                 PaymentSendFailure::AllFailedRetrySafe (
1337                                         local_a.into(),
1338                                 )
1339                         },
1340                         nativePaymentSendFailure::PartialFailure {mut results, mut failed_paths_retry, mut payment_id, } => {
1341                                 let mut local_results = Vec::new(); for mut item in results.drain(..) { local_results.push( { let mut local_results_0 = match item { 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() }; local_results_0 }); };
1342                                 let mut local_failed_paths_retry = crate::lightning::routing::router::RouteParameters { inner: if failed_paths_retry.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((failed_paths_retry.unwrap())) } }, is_owned: true };
1343                                 PaymentSendFailure::PartialFailure {
1344                                         results: local_results.into(),
1345                                         failed_paths_retry: local_failed_paths_retry,
1346                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1347                                 }
1348                         },
1349                 }
1350         }
1351 }
1352 /// Frees any resources used by the PaymentSendFailure
1353 #[no_mangle]
1354 pub extern "C" fn PaymentSendFailure_free(this_ptr: PaymentSendFailure) { }
1355 /// Creates a copy of the PaymentSendFailure
1356 #[no_mangle]
1357 pub extern "C" fn PaymentSendFailure_clone(orig: &PaymentSendFailure) -> PaymentSendFailure {
1358         orig.clone()
1359 }
1360 #[no_mangle]
1361 /// Utility method to constructs a new ParameterError-variant PaymentSendFailure
1362 pub extern "C" fn PaymentSendFailure_parameter_error(a: crate::lightning::util::errors::APIError) -> PaymentSendFailure {
1363         PaymentSendFailure::ParameterError(a, )
1364 }
1365 #[no_mangle]
1366 /// Utility method to constructs a new PathParameterError-variant PaymentSendFailure
1367 pub extern "C" fn PaymentSendFailure_path_parameter_error(a: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ) -> PaymentSendFailure {
1368         PaymentSendFailure::PathParameterError(a, )
1369 }
1370 #[no_mangle]
1371 /// Utility method to constructs a new AllFailedRetrySafe-variant PaymentSendFailure
1372 pub extern "C" fn PaymentSendFailure_all_failed_retry_safe(a: crate::c_types::derived::CVec_APIErrorZ) -> PaymentSendFailure {
1373         PaymentSendFailure::AllFailedRetrySafe(a, )
1374 }
1375 #[no_mangle]
1376 /// Utility method to constructs a new PartialFailure-variant PaymentSendFailure
1377 pub extern "C" fn PaymentSendFailure_partial_failure(results: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ, failed_paths_retry: crate::lightning::routing::router::RouteParameters, payment_id: crate::c_types::ThirtyTwoBytes) -> PaymentSendFailure {
1378         PaymentSendFailure::PartialFailure {
1379                 results,
1380                 failed_paths_retry,
1381                 payment_id,
1382         }
1383 }
1384
1385 use lightning::ln::channelmanager::PhantomRouteHints as nativePhantomRouteHintsImport;
1386 pub(crate) type nativePhantomRouteHints = nativePhantomRouteHintsImport;
1387
1388 /// Route hints used in constructing invoices for [phantom node payents].
1389 ///
1390 /// [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
1391 #[must_use]
1392 #[repr(C)]
1393 pub struct PhantomRouteHints {
1394         /// A pointer to the opaque Rust object.
1395
1396         /// Nearly everywhere, inner must be non-null, however in places where
1397         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1398         pub inner: *mut nativePhantomRouteHints,
1399         /// Indicates that this is the only struct which contains the same pointer.
1400
1401         /// Rust functions which take ownership of an object provided via an argument require
1402         /// this to be true and invalidate the object pointed to by inner.
1403         pub is_owned: bool,
1404 }
1405
1406 impl Drop for PhantomRouteHints {
1407         fn drop(&mut self) {
1408                 if self.is_owned && !<*mut nativePhantomRouteHints>::is_null(self.inner) {
1409                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1410                 }
1411         }
1412 }
1413 /// Frees any resources used by the PhantomRouteHints, if is_owned is set and inner is non-NULL.
1414 #[no_mangle]
1415 pub extern "C" fn PhantomRouteHints_free(this_obj: PhantomRouteHints) { }
1416 #[allow(unused)]
1417 /// Used only if an object of this type is returned as a trait impl by a method
1418 pub(crate) extern "C" fn PhantomRouteHints_free_void(this_ptr: *mut c_void) {
1419         unsafe { let _ = Box::from_raw(this_ptr as *mut nativePhantomRouteHints); }
1420 }
1421 #[allow(unused)]
1422 impl PhantomRouteHints {
1423         pub(crate) fn get_native_ref(&self) -> &'static nativePhantomRouteHints {
1424                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1425         }
1426         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePhantomRouteHints {
1427                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1428         }
1429         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1430         pub(crate) fn take_inner(mut self) -> *mut nativePhantomRouteHints {
1431                 assert!(self.is_owned);
1432                 let ret = ObjOps::untweak_ptr(self.inner);
1433                 self.inner = core::ptr::null_mut();
1434                 ret
1435         }
1436 }
1437 /// The list of channels to be included in the invoice route hints.
1438 #[no_mangle]
1439 pub extern "C" fn PhantomRouteHints_get_channels(this_ptr: &PhantomRouteHints) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1440         let mut inner_val = &mut this_ptr.get_native_mut_ref().channels;
1441         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 } }); };
1442         local_inner_val.into()
1443 }
1444 /// The list of channels to be included in the invoice route hints.
1445 #[no_mangle]
1446 pub extern "C" fn PhantomRouteHints_set_channels(this_ptr: &mut PhantomRouteHints, mut val: crate::c_types::derived::CVec_ChannelDetailsZ) {
1447         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1448         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val;
1449 }
1450 /// A fake scid used for representing the phantom node's fake channel in generating the invoice
1451 /// route hints.
1452 #[no_mangle]
1453 pub extern "C" fn PhantomRouteHints_get_phantom_scid(this_ptr: &PhantomRouteHints) -> u64 {
1454         let mut inner_val = &mut this_ptr.get_native_mut_ref().phantom_scid;
1455         *inner_val
1456 }
1457 /// A fake scid used for representing the phantom node's fake channel in generating the invoice
1458 /// route hints.
1459 #[no_mangle]
1460 pub extern "C" fn PhantomRouteHints_set_phantom_scid(this_ptr: &mut PhantomRouteHints, mut val: u64) {
1461         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.phantom_scid = val;
1462 }
1463 /// The pubkey of the real backing node that would ultimately receive the payment.
1464 #[no_mangle]
1465 pub extern "C" fn PhantomRouteHints_get_real_node_pubkey(this_ptr: &PhantomRouteHints) -> crate::c_types::PublicKey {
1466         let mut inner_val = &mut this_ptr.get_native_mut_ref().real_node_pubkey;
1467         crate::c_types::PublicKey::from_rust(&inner_val)
1468 }
1469 /// The pubkey of the real backing node that would ultimately receive the payment.
1470 #[no_mangle]
1471 pub extern "C" fn PhantomRouteHints_set_real_node_pubkey(this_ptr: &mut PhantomRouteHints, mut val: crate::c_types::PublicKey) {
1472         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.real_node_pubkey = val.into_rust();
1473 }
1474 /// Constructs a new PhantomRouteHints given each field
1475 #[must_use]
1476 #[no_mangle]
1477 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 {
1478         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()) } }); };
1479         PhantomRouteHints { inner: ObjOps::heap_alloc(nativePhantomRouteHints {
1480                 channels: local_channels_arg,
1481                 phantom_scid: phantom_scid_arg,
1482                 real_node_pubkey: real_node_pubkey_arg.into_rust(),
1483         }), is_owned: true }
1484 }
1485 impl Clone for PhantomRouteHints {
1486         fn clone(&self) -> Self {
1487                 Self {
1488                         inner: if <*mut nativePhantomRouteHints>::is_null(self.inner) { core::ptr::null_mut() } else {
1489                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1490                         is_owned: true,
1491                 }
1492         }
1493 }
1494 #[allow(unused)]
1495 /// Used only if an object of this type is returned as a trait impl by a method
1496 pub(crate) extern "C" fn PhantomRouteHints_clone_void(this_ptr: *const c_void) -> *mut c_void {
1497         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePhantomRouteHints)).clone() })) as *mut c_void
1498 }
1499 #[no_mangle]
1500 /// Creates a copy of the PhantomRouteHints
1501 pub extern "C" fn PhantomRouteHints_clone(orig: &PhantomRouteHints) -> PhantomRouteHints {
1502         orig.clone()
1503 }
1504 /// Constructs a new ChannelManager to hold several channels and route between them.
1505 ///
1506 /// This is the main \"logic hub\" for all channel-related actions, and implements
1507 /// ChannelMessageHandler.
1508 ///
1509 /// Non-proportional fees are fixed according to our risk using the provided fee estimator.
1510 ///
1511 /// Users need to notify the new ChannelManager when a new block is connected or
1512 /// disconnected using its `block_connected` and `block_disconnected` methods, starting
1513 /// from after `params.latest_hash`.
1514 #[must_use]
1515 #[no_mangle]
1516 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 logger: crate::lightning::util::logger::Logger, mut keys_manager: crate::lightning::chain::keysinterface::KeysInterface, mut config: crate::lightning::util::config::UserConfig, mut params: crate::lightning::ln::channelmanager::ChainParameters) -> crate::lightning::ln::channelmanager::ChannelManager {
1517         let mut ret = lightning::ln::channelmanager::ChannelManager::new(fee_est, chain_monitor, tx_broadcaster, logger, keys_manager, *unsafe { Box::from_raw(config.take_inner()) }, *unsafe { Box::from_raw(params.take_inner()) });
1518         crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
1519 }
1520
1521 /// Gets the current configuration applied to all new channels,  as
1522 #[must_use]
1523 #[no_mangle]
1524 pub extern "C" fn ChannelManager_get_current_default_configuration(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::util::config::UserConfig {
1525         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_current_default_configuration();
1526         crate::lightning::util::config::UserConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::util::config::UserConfig<>) as *mut _) }, is_owned: false }
1527 }
1528
1529 /// Creates a new outbound channel to the given remote node and with the given value.
1530 ///
1531 /// `user_channel_id` will be provided back as in
1532 /// [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
1533 /// correspond with which `create_channel` call. Note that the `user_channel_id` defaults to 0
1534 /// for inbound channels, so you may wish to avoid using 0 for `user_channel_id` here.
1535 /// `user_channel_id` has no meaning inside of LDK, it is simply copied to events and otherwise
1536 /// ignored.
1537 ///
1538 /// Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is
1539 /// greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`.
1540 ///
1541 /// Note that we do not check if you are currently connected to the given peer. If no
1542 /// connection is available, the outbound `open_channel` message may fail to send, resulting in
1543 /// the channel eventually being silently forgotten (dropped on reload).
1544 ///
1545 /// Returns the new Channel's temporary `channel_id`. This ID will appear as
1546 /// [`Event::FundingGenerationReady::temporary_channel_id`] and in
1547 /// [`ChannelDetails::channel_id`] until after
1548 /// [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
1549 /// one derived from the funding transaction's TXID. If the counterparty rejects the channel
1550 /// immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
1551 ///
1552 /// [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
1553 /// [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
1554 /// [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
1555 ///
1556 /// Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
1557 #[must_use]
1558 #[no_mangle]
1559 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: u64, mut override_config: crate::lightning::util::config::UserConfig) -> crate::c_types::derived::CResult__u832APIErrorZ {
1560         let mut local_override_config = if override_config.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(override_config.take_inner()) } }) };
1561         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, local_override_config);
1562         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() };
1563         local_ret
1564 }
1565
1566 /// Gets the list of open channels, in random order. See ChannelDetail field documentation for
1567 /// more information.
1568 #[must_use]
1569 #[no_mangle]
1570 pub extern "C" fn ChannelManager_list_channels(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1571         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_channels();
1572         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 } }); };
1573         local_ret.into()
1574 }
1575
1576 /// Gets the list of usable channels, in random order. Useful as an argument to [`find_route`]
1577 /// to ensure non-announced channels are used.
1578 ///
1579 /// These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
1580 /// documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
1581 /// are.
1582 ///
1583 /// [`find_route`]: crate::routing::router::find_route
1584 #[must_use]
1585 #[no_mangle]
1586 pub extern "C" fn ChannelManager_list_usable_channels(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1587         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_usable_channels();
1588         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 } }); };
1589         local_ret.into()
1590 }
1591
1592 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
1593 /// will be accepted on the given channel, and after additional timeout/the closing of all
1594 /// pending HTLCs, the channel will be closed on chain.
1595 ///
1596 ///  * If we are the channel initiator, we will pay between our [`Background`] and
1597 ///    [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
1598 ///    estimate.
1599 ///  * If our counterparty is the channel initiator, we will require a channel closing
1600 ///    transaction feerate of at least our [`Background`] feerate or the feerate which
1601 ///    would appear on a force-closure transaction, whichever is lower. We will allow our
1602 ///    counterparty to pay as much fee as they'd like, however.
1603 ///
1604 /// May generate a SendShutdown message event on success, which should be relayed.
1605 ///
1606 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
1607 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1608 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1609 #[must_use]
1610 #[no_mangle]
1611 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 {
1612         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel(unsafe { &*channel_id}, &counterparty_node_id.into_rust());
1613         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() };
1614         local_ret
1615 }
1616
1617 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
1618 /// will be accepted on the given channel, and after additional timeout/the closing of all
1619 /// pending HTLCs, the channel will be closed on chain.
1620 ///
1621 /// `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
1622 /// the channel being closed or not:
1623 ///  * If we are the channel initiator, we will pay at least this feerate on the closing
1624 ///    transaction. The upper-bound is set by
1625 ///    [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
1626 ///    estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
1627 ///  * If our counterparty is the channel initiator, we will refuse to accept a channel closure
1628 ///    transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
1629 ///    will appear on a force-closure transaction, whichever is lower).
1630 ///
1631 /// May generate a SendShutdown message event on success, which should be relayed.
1632 ///
1633 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
1634 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1635 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1636 #[must_use]
1637 #[no_mangle]
1638 pub extern "C" fn ChannelManager_close_channel_with_target_feerate(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: u32) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1639         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel_with_target_feerate(unsafe { &*channel_id}, &counterparty_node_id.into_rust(), target_feerate_sats_per_1000_weight);
1640         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() };
1641         local_ret
1642 }
1643
1644 /// Force closes a channel, immediately broadcasting the latest local commitment transaction to
1645 /// the chain and rejecting new HTLCs on the given channel. Fails if `channel_id` is unknown to
1646 /// the manager, or if the `counterparty_node_id` isn't the counterparty of the corresponding
1647 /// channel.
1648 #[must_use]
1649 #[no_mangle]
1650 pub extern "C" fn ChannelManager_force_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 {
1651         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_channel(unsafe { &*channel_id}, &counterparty_node_id.into_rust());
1652         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() };
1653         local_ret
1654 }
1655
1656 /// Force close all channels, immediately broadcasting the latest local commitment transaction
1657 /// for each to the chain and rejecting new HTLCs on each.
1658 #[no_mangle]
1659 pub extern "C" fn ChannelManager_force_close_all_channels(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
1660         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_all_channels()
1661 }
1662
1663 /// Sends a payment along a given route.
1664 ///
1665 /// Value parameters are provided via the last hop in route, see documentation for RouteHop
1666 /// fields for more info.
1667 ///
1668 /// Note that if the payment_hash already exists elsewhere (eg you're sending a duplicative
1669 /// payment), we don't do anything to stop you! We always try to ensure that if the provided
1670 /// next hop knows the preimage to payment_hash they can claim an additional amount as
1671 /// specified in the last hop in the route! Thus, you should probably do your own
1672 /// payment_preimage tracking (which you should already be doing as they represent \"proof of
1673 /// payment\") and prevent double-sends yourself.
1674 ///
1675 /// May generate SendHTLCs message(s) event on success, which should be relayed.
1676 ///
1677 /// Each path may have a different return value, and PaymentSendValue may return a Vec with
1678 /// each entry matching the corresponding-index entry in the route paths, see
1679 /// PaymentSendFailure for more info.
1680 ///
1681 /// In general, a path may raise:
1682 ///  * APIError::RouteError when an invalid route or forwarding parameter (cltv_delta, fee,
1683 ///    node public key) is specified.
1684 ///  * APIError::ChannelUnavailable if the next-hop channel is not available for updates
1685 ///    (including due to previous monitor update failure or new permanent monitor update
1686 ///    failure).
1687 ///  * APIError::MonitorUpdateFailed if a new monitor update failure prevented sending the
1688 ///    relevant updates.
1689 ///
1690 /// Note that depending on the type of the PaymentSendFailure the HTLC may have been
1691 /// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
1692 /// different route unless you intend to pay twice!
1693 ///
1694 /// payment_secret is unrelated to payment_hash (or PaymentPreimage) and exists to authenticate
1695 /// the sender to the recipient and prevent payment-probing (deanonymization) attacks. For
1696 /// newer nodes, it will be provided to you in the invoice. If you do not have one, the Route
1697 /// must not contain multiple paths as multi-path payments require a recipient-provided
1698 /// payment_secret.
1699 /// If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature
1700 /// bit set (either as required or as available). If multiple paths are present in the Route,
1701 /// we assume the invoice had the basic_mpp feature set.
1702 ///
1703 /// Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
1704 #[must_use]
1705 #[no_mangle]
1706 pub extern "C" fn ChannelManager_send_payment(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut payment_secret: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_PaymentIdPaymentSendFailureZ {
1707         let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentSecret(payment_secret.data) }) };
1708         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_payment(route.get_native_ref(), ::lightning::ln::PaymentHash(payment_hash.data), &local_payment_secret);
1709         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::channelmanager::PaymentSendFailure::native_into(e) }).into() };
1710         local_ret
1711 }
1712
1713 /// Retries a payment along the given [`Route`].
1714 ///
1715 /// Errors returned are a superset of those returned from [`send_payment`], so see
1716 /// [`send_payment`] documentation for more details on errors. This method will also error if the
1717 /// retry amount puts the payment more than 10% over the payment's total amount, if the payment
1718 /// for the given `payment_id` cannot be found (likely due to timeout or success), or if
1719 /// further retries have been disabled with [`abandon_payment`].
1720 ///
1721 /// [`send_payment`]: [`ChannelManager::send_payment`]
1722 /// [`abandon_payment`]: [`ChannelManager::abandon_payment`]
1723 #[must_use]
1724 #[no_mangle]
1725 pub extern "C" fn ChannelManager_retry_payment(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_NonePaymentSendFailureZ {
1726         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.retry_payment(route.get_native_ref(), ::lightning::ln::channelmanager::PaymentId(payment_id.data));
1727         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::channelmanager::PaymentSendFailure::native_into(e) }).into() };
1728         local_ret
1729 }
1730
1731 /// Signals that no further retries for the given payment will occur.
1732 ///
1733 /// After this method returns, any future calls to [`retry_payment`] for the given `payment_id`
1734 /// will fail with [`PaymentSendFailure::ParameterError`]. If no such event has been generated,
1735 /// an [`Event::PaymentFailed`] event will be generated as soon as there are no remaining
1736 /// pending HTLCs for this payment.
1737 ///
1738 /// Note that calling this method does *not* prevent a payment from succeeding. You must still
1739 /// wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to
1740 /// determine the ultimate status of a payment.
1741 ///
1742 /// [`retry_payment`]: Self::retry_payment
1743 /// [`Event::PaymentFailed`]: events::Event::PaymentFailed
1744 /// [`Event::PaymentSent`]: events::Event::PaymentSent
1745 #[no_mangle]
1746 pub extern "C" fn ChannelManager_abandon_payment(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_id: crate::c_types::ThirtyTwoBytes) {
1747         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.abandon_payment(::lightning::ln::channelmanager::PaymentId(payment_id.data))
1748 }
1749
1750 /// Send a spontaneous payment, which is a payment that does not require the recipient to have
1751 /// generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
1752 /// the preimage, it must be a cryptographically secure random value that no intermediate node
1753 /// would be able to guess -- otherwise, an intermediate node may claim the payment and it will
1754 /// never reach the recipient.
1755 ///
1756 /// See [`send_payment`] documentation for more details on the return value of this function.
1757 ///
1758 /// Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
1759 /// [`send_payment`] for more information about the risks of duplicate preimage usage.
1760 ///
1761 /// Note that `route` must have exactly one path.
1762 ///
1763 /// [`send_payment`]: Self::send_payment
1764 ///
1765 /// Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None
1766 #[must_use]
1767 #[no_mangle]
1768 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::ThirtyTwoBytes) -> crate::c_types::derived::CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ {
1769         let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
1770         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_spontaneous_payment(route.get_native_ref(), local_payment_preimage);
1771         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::channelmanager::PaymentSendFailure::native_into(e) }).into() };
1772         local_ret
1773 }
1774
1775 /// Call this upon creation of a funding transaction for the given channel.
1776 ///
1777 /// Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
1778 /// or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
1779 ///
1780 /// Returns [`APIError::ChannelUnavailable`] if a funding transaction has already been provided
1781 /// for the channel or if the channel has been closed as indicated by [`Event::ChannelClosed`].
1782 ///
1783 /// May panic if the output found in the funding transaction is duplicative with some other
1784 /// channel (note that this should be trivially prevented by using unique funding transaction
1785 /// keys per-channel).
1786 ///
1787 /// Do NOT broadcast the funding transaction yourself. When we have safely received our
1788 /// counterparty's signature the funding transaction will automatically be broadcast via the
1789 /// [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
1790 ///
1791 /// Note that this includes RBF or similar transaction replacement strategies - lightning does
1792 /// not currently support replacing a funding transaction on an existing channel. Instead,
1793 /// create a new channel with a conflicting funding transaction.
1794 ///
1795 /// [`Event::FundingGenerationReady`]: crate::util::events::Event::FundingGenerationReady
1796 /// [`Event::ChannelClosed`]: crate::util::events::Event::ChannelClosed
1797 #[must_use]
1798 #[no_mangle]
1799 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 {
1800         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());
1801         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() };
1802         local_ret
1803 }
1804
1805 /// Regenerates channel_announcements and generates a signed node_announcement from the given
1806 /// arguments, providing them in corresponding events via
1807 /// [`get_and_clear_pending_msg_events`], if at least one public channel has been confirmed
1808 /// on-chain. This effectively re-broadcasts all channel announcements and sends our node
1809 /// announcement to ensure that the lightning P2P network is aware of the channels we have and
1810 /// our network addresses.
1811 ///
1812 /// `rgb` is a node \"color\" and `alias` is a printable human-readable string to describe this
1813 /// node to humans. They carry no in-protocol meaning.
1814 ///
1815 /// `addresses` represent the set (possibly empty) of socket addresses on which this node
1816 /// accepts incoming connections. These will be included in the node_announcement, publicly
1817 /// tying these addresses together and to this node. If you wish to preserve user privacy,
1818 /// addresses should likely contain only Tor Onion addresses.
1819 ///
1820 /// Panics if `addresses` is absurdly large (more than 500).
1821 ///
1822 /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
1823 #[no_mangle]
1824 pub extern "C" fn ChannelManager_broadcast_node_announcement(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut rgb: crate::c_types::ThreeBytes, mut alias: crate::c_types::ThirtyTwoBytes, mut addresses: crate::c_types::derived::CVec_NetAddressZ) {
1825         let mut local_addresses = Vec::new(); for mut item in addresses.into_rust().drain(..) { local_addresses.push( { item.into_native() }); };
1826         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.broadcast_node_announcement(rgb.data, alias.data, local_addresses)
1827 }
1828
1829 /// Processes HTLCs which are pending waiting on random forward delay.
1830 ///
1831 /// Should only really ever be called in response to a PendingHTLCsForwardable event.
1832 /// Will likely generate further events.
1833 #[no_mangle]
1834 pub extern "C" fn ChannelManager_process_pending_htlc_forwards(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
1835         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_pending_htlc_forwards()
1836 }
1837
1838 /// Performs actions which should happen on startup and roughly once per minute thereafter.
1839 ///
1840 /// This currently includes:
1841 ///  * Increasing or decreasing the on-chain feerate estimates for our outbound channels,
1842 ///  * Broadcasting `ChannelUpdate` messages if we've been disconnected from our peer for more
1843 ///    than a minute, informing the network that they should no longer attempt to route over
1844 ///    the channel.
1845 ///
1846 /// Note that this may cause reentrancy through `chain::Watch::update_channel` calls or feerate
1847 /// estimate fetches.
1848 #[no_mangle]
1849 pub extern "C" fn ChannelManager_timer_tick_occurred(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
1850         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timer_tick_occurred()
1851 }
1852
1853 /// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
1854 /// after a PaymentReceived event, failing the HTLC back to its origin and freeing resources
1855 /// along the path (including in our own channel on which we received it).
1856 ///
1857 /// Note that in some cases around unclean shutdown, it is possible the payment may have
1858 /// already been claimed by you via [`ChannelManager::claim_funds`] prior to you seeing (a
1859 /// second copy of) the [`events::Event::PaymentReceived`] event. Alternatively, the payment
1860 /// may have already been failed automatically by LDK if it was nearing its expiration time.
1861 ///
1862 /// While LDK will never claim a payment automatically on your behalf (i.e. without you calling
1863 /// [`ChannelManager::claim_funds`]), you should still monitor for
1864 /// [`events::Event::PaymentClaimed`] events even for payments you intend to fail, especially on
1865 /// startup during which time claims that were in-progress at shutdown may be replayed.
1866 #[no_mangle]
1867 pub extern "C" fn ChannelManager_fail_htlc_backwards(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, payment_hash: *const [u8; 32]) {
1868         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_htlc_backwards(&::lightning::ln::PaymentHash(unsafe { *payment_hash }))
1869 }
1870
1871 /// Provides a payment preimage in response to [`Event::PaymentReceived`], generating any
1872 /// [`MessageSendEvent`]s needed to claim the payment.
1873 ///
1874 /// Note that calling this method does *not* guarantee that the payment has been claimed. You
1875 /// *must* wait for an [`Event::PaymentClaimed`] event which upon a successful claim will be
1876 /// provided to your [`EventHandler`] when [`process_pending_events`] is next called.
1877 ///
1878 /// Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
1879 /// [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentReceived`
1880 /// event matches your expectation. If you fail to do so and call this method, you may provide
1881 /// the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
1882 ///
1883 /// [`Event::PaymentReceived`]: crate::util::events::Event::PaymentReceived
1884 /// [`Event::PaymentClaimed`]: crate::util::events::Event::PaymentClaimed
1885 /// [`process_pending_events`]: EventsProvider::process_pending_events
1886 /// [`create_inbound_payment`]: Self::create_inbound_payment
1887 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1888 /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
1889 #[no_mangle]
1890 pub extern "C" fn ChannelManager_claim_funds(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_preimage: crate::c_types::ThirtyTwoBytes) {
1891         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.claim_funds(::lightning::ln::PaymentPreimage(payment_preimage.data))
1892 }
1893
1894 /// Gets the node_id held by this ChannelManager
1895 #[must_use]
1896 #[no_mangle]
1897 pub extern "C" fn ChannelManager_get_our_node_id(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::PublicKey {
1898         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_our_node_id();
1899         crate::c_types::PublicKey::from_rust(&ret)
1900 }
1901
1902 /// Accepts a request to open a channel after a [`Event::OpenChannelRequest`].
1903 ///
1904 /// The `temporary_channel_id` parameter indicates which inbound channel should be accepted,
1905 /// and the `counterparty_node_id` parameter is the id of the peer which has requested to open
1906 /// the channel.
1907 ///
1908 /// The `user_channel_id` parameter will be provided back in
1909 /// [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
1910 /// with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
1911 ///
1912 /// Note that this method will return an error and reject the channel, if it requires support
1913 /// for zero confirmations. Instead, `accept_inbound_channel_from_trusted_peer_0conf` must be
1914 /// used to accept such channels.
1915 ///
1916 /// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
1917 /// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
1918 #[must_use]
1919 #[no_mangle]
1920 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: u64) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1921         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);
1922         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() };
1923         local_ret
1924 }
1925
1926 /// Accepts a request to open a channel after a [`events::Event::OpenChannelRequest`], treating
1927 /// it as confirmed immediately.
1928 ///
1929 /// The `user_channel_id` parameter will be provided back in
1930 /// [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
1931 /// with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
1932 ///
1933 /// Unlike [`ChannelManager::accept_inbound_channel`], this method accepts the incoming channel
1934 /// and (if the counterparty agrees), enables forwarding of payments immediately.
1935 ///
1936 /// This fully trusts that the counterparty has honestly and correctly constructed the funding
1937 /// transaction and blindly assumes that it will eventually confirm.
1938 ///
1939 /// If it does not confirm before we decide to close the channel, or if the funding transaction
1940 /// does not pay to the correct script the correct amount, *you will lose funds*.
1941 ///
1942 /// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
1943 /// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
1944 #[must_use]
1945 #[no_mangle]
1946 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: u64) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1947         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);
1948         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() };
1949         local_ret
1950 }
1951
1952 /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
1953 /// to pay us.
1954 ///
1955 /// This differs from [`create_inbound_payment_for_hash`] only in that it generates the
1956 /// [`PaymentHash`] and [`PaymentPreimage`] for you.
1957 ///
1958 /// The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentReceived`], which
1959 /// will have the [`PaymentReceived::payment_preimage`] field filled in. That should then be
1960 /// passed directly to [`claim_funds`].
1961 ///
1962 /// See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
1963 ///
1964 /// Note that a malicious eavesdropper can intuit whether an inbound payment was created by
1965 /// `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
1966 ///
1967 /// # Note
1968 ///
1969 /// If you register an inbound payment with this method, then serialize the `ChannelManager`, then
1970 /// deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
1971 ///
1972 /// Errors if `min_value_msat` is greater than total bitcoin supply.
1973 ///
1974 /// [`claim_funds`]: Self::claim_funds
1975 /// [`PaymentReceived`]: events::Event::PaymentReceived
1976 /// [`PaymentReceived::payment_preimage`]: events::Event::PaymentReceived::payment_preimage
1977 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1978 #[must_use]
1979 #[no_mangle]
1980 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) -> crate::c_types::derived::CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ {
1981         let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
1982         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment(local_min_value_msat, invoice_expiry_delta_secs);
1983         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() };
1984         local_ret
1985 }
1986
1987 /// Legacy version of [`create_inbound_payment`]. Use this method if you wish to share
1988 /// serialized state with LDK node(s) running 0.0.103 and earlier.
1989 ///
1990 /// May panic if `invoice_expiry_delta_secs` is greater than one year.
1991 ///
1992 /// # Note
1993 /// This method is deprecated and will be removed soon.
1994 ///
1995 /// [`create_inbound_payment`]: Self::create_inbound_payment
1996 #[must_use]
1997 #[no_mangle]
1998 pub extern "C" fn ChannelManager_create_inbound_payment_legacy(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32) -> crate::c_types::derived::CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ {
1999         let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
2000         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment_legacy(local_min_value_msat, invoice_expiry_delta_secs);
2001         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::util::errors::APIError::native_into(e) }).into() };
2002         local_ret
2003 }
2004
2005 /// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
2006 /// stored external to LDK.
2007 ///
2008 /// A [`PaymentReceived`] event will only be generated if the [`PaymentSecret`] matches a
2009 /// payment secret fetched via this method or [`create_inbound_payment`], and which is at least
2010 /// the `min_value_msat` provided here, if one is provided.
2011 ///
2012 /// The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) should be globally unique, though
2013 /// note that LDK will not stop you from registering duplicate payment hashes for inbound
2014 /// payments.
2015 ///
2016 /// `min_value_msat` should be set if the invoice being generated contains a value. Any payment
2017 /// received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
2018 /// before a [`PaymentReceived`] event will be generated, ensuring that we do not provide the
2019 /// sender \"proof-of-payment\" unless they have paid the required amount.
2020 ///
2021 /// `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
2022 /// in excess of the current time. This should roughly match the expiry time set in the invoice.
2023 /// After this many seconds, we will remove the inbound payment, resulting in any attempts to
2024 /// pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
2025 /// invoices when no timeout is set.
2026 ///
2027 /// Note that we use block header time to time-out pending inbound payments (with some margin
2028 /// to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
2029 /// accept a payment and generate a [`PaymentReceived`] event for some time after the expiry.
2030 /// If you need exact expiry semantics, you should enforce them upon receipt of
2031 /// [`PaymentReceived`].
2032 ///
2033 /// Note that invoices generated for inbound payments should have their `min_final_cltv_expiry`
2034 /// set to at least [`MIN_FINAL_CLTV_EXPIRY`].
2035 ///
2036 /// Note that a malicious eavesdropper can intuit whether an inbound payment was created by
2037 /// `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
2038 ///
2039 /// # Note
2040 ///
2041 /// If you register an inbound payment with this method, then serialize the `ChannelManager`, then
2042 /// deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
2043 ///
2044 /// Errors if `min_value_msat` is greater than total bitcoin supply.
2045 ///
2046 /// [`create_inbound_payment`]: Self::create_inbound_payment
2047 /// [`PaymentReceived`]: events::Event::PaymentReceived
2048 #[must_use]
2049 #[no_mangle]
2050 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) -> crate::c_types::derived::CResult_PaymentSecretNoneZ {
2051         let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
2052         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);
2053         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() };
2054         local_ret
2055 }
2056
2057 /// Legacy version of [`create_inbound_payment_for_hash`]. Use this method if you wish to share
2058 /// serialized state with LDK node(s) running 0.0.103 and earlier.
2059 ///
2060 /// May panic if `invoice_expiry_delta_secs` is greater than one year.
2061 ///
2062 /// # Note
2063 /// This method is deprecated and will be removed soon.
2064 ///
2065 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
2066 #[must_use]
2067 #[no_mangle]
2068 pub extern "C" fn ChannelManager_create_inbound_payment_for_hash_legacy(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) -> crate::c_types::derived::CResult_PaymentSecretAPIErrorZ {
2069         let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
2070         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment_for_hash_legacy(::lightning::ln::PaymentHash(payment_hash.data), local_min_value_msat, invoice_expiry_delta_secs);
2071         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() };
2072         local_ret
2073 }
2074
2075 /// Gets an LDK-generated payment preimage from a payment hash and payment secret that were
2076 /// previously returned from [`create_inbound_payment`].
2077 ///
2078 /// [`create_inbound_payment`]: Self::create_inbound_payment
2079 #[must_use]
2080 #[no_mangle]
2081 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 {
2082         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));
2083         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() };
2084         local_ret
2085 }
2086
2087 /// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
2088 /// are used when constructing the phantom invoice's route hints.
2089 ///
2090 /// [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
2091 #[must_use]
2092 #[no_mangle]
2093 pub extern "C" fn ChannelManager_get_phantom_scid(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> u64 {
2094         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_phantom_scid();
2095         ret
2096 }
2097
2098 /// Gets route hints for use in receiving [phantom node payments].
2099 ///
2100 /// [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
2101 #[must_use]
2102 #[no_mangle]
2103 pub extern "C" fn ChannelManager_get_phantom_route_hints(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::ln::channelmanager::PhantomRouteHints {
2104         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_phantom_route_hints();
2105         crate::lightning::ln::channelmanager::PhantomRouteHints { inner: ObjOps::heap_alloc(ret), is_owned: true }
2106 }
2107
2108 impl From<nativeChannelManager> for crate::lightning::util::events::MessageSendEventsProvider {
2109         fn from(obj: nativeChannelManager) -> Self {
2110                 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2111                 let mut ret = ChannelManager_as_MessageSendEventsProvider(&rust_obj);
2112                 // 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
2113                 rust_obj.inner = core::ptr::null_mut();
2114                 ret.free = Some(ChannelManager_free_void);
2115                 ret
2116         }
2117 }
2118 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
2119 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
2120 #[no_mangle]
2121 pub extern "C" fn ChannelManager_as_MessageSendEventsProvider(this_arg: &ChannelManager) -> crate::lightning::util::events::MessageSendEventsProvider {
2122         crate::lightning::util::events::MessageSendEventsProvider {
2123                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2124                 free: None,
2125                 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
2126         }
2127 }
2128
2129 #[must_use]
2130 extern "C" fn ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
2131         let mut ret = <nativeChannelManager as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
2132         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
2133         local_ret.into()
2134 }
2135
2136 impl From<nativeChannelManager> for crate::lightning::util::events::EventsProvider {
2137         fn from(obj: nativeChannelManager) -> Self {
2138                 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2139                 let mut ret = ChannelManager_as_EventsProvider(&rust_obj);
2140                 // 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
2141                 rust_obj.inner = core::ptr::null_mut();
2142                 ret.free = Some(ChannelManager_free_void);
2143                 ret
2144         }
2145 }
2146 /// Constructs a new EventsProvider which calls the relevant methods on this_arg.
2147 /// This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
2148 #[no_mangle]
2149 pub extern "C" fn ChannelManager_as_EventsProvider(this_arg: &ChannelManager) -> crate::lightning::util::events::EventsProvider {
2150         crate::lightning::util::events::EventsProvider {
2151                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2152                 free: None,
2153                 process_pending_events: ChannelManager_EventsProvider_process_pending_events,
2154         }
2155 }
2156
2157 extern "C" fn ChannelManager_EventsProvider_process_pending_events(this_arg: *const c_void, mut handler: crate::lightning::util::events::EventHandler) {
2158         <nativeChannelManager as lightning::util::events::EventsProvider<>>::process_pending_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, handler)
2159 }
2160
2161 impl From<nativeChannelManager> for crate::lightning::chain::Listen {
2162         fn from(obj: nativeChannelManager) -> Self {
2163                 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2164                 let mut ret = ChannelManager_as_Listen(&rust_obj);
2165                 // 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
2166                 rust_obj.inner = core::ptr::null_mut();
2167                 ret.free = Some(ChannelManager_free_void);
2168                 ret
2169         }
2170 }
2171 /// Constructs a new Listen which calls the relevant methods on this_arg.
2172 /// This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
2173 #[no_mangle]
2174 pub extern "C" fn ChannelManager_as_Listen(this_arg: &ChannelManager) -> crate::lightning::chain::Listen {
2175         crate::lightning::chain::Listen {
2176                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2177                 free: None,
2178                 filtered_block_connected: ChannelManager_Listen_filtered_block_connected,
2179                 block_connected: ChannelManager_Listen_block_connected,
2180                 block_disconnected: ChannelManager_Listen_block_disconnected,
2181         }
2182 }
2183
2184 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) {
2185         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 }); };
2186         <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)
2187 }
2188 extern "C" fn ChannelManager_Listen_block_connected(this_arg: *const c_void, mut block: crate::c_types::u8slice, mut height: u32) {
2189         <nativeChannelManager as lightning::chain::Listen<>>::block_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height)
2190 }
2191 extern "C" fn ChannelManager_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
2192         <nativeChannelManager as lightning::chain::Listen<>>::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
2193 }
2194
2195 impl From<nativeChannelManager> for crate::lightning::chain::Confirm {
2196         fn from(obj: nativeChannelManager) -> Self {
2197                 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2198                 let mut ret = ChannelManager_as_Confirm(&rust_obj);
2199                 // 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
2200                 rust_obj.inner = core::ptr::null_mut();
2201                 ret.free = Some(ChannelManager_free_void);
2202                 ret
2203         }
2204 }
2205 /// Constructs a new Confirm which calls the relevant methods on this_arg.
2206 /// This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
2207 #[no_mangle]
2208 pub extern "C" fn ChannelManager_as_Confirm(this_arg: &ChannelManager) -> crate::lightning::chain::Confirm {
2209         crate::lightning::chain::Confirm {
2210                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2211                 free: None,
2212                 transactions_confirmed: ChannelManager_Confirm_transactions_confirmed,
2213                 transaction_unconfirmed: ChannelManager_Confirm_transaction_unconfirmed,
2214                 best_block_updated: ChannelManager_Confirm_best_block_updated,
2215                 get_relevant_txids: ChannelManager_Confirm_get_relevant_txids,
2216         }
2217 }
2218
2219 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) {
2220         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 }); };
2221         <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)
2222 }
2223 extern "C" fn ChannelManager_Confirm_transaction_unconfirmed(this_arg: *const c_void, txid: *const [u8; 32]) {
2224         <nativeChannelManager as lightning::chain::Confirm<>>::transaction_unconfirmed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap())
2225 }
2226 extern "C" fn ChannelManager_Confirm_best_block_updated(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
2227         <nativeChannelManager as lightning::chain::Confirm<>>::best_block_updated(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
2228 }
2229 #[must_use]
2230 extern "C" fn ChannelManager_Confirm_get_relevant_txids(this_arg: *const c_void) -> crate::c_types::derived::CVec_TxidZ {
2231         let mut ret = <nativeChannelManager as lightning::chain::Confirm<>>::get_relevant_txids(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
2232         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::ThirtyTwoBytes { data: item.into_inner() } }); };
2233         local_ret.into()
2234 }
2235
2236 /// Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
2237 /// indicating whether persistence is necessary. Only one listener on
2238 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
2239 /// up.
2240 ///
2241 /// Note that this method is not available with the `no-std` feature.
2242 #[must_use]
2243 #[no_mangle]
2244 pub extern "C" fn ChannelManager_await_persistable_update_timeout(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut max_wait: u64) -> bool {
2245         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.await_persistable_update_timeout(core::time::Duration::from_secs(max_wait));
2246         ret
2247 }
2248
2249 /// Blocks until ChannelManager needs to be persisted. Only one listener on
2250 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
2251 /// up.
2252 #[no_mangle]
2253 pub extern "C" fn ChannelManager_await_persistable_update(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
2254         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.await_persistable_update()
2255 }
2256
2257 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
2258 /// [`chain::Confirm`] interfaces.
2259 #[must_use]
2260 #[no_mangle]
2261 pub extern "C" fn ChannelManager_current_best_block(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::chain::BestBlock {
2262         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
2263         crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
2264 }
2265
2266 impl From<nativeChannelManager> for crate::lightning::ln::msgs::ChannelMessageHandler {
2267         fn from(obj: nativeChannelManager) -> Self {
2268                 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2269                 let mut ret = ChannelManager_as_ChannelMessageHandler(&rust_obj);
2270                 // 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
2271                 rust_obj.inner = core::ptr::null_mut();
2272                 ret.free = Some(ChannelManager_free_void);
2273                 ret
2274         }
2275 }
2276 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
2277 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
2278 #[no_mangle]
2279 pub extern "C" fn ChannelManager_as_ChannelMessageHandler(this_arg: &ChannelManager) -> crate::lightning::ln::msgs::ChannelMessageHandler {
2280         crate::lightning::ln::msgs::ChannelMessageHandler {
2281                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2282                 free: None,
2283                 handle_open_channel: ChannelManager_ChannelMessageHandler_handle_open_channel,
2284                 handle_accept_channel: ChannelManager_ChannelMessageHandler_handle_accept_channel,
2285                 handle_funding_created: ChannelManager_ChannelMessageHandler_handle_funding_created,
2286                 handle_funding_signed: ChannelManager_ChannelMessageHandler_handle_funding_signed,
2287                 handle_channel_ready: ChannelManager_ChannelMessageHandler_handle_channel_ready,
2288                 handle_shutdown: ChannelManager_ChannelMessageHandler_handle_shutdown,
2289                 handle_closing_signed: ChannelManager_ChannelMessageHandler_handle_closing_signed,
2290                 handle_update_add_htlc: ChannelManager_ChannelMessageHandler_handle_update_add_htlc,
2291                 handle_update_fulfill_htlc: ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc,
2292                 handle_update_fail_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_htlc,
2293                 handle_update_fail_malformed_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_malformed_htlc,
2294                 handle_commitment_signed: ChannelManager_ChannelMessageHandler_handle_commitment_signed,
2295                 handle_revoke_and_ack: ChannelManager_ChannelMessageHandler_handle_revoke_and_ack,
2296                 handle_update_fee: ChannelManager_ChannelMessageHandler_handle_update_fee,
2297                 handle_announcement_signatures: ChannelManager_ChannelMessageHandler_handle_announcement_signatures,
2298                 peer_disconnected: ChannelManager_ChannelMessageHandler_peer_disconnected,
2299                 peer_connected: ChannelManager_ChannelMessageHandler_peer_connected,
2300                 handle_channel_reestablish: ChannelManager_ChannelMessageHandler_handle_channel_reestablish,
2301                 handle_channel_update: ChannelManager_ChannelMessageHandler_handle_channel_update,
2302                 handle_error: ChannelManager_ChannelMessageHandler_handle_error,
2303                 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
2304                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2305                         free: None,
2306                         get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
2307                 },
2308         }
2309 }
2310
2311 extern "C" fn ChannelManager_ChannelMessageHandler_handle_open_channel(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, mut their_features: crate::lightning::ln::features::InitFeatures, msg: &crate::lightning::ln::msgs::OpenChannel) {
2312         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_open_channel(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), *unsafe { Box::from_raw(their_features.take_inner()) }, msg.get_native_ref())
2313 }
2314 extern "C" fn ChannelManager_ChannelMessageHandler_handle_accept_channel(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, mut their_features: crate::lightning::ln::features::InitFeatures, msg: &crate::lightning::ln::msgs::AcceptChannel) {
2315         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_accept_channel(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), *unsafe { Box::from_raw(their_features.take_inner()) }, msg.get_native_ref())
2316 }
2317 extern "C" fn ChannelManager_ChannelMessageHandler_handle_funding_created(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::FundingCreated) {
2318         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_created(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2319 }
2320 extern "C" fn ChannelManager_ChannelMessageHandler_handle_funding_signed(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::FundingSigned) {
2321         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2322 }
2323 extern "C" fn ChannelManager_ChannelMessageHandler_handle_channel_ready(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ChannelReady) {
2324         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_channel_ready(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2325 }
2326 extern "C" fn ChannelManager_ChannelMessageHandler_handle_shutdown(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, their_features: &crate::lightning::ln::features::InitFeatures, msg: &crate::lightning::ln::msgs::Shutdown) {
2327         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_shutdown(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), their_features.get_native_ref(), msg.get_native_ref())
2328 }
2329 extern "C" fn ChannelManager_ChannelMessageHandler_handle_closing_signed(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ClosingSigned) {
2330         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_closing_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2331 }
2332 extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_add_htlc(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateAddHTLC) {
2333         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_add_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2334 }
2335 extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateFulfillHTLC) {
2336         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fulfill_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2337 }
2338 extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_fail_htlc(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateFailHTLC) {
2339         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fail_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2340 }
2341 extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_fail_malformed_htlc(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateFailMalformedHTLC) {
2342         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fail_malformed_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2343 }
2344 extern "C" fn ChannelManager_ChannelMessageHandler_handle_commitment_signed(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::CommitmentSigned) {
2345         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_commitment_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2346 }
2347 extern "C" fn ChannelManager_ChannelMessageHandler_handle_revoke_and_ack(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::RevokeAndACK) {
2348         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_revoke_and_ack(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2349 }
2350 extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_fee(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateFee) {
2351         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fee(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2352 }
2353 extern "C" fn ChannelManager_ChannelMessageHandler_handle_announcement_signatures(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::AnnouncementSignatures) {
2354         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_announcement_signatures(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2355 }
2356 extern "C" fn ChannelManager_ChannelMessageHandler_peer_disconnected(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, mut no_connection_possible: bool) {
2357         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), no_connection_possible)
2358 }
2359 extern "C" fn ChannelManager_ChannelMessageHandler_peer_connected(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, init_msg: &crate::lightning::ln::msgs::Init) {
2360         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::peer_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), init_msg.get_native_ref())
2361 }
2362 extern "C" fn ChannelManager_ChannelMessageHandler_handle_channel_reestablish(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ChannelReestablish) {
2363         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_channel_reestablish(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2364 }
2365 extern "C" fn ChannelManager_ChannelMessageHandler_handle_channel_update(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ChannelUpdate) {
2366         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2367 }
2368 extern "C" fn ChannelManager_ChannelMessageHandler_handle_error(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ErrorMessage) {
2369         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2370 }
2371
2372 #[no_mangle]
2373 /// Serialize the CounterpartyForwardingInfo object into a byte array which can be read by CounterpartyForwardingInfo_read
2374 pub extern "C" fn CounterpartyForwardingInfo_write(obj: &crate::lightning::ln::channelmanager::CounterpartyForwardingInfo) -> crate::c_types::derived::CVec_u8Z {
2375         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2376 }
2377 #[no_mangle]
2378 pub(crate) extern "C" fn CounterpartyForwardingInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2379         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCounterpartyForwardingInfo) })
2380 }
2381 #[no_mangle]
2382 /// Read a CounterpartyForwardingInfo from a byte array, created by CounterpartyForwardingInfo_write
2383 pub extern "C" fn CounterpartyForwardingInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CounterpartyForwardingInfoDecodeErrorZ {
2384         let res: Result<lightning::ln::channelmanager::CounterpartyForwardingInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2385         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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
2386         local_res
2387 }
2388 #[no_mangle]
2389 /// Serialize the ChannelCounterparty object into a byte array which can be read by ChannelCounterparty_read
2390 pub extern "C" fn ChannelCounterparty_write(obj: &crate::lightning::ln::channelmanager::ChannelCounterparty) -> crate::c_types::derived::CVec_u8Z {
2391         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2392 }
2393 #[no_mangle]
2394 pub(crate) extern "C" fn ChannelCounterparty_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2395         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelCounterparty) })
2396 }
2397 #[no_mangle]
2398 /// Read a ChannelCounterparty from a byte array, created by ChannelCounterparty_write
2399 pub extern "C" fn ChannelCounterparty_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelCounterpartyDecodeErrorZ {
2400         let res: Result<lightning::ln::channelmanager::ChannelCounterparty, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2401         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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
2402         local_res
2403 }
2404 #[no_mangle]
2405 /// Serialize the ChannelDetails object into a byte array which can be read by ChannelDetails_read
2406 pub extern "C" fn ChannelDetails_write(obj: &crate::lightning::ln::channelmanager::ChannelDetails) -> crate::c_types::derived::CVec_u8Z {
2407         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2408 }
2409 #[no_mangle]
2410 pub(crate) extern "C" fn ChannelDetails_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2411         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelDetails) })
2412 }
2413 #[no_mangle]
2414 /// Read a ChannelDetails from a byte array, created by ChannelDetails_write
2415 pub extern "C" fn ChannelDetails_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelDetailsDecodeErrorZ {
2416         let res: Result<lightning::ln::channelmanager::ChannelDetails, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2417         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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
2418         local_res
2419 }
2420 #[no_mangle]
2421 /// Serialize the PhantomRouteHints object into a byte array which can be read by PhantomRouteHints_read
2422 pub extern "C" fn PhantomRouteHints_write(obj: &crate::lightning::ln::channelmanager::PhantomRouteHints) -> crate::c_types::derived::CVec_u8Z {
2423         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2424 }
2425 #[no_mangle]
2426 pub(crate) extern "C" fn PhantomRouteHints_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2427         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePhantomRouteHints) })
2428 }
2429 #[no_mangle]
2430 /// Read a PhantomRouteHints from a byte array, created by PhantomRouteHints_write
2431 pub extern "C" fn PhantomRouteHints_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PhantomRouteHintsDecodeErrorZ {
2432         let res: Result<lightning::ln::channelmanager::PhantomRouteHints, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2433         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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
2434         local_res
2435 }
2436 #[no_mangle]
2437 /// Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
2438 pub extern "C" fn ChannelManager_write(obj: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_u8Z {
2439         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2440 }
2441 #[no_mangle]
2442 pub(crate) extern "C" fn ChannelManager_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2443         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelManager) })
2444 }
2445
2446 use lightning::ln::channelmanager::ChannelManagerReadArgs as nativeChannelManagerReadArgsImport;
2447 pub(crate) type nativeChannelManagerReadArgs = nativeChannelManagerReadArgsImport<'static, crate::lightning::chain::keysinterface::Sign, crate::lightning::chain::Watch, crate::lightning::chain::chaininterface::BroadcasterInterface, crate::lightning::chain::keysinterface::KeysInterface, crate::lightning::chain::chaininterface::FeeEstimator, crate::lightning::util::logger::Logger>;
2448
2449 /// Arguments for the creation of a ChannelManager that are not deserialized.
2450 ///
2451 /// At a high-level, the process for deserializing a ChannelManager and resuming normal operation
2452 /// is:
2453 /// 1) Deserialize all stored [`ChannelMonitor`]s.
2454 /// 2) Deserialize the [`ChannelManager`] by filling in this struct and calling:
2455 ///    `<(BlockHash, ChannelManager)>::read(reader, args)`
2456 ///    This may result in closing some channels if the [`ChannelMonitor`] is newer than the stored
2457 ///    [`ChannelManager`] state to ensure no loss of funds. Thus, transactions may be broadcasted.
2458 /// 3) If you are not fetching full blocks, register all relevant [`ChannelMonitor`] outpoints the
2459 ///    same way you would handle a [`chain::Filter`] call using
2460 ///    [`ChannelMonitor::get_outputs_to_watch`] and [`ChannelMonitor::get_funding_txo`].
2461 /// 4) Reconnect blocks on your [`ChannelMonitor`]s.
2462 /// 5) Disconnect/connect blocks on the [`ChannelManager`].
2463 /// 6) Re-persist the [`ChannelMonitor`]s to ensure the latest state is on disk.
2464 ///    Note that if you're using a [`ChainMonitor`] for your [`chain::Watch`] implementation, you
2465 ///    will likely accomplish this as a side-effect of calling [`chain::Watch::watch_channel`] in
2466 ///    the next step.
2467 /// 7) Move the [`ChannelMonitor`]s into your local [`chain::Watch`]. If you're using a
2468 ///    [`ChainMonitor`], this is done by calling [`chain::Watch::watch_channel`].
2469 ///
2470 /// Note that the ordering of #4-7 is not of importance, however all four must occur before you
2471 /// call any other methods on the newly-deserialized [`ChannelManager`].
2472 ///
2473 /// Note that because some channels may be closed during deserialization, it is critical that you
2474 /// always deserialize only the latest version of a ChannelManager and ChannelMonitors available to
2475 /// you. If you deserialize an old ChannelManager (during which force-closure transactions may be
2476 /// broadcast), and then later deserialize a newer version of the same ChannelManager (which will
2477 /// not force-close the same channels but consider them live), you may end up revoking a state for
2478 /// which you've already broadcasted the transaction.
2479 ///
2480 /// [`ChainMonitor`]: crate::chain::chainmonitor::ChainMonitor
2481 #[must_use]
2482 #[repr(C)]
2483 pub struct ChannelManagerReadArgs {
2484         /// A pointer to the opaque Rust object.
2485
2486         /// Nearly everywhere, inner must be non-null, however in places where
2487         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2488         pub inner: *mut nativeChannelManagerReadArgs,
2489         /// Indicates that this is the only struct which contains the same pointer.
2490
2491         /// Rust functions which take ownership of an object provided via an argument require
2492         /// this to be true and invalidate the object pointed to by inner.
2493         pub is_owned: bool,
2494 }
2495
2496 impl Drop for ChannelManagerReadArgs {
2497         fn drop(&mut self) {
2498                 if self.is_owned && !<*mut nativeChannelManagerReadArgs>::is_null(self.inner) {
2499                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2500                 }
2501         }
2502 }
2503 /// Frees any resources used by the ChannelManagerReadArgs, if is_owned is set and inner is non-NULL.
2504 #[no_mangle]
2505 pub extern "C" fn ChannelManagerReadArgs_free(this_obj: ChannelManagerReadArgs) { }
2506 #[allow(unused)]
2507 /// Used only if an object of this type is returned as a trait impl by a method
2508 pub(crate) extern "C" fn ChannelManagerReadArgs_free_void(this_ptr: *mut c_void) {
2509         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManagerReadArgs); }
2510 }
2511 #[allow(unused)]
2512 impl ChannelManagerReadArgs {
2513         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManagerReadArgs {
2514                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2515         }
2516         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManagerReadArgs {
2517                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2518         }
2519         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2520         pub(crate) fn take_inner(mut self) -> *mut nativeChannelManagerReadArgs {
2521                 assert!(self.is_owned);
2522                 let ret = ObjOps::untweak_ptr(self.inner);
2523                 self.inner = core::ptr::null_mut();
2524                 ret
2525         }
2526 }
2527 /// The keys provider which will give us relevant keys. Some keys will be loaded during
2528 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
2529 /// signing data.
2530 #[no_mangle]
2531 pub extern "C" fn ChannelManagerReadArgs_get_keys_manager(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::keysinterface::KeysInterface {
2532         let mut inner_val = &mut this_ptr.get_native_mut_ref().keys_manager;
2533         inner_val
2534 }
2535 /// The keys provider which will give us relevant keys. Some keys will be loaded during
2536 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
2537 /// signing data.
2538 #[no_mangle]
2539 pub extern "C" fn ChannelManagerReadArgs_set_keys_manager(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::keysinterface::KeysInterface) {
2540         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.keys_manager = val;
2541 }
2542 /// The fee_estimator for use in the ChannelManager in the future.
2543 ///
2544 /// No calls to the FeeEstimator will be made during deserialization.
2545 #[no_mangle]
2546 pub extern "C" fn ChannelManagerReadArgs_get_fee_estimator(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::FeeEstimator {
2547         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_estimator;
2548         inner_val
2549 }
2550 /// The fee_estimator for use in the ChannelManager in the future.
2551 ///
2552 /// No calls to the FeeEstimator will be made during deserialization.
2553 #[no_mangle]
2554 pub extern "C" fn ChannelManagerReadArgs_set_fee_estimator(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::FeeEstimator) {
2555         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_estimator = val;
2556 }
2557 /// The chain::Watch for use in the ChannelManager in the future.
2558 ///
2559 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
2560 /// you have deserialized ChannelMonitors separately and will add them to your
2561 /// chain::Watch after deserializing this ChannelManager.
2562 #[no_mangle]
2563 pub extern "C" fn ChannelManagerReadArgs_get_chain_monitor(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::Watch {
2564         let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_monitor;
2565         inner_val
2566 }
2567 /// The chain::Watch for use in the ChannelManager in the future.
2568 ///
2569 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
2570 /// you have deserialized ChannelMonitors separately and will add them to your
2571 /// chain::Watch after deserializing this ChannelManager.
2572 #[no_mangle]
2573 pub extern "C" fn ChannelManagerReadArgs_set_chain_monitor(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::Watch) {
2574         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_monitor = val;
2575 }
2576 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
2577 /// used to broadcast the latest local commitment transactions of channels which must be
2578 /// force-closed during deserialization.
2579 #[no_mangle]
2580 pub extern "C" fn ChannelManagerReadArgs_get_tx_broadcaster(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::BroadcasterInterface {
2581         let mut inner_val = &mut this_ptr.get_native_mut_ref().tx_broadcaster;
2582         inner_val
2583 }
2584 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
2585 /// used to broadcast the latest local commitment transactions of channels which must be
2586 /// force-closed during deserialization.
2587 #[no_mangle]
2588 pub extern "C" fn ChannelManagerReadArgs_set_tx_broadcaster(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::BroadcasterInterface) {
2589         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.tx_broadcaster = val;
2590 }
2591 /// The Logger for use in the ChannelManager and which may be used to log information during
2592 /// deserialization.
2593 #[no_mangle]
2594 pub extern "C" fn ChannelManagerReadArgs_get_logger(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::util::logger::Logger {
2595         let mut inner_val = &mut this_ptr.get_native_mut_ref().logger;
2596         inner_val
2597 }
2598 /// The Logger for use in the ChannelManager and which may be used to log information during
2599 /// deserialization.
2600 #[no_mangle]
2601 pub extern "C" fn ChannelManagerReadArgs_set_logger(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::logger::Logger) {
2602         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.logger = val;
2603 }
2604 /// Default settings used for new channels. Any existing channels will continue to use the
2605 /// runtime settings which were stored when the ChannelManager was serialized.
2606 #[no_mangle]
2607 pub extern "C" fn ChannelManagerReadArgs_get_default_config(this_ptr: &ChannelManagerReadArgs) -> crate::lightning::util::config::UserConfig {
2608         let mut inner_val = &mut this_ptr.get_native_mut_ref().default_config;
2609         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 }
2610 }
2611 /// Default settings used for new channels. Any existing channels will continue to use the
2612 /// runtime settings which were stored when the ChannelManager was serialized.
2613 #[no_mangle]
2614 pub extern "C" fn ChannelManagerReadArgs_set_default_config(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::config::UserConfig) {
2615         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.default_config = *unsafe { Box::from_raw(val.take_inner()) };
2616 }
2617 /// Simple utility function to create a ChannelManagerReadArgs which creates the monitor
2618 /// HashMap for you. This is primarily useful for C bindings where it is not practical to
2619 /// populate a HashMap directly from C.
2620 #[must_use]
2621 #[no_mangle]
2622 pub extern "C" fn ChannelManagerReadArgs_new(mut keys_manager: crate::lightning::chain::keysinterface::KeysInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, mut chain_monitor: crate::lightning::chain::Watch, mut tx_broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, 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 {
2623         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() }); };
2624         let mut ret = lightning::ln::channelmanager::ChannelManagerReadArgs::new(keys_manager, fee_estimator, chain_monitor, tx_broadcaster, logger, *unsafe { Box::from_raw(default_config.take_inner()) }, local_channel_monitors);
2625         crate::lightning::ln::channelmanager::ChannelManagerReadArgs { inner: ObjOps::heap_alloc(ret), is_owned: true }
2626 }
2627
2628 #[no_mangle]
2629 /// Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_write
2630 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 {
2631         let arg_conv = *unsafe { Box::from_raw(arg.take_inner()) };
2632         let res: Result<(bitcoin::hash_types::BlockHash, lightning::ln::channelmanager::ChannelManager<crate::lightning::chain::keysinterface::Sign, crate::lightning::chain::Watch, crate::lightning::chain::chaininterface::BroadcasterInterface, crate::lightning::chain::keysinterface::KeysInterface, crate::lightning::chain::chaininterface::FeeEstimator, crate::lightning::util::logger::Logger>), lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
2633         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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
2634         local_res
2635 }