Merge pull request #45 from TheBlueMatt/main
[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 routing::router::get_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
20 use std::str::FromStr;
21 use std::ffi::c_void;
22 use core::convert::Infallible;
23 use bitcoin::hashes::Hash;
24 use crate::c_types::*;
25
26
27 use lightning::ln::channelmanager::ChannelManager as nativeChannelManagerImport;
28 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>;
29
30 /// Manager which keeps track of a number of channels and sends messages to the appropriate
31 /// channel, also tracking HTLC preimages and forwarding onion packets appropriately.
32 ///
33 /// Implements ChannelMessageHandler, handling the multi-channel parts and passing things through
34 /// to individual Channels.
35 ///
36 /// Implements Writeable to write out all channel state to disk. Implies peer_disconnected() for
37 /// all peers during write/read (though does not modify this instance, only the instance being
38 /// serialized). This will result in any channels which have not yet exchanged funding_created (ie
39 /// called funding_transaction_generated for outbound channels).
40 ///
41 /// Note that you can be a bit lazier about writing out ChannelManager than you can be with
42 /// ChannelMonitors. With ChannelMonitors you MUST write each monitor update out to disk before
43 /// returning from chain::Watch::watch_/update_channel, with ChannelManagers, writing updates
44 /// happens out-of-band (and will prevent any other ChannelManager operations from occurring during
45 /// the serialization process). If the deserialized version is out-of-date compared to the
46 /// ChannelMonitors passed by reference to read(), those channels will be force-closed based on the
47 /// ChannelMonitor state and no funds will be lost (mod on-chain transaction fees).
48 ///
49 /// Note that the deserializer is only implemented for (BlockHash, ChannelManager), which
50 /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
51 /// the \"reorg path\" (ie call block_disconnected() until you get to a common block and then call
52 /// block_connected() to step towards your best block) upon deserialization before using the
53 /// object!
54 ///
55 /// Note that ChannelManager is responsible for tracking liveness of its channels and generating
56 /// ChannelUpdate messages informing peers that the channel is temporarily disabled. To avoid
57 /// spam due to quick disconnection/reconnection, updates are not sent until the channel has been
58 /// offline for a full minute. In order to track this, you must call
59 /// timer_tick_occurred roughly once per minute, though it doesn't have to be perfect.
60 ///
61 /// Rather than using a plain ChannelManager, it is preferable to use either a SimpleArcChannelManager
62 /// a SimpleRefChannelManager, for conciseness. See their documentation for more details, but
63 /// essentially you should default to using a SimpleRefChannelManager, and use a
64 /// SimpleArcChannelManager when you require a ChannelManager with a static lifetime, such as when
65 /// you're using lightning-net-tokio.
66 #[must_use]
67 #[repr(C)]
68 pub struct ChannelManager {
69         /// A pointer to the opaque Rust object.
70
71         /// Nearly everywhere, inner must be non-null, however in places where
72         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
73         pub inner: *mut nativeChannelManager,
74         /// Indicates that this is the only struct which contains the same pointer.
75
76         /// Rust functions which take ownership of an object provided via an argument require
77         /// this to be true and invalidate the object pointed to by inner.
78         pub is_owned: bool,
79 }
80
81 impl Drop for ChannelManager {
82         fn drop(&mut self) {
83                 if self.is_owned && !<*mut nativeChannelManager>::is_null(self.inner) {
84                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
85                 }
86         }
87 }
88 /// Frees any resources used by the ChannelManager, if is_owned is set and inner is non-NULL.
89 #[no_mangle]
90 pub extern "C" fn ChannelManager_free(this_obj: ChannelManager) { }
91 #[allow(unused)]
92 /// Used only if an object of this type is returned as a trait impl by a method
93 extern "C" fn ChannelManager_free_void(this_ptr: *mut c_void) {
94         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManager); }
95 }
96 #[allow(unused)]
97 impl ChannelManager {
98         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManager {
99                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
100         }
101         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManager {
102                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
103         }
104         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
105         pub(crate) fn take_inner(mut self) -> *mut nativeChannelManager {
106                 assert!(self.is_owned);
107                 let ret = ObjOps::untweak_ptr(self.inner);
108                 self.inner = std::ptr::null_mut();
109                 ret
110         }
111 }
112
113 use lightning::ln::channelmanager::ChainParameters as nativeChainParametersImport;
114 type nativeChainParameters = nativeChainParametersImport;
115
116 /// Chain-related parameters used to construct a new `ChannelManager`.
117 ///
118 /// Typically, the block-specific parameters are derived from the best block hash for the network,
119 /// as a newly constructed `ChannelManager` will not have created any channels yet. These parameters
120 /// are not needed when deserializing a previously constructed `ChannelManager`.
121 #[must_use]
122 #[repr(C)]
123 pub struct ChainParameters {
124         /// A pointer to the opaque Rust object.
125
126         /// Nearly everywhere, inner must be non-null, however in places where
127         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
128         pub inner: *mut nativeChainParameters,
129         /// Indicates that this is the only struct which contains the same pointer.
130
131         /// Rust functions which take ownership of an object provided via an argument require
132         /// this to be true and invalidate the object pointed to by inner.
133         pub is_owned: bool,
134 }
135
136 impl Drop for ChainParameters {
137         fn drop(&mut self) {
138                 if self.is_owned && !<*mut nativeChainParameters>::is_null(self.inner) {
139                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
140                 }
141         }
142 }
143 /// Frees any resources used by the ChainParameters, if is_owned is set and inner is non-NULL.
144 #[no_mangle]
145 pub extern "C" fn ChainParameters_free(this_obj: ChainParameters) { }
146 #[allow(unused)]
147 /// Used only if an object of this type is returned as a trait impl by a method
148 extern "C" fn ChainParameters_free_void(this_ptr: *mut c_void) {
149         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChainParameters); }
150 }
151 #[allow(unused)]
152 impl ChainParameters {
153         pub(crate) fn get_native_ref(&self) -> &'static nativeChainParameters {
154                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
155         }
156         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChainParameters {
157                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
158         }
159         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
160         pub(crate) fn take_inner(mut self) -> *mut nativeChainParameters {
161                 assert!(self.is_owned);
162                 let ret = ObjOps::untweak_ptr(self.inner);
163                 self.inner = std::ptr::null_mut();
164                 ret
165         }
166 }
167 /// The network for determining the `chain_hash` in Lightning messages.
168 #[no_mangle]
169 pub extern "C" fn ChainParameters_get_network(this_ptr: &ChainParameters) -> crate::bitcoin::network::Network {
170         let mut inner_val = &mut this_ptr.get_native_mut_ref().network;
171         crate::bitcoin::network::Network::from_bitcoin(inner_val)
172 }
173 /// The network for determining the `chain_hash` in Lightning messages.
174 #[no_mangle]
175 pub extern "C" fn ChainParameters_set_network(this_ptr: &mut ChainParameters, mut val: crate::bitcoin::network::Network) {
176         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.network = val.into_bitcoin();
177 }
178 /// The hash and height of the latest block successfully connected.
179 ///
180 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
181 #[no_mangle]
182 pub extern "C" fn ChainParameters_get_best_block(this_ptr: &ChainParameters) -> crate::lightning::chain::BestBlock {
183         let mut inner_val = &mut this_ptr.get_native_mut_ref().best_block;
184         crate::lightning::chain::BestBlock { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
185 }
186 /// The hash and height of the latest block successfully connected.
187 ///
188 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
189 #[no_mangle]
190 pub extern "C" fn ChainParameters_set_best_block(this_ptr: &mut ChainParameters, mut val: crate::lightning::chain::BestBlock) {
191         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.best_block = *unsafe { Box::from_raw(val.take_inner()) };
192 }
193 /// Constructs a new ChainParameters given each field
194 #[must_use]
195 #[no_mangle]
196 pub extern "C" fn ChainParameters_new(mut network_arg: crate::bitcoin::network::Network, mut best_block_arg: crate::lightning::chain::BestBlock) -> ChainParameters {
197         ChainParameters { inner: ObjOps::heap_alloc(nativeChainParameters {
198                 network: network_arg.into_bitcoin(),
199                 best_block: *unsafe { Box::from_raw(best_block_arg.take_inner()) },
200         }), is_owned: true }
201 }
202 impl Clone for ChainParameters {
203         fn clone(&self) -> Self {
204                 Self {
205                         inner: if <*mut nativeChainParameters>::is_null(self.inner) { std::ptr::null_mut() } else {
206                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
207                         is_owned: true,
208                 }
209         }
210 }
211 #[allow(unused)]
212 /// Used only if an object of this type is returned as a trait impl by a method
213 pub(crate) extern "C" fn ChainParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
214         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChainParameters)).clone() })) as *mut c_void
215 }
216 #[no_mangle]
217 /// Creates a copy of the ChainParameters
218 pub extern "C" fn ChainParameters_clone(orig: &ChainParameters) -> ChainParameters {
219         orig.clone()
220 }
221 /// The amount of time in blocks we require our counterparty wait to claim their money (ie time
222 /// between when we, or our watchtower, must check for them having broadcast a theft transaction).
223 ///
224 /// This can be increased (but not decreased) through [`ChannelHandshakeConfig::our_to_self_delay`]
225 ///
226 /// [`ChannelHandshakeConfig::our_to_self_delay`]: crate::util::config::ChannelHandshakeConfig::our_to_self_delay
227
228 #[no_mangle]
229 pub static BREAKDOWN_TIMEOUT: u16 = lightning::ln::channelmanager::BREAKDOWN_TIMEOUT;
230 /// The minimum number of blocks between an inbound HTLC's CLTV and the corresponding outbound
231 /// HTLC's CLTV. The current default represents roughly seven hours of blocks at six blocks/hour.
232 ///
233 /// This can be increased (but not decreased) through [`ChannelConfig::cltv_expiry_delta`]
234 ///
235 /// [`ChannelConfig::cltv_expiry_delta`]: crate::util::config::ChannelConfig::cltv_expiry_delta
236
237 #[no_mangle]
238 pub static MIN_CLTV_EXPIRY_DELTA: u16 = lightning::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA;
239 /// Minimum CLTV difference between the current block height and received inbound payments.
240 /// Invoices generated for payment to us must set their `min_final_cltv_expiry` field to at least
241 /// this value.
242
243 #[no_mangle]
244 pub static MIN_FINAL_CLTV_EXPIRY: u32 = lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY;
245
246 use lightning::ln::channelmanager::CounterpartyForwardingInfo as nativeCounterpartyForwardingInfoImport;
247 type nativeCounterpartyForwardingInfo = nativeCounterpartyForwardingInfoImport;
248
249 /// Information needed for constructing an invoice route hint for this channel.
250 #[must_use]
251 #[repr(C)]
252 pub struct CounterpartyForwardingInfo {
253         /// A pointer to the opaque Rust object.
254
255         /// Nearly everywhere, inner must be non-null, however in places where
256         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
257         pub inner: *mut nativeCounterpartyForwardingInfo,
258         /// Indicates that this is the only struct which contains the same pointer.
259
260         /// Rust functions which take ownership of an object provided via an argument require
261         /// this to be true and invalidate the object pointed to by inner.
262         pub is_owned: bool,
263 }
264
265 impl Drop for CounterpartyForwardingInfo {
266         fn drop(&mut self) {
267                 if self.is_owned && !<*mut nativeCounterpartyForwardingInfo>::is_null(self.inner) {
268                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
269                 }
270         }
271 }
272 /// Frees any resources used by the CounterpartyForwardingInfo, if is_owned is set and inner is non-NULL.
273 #[no_mangle]
274 pub extern "C" fn CounterpartyForwardingInfo_free(this_obj: CounterpartyForwardingInfo) { }
275 #[allow(unused)]
276 /// Used only if an object of this type is returned as a trait impl by a method
277 extern "C" fn CounterpartyForwardingInfo_free_void(this_ptr: *mut c_void) {
278         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCounterpartyForwardingInfo); }
279 }
280 #[allow(unused)]
281 impl CounterpartyForwardingInfo {
282         pub(crate) fn get_native_ref(&self) -> &'static nativeCounterpartyForwardingInfo {
283                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
284         }
285         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCounterpartyForwardingInfo {
286                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
287         }
288         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
289         pub(crate) fn take_inner(mut self) -> *mut nativeCounterpartyForwardingInfo {
290                 assert!(self.is_owned);
291                 let ret = ObjOps::untweak_ptr(self.inner);
292                 self.inner = std::ptr::null_mut();
293                 ret
294         }
295 }
296 /// Base routing fee in millisatoshis.
297 #[no_mangle]
298 pub extern "C" fn CounterpartyForwardingInfo_get_fee_base_msat(this_ptr: &CounterpartyForwardingInfo) -> u32 {
299         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_base_msat;
300         *inner_val
301 }
302 /// Base routing fee in millisatoshis.
303 #[no_mangle]
304 pub extern "C" fn CounterpartyForwardingInfo_set_fee_base_msat(this_ptr: &mut CounterpartyForwardingInfo, mut val: u32) {
305         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_base_msat = val;
306 }
307 /// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
308 #[no_mangle]
309 pub extern "C" fn CounterpartyForwardingInfo_get_fee_proportional_millionths(this_ptr: &CounterpartyForwardingInfo) -> u32 {
310         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_proportional_millionths;
311         *inner_val
312 }
313 /// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
314 #[no_mangle]
315 pub extern "C" fn CounterpartyForwardingInfo_set_fee_proportional_millionths(this_ptr: &mut CounterpartyForwardingInfo, mut val: u32) {
316         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_proportional_millionths = val;
317 }
318 /// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
319 /// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
320 /// `cltv_expiry_delta` for more details.
321 #[no_mangle]
322 pub extern "C" fn CounterpartyForwardingInfo_get_cltv_expiry_delta(this_ptr: &CounterpartyForwardingInfo) -> u16 {
323         let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
324         *inner_val
325 }
326 /// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
327 /// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
328 /// `cltv_expiry_delta` for more details.
329 #[no_mangle]
330 pub extern "C" fn CounterpartyForwardingInfo_set_cltv_expiry_delta(this_ptr: &mut CounterpartyForwardingInfo, mut val: u16) {
331         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
332 }
333 /// Constructs a new CounterpartyForwardingInfo given each field
334 #[must_use]
335 #[no_mangle]
336 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 {
337         CounterpartyForwardingInfo { inner: ObjOps::heap_alloc(nativeCounterpartyForwardingInfo {
338                 fee_base_msat: fee_base_msat_arg,
339                 fee_proportional_millionths: fee_proportional_millionths_arg,
340                 cltv_expiry_delta: cltv_expiry_delta_arg,
341         }), is_owned: true }
342 }
343 impl Clone for CounterpartyForwardingInfo {
344         fn clone(&self) -> Self {
345                 Self {
346                         inner: if <*mut nativeCounterpartyForwardingInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
347                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
348                         is_owned: true,
349                 }
350         }
351 }
352 #[allow(unused)]
353 /// Used only if an object of this type is returned as a trait impl by a method
354 pub(crate) extern "C" fn CounterpartyForwardingInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
355         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCounterpartyForwardingInfo)).clone() })) as *mut c_void
356 }
357 #[no_mangle]
358 /// Creates a copy of the CounterpartyForwardingInfo
359 pub extern "C" fn CounterpartyForwardingInfo_clone(orig: &CounterpartyForwardingInfo) -> CounterpartyForwardingInfo {
360         orig.clone()
361 }
362
363 use lightning::ln::channelmanager::ChannelCounterparty as nativeChannelCounterpartyImport;
364 type nativeChannelCounterparty = nativeChannelCounterpartyImport;
365
366 /// Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
367 /// to better separate parameters.
368 #[must_use]
369 #[repr(C)]
370 pub struct ChannelCounterparty {
371         /// A pointer to the opaque Rust object.
372
373         /// Nearly everywhere, inner must be non-null, however in places where
374         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
375         pub inner: *mut nativeChannelCounterparty,
376         /// Indicates that this is the only struct which contains the same pointer.
377
378         /// Rust functions which take ownership of an object provided via an argument require
379         /// this to be true and invalidate the object pointed to by inner.
380         pub is_owned: bool,
381 }
382
383 impl Drop for ChannelCounterparty {
384         fn drop(&mut self) {
385                 if self.is_owned && !<*mut nativeChannelCounterparty>::is_null(self.inner) {
386                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
387                 }
388         }
389 }
390 /// Frees any resources used by the ChannelCounterparty, if is_owned is set and inner is non-NULL.
391 #[no_mangle]
392 pub extern "C" fn ChannelCounterparty_free(this_obj: ChannelCounterparty) { }
393 #[allow(unused)]
394 /// Used only if an object of this type is returned as a trait impl by a method
395 extern "C" fn ChannelCounterparty_free_void(this_ptr: *mut c_void) {
396         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelCounterparty); }
397 }
398 #[allow(unused)]
399 impl ChannelCounterparty {
400         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelCounterparty {
401                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
402         }
403         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelCounterparty {
404                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
405         }
406         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
407         pub(crate) fn take_inner(mut self) -> *mut nativeChannelCounterparty {
408                 assert!(self.is_owned);
409                 let ret = ObjOps::untweak_ptr(self.inner);
410                 self.inner = std::ptr::null_mut();
411                 ret
412         }
413 }
414 /// The node_id of our counterparty
415 #[no_mangle]
416 pub extern "C" fn ChannelCounterparty_get_node_id(this_ptr: &ChannelCounterparty) -> crate::c_types::PublicKey {
417         let mut inner_val = &mut this_ptr.get_native_mut_ref().node_id;
418         crate::c_types::PublicKey::from_rust(&inner_val)
419 }
420 /// The node_id of our counterparty
421 #[no_mangle]
422 pub extern "C" fn ChannelCounterparty_set_node_id(this_ptr: &mut ChannelCounterparty, mut val: crate::c_types::PublicKey) {
423         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_id = val.into_rust();
424 }
425 /// The Features the channel counterparty provided upon last connection.
426 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
427 /// many routing-relevant features are present in the init context.
428 #[no_mangle]
429 pub extern "C" fn ChannelCounterparty_get_features(this_ptr: &ChannelCounterparty) -> crate::lightning::ln::features::InitFeatures {
430         let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
431         crate::lightning::ln::features::InitFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
432 }
433 /// The Features the channel counterparty provided upon last connection.
434 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
435 /// many routing-relevant features are present in the init context.
436 #[no_mangle]
437 pub extern "C" fn ChannelCounterparty_set_features(this_ptr: &mut ChannelCounterparty, mut val: crate::lightning::ln::features::InitFeatures) {
438         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
439 }
440 /// The value, in satoshis, that must always be held in the channel for our counterparty. This
441 /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
442 /// claiming at least this value on chain.
443 ///
444 /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
445 ///
446 /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
447 #[no_mangle]
448 pub extern "C" fn ChannelCounterparty_get_unspendable_punishment_reserve(this_ptr: &ChannelCounterparty) -> u64 {
449         let mut inner_val = &mut this_ptr.get_native_mut_ref().unspendable_punishment_reserve;
450         *inner_val
451 }
452 /// The value, in satoshis, that must always be held in the channel for our counterparty. This
453 /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
454 /// claiming at least this value on chain.
455 ///
456 /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
457 ///
458 /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
459 #[no_mangle]
460 pub extern "C" fn ChannelCounterparty_set_unspendable_punishment_reserve(this_ptr: &mut ChannelCounterparty, mut val: u64) {
461         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = val;
462 }
463 /// Information on the fees and requirements that the counterparty requires when forwarding
464 /// payments to us through this channel.
465 ///
466 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
467 #[no_mangle]
468 pub extern "C" fn ChannelCounterparty_get_forwarding_info(this_ptr: &ChannelCounterparty) -> crate::lightning::ln::channelmanager::CounterpartyForwardingInfo {
469         let mut inner_val = &mut this_ptr.get_native_mut_ref().forwarding_info;
470         let mut local_inner_val = crate::lightning::ln::channelmanager::CounterpartyForwardingInfo { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
471         local_inner_val
472 }
473 /// Information on the fees and requirements that the counterparty requires when forwarding
474 /// payments to us through this channel.
475 ///
476 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
477 #[no_mangle]
478 pub extern "C" fn ChannelCounterparty_set_forwarding_info(this_ptr: &mut ChannelCounterparty, mut val: crate::lightning::ln::channelmanager::CounterpartyForwardingInfo) {
479         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
480         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.forwarding_info = local_val;
481 }
482 /// Constructs a new ChannelCounterparty given each field
483 #[must_use]
484 #[no_mangle]
485 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) -> ChannelCounterparty {
486         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()) } }) };
487         ChannelCounterparty { inner: ObjOps::heap_alloc(nativeChannelCounterparty {
488                 node_id: node_id_arg.into_rust(),
489                 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
490                 unspendable_punishment_reserve: unspendable_punishment_reserve_arg,
491                 forwarding_info: local_forwarding_info_arg,
492         }), is_owned: true }
493 }
494 impl Clone for ChannelCounterparty {
495         fn clone(&self) -> Self {
496                 Self {
497                         inner: if <*mut nativeChannelCounterparty>::is_null(self.inner) { std::ptr::null_mut() } else {
498                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
499                         is_owned: true,
500                 }
501         }
502 }
503 #[allow(unused)]
504 /// Used only if an object of this type is returned as a trait impl by a method
505 pub(crate) extern "C" fn ChannelCounterparty_clone_void(this_ptr: *const c_void) -> *mut c_void {
506         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelCounterparty)).clone() })) as *mut c_void
507 }
508 #[no_mangle]
509 /// Creates a copy of the ChannelCounterparty
510 pub extern "C" fn ChannelCounterparty_clone(orig: &ChannelCounterparty) -> ChannelCounterparty {
511         orig.clone()
512 }
513
514 use lightning::ln::channelmanager::ChannelDetails as nativeChannelDetailsImport;
515 type nativeChannelDetails = nativeChannelDetailsImport;
516
517 /// Details of a channel, as returned by ChannelManager::list_channels and ChannelManager::list_usable_channels
518 #[must_use]
519 #[repr(C)]
520 pub struct ChannelDetails {
521         /// A pointer to the opaque Rust object.
522
523         /// Nearly everywhere, inner must be non-null, however in places where
524         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
525         pub inner: *mut nativeChannelDetails,
526         /// Indicates that this is the only struct which contains the same pointer.
527
528         /// Rust functions which take ownership of an object provided via an argument require
529         /// this to be true and invalidate the object pointed to by inner.
530         pub is_owned: bool,
531 }
532
533 impl Drop for ChannelDetails {
534         fn drop(&mut self) {
535                 if self.is_owned && !<*mut nativeChannelDetails>::is_null(self.inner) {
536                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
537                 }
538         }
539 }
540 /// Frees any resources used by the ChannelDetails, if is_owned is set and inner is non-NULL.
541 #[no_mangle]
542 pub extern "C" fn ChannelDetails_free(this_obj: ChannelDetails) { }
543 #[allow(unused)]
544 /// Used only if an object of this type is returned as a trait impl by a method
545 extern "C" fn ChannelDetails_free_void(this_ptr: *mut c_void) {
546         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelDetails); }
547 }
548 #[allow(unused)]
549 impl ChannelDetails {
550         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelDetails {
551                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
552         }
553         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelDetails {
554                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
555         }
556         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
557         pub(crate) fn take_inner(mut self) -> *mut nativeChannelDetails {
558                 assert!(self.is_owned);
559                 let ret = ObjOps::untweak_ptr(self.inner);
560                 self.inner = std::ptr::null_mut();
561                 ret
562         }
563 }
564 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
565 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
566 /// Note that this means this value is *not* persistent - it can change once during the
567 /// lifetime of the channel.
568 #[no_mangle]
569 pub extern "C" fn ChannelDetails_get_channel_id(this_ptr: &ChannelDetails) -> *const [u8; 32] {
570         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id;
571         inner_val
572 }
573 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
574 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
575 /// Note that this means this value is *not* persistent - it can change once during the
576 /// lifetime of the channel.
577 #[no_mangle]
578 pub extern "C" fn ChannelDetails_set_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::ThirtyTwoBytes) {
579         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = val.data;
580 }
581 /// Parameters which apply to our counterparty. See individual fields for more information.
582 #[no_mangle]
583 pub extern "C" fn ChannelDetails_get_counterparty(this_ptr: &ChannelDetails) -> crate::lightning::ln::channelmanager::ChannelCounterparty {
584         let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty;
585         crate::lightning::ln::channelmanager::ChannelCounterparty { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
586 }
587 /// Parameters which apply to our counterparty. See individual fields for more information.
588 #[no_mangle]
589 pub extern "C" fn ChannelDetails_set_counterparty(this_ptr: &mut ChannelDetails, mut val: crate::lightning::ln::channelmanager::ChannelCounterparty) {
590         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty = *unsafe { Box::from_raw(val.take_inner()) };
591 }
592 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
593 /// our counterparty already.
594 ///
595 /// Note that, if this has been set, `channel_id` will be equivalent to
596 /// `funding_txo.unwrap().to_channel_id()`.
597 ///
598 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
599 #[no_mangle]
600 pub extern "C" fn ChannelDetails_get_funding_txo(this_ptr: &ChannelDetails) -> crate::lightning::chain::transaction::OutPoint {
601         let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_txo;
602         let mut local_inner_val = crate::lightning::chain::transaction::OutPoint { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
603         local_inner_val
604 }
605 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
606 /// our counterparty already.
607 ///
608 /// Note that, if this has been set, `channel_id` will be equivalent to
609 /// `funding_txo.unwrap().to_channel_id()`.
610 ///
611 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
612 #[no_mangle]
613 pub extern "C" fn ChannelDetails_set_funding_txo(this_ptr: &mut ChannelDetails, mut val: crate::lightning::chain::transaction::OutPoint) {
614         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
615         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_txo = local_val;
616 }
617 /// The position of the funding transaction in the chain. None if the funding transaction has
618 /// not yet been confirmed and the channel fully opened.
619 #[no_mangle]
620 pub extern "C" fn ChannelDetails_get_short_channel_id(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
621         let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
622         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() }) };
623         local_inner_val
624 }
625 /// The position of the funding transaction in the chain. None if the funding transaction has
626 /// not yet been confirmed and the channel fully opened.
627 #[no_mangle]
628 pub extern "C" fn ChannelDetails_set_short_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
629         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
630         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = local_val;
631 }
632 /// The value, in satoshis, of this channel as appears in the funding output
633 #[no_mangle]
634 pub extern "C" fn ChannelDetails_get_channel_value_satoshis(this_ptr: &ChannelDetails) -> u64 {
635         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
636         *inner_val
637 }
638 /// The value, in satoshis, of this channel as appears in the funding output
639 #[no_mangle]
640 pub extern "C" fn ChannelDetails_set_channel_value_satoshis(this_ptr: &mut ChannelDetails, mut val: u64) {
641         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
642 }
643 /// The value, in satoshis, that must always be held in the channel for us. This value ensures
644 /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
645 /// this value on chain.
646 ///
647 /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
648 ///
649 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
650 ///
651 /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
652 #[no_mangle]
653 pub extern "C" fn ChannelDetails_get_unspendable_punishment_reserve(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
654         let mut inner_val = &mut this_ptr.get_native_mut_ref().unspendable_punishment_reserve;
655         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() }) };
656         local_inner_val
657 }
658 /// The value, in satoshis, that must always be held in the channel for us. This value ensures
659 /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
660 /// this value on chain.
661 ///
662 /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
663 ///
664 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
665 ///
666 /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
667 #[no_mangle]
668 pub extern "C" fn ChannelDetails_set_unspendable_punishment_reserve(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
669         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
670         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = local_val;
671 }
672 /// The user_id passed in to create_channel, or 0 if the channel was inbound.
673 #[no_mangle]
674 pub extern "C" fn ChannelDetails_get_user_id(this_ptr: &ChannelDetails) -> u64 {
675         let mut inner_val = &mut this_ptr.get_native_mut_ref().user_id;
676         *inner_val
677 }
678 /// The user_id passed in to create_channel, or 0 if the channel was inbound.
679 #[no_mangle]
680 pub extern "C" fn ChannelDetails_set_user_id(this_ptr: &mut ChannelDetails, mut val: u64) {
681         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.user_id = val;
682 }
683 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
684 /// any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
685 /// available for inclusion in new outbound HTLCs). This further does not include any pending
686 /// outgoing HTLCs which are awaiting some other resolution to be sent.
687 ///
688 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
689 /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
690 /// should be able to spend nearly this amount.
691 #[no_mangle]
692 pub extern "C" fn ChannelDetails_get_outbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
693         let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_capacity_msat;
694         *inner_val
695 }
696 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
697 /// any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
698 /// available for inclusion in new outbound HTLCs). This further does not include any pending
699 /// outgoing HTLCs which are awaiting some other resolution to be sent.
700 ///
701 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
702 /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
703 /// should be able to spend nearly this amount.
704 #[no_mangle]
705 pub extern "C" fn ChannelDetails_set_outbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
706         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_capacity_msat = val;
707 }
708 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
709 /// include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
710 /// available for inclusion in new inbound HTLCs).
711 /// Note that there are some corner cases not fully handled here, so the actual available
712 /// inbound capacity may be slightly higher than this.
713 ///
714 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
715 /// counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
716 /// However, our counterparty should be able to spend nearly this amount.
717 #[no_mangle]
718 pub extern "C" fn ChannelDetails_get_inbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
719         let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_capacity_msat;
720         *inner_val
721 }
722 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
723 /// include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
724 /// available for inclusion in new inbound HTLCs).
725 /// Note that there are some corner cases not fully handled here, so the actual available
726 /// inbound capacity may be slightly higher than this.
727 ///
728 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
729 /// counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
730 /// However, our counterparty should be able to spend nearly this amount.
731 #[no_mangle]
732 pub extern "C" fn ChannelDetails_set_inbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
733         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_capacity_msat = val;
734 }
735 /// The number of required confirmations on the funding transaction before the funding will be
736 /// considered \"locked\". This number is selected by the channel fundee (i.e. us if
737 /// [`is_outbound`] is *not* set), and can be selected for inbound channels with
738 /// [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
739 /// [`ChannelHandshakeLimits::max_minimum_depth`].
740 ///
741 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
742 ///
743 /// [`is_outbound`]: ChannelDetails::is_outbound
744 /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
745 /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
746 #[no_mangle]
747 pub extern "C" fn ChannelDetails_get_confirmations_required(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u32Z {
748         let mut inner_val = &mut this_ptr.get_native_mut_ref().confirmations_required;
749         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() }) };
750         local_inner_val
751 }
752 /// The number of required confirmations on the funding transaction before the funding will be
753 /// considered \"locked\". This number is selected by the channel fundee (i.e. us if
754 /// [`is_outbound`] is *not* set), and can be selected for inbound channels with
755 /// [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
756 /// [`ChannelHandshakeLimits::max_minimum_depth`].
757 ///
758 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
759 ///
760 /// [`is_outbound`]: ChannelDetails::is_outbound
761 /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
762 /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
763 #[no_mangle]
764 pub extern "C" fn ChannelDetails_set_confirmations_required(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u32Z) {
765         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
766         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.confirmations_required = local_val;
767 }
768 /// The number of blocks (after our commitment transaction confirms) that we will need to wait
769 /// until we can claim our funds after we force-close the channel. During this time our
770 /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
771 /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any
772 /// time to claim our non-HTLC-encumbered funds.
773 ///
774 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
775 #[no_mangle]
776 pub extern "C" fn ChannelDetails_get_force_close_spend_delay(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u16Z {
777         let mut inner_val = &mut this_ptr.get_native_mut_ref().force_close_spend_delay;
778         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() }) };
779         local_inner_val
780 }
781 /// The number of blocks (after our commitment transaction confirms) that we will need to wait
782 /// until we can claim our funds after we force-close the channel. During this time our
783 /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
784 /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any
785 /// time to claim our non-HTLC-encumbered funds.
786 ///
787 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
788 #[no_mangle]
789 pub extern "C" fn ChannelDetails_set_force_close_spend_delay(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u16Z) {
790         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
791         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.force_close_spend_delay = local_val;
792 }
793 /// True if the channel was initiated (and thus funded) by us.
794 #[no_mangle]
795 pub extern "C" fn ChannelDetails_get_is_outbound(this_ptr: &ChannelDetails) -> bool {
796         let mut inner_val = &mut this_ptr.get_native_mut_ref().is_outbound;
797         *inner_val
798 }
799 /// True if the channel was initiated (and thus funded) by us.
800 #[no_mangle]
801 pub extern "C" fn ChannelDetails_set_is_outbound(this_ptr: &mut ChannelDetails, mut val: bool) {
802         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_outbound = val;
803 }
804 /// True if the channel is confirmed, funding_locked messages have been exchanged, and the
805 /// channel is not currently being shut down. `funding_locked` message exchange implies the
806 /// required confirmation count has been reached (and we were connected to the peer at some
807 /// point after the funding transaction received enough confirmations). The required
808 /// confirmation count is provided in [`confirmations_required`].
809 ///
810 /// [`confirmations_required`]: ChannelDetails::confirmations_required
811 #[no_mangle]
812 pub extern "C" fn ChannelDetails_get_is_funding_locked(this_ptr: &ChannelDetails) -> bool {
813         let mut inner_val = &mut this_ptr.get_native_mut_ref().is_funding_locked;
814         *inner_val
815 }
816 /// True if the channel is confirmed, funding_locked messages have been exchanged, and the
817 /// channel is not currently being shut down. `funding_locked` message exchange implies the
818 /// required confirmation count has been reached (and we were connected to the peer at some
819 /// point after the funding transaction received enough confirmations). The required
820 /// confirmation count is provided in [`confirmations_required`].
821 ///
822 /// [`confirmations_required`]: ChannelDetails::confirmations_required
823 #[no_mangle]
824 pub extern "C" fn ChannelDetails_set_is_funding_locked(this_ptr: &mut ChannelDetails, mut val: bool) {
825         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_funding_locked = val;
826 }
827 /// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
828 /// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
829 ///
830 /// This is a strict superset of `is_funding_locked`.
831 #[no_mangle]
832 pub extern "C" fn ChannelDetails_get_is_usable(this_ptr: &ChannelDetails) -> bool {
833         let mut inner_val = &mut this_ptr.get_native_mut_ref().is_usable;
834         *inner_val
835 }
836 /// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
837 /// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
838 ///
839 /// This is a strict superset of `is_funding_locked`.
840 #[no_mangle]
841 pub extern "C" fn ChannelDetails_set_is_usable(this_ptr: &mut ChannelDetails, mut val: bool) {
842         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_usable = val;
843 }
844 /// True if this channel is (or will be) publicly-announced.
845 #[no_mangle]
846 pub extern "C" fn ChannelDetails_get_is_public(this_ptr: &ChannelDetails) -> bool {
847         let mut inner_val = &mut this_ptr.get_native_mut_ref().is_public;
848         *inner_val
849 }
850 /// True if this channel is (or will be) publicly-announced.
851 #[no_mangle]
852 pub extern "C" fn ChannelDetails_set_is_public(this_ptr: &mut ChannelDetails, mut val: bool) {
853         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_public = val;
854 }
855 /// Constructs a new ChannelDetails given each field
856 #[must_use]
857 #[no_mangle]
858 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 short_channel_id_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_id_arg: u64, mut outbound_capacity_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_funding_locked_arg: bool, mut is_usable_arg: bool, mut is_public_arg: bool) -> ChannelDetails {
859         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()) } }) };
860         let mut local_short_channel_id_arg = if short_channel_id_arg.is_some() { Some( { short_channel_id_arg.take() }) } else { None };
861         let mut local_unspendable_punishment_reserve_arg = if unspendable_punishment_reserve_arg.is_some() { Some( { unspendable_punishment_reserve_arg.take() }) } else { None };
862         let mut local_confirmations_required_arg = if confirmations_required_arg.is_some() { Some( { confirmations_required_arg.take() }) } else { None };
863         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 };
864         ChannelDetails { inner: ObjOps::heap_alloc(nativeChannelDetails {
865                 channel_id: channel_id_arg.data,
866                 counterparty: *unsafe { Box::from_raw(counterparty_arg.take_inner()) },
867                 funding_txo: local_funding_txo_arg,
868                 short_channel_id: local_short_channel_id_arg,
869                 channel_value_satoshis: channel_value_satoshis_arg,
870                 unspendable_punishment_reserve: local_unspendable_punishment_reserve_arg,
871                 user_id: user_id_arg,
872                 outbound_capacity_msat: outbound_capacity_msat_arg,
873                 inbound_capacity_msat: inbound_capacity_msat_arg,
874                 confirmations_required: local_confirmations_required_arg,
875                 force_close_spend_delay: local_force_close_spend_delay_arg,
876                 is_outbound: is_outbound_arg,
877                 is_funding_locked: is_funding_locked_arg,
878                 is_usable: is_usable_arg,
879                 is_public: is_public_arg,
880         }), is_owned: true }
881 }
882 impl Clone for ChannelDetails {
883         fn clone(&self) -> Self {
884                 Self {
885                         inner: if <*mut nativeChannelDetails>::is_null(self.inner) { std::ptr::null_mut() } else {
886                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
887                         is_owned: true,
888                 }
889         }
890 }
891 #[allow(unused)]
892 /// Used only if an object of this type is returned as a trait impl by a method
893 pub(crate) extern "C" fn ChannelDetails_clone_void(this_ptr: *const c_void) -> *mut c_void {
894         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelDetails)).clone() })) as *mut c_void
895 }
896 #[no_mangle]
897 /// Creates a copy of the ChannelDetails
898 pub extern "C" fn ChannelDetails_clone(orig: &ChannelDetails) -> ChannelDetails {
899         orig.clone()
900 }
901 /// If a payment fails to send, it can be in one of several states. This enum is returned as the
902 /// Err() type describing which state the payment is in, see the description of individual enum
903 /// states for more.
904 #[must_use]
905 #[derive(Clone)]
906 #[repr(C)]
907 pub enum PaymentSendFailure {
908         /// A parameter which was passed to send_payment was invalid, preventing us from attempting to
909         /// send the payment at all. No channel state has been changed or messages sent to peers, and
910         /// once you've changed the parameter at error, you can freely retry the payment in full.
911         ParameterError(crate::lightning::util::errors::APIError),
912         /// A parameter in a single path which was passed to send_payment was invalid, preventing us
913         /// from attempting to send the payment at all. No channel state has been changed or messages
914         /// sent to peers, and once you've changed the parameter at error, you can freely retry the
915         /// payment in full.
916         ///
917         /// The results here are ordered the same as the paths in the route object which was passed to
918         /// send_payment.
919         PathParameterError(crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ),
920         /// All paths which were attempted failed to send, with no channel state change taking place.
921         /// You can freely retry the payment in full (though you probably want to do so over different
922         /// paths than the ones selected).
923         AllFailedRetrySafe(crate::c_types::derived::CVec_APIErrorZ),
924         /// Some paths which were attempted failed to send, though possibly not all. At least some
925         /// paths have irrevocably committed to the HTLC and retrying the payment in full would result
926         /// in over-/re-payment.
927         ///
928         /// The results here are ordered the same as the paths in the route object which was passed to
929         /// send_payment, and any Errs which are not APIError::MonitorUpdateFailed can be safely
930         /// retried (though there is currently no API with which to do so).
931         ///
932         /// Any entries which contain Err(APIError::MonitorUpdateFailed) or Ok(()) MUST NOT be retried
933         /// as they will result in over-/re-payment. These HTLCs all either successfully sent (in the
934         /// case of Ok(())) or will send once channel_monitor_updated is called on the next-hop channel
935         /// with the latest update_id.
936         PartialFailure(crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ),
937 }
938 use lightning::ln::channelmanager::PaymentSendFailure as nativePaymentSendFailure;
939 impl PaymentSendFailure {
940         #[allow(unused)]
941         pub(crate) fn to_native(&self) -> nativePaymentSendFailure {
942                 match self {
943                         PaymentSendFailure::ParameterError (ref a, ) => {
944                                 let mut a_nonref = (*a).clone();
945                                 nativePaymentSendFailure::ParameterError (
946                                         a_nonref.into_native(),
947                                 )
948                         },
949                         PaymentSendFailure::PathParameterError (ref a, ) => {
950                                 let mut a_nonref = (*a).clone();
951                                 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 }); };
952                                 nativePaymentSendFailure::PathParameterError (
953                                         local_a_nonref,
954                                 )
955                         },
956                         PaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
957                                 let mut a_nonref = (*a).clone();
958                                 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { item.into_native() }); };
959                                 nativePaymentSendFailure::AllFailedRetrySafe (
960                                         local_a_nonref,
961                                 )
962                         },
963                         PaymentSendFailure::PartialFailure (ref a, ) => {
964                                 let mut a_nonref = (*a).clone();
965                                 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 }); };
966                                 nativePaymentSendFailure::PartialFailure (
967                                         local_a_nonref,
968                                 )
969                         },
970                 }
971         }
972         #[allow(unused)]
973         pub(crate) fn into_native(self) -> nativePaymentSendFailure {
974                 match self {
975                         PaymentSendFailure::ParameterError (mut a, ) => {
976                                 nativePaymentSendFailure::ParameterError (
977                                         a.into_native(),
978                                 )
979                         },
980                         PaymentSendFailure::PathParameterError (mut a, ) => {
981                                 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 }); };
982                                 nativePaymentSendFailure::PathParameterError (
983                                         local_a,
984                                 )
985                         },
986                         PaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
987                                 let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { item.into_native() }); };
988                                 nativePaymentSendFailure::AllFailedRetrySafe (
989                                         local_a,
990                                 )
991                         },
992                         PaymentSendFailure::PartialFailure (mut a, ) => {
993                                 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 }); };
994                                 nativePaymentSendFailure::PartialFailure (
995                                         local_a,
996                                 )
997                         },
998                 }
999         }
1000         #[allow(unused)]
1001         pub(crate) fn from_native(native: &nativePaymentSendFailure) -> Self {
1002                 match native {
1003                         nativePaymentSendFailure::ParameterError (ref a, ) => {
1004                                 let mut a_nonref = (*a).clone();
1005                                 PaymentSendFailure::ParameterError (
1006                                         crate::lightning::util::errors::APIError::native_into(a_nonref),
1007                                 )
1008                         },
1009                         nativePaymentSendFailure::PathParameterError (ref a, ) => {
1010                                 let mut a_nonref = (*a).clone();
1011                                 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 }); };
1012                                 PaymentSendFailure::PathParameterError (
1013                                         local_a_nonref.into(),
1014                                 )
1015                         },
1016                         nativePaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
1017                                 let mut a_nonref = (*a).clone();
1018                                 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) }); };
1019                                 PaymentSendFailure::AllFailedRetrySafe (
1020                                         local_a_nonref.into(),
1021                                 )
1022                         },
1023                         nativePaymentSendFailure::PartialFailure (ref a, ) => {
1024                                 let mut a_nonref = (*a).clone();
1025                                 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 }); };
1026                                 PaymentSendFailure::PartialFailure (
1027                                         local_a_nonref.into(),
1028                                 )
1029                         },
1030                 }
1031         }
1032         #[allow(unused)]
1033         pub(crate) fn native_into(native: nativePaymentSendFailure) -> Self {
1034                 match native {
1035                         nativePaymentSendFailure::ParameterError (mut a, ) => {
1036                                 PaymentSendFailure::ParameterError (
1037                                         crate::lightning::util::errors::APIError::native_into(a),
1038                                 )
1039                         },
1040                         nativePaymentSendFailure::PathParameterError (mut a, ) => {
1041                                 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 }); };
1042                                 PaymentSendFailure::PathParameterError (
1043                                         local_a.into(),
1044                                 )
1045                         },
1046                         nativePaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
1047                                 let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { crate::lightning::util::errors::APIError::native_into(item) }); };
1048                                 PaymentSendFailure::AllFailedRetrySafe (
1049                                         local_a.into(),
1050                                 )
1051                         },
1052                         nativePaymentSendFailure::PartialFailure (mut a, ) => {
1053                                 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 }); };
1054                                 PaymentSendFailure::PartialFailure (
1055                                         local_a.into(),
1056                                 )
1057                         },
1058                 }
1059         }
1060 }
1061 /// Frees any resources used by the PaymentSendFailure
1062 #[no_mangle]
1063 pub extern "C" fn PaymentSendFailure_free(this_ptr: PaymentSendFailure) { }
1064 /// Creates a copy of the PaymentSendFailure
1065 #[no_mangle]
1066 pub extern "C" fn PaymentSendFailure_clone(orig: &PaymentSendFailure) -> PaymentSendFailure {
1067         orig.clone()
1068 }
1069 #[no_mangle]
1070 /// Utility method to constructs a new ParameterError-variant PaymentSendFailure
1071 pub extern "C" fn PaymentSendFailure_parameter_error(a: crate::lightning::util::errors::APIError) -> PaymentSendFailure {
1072         PaymentSendFailure::ParameterError(a, )
1073 }
1074 #[no_mangle]
1075 /// Utility method to constructs a new PathParameterError-variant PaymentSendFailure
1076 pub extern "C" fn PaymentSendFailure_path_parameter_error(a: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ) -> PaymentSendFailure {
1077         PaymentSendFailure::PathParameterError(a, )
1078 }
1079 #[no_mangle]
1080 /// Utility method to constructs a new AllFailedRetrySafe-variant PaymentSendFailure
1081 pub extern "C" fn PaymentSendFailure_all_failed_retry_safe(a: crate::c_types::derived::CVec_APIErrorZ) -> PaymentSendFailure {
1082         PaymentSendFailure::AllFailedRetrySafe(a, )
1083 }
1084 #[no_mangle]
1085 /// Utility method to constructs a new PartialFailure-variant PaymentSendFailure
1086 pub extern "C" fn PaymentSendFailure_partial_failure(a: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ) -> PaymentSendFailure {
1087         PaymentSendFailure::PartialFailure(a, )
1088 }
1089 /// Constructs a new ChannelManager to hold several channels and route between them.
1090 ///
1091 /// This is the main \"logic hub\" for all channel-related actions, and implements
1092 /// ChannelMessageHandler.
1093 ///
1094 /// Non-proportional fees are fixed according to our risk using the provided fee estimator.
1095 ///
1096 /// panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`!
1097 ///
1098 /// Users need to notify the new ChannelManager when a new block is connected or
1099 /// disconnected using its `block_connected` and `block_disconnected` methods, starting
1100 /// from after `params.latest_hash`.
1101 #[must_use]
1102 #[no_mangle]
1103 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) -> ChannelManager {
1104         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()) });
1105         ChannelManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
1106 }
1107
1108 /// Gets the current configuration applied to all new channels,  as
1109 #[must_use]
1110 #[no_mangle]
1111 pub extern "C" fn ChannelManager_get_current_default_configuration(this_arg: &ChannelManager) -> crate::lightning::util::config::UserConfig {
1112         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_current_default_configuration();
1113         crate::lightning::util::config::UserConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const _) as *mut _) }, is_owned: false }
1114 }
1115
1116 /// Creates a new outbound channel to the given remote node and with the given value.
1117 ///
1118 /// user_id will be provided back as user_channel_id in FundingGenerationReady events to allow
1119 /// tracking of which events correspond with which create_channel call. Note that the
1120 /// user_channel_id defaults to 0 for inbound channels, so you may wish to avoid using 0 for
1121 /// user_id here. user_id has no meaning inside of LDK, it is simply copied to events and
1122 /// otherwise ignored.
1123 ///
1124 /// If successful, will generate a SendOpenChannel message event, so you should probably poll
1125 /// PeerManager::process_events afterwards.
1126 ///
1127 /// Raises APIError::APIMisuseError when channel_value_satoshis > 2**24 or push_msat is
1128 /// greater than channel_value_satoshis * 1k or channel_value_satoshis is < 1000.
1129 ///
1130 /// Note that we do not check if you are currently connected to the given peer. If no
1131 /// connection is available, the outbound `open_channel` message may fail to send, resulting in
1132 /// the channel eventually being silently forgotten.
1133 ///
1134 /// Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
1135 #[must_use]
1136 #[no_mangle]
1137 pub extern "C" fn ChannelManager_create_channel(this_arg: &ChannelManager, mut their_network_key: crate::c_types::PublicKey, mut channel_value_satoshis: u64, mut push_msat: u64, mut user_id: u64, mut override_config: crate::lightning::util::config::UserConfig) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1138         let mut local_override_config = if override_config.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(override_config.take_inner()) } }) };
1139         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_channel(their_network_key.into_rust(), channel_value_satoshis, push_msat, user_id, local_override_config);
1140         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() };
1141         local_ret
1142 }
1143
1144 /// Gets the list of open channels, in random order. See ChannelDetail field documentation for
1145 /// more information.
1146 #[must_use]
1147 #[no_mangle]
1148 pub extern "C" fn ChannelManager_list_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1149         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_channels();
1150         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 } }); };
1151         local_ret.into()
1152 }
1153
1154 /// Gets the list of usable channels, in random order. Useful as an argument to
1155 /// get_route to ensure non-announced channels are used.
1156 ///
1157 /// These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
1158 /// documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
1159 /// are.
1160 #[must_use]
1161 #[no_mangle]
1162 pub extern "C" fn ChannelManager_list_usable_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1163         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_usable_channels();
1164         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 } }); };
1165         local_ret.into()
1166 }
1167
1168 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
1169 /// will be accepted on the given channel, and after additional timeout/the closing of all
1170 /// pending HTLCs, the channel will be closed on chain.
1171 ///
1172 ///  * If we are the channel initiator, we will pay between our [`Background`] and
1173 ///    [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
1174 ///    estimate.
1175 ///  * If our counterparty is the channel initiator, we will require a channel closing
1176 ///    transaction feerate of at least our [`Background`] feerate or the feerate which
1177 ///    would appear on a force-closure transaction, whichever is lower. We will allow our
1178 ///    counterparty to pay as much fee as they'd like, however.
1179 ///
1180 /// May generate a SendShutdown message event on success, which should be relayed.
1181 ///
1182 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
1183 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1184 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1185 #[must_use]
1186 #[no_mangle]
1187 pub extern "C" fn ChannelManager_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1188         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel(unsafe { &*channel_id});
1189         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() };
1190         local_ret
1191 }
1192
1193 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
1194 /// will be accepted on the given channel, and after additional timeout/the closing of all
1195 /// pending HTLCs, the channel will be closed on chain.
1196 ///
1197 /// `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
1198 /// the channel being closed or not:
1199 ///  * If we are the channel initiator, we will pay at least this feerate on the closing
1200 ///    transaction. The upper-bound is set by
1201 ///    [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
1202 ///    estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
1203 ///  * If our counterparty is the channel initiator, we will refuse to accept a channel closure
1204 ///    transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
1205 ///    will appear on a force-closure transaction, whichever is lower).
1206 ///
1207 /// May generate a SendShutdown message event on success, which should be relayed.
1208 ///
1209 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
1210 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1211 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1212 #[must_use]
1213 #[no_mangle]
1214 pub extern "C" fn ChannelManager_close_channel_with_target_feerate(this_arg: &ChannelManager, channel_id: *const [u8; 32], mut target_feerate_sats_per_1000_weight: u32) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1215         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel_with_target_feerate(unsafe { &*channel_id}, target_feerate_sats_per_1000_weight);
1216         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() };
1217         local_ret
1218 }
1219
1220 /// Force closes a channel, immediately broadcasting the latest local commitment transaction to
1221 /// the chain and rejecting new HTLCs on the given channel. Fails if channel_id is unknown to the manager.
1222 #[must_use]
1223 #[no_mangle]
1224 pub extern "C" fn ChannelManager_force_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1225         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_channel(unsafe { &*channel_id});
1226         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() };
1227         local_ret
1228 }
1229
1230 /// Force close all channels, immediately broadcasting the latest local commitment transaction
1231 /// for each to the chain and rejecting new HTLCs on each.
1232 #[no_mangle]
1233 pub extern "C" fn ChannelManager_force_close_all_channels(this_arg: &ChannelManager) {
1234         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_all_channels()
1235 }
1236
1237 /// Sends a payment along a given route.
1238 ///
1239 /// Value parameters are provided via the last hop in route, see documentation for RouteHop
1240 /// fields for more info.
1241 ///
1242 /// Note that if the payment_hash already exists elsewhere (eg you're sending a duplicative
1243 /// payment), we don't do anything to stop you! We always try to ensure that if the provided
1244 /// next hop knows the preimage to payment_hash they can claim an additional amount as
1245 /// specified in the last hop in the route! Thus, you should probably do your own
1246 /// payment_preimage tracking (which you should already be doing as they represent \"proof of
1247 /// payment\") and prevent double-sends yourself.
1248 ///
1249 /// May generate SendHTLCs message(s) event on success, which should be relayed.
1250 ///
1251 /// Each path may have a different return value, and PaymentSendValue may return a Vec with
1252 /// each entry matching the corresponding-index entry in the route paths, see
1253 /// PaymentSendFailure for more info.
1254 ///
1255 /// In general, a path may raise:
1256 ///  * APIError::RouteError when an invalid route or forwarding parameter (cltv_delta, fee,
1257 ///    node public key) is specified.
1258 ///  * APIError::ChannelUnavailable if the next-hop channel is not available for updates
1259 ///    (including due to previous monitor update failure or new permanent monitor update
1260 ///    failure).
1261 ///  * APIError::MonitorUpdateFailed if a new monitor update failure prevented sending the
1262 ///    relevant updates.
1263 ///
1264 /// Note that depending on the type of the PaymentSendFailure the HTLC may have been
1265 /// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
1266 /// different route unless you intend to pay twice!
1267 ///
1268 /// payment_secret is unrelated to payment_hash (or PaymentPreimage) and exists to authenticate
1269 /// the sender to the recipient and prevent payment-probing (deanonymization) attacks. For
1270 /// newer nodes, it will be provided to you in the invoice. If you do not have one, the Route
1271 /// must not contain multiple paths as multi-path payments require a recipient-provided
1272 /// payment_secret.
1273 /// If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature
1274 /// bit set (either as required or as available). If multiple paths are present in the Route,
1275 /// we assume the invoice had the basic_mpp feature set.
1276 ///
1277 /// Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
1278 #[must_use]
1279 #[no_mangle]
1280 pub extern "C" fn ChannelManager_send_payment(this_arg: &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_NonePaymentSendFailureZ {
1281         let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentSecret(payment_secret.data) }) };
1282         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);
1283         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() };
1284         local_ret
1285 }
1286
1287 /// Send a spontaneous payment, which is a payment that does not require the recipient to have
1288 /// generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
1289 /// the preimage, it must be a cryptographically secure random value that no intermediate node
1290 /// would be able to guess -- otherwise, an intermediate node may claim the payment and it will
1291 /// never reach the recipient.
1292 ///
1293 /// See [`send_payment`] documentation for more details on the return value of this function.
1294 ///
1295 /// Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
1296 /// [`send_payment`] for more information about the risks of duplicate preimage usage.
1297 ///
1298 /// Note that `route` must have exactly one path.
1299 ///
1300 /// [`send_payment`]: Self::send_payment
1301 ///
1302 /// Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None
1303 #[must_use]
1304 #[no_mangle]
1305 pub extern "C" fn ChannelManager_send_spontaneous_payment(this_arg: &ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_preimage: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_PaymentHashPaymentSendFailureZ {
1306         let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
1307         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_spontaneous_payment(route.get_native_ref(), local_payment_preimage);
1308         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() };
1309         local_ret
1310 }
1311
1312 /// Call this upon creation of a funding transaction for the given channel.
1313 ///
1314 /// Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
1315 /// or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
1316 ///
1317 /// Panics if a funding transaction has already been provided for this channel.
1318 ///
1319 /// May panic if the output found in the funding transaction is duplicative with some other
1320 /// channel (note that this should be trivially prevented by using unique funding transaction
1321 /// keys per-channel).
1322 ///
1323 /// Do NOT broadcast the funding transaction yourself. When we have safely received our
1324 /// counterparty's signature the funding transaction will automatically be broadcast via the
1325 /// [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
1326 ///
1327 /// Note that this includes RBF or similar transaction replacement strategies - lightning does
1328 /// not currently support replacing a funding transaction on an existing channel. Instead,
1329 /// create a new channel with a conflicting funding transaction.
1330 ///
1331 /// [`Event::FundingGenerationReady`]: crate::util::events::Event::FundingGenerationReady
1332 #[must_use]
1333 #[no_mangle]
1334 pub extern "C" fn ChannelManager_funding_transaction_generated(this_arg: &ChannelManager, temporary_channel_id: *const [u8; 32], mut funding_transaction: crate::c_types::Transaction) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1335         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_transaction_generated(unsafe { &*temporary_channel_id}, funding_transaction.into_bitcoin());
1336         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() };
1337         local_ret
1338 }
1339
1340 /// Regenerates channel_announcements and generates a signed node_announcement from the given
1341 /// arguments, providing them in corresponding events via
1342 /// [`get_and_clear_pending_msg_events`], if at least one public channel has been confirmed
1343 /// on-chain. This effectively re-broadcasts all channel announcements and sends our node
1344 /// announcement to ensure that the lightning P2P network is aware of the channels we have and
1345 /// our network addresses.
1346 ///
1347 /// `rgb` is a node \"color\" and `alias` is a printable human-readable string to describe this
1348 /// node to humans. They carry no in-protocol meaning.
1349 ///
1350 /// `addresses` represent the set (possibly empty) of socket addresses on which this node
1351 /// accepts incoming connections. These will be included in the node_announcement, publicly
1352 /// tying these addresses together and to this node. If you wish to preserve user privacy,
1353 /// addresses should likely contain only Tor Onion addresses.
1354 ///
1355 /// Panics if `addresses` is absurdly large (more than 500).
1356 ///
1357 /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
1358 #[no_mangle]
1359 pub extern "C" fn ChannelManager_broadcast_node_announcement(this_arg: &ChannelManager, mut rgb: crate::c_types::ThreeBytes, mut alias: crate::c_types::ThirtyTwoBytes, mut addresses: crate::c_types::derived::CVec_NetAddressZ) {
1360         let mut local_addresses = Vec::new(); for mut item in addresses.into_rust().drain(..) { local_addresses.push( { item.into_native() }); };
1361         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.broadcast_node_announcement(rgb.data, alias.data, local_addresses)
1362 }
1363
1364 /// Processes HTLCs which are pending waiting on random forward delay.
1365 ///
1366 /// Should only really ever be called in response to a PendingHTLCsForwardable event.
1367 /// Will likely generate further events.
1368 #[no_mangle]
1369 pub extern "C" fn ChannelManager_process_pending_htlc_forwards(this_arg: &ChannelManager) {
1370         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_pending_htlc_forwards()
1371 }
1372
1373 /// Performs actions which should happen on startup and roughly once per minute thereafter.
1374 ///
1375 /// This currently includes:
1376 ///  * Increasing or decreasing the on-chain feerate estimates for our outbound channels,
1377 ///  * Broadcasting `ChannelUpdate` messages if we've been disconnected from our peer for more
1378 ///    than a minute, informing the network that they should no longer attempt to route over
1379 ///    the channel.
1380 ///
1381 /// Note that this may cause reentrancy through `chain::Watch::update_channel` calls or feerate
1382 /// estimate fetches.
1383 #[no_mangle]
1384 pub extern "C" fn ChannelManager_timer_tick_occurred(this_arg: &ChannelManager) {
1385         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timer_tick_occurred()
1386 }
1387
1388 /// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
1389 /// after a PaymentReceived event, failing the HTLC back to its origin and freeing resources
1390 /// along the path (including in our own channel on which we received it).
1391 /// Returns false if no payment was found to fail backwards, true if the process of failing the
1392 /// HTLC backwards has been started.
1393 #[must_use]
1394 #[no_mangle]
1395 pub extern "C" fn ChannelManager_fail_htlc_backwards(this_arg: &ChannelManager, payment_hash: *const [u8; 32]) -> bool {
1396         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_htlc_backwards(&::lightning::ln::PaymentHash(unsafe { *payment_hash }));
1397         ret
1398 }
1399
1400 /// Provides a payment preimage in response to a PaymentReceived event, returning true and
1401 /// generating message events for the net layer to claim the payment, if possible. Thus, you
1402 /// should probably kick the net layer to go send messages if this returns true!
1403 ///
1404 /// Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
1405 /// [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentReceived`
1406 /// event matches your expectation. If you fail to do so and call this method, you may provide
1407 /// the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
1408 ///
1409 /// May panic if called except in response to a PaymentReceived event.
1410 ///
1411 /// [`create_inbound_payment`]: Self::create_inbound_payment
1412 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1413 #[must_use]
1414 #[no_mangle]
1415 pub extern "C" fn ChannelManager_claim_funds(this_arg: &ChannelManager, mut payment_preimage: crate::c_types::ThirtyTwoBytes) -> bool {
1416         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.claim_funds(::lightning::ln::PaymentPreimage(payment_preimage.data));
1417         ret
1418 }
1419
1420 /// Gets the node_id held by this ChannelManager
1421 #[must_use]
1422 #[no_mangle]
1423 pub extern "C" fn ChannelManager_get_our_node_id(this_arg: &ChannelManager) -> crate::c_types::PublicKey {
1424         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_our_node_id();
1425         crate::c_types::PublicKey::from_rust(&ret)
1426 }
1427
1428 /// Restores a single, given channel to normal operation after a
1429 /// ChannelMonitorUpdateErr::TemporaryFailure was returned from a channel monitor update
1430 /// operation.
1431 ///
1432 /// All ChannelMonitor updates up to and including highest_applied_update_id must have been
1433 /// fully committed in every copy of the given channels' ChannelMonitors.
1434 ///
1435 /// Note that there is no effect to calling with a highest_applied_update_id other than the
1436 /// current latest ChannelMonitorUpdate and one call to this function after multiple
1437 /// ChannelMonitorUpdateErr::TemporaryFailures is fine. The highest_applied_update_id field
1438 /// exists largely only to prevent races between this and concurrent update_monitor calls.
1439 ///
1440 /// Thus, the anticipated use is, at a high level:
1441 ///  1) You register a chain::Watch with this ChannelManager,
1442 ///  2) it stores each update to disk, and begins updating any remote (eg watchtower) copies of
1443 ///     said ChannelMonitors as it can, returning ChannelMonitorUpdateErr::TemporaryFailures
1444 ///     any time it cannot do so instantly,
1445 ///  3) update(s) are applied to each remote copy of a ChannelMonitor,
1446 ///  4) once all remote copies are updated, you call this function with the update_id that
1447 ///     completed, and once it is the latest the Channel will be re-enabled.
1448 #[no_mangle]
1449 pub extern "C" fn ChannelManager_channel_monitor_updated(this_arg: &ChannelManager, funding_txo: &crate::lightning::chain::transaction::OutPoint, mut highest_applied_update_id: u64) {
1450         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_monitor_updated(funding_txo.get_native_ref(), highest_applied_update_id)
1451 }
1452
1453 /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
1454 /// to pay us.
1455 ///
1456 /// This differs from [`create_inbound_payment_for_hash`] only in that it generates the
1457 /// [`PaymentHash`] and [`PaymentPreimage`] for you, returning the first and storing the second.
1458 ///
1459 /// The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentReceived`], which
1460 /// will have the [`PaymentReceived::payment_preimage`] field filled in. That should then be
1461 /// passed directly to [`claim_funds`].
1462 ///
1463 /// See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
1464 ///
1465 /// [`claim_funds`]: Self::claim_funds
1466 /// [`PaymentReceived`]: events::Event::PaymentReceived
1467 /// [`PaymentReceived::payment_preimage`]: events::Event::PaymentReceived::payment_preimage
1468 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1469 #[must_use]
1470 #[no_mangle]
1471 pub extern "C" fn ChannelManager_create_inbound_payment(this_arg: &ChannelManager, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32, mut user_payment_id: u64) -> crate::c_types::derived::C2Tuple_PaymentHashPaymentSecretZ {
1472         let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
1473         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment(local_min_value_msat, invoice_expiry_delta_secs, user_payment_id);
1474         let (mut orig_ret_0, mut orig_ret_1) = ret; let mut local_ret = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0.0 }, crate::c_types::ThirtyTwoBytes { data: orig_ret_1.0 }).into();
1475         local_ret
1476 }
1477
1478 /// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
1479 /// stored external to LDK.
1480 ///
1481 /// A [`PaymentReceived`] event will only be generated if the [`PaymentSecret`] matches a
1482 /// payment secret fetched via this method or [`create_inbound_payment`], and which is at least
1483 /// the `min_value_msat` provided here, if one is provided.
1484 ///
1485 /// The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) must be globally unique. This
1486 /// method may return an Err if another payment with the same payment_hash is still pending.
1487 ///
1488 /// `user_payment_id` will be provided back in [`PaymentPurpose::InvoicePayment::user_payment_id`] events to
1489 /// allow tracking of which events correspond with which calls to this and
1490 /// [`create_inbound_payment`]. `user_payment_id` has no meaning inside of LDK, it is simply
1491 /// copied to events and otherwise ignored. It may be used to correlate PaymentReceived events
1492 /// with invoice metadata stored elsewhere.
1493 ///
1494 /// `min_value_msat` should be set if the invoice being generated contains a value. Any payment
1495 /// received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
1496 /// before a [`PaymentReceived`] event will be generated, ensuring that we do not provide the
1497 /// sender \"proof-of-payment\" unless they have paid the required amount.
1498 ///
1499 /// `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
1500 /// in excess of the current time. This should roughly match the expiry time set in the invoice.
1501 /// After this many seconds, we will remove the inbound payment, resulting in any attempts to
1502 /// pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
1503 /// invoices when no timeout is set.
1504 ///
1505 /// Note that we use block header time to time-out pending inbound payments (with some margin
1506 /// to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
1507 /// accept a payment and generate a [`PaymentReceived`] event for some time after the expiry.
1508 /// If you need exact expiry semantics, you should enforce them upon receipt of
1509 /// [`PaymentReceived`].
1510 ///
1511 /// Pending inbound payments are stored in memory and in serialized versions of this
1512 /// [`ChannelManager`]. If potentially unbounded numbers of inbound payments may exist and
1513 /// space is limited, you may wish to rate-limit inbound payment creation.
1514 ///
1515 /// May panic if `invoice_expiry_delta_secs` is greater than one year.
1516 ///
1517 /// Note that invoices generated for inbound payments should have their `min_final_cltv_expiry`
1518 /// set to at least [`MIN_FINAL_CLTV_EXPIRY`].
1519 ///
1520 /// [`create_inbound_payment`]: Self::create_inbound_payment
1521 /// [`PaymentReceived`]: events::Event::PaymentReceived
1522 /// [`PaymentPurpose::InvoicePayment::user_payment_id`]: events::PaymentPurpose::InvoicePayment::user_payment_id
1523 #[must_use]
1524 #[no_mangle]
1525 pub extern "C" fn ChannelManager_create_inbound_payment_for_hash(this_arg: &ChannelManager, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32, mut user_payment_id: u64) -> crate::c_types::derived::CResult_PaymentSecretAPIErrorZ {
1526         let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
1527         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, user_payment_id);
1528         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() };
1529         local_ret
1530 }
1531
1532 impl From<nativeChannelManager> for crate::lightning::util::events::MessageSendEventsProvider {
1533         fn from(obj: nativeChannelManager) -> Self {
1534                 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1535                 let mut ret = ChannelManager_as_MessageSendEventsProvider(&rust_obj);
1536                 // 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
1537                 rust_obj.inner = std::ptr::null_mut();
1538                 ret.free = Some(ChannelManager_free_void);
1539                 ret
1540         }
1541 }
1542 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
1543 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
1544 #[no_mangle]
1545 pub extern "C" fn ChannelManager_as_MessageSendEventsProvider(this_arg: &ChannelManager) -> crate::lightning::util::events::MessageSendEventsProvider {
1546         crate::lightning::util::events::MessageSendEventsProvider {
1547                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1548                 free: None,
1549                 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
1550         }
1551 }
1552
1553 #[must_use]
1554 extern "C" fn ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
1555         let mut ret = <nativeChannelManager as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
1556         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
1557         local_ret.into()
1558 }
1559
1560 impl From<nativeChannelManager> for crate::lightning::util::events::EventsProvider {
1561         fn from(obj: nativeChannelManager) -> Self {
1562                 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1563                 let mut ret = ChannelManager_as_EventsProvider(&rust_obj);
1564                 // 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
1565                 rust_obj.inner = std::ptr::null_mut();
1566                 ret.free = Some(ChannelManager_free_void);
1567                 ret
1568         }
1569 }
1570 /// Constructs a new EventsProvider which calls the relevant methods on this_arg.
1571 /// This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
1572 #[no_mangle]
1573 pub extern "C" fn ChannelManager_as_EventsProvider(this_arg: &ChannelManager) -> crate::lightning::util::events::EventsProvider {
1574         crate::lightning::util::events::EventsProvider {
1575                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1576                 free: None,
1577                 process_pending_events: ChannelManager_EventsProvider_process_pending_events,
1578         }
1579 }
1580
1581 extern "C" fn ChannelManager_EventsProvider_process_pending_events(this_arg: *const c_void, mut handler: crate::lightning::util::events::EventHandler) {
1582         <nativeChannelManager as lightning::util::events::EventsProvider<>>::process_pending_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, handler)
1583 }
1584
1585 impl From<nativeChannelManager> for crate::lightning::chain::Listen {
1586         fn from(obj: nativeChannelManager) -> Self {
1587                 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1588                 let mut ret = ChannelManager_as_Listen(&rust_obj);
1589                 // 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
1590                 rust_obj.inner = std::ptr::null_mut();
1591                 ret.free = Some(ChannelManager_free_void);
1592                 ret
1593         }
1594 }
1595 /// Constructs a new Listen which calls the relevant methods on this_arg.
1596 /// This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
1597 #[no_mangle]
1598 pub extern "C" fn ChannelManager_as_Listen(this_arg: &ChannelManager) -> crate::lightning::chain::Listen {
1599         crate::lightning::chain::Listen {
1600                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1601                 free: None,
1602                 block_connected: ChannelManager_Listen_block_connected,
1603                 block_disconnected: ChannelManager_Listen_block_disconnected,
1604         }
1605 }
1606
1607 extern "C" fn ChannelManager_Listen_block_connected(this_arg: *const c_void, mut block: crate::c_types::u8slice, mut height: u32) {
1608         <nativeChannelManager as lightning::chain::Listen<>>::block_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height)
1609 }
1610 extern "C" fn ChannelManager_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
1611         <nativeChannelManager as lightning::chain::Listen<>>::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
1612 }
1613
1614 impl From<nativeChannelManager> for crate::lightning::chain::Confirm {
1615         fn from(obj: nativeChannelManager) -> Self {
1616                 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1617                 let mut ret = ChannelManager_as_Confirm(&rust_obj);
1618                 // 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
1619                 rust_obj.inner = std::ptr::null_mut();
1620                 ret.free = Some(ChannelManager_free_void);
1621                 ret
1622         }
1623 }
1624 /// Constructs a new Confirm which calls the relevant methods on this_arg.
1625 /// This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
1626 #[no_mangle]
1627 pub extern "C" fn ChannelManager_as_Confirm(this_arg: &ChannelManager) -> crate::lightning::chain::Confirm {
1628         crate::lightning::chain::Confirm {
1629                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1630                 free: None,
1631                 transactions_confirmed: ChannelManager_Confirm_transactions_confirmed,
1632                 transaction_unconfirmed: ChannelManager_Confirm_transaction_unconfirmed,
1633                 best_block_updated: ChannelManager_Confirm_best_block_updated,
1634                 get_relevant_txids: ChannelManager_Confirm_get_relevant_txids,
1635         }
1636 }
1637
1638 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) {
1639         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 }); };
1640         <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)
1641 }
1642 extern "C" fn ChannelManager_Confirm_best_block_updated(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
1643         <nativeChannelManager as lightning::chain::Confirm<>>::best_block_updated(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
1644 }
1645 #[must_use]
1646 extern "C" fn ChannelManager_Confirm_get_relevant_txids(this_arg: *const c_void) -> crate::c_types::derived::CVec_TxidZ {
1647         let mut ret = <nativeChannelManager as lightning::chain::Confirm<>>::get_relevant_txids(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
1648         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::ThirtyTwoBytes { data: item.into_inner() } }); };
1649         local_ret.into()
1650 }
1651 extern "C" fn ChannelManager_Confirm_transaction_unconfirmed(this_arg: *const c_void, txid: *const [u8; 32]) {
1652         <nativeChannelManager as lightning::chain::Confirm<>>::transaction_unconfirmed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap())
1653 }
1654
1655 /// Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
1656 /// indicating whether persistence is necessary. Only one listener on
1657 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
1658 /// up.
1659 /// Note that the feature `allow_wallclock_use` must be enabled to use this function.
1660 #[must_use]
1661 #[no_mangle]
1662 pub extern "C" fn ChannelManager_await_persistable_update_timeout(this_arg: &ChannelManager, mut max_wait: u64) -> bool {
1663         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.await_persistable_update_timeout(std::time::Duration::from_secs(max_wait));
1664         ret
1665 }
1666
1667 /// Blocks until ChannelManager needs to be persisted. Only one listener on
1668 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
1669 /// up.
1670 #[no_mangle]
1671 pub extern "C" fn ChannelManager_await_persistable_update(this_arg: &ChannelManager) {
1672         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.await_persistable_update()
1673 }
1674
1675 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
1676 /// [`chain::Confirm`] interfaces.
1677 #[must_use]
1678 #[no_mangle]
1679 pub extern "C" fn ChannelManager_current_best_block(this_arg: &ChannelManager) -> crate::lightning::chain::BestBlock {
1680         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
1681         crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
1682 }
1683
1684 impl From<nativeChannelManager> for crate::lightning::ln::msgs::ChannelMessageHandler {
1685         fn from(obj: nativeChannelManager) -> Self {
1686                 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1687                 let mut ret = ChannelManager_as_ChannelMessageHandler(&rust_obj);
1688                 // 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
1689                 rust_obj.inner = std::ptr::null_mut();
1690                 ret.free = Some(ChannelManager_free_void);
1691                 ret
1692         }
1693 }
1694 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
1695 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
1696 #[no_mangle]
1697 pub extern "C" fn ChannelManager_as_ChannelMessageHandler(this_arg: &ChannelManager) -> crate::lightning::ln::msgs::ChannelMessageHandler {
1698         crate::lightning::ln::msgs::ChannelMessageHandler {
1699                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1700                 free: None,
1701                 handle_open_channel: ChannelManager_ChannelMessageHandler_handle_open_channel,
1702                 handle_accept_channel: ChannelManager_ChannelMessageHandler_handle_accept_channel,
1703                 handle_funding_created: ChannelManager_ChannelMessageHandler_handle_funding_created,
1704                 handle_funding_signed: ChannelManager_ChannelMessageHandler_handle_funding_signed,
1705                 handle_funding_locked: ChannelManager_ChannelMessageHandler_handle_funding_locked,
1706                 handle_shutdown: ChannelManager_ChannelMessageHandler_handle_shutdown,
1707                 handle_closing_signed: ChannelManager_ChannelMessageHandler_handle_closing_signed,
1708                 handle_update_add_htlc: ChannelManager_ChannelMessageHandler_handle_update_add_htlc,
1709                 handle_update_fulfill_htlc: ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc,
1710                 handle_update_fail_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_htlc,
1711                 handle_update_fail_malformed_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_malformed_htlc,
1712                 handle_commitment_signed: ChannelManager_ChannelMessageHandler_handle_commitment_signed,
1713                 handle_revoke_and_ack: ChannelManager_ChannelMessageHandler_handle_revoke_and_ack,
1714                 handle_update_fee: ChannelManager_ChannelMessageHandler_handle_update_fee,
1715                 handle_announcement_signatures: ChannelManager_ChannelMessageHandler_handle_announcement_signatures,
1716                 peer_disconnected: ChannelManager_ChannelMessageHandler_peer_disconnected,
1717                 peer_connected: ChannelManager_ChannelMessageHandler_peer_connected,
1718                 handle_channel_reestablish: ChannelManager_ChannelMessageHandler_handle_channel_reestablish,
1719                 handle_channel_update: ChannelManager_ChannelMessageHandler_handle_channel_update,
1720                 handle_error: ChannelManager_ChannelMessageHandler_handle_error,
1721                 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
1722                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1723                         free: None,
1724                         get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
1725                 },
1726         }
1727 }
1728
1729 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) {
1730         <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())
1731 }
1732 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) {
1733         <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())
1734 }
1735 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) {
1736         <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())
1737 }
1738 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) {
1739         <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())
1740 }
1741 extern "C" fn ChannelManager_ChannelMessageHandler_handle_funding_locked(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::FundingLocked) {
1742         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_locked(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
1743 }
1744 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) {
1745         <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())
1746 }
1747 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) {
1748         <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())
1749 }
1750 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) {
1751         <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())
1752 }
1753 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) {
1754         <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())
1755 }
1756 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) {
1757         <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())
1758 }
1759 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) {
1760         <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())
1761 }
1762 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) {
1763         <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())
1764 }
1765 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) {
1766         <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())
1767 }
1768 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) {
1769         <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())
1770 }
1771 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) {
1772         <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())
1773 }
1774 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) {
1775         <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())
1776 }
1777 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) {
1778         <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())
1779 }
1780 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) {
1781         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), no_connection_possible)
1782 }
1783 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) {
1784         <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())
1785 }
1786 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) {
1787         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
1788 }
1789
1790 #[no_mangle]
1791 /// Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
1792 pub extern "C" fn ChannelManager_write(obj: &ChannelManager) -> crate::c_types::derived::CVec_u8Z {
1793         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1794 }
1795 #[no_mangle]
1796 pub(crate) extern "C" fn ChannelManager_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1797         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelManager) })
1798 }
1799
1800 use lightning::ln::channelmanager::ChannelManagerReadArgs as nativeChannelManagerReadArgsImport;
1801 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>;
1802
1803 /// Arguments for the creation of a ChannelManager that are not deserialized.
1804 ///
1805 /// At a high-level, the process for deserializing a ChannelManager and resuming normal operation
1806 /// is:
1807 /// 1) Deserialize all stored ChannelMonitors.
1808 /// 2) Deserialize the ChannelManager by filling in this struct and calling:
1809 ///    <(BlockHash, ChannelManager)>::read(reader, args)
1810 ///    This may result in closing some Channels if the ChannelMonitor is newer than the stored
1811 ///    ChannelManager state to ensure no loss of funds. Thus, transactions may be broadcasted.
1812 /// 3) If you are not fetching full blocks, register all relevant ChannelMonitor outpoints the same
1813 ///    way you would handle a `chain::Filter` call using ChannelMonitor::get_outputs_to_watch() and
1814 ///    ChannelMonitor::get_funding_txo().
1815 /// 4) Reconnect blocks on your ChannelMonitors.
1816 /// 5) Disconnect/connect blocks on the ChannelManager.
1817 /// 6) Move the ChannelMonitors into your local chain::Watch.
1818 ///
1819 /// Note that the ordering of #4-6 is not of importance, however all three must occur before you
1820 /// call any other methods on the newly-deserialized ChannelManager.
1821 ///
1822 /// Note that because some channels may be closed during deserialization, it is critical that you
1823 /// always deserialize only the latest version of a ChannelManager and ChannelMonitors available to
1824 /// you. If you deserialize an old ChannelManager (during which force-closure transactions may be
1825 /// broadcast), and then later deserialize a newer version of the same ChannelManager (which will
1826 /// not force-close the same channels but consider them live), you may end up revoking a state for
1827 /// which you've already broadcasted the transaction.
1828 #[must_use]
1829 #[repr(C)]
1830 pub struct ChannelManagerReadArgs {
1831         /// A pointer to the opaque Rust object.
1832
1833         /// Nearly everywhere, inner must be non-null, however in places where
1834         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1835         pub inner: *mut nativeChannelManagerReadArgs,
1836         /// Indicates that this is the only struct which contains the same pointer.
1837
1838         /// Rust functions which take ownership of an object provided via an argument require
1839         /// this to be true and invalidate the object pointed to by inner.
1840         pub is_owned: bool,
1841 }
1842
1843 impl Drop for ChannelManagerReadArgs {
1844         fn drop(&mut self) {
1845                 if self.is_owned && !<*mut nativeChannelManagerReadArgs>::is_null(self.inner) {
1846                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1847                 }
1848         }
1849 }
1850 /// Frees any resources used by the ChannelManagerReadArgs, if is_owned is set and inner is non-NULL.
1851 #[no_mangle]
1852 pub extern "C" fn ChannelManagerReadArgs_free(this_obj: ChannelManagerReadArgs) { }
1853 #[allow(unused)]
1854 /// Used only if an object of this type is returned as a trait impl by a method
1855 extern "C" fn ChannelManagerReadArgs_free_void(this_ptr: *mut c_void) {
1856         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManagerReadArgs); }
1857 }
1858 #[allow(unused)]
1859 impl ChannelManagerReadArgs {
1860         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManagerReadArgs {
1861                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1862         }
1863         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManagerReadArgs {
1864                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1865         }
1866         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1867         pub(crate) fn take_inner(mut self) -> *mut nativeChannelManagerReadArgs {
1868                 assert!(self.is_owned);
1869                 let ret = ObjOps::untweak_ptr(self.inner);
1870                 self.inner = std::ptr::null_mut();
1871                 ret
1872         }
1873 }
1874 /// The keys provider which will give us relevant keys. Some keys will be loaded during
1875 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
1876 /// signing data.
1877 #[no_mangle]
1878 pub extern "C" fn ChannelManagerReadArgs_get_keys_manager(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::keysinterface::KeysInterface {
1879         let mut inner_val = &mut this_ptr.get_native_mut_ref().keys_manager;
1880         inner_val
1881 }
1882 /// The keys provider which will give us relevant keys. Some keys will be loaded during
1883 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
1884 /// signing data.
1885 #[no_mangle]
1886 pub extern "C" fn ChannelManagerReadArgs_set_keys_manager(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::keysinterface::KeysInterface) {
1887         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.keys_manager = val;
1888 }
1889 /// The fee_estimator for use in the ChannelManager in the future.
1890 ///
1891 /// No calls to the FeeEstimator will be made during deserialization.
1892 #[no_mangle]
1893 pub extern "C" fn ChannelManagerReadArgs_get_fee_estimator(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::FeeEstimator {
1894         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_estimator;
1895         inner_val
1896 }
1897 /// The fee_estimator for use in the ChannelManager in the future.
1898 ///
1899 /// No calls to the FeeEstimator will be made during deserialization.
1900 #[no_mangle]
1901 pub extern "C" fn ChannelManagerReadArgs_set_fee_estimator(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::FeeEstimator) {
1902         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_estimator = val;
1903 }
1904 /// The chain::Watch for use in the ChannelManager in the future.
1905 ///
1906 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
1907 /// you have deserialized ChannelMonitors separately and will add them to your
1908 /// chain::Watch after deserializing this ChannelManager.
1909 #[no_mangle]
1910 pub extern "C" fn ChannelManagerReadArgs_get_chain_monitor(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::Watch {
1911         let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_monitor;
1912         inner_val
1913 }
1914 /// The chain::Watch for use in the ChannelManager in the future.
1915 ///
1916 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
1917 /// you have deserialized ChannelMonitors separately and will add them to your
1918 /// chain::Watch after deserializing this ChannelManager.
1919 #[no_mangle]
1920 pub extern "C" fn ChannelManagerReadArgs_set_chain_monitor(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::Watch) {
1921         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_monitor = val;
1922 }
1923 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
1924 /// used to broadcast the latest local commitment transactions of channels which must be
1925 /// force-closed during deserialization.
1926 #[no_mangle]
1927 pub extern "C" fn ChannelManagerReadArgs_get_tx_broadcaster(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::BroadcasterInterface {
1928         let mut inner_val = &mut this_ptr.get_native_mut_ref().tx_broadcaster;
1929         inner_val
1930 }
1931 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
1932 /// used to broadcast the latest local commitment transactions of channels which must be
1933 /// force-closed during deserialization.
1934 #[no_mangle]
1935 pub extern "C" fn ChannelManagerReadArgs_set_tx_broadcaster(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::BroadcasterInterface) {
1936         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.tx_broadcaster = val;
1937 }
1938 /// The Logger for use in the ChannelManager and which may be used to log information during
1939 /// deserialization.
1940 #[no_mangle]
1941 pub extern "C" fn ChannelManagerReadArgs_get_logger(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::util::logger::Logger {
1942         let mut inner_val = &mut this_ptr.get_native_mut_ref().logger;
1943         inner_val
1944 }
1945 /// The Logger for use in the ChannelManager and which may be used to log information during
1946 /// deserialization.
1947 #[no_mangle]
1948 pub extern "C" fn ChannelManagerReadArgs_set_logger(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::logger::Logger) {
1949         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.logger = val;
1950 }
1951 /// Default settings used for new channels. Any existing channels will continue to use the
1952 /// runtime settings which were stored when the ChannelManager was serialized.
1953 #[no_mangle]
1954 pub extern "C" fn ChannelManagerReadArgs_get_default_config(this_ptr: &ChannelManagerReadArgs) -> crate::lightning::util::config::UserConfig {
1955         let mut inner_val = &mut this_ptr.get_native_mut_ref().default_config;
1956         crate::lightning::util::config::UserConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
1957 }
1958 /// Default settings used for new channels. Any existing channels will continue to use the
1959 /// runtime settings which were stored when the ChannelManager was serialized.
1960 #[no_mangle]
1961 pub extern "C" fn ChannelManagerReadArgs_set_default_config(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::config::UserConfig) {
1962         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.default_config = *unsafe { Box::from_raw(val.take_inner()) };
1963 }
1964 /// Simple utility function to create a ChannelManagerReadArgs which creates the monitor
1965 /// HashMap for you. This is primarily useful for C bindings where it is not practical to
1966 /// populate a HashMap directly from C.
1967 #[must_use]
1968 #[no_mangle]
1969 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) -> ChannelManagerReadArgs {
1970         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() }); };
1971         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);
1972         ChannelManagerReadArgs { inner: ObjOps::heap_alloc(ret), is_owned: true }
1973 }
1974
1975 #[no_mangle]
1976 /// Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_write
1977 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 {
1978         let arg_conv = *unsafe { Box::from_raw(arg.take_inner()) };
1979         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);
1980         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() };
1981         local_res
1982 }