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