Update auto-generated bindings with latest upstream + generator
[ldk-c-bindings] / lightning-c-bindings / src / 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::ffi::c_void;
21 use bitcoin::hashes::Hash;
22 use crate::c_types::*;
23
24
25 use lightning::ln::channelmanager::ChannelManager as nativeChannelManagerImport;
26 type nativeChannelManager = nativeChannelManagerImport<crate::chain::keysinterface::Sign, crate::chain::Watch, crate::chain::chaininterface::BroadcasterInterface, crate::chain::keysinterface::KeysInterface, crate::chain::chaininterface::FeeEstimator, crate::util::logger::Logger>;
27
28 /// Manager which keeps track of a number of channels and sends messages to the appropriate
29 /// channel, also tracking HTLC preimages and forwarding onion packets appropriately.
30 ///
31 /// Implements ChannelMessageHandler, handling the multi-channel parts and passing things through
32 /// to individual Channels.
33 ///
34 /// Implements Writeable to write out all channel state to disk. Implies peer_disconnected() for
35 /// all peers during write/read (though does not modify this instance, only the instance being
36 /// serialized). This will result in any channels which have not yet exchanged funding_created (ie
37 /// called funding_transaction_generated for outbound channels).
38 ///
39 /// Note that you can be a bit lazier about writing out ChannelManager than you can be with
40 /// ChannelMonitors. With ChannelMonitors you MUST write each monitor update out to disk before
41 /// returning from chain::Watch::watch_/update_channel, with ChannelManagers, writing updates
42 /// happens out-of-band (and will prevent any other ChannelManager operations from occurring during
43 /// the serialization process). If the deserialized version is out-of-date compared to the
44 /// ChannelMonitors passed by reference to read(), those channels will be force-closed based on the
45 /// ChannelMonitor state and no funds will be lost (mod on-chain transaction fees).
46 ///
47 /// Note that the deserializer is only implemented for (BlockHash, ChannelManager), which
48 /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
49 /// the \"reorg path\" (ie call block_disconnected() until you get to a common block and then call
50 /// block_connected() to step towards your best block) upon deserialization before using the
51 /// object!
52 ///
53 /// Note that ChannelManager is responsible for tracking liveness of its channels and generating
54 /// ChannelUpdate messages informing peers that the channel is temporarily disabled. To avoid
55 /// spam due to quick disconnection/reconnection, updates are not sent until the channel has been
56 /// offline for a full minute. In order to track this, you must call
57 /// timer_chan_freshness_every_min roughly once per minute, though it doesn't have to be perfect.
58 ///
59 /// Rather than using a plain ChannelManager, it is preferable to use either a SimpleArcChannelManager
60 /// a SimpleRefChannelManager, for conciseness. See their documentation for more details, but
61 /// essentially you should default to using a SimpleRefChannelManager, and use a
62 /// SimpleArcChannelManager when you require a ChannelManager with a static lifetime, such as when
63 /// you're using lightning-net-tokio.
64 #[must_use]
65 #[repr(C)]
66 pub struct ChannelManager {
67         /// A pointer to the opaque Rust object.
68
69         /// Nearly everywhere, inner must be non-null, however in places where
70         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
71         pub inner: *mut nativeChannelManager,
72         /// Indicates that this is the only struct which contains the same pointer.
73
74         /// Rust functions which take ownership of an object provided via an argument require
75         /// this to be true and invalidate the object pointed to by inner.
76         pub is_owned: bool,
77 }
78
79 impl Drop for ChannelManager {
80         fn drop(&mut self) {
81                 if self.is_owned && !<*mut nativeChannelManager>::is_null(self.inner) {
82                         let _ = unsafe { Box::from_raw(self.inner) };
83                 }
84         }
85 }
86 /// Frees any resources used by the ChannelManager, if is_owned is set and inner is non-NULL.
87 #[no_mangle]
88 pub extern "C" fn ChannelManager_free(this_obj: ChannelManager) { }
89 #[allow(unused)]
90 /// Used only if an object of this type is returned as a trait impl by a method
91 extern "C" fn ChannelManager_free_void(this_ptr: *mut c_void) {
92         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManager); }
93 }
94 #[allow(unused)]
95 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
96 impl ChannelManager {
97         pub(crate) fn take_inner(mut self) -> *mut nativeChannelManager {
98                 assert!(self.is_owned);
99                 let ret = self.inner;
100                 self.inner = std::ptr::null_mut();
101                 ret
102         }
103 }
104
105 use lightning::ln::channelmanager::ChainParameters as nativeChainParametersImport;
106 type nativeChainParameters = nativeChainParametersImport;
107
108 /// Chain-related parameters used to construct a new `ChannelManager`.
109 ///
110 /// Typically, the block-specific parameters are derived from the best block hash for the network,
111 /// as a newly constructed `ChannelManager` will not have created any channels yet. These parameters
112 /// are not needed when deserializing a previously constructed `ChannelManager`.
113 #[must_use]
114 #[repr(C)]
115 pub struct ChainParameters {
116         /// A pointer to the opaque Rust object.
117
118         /// Nearly everywhere, inner must be non-null, however in places where
119         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
120         pub inner: *mut nativeChainParameters,
121         /// Indicates that this is the only struct which contains the same pointer.
122
123         /// Rust functions which take ownership of an object provided via an argument require
124         /// this to be true and invalidate the object pointed to by inner.
125         pub is_owned: bool,
126 }
127
128 impl Drop for ChainParameters {
129         fn drop(&mut self) {
130                 if self.is_owned && !<*mut nativeChainParameters>::is_null(self.inner) {
131                         let _ = unsafe { Box::from_raw(self.inner) };
132                 }
133         }
134 }
135 /// Frees any resources used by the ChainParameters, if is_owned is set and inner is non-NULL.
136 #[no_mangle]
137 pub extern "C" fn ChainParameters_free(this_obj: ChainParameters) { }
138 #[allow(unused)]
139 /// Used only if an object of this type is returned as a trait impl by a method
140 extern "C" fn ChainParameters_free_void(this_ptr: *mut c_void) {
141         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChainParameters); }
142 }
143 #[allow(unused)]
144 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
145 impl ChainParameters {
146         pub(crate) fn take_inner(mut self) -> *mut nativeChainParameters {
147                 assert!(self.is_owned);
148                 let ret = self.inner;
149                 self.inner = std::ptr::null_mut();
150                 ret
151         }
152 }
153 /// The network for determining the `chain_hash` in Lightning messages.
154 #[no_mangle]
155 pub extern "C" fn ChainParameters_get_network(this_ptr: &ChainParameters) -> crate::bitcoin::network::Network {
156         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.network;
157         crate::bitcoin::network::Network::from_bitcoin((*inner_val))
158 }
159 /// The network for determining the `chain_hash` in Lightning messages.
160 #[no_mangle]
161 pub extern "C" fn ChainParameters_set_network(this_ptr: &mut ChainParameters, mut val: crate::bitcoin::network::Network) {
162         unsafe { &mut *this_ptr.inner }.network = val.into_bitcoin();
163 }
164 /// The hash of the latest block successfully connected.
165 #[no_mangle]
166 pub extern "C" fn ChainParameters_get_latest_hash(this_ptr: &ChainParameters) -> *const [u8; 32] {
167         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.latest_hash;
168         (*inner_val).as_inner()
169 }
170 /// The hash of the latest block successfully connected.
171 #[no_mangle]
172 pub extern "C" fn ChainParameters_set_latest_hash(this_ptr: &mut ChainParameters, mut val: crate::c_types::ThirtyTwoBytes) {
173         unsafe { &mut *this_ptr.inner }.latest_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap();
174 }
175 /// The height of the latest block successfully connected.
176 ///
177 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
178 #[no_mangle]
179 pub extern "C" fn ChainParameters_get_latest_height(this_ptr: &ChainParameters) -> usize {
180         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.latest_height;
181         (*inner_val)
182 }
183 /// The height of the latest block successfully connected.
184 ///
185 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
186 #[no_mangle]
187 pub extern "C" fn ChainParameters_set_latest_height(this_ptr: &mut ChainParameters, mut val: usize) {
188         unsafe { &mut *this_ptr.inner }.latest_height = val;
189 }
190 /// Constructs a new ChainParameters given each field
191 #[must_use]
192 #[no_mangle]
193 pub extern "C" fn ChainParameters_new(mut network_arg: crate::bitcoin::network::Network, mut latest_hash_arg: crate::c_types::ThirtyTwoBytes, mut latest_height_arg: usize) -> ChainParameters {
194         ChainParameters { inner: Box::into_raw(Box::new(nativeChainParameters {
195                 network: network_arg.into_bitcoin(),
196                 latest_hash: ::bitcoin::hash_types::BlockHash::from_slice(&latest_hash_arg.data[..]).unwrap(),
197                 latest_height: latest_height_arg,
198         })), is_owned: true }
199 }
200 /// The amount of time in blocks we require our counterparty wait to claim their money (ie time
201 /// between when we, or our watchtower, must check for them having broadcast a theft transaction).
202 ///
203 /// This can be increased (but not decreased) through [`ChannelHandshakeConfig::our_to_self_delay`]
204 ///
205 /// [`ChannelHandshakeConfig::our_to_self_delay`]: crate::util::config::ChannelHandshakeConfig::our_to_self_delay
206
207 #[no_mangle]
208 pub static BREAKDOWN_TIMEOUT: u16 = lightning::ln::channelmanager::BREAKDOWN_TIMEOUT;
209 /// The minimum number of blocks between an inbound HTLC's CLTV and the corresponding outbound
210 /// HTLC's CLTV. The current default represents roughly six hours of blocks at six blocks/hour.
211 ///
212 /// This can be increased (but not decreased) through [`ChannelConfig::cltv_expiry_delta`]
213 ///
214 /// [`ChannelConfig::cltv_expiry_delta`]: crate::util::config::ChannelConfig::cltv_expiry_delta
215
216 #[no_mangle]
217 pub static MIN_CLTV_EXPIRY_DELTA: u16 = lightning::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA;
218
219 use lightning::ln::channelmanager::ChannelDetails as nativeChannelDetailsImport;
220 type nativeChannelDetails = nativeChannelDetailsImport;
221
222 /// Details of a channel, as returned by ChannelManager::list_channels and ChannelManager::list_usable_channels
223 #[must_use]
224 #[repr(C)]
225 pub struct ChannelDetails {
226         /// A pointer to the opaque Rust object.
227
228         /// Nearly everywhere, inner must be non-null, however in places where
229         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
230         pub inner: *mut nativeChannelDetails,
231         /// Indicates that this is the only struct which contains the same pointer.
232
233         /// Rust functions which take ownership of an object provided via an argument require
234         /// this to be true and invalidate the object pointed to by inner.
235         pub is_owned: bool,
236 }
237
238 impl Drop for ChannelDetails {
239         fn drop(&mut self) {
240                 if self.is_owned && !<*mut nativeChannelDetails>::is_null(self.inner) {
241                         let _ = unsafe { Box::from_raw(self.inner) };
242                 }
243         }
244 }
245 /// Frees any resources used by the ChannelDetails, if is_owned is set and inner is non-NULL.
246 #[no_mangle]
247 pub extern "C" fn ChannelDetails_free(this_obj: ChannelDetails) { }
248 #[allow(unused)]
249 /// Used only if an object of this type is returned as a trait impl by a method
250 extern "C" fn ChannelDetails_free_void(this_ptr: *mut c_void) {
251         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelDetails); }
252 }
253 #[allow(unused)]
254 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
255 impl ChannelDetails {
256         pub(crate) fn take_inner(mut self) -> *mut nativeChannelDetails {
257                 assert!(self.is_owned);
258                 let ret = self.inner;
259                 self.inner = std::ptr::null_mut();
260                 ret
261         }
262 }
263 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
264 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
265 /// Note that this means this value is *not* persistent - it can change once during the
266 /// lifetime of the channel.
267 #[no_mangle]
268 pub extern "C" fn ChannelDetails_get_channel_id(this_ptr: &ChannelDetails) -> *const [u8; 32] {
269         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_id;
270         &(*inner_val)
271 }
272 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
273 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
274 /// Note that this means this value is *not* persistent - it can change once during the
275 /// lifetime of the channel.
276 #[no_mangle]
277 pub extern "C" fn ChannelDetails_set_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::ThirtyTwoBytes) {
278         unsafe { &mut *this_ptr.inner }.channel_id = val.data;
279 }
280 /// The position of the funding transaction in the chain. None if the funding transaction has
281 /// not yet been confirmed and the channel fully opened.
282 #[no_mangle]
283 pub extern "C" fn ChannelDetails_get_short_channel_id(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
284         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.short_channel_id;
285         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()) } };
286         local_inner_val
287 }
288 /// The position of the funding transaction in the chain. None if the funding transaction has
289 /// not yet been confirmed and the channel fully opened.
290 #[no_mangle]
291 pub extern "C" fn ChannelDetails_set_short_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
292         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
293         unsafe { &mut *this_ptr.inner }.short_channel_id = local_val;
294 }
295 /// The node_id of our counterparty
296 #[no_mangle]
297 pub extern "C" fn ChannelDetails_get_remote_network_id(this_ptr: &ChannelDetails) -> crate::c_types::PublicKey {
298         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.remote_network_id;
299         crate::c_types::PublicKey::from_rust(&(*inner_val))
300 }
301 /// The node_id of our counterparty
302 #[no_mangle]
303 pub extern "C" fn ChannelDetails_set_remote_network_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::PublicKey) {
304         unsafe { &mut *this_ptr.inner }.remote_network_id = val.into_rust();
305 }
306 /// The Features the channel counterparty provided upon last connection.
307 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
308 /// many routing-relevant features are present in the init context.
309 #[no_mangle]
310 pub extern "C" fn ChannelDetails_get_counterparty_features(this_ptr: &ChannelDetails) -> crate::ln::features::InitFeatures {
311         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.counterparty_features;
312         crate::ln::features::InitFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
313 }
314 /// The Features the channel counterparty provided upon last connection.
315 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
316 /// many routing-relevant features are present in the init context.
317 #[no_mangle]
318 pub extern "C" fn ChannelDetails_set_counterparty_features(this_ptr: &mut ChannelDetails, mut val: crate::ln::features::InitFeatures) {
319         unsafe { &mut *this_ptr.inner }.counterparty_features = *unsafe { Box::from_raw(val.take_inner()) };
320 }
321 /// The value, in satoshis, of this channel as appears in the funding output
322 #[no_mangle]
323 pub extern "C" fn ChannelDetails_get_channel_value_satoshis(this_ptr: &ChannelDetails) -> u64 {
324         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_value_satoshis;
325         (*inner_val)
326 }
327 /// The value, in satoshis, of this channel as appears in the funding output
328 #[no_mangle]
329 pub extern "C" fn ChannelDetails_set_channel_value_satoshis(this_ptr: &mut ChannelDetails, mut val: u64) {
330         unsafe { &mut *this_ptr.inner }.channel_value_satoshis = val;
331 }
332 /// The user_id passed in to create_channel, or 0 if the channel was inbound.
333 #[no_mangle]
334 pub extern "C" fn ChannelDetails_get_user_id(this_ptr: &ChannelDetails) -> u64 {
335         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.user_id;
336         (*inner_val)
337 }
338 /// The user_id passed in to create_channel, or 0 if the channel was inbound.
339 #[no_mangle]
340 pub extern "C" fn ChannelDetails_set_user_id(this_ptr: &mut ChannelDetails, mut val: u64) {
341         unsafe { &mut *this_ptr.inner }.user_id = val;
342 }
343 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
344 /// any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
345 /// available for inclusion in new outbound HTLCs). This further does not include any pending
346 /// outgoing HTLCs which are awaiting some other resolution to be sent.
347 #[no_mangle]
348 pub extern "C" fn ChannelDetails_get_outbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
349         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.outbound_capacity_msat;
350         (*inner_val)
351 }
352 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
353 /// any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
354 /// available for inclusion in new outbound HTLCs). This further does not include any pending
355 /// outgoing HTLCs which are awaiting some other resolution to be sent.
356 #[no_mangle]
357 pub extern "C" fn ChannelDetails_set_outbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
358         unsafe { &mut *this_ptr.inner }.outbound_capacity_msat = val;
359 }
360 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
361 /// include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
362 /// available for inclusion in new inbound HTLCs).
363 /// Note that there are some corner cases not fully handled here, so the actual available
364 /// inbound capacity may be slightly higher than this.
365 #[no_mangle]
366 pub extern "C" fn ChannelDetails_get_inbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
367         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.inbound_capacity_msat;
368         (*inner_val)
369 }
370 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
371 /// include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
372 /// available for inclusion in new inbound HTLCs).
373 /// Note that there are some corner cases not fully handled here, so the actual available
374 /// inbound capacity may be slightly higher than this.
375 #[no_mangle]
376 pub extern "C" fn ChannelDetails_set_inbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
377         unsafe { &mut *this_ptr.inner }.inbound_capacity_msat = val;
378 }
379 /// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
380 /// the peer is connected, and (c) no monitor update failure is pending resolution.
381 #[no_mangle]
382 pub extern "C" fn ChannelDetails_get_is_live(this_ptr: &ChannelDetails) -> bool {
383         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.is_live;
384         (*inner_val)
385 }
386 /// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
387 /// the peer is connected, and (c) no monitor update failure is pending resolution.
388 #[no_mangle]
389 pub extern "C" fn ChannelDetails_set_is_live(this_ptr: &mut ChannelDetails, mut val: bool) {
390         unsafe { &mut *this_ptr.inner }.is_live = val;
391 }
392 impl Clone for ChannelDetails {
393         fn clone(&self) -> Self {
394                 Self {
395                         inner: if <*mut nativeChannelDetails>::is_null(self.inner) { std::ptr::null_mut() } else {
396                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
397                         is_owned: true,
398                 }
399         }
400 }
401 #[allow(unused)]
402 /// Used only if an object of this type is returned as a trait impl by a method
403 pub(crate) extern "C" fn ChannelDetails_clone_void(this_ptr: *const c_void) -> *mut c_void {
404         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelDetails)).clone() })) as *mut c_void
405 }
406 #[no_mangle]
407 /// Creates a copy of the ChannelDetails
408 pub extern "C" fn ChannelDetails_clone(orig: &ChannelDetails) -> ChannelDetails {
409         orig.clone()
410 }
411 /// If a payment fails to send, it can be in one of several states. This enum is returned as the
412 /// Err() type describing which state the payment is in, see the description of individual enum
413 /// states for more.
414 #[must_use]
415 #[derive(Clone)]
416 #[repr(C)]
417 pub enum PaymentSendFailure {
418         /// A parameter which was passed to send_payment was invalid, preventing us from attempting to
419         /// send the payment at all. No channel state has been changed or messages sent to peers, and
420         /// once you've changed the parameter at error, you can freely retry the payment in full.
421         ParameterError(crate::util::errors::APIError),
422         /// A parameter in a single path which was passed to send_payment was invalid, preventing us
423         /// from attempting to send the payment at all. No channel state has been changed or messages
424         /// sent to peers, and once you've changed the parameter at error, you can freely retry the
425         /// payment in full.
426         ///
427         /// The results here are ordered the same as the paths in the route object which was passed to
428         /// send_payment.
429         PathParameterError(crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ),
430         /// All paths which were attempted failed to send, with no channel state change taking place.
431         /// You can freely retry the payment in full (though you probably want to do so over different
432         /// paths than the ones selected).
433         AllFailedRetrySafe(crate::c_types::derived::CVec_APIErrorZ),
434         /// Some paths which were attempted failed to send, though possibly not all. At least some
435         /// paths have irrevocably committed to the HTLC and retrying the payment in full would result
436         /// in over-/re-payment.
437         ///
438         /// The results here are ordered the same as the paths in the route object which was passed to
439         /// send_payment, and any Errs which are not APIError::MonitorUpdateFailed can be safely
440         /// retried (though there is currently no API with which to do so).
441         ///
442         /// Any entries which contain Err(APIError::MonitorUpdateFailed) or Ok(()) MUST NOT be retried
443         /// as they will result in over-/re-payment. These HTLCs all either successfully sent (in the
444         /// case of Ok(())) or will send once channel_monitor_updated is called on the next-hop channel
445         /// with the latest update_id.
446         PartialFailure(crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ),
447 }
448 use lightning::ln::channelmanager::PaymentSendFailure as nativePaymentSendFailure;
449 impl PaymentSendFailure {
450         #[allow(unused)]
451         pub(crate) fn to_native(&self) -> nativePaymentSendFailure {
452                 match self {
453                         PaymentSendFailure::ParameterError (ref a, ) => {
454                                 let mut a_nonref = (*a).clone();
455                                 nativePaymentSendFailure::ParameterError (
456                                         a_nonref.into_native(),
457                                 )
458                         },
459                         PaymentSendFailure::PathParameterError (ref a, ) => {
460                                 let mut a_nonref = (*a).clone();
461                                 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 }); };
462                                 nativePaymentSendFailure::PathParameterError (
463                                         local_a_nonref,
464                                 )
465                         },
466                         PaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
467                                 let mut a_nonref = (*a).clone();
468                                 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { item.into_native() }); };
469                                 nativePaymentSendFailure::AllFailedRetrySafe (
470                                         local_a_nonref,
471                                 )
472                         },
473                         PaymentSendFailure::PartialFailure (ref a, ) => {
474                                 let mut a_nonref = (*a).clone();
475                                 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 }); };
476                                 nativePaymentSendFailure::PartialFailure (
477                                         local_a_nonref,
478                                 )
479                         },
480                 }
481         }
482         #[allow(unused)]
483         pub(crate) fn into_native(self) -> nativePaymentSendFailure {
484                 match self {
485                         PaymentSendFailure::ParameterError (mut a, ) => {
486                                 nativePaymentSendFailure::ParameterError (
487                                         a.into_native(),
488                                 )
489                         },
490                         PaymentSendFailure::PathParameterError (mut a, ) => {
491                                 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 }); };
492                                 nativePaymentSendFailure::PathParameterError (
493                                         local_a,
494                                 )
495                         },
496                         PaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
497                                 let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { item.into_native() }); };
498                                 nativePaymentSendFailure::AllFailedRetrySafe (
499                                         local_a,
500                                 )
501                         },
502                         PaymentSendFailure::PartialFailure (mut a, ) => {
503                                 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 }); };
504                                 nativePaymentSendFailure::PartialFailure (
505                                         local_a,
506                                 )
507                         },
508                 }
509         }
510         #[allow(unused)]
511         pub(crate) fn from_native(native: &nativePaymentSendFailure) -> Self {
512                 match native {
513                         nativePaymentSendFailure::ParameterError (ref a, ) => {
514                                 let mut a_nonref = (*a).clone();
515                                 PaymentSendFailure::ParameterError (
516                                         crate::util::errors::APIError::native_into(a_nonref),
517                                 )
518                         },
519                         nativePaymentSendFailure::PathParameterError (ref a, ) => {
520                                 let mut a_nonref = (*a).clone();
521                                 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( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::util::errors::APIError::native_into(e) }).into() }; local_a_nonref_0 }); };
522                                 PaymentSendFailure::PathParameterError (
523                                         local_a_nonref.into(),
524                                 )
525                         },
526                         nativePaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
527                                 let mut a_nonref = (*a).clone();
528                                 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.drain(..) { local_a_nonref.push( { crate::util::errors::APIError::native_into(item) }); };
529                                 PaymentSendFailure::AllFailedRetrySafe (
530                                         local_a_nonref.into(),
531                                 )
532                         },
533                         nativePaymentSendFailure::PartialFailure (ref a, ) => {
534                                 let mut a_nonref = (*a).clone();
535                                 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( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::util::errors::APIError::native_into(e) }).into() }; local_a_nonref_0 }); };
536                                 PaymentSendFailure::PartialFailure (
537                                         local_a_nonref.into(),
538                                 )
539                         },
540                 }
541         }
542         #[allow(unused)]
543         pub(crate) fn native_into(native: nativePaymentSendFailure) -> Self {
544                 match native {
545                         nativePaymentSendFailure::ParameterError (mut a, ) => {
546                                 PaymentSendFailure::ParameterError (
547                                         crate::util::errors::APIError::native_into(a),
548                                 )
549                         },
550                         nativePaymentSendFailure::PathParameterError (mut a, ) => {
551                                 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( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::util::errors::APIError::native_into(e) }).into() }; local_a_0 }); };
552                                 PaymentSendFailure::PathParameterError (
553                                         local_a.into(),
554                                 )
555                         },
556                         nativePaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
557                                 let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { crate::util::errors::APIError::native_into(item) }); };
558                                 PaymentSendFailure::AllFailedRetrySafe (
559                                         local_a.into(),
560                                 )
561                         },
562                         nativePaymentSendFailure::PartialFailure (mut a, ) => {
563                                 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( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::util::errors::APIError::native_into(e) }).into() }; local_a_0 }); };
564                                 PaymentSendFailure::PartialFailure (
565                                         local_a.into(),
566                                 )
567                         },
568                 }
569         }
570 }
571 /// Frees any resources used by the PaymentSendFailure
572 #[no_mangle]
573 pub extern "C" fn PaymentSendFailure_free(this_ptr: PaymentSendFailure) { }
574 /// Creates a copy of the PaymentSendFailure
575 #[no_mangle]
576 pub extern "C" fn PaymentSendFailure_clone(orig: &PaymentSendFailure) -> PaymentSendFailure {
577         orig.clone()
578 }
579 /// Constructs a new ChannelManager to hold several channels and route between them.
580 ///
581 /// This is the main \"logic hub\" for all channel-related actions, and implements
582 /// ChannelMessageHandler.
583 ///
584 /// Non-proportional fees are fixed according to our risk using the provided fee estimator.
585 ///
586 /// panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`!
587 ///
588 /// Users need to notify the new ChannelManager when a new block is connected or
589 /// disconnected using its `block_connected` and `block_disconnected` methods, starting
590 /// from after `params.latest_hash`.
591 #[must_use]
592 #[no_mangle]
593 pub extern "C" fn ChannelManager_new(mut fee_est: crate::chain::chaininterface::FeeEstimator, mut chain_monitor: crate::chain::Watch, mut tx_broadcaster: crate::chain::chaininterface::BroadcasterInterface, mut logger: crate::util::logger::Logger, mut keys_manager: crate::chain::keysinterface::KeysInterface, mut config: crate::util::config::UserConfig, mut params: crate::ln::channelmanager::ChainParameters) -> ChannelManager {
594         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()) });
595         ChannelManager { inner: Box::into_raw(Box::new(ret)), is_owned: true }
596 }
597
598 /// Creates a new outbound channel to the given remote node and with the given value.
599 ///
600 /// user_id will be provided back as user_channel_id in FundingGenerationReady events to allow
601 /// tracking of which events correspond with which create_channel call. Note that the
602 /// user_channel_id defaults to 0 for inbound channels, so you may wish to avoid using 0 for
603 /// user_id here. user_id has no meaning inside of LDK, it is simply copied to events and
604 /// otherwise ignored.
605 ///
606 /// If successful, will generate a SendOpenChannel message event, so you should probably poll
607 /// PeerManager::process_events afterwards.
608 ///
609 /// Raises APIError::APIMisuseError when channel_value_satoshis > 2**24 or push_msat is
610 /// greater than channel_value_satoshis * 1k or channel_value_satoshis is < 1000.
611 #[must_use]
612 #[no_mangle]
613 pub extern "C" fn ChannelManager_create_channel(this_arg: &ChannelManager, mut their_network_key: crate::c_types::PublicKey, mut channel_value_satoshis: u64, mut push_msat: u64, mut user_id: u64, mut override_config: crate::util::config::UserConfig) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
614         let mut local_override_config = if override_config.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(override_config.take_inner()) } }) };
615         let mut ret = unsafe { &*this_arg.inner }.create_channel(their_network_key.into_rust(), channel_value_satoshis, push_msat, user_id, local_override_config);
616         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::util::errors::APIError::native_into(e) }).into() };
617         local_ret
618 }
619
620 /// Gets the list of open channels, in random order. See ChannelDetail field documentation for
621 /// more information.
622 #[must_use]
623 #[no_mangle]
624 pub extern "C" fn ChannelManager_list_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
625         let mut ret = unsafe { &*this_arg.inner }.list_channels();
626         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::ln::channelmanager::ChannelDetails { inner: Box::into_raw(Box::new(item)), is_owned: true } }); };
627         local_ret.into()
628 }
629
630 /// Gets the list of usable channels, in random order. Useful as an argument to
631 /// get_route to ensure non-announced channels are used.
632 ///
633 /// These are guaranteed to have their is_live value set to true, see the documentation for
634 /// ChannelDetails::is_live for more info on exactly what the criteria are.
635 #[must_use]
636 #[no_mangle]
637 pub extern "C" fn ChannelManager_list_usable_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
638         let mut ret = unsafe { &*this_arg.inner }.list_usable_channels();
639         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::ln::channelmanager::ChannelDetails { inner: Box::into_raw(Box::new(item)), is_owned: true } }); };
640         local_ret.into()
641 }
642
643 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
644 /// will be accepted on the given channel, and after additional timeout/the closing of all
645 /// pending HTLCs, the channel will be closed on chain.
646 ///
647 /// May generate a SendShutdown message event on success, which should be relayed.
648 #[must_use]
649 #[no_mangle]
650 pub extern "C" fn ChannelManager_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
651         let mut ret = unsafe { &*this_arg.inner }.close_channel(unsafe { &*channel_id});
652         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::util::errors::APIError::native_into(e) }).into() };
653         local_ret
654 }
655
656 /// Force closes a channel, immediately broadcasting the latest local commitment transaction to
657 /// the chain and rejecting new HTLCs on the given channel. Fails if channel_id is unknown to the manager.
658 #[must_use]
659 #[no_mangle]
660 pub extern "C" fn ChannelManager_force_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
661         let mut ret = unsafe { &*this_arg.inner }.force_close_channel(unsafe { &*channel_id});
662         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::util::errors::APIError::native_into(e) }).into() };
663         local_ret
664 }
665
666 /// Force close all channels, immediately broadcasting the latest local commitment transaction
667 /// for each to the chain and rejecting new HTLCs on each.
668 #[no_mangle]
669 pub extern "C" fn ChannelManager_force_close_all_channels(this_arg: &ChannelManager) {
670         unsafe { &*this_arg.inner }.force_close_all_channels()
671 }
672
673 /// Sends a payment along a given route.
674 ///
675 /// Value parameters are provided via the last hop in route, see documentation for RouteHop
676 /// fields for more info.
677 ///
678 /// Note that if the payment_hash already exists elsewhere (eg you're sending a duplicative
679 /// payment), we don't do anything to stop you! We always try to ensure that if the provided
680 /// next hop knows the preimage to payment_hash they can claim an additional amount as
681 /// specified in the last hop in the route! Thus, you should probably do your own
682 /// payment_preimage tracking (which you should already be doing as they represent \"proof of
683 /// payment\") and prevent double-sends yourself.
684 ///
685 /// May generate SendHTLCs message(s) event on success, which should be relayed.
686 ///
687 /// Each path may have a different return value, and PaymentSendValue may return a Vec with
688 /// each entry matching the corresponding-index entry in the route paths, see
689 /// PaymentSendFailure for more info.
690 ///
691 /// In general, a path may raise:
692 ///  * APIError::RouteError when an invalid route or forwarding parameter (cltv_delta, fee,
693 ///    node public key) is specified.
694 ///  * APIError::ChannelUnavailable if the next-hop channel is not available for updates
695 ///    (including due to previous monitor update failure or new permanent monitor update
696 ///    failure).
697 ///  * APIError::MonitorUpdateFailed if a new monitor update failure prevented sending the
698 ///    relevant updates.
699 ///
700 /// Note that depending on the type of the PaymentSendFailure the HTLC may have been
701 /// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
702 /// different route unless you intend to pay twice!
703 ///
704 /// payment_secret is unrelated to payment_hash (or PaymentPreimage) and exists to authenticate
705 /// the sender to the recipient and prevent payment-probing (deanonymization) attacks. For
706 /// newer nodes, it will be provided to you in the invoice. If you do not have one, the Route
707 /// must not contain multiple paths as multi-path payments require a recipient-provided
708 /// payment_secret.
709 /// If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature
710 /// bit set (either as required or as available). If multiple paths are present in the Route,
711 /// we assume the invoice had the basic_mpp feature set.
712 #[must_use]
713 #[no_mangle]
714 pub extern "C" fn ChannelManager_send_payment(this_arg: &ChannelManager, route: &crate::routing::router::Route, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut payment_secret: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_NonePaymentSendFailureZ {
715         let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentSecret(payment_secret.data) }) };
716         let mut ret = unsafe { &*this_arg.inner }.send_payment(unsafe { &*route.inner }, ::lightning::ln::channelmanager::PaymentHash(payment_hash.data), &local_payment_secret);
717         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::channelmanager::PaymentSendFailure::native_into(e) }).into() };
718         local_ret
719 }
720
721 /// Call this upon creation of a funding transaction for the given channel.
722 ///
723 /// Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
724 /// or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
725 ///
726 /// Panics if a funding transaction has already been provided for this channel.
727 ///
728 /// May panic if the output found in the funding transaction is duplicative with some other
729 /// channel (note that this should be trivially prevented by using unique funding transaction
730 /// keys per-channel).
731 ///
732 /// Do NOT broadcast the funding transaction yourself. When we have safely received our
733 /// counterparty's signature the funding transaction will automatically be broadcast via the
734 /// [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
735 ///
736 /// Note that this includes RBF or similar transaction replacement strategies - lightning does
737 /// not currently support replacing a funding transaction on an existing channel. Instead,
738 /// create a new channel with a conflicting funding transaction.
739 #[must_use]
740 #[no_mangle]
741 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 {
742         let mut ret = unsafe { &*this_arg.inner }.funding_transaction_generated(unsafe { &*temporary_channel_id}, funding_transaction.into_bitcoin());
743         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::util::errors::APIError::native_into(e) }).into() };
744         local_ret
745 }
746
747 /// Generates a signed node_announcement from the given arguments and creates a
748 /// BroadcastNodeAnnouncement event. Note that such messages will be ignored unless peers have
749 /// seen a channel_announcement from us (ie unless we have public channels open).
750 ///
751 /// RGB is a node \"color\" and alias is a printable human-readable string to describe this node
752 /// to humans. They carry no in-protocol meaning.
753 ///
754 /// addresses represent the set (possibly empty) of socket addresses on which this node accepts
755 /// incoming connections. These will be broadcast to the network, publicly tying these
756 /// addresses together. If you wish to preserve user privacy, addresses should likely contain
757 /// only Tor Onion addresses.
758 ///
759 /// Panics if addresses is absurdly large (more than 500).
760 #[no_mangle]
761 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) {
762         let mut local_addresses = Vec::new(); for mut item in addresses.into_rust().drain(..) { local_addresses.push( { item.into_native() }); };
763         unsafe { &*this_arg.inner }.broadcast_node_announcement(rgb.data, alias.data, local_addresses)
764 }
765
766 /// Processes HTLCs which are pending waiting on random forward delay.
767 ///
768 /// Should only really ever be called in response to a PendingHTLCsForwardable event.
769 /// Will likely generate further events.
770 #[no_mangle]
771 pub extern "C" fn ChannelManager_process_pending_htlc_forwards(this_arg: &ChannelManager) {
772         unsafe { &*this_arg.inner }.process_pending_htlc_forwards()
773 }
774
775 /// If a peer is disconnected we mark any channels with that peer as 'disabled'.
776 /// After some time, if channels are still disabled we need to broadcast a ChannelUpdate
777 /// to inform the network about the uselessness of these channels.
778 ///
779 /// This method handles all the details, and must be called roughly once per minute.
780 ///
781 /// Note that in some rare cases this may generate a `chain::Watch::update_channel` call.
782 #[no_mangle]
783 pub extern "C" fn ChannelManager_timer_chan_freshness_every_min(this_arg: &ChannelManager) {
784         unsafe { &*this_arg.inner }.timer_chan_freshness_every_min()
785 }
786
787 /// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
788 /// after a PaymentReceived event, failing the HTLC back to its origin and freeing resources
789 /// along the path (including in our own channel on which we received it).
790 /// Returns false if no payment was found to fail backwards, true if the process of failing the
791 /// HTLC backwards has been started.
792 #[must_use]
793 #[no_mangle]
794 pub extern "C" fn ChannelManager_fail_htlc_backwards(this_arg: &ChannelManager, payment_hash: *const [u8; 32], mut payment_secret: crate::c_types::ThirtyTwoBytes) -> bool {
795         let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentSecret(payment_secret.data) }) };
796         let mut ret = unsafe { &*this_arg.inner }.fail_htlc_backwards(&::lightning::ln::channelmanager::PaymentHash(unsafe { *payment_hash }), &local_payment_secret);
797         ret
798 }
799
800 /// Provides a payment preimage in response to a PaymentReceived event, returning true and
801 /// generating message events for the net layer to claim the payment, if possible. Thus, you
802 /// should probably kick the net layer to go send messages if this returns true!
803 ///
804 /// You must specify the expected amounts for this HTLC, and we will only claim HTLCs
805 /// available within a few percent of the expected amount. This is critical for several
806 /// reasons : a) it avoids providing senders with `proof-of-payment` (in the form of the
807 /// payment_preimage without having provided the full value and b) it avoids certain
808 /// privacy-breaking recipient-probing attacks which may reveal payment activity to
809 /// motivated attackers.
810 ///
811 /// Note that the privacy concerns in (b) are not relevant in payments with a payment_secret
812 /// set. Thus, for such payments we will claim any payments which do not under-pay.
813 ///
814 /// May panic if called except in response to a PaymentReceived event.
815 #[must_use]
816 #[no_mangle]
817 pub extern "C" fn ChannelManager_claim_funds(this_arg: &ChannelManager, mut payment_preimage: crate::c_types::ThirtyTwoBytes, mut payment_secret: crate::c_types::ThirtyTwoBytes, mut expected_amount: u64) -> bool {
818         let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentSecret(payment_secret.data) }) };
819         let mut ret = unsafe { &*this_arg.inner }.claim_funds(::lightning::ln::channelmanager::PaymentPreimage(payment_preimage.data), &local_payment_secret, expected_amount);
820         ret
821 }
822
823 /// Gets the node_id held by this ChannelManager
824 #[must_use]
825 #[no_mangle]
826 pub extern "C" fn ChannelManager_get_our_node_id(this_arg: &ChannelManager) -> crate::c_types::PublicKey {
827         let mut ret = unsafe { &*this_arg.inner }.get_our_node_id();
828         crate::c_types::PublicKey::from_rust(&ret)
829 }
830
831 /// Restores a single, given channel to normal operation after a
832 /// ChannelMonitorUpdateErr::TemporaryFailure was returned from a channel monitor update
833 /// operation.
834 ///
835 /// All ChannelMonitor updates up to and including highest_applied_update_id must have been
836 /// fully committed in every copy of the given channels' ChannelMonitors.
837 ///
838 /// Note that there is no effect to calling with a highest_applied_update_id other than the
839 /// current latest ChannelMonitorUpdate and one call to this function after multiple
840 /// ChannelMonitorUpdateErr::TemporaryFailures is fine. The highest_applied_update_id field
841 /// exists largely only to prevent races between this and concurrent update_monitor calls.
842 ///
843 /// Thus, the anticipated use is, at a high level:
844 ///  1) You register a chain::Watch with this ChannelManager,
845 ///  2) it stores each update to disk, and begins updating any remote (eg watchtower) copies of
846 ///     said ChannelMonitors as it can, returning ChannelMonitorUpdateErr::TemporaryFailures
847 ///     any time it cannot do so instantly,
848 ///  3) update(s) are applied to each remote copy of a ChannelMonitor,
849 ///  4) once all remote copies are updated, you call this function with the update_id that
850 ///     completed, and once it is the latest the Channel will be re-enabled.
851 #[no_mangle]
852 pub extern "C" fn ChannelManager_channel_monitor_updated(this_arg: &ChannelManager, funding_txo: &crate::chain::transaction::OutPoint, mut highest_applied_update_id: u64) {
853         unsafe { &*this_arg.inner }.channel_monitor_updated(unsafe { &*funding_txo.inner }, highest_applied_update_id)
854 }
855
856 impl From<nativeChannelManager> for crate::util::events::MessageSendEventsProvider {
857         fn from(obj: nativeChannelManager) -> Self {
858                 let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true };
859                 let mut ret = ChannelManager_as_MessageSendEventsProvider(&rust_obj);
860                 // 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
861                 rust_obj.inner = std::ptr::null_mut();
862                 ret.free = Some(ChannelManager_free_void);
863                 ret
864         }
865 }
866 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
867 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
868 #[no_mangle]
869 pub extern "C" fn ChannelManager_as_MessageSendEventsProvider(this_arg: &ChannelManager) -> crate::util::events::MessageSendEventsProvider {
870         crate::util::events::MessageSendEventsProvider {
871                 this_arg: unsafe { (*this_arg).inner as *mut c_void },
872                 free: None,
873                 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
874         }
875 }
876
877 #[must_use]
878 extern "C" fn ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
879         let mut ret = <nativeChannelManager as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
880         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); };
881         local_ret.into()
882 }
883
884 impl From<nativeChannelManager> for crate::util::events::EventsProvider {
885         fn from(obj: nativeChannelManager) -> Self {
886                 let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true };
887                 let mut ret = ChannelManager_as_EventsProvider(&rust_obj);
888                 // 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
889                 rust_obj.inner = std::ptr::null_mut();
890                 ret.free = Some(ChannelManager_free_void);
891                 ret
892         }
893 }
894 /// Constructs a new EventsProvider which calls the relevant methods on this_arg.
895 /// This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
896 #[no_mangle]
897 pub extern "C" fn ChannelManager_as_EventsProvider(this_arg: &ChannelManager) -> crate::util::events::EventsProvider {
898         crate::util::events::EventsProvider {
899                 this_arg: unsafe { (*this_arg).inner as *mut c_void },
900                 free: None,
901                 get_and_clear_pending_events: ChannelManager_EventsProvider_get_and_clear_pending_events,
902         }
903 }
904
905 #[must_use]
906 extern "C" fn ChannelManager_EventsProvider_get_and_clear_pending_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_EventZ {
907         let mut ret = <nativeChannelManager as lightning::util::events::EventsProvider<>>::get_and_clear_pending_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
908         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::Event::native_into(item) }); };
909         local_ret.into()
910 }
911
912 impl From<nativeChannelManager> for crate::chain::Listen {
913         fn from(obj: nativeChannelManager) -> Self {
914                 let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true };
915                 let mut ret = ChannelManager_as_Listen(&rust_obj);
916                 // 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
917                 rust_obj.inner = std::ptr::null_mut();
918                 ret.free = Some(ChannelManager_free_void);
919                 ret
920         }
921 }
922 /// Constructs a new Listen which calls the relevant methods on this_arg.
923 /// This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
924 #[no_mangle]
925 pub extern "C" fn ChannelManager_as_Listen(this_arg: &ChannelManager) -> crate::chain::Listen {
926         crate::chain::Listen {
927                 this_arg: unsafe { (*this_arg).inner as *mut c_void },
928                 free: None,
929                 block_connected: ChannelManager_Listen_block_connected,
930                 block_disconnected: ChannelManager_Listen_block_disconnected,
931         }
932 }
933
934 extern "C" fn ChannelManager_Listen_block_connected(this_arg: *const c_void, mut block: crate::c_types::u8slice, mut height: u32) {
935         <nativeChannelManager as lightning::chain::Listen<>>::block_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height)
936 }
937 extern "C" fn ChannelManager_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
938         <nativeChannelManager as lightning::chain::Listen<>>::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
939 }
940
941 /// Updates channel state to take note of transactions which were confirmed in the given block
942 /// at the given height.
943 ///
944 /// Note that you must still call (or have called) [`update_best_block`] with the block
945 /// information which is included here.
946 ///
947 /// This method may be called before or after [`update_best_block`] for a given block's
948 /// transaction data and may be called multiple times with additional transaction data for a
949 /// given block.
950 ///
951 /// This method may be called for a previous block after an [`update_best_block`] call has
952 /// been made for a later block, however it must *not* be called with transaction data from a
953 /// block which is no longer in the best chain (ie where [`update_best_block`] has already
954 /// been informed about a blockchain reorganization which no longer includes the block which
955 /// corresponds to `header`).
956 ///
957 /// [`update_best_block`]: `Self::update_best_block`
958 #[no_mangle]
959 pub extern "C" fn ChannelManager_transactions_confirmed(this_arg: &ChannelManager, header: *const [u8; 80], mut height: u32, mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ) {
960         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 }); };
961         unsafe { &*this_arg.inner }.transactions_confirmed(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height, &local_txdata.iter().map(|(a, b)| (*a, b)).collect::<Vec<_>>()[..])
962 }
963
964 /// Updates channel state with the current best blockchain tip. You should attempt to call this
965 /// quickly after a new block becomes available, however if multiple new blocks become
966 /// available at the same time, only a single `update_best_block()` call needs to be made.
967 ///
968 /// This method should also be called immediately after any block disconnections, once at the
969 /// reorganization fork point, and once with the new chain tip. Calling this method at the
970 /// blockchain reorganization fork point ensures we learn when a funding transaction which was
971 /// previously confirmed is reorganized out of the blockchain, ensuring we do not continue to
972 /// accept payments which cannot be enforced on-chain.
973 ///
974 /// In both the block-connection and block-disconnection case, this method may be called either
975 /// once per block connected or disconnected, or simply at the fork point and new tip(s),
976 /// skipping any intermediary blocks.
977 #[no_mangle]
978 pub extern "C" fn ChannelManager_update_best_block(this_arg: &ChannelManager, header: *const [u8; 80], mut height: u32) {
979         unsafe { &*this_arg.inner }.update_best_block(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
980 }
981
982 /// Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
983 /// indicating whether persistence is necessary. Only one listener on
984 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
985 /// up.
986 /// Note that the feature `allow_wallclock_use` must be enabled to use this function.
987 #[must_use]
988 #[no_mangle]
989 pub extern "C" fn ChannelManager_await_persistable_update_timeout(this_arg: &ChannelManager, mut max_wait: u64) -> bool {
990         let mut ret = unsafe { &*this_arg.inner }.await_persistable_update_timeout(std::time::Duration::from_secs(max_wait));
991         ret
992 }
993
994 /// Blocks until ChannelManager needs to be persisted. Only one listener on
995 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
996 /// up.
997 #[no_mangle]
998 pub extern "C" fn ChannelManager_await_persistable_update(this_arg: &ChannelManager) {
999         unsafe { &*this_arg.inner }.await_persistable_update()
1000 }
1001
1002 impl From<nativeChannelManager> for crate::ln::msgs::ChannelMessageHandler {
1003         fn from(obj: nativeChannelManager) -> Self {
1004                 let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true };
1005                 let mut ret = ChannelManager_as_ChannelMessageHandler(&rust_obj);
1006                 // 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
1007                 rust_obj.inner = std::ptr::null_mut();
1008                 ret.free = Some(ChannelManager_free_void);
1009                 ret
1010         }
1011 }
1012 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
1013 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
1014 #[no_mangle]
1015 pub extern "C" fn ChannelManager_as_ChannelMessageHandler(this_arg: &ChannelManager) -> crate::ln::msgs::ChannelMessageHandler {
1016         crate::ln::msgs::ChannelMessageHandler {
1017                 this_arg: unsafe { (*this_arg).inner as *mut c_void },
1018                 free: None,
1019                 handle_open_channel: ChannelManager_ChannelMessageHandler_handle_open_channel,
1020                 handle_accept_channel: ChannelManager_ChannelMessageHandler_handle_accept_channel,
1021                 handle_funding_created: ChannelManager_ChannelMessageHandler_handle_funding_created,
1022                 handle_funding_signed: ChannelManager_ChannelMessageHandler_handle_funding_signed,
1023                 handle_funding_locked: ChannelManager_ChannelMessageHandler_handle_funding_locked,
1024                 handle_shutdown: ChannelManager_ChannelMessageHandler_handle_shutdown,
1025                 handle_closing_signed: ChannelManager_ChannelMessageHandler_handle_closing_signed,
1026                 handle_update_add_htlc: ChannelManager_ChannelMessageHandler_handle_update_add_htlc,
1027                 handle_update_fulfill_htlc: ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc,
1028                 handle_update_fail_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_htlc,
1029                 handle_update_fail_malformed_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_malformed_htlc,
1030                 handle_commitment_signed: ChannelManager_ChannelMessageHandler_handle_commitment_signed,
1031                 handle_revoke_and_ack: ChannelManager_ChannelMessageHandler_handle_revoke_and_ack,
1032                 handle_update_fee: ChannelManager_ChannelMessageHandler_handle_update_fee,
1033                 handle_announcement_signatures: ChannelManager_ChannelMessageHandler_handle_announcement_signatures,
1034                 peer_disconnected: ChannelManager_ChannelMessageHandler_peer_disconnected,
1035                 peer_connected: ChannelManager_ChannelMessageHandler_peer_connected,
1036                 handle_channel_reestablish: ChannelManager_ChannelMessageHandler_handle_channel_reestablish,
1037                 handle_channel_update: ChannelManager_ChannelMessageHandler_handle_channel_update,
1038                 handle_error: ChannelManager_ChannelMessageHandler_handle_error,
1039                 MessageSendEventsProvider: crate::util::events::MessageSendEventsProvider {
1040                         this_arg: unsafe { (*this_arg).inner as *mut c_void },
1041                         free: None,
1042                         get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
1043                 },
1044         }
1045 }
1046
1047 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::ln::features::InitFeatures, msg: &crate::ln::msgs::OpenChannel) {
1048         <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()) }, unsafe { &*msg.inner })
1049 }
1050 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::ln::features::InitFeatures, msg: &crate::ln::msgs::AcceptChannel) {
1051         <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()) }, unsafe { &*msg.inner })
1052 }
1053 extern "C" fn ChannelManager_ChannelMessageHandler_handle_funding_created(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::FundingCreated) {
1054         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_created(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1055 }
1056 extern "C" fn ChannelManager_ChannelMessageHandler_handle_funding_signed(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::FundingSigned) {
1057         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1058 }
1059 extern "C" fn ChannelManager_ChannelMessageHandler_handle_funding_locked(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::FundingLocked) {
1060         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_locked(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1061 }
1062 extern "C" fn ChannelManager_ChannelMessageHandler_handle_shutdown(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, their_features: &crate::ln::features::InitFeatures, msg: &crate::ln::msgs::Shutdown) {
1063         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_shutdown(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*their_features.inner }, unsafe { &*msg.inner })
1064 }
1065 extern "C" fn ChannelManager_ChannelMessageHandler_handle_closing_signed(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::ClosingSigned) {
1066         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_closing_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1067 }
1068 extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_add_htlc(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateAddHTLC) {
1069         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_add_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1070 }
1071 extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateFulfillHTLC) {
1072         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fulfill_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1073 }
1074 extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_fail_htlc(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateFailHTLC) {
1075         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fail_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1076 }
1077 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::ln::msgs::UpdateFailMalformedHTLC) {
1078         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fail_malformed_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1079 }
1080 extern "C" fn ChannelManager_ChannelMessageHandler_handle_commitment_signed(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::CommitmentSigned) {
1081         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_commitment_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1082 }
1083 extern "C" fn ChannelManager_ChannelMessageHandler_handle_revoke_and_ack(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::RevokeAndACK) {
1084         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_revoke_and_ack(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1085 }
1086 extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_fee(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateFee) {
1087         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fee(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1088 }
1089 extern "C" fn ChannelManager_ChannelMessageHandler_handle_announcement_signatures(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::AnnouncementSignatures) {
1090         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_announcement_signatures(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1091 }
1092 extern "C" fn ChannelManager_ChannelMessageHandler_handle_channel_update(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::ChannelUpdate) {
1093         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1094 }
1095 extern "C" fn ChannelManager_ChannelMessageHandler_handle_channel_reestablish(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::ChannelReestablish) {
1096         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_channel_reestablish(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1097 }
1098 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) {
1099         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), no_connection_possible)
1100 }
1101 extern "C" fn ChannelManager_ChannelMessageHandler_peer_connected(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, init_msg: &crate::ln::msgs::Init) {
1102         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::peer_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*init_msg.inner })
1103 }
1104 extern "C" fn ChannelManager_ChannelMessageHandler_handle_error(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::ErrorMessage) {
1105         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1106 }
1107
1108 #[no_mangle]
1109 /// Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
1110 pub extern "C" fn ChannelManager_write(obj: &ChannelManager) -> crate::c_types::derived::CVec_u8Z {
1111         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1112 }
1113 #[no_mangle]
1114 pub(crate) extern "C" fn ChannelManager_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1115         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelManager) })
1116 }
1117
1118 use lightning::ln::channelmanager::ChannelManagerReadArgs as nativeChannelManagerReadArgsImport;
1119 type nativeChannelManagerReadArgs = nativeChannelManagerReadArgsImport<'static, crate::chain::keysinterface::Sign, crate::chain::Watch, crate::chain::chaininterface::BroadcasterInterface, crate::chain::keysinterface::KeysInterface, crate::chain::chaininterface::FeeEstimator, crate::util::logger::Logger>;
1120
1121 /// Arguments for the creation of a ChannelManager that are not deserialized.
1122 ///
1123 /// At a high-level, the process for deserializing a ChannelManager and resuming normal operation
1124 /// is:
1125 /// 1) Deserialize all stored ChannelMonitors.
1126 /// 2) Deserialize the ChannelManager by filling in this struct and calling:
1127 ///    <(BlockHash, ChannelManager)>::read(reader, args)
1128 ///    This may result in closing some Channels if the ChannelMonitor is newer than the stored
1129 ///    ChannelManager state to ensure no loss of funds. Thus, transactions may be broadcasted.
1130 /// 3) If you are not fetching full blocks, register all relevant ChannelMonitor outpoints the same
1131 ///    way you would handle a `chain::Filter` call using ChannelMonitor::get_outputs_to_watch() and
1132 ///    ChannelMonitor::get_funding_txo().
1133 /// 4) Reconnect blocks on your ChannelMonitors.
1134 /// 5) Disconnect/connect blocks on the ChannelManager.
1135 /// 6) Move the ChannelMonitors into your local chain::Watch.
1136 ///
1137 /// Note that the ordering of #4-6 is not of importance, however all three must occur before you
1138 /// call any other methods on the newly-deserialized ChannelManager.
1139 ///
1140 /// Note that because some channels may be closed during deserialization, it is critical that you
1141 /// always deserialize only the latest version of a ChannelManager and ChannelMonitors available to
1142 /// you. If you deserialize an old ChannelManager (during which force-closure transactions may be
1143 /// broadcast), and then later deserialize a newer version of the same ChannelManager (which will
1144 /// not force-close the same channels but consider them live), you may end up revoking a state for
1145 /// which you've already broadcasted the transaction.
1146 #[must_use]
1147 #[repr(C)]
1148 pub struct ChannelManagerReadArgs {
1149         /// A pointer to the opaque Rust object.
1150
1151         /// Nearly everywhere, inner must be non-null, however in places where
1152         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1153         pub inner: *mut nativeChannelManagerReadArgs,
1154         /// Indicates that this is the only struct which contains the same pointer.
1155
1156         /// Rust functions which take ownership of an object provided via an argument require
1157         /// this to be true and invalidate the object pointed to by inner.
1158         pub is_owned: bool,
1159 }
1160
1161 impl Drop for ChannelManagerReadArgs {
1162         fn drop(&mut self) {
1163                 if self.is_owned && !<*mut nativeChannelManagerReadArgs>::is_null(self.inner) {
1164                         let _ = unsafe { Box::from_raw(self.inner) };
1165                 }
1166         }
1167 }
1168 /// Frees any resources used by the ChannelManagerReadArgs, if is_owned is set and inner is non-NULL.
1169 #[no_mangle]
1170 pub extern "C" fn ChannelManagerReadArgs_free(this_obj: ChannelManagerReadArgs) { }
1171 #[allow(unused)]
1172 /// Used only if an object of this type is returned as a trait impl by a method
1173 extern "C" fn ChannelManagerReadArgs_free_void(this_ptr: *mut c_void) {
1174         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManagerReadArgs); }
1175 }
1176 #[allow(unused)]
1177 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1178 impl ChannelManagerReadArgs {
1179         pub(crate) fn take_inner(mut self) -> *mut nativeChannelManagerReadArgs {
1180                 assert!(self.is_owned);
1181                 let ret = self.inner;
1182                 self.inner = std::ptr::null_mut();
1183                 ret
1184         }
1185 }
1186 /// The keys provider which will give us relevant keys. Some keys will be loaded during
1187 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
1188 /// signing data.
1189 #[no_mangle]
1190 pub extern "C" fn ChannelManagerReadArgs_get_keys_manager(this_ptr: &ChannelManagerReadArgs) -> *const crate::chain::keysinterface::KeysInterface {
1191         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.keys_manager;
1192         &(*inner_val)
1193 }
1194 /// The keys provider which will give us relevant keys. Some keys will be loaded during
1195 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
1196 /// signing data.
1197 #[no_mangle]
1198 pub extern "C" fn ChannelManagerReadArgs_set_keys_manager(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::chain::keysinterface::KeysInterface) {
1199         unsafe { &mut *this_ptr.inner }.keys_manager = val;
1200 }
1201 /// The fee_estimator for use in the ChannelManager in the future.
1202 ///
1203 /// No calls to the FeeEstimator will be made during deserialization.
1204 #[no_mangle]
1205 pub extern "C" fn ChannelManagerReadArgs_get_fee_estimator(this_ptr: &ChannelManagerReadArgs) -> *const crate::chain::chaininterface::FeeEstimator {
1206         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fee_estimator;
1207         &(*inner_val)
1208 }
1209 /// The fee_estimator for use in the ChannelManager in the future.
1210 ///
1211 /// No calls to the FeeEstimator will be made during deserialization.
1212 #[no_mangle]
1213 pub extern "C" fn ChannelManagerReadArgs_set_fee_estimator(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::chain::chaininterface::FeeEstimator) {
1214         unsafe { &mut *this_ptr.inner }.fee_estimator = val;
1215 }
1216 /// The chain::Watch for use in the ChannelManager in the future.
1217 ///
1218 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
1219 /// you have deserialized ChannelMonitors separately and will add them to your
1220 /// chain::Watch after deserializing this ChannelManager.
1221 #[no_mangle]
1222 pub extern "C" fn ChannelManagerReadArgs_get_chain_monitor(this_ptr: &ChannelManagerReadArgs) -> *const crate::chain::Watch {
1223         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.chain_monitor;
1224         &(*inner_val)
1225 }
1226 /// The chain::Watch for use in the ChannelManager in the future.
1227 ///
1228 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
1229 /// you have deserialized ChannelMonitors separately and will add them to your
1230 /// chain::Watch after deserializing this ChannelManager.
1231 #[no_mangle]
1232 pub extern "C" fn ChannelManagerReadArgs_set_chain_monitor(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::chain::Watch) {
1233         unsafe { &mut *this_ptr.inner }.chain_monitor = val;
1234 }
1235 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
1236 /// used to broadcast the latest local commitment transactions of channels which must be
1237 /// force-closed during deserialization.
1238 #[no_mangle]
1239 pub extern "C" fn ChannelManagerReadArgs_get_tx_broadcaster(this_ptr: &ChannelManagerReadArgs) -> *const crate::chain::chaininterface::BroadcasterInterface {
1240         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.tx_broadcaster;
1241         &(*inner_val)
1242 }
1243 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
1244 /// used to broadcast the latest local commitment transactions of channels which must be
1245 /// force-closed during deserialization.
1246 #[no_mangle]
1247 pub extern "C" fn ChannelManagerReadArgs_set_tx_broadcaster(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::chain::chaininterface::BroadcasterInterface) {
1248         unsafe { &mut *this_ptr.inner }.tx_broadcaster = val;
1249 }
1250 /// The Logger for use in the ChannelManager and which may be used to log information during
1251 /// deserialization.
1252 #[no_mangle]
1253 pub extern "C" fn ChannelManagerReadArgs_get_logger(this_ptr: &ChannelManagerReadArgs) -> *const crate::util::logger::Logger {
1254         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.logger;
1255         &(*inner_val)
1256 }
1257 /// The Logger for use in the ChannelManager and which may be used to log information during
1258 /// deserialization.
1259 #[no_mangle]
1260 pub extern "C" fn ChannelManagerReadArgs_set_logger(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::util::logger::Logger) {
1261         unsafe { &mut *this_ptr.inner }.logger = val;
1262 }
1263 /// Default settings used for new channels. Any existing channels will continue to use the
1264 /// runtime settings which were stored when the ChannelManager was serialized.
1265 #[no_mangle]
1266 pub extern "C" fn ChannelManagerReadArgs_get_default_config(this_ptr: &ChannelManagerReadArgs) -> crate::util::config::UserConfig {
1267         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.default_config;
1268         crate::util::config::UserConfig { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
1269 }
1270 /// Default settings used for new channels. Any existing channels will continue to use the
1271 /// runtime settings which were stored when the ChannelManager was serialized.
1272 #[no_mangle]
1273 pub extern "C" fn ChannelManagerReadArgs_set_default_config(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::util::config::UserConfig) {
1274         unsafe { &mut *this_ptr.inner }.default_config = *unsafe { Box::from_raw(val.take_inner()) };
1275 }
1276 /// Simple utility function to create a ChannelManagerReadArgs which creates the monitor
1277 /// HashMap for you. This is primarily useful for C bindings where it is not practical to
1278 /// populate a HashMap directly from C.
1279 #[must_use]
1280 #[no_mangle]
1281 pub extern "C" fn ChannelManagerReadArgs_new(mut keys_manager: crate::chain::keysinterface::KeysInterface, mut fee_estimator: crate::chain::chaininterface::FeeEstimator, mut chain_monitor: crate::chain::Watch, mut tx_broadcaster: crate::chain::chaininterface::BroadcasterInterface, mut logger: crate::util::logger::Logger, mut default_config: crate::util::config::UserConfig, mut channel_monitors: crate::c_types::derived::CVec_ChannelMonitorZ) -> ChannelManagerReadArgs {
1282         let mut local_channel_monitors = Vec::new(); for mut item in channel_monitors.into_rust().drain(..) { local_channel_monitors.push( { unsafe { &mut *item.inner } }); };
1283         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);
1284         ChannelManagerReadArgs { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1285 }
1286
1287 #[no_mangle]
1288 /// Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_write
1289 pub extern "C" fn C2Tuple_BlockHashChannelManagerZ_read(ser: crate::c_types::u8slice, arg: crate::ln::channelmanager::ChannelManagerReadArgs) -> crate::c_types::derived::CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ {
1290         let arg_conv = *unsafe { Box::from_raw(arg.take_inner()) };
1291         let res: Result<(bitcoin::hash_types::BlockHash, lightning::ln::channelmanager::ChannelManager<crate::chain::keysinterface::Sign, crate::chain::Watch, crate::chain::chaininterface::BroadcasterInterface, crate::chain::keysinterface::KeysInterface, crate::chain::chaininterface::FeeEstimator, crate::util::logger::Logger>), lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
1292         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::ln::channelmanager::ChannelManager { inner: Box::into_raw(Box::new(orig_res_0_1)), is_owned: true }).into(); local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
1293         local_res
1294 }