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