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(
1174                 crate::lightning::util::errors::APIError),
1175         /// A parameter in a single path which was passed to send_payment was invalid, preventing us
1176         /// from attempting to send the payment at all. No channel state has been changed or messages
1177         /// sent to peers, and once you've changed the parameter at error, you can freely retry the
1178         /// payment in full.
1179         ///
1180         /// The results here are ordered the same as the paths in the route object which was passed to
1181         /// send_payment.
1182         PathParameterError(
1183                 crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ),
1184         /// All paths which were attempted failed to send, with no channel state change taking place.
1185         /// You can freely retry the payment in full (though you probably want to do so over different
1186         /// paths than the ones selected).
1187         AllFailedRetrySafe(
1188                 crate::c_types::derived::CVec_APIErrorZ),
1189         /// Some paths which were attempted failed to send, though possibly not all. At least some
1190         /// paths have irrevocably committed to the HTLC and retrying the payment in full would result
1191         /// in over-/re-payment.
1192         ///
1193         /// The results here are ordered the same as the paths in the route object which was passed to
1194         /// send_payment, and any Errs which are not APIError::MonitorUpdateFailed can be safely
1195         /// retried (though there is currently no API with which to do so).
1196         ///
1197         /// Any entries which contain Err(APIError::MonitorUpdateFailed) or Ok(()) MUST NOT be retried
1198         /// as they will result in over-/re-payment. These HTLCs all either successfully sent (in the
1199         /// case of Ok(())) or will send once channel_monitor_updated is called on the next-hop channel
1200         /// with the latest update_id.
1201         PartialFailure {
1202                 /// The errors themselves, in the same order as the route hops.
1203                 results: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ,
1204                 /// If some paths failed without irrevocably committing to the new HTLC(s), this will
1205                 /// contain a [`RouteParameters`] object which can be used to calculate a new route that
1206                 /// will pay all remaining unpaid balance.
1207                 ///
1208                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1209                 failed_paths_retry: crate::lightning::routing::router::RouteParameters,
1210                 /// The payment id for the payment, which is now at least partially pending.
1211                 payment_id: crate::c_types::ThirtyTwoBytes,
1212         },
1213 }
1214 use lightning::ln::channelmanager::PaymentSendFailure as PaymentSendFailureImport;
1215 pub(crate) type nativePaymentSendFailure = PaymentSendFailureImport;
1216
1217 impl PaymentSendFailure {
1218         #[allow(unused)]
1219         pub(crate) fn to_native(&self) -> nativePaymentSendFailure {
1220                 match self {
1221                         PaymentSendFailure::ParameterError (ref a, ) => {
1222                                 let mut a_nonref = (*a).clone();
1223                                 nativePaymentSendFailure::ParameterError (
1224                                         a_nonref.into_native(),
1225                                 )
1226                         },
1227                         PaymentSendFailure::PathParameterError (ref a, ) => {
1228                                 let mut a_nonref = (*a).clone();
1229                                 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 }); };
1230                                 nativePaymentSendFailure::PathParameterError (
1231                                         local_a_nonref,
1232                                 )
1233                         },
1234                         PaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
1235                                 let mut a_nonref = (*a).clone();
1236                                 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { item.into_native() }); };
1237                                 nativePaymentSendFailure::AllFailedRetrySafe (
1238                                         local_a_nonref,
1239                                 )
1240                         },
1241                         PaymentSendFailure::PartialFailure {ref results, ref failed_paths_retry, ref payment_id, } => {
1242                                 let mut results_nonref = (*results).clone();
1243                                 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 }); };
1244                                 let mut failed_paths_retry_nonref = (*failed_paths_retry).clone();
1245                                 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()) } }) };
1246                                 let mut payment_id_nonref = (*payment_id).clone();
1247                                 nativePaymentSendFailure::PartialFailure {
1248                                         results: local_results_nonref,
1249                                         failed_paths_retry: local_failed_paths_retry_nonref,
1250                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1251                                 }
1252                         },
1253                 }
1254         }
1255         #[allow(unused)]
1256         pub(crate) fn into_native(self) -> nativePaymentSendFailure {
1257                 match self {
1258                         PaymentSendFailure::ParameterError (mut a, ) => {
1259                                 nativePaymentSendFailure::ParameterError (
1260                                         a.into_native(),
1261                                 )
1262                         },
1263                         PaymentSendFailure::PathParameterError (mut a, ) => {
1264                                 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 }); };
1265                                 nativePaymentSendFailure::PathParameterError (
1266                                         local_a,
1267                                 )
1268                         },
1269                         PaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
1270                                 let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { item.into_native() }); };
1271                                 nativePaymentSendFailure::AllFailedRetrySafe (
1272                                         local_a,
1273                                 )
1274                         },
1275                         PaymentSendFailure::PartialFailure {mut results, mut failed_paths_retry, mut payment_id, } => {
1276                                 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 }); };
1277                                 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()) } }) };
1278                                 nativePaymentSendFailure::PartialFailure {
1279                                         results: local_results,
1280                                         failed_paths_retry: local_failed_paths_retry,
1281                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1282                                 }
1283                         },
1284                 }
1285         }
1286         #[allow(unused)]
1287         pub(crate) fn from_native(native: &nativePaymentSendFailure) -> Self {
1288                 match native {
1289                         nativePaymentSendFailure::ParameterError (ref a, ) => {
1290                                 let mut a_nonref = (*a).clone();
1291                                 PaymentSendFailure::ParameterError (
1292                                         crate::lightning::util::errors::APIError::native_into(a_nonref),
1293                                 )
1294                         },
1295                         nativePaymentSendFailure::PathParameterError (ref a, ) => {
1296                                 let mut a_nonref = (*a).clone();
1297                                 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 }); };
1298                                 PaymentSendFailure::PathParameterError (
1299                                         local_a_nonref.into(),
1300                                 )
1301                         },
1302                         nativePaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
1303                                 let mut a_nonref = (*a).clone();
1304                                 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) }); };
1305                                 PaymentSendFailure::AllFailedRetrySafe (
1306                                         local_a_nonref.into(),
1307                                 )
1308                         },
1309                         nativePaymentSendFailure::PartialFailure {ref results, ref failed_paths_retry, ref payment_id, } => {
1310                                 let mut results_nonref = (*results).clone();
1311                                 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 }); };
1312                                 let mut failed_paths_retry_nonref = (*failed_paths_retry).clone();
1313                                 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 };
1314                                 let mut payment_id_nonref = (*payment_id).clone();
1315                                 PaymentSendFailure::PartialFailure {
1316                                         results: local_results_nonref.into(),
1317                                         failed_paths_retry: local_failed_paths_retry_nonref,
1318                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1319                                 }
1320                         },
1321                 }
1322         }
1323         #[allow(unused)]
1324         pub(crate) fn native_into(native: nativePaymentSendFailure) -> Self {
1325                 match native {
1326                         nativePaymentSendFailure::ParameterError (mut a, ) => {
1327                                 PaymentSendFailure::ParameterError (
1328                                         crate::lightning::util::errors::APIError::native_into(a),
1329                                 )
1330                         },
1331                         nativePaymentSendFailure::PathParameterError (mut a, ) => {
1332                                 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 }); };
1333                                 PaymentSendFailure::PathParameterError (
1334                                         local_a.into(),
1335                                 )
1336                         },
1337                         nativePaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
1338                                 let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { crate::lightning::util::errors::APIError::native_into(item) }); };
1339                                 PaymentSendFailure::AllFailedRetrySafe (
1340                                         local_a.into(),
1341                                 )
1342                         },
1343                         nativePaymentSendFailure::PartialFailure {mut results, mut failed_paths_retry, mut payment_id, } => {
1344                                 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 }); };
1345                                 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 };
1346                                 PaymentSendFailure::PartialFailure {
1347                                         results: local_results.into(),
1348                                         failed_paths_retry: local_failed_paths_retry,
1349                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1350                                 }
1351                         },
1352                 }
1353         }
1354 }
1355 /// Frees any resources used by the PaymentSendFailure
1356 #[no_mangle]
1357 pub extern "C" fn PaymentSendFailure_free(this_ptr: PaymentSendFailure) { }
1358 /// Creates a copy of the PaymentSendFailure
1359 #[no_mangle]
1360 pub extern "C" fn PaymentSendFailure_clone(orig: &PaymentSendFailure) -> PaymentSendFailure {
1361         orig.clone()
1362 }
1363 #[no_mangle]
1364 /// Utility method to constructs a new ParameterError-variant PaymentSendFailure
1365 pub extern "C" fn PaymentSendFailure_parameter_error(a: crate::lightning::util::errors::APIError) -> PaymentSendFailure {
1366         PaymentSendFailure::ParameterError(a, )
1367 }
1368 #[no_mangle]
1369 /// Utility method to constructs a new PathParameterError-variant PaymentSendFailure
1370 pub extern "C" fn PaymentSendFailure_path_parameter_error(a: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ) -> PaymentSendFailure {
1371         PaymentSendFailure::PathParameterError(a, )
1372 }
1373 #[no_mangle]
1374 /// Utility method to constructs a new AllFailedRetrySafe-variant PaymentSendFailure
1375 pub extern "C" fn PaymentSendFailure_all_failed_retry_safe(a: crate::c_types::derived::CVec_APIErrorZ) -> PaymentSendFailure {
1376         PaymentSendFailure::AllFailedRetrySafe(a, )
1377 }
1378 #[no_mangle]
1379 /// Utility method to constructs a new PartialFailure-variant PaymentSendFailure
1380 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 {
1381         PaymentSendFailure::PartialFailure {
1382                 results,
1383                 failed_paths_retry,
1384                 payment_id,
1385         }
1386 }
1387
1388 use lightning::ln::channelmanager::PhantomRouteHints as nativePhantomRouteHintsImport;
1389 pub(crate) type nativePhantomRouteHints = nativePhantomRouteHintsImport;
1390
1391 /// Route hints used in constructing invoices for [phantom node payents].
1392 ///
1393 /// [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
1394 #[must_use]
1395 #[repr(C)]
1396 pub struct PhantomRouteHints {
1397         /// A pointer to the opaque Rust object.
1398
1399         /// Nearly everywhere, inner must be non-null, however in places where
1400         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1401         pub inner: *mut nativePhantomRouteHints,
1402         /// Indicates that this is the only struct which contains the same pointer.
1403
1404         /// Rust functions which take ownership of an object provided via an argument require
1405         /// this to be true and invalidate the object pointed to by inner.
1406         pub is_owned: bool,
1407 }
1408
1409 impl Drop for PhantomRouteHints {
1410         fn drop(&mut self) {
1411                 if self.is_owned && !<*mut nativePhantomRouteHints>::is_null(self.inner) {
1412                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1413                 }
1414         }
1415 }
1416 /// Frees any resources used by the PhantomRouteHints, if is_owned is set and inner is non-NULL.
1417 #[no_mangle]
1418 pub extern "C" fn PhantomRouteHints_free(this_obj: PhantomRouteHints) { }
1419 #[allow(unused)]
1420 /// Used only if an object of this type is returned as a trait impl by a method
1421 pub(crate) extern "C" fn PhantomRouteHints_free_void(this_ptr: *mut c_void) {
1422         unsafe { let _ = Box::from_raw(this_ptr as *mut nativePhantomRouteHints); }
1423 }
1424 #[allow(unused)]
1425 impl PhantomRouteHints {
1426         pub(crate) fn get_native_ref(&self) -> &'static nativePhantomRouteHints {
1427                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1428         }
1429         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePhantomRouteHints {
1430                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1431         }
1432         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1433         pub(crate) fn take_inner(mut self) -> *mut nativePhantomRouteHints {
1434                 assert!(self.is_owned);
1435                 let ret = ObjOps::untweak_ptr(self.inner);
1436                 self.inner = core::ptr::null_mut();
1437                 ret
1438         }
1439 }
1440 /// The list of channels to be included in the invoice route hints.
1441 #[no_mangle]
1442 pub extern "C" fn PhantomRouteHints_get_channels(this_ptr: &PhantomRouteHints) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1443         let mut inner_val = &mut this_ptr.get_native_mut_ref().channels;
1444         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 } }); };
1445         local_inner_val.into()
1446 }
1447 /// The list of channels to be included in the invoice route hints.
1448 #[no_mangle]
1449 pub extern "C" fn PhantomRouteHints_set_channels(this_ptr: &mut PhantomRouteHints, mut val: crate::c_types::derived::CVec_ChannelDetailsZ) {
1450         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1451         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val;
1452 }
1453 /// A fake scid used for representing the phantom node's fake channel in generating the invoice
1454 /// route hints.
1455 #[no_mangle]
1456 pub extern "C" fn PhantomRouteHints_get_phantom_scid(this_ptr: &PhantomRouteHints) -> u64 {
1457         let mut inner_val = &mut this_ptr.get_native_mut_ref().phantom_scid;
1458         *inner_val
1459 }
1460 /// A fake scid used for representing the phantom node's fake channel in generating the invoice
1461 /// route hints.
1462 #[no_mangle]
1463 pub extern "C" fn PhantomRouteHints_set_phantom_scid(this_ptr: &mut PhantomRouteHints, mut val: u64) {
1464         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.phantom_scid = val;
1465 }
1466 /// The pubkey of the real backing node that would ultimately receive the payment.
1467 #[no_mangle]
1468 pub extern "C" fn PhantomRouteHints_get_real_node_pubkey(this_ptr: &PhantomRouteHints) -> crate::c_types::PublicKey {
1469         let mut inner_val = &mut this_ptr.get_native_mut_ref().real_node_pubkey;
1470         crate::c_types::PublicKey::from_rust(&inner_val)
1471 }
1472 /// The pubkey of the real backing node that would ultimately receive the payment.
1473 #[no_mangle]
1474 pub extern "C" fn PhantomRouteHints_set_real_node_pubkey(this_ptr: &mut PhantomRouteHints, mut val: crate::c_types::PublicKey) {
1475         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.real_node_pubkey = val.into_rust();
1476 }
1477 /// Constructs a new PhantomRouteHints given each field
1478 #[must_use]
1479 #[no_mangle]
1480 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 {
1481         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()) } }); };
1482         PhantomRouteHints { inner: ObjOps::heap_alloc(nativePhantomRouteHints {
1483                 channels: local_channels_arg,
1484                 phantom_scid: phantom_scid_arg,
1485                 real_node_pubkey: real_node_pubkey_arg.into_rust(),
1486         }), is_owned: true }
1487 }
1488 impl Clone for PhantomRouteHints {
1489         fn clone(&self) -> Self {
1490                 Self {
1491                         inner: if <*mut nativePhantomRouteHints>::is_null(self.inner) { core::ptr::null_mut() } else {
1492                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1493                         is_owned: true,
1494                 }
1495         }
1496 }
1497 #[allow(unused)]
1498 /// Used only if an object of this type is returned as a trait impl by a method
1499 pub(crate) extern "C" fn PhantomRouteHints_clone_void(this_ptr: *const c_void) -> *mut c_void {
1500         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePhantomRouteHints)).clone() })) as *mut c_void
1501 }
1502 #[no_mangle]
1503 /// Creates a copy of the PhantomRouteHints
1504 pub extern "C" fn PhantomRouteHints_clone(orig: &PhantomRouteHints) -> PhantomRouteHints {
1505         orig.clone()
1506 }
1507 /// Constructs a new ChannelManager to hold several channels and route between them.
1508 ///
1509 /// This is the main \"logic hub\" for all channel-related actions, and implements
1510 /// ChannelMessageHandler.
1511 ///
1512 /// Non-proportional fees are fixed according to our risk using the provided fee estimator.
1513 ///
1514 /// Users need to notify the new ChannelManager when a new block is connected or
1515 /// disconnected using its `block_connected` and `block_disconnected` methods, starting
1516 /// from after `params.latest_hash`.
1517 #[must_use]
1518 #[no_mangle]
1519 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 {
1520         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()) });
1521         crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
1522 }
1523
1524 /// Gets the current configuration applied to all new channels,  as
1525 #[must_use]
1526 #[no_mangle]
1527 pub extern "C" fn ChannelManager_get_current_default_configuration(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::util::config::UserConfig {
1528         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_current_default_configuration();
1529         crate::lightning::util::config::UserConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::util::config::UserConfig<>) as *mut _) }, is_owned: false }
1530 }
1531
1532 /// Creates a new outbound channel to the given remote node and with the given value.
1533 ///
1534 /// `user_channel_id` will be provided back as in
1535 /// [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
1536 /// correspond with which `create_channel` call. Note that the `user_channel_id` defaults to 0
1537 /// for inbound channels, so you may wish to avoid using 0 for `user_channel_id` here.
1538 /// `user_channel_id` has no meaning inside of LDK, it is simply copied to events and otherwise
1539 /// ignored.
1540 ///
1541 /// Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is
1542 /// greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`.
1543 ///
1544 /// Note that we do not check if you are currently connected to the given peer. If no
1545 /// connection is available, the outbound `open_channel` message may fail to send, resulting in
1546 /// the channel eventually being silently forgotten (dropped on reload).
1547 ///
1548 /// Returns the new Channel's temporary `channel_id`. This ID will appear as
1549 /// [`Event::FundingGenerationReady::temporary_channel_id`] and in
1550 /// [`ChannelDetails::channel_id`] until after
1551 /// [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
1552 /// one derived from the funding transaction's TXID. If the counterparty rejects the channel
1553 /// immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
1554 ///
1555 /// [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
1556 /// [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
1557 /// [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
1558 ///
1559 /// Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
1560 #[must_use]
1561 #[no_mangle]
1562 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 {
1563         let mut local_override_config = if override_config.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(override_config.take_inner()) } }) };
1564         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);
1565         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() };
1566         local_ret
1567 }
1568
1569 /// Gets the list of open channels, in random order. See ChannelDetail field documentation for
1570 /// more information.
1571 #[must_use]
1572 #[no_mangle]
1573 pub extern "C" fn ChannelManager_list_channels(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1574         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_channels();
1575         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 } }); };
1576         local_ret.into()
1577 }
1578
1579 /// Gets the list of usable channels, in random order. Useful as an argument to [`find_route`]
1580 /// to ensure non-announced channels are used.
1581 ///
1582 /// These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
1583 /// documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
1584 /// are.
1585 ///
1586 /// [`find_route`]: crate::routing::router::find_route
1587 #[must_use]
1588 #[no_mangle]
1589 pub extern "C" fn ChannelManager_list_usable_channels(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1590         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_usable_channels();
1591         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 } }); };
1592         local_ret.into()
1593 }
1594
1595 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
1596 /// will be accepted on the given channel, and after additional timeout/the closing of all
1597 /// pending HTLCs, the channel will be closed on chain.
1598 ///
1599 ///  * If we are the channel initiator, we will pay between our [`Background`] and
1600 ///    [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
1601 ///    estimate.
1602 ///  * If our counterparty is the channel initiator, we will require a channel closing
1603 ///    transaction feerate of at least our [`Background`] feerate or the feerate which
1604 ///    would appear on a force-closure transaction, whichever is lower. We will allow our
1605 ///    counterparty to pay as much fee as they'd like, however.
1606 ///
1607 /// May generate a SendShutdown message event on success, which should be relayed.
1608 ///
1609 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
1610 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1611 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1612 #[must_use]
1613 #[no_mangle]
1614 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 {
1615         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel(unsafe { &*channel_id}, &counterparty_node_id.into_rust());
1616         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() };
1617         local_ret
1618 }
1619
1620 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
1621 /// will be accepted on the given channel, and after additional timeout/the closing of all
1622 /// pending HTLCs, the channel will be closed on chain.
1623 ///
1624 /// `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
1625 /// the channel being closed or not:
1626 ///  * If we are the channel initiator, we will pay at least this feerate on the closing
1627 ///    transaction. The upper-bound is set by
1628 ///    [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
1629 ///    estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
1630 ///  * If our counterparty is the channel initiator, we will refuse to accept a channel closure
1631 ///    transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
1632 ///    will appear on a force-closure transaction, whichever is lower).
1633 ///
1634 /// May generate a SendShutdown message event on success, which should be relayed.
1635 ///
1636 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
1637 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1638 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1639 #[must_use]
1640 #[no_mangle]
1641 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 {
1642         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);
1643         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() };
1644         local_ret
1645 }
1646
1647 /// Force closes a channel, immediately broadcasting the latest local commitment transaction to
1648 /// the chain and rejecting new HTLCs on the given channel. Fails if `channel_id` is unknown to
1649 /// the manager, or if the `counterparty_node_id` isn't the counterparty of the corresponding
1650 /// channel.
1651 #[must_use]
1652 #[no_mangle]
1653 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 {
1654         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_channel(unsafe { &*channel_id}, &counterparty_node_id.into_rust());
1655         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() };
1656         local_ret
1657 }
1658
1659 /// Force close all channels, immediately broadcasting the latest local commitment transaction
1660 /// for each to the chain and rejecting new HTLCs on each.
1661 #[no_mangle]
1662 pub extern "C" fn ChannelManager_force_close_all_channels(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
1663         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_all_channels()
1664 }
1665
1666 /// Sends a payment along a given route.
1667 ///
1668 /// Value parameters are provided via the last hop in route, see documentation for RouteHop
1669 /// fields for more info.
1670 ///
1671 /// Note that if the payment_hash already exists elsewhere (eg you're sending a duplicative
1672 /// payment), we don't do anything to stop you! We always try to ensure that if the provided
1673 /// next hop knows the preimage to payment_hash they can claim an additional amount as
1674 /// specified in the last hop in the route! Thus, you should probably do your own
1675 /// payment_preimage tracking (which you should already be doing as they represent \"proof of
1676 /// payment\") and prevent double-sends yourself.
1677 ///
1678 /// May generate SendHTLCs message(s) event on success, which should be relayed.
1679 ///
1680 /// Each path may have a different return value, and PaymentSendValue may return a Vec with
1681 /// each entry matching the corresponding-index entry in the route paths, see
1682 /// PaymentSendFailure for more info.
1683 ///
1684 /// In general, a path may raise:
1685 ///  * APIError::RouteError when an invalid route or forwarding parameter (cltv_delta, fee,
1686 ///    node public key) is specified.
1687 ///  * APIError::ChannelUnavailable if the next-hop channel is not available for updates
1688 ///    (including due to previous monitor update failure or new permanent monitor update
1689 ///    failure).
1690 ///  * APIError::MonitorUpdateFailed if a new monitor update failure prevented sending the
1691 ///    relevant updates.
1692 ///
1693 /// Note that depending on the type of the PaymentSendFailure the HTLC may have been
1694 /// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
1695 /// different route unless you intend to pay twice!
1696 ///
1697 /// payment_secret is unrelated to payment_hash (or PaymentPreimage) and exists to authenticate
1698 /// the sender to the recipient and prevent payment-probing (deanonymization) attacks. For
1699 /// newer nodes, it will be provided to you in the invoice. If you do not have one, the Route
1700 /// must not contain multiple paths as multi-path payments require a recipient-provided
1701 /// payment_secret.
1702 /// If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature
1703 /// bit set (either as required or as available). If multiple paths are present in the Route,
1704 /// we assume the invoice had the basic_mpp feature set.
1705 ///
1706 /// Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
1707 #[must_use]
1708 #[no_mangle]
1709 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 {
1710         let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentSecret(payment_secret.data) }) };
1711         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);
1712         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() };
1713         local_ret
1714 }
1715
1716 /// Retries a payment along the given [`Route`].
1717 ///
1718 /// Errors returned are a superset of those returned from [`send_payment`], so see
1719 /// [`send_payment`] documentation for more details on errors. This method will also error if the
1720 /// retry amount puts the payment more than 10% over the payment's total amount, if the payment
1721 /// for the given `payment_id` cannot be found (likely due to timeout or success), or if
1722 /// further retries have been disabled with [`abandon_payment`].
1723 ///
1724 /// [`send_payment`]: [`ChannelManager::send_payment`]
1725 /// [`abandon_payment`]: [`ChannelManager::abandon_payment`]
1726 #[must_use]
1727 #[no_mangle]
1728 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 {
1729         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.retry_payment(route.get_native_ref(), ::lightning::ln::channelmanager::PaymentId(payment_id.data));
1730         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() };
1731         local_ret
1732 }
1733
1734 /// Signals that no further retries for the given payment will occur.
1735 ///
1736 /// After this method returns, any future calls to [`retry_payment`] for the given `payment_id`
1737 /// will fail with [`PaymentSendFailure::ParameterError`]. If no such event has been generated,
1738 /// an [`Event::PaymentFailed`] event will be generated as soon as there are no remaining
1739 /// pending HTLCs for this payment.
1740 ///
1741 /// Note that calling this method does *not* prevent a payment from succeeding. You must still
1742 /// wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to
1743 /// determine the ultimate status of a payment.
1744 ///
1745 /// [`retry_payment`]: Self::retry_payment
1746 /// [`Event::PaymentFailed`]: events::Event::PaymentFailed
1747 /// [`Event::PaymentSent`]: events::Event::PaymentSent
1748 #[no_mangle]
1749 pub extern "C" fn ChannelManager_abandon_payment(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_id: crate::c_types::ThirtyTwoBytes) {
1750         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.abandon_payment(::lightning::ln::channelmanager::PaymentId(payment_id.data))
1751 }
1752
1753 /// Send a spontaneous payment, which is a payment that does not require the recipient to have
1754 /// generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
1755 /// the preimage, it must be a cryptographically secure random value that no intermediate node
1756 /// would be able to guess -- otherwise, an intermediate node may claim the payment and it will
1757 /// never reach the recipient.
1758 ///
1759 /// See [`send_payment`] documentation for more details on the return value of this function.
1760 ///
1761 /// Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
1762 /// [`send_payment`] for more information about the risks of duplicate preimage usage.
1763 ///
1764 /// Note that `route` must have exactly one path.
1765 ///
1766 /// [`send_payment`]: Self::send_payment
1767 ///
1768 /// Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None
1769 #[must_use]
1770 #[no_mangle]
1771 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 {
1772         let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
1773         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_spontaneous_payment(route.get_native_ref(), local_payment_preimage);
1774         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() };
1775         local_ret
1776 }
1777
1778 /// Call this upon creation of a funding transaction for the given channel.
1779 ///
1780 /// Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
1781 /// or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
1782 ///
1783 /// Returns [`APIError::ChannelUnavailable`] if a funding transaction has already been provided
1784 /// for the channel or if the channel has been closed as indicated by [`Event::ChannelClosed`].
1785 ///
1786 /// May panic if the output found in the funding transaction is duplicative with some other
1787 /// channel (note that this should be trivially prevented by using unique funding transaction
1788 /// keys per-channel).
1789 ///
1790 /// Do NOT broadcast the funding transaction yourself. When we have safely received our
1791 /// counterparty's signature the funding transaction will automatically be broadcast via the
1792 /// [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
1793 ///
1794 /// Note that this includes RBF or similar transaction replacement strategies - lightning does
1795 /// not currently support replacing a funding transaction on an existing channel. Instead,
1796 /// create a new channel with a conflicting funding transaction.
1797 ///
1798 /// [`Event::FundingGenerationReady`]: crate::util::events::Event::FundingGenerationReady
1799 /// [`Event::ChannelClosed`]: crate::util::events::Event::ChannelClosed
1800 #[must_use]
1801 #[no_mangle]
1802 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 {
1803         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());
1804         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() };
1805         local_ret
1806 }
1807
1808 /// Regenerates channel_announcements and generates a signed node_announcement from the given
1809 /// arguments, providing them in corresponding events via
1810 /// [`get_and_clear_pending_msg_events`], if at least one public channel has been confirmed
1811 /// on-chain. This effectively re-broadcasts all channel announcements and sends our node
1812 /// announcement to ensure that the lightning P2P network is aware of the channels we have and
1813 /// our network addresses.
1814 ///
1815 /// `rgb` is a node \"color\" and `alias` is a printable human-readable string to describe this
1816 /// node to humans. They carry no in-protocol meaning.
1817 ///
1818 /// `addresses` represent the set (possibly empty) of socket addresses on which this node
1819 /// accepts incoming connections. These will be included in the node_announcement, publicly
1820 /// tying these addresses together and to this node. If you wish to preserve user privacy,
1821 /// addresses should likely contain only Tor Onion addresses.
1822 ///
1823 /// Panics if `addresses` is absurdly large (more than 500).
1824 ///
1825 /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
1826 #[no_mangle]
1827 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) {
1828         let mut local_addresses = Vec::new(); for mut item in addresses.into_rust().drain(..) { local_addresses.push( { item.into_native() }); };
1829         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.broadcast_node_announcement(rgb.data, alias.data, local_addresses)
1830 }
1831
1832 /// Processes HTLCs which are pending waiting on random forward delay.
1833 ///
1834 /// Should only really ever be called in response to a PendingHTLCsForwardable event.
1835 /// Will likely generate further events.
1836 #[no_mangle]
1837 pub extern "C" fn ChannelManager_process_pending_htlc_forwards(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
1838         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_pending_htlc_forwards()
1839 }
1840
1841 /// Performs actions which should happen on startup and roughly once per minute thereafter.
1842 ///
1843 /// This currently includes:
1844 ///  * Increasing or decreasing the on-chain feerate estimates for our outbound channels,
1845 ///  * Broadcasting `ChannelUpdate` messages if we've been disconnected from our peer for more
1846 ///    than a minute, informing the network that they should no longer attempt to route over
1847 ///    the channel.
1848 ///
1849 /// Note that this may cause reentrancy through `chain::Watch::update_channel` calls or feerate
1850 /// estimate fetches.
1851 #[no_mangle]
1852 pub extern "C" fn ChannelManager_timer_tick_occurred(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
1853         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timer_tick_occurred()
1854 }
1855
1856 /// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
1857 /// after a PaymentReceived event, failing the HTLC back to its origin and freeing resources
1858 /// along the path (including in our own channel on which we received it).
1859 ///
1860 /// Note that in some cases around unclean shutdown, it is possible the payment may have
1861 /// already been claimed by you via [`ChannelManager::claim_funds`] prior to you seeing (a
1862 /// second copy of) the [`events::Event::PaymentReceived`] event. Alternatively, the payment
1863 /// may have already been failed automatically by LDK if it was nearing its expiration time.
1864 ///
1865 /// While LDK will never claim a payment automatically on your behalf (i.e. without you calling
1866 /// [`ChannelManager::claim_funds`]), you should still monitor for
1867 /// [`events::Event::PaymentClaimed`] events even for payments you intend to fail, especially on
1868 /// startup during which time claims that were in-progress at shutdown may be replayed.
1869 #[no_mangle]
1870 pub extern "C" fn ChannelManager_fail_htlc_backwards(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, payment_hash: *const [u8; 32]) {
1871         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_htlc_backwards(&::lightning::ln::PaymentHash(unsafe { *payment_hash }))
1872 }
1873
1874 /// Provides a payment preimage in response to [`Event::PaymentReceived`], generating any
1875 /// [`MessageSendEvent`]s needed to claim the payment.
1876 ///
1877 /// Note that calling this method does *not* guarantee that the payment has been claimed. You
1878 /// *must* wait for an [`Event::PaymentClaimed`] event which upon a successful claim will be
1879 /// provided to your [`EventHandler`] when [`process_pending_events`] is next called.
1880 ///
1881 /// Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
1882 /// [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentReceived`
1883 /// event matches your expectation. If you fail to do so and call this method, you may provide
1884 /// the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
1885 ///
1886 /// [`Event::PaymentReceived`]: crate::util::events::Event::PaymentReceived
1887 /// [`Event::PaymentClaimed`]: crate::util::events::Event::PaymentClaimed
1888 /// [`process_pending_events`]: EventsProvider::process_pending_events
1889 /// [`create_inbound_payment`]: Self::create_inbound_payment
1890 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1891 /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
1892 #[no_mangle]
1893 pub extern "C" fn ChannelManager_claim_funds(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_preimage: crate::c_types::ThirtyTwoBytes) {
1894         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.claim_funds(::lightning::ln::PaymentPreimage(payment_preimage.data))
1895 }
1896
1897 /// Gets the node_id held by this ChannelManager
1898 #[must_use]
1899 #[no_mangle]
1900 pub extern "C" fn ChannelManager_get_our_node_id(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::PublicKey {
1901         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_our_node_id();
1902         crate::c_types::PublicKey::from_rust(&ret)
1903 }
1904
1905 /// Accepts a request to open a channel after a [`Event::OpenChannelRequest`].
1906 ///
1907 /// The `temporary_channel_id` parameter indicates which inbound channel should be accepted,
1908 /// and the `counterparty_node_id` parameter is the id of the peer which has requested to open
1909 /// the channel.
1910 ///
1911 /// The `user_channel_id` parameter will be provided back in
1912 /// [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
1913 /// with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
1914 ///
1915 /// Note that this method will return an error and reject the channel, if it requires support
1916 /// for zero confirmations. Instead, `accept_inbound_channel_from_trusted_peer_0conf` must be
1917 /// used to accept such channels.
1918 ///
1919 /// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
1920 /// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
1921 #[must_use]
1922 #[no_mangle]
1923 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 {
1924         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);
1925         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() };
1926         local_ret
1927 }
1928
1929 /// Accepts a request to open a channel after a [`events::Event::OpenChannelRequest`], treating
1930 /// it as confirmed immediately.
1931 ///
1932 /// The `user_channel_id` parameter will be provided back in
1933 /// [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
1934 /// with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
1935 ///
1936 /// Unlike [`ChannelManager::accept_inbound_channel`], this method accepts the incoming channel
1937 /// and (if the counterparty agrees), enables forwarding of payments immediately.
1938 ///
1939 /// This fully trusts that the counterparty has honestly and correctly constructed the funding
1940 /// transaction and blindly assumes that it will eventually confirm.
1941 ///
1942 /// If it does not confirm before we decide to close the channel, or if the funding transaction
1943 /// does not pay to the correct script the correct amount, *you will lose funds*.
1944 ///
1945 /// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
1946 /// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
1947 #[must_use]
1948 #[no_mangle]
1949 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 {
1950         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);
1951         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() };
1952         local_ret
1953 }
1954
1955 /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
1956 /// to pay us.
1957 ///
1958 /// This differs from [`create_inbound_payment_for_hash`] only in that it generates the
1959 /// [`PaymentHash`] and [`PaymentPreimage`] for you.
1960 ///
1961 /// The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentReceived`], which
1962 /// will have the [`PaymentReceived::payment_preimage`] field filled in. That should then be
1963 /// passed directly to [`claim_funds`].
1964 ///
1965 /// See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
1966 ///
1967 /// Note that a malicious eavesdropper can intuit whether an inbound payment was created by
1968 /// `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
1969 ///
1970 /// # Note
1971 ///
1972 /// If you register an inbound payment with this method, then serialize the `ChannelManager`, then
1973 /// deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
1974 ///
1975 /// Errors if `min_value_msat` is greater than total bitcoin supply.
1976 ///
1977 /// [`claim_funds`]: Self::claim_funds
1978 /// [`PaymentReceived`]: events::Event::PaymentReceived
1979 /// [`PaymentReceived::payment_preimage`]: events::Event::PaymentReceived::payment_preimage
1980 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1981 #[must_use]
1982 #[no_mangle]
1983 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 {
1984         let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
1985         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment(local_min_value_msat, invoice_expiry_delta_secs);
1986         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() };
1987         local_ret
1988 }
1989
1990 /// Legacy version of [`create_inbound_payment`]. Use this method if you wish to share
1991 /// serialized state with LDK node(s) running 0.0.103 and earlier.
1992 ///
1993 /// May panic if `invoice_expiry_delta_secs` is greater than one year.
1994 ///
1995 /// # Note
1996 /// This method is deprecated and will be removed soon.
1997 ///
1998 /// [`create_inbound_payment`]: Self::create_inbound_payment
1999 #[must_use]
2000 #[no_mangle]
2001 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 {
2002         let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
2003         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment_legacy(local_min_value_msat, invoice_expiry_delta_secs);
2004         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() };
2005         local_ret
2006 }
2007
2008 /// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
2009 /// stored external to LDK.
2010 ///
2011 /// A [`PaymentReceived`] event will only be generated if the [`PaymentSecret`] matches a
2012 /// payment secret fetched via this method or [`create_inbound_payment`], and which is at least
2013 /// the `min_value_msat` provided here, if one is provided.
2014 ///
2015 /// The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) should be globally unique, though
2016 /// note that LDK will not stop you from registering duplicate payment hashes for inbound
2017 /// payments.
2018 ///
2019 /// `min_value_msat` should be set if the invoice being generated contains a value. Any payment
2020 /// received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
2021 /// before a [`PaymentReceived`] event will be generated, ensuring that we do not provide the
2022 /// sender \"proof-of-payment\" unless they have paid the required amount.
2023 ///
2024 /// `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
2025 /// in excess of the current time. This should roughly match the expiry time set in the invoice.
2026 /// After this many seconds, we will remove the inbound payment, resulting in any attempts to
2027 /// pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
2028 /// invoices when no timeout is set.
2029 ///
2030 /// Note that we use block header time to time-out pending inbound payments (with some margin
2031 /// to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
2032 /// accept a payment and generate a [`PaymentReceived`] event for some time after the expiry.
2033 /// If you need exact expiry semantics, you should enforce them upon receipt of
2034 /// [`PaymentReceived`].
2035 ///
2036 /// Note that invoices generated for inbound payments should have their `min_final_cltv_expiry`
2037 /// set to at least [`MIN_FINAL_CLTV_EXPIRY`].
2038 ///
2039 /// Note that a malicious eavesdropper can intuit whether an inbound payment was created by
2040 /// `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
2041 ///
2042 /// # Note
2043 ///
2044 /// If you register an inbound payment with this method, then serialize the `ChannelManager`, then
2045 /// deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
2046 ///
2047 /// Errors if `min_value_msat` is greater than total bitcoin supply.
2048 ///
2049 /// [`create_inbound_payment`]: Self::create_inbound_payment
2050 /// [`PaymentReceived`]: events::Event::PaymentReceived
2051 #[must_use]
2052 #[no_mangle]
2053 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 {
2054         let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
2055         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);
2056         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() };
2057         local_ret
2058 }
2059
2060 /// Legacy version of [`create_inbound_payment_for_hash`]. Use this method if you wish to share
2061 /// serialized state with LDK node(s) running 0.0.103 and earlier.
2062 ///
2063 /// May panic if `invoice_expiry_delta_secs` is greater than one year.
2064 ///
2065 /// # Note
2066 /// This method is deprecated and will be removed soon.
2067 ///
2068 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
2069 #[must_use]
2070 #[no_mangle]
2071 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 {
2072         let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
2073         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);
2074         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() };
2075         local_ret
2076 }
2077
2078 /// Gets an LDK-generated payment preimage from a payment hash and payment secret that were
2079 /// previously returned from [`create_inbound_payment`].
2080 ///
2081 /// [`create_inbound_payment`]: Self::create_inbound_payment
2082 #[must_use]
2083 #[no_mangle]
2084 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 {
2085         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));
2086         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() };
2087         local_ret
2088 }
2089
2090 /// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
2091 /// are used when constructing the phantom invoice's route hints.
2092 ///
2093 /// [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
2094 #[must_use]
2095 #[no_mangle]
2096 pub extern "C" fn ChannelManager_get_phantom_scid(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> u64 {
2097         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_phantom_scid();
2098         ret
2099 }
2100
2101 /// Gets route hints for use in receiving [phantom node payments].
2102 ///
2103 /// [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
2104 #[must_use]
2105 #[no_mangle]
2106 pub extern "C" fn ChannelManager_get_phantom_route_hints(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::ln::channelmanager::PhantomRouteHints {
2107         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_phantom_route_hints();
2108         crate::lightning::ln::channelmanager::PhantomRouteHints { inner: ObjOps::heap_alloc(ret), is_owned: true }
2109 }
2110
2111 impl From<nativeChannelManager> for crate::lightning::util::events::MessageSendEventsProvider {
2112         fn from(obj: nativeChannelManager) -> Self {
2113                 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2114                 let mut ret = ChannelManager_as_MessageSendEventsProvider(&rust_obj);
2115                 // 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
2116                 rust_obj.inner = core::ptr::null_mut();
2117                 ret.free = Some(ChannelManager_free_void);
2118                 ret
2119         }
2120 }
2121 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
2122 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
2123 #[no_mangle]
2124 pub extern "C" fn ChannelManager_as_MessageSendEventsProvider(this_arg: &ChannelManager) -> crate::lightning::util::events::MessageSendEventsProvider {
2125         crate::lightning::util::events::MessageSendEventsProvider {
2126                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2127                 free: None,
2128                 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
2129         }
2130 }
2131
2132 #[must_use]
2133 extern "C" fn ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
2134         let mut ret = <nativeChannelManager as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
2135         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
2136         local_ret.into()
2137 }
2138
2139 impl From<nativeChannelManager> for crate::lightning::util::events::EventsProvider {
2140         fn from(obj: nativeChannelManager) -> Self {
2141                 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2142                 let mut ret = ChannelManager_as_EventsProvider(&rust_obj);
2143                 // 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
2144                 rust_obj.inner = core::ptr::null_mut();
2145                 ret.free = Some(ChannelManager_free_void);
2146                 ret
2147         }
2148 }
2149 /// Constructs a new EventsProvider which calls the relevant methods on this_arg.
2150 /// This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
2151 #[no_mangle]
2152 pub extern "C" fn ChannelManager_as_EventsProvider(this_arg: &ChannelManager) -> crate::lightning::util::events::EventsProvider {
2153         crate::lightning::util::events::EventsProvider {
2154                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2155                 free: None,
2156                 process_pending_events: ChannelManager_EventsProvider_process_pending_events,
2157         }
2158 }
2159
2160 extern "C" fn ChannelManager_EventsProvider_process_pending_events(this_arg: *const c_void, mut handler: crate::lightning::util::events::EventHandler) {
2161         <nativeChannelManager as lightning::util::events::EventsProvider<>>::process_pending_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, handler)
2162 }
2163
2164 impl From<nativeChannelManager> for crate::lightning::chain::Listen {
2165         fn from(obj: nativeChannelManager) -> Self {
2166                 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2167                 let mut ret = ChannelManager_as_Listen(&rust_obj);
2168                 // 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
2169                 rust_obj.inner = core::ptr::null_mut();
2170                 ret.free = Some(ChannelManager_free_void);
2171                 ret
2172         }
2173 }
2174 /// Constructs a new Listen which calls the relevant methods on this_arg.
2175 /// This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
2176 #[no_mangle]
2177 pub extern "C" fn ChannelManager_as_Listen(this_arg: &ChannelManager) -> crate::lightning::chain::Listen {
2178         crate::lightning::chain::Listen {
2179                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2180                 free: None,
2181                 filtered_block_connected: ChannelManager_Listen_filtered_block_connected,
2182                 block_connected: ChannelManager_Listen_block_connected,
2183                 block_disconnected: ChannelManager_Listen_block_disconnected,
2184         }
2185 }
2186
2187 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) {
2188         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 }); };
2189         <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)
2190 }
2191 extern "C" fn ChannelManager_Listen_block_connected(this_arg: *const c_void, mut block: crate::c_types::u8slice, mut height: u32) {
2192         <nativeChannelManager as lightning::chain::Listen<>>::block_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height)
2193 }
2194 extern "C" fn ChannelManager_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
2195         <nativeChannelManager as lightning::chain::Listen<>>::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
2196 }
2197
2198 impl From<nativeChannelManager> for crate::lightning::chain::Confirm {
2199         fn from(obj: nativeChannelManager) -> Self {
2200                 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2201                 let mut ret = ChannelManager_as_Confirm(&rust_obj);
2202                 // 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
2203                 rust_obj.inner = core::ptr::null_mut();
2204                 ret.free = Some(ChannelManager_free_void);
2205                 ret
2206         }
2207 }
2208 /// Constructs a new Confirm which calls the relevant methods on this_arg.
2209 /// This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
2210 #[no_mangle]
2211 pub extern "C" fn ChannelManager_as_Confirm(this_arg: &ChannelManager) -> crate::lightning::chain::Confirm {
2212         crate::lightning::chain::Confirm {
2213                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2214                 free: None,
2215                 transactions_confirmed: ChannelManager_Confirm_transactions_confirmed,
2216                 transaction_unconfirmed: ChannelManager_Confirm_transaction_unconfirmed,
2217                 best_block_updated: ChannelManager_Confirm_best_block_updated,
2218                 get_relevant_txids: ChannelManager_Confirm_get_relevant_txids,
2219         }
2220 }
2221
2222 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) {
2223         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 }); };
2224         <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)
2225 }
2226 extern "C" fn ChannelManager_Confirm_transaction_unconfirmed(this_arg: *const c_void, txid: *const [u8; 32]) {
2227         <nativeChannelManager as lightning::chain::Confirm<>>::transaction_unconfirmed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap())
2228 }
2229 extern "C" fn ChannelManager_Confirm_best_block_updated(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
2230         <nativeChannelManager as lightning::chain::Confirm<>>::best_block_updated(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
2231 }
2232 #[must_use]
2233 extern "C" fn ChannelManager_Confirm_get_relevant_txids(this_arg: *const c_void) -> crate::c_types::derived::CVec_TxidZ {
2234         let mut ret = <nativeChannelManager as lightning::chain::Confirm<>>::get_relevant_txids(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
2235         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::ThirtyTwoBytes { data: item.into_inner() } }); };
2236         local_ret.into()
2237 }
2238
2239 /// Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
2240 /// indicating whether persistence is necessary. Only one listener on
2241 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
2242 /// up.
2243 ///
2244 /// Note that this method is not available with the `no-std` feature.
2245 #[must_use]
2246 #[no_mangle]
2247 pub extern "C" fn ChannelManager_await_persistable_update_timeout(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut max_wait: u64) -> bool {
2248         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.await_persistable_update_timeout(core::time::Duration::from_secs(max_wait));
2249         ret
2250 }
2251
2252 /// Blocks until ChannelManager needs to be persisted. Only one listener on
2253 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
2254 /// up.
2255 #[no_mangle]
2256 pub extern "C" fn ChannelManager_await_persistable_update(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
2257         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.await_persistable_update()
2258 }
2259
2260 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
2261 /// [`chain::Confirm`] interfaces.
2262 #[must_use]
2263 #[no_mangle]
2264 pub extern "C" fn ChannelManager_current_best_block(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::chain::BestBlock {
2265         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
2266         crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
2267 }
2268
2269 impl From<nativeChannelManager> for crate::lightning::ln::msgs::ChannelMessageHandler {
2270         fn from(obj: nativeChannelManager) -> Self {
2271                 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2272                 let mut ret = ChannelManager_as_ChannelMessageHandler(&rust_obj);
2273                 // 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
2274                 rust_obj.inner = core::ptr::null_mut();
2275                 ret.free = Some(ChannelManager_free_void);
2276                 ret
2277         }
2278 }
2279 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
2280 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
2281 #[no_mangle]
2282 pub extern "C" fn ChannelManager_as_ChannelMessageHandler(this_arg: &ChannelManager) -> crate::lightning::ln::msgs::ChannelMessageHandler {
2283         crate::lightning::ln::msgs::ChannelMessageHandler {
2284                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2285                 free: None,
2286                 handle_open_channel: ChannelManager_ChannelMessageHandler_handle_open_channel,
2287                 handle_accept_channel: ChannelManager_ChannelMessageHandler_handle_accept_channel,
2288                 handle_funding_created: ChannelManager_ChannelMessageHandler_handle_funding_created,
2289                 handle_funding_signed: ChannelManager_ChannelMessageHandler_handle_funding_signed,
2290                 handle_channel_ready: ChannelManager_ChannelMessageHandler_handle_channel_ready,
2291                 handle_shutdown: ChannelManager_ChannelMessageHandler_handle_shutdown,
2292                 handle_closing_signed: ChannelManager_ChannelMessageHandler_handle_closing_signed,
2293                 handle_update_add_htlc: ChannelManager_ChannelMessageHandler_handle_update_add_htlc,
2294                 handle_update_fulfill_htlc: ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc,
2295                 handle_update_fail_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_htlc,
2296                 handle_update_fail_malformed_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_malformed_htlc,
2297                 handle_commitment_signed: ChannelManager_ChannelMessageHandler_handle_commitment_signed,
2298                 handle_revoke_and_ack: ChannelManager_ChannelMessageHandler_handle_revoke_and_ack,
2299                 handle_update_fee: ChannelManager_ChannelMessageHandler_handle_update_fee,
2300                 handle_announcement_signatures: ChannelManager_ChannelMessageHandler_handle_announcement_signatures,
2301                 peer_disconnected: ChannelManager_ChannelMessageHandler_peer_disconnected,
2302                 peer_connected: ChannelManager_ChannelMessageHandler_peer_connected,
2303                 handle_channel_reestablish: ChannelManager_ChannelMessageHandler_handle_channel_reestablish,
2304                 handle_channel_update: ChannelManager_ChannelMessageHandler_handle_channel_update,
2305                 handle_error: ChannelManager_ChannelMessageHandler_handle_error,
2306                 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
2307                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2308                         free: None,
2309                         get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
2310                 },
2311         }
2312 }
2313
2314 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) {
2315         <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())
2316 }
2317 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) {
2318         <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())
2319 }
2320 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) {
2321         <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())
2322 }
2323 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) {
2324         <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())
2325 }
2326 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) {
2327         <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())
2328 }
2329 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) {
2330         <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())
2331 }
2332 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) {
2333         <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())
2334 }
2335 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) {
2336         <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())
2337 }
2338 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) {
2339         <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())
2340 }
2341 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) {
2342         <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())
2343 }
2344 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) {
2345         <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())
2346 }
2347 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) {
2348         <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())
2349 }
2350 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) {
2351         <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())
2352 }
2353 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) {
2354         <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())
2355 }
2356 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) {
2357         <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())
2358 }
2359 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) {
2360         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), no_connection_possible)
2361 }
2362 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) {
2363         <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())
2364 }
2365 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) {
2366         <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())
2367 }
2368 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) {
2369         <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())
2370 }
2371 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) {
2372         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2373 }
2374
2375 #[no_mangle]
2376 /// Serialize the CounterpartyForwardingInfo object into a byte array which can be read by CounterpartyForwardingInfo_read
2377 pub extern "C" fn CounterpartyForwardingInfo_write(obj: &crate::lightning::ln::channelmanager::CounterpartyForwardingInfo) -> crate::c_types::derived::CVec_u8Z {
2378         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2379 }
2380 #[no_mangle]
2381 pub(crate) extern "C" fn CounterpartyForwardingInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2382         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCounterpartyForwardingInfo) })
2383 }
2384 #[no_mangle]
2385 /// Read a CounterpartyForwardingInfo from a byte array, created by CounterpartyForwardingInfo_write
2386 pub extern "C" fn CounterpartyForwardingInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CounterpartyForwardingInfoDecodeErrorZ {
2387         let res: Result<lightning::ln::channelmanager::CounterpartyForwardingInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2388         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() };
2389         local_res
2390 }
2391 #[no_mangle]
2392 /// Serialize the ChannelCounterparty object into a byte array which can be read by ChannelCounterparty_read
2393 pub extern "C" fn ChannelCounterparty_write(obj: &crate::lightning::ln::channelmanager::ChannelCounterparty) -> crate::c_types::derived::CVec_u8Z {
2394         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2395 }
2396 #[no_mangle]
2397 pub(crate) extern "C" fn ChannelCounterparty_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2398         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelCounterparty) })
2399 }
2400 #[no_mangle]
2401 /// Read a ChannelCounterparty from a byte array, created by ChannelCounterparty_write
2402 pub extern "C" fn ChannelCounterparty_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelCounterpartyDecodeErrorZ {
2403         let res: Result<lightning::ln::channelmanager::ChannelCounterparty, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2404         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() };
2405         local_res
2406 }
2407 #[no_mangle]
2408 /// Serialize the ChannelDetails object into a byte array which can be read by ChannelDetails_read
2409 pub extern "C" fn ChannelDetails_write(obj: &crate::lightning::ln::channelmanager::ChannelDetails) -> crate::c_types::derived::CVec_u8Z {
2410         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2411 }
2412 #[no_mangle]
2413 pub(crate) extern "C" fn ChannelDetails_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2414         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelDetails) })
2415 }
2416 #[no_mangle]
2417 /// Read a ChannelDetails from a byte array, created by ChannelDetails_write
2418 pub extern "C" fn ChannelDetails_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelDetailsDecodeErrorZ {
2419         let res: Result<lightning::ln::channelmanager::ChannelDetails, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2420         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() };
2421         local_res
2422 }
2423 #[no_mangle]
2424 /// Serialize the PhantomRouteHints object into a byte array which can be read by PhantomRouteHints_read
2425 pub extern "C" fn PhantomRouteHints_write(obj: &crate::lightning::ln::channelmanager::PhantomRouteHints) -> crate::c_types::derived::CVec_u8Z {
2426         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2427 }
2428 #[no_mangle]
2429 pub(crate) extern "C" fn PhantomRouteHints_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2430         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePhantomRouteHints) })
2431 }
2432 #[no_mangle]
2433 /// Read a PhantomRouteHints from a byte array, created by PhantomRouteHints_write
2434 pub extern "C" fn PhantomRouteHints_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PhantomRouteHintsDecodeErrorZ {
2435         let res: Result<lightning::ln::channelmanager::PhantomRouteHints, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2436         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() };
2437         local_res
2438 }
2439 #[no_mangle]
2440 /// Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
2441 pub extern "C" fn ChannelManager_write(obj: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_u8Z {
2442         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2443 }
2444 #[no_mangle]
2445 pub(crate) extern "C" fn ChannelManager_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2446         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelManager) })
2447 }
2448
2449 use lightning::ln::channelmanager::ChannelManagerReadArgs as nativeChannelManagerReadArgsImport;
2450 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>;
2451
2452 /// Arguments for the creation of a ChannelManager that are not deserialized.
2453 ///
2454 /// At a high-level, the process for deserializing a ChannelManager and resuming normal operation
2455 /// is:
2456 /// 1) Deserialize all stored [`ChannelMonitor`]s.
2457 /// 2) Deserialize the [`ChannelManager`] by filling in this struct and calling:
2458 ///    `<(BlockHash, ChannelManager)>::read(reader, args)`
2459 ///    This may result in closing some channels if the [`ChannelMonitor`] is newer than the stored
2460 ///    [`ChannelManager`] state to ensure no loss of funds. Thus, transactions may be broadcasted.
2461 /// 3) If you are not fetching full blocks, register all relevant [`ChannelMonitor`] outpoints the
2462 ///    same way you would handle a [`chain::Filter`] call using
2463 ///    [`ChannelMonitor::get_outputs_to_watch`] and [`ChannelMonitor::get_funding_txo`].
2464 /// 4) Reconnect blocks on your [`ChannelMonitor`]s.
2465 /// 5) Disconnect/connect blocks on the [`ChannelManager`].
2466 /// 6) Re-persist the [`ChannelMonitor`]s to ensure the latest state is on disk.
2467 ///    Note that if you're using a [`ChainMonitor`] for your [`chain::Watch`] implementation, you
2468 ///    will likely accomplish this as a side-effect of calling [`chain::Watch::watch_channel`] in
2469 ///    the next step.
2470 /// 7) Move the [`ChannelMonitor`]s into your local [`chain::Watch`]. If you're using a
2471 ///    [`ChainMonitor`], this is done by calling [`chain::Watch::watch_channel`].
2472 ///
2473 /// Note that the ordering of #4-7 is not of importance, however all four must occur before you
2474 /// call any other methods on the newly-deserialized [`ChannelManager`].
2475 ///
2476 /// Note that because some channels may be closed during deserialization, it is critical that you
2477 /// always deserialize only the latest version of a ChannelManager and ChannelMonitors available to
2478 /// you. If you deserialize an old ChannelManager (during which force-closure transactions may be
2479 /// broadcast), and then later deserialize a newer version of the same ChannelManager (which will
2480 /// not force-close the same channels but consider them live), you may end up revoking a state for
2481 /// which you've already broadcasted the transaction.
2482 ///
2483 /// [`ChainMonitor`]: crate::chain::chainmonitor::ChainMonitor
2484 #[must_use]
2485 #[repr(C)]
2486 pub struct ChannelManagerReadArgs {
2487         /// A pointer to the opaque Rust object.
2488
2489         /// Nearly everywhere, inner must be non-null, however in places where
2490         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2491         pub inner: *mut nativeChannelManagerReadArgs,
2492         /// Indicates that this is the only struct which contains the same pointer.
2493
2494         /// Rust functions which take ownership of an object provided via an argument require
2495         /// this to be true and invalidate the object pointed to by inner.
2496         pub is_owned: bool,
2497 }
2498
2499 impl Drop for ChannelManagerReadArgs {
2500         fn drop(&mut self) {
2501                 if self.is_owned && !<*mut nativeChannelManagerReadArgs>::is_null(self.inner) {
2502                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2503                 }
2504         }
2505 }
2506 /// Frees any resources used by the ChannelManagerReadArgs, if is_owned is set and inner is non-NULL.
2507 #[no_mangle]
2508 pub extern "C" fn ChannelManagerReadArgs_free(this_obj: ChannelManagerReadArgs) { }
2509 #[allow(unused)]
2510 /// Used only if an object of this type is returned as a trait impl by a method
2511 pub(crate) extern "C" fn ChannelManagerReadArgs_free_void(this_ptr: *mut c_void) {
2512         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManagerReadArgs); }
2513 }
2514 #[allow(unused)]
2515 impl ChannelManagerReadArgs {
2516         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManagerReadArgs {
2517                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2518         }
2519         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManagerReadArgs {
2520                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2521         }
2522         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2523         pub(crate) fn take_inner(mut self) -> *mut nativeChannelManagerReadArgs {
2524                 assert!(self.is_owned);
2525                 let ret = ObjOps::untweak_ptr(self.inner);
2526                 self.inner = core::ptr::null_mut();
2527                 ret
2528         }
2529 }
2530 /// The keys provider which will give us relevant keys. Some keys will be loaded during
2531 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
2532 /// signing data.
2533 #[no_mangle]
2534 pub extern "C" fn ChannelManagerReadArgs_get_keys_manager(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::keysinterface::KeysInterface {
2535         let mut inner_val = &mut this_ptr.get_native_mut_ref().keys_manager;
2536         inner_val
2537 }
2538 /// The keys provider which will give us relevant keys. Some keys will be loaded during
2539 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
2540 /// signing data.
2541 #[no_mangle]
2542 pub extern "C" fn ChannelManagerReadArgs_set_keys_manager(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::keysinterface::KeysInterface) {
2543         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.keys_manager = val;
2544 }
2545 /// The fee_estimator for use in the ChannelManager in the future.
2546 ///
2547 /// No calls to the FeeEstimator will be made during deserialization.
2548 #[no_mangle]
2549 pub extern "C" fn ChannelManagerReadArgs_get_fee_estimator(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::FeeEstimator {
2550         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_estimator;
2551         inner_val
2552 }
2553 /// The fee_estimator for use in the ChannelManager in the future.
2554 ///
2555 /// No calls to the FeeEstimator will be made during deserialization.
2556 #[no_mangle]
2557 pub extern "C" fn ChannelManagerReadArgs_set_fee_estimator(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::FeeEstimator) {
2558         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_estimator = val;
2559 }
2560 /// The chain::Watch for use in the ChannelManager in the future.
2561 ///
2562 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
2563 /// you have deserialized ChannelMonitors separately and will add them to your
2564 /// chain::Watch after deserializing this ChannelManager.
2565 #[no_mangle]
2566 pub extern "C" fn ChannelManagerReadArgs_get_chain_monitor(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::Watch {
2567         let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_monitor;
2568         inner_val
2569 }
2570 /// The chain::Watch for use in the ChannelManager in the future.
2571 ///
2572 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
2573 /// you have deserialized ChannelMonitors separately and will add them to your
2574 /// chain::Watch after deserializing this ChannelManager.
2575 #[no_mangle]
2576 pub extern "C" fn ChannelManagerReadArgs_set_chain_monitor(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::Watch) {
2577         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_monitor = val;
2578 }
2579 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
2580 /// used to broadcast the latest local commitment transactions of channels which must be
2581 /// force-closed during deserialization.
2582 #[no_mangle]
2583 pub extern "C" fn ChannelManagerReadArgs_get_tx_broadcaster(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::BroadcasterInterface {
2584         let mut inner_val = &mut this_ptr.get_native_mut_ref().tx_broadcaster;
2585         inner_val
2586 }
2587 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
2588 /// used to broadcast the latest local commitment transactions of channels which must be
2589 /// force-closed during deserialization.
2590 #[no_mangle]
2591 pub extern "C" fn ChannelManagerReadArgs_set_tx_broadcaster(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::BroadcasterInterface) {
2592         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.tx_broadcaster = val;
2593 }
2594 /// The Logger for use in the ChannelManager and which may be used to log information during
2595 /// deserialization.
2596 #[no_mangle]
2597 pub extern "C" fn ChannelManagerReadArgs_get_logger(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::util::logger::Logger {
2598         let mut inner_val = &mut this_ptr.get_native_mut_ref().logger;
2599         inner_val
2600 }
2601 /// The Logger for use in the ChannelManager and which may be used to log information during
2602 /// deserialization.
2603 #[no_mangle]
2604 pub extern "C" fn ChannelManagerReadArgs_set_logger(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::logger::Logger) {
2605         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.logger = val;
2606 }
2607 /// Default settings used for new channels. Any existing channels will continue to use the
2608 /// runtime settings which were stored when the ChannelManager was serialized.
2609 #[no_mangle]
2610 pub extern "C" fn ChannelManagerReadArgs_get_default_config(this_ptr: &ChannelManagerReadArgs) -> crate::lightning::util::config::UserConfig {
2611         let mut inner_val = &mut this_ptr.get_native_mut_ref().default_config;
2612         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 }
2613 }
2614 /// Default settings used for new channels. Any existing channels will continue to use the
2615 /// runtime settings which were stored when the ChannelManager was serialized.
2616 #[no_mangle]
2617 pub extern "C" fn ChannelManagerReadArgs_set_default_config(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::config::UserConfig) {
2618         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.default_config = *unsafe { Box::from_raw(val.take_inner()) };
2619 }
2620 /// Simple utility function to create a ChannelManagerReadArgs which creates the monitor
2621 /// HashMap for you. This is primarily useful for C bindings where it is not practical to
2622 /// populate a HashMap directly from C.
2623 #[must_use]
2624 #[no_mangle]
2625 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 {
2626         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() }); };
2627         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);
2628         crate::lightning::ln::channelmanager::ChannelManagerReadArgs { inner: ObjOps::heap_alloc(ret), is_owned: true }
2629 }
2630
2631 #[no_mangle]
2632 /// Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_write
2633 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 {
2634         let arg_conv = *unsafe { Box::from_raw(arg.take_inner()) };
2635         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);
2636         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() };
2637         local_res
2638 }