Regenerate auto-generated bindings with license info and new upstream
[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
210 use lightning::ln::channelmanager::ChannelDetails as nativeChannelDetailsImport;
211 type nativeChannelDetails = nativeChannelDetailsImport;
212
213 /// Details of a channel, as returned by ChannelManager::list_channels and ChannelManager::list_usable_channels
214 #[must_use]
215 #[repr(C)]
216 pub struct ChannelDetails {
217         /// A pointer to the opaque Rust object.
218
219         /// Nearly everywhere, inner must be non-null, however in places where
220         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
221         pub inner: *mut nativeChannelDetails,
222         /// Indicates that this is the only struct which contains the same pointer.
223
224         /// Rust functions which take ownership of an object provided via an argument require
225         /// this to be true and invalidate the object pointed to by inner.
226         pub is_owned: bool,
227 }
228
229 impl Drop for ChannelDetails {
230         fn drop(&mut self) {
231                 if self.is_owned && !<*mut nativeChannelDetails>::is_null(self.inner) {
232                         let _ = unsafe { Box::from_raw(self.inner) };
233                 }
234         }
235 }
236 /// Frees any resources used by the ChannelDetails, if is_owned is set and inner is non-NULL.
237 #[no_mangle]
238 pub extern "C" fn ChannelDetails_free(this_obj: ChannelDetails) { }
239 #[allow(unused)]
240 /// Used only if an object of this type is returned as a trait impl by a method
241 extern "C" fn ChannelDetails_free_void(this_ptr: *mut c_void) {
242         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelDetails); }
243 }
244 #[allow(unused)]
245 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
246 impl ChannelDetails {
247         pub(crate) fn take_inner(mut self) -> *mut nativeChannelDetails {
248                 assert!(self.is_owned);
249                 let ret = self.inner;
250                 self.inner = std::ptr::null_mut();
251                 ret
252         }
253 }
254 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
255 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
256 /// Note that this means this value is *not* persistent - it can change once during the
257 /// lifetime of the channel.
258 #[no_mangle]
259 pub extern "C" fn ChannelDetails_get_channel_id(this_ptr: &ChannelDetails) -> *const [u8; 32] {
260         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_id;
261         &(*inner_val)
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_set_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::ThirtyTwoBytes) {
269         unsafe { &mut *this_ptr.inner }.channel_id = val.data;
270 }
271 /// The node_id of our counterparty
272 #[no_mangle]
273 pub extern "C" fn ChannelDetails_get_remote_network_id(this_ptr: &ChannelDetails) -> crate::c_types::PublicKey {
274         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.remote_network_id;
275         crate::c_types::PublicKey::from_rust(&(*inner_val))
276 }
277 /// The node_id of our counterparty
278 #[no_mangle]
279 pub extern "C" fn ChannelDetails_set_remote_network_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::PublicKey) {
280         unsafe { &mut *this_ptr.inner }.remote_network_id = val.into_rust();
281 }
282 /// The Features the channel counterparty provided upon last connection.
283 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
284 /// many routing-relevant features are present in the init context.
285 #[no_mangle]
286 pub extern "C" fn ChannelDetails_get_counterparty_features(this_ptr: &ChannelDetails) -> crate::ln::features::InitFeatures {
287         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.counterparty_features;
288         crate::ln::features::InitFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
289 }
290 /// The Features the channel counterparty provided upon last connection.
291 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
292 /// many routing-relevant features are present in the init context.
293 #[no_mangle]
294 pub extern "C" fn ChannelDetails_set_counterparty_features(this_ptr: &mut ChannelDetails, mut val: crate::ln::features::InitFeatures) {
295         unsafe { &mut *this_ptr.inner }.counterparty_features = *unsafe { Box::from_raw(val.take_inner()) };
296 }
297 /// The value, in satoshis, of this channel as appears in the funding output
298 #[no_mangle]
299 pub extern "C" fn ChannelDetails_get_channel_value_satoshis(this_ptr: &ChannelDetails) -> u64 {
300         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_value_satoshis;
301         (*inner_val)
302 }
303 /// The value, in satoshis, of this channel as appears in the funding output
304 #[no_mangle]
305 pub extern "C" fn ChannelDetails_set_channel_value_satoshis(this_ptr: &mut ChannelDetails, mut val: u64) {
306         unsafe { &mut *this_ptr.inner }.channel_value_satoshis = val;
307 }
308 /// The user_id passed in to create_channel, or 0 if the channel was inbound.
309 #[no_mangle]
310 pub extern "C" fn ChannelDetails_get_user_id(this_ptr: &ChannelDetails) -> u64 {
311         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.user_id;
312         (*inner_val)
313 }
314 /// The user_id passed in to create_channel, or 0 if the channel was inbound.
315 #[no_mangle]
316 pub extern "C" fn ChannelDetails_set_user_id(this_ptr: &mut ChannelDetails, mut val: u64) {
317         unsafe { &mut *this_ptr.inner }.user_id = val;
318 }
319 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
320 /// any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
321 /// available for inclusion in new outbound HTLCs). This further does not include any pending
322 /// outgoing HTLCs which are awaiting some other resolution to be sent.
323 #[no_mangle]
324 pub extern "C" fn ChannelDetails_get_outbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
325         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.outbound_capacity_msat;
326         (*inner_val)
327 }
328 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
329 /// any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
330 /// available for inclusion in new outbound HTLCs). This further does not include any pending
331 /// outgoing HTLCs which are awaiting some other resolution to be sent.
332 #[no_mangle]
333 pub extern "C" fn ChannelDetails_set_outbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
334         unsafe { &mut *this_ptr.inner }.outbound_capacity_msat = val;
335 }
336 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
337 /// include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
338 /// available for inclusion in new inbound HTLCs).
339 /// Note that there are some corner cases not fully handled here, so the actual available
340 /// inbound capacity may be slightly higher than this.
341 #[no_mangle]
342 pub extern "C" fn ChannelDetails_get_inbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
343         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.inbound_capacity_msat;
344         (*inner_val)
345 }
346 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
347 /// include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
348 /// available for inclusion in new inbound HTLCs).
349 /// Note that there are some corner cases not fully handled here, so the actual available
350 /// inbound capacity may be slightly higher than this.
351 #[no_mangle]
352 pub extern "C" fn ChannelDetails_set_inbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
353         unsafe { &mut *this_ptr.inner }.inbound_capacity_msat = val;
354 }
355 /// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
356 /// the peer is connected, and (c) no monitor update failure is pending resolution.
357 #[no_mangle]
358 pub extern "C" fn ChannelDetails_get_is_live(this_ptr: &ChannelDetails) -> bool {
359         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.is_live;
360         (*inner_val)
361 }
362 /// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
363 /// the peer is connected, and (c) no monitor update failure is pending resolution.
364 #[no_mangle]
365 pub extern "C" fn ChannelDetails_set_is_live(this_ptr: &mut ChannelDetails, mut val: bool) {
366         unsafe { &mut *this_ptr.inner }.is_live = val;
367 }
368 impl Clone for ChannelDetails {
369         fn clone(&self) -> Self {
370                 Self {
371                         inner: if <*mut nativeChannelDetails>::is_null(self.inner) { std::ptr::null_mut() } else {
372                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
373                         is_owned: true,
374                 }
375         }
376 }
377 #[allow(unused)]
378 /// Used only if an object of this type is returned as a trait impl by a method
379 pub(crate) extern "C" fn ChannelDetails_clone_void(this_ptr: *const c_void) -> *mut c_void {
380         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelDetails)).clone() })) as *mut c_void
381 }
382 #[no_mangle]
383 /// Creates a copy of the ChannelDetails
384 pub extern "C" fn ChannelDetails_clone(orig: &ChannelDetails) -> ChannelDetails {
385         orig.clone()
386 }
387 /// If a payment fails to send, it can be in one of several states. This enum is returned as the
388 /// Err() type describing which state the payment is in, see the description of individual enum
389 /// states for more.
390 #[must_use]
391 #[derive(Clone)]
392 #[repr(C)]
393 pub enum PaymentSendFailure {
394         /// A parameter which was passed to send_payment was invalid, preventing us from attempting to
395         /// send the payment at all. No channel state has been changed or messages sent to peers, and
396         /// once you've changed the parameter at error, you can freely retry the payment in full.
397         ParameterError(crate::util::errors::APIError),
398         /// A parameter in a single path which was passed to send_payment was invalid, preventing us
399         /// from attempting to send the payment at all. No channel state has been changed or messages
400         /// sent to peers, and once you've changed the parameter at error, you can freely retry the
401         /// payment in full.
402         ///
403         /// The results here are ordered the same as the paths in the route object which was passed to
404         /// send_payment.
405         PathParameterError(crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ),
406         /// All paths which were attempted failed to send, with no channel state change taking place.
407         /// You can freely retry the payment in full (though you probably want to do so over different
408         /// paths than the ones selected).
409         AllFailedRetrySafe(crate::c_types::derived::CVec_APIErrorZ),
410         /// Some paths which were attempted failed to send, though possibly not all. At least some
411         /// paths have irrevocably committed to the HTLC and retrying the payment in full would result
412         /// in over-/re-payment.
413         ///
414         /// The results here are ordered the same as the paths in the route object which was passed to
415         /// send_payment, and any Errs which are not APIError::MonitorUpdateFailed can be safely
416         /// retried (though there is currently no API with which to do so).
417         ///
418         /// Any entries which contain Err(APIError::MonitorUpdateFailed) or Ok(()) MUST NOT be retried
419         /// as they will result in over-/re-payment. These HTLCs all either successfully sent (in the
420         /// case of Ok(())) or will send once channel_monitor_updated is called on the next-hop channel
421         /// with the latest update_id.
422         PartialFailure(crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ),
423 }
424 use lightning::ln::channelmanager::PaymentSendFailure as nativePaymentSendFailure;
425 impl PaymentSendFailure {
426         #[allow(unused)]
427         pub(crate) fn to_native(&self) -> nativePaymentSendFailure {
428                 match self {
429                         PaymentSendFailure::ParameterError (ref a, ) => {
430                                 let mut a_nonref = (*a).clone();
431                                 nativePaymentSendFailure::ParameterError (
432                                         a_nonref.into_native(),
433                                 )
434                         },
435                         PaymentSendFailure::PathParameterError (ref a, ) => {
436                                 let mut a_nonref = (*a).clone();
437                                 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 }); };
438                                 nativePaymentSendFailure::PathParameterError (
439                                         local_a_nonref,
440                                 )
441                         },
442                         PaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
443                                 let mut a_nonref = (*a).clone();
444                                 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { item.into_native() }); };
445                                 nativePaymentSendFailure::AllFailedRetrySafe (
446                                         local_a_nonref,
447                                 )
448                         },
449                         PaymentSendFailure::PartialFailure (ref a, ) => {
450                                 let mut a_nonref = (*a).clone();
451                                 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 }); };
452                                 nativePaymentSendFailure::PartialFailure (
453                                         local_a_nonref,
454                                 )
455                         },
456                 }
457         }
458         #[allow(unused)]
459         pub(crate) fn into_native(self) -> nativePaymentSendFailure {
460                 match self {
461                         PaymentSendFailure::ParameterError (mut a, ) => {
462                                 nativePaymentSendFailure::ParameterError (
463                                         a.into_native(),
464                                 )
465                         },
466                         PaymentSendFailure::PathParameterError (mut a, ) => {
467                                 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 }); };
468                                 nativePaymentSendFailure::PathParameterError (
469                                         local_a,
470                                 )
471                         },
472                         PaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
473                                 let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { item.into_native() }); };
474                                 nativePaymentSendFailure::AllFailedRetrySafe (
475                                         local_a,
476                                 )
477                         },
478                         PaymentSendFailure::PartialFailure (mut a, ) => {
479                                 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 }); };
480                                 nativePaymentSendFailure::PartialFailure (
481                                         local_a,
482                                 )
483                         },
484                 }
485         }
486         #[allow(unused)]
487         pub(crate) fn from_native(native: &nativePaymentSendFailure) -> Self {
488                 match native {
489                         nativePaymentSendFailure::ParameterError (ref a, ) => {
490                                 let mut a_nonref = (*a).clone();
491                                 PaymentSendFailure::ParameterError (
492                                         crate::util::errors::APIError::native_into(a_nonref),
493                                 )
494                         },
495                         nativePaymentSendFailure::PathParameterError (ref a, ) => {
496                                 let mut a_nonref = (*a).clone();
497                                 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 }); };
498                                 PaymentSendFailure::PathParameterError (
499                                         local_a_nonref.into(),
500                                 )
501                         },
502                         nativePaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
503                                 let mut a_nonref = (*a).clone();
504                                 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) }); };
505                                 PaymentSendFailure::AllFailedRetrySafe (
506                                         local_a_nonref.into(),
507                                 )
508                         },
509                         nativePaymentSendFailure::PartialFailure (ref a, ) => {
510                                 let mut a_nonref = (*a).clone();
511                                 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 }); };
512                                 PaymentSendFailure::PartialFailure (
513                                         local_a_nonref.into(),
514                                 )
515                         },
516                 }
517         }
518         #[allow(unused)]
519         pub(crate) fn native_into(native: nativePaymentSendFailure) -> Self {
520                 match native {
521                         nativePaymentSendFailure::ParameterError (mut a, ) => {
522                                 PaymentSendFailure::ParameterError (
523                                         crate::util::errors::APIError::native_into(a),
524                                 )
525                         },
526                         nativePaymentSendFailure::PathParameterError (mut a, ) => {
527                                 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 }); };
528                                 PaymentSendFailure::PathParameterError (
529                                         local_a.into(),
530                                 )
531                         },
532                         nativePaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
533                                 let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { crate::util::errors::APIError::native_into(item) }); };
534                                 PaymentSendFailure::AllFailedRetrySafe (
535                                         local_a.into(),
536                                 )
537                         },
538                         nativePaymentSendFailure::PartialFailure (mut a, ) => {
539                                 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 }); };
540                                 PaymentSendFailure::PartialFailure (
541                                         local_a.into(),
542                                 )
543                         },
544                 }
545         }
546 }
547 /// Frees any resources used by the PaymentSendFailure
548 #[no_mangle]
549 pub extern "C" fn PaymentSendFailure_free(this_ptr: PaymentSendFailure) { }
550 /// Creates a copy of the PaymentSendFailure
551 #[no_mangle]
552 pub extern "C" fn PaymentSendFailure_clone(orig: &PaymentSendFailure) -> PaymentSendFailure {
553         orig.clone()
554 }
555 /// Constructs a new ChannelManager to hold several channels and route between them.
556 ///
557 /// This is the main \"logic hub\" for all channel-related actions, and implements
558 /// ChannelMessageHandler.
559 ///
560 /// Non-proportional fees are fixed according to our risk using the provided fee estimator.
561 ///
562 /// panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`!
563 ///
564 /// Users need to notify the new ChannelManager when a new block is connected or
565 /// disconnected using its `block_connected` and `block_disconnected` methods, starting
566 /// from after `params.latest_hash`.
567 #[must_use]
568 #[no_mangle]
569 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 {
570         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()) });
571         ChannelManager { inner: Box::into_raw(Box::new(ret)), is_owned: true }
572 }
573
574 /// Creates a new outbound channel to the given remote node and with the given value.
575 ///
576 /// user_id will be provided back as user_channel_id in FundingGenerationReady and
577 /// FundingBroadcastSafe events to allow tracking of which events correspond with which
578 /// create_channel call. Note that user_channel_id defaults to 0 for inbound channels, so you
579 /// may wish to avoid using 0 for user_id here.
580 ///
581 /// If successful, will generate a SendOpenChannel message event, so you should probably poll
582 /// PeerManager::process_events afterwards.
583 ///
584 /// Raises APIError::APIMisuseError when channel_value_satoshis > 2**24 or push_msat is
585 /// greater than channel_value_satoshis * 1k or channel_value_satoshis is < 1000.
586 #[must_use]
587 #[no_mangle]
588 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 {
589         let mut local_override_config = if override_config.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(override_config.take_inner()) } }) };
590         let mut ret = unsafe { &*this_arg.inner }.create_channel(their_network_key.into_rust(), channel_value_satoshis, push_msat, user_id, local_override_config);
591         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() };
592         local_ret
593 }
594
595 /// Gets the list of open channels, in random order. See ChannelDetail field documentation for
596 /// more information.
597 #[must_use]
598 #[no_mangle]
599 pub extern "C" fn ChannelManager_list_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
600         let mut ret = unsafe { &*this_arg.inner }.list_channels();
601         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 } }); };
602         local_ret.into()
603 }
604
605 /// Gets the list of usable channels, in random order. Useful as an argument to
606 /// get_route to ensure non-announced channels are used.
607 ///
608 /// These are guaranteed to have their is_live value set to true, see the documentation for
609 /// ChannelDetails::is_live for more info on exactly what the criteria are.
610 #[must_use]
611 #[no_mangle]
612 pub extern "C" fn ChannelManager_list_usable_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
613         let mut ret = unsafe { &*this_arg.inner }.list_usable_channels();
614         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 } }); };
615         local_ret.into()
616 }
617
618 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
619 /// will be accepted on the given channel, and after additional timeout/the closing of all
620 /// pending HTLCs, the channel will be closed on chain.
621 ///
622 /// May generate a SendShutdown message event on success, which should be relayed.
623 #[must_use]
624 #[no_mangle]
625 pub extern "C" fn ChannelManager_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
626         let mut ret = unsafe { &*this_arg.inner }.close_channel(unsafe { &*channel_id});
627         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() };
628         local_ret
629 }
630
631 /// Force closes a channel, immediately broadcasting the latest local commitment transaction to
632 /// the chain and rejecting new HTLCs on the given channel. Fails if channel_id is unknown to the manager.
633 #[must_use]
634 #[no_mangle]
635 pub extern "C" fn ChannelManager_force_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
636         let mut ret = unsafe { &*this_arg.inner }.force_close_channel(unsafe { &*channel_id});
637         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() };
638         local_ret
639 }
640
641 /// Force close all channels, immediately broadcasting the latest local commitment transaction
642 /// for each to the chain and rejecting new HTLCs on each.
643 #[no_mangle]
644 pub extern "C" fn ChannelManager_force_close_all_channels(this_arg: &ChannelManager) {
645         unsafe { &*this_arg.inner }.force_close_all_channels()
646 }
647
648 /// Sends a payment along a given route.
649 ///
650 /// Value parameters are provided via the last hop in route, see documentation for RouteHop
651 /// fields for more info.
652 ///
653 /// Note that if the payment_hash already exists elsewhere (eg you're sending a duplicative
654 /// payment), we don't do anything to stop you! We always try to ensure that if the provided
655 /// next hop knows the preimage to payment_hash they can claim an additional amount as
656 /// specified in the last hop in the route! Thus, you should probably do your own
657 /// payment_preimage tracking (which you should already be doing as they represent \"proof of
658 /// payment\") and prevent double-sends yourself.
659 ///
660 /// May generate SendHTLCs message(s) event on success, which should be relayed.
661 ///
662 /// Each path may have a different return value, and PaymentSendValue may return a Vec with
663 /// each entry matching the corresponding-index entry in the route paths, see
664 /// PaymentSendFailure for more info.
665 ///
666 /// In general, a path may raise:
667 ///  * APIError::RouteError when an invalid route or forwarding parameter (cltv_delta, fee,
668 ///    node public key) is specified.
669 ///  * APIError::ChannelUnavailable if the next-hop channel is not available for updates
670 ///    (including due to previous monitor update failure or new permanent monitor update
671 ///    failure).
672 ///  * APIError::MonitorUpdateFailed if a new monitor update failure prevented sending the
673 ///    relevant updates.
674 ///
675 /// Note that depending on the type of the PaymentSendFailure the HTLC may have been
676 /// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
677 /// different route unless you intend to pay twice!
678 ///
679 /// payment_secret is unrelated to payment_hash (or PaymentPreimage) and exists to authenticate
680 /// the sender to the recipient and prevent payment-probing (deanonymization) attacks. For
681 /// newer nodes, it will be provided to you in the invoice. If you do not have one, the Route
682 /// must not contain multiple paths as multi-path payments require a recipient-provided
683 /// payment_secret.
684 /// If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature
685 /// bit set (either as required or as available). If multiple paths are present in the Route,
686 /// we assume the invoice had the basic_mpp feature set.
687 #[must_use]
688 #[no_mangle]
689 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 {
690         let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentSecret(payment_secret.data) }) };
691         let mut ret = unsafe { &*this_arg.inner }.send_payment(unsafe { &*route.inner }, ::lightning::ln::channelmanager::PaymentHash(payment_hash.data), &local_payment_secret);
692         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() };
693         local_ret
694 }
695
696 /// Call this upon creation of a funding transaction for the given channel.
697 ///
698 /// Note that ALL inputs in the transaction pointed to by funding_txo MUST spend SegWit outputs
699 /// or your counterparty can steal your funds!
700 ///
701 /// Panics if a funding transaction has already been provided for this channel.
702 ///
703 /// May panic if the funding_txo is duplicative with some other channel (note that this should
704 /// be trivially prevented by using unique funding transaction keys per-channel).
705 #[no_mangle]
706 pub extern "C" fn ChannelManager_funding_transaction_generated(this_arg: &ChannelManager, temporary_channel_id: *const [u8; 32], mut funding_txo: crate::chain::transaction::OutPoint) {
707         unsafe { &*this_arg.inner }.funding_transaction_generated(unsafe { &*temporary_channel_id}, *unsafe { Box::from_raw(funding_txo.take_inner()) })
708 }
709
710 /// Generates a signed node_announcement from the given arguments and creates a
711 /// BroadcastNodeAnnouncement event. Note that such messages will be ignored unless peers have
712 /// seen a channel_announcement from us (ie unless we have public channels open).
713 ///
714 /// RGB is a node \"color\" and alias is a printable human-readable string to describe this node
715 /// to humans. They carry no in-protocol meaning.
716 ///
717 /// addresses represent the set (possibly empty) of socket addresses on which this node accepts
718 /// incoming connections. These will be broadcast to the network, publicly tying these
719 /// addresses together. If you wish to preserve user privacy, addresses should likely contain
720 /// only Tor Onion addresses.
721 ///
722 /// Panics if addresses is absurdly large (more than 500).
723 #[no_mangle]
724 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) {
725         let mut local_addresses = Vec::new(); for mut item in addresses.into_rust().drain(..) { local_addresses.push( { item.into_native() }); };
726         unsafe { &*this_arg.inner }.broadcast_node_announcement(rgb.data, alias.data, local_addresses)
727 }
728
729 /// Processes HTLCs which are pending waiting on random forward delay.
730 ///
731 /// Should only really ever be called in response to a PendingHTLCsForwardable event.
732 /// Will likely generate further events.
733 #[no_mangle]
734 pub extern "C" fn ChannelManager_process_pending_htlc_forwards(this_arg: &ChannelManager) {
735         unsafe { &*this_arg.inner }.process_pending_htlc_forwards()
736 }
737
738 /// If a peer is disconnected we mark any channels with that peer as 'disabled'.
739 /// After some time, if channels are still disabled we need to broadcast a ChannelUpdate
740 /// to inform the network about the uselessness of these channels.
741 ///
742 /// This method handles all the details, and must be called roughly once per minute.
743 ///
744 /// Note that in some rare cases this may generate a `chain::Watch::update_channel` call.
745 #[no_mangle]
746 pub extern "C" fn ChannelManager_timer_chan_freshness_every_min(this_arg: &ChannelManager) {
747         unsafe { &*this_arg.inner }.timer_chan_freshness_every_min()
748 }
749
750 /// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
751 /// after a PaymentReceived event, failing the HTLC back to its origin and freeing resources
752 /// along the path (including in our own channel on which we received it).
753 /// Returns false if no payment was found to fail backwards, true if the process of failing the
754 /// HTLC backwards has been started.
755 #[must_use]
756 #[no_mangle]
757 pub extern "C" fn ChannelManager_fail_htlc_backwards(this_arg: &ChannelManager, payment_hash: *const [u8; 32], mut payment_secret: crate::c_types::ThirtyTwoBytes) -> bool {
758         let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentSecret(payment_secret.data) }) };
759         let mut ret = unsafe { &*this_arg.inner }.fail_htlc_backwards(&::lightning::ln::channelmanager::PaymentHash(unsafe { *payment_hash }), &local_payment_secret);
760         ret
761 }
762
763 /// Provides a payment preimage in response to a PaymentReceived event, returning true and
764 /// generating message events for the net layer to claim the payment, if possible. Thus, you
765 /// should probably kick the net layer to go send messages if this returns true!
766 ///
767 /// You must specify the expected amounts for this HTLC, and we will only claim HTLCs
768 /// available within a few percent of the expected amount. This is critical for several
769 /// reasons : a) it avoids providing senders with `proof-of-payment` (in the form of the
770 /// payment_preimage without having provided the full value and b) it avoids certain
771 /// privacy-breaking recipient-probing attacks which may reveal payment activity to
772 /// motivated attackers.
773 ///
774 /// Note that the privacy concerns in (b) are not relevant in payments with a payment_secret
775 /// set. Thus, for such payments we will claim any payments which do not under-pay.
776 ///
777 /// May panic if called except in response to a PaymentReceived event.
778 #[must_use]
779 #[no_mangle]
780 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 {
781         let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentSecret(payment_secret.data) }) };
782         let mut ret = unsafe { &*this_arg.inner }.claim_funds(::lightning::ln::channelmanager::PaymentPreimage(payment_preimage.data), &local_payment_secret, expected_amount);
783         ret
784 }
785
786 /// Gets the node_id held by this ChannelManager
787 #[must_use]
788 #[no_mangle]
789 pub extern "C" fn ChannelManager_get_our_node_id(this_arg: &ChannelManager) -> crate::c_types::PublicKey {
790         let mut ret = unsafe { &*this_arg.inner }.get_our_node_id();
791         crate::c_types::PublicKey::from_rust(&ret)
792 }
793
794 /// Restores a single, given channel to normal operation after a
795 /// ChannelMonitorUpdateErr::TemporaryFailure was returned from a channel monitor update
796 /// operation.
797 ///
798 /// All ChannelMonitor updates up to and including highest_applied_update_id must have been
799 /// fully committed in every copy of the given channels' ChannelMonitors.
800 ///
801 /// Note that there is no effect to calling with a highest_applied_update_id other than the
802 /// current latest ChannelMonitorUpdate and one call to this function after multiple
803 /// ChannelMonitorUpdateErr::TemporaryFailures is fine. The highest_applied_update_id field
804 /// exists largely only to prevent races between this and concurrent update_monitor calls.
805 ///
806 /// Thus, the anticipated use is, at a high level:
807 ///  1) You register a chain::Watch with this ChannelManager,
808 ///  2) it stores each update to disk, and begins updating any remote (eg watchtower) copies of
809 ///     said ChannelMonitors as it can, returning ChannelMonitorUpdateErr::TemporaryFailures
810 ///     any time it cannot do so instantly,
811 ///  3) update(s) are applied to each remote copy of a ChannelMonitor,
812 ///  4) once all remote copies are updated, you call this function with the update_id that
813 ///     completed, and once it is the latest the Channel will be re-enabled.
814 #[no_mangle]
815 pub extern "C" fn ChannelManager_channel_monitor_updated(this_arg: &ChannelManager, funding_txo: &crate::chain::transaction::OutPoint, mut highest_applied_update_id: u64) {
816         unsafe { &*this_arg.inner }.channel_monitor_updated(unsafe { &*funding_txo.inner }, highest_applied_update_id)
817 }
818
819 impl From<nativeChannelManager> for crate::util::events::MessageSendEventsProvider {
820         fn from(obj: nativeChannelManager) -> Self {
821                 let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true };
822                 let mut ret = ChannelManager_as_MessageSendEventsProvider(&rust_obj);
823                 // 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
824                 rust_obj.inner = std::ptr::null_mut();
825                 ret.free = Some(ChannelManager_free_void);
826                 ret
827         }
828 }
829 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
830 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
831 #[no_mangle]
832 pub extern "C" fn ChannelManager_as_MessageSendEventsProvider(this_arg: &ChannelManager) -> crate::util::events::MessageSendEventsProvider {
833         crate::util::events::MessageSendEventsProvider {
834                 this_arg: unsafe { (*this_arg).inner as *mut c_void },
835                 free: None,
836                 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
837         }
838 }
839
840 #[must_use]
841 extern "C" fn ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
842         let mut ret = <nativeChannelManager as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
843         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); };
844         local_ret.into()
845 }
846
847 impl From<nativeChannelManager> for crate::util::events::EventsProvider {
848         fn from(obj: nativeChannelManager) -> Self {
849                 let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true };
850                 let mut ret = ChannelManager_as_EventsProvider(&rust_obj);
851                 // 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
852                 rust_obj.inner = std::ptr::null_mut();
853                 ret.free = Some(ChannelManager_free_void);
854                 ret
855         }
856 }
857 /// Constructs a new EventsProvider which calls the relevant methods on this_arg.
858 /// This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
859 #[no_mangle]
860 pub extern "C" fn ChannelManager_as_EventsProvider(this_arg: &ChannelManager) -> crate::util::events::EventsProvider {
861         crate::util::events::EventsProvider {
862                 this_arg: unsafe { (*this_arg).inner as *mut c_void },
863                 free: None,
864                 get_and_clear_pending_events: ChannelManager_EventsProvider_get_and_clear_pending_events,
865         }
866 }
867
868 #[must_use]
869 extern "C" fn ChannelManager_EventsProvider_get_and_clear_pending_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_EventZ {
870         let mut ret = <nativeChannelManager as lightning::util::events::EventsProvider<>>::get_and_clear_pending_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
871         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::Event::native_into(item) }); };
872         local_ret.into()
873 }
874
875 impl From<nativeChannelManager> for crate::chain::Listen {
876         fn from(obj: nativeChannelManager) -> Self {
877                 let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true };
878                 let mut ret = ChannelManager_as_Listen(&rust_obj);
879                 // 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
880                 rust_obj.inner = std::ptr::null_mut();
881                 ret.free = Some(ChannelManager_free_void);
882                 ret
883         }
884 }
885 /// Constructs a new Listen which calls the relevant methods on this_arg.
886 /// This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
887 #[no_mangle]
888 pub extern "C" fn ChannelManager_as_Listen(this_arg: &ChannelManager) -> crate::chain::Listen {
889         crate::chain::Listen {
890                 this_arg: unsafe { (*this_arg).inner as *mut c_void },
891                 free: None,
892                 block_connected: ChannelManager_Listen_block_connected,
893                 block_disconnected: ChannelManager_Listen_block_disconnected,
894         }
895 }
896
897 extern "C" fn ChannelManager_Listen_block_connected(this_arg: *const c_void, mut block: crate::c_types::u8slice, mut height: u32) {
898         <nativeChannelManager as lightning::chain::Listen<>>::block_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height)
899 }
900 extern "C" fn ChannelManager_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut _height: u32) {
901         <nativeChannelManager as lightning::chain::Listen<>>::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), _height)
902 }
903
904 /// Updates channel state based on transactions seen in a connected block.
905 #[no_mangle]
906 pub extern "C" fn ChannelManager_block_connected(this_arg: &ChannelManager, header: *const [u8; 80], mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, mut height: u32) {
907         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 }); };
908         unsafe { &*this_arg.inner }.block_connected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), &local_txdata.iter().map(|(a, b)| (*a, b)).collect::<Vec<_>>()[..], height)
909 }
910
911 /// Updates channel state based on a disconnected block.
912 ///
913 /// If necessary, the channel may be force-closed without letting the counterparty participate
914 /// in the shutdown.
915 #[no_mangle]
916 pub extern "C" fn ChannelManager_block_disconnected(this_arg: &ChannelManager, header: *const [u8; 80]) {
917         unsafe { &*this_arg.inner }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap())
918 }
919
920 /// Blocks until ChannelManager needs to be persisted. Only one listener on
921 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
922 /// up.
923 #[no_mangle]
924 pub extern "C" fn ChannelManager_await_persistable_update(this_arg: &ChannelManager) {
925         unsafe { &*this_arg.inner }.await_persistable_update()
926 }
927
928 impl From<nativeChannelManager> for crate::ln::msgs::ChannelMessageHandler {
929         fn from(obj: nativeChannelManager) -> Self {
930                 let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true };
931                 let mut ret = ChannelManager_as_ChannelMessageHandler(&rust_obj);
932                 // 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
933                 rust_obj.inner = std::ptr::null_mut();
934                 ret.free = Some(ChannelManager_free_void);
935                 ret
936         }
937 }
938 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
939 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
940 #[no_mangle]
941 pub extern "C" fn ChannelManager_as_ChannelMessageHandler(this_arg: &ChannelManager) -> crate::ln::msgs::ChannelMessageHandler {
942         crate::ln::msgs::ChannelMessageHandler {
943                 this_arg: unsafe { (*this_arg).inner as *mut c_void },
944                 free: None,
945                 handle_open_channel: ChannelManager_ChannelMessageHandler_handle_open_channel,
946                 handle_accept_channel: ChannelManager_ChannelMessageHandler_handle_accept_channel,
947                 handle_funding_created: ChannelManager_ChannelMessageHandler_handle_funding_created,
948                 handle_funding_signed: ChannelManager_ChannelMessageHandler_handle_funding_signed,
949                 handle_funding_locked: ChannelManager_ChannelMessageHandler_handle_funding_locked,
950                 handle_shutdown: ChannelManager_ChannelMessageHandler_handle_shutdown,
951                 handle_closing_signed: ChannelManager_ChannelMessageHandler_handle_closing_signed,
952                 handle_update_add_htlc: ChannelManager_ChannelMessageHandler_handle_update_add_htlc,
953                 handle_update_fulfill_htlc: ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc,
954                 handle_update_fail_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_htlc,
955                 handle_update_fail_malformed_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_malformed_htlc,
956                 handle_commitment_signed: ChannelManager_ChannelMessageHandler_handle_commitment_signed,
957                 handle_revoke_and_ack: ChannelManager_ChannelMessageHandler_handle_revoke_and_ack,
958                 handle_update_fee: ChannelManager_ChannelMessageHandler_handle_update_fee,
959                 handle_announcement_signatures: ChannelManager_ChannelMessageHandler_handle_announcement_signatures,
960                 peer_disconnected: ChannelManager_ChannelMessageHandler_peer_disconnected,
961                 peer_connected: ChannelManager_ChannelMessageHandler_peer_connected,
962                 handle_channel_reestablish: ChannelManager_ChannelMessageHandler_handle_channel_reestablish,
963                 handle_channel_update: ChannelManager_ChannelMessageHandler_handle_channel_update,
964                 handle_error: ChannelManager_ChannelMessageHandler_handle_error,
965                 MessageSendEventsProvider: crate::util::events::MessageSendEventsProvider {
966                         this_arg: unsafe { (*this_arg).inner as *mut c_void },
967                         free: None,
968                         get_and_clear_pending_msg_events: ChannelManager_ChannelMessageHandler_get_and_clear_pending_msg_events,
969                 },
970         }
971 }
972
973 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) {
974         <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 })
975 }
976 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) {
977         <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 })
978 }
979 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) {
980         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_created(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
981 }
982 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) {
983         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
984 }
985 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) {
986         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_locked(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
987 }
988 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) {
989         <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 })
990 }
991 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) {
992         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_closing_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
993 }
994 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) {
995         <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 })
996 }
997 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) {
998         <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 })
999 }
1000 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) {
1001         <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 })
1002 }
1003 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) {
1004         <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 })
1005 }
1006 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) {
1007         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_commitment_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1008 }
1009 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) {
1010         <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 })
1011 }
1012 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) {
1013         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fee(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1014 }
1015 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) {
1016         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_announcement_signatures(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1017 }
1018 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) {
1019         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1020 }
1021 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) {
1022         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_channel_reestablish(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1023 }
1024 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) {
1025         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), no_connection_possible)
1026 }
1027 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) {
1028         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::peer_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*init_msg.inner })
1029 }
1030 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) {
1031         <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1032 }
1033 #[must_use]
1034 extern "C" fn ChannelManager_ChannelMessageHandler_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
1035         let mut ret = <nativeChannelManager as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
1036         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); };
1037         local_ret.into()
1038 }
1039
1040 #[no_mangle]
1041 /// Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
1042 pub extern "C" fn ChannelManager_write(obj: &ChannelManager) -> crate::c_types::derived::CVec_u8Z {
1043         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1044 }
1045 #[no_mangle]
1046 pub(crate) extern "C" fn ChannelManager_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1047         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelManager) })
1048 }
1049
1050 use lightning::ln::channelmanager::ChannelManagerReadArgs as nativeChannelManagerReadArgsImport;
1051 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>;
1052
1053 /// Arguments for the creation of a ChannelManager that are not deserialized.
1054 ///
1055 /// At a high-level, the process for deserializing a ChannelManager and resuming normal operation
1056 /// is:
1057 /// 1) Deserialize all stored ChannelMonitors.
1058 /// 2) Deserialize the ChannelManager by filling in this struct and calling:
1059 ///    <(BlockHash, ChannelManager)>::read(reader, args)
1060 ///    This may result in closing some Channels if the ChannelMonitor is newer than the stored
1061 ///    ChannelManager state to ensure no loss of funds. Thus, transactions may be broadcasted.
1062 /// 3) If you are not fetching full blocks, register all relevant ChannelMonitor outpoints the same
1063 ///    way you would handle a `chain::Filter` call using ChannelMonitor::get_outputs_to_watch() and
1064 ///    ChannelMonitor::get_funding_txo().
1065 /// 4) Reconnect blocks on your ChannelMonitors.
1066 /// 5) Disconnect/connect blocks on the ChannelManager.
1067 /// 6) Move the ChannelMonitors into your local chain::Watch.
1068 ///
1069 /// Note that the ordering of #4-6 is not of importance, however all three must occur before you
1070 /// call any other methods on the newly-deserialized ChannelManager.
1071 ///
1072 /// Note that because some channels may be closed during deserialization, it is critical that you
1073 /// always deserialize only the latest version of a ChannelManager and ChannelMonitors available to
1074 /// you. If you deserialize an old ChannelManager (during which force-closure transactions may be
1075 /// broadcast), and then later deserialize a newer version of the same ChannelManager (which will
1076 /// not force-close the same channels but consider them live), you may end up revoking a state for
1077 /// which you've already broadcasted the transaction.
1078 #[must_use]
1079 #[repr(C)]
1080 pub struct ChannelManagerReadArgs {
1081         /// A pointer to the opaque Rust object.
1082
1083         /// Nearly everywhere, inner must be non-null, however in places where
1084         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1085         pub inner: *mut nativeChannelManagerReadArgs,
1086         /// Indicates that this is the only struct which contains the same pointer.
1087
1088         /// Rust functions which take ownership of an object provided via an argument require
1089         /// this to be true and invalidate the object pointed to by inner.
1090         pub is_owned: bool,
1091 }
1092
1093 impl Drop for ChannelManagerReadArgs {
1094         fn drop(&mut self) {
1095                 if self.is_owned && !<*mut nativeChannelManagerReadArgs>::is_null(self.inner) {
1096                         let _ = unsafe { Box::from_raw(self.inner) };
1097                 }
1098         }
1099 }
1100 /// Frees any resources used by the ChannelManagerReadArgs, if is_owned is set and inner is non-NULL.
1101 #[no_mangle]
1102 pub extern "C" fn ChannelManagerReadArgs_free(this_obj: ChannelManagerReadArgs) { }
1103 #[allow(unused)]
1104 /// Used only if an object of this type is returned as a trait impl by a method
1105 extern "C" fn ChannelManagerReadArgs_free_void(this_ptr: *mut c_void) {
1106         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManagerReadArgs); }
1107 }
1108 #[allow(unused)]
1109 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1110 impl ChannelManagerReadArgs {
1111         pub(crate) fn take_inner(mut self) -> *mut nativeChannelManagerReadArgs {
1112                 assert!(self.is_owned);
1113                 let ret = self.inner;
1114                 self.inner = std::ptr::null_mut();
1115                 ret
1116         }
1117 }
1118 /// The keys provider which will give us relevant keys. Some keys will be loaded during
1119 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
1120 /// signing data.
1121 #[no_mangle]
1122 pub extern "C" fn ChannelManagerReadArgs_get_keys_manager(this_ptr: &ChannelManagerReadArgs) -> *const crate::chain::keysinterface::KeysInterface {
1123         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.keys_manager;
1124         &(*inner_val)
1125 }
1126 /// The keys provider which will give us relevant keys. Some keys will be loaded during
1127 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
1128 /// signing data.
1129 #[no_mangle]
1130 pub extern "C" fn ChannelManagerReadArgs_set_keys_manager(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::chain::keysinterface::KeysInterface) {
1131         unsafe { &mut *this_ptr.inner }.keys_manager = val;
1132 }
1133 /// The fee_estimator for use in the ChannelManager in the future.
1134 ///
1135 /// No calls to the FeeEstimator will be made during deserialization.
1136 #[no_mangle]
1137 pub extern "C" fn ChannelManagerReadArgs_get_fee_estimator(this_ptr: &ChannelManagerReadArgs) -> *const crate::chain::chaininterface::FeeEstimator {
1138         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fee_estimator;
1139         &(*inner_val)
1140 }
1141 /// The fee_estimator for use in the ChannelManager in the future.
1142 ///
1143 /// No calls to the FeeEstimator will be made during deserialization.
1144 #[no_mangle]
1145 pub extern "C" fn ChannelManagerReadArgs_set_fee_estimator(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::chain::chaininterface::FeeEstimator) {
1146         unsafe { &mut *this_ptr.inner }.fee_estimator = val;
1147 }
1148 /// The chain::Watch for use in the ChannelManager in the future.
1149 ///
1150 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
1151 /// you have deserialized ChannelMonitors separately and will add them to your
1152 /// chain::Watch after deserializing this ChannelManager.
1153 #[no_mangle]
1154 pub extern "C" fn ChannelManagerReadArgs_get_chain_monitor(this_ptr: &ChannelManagerReadArgs) -> *const crate::chain::Watch {
1155         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.chain_monitor;
1156         &(*inner_val)
1157 }
1158 /// The chain::Watch for use in the ChannelManager in the future.
1159 ///
1160 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
1161 /// you have deserialized ChannelMonitors separately and will add them to your
1162 /// chain::Watch after deserializing this ChannelManager.
1163 #[no_mangle]
1164 pub extern "C" fn ChannelManagerReadArgs_set_chain_monitor(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::chain::Watch) {
1165         unsafe { &mut *this_ptr.inner }.chain_monitor = val;
1166 }
1167 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
1168 /// used to broadcast the latest local commitment transactions of channels which must be
1169 /// force-closed during deserialization.
1170 #[no_mangle]
1171 pub extern "C" fn ChannelManagerReadArgs_get_tx_broadcaster(this_ptr: &ChannelManagerReadArgs) -> *const crate::chain::chaininterface::BroadcasterInterface {
1172         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.tx_broadcaster;
1173         &(*inner_val)
1174 }
1175 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
1176 /// used to broadcast the latest local commitment transactions of channels which must be
1177 /// force-closed during deserialization.
1178 #[no_mangle]
1179 pub extern "C" fn ChannelManagerReadArgs_set_tx_broadcaster(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::chain::chaininterface::BroadcasterInterface) {
1180         unsafe { &mut *this_ptr.inner }.tx_broadcaster = val;
1181 }
1182 /// The Logger for use in the ChannelManager and which may be used to log information during
1183 /// deserialization.
1184 #[no_mangle]
1185 pub extern "C" fn ChannelManagerReadArgs_get_logger(this_ptr: &ChannelManagerReadArgs) -> *const crate::util::logger::Logger {
1186         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.logger;
1187         &(*inner_val)
1188 }
1189 /// The Logger for use in the ChannelManager and which may be used to log information during
1190 /// deserialization.
1191 #[no_mangle]
1192 pub extern "C" fn ChannelManagerReadArgs_set_logger(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::util::logger::Logger) {
1193         unsafe { &mut *this_ptr.inner }.logger = val;
1194 }
1195 /// Default settings used for new channels. Any existing channels will continue to use the
1196 /// runtime settings which were stored when the ChannelManager was serialized.
1197 #[no_mangle]
1198 pub extern "C" fn ChannelManagerReadArgs_get_default_config(this_ptr: &ChannelManagerReadArgs) -> crate::util::config::UserConfig {
1199         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.default_config;
1200         crate::util::config::UserConfig { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
1201 }
1202 /// Default settings used for new channels. Any existing channels will continue to use the
1203 /// runtime settings which were stored when the ChannelManager was serialized.
1204 #[no_mangle]
1205 pub extern "C" fn ChannelManagerReadArgs_set_default_config(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::util::config::UserConfig) {
1206         unsafe { &mut *this_ptr.inner }.default_config = *unsafe { Box::from_raw(val.take_inner()) };
1207 }
1208 /// Simple utility function to create a ChannelManagerReadArgs which creates the monitor
1209 /// HashMap for you. This is primarily useful for C bindings where it is not practical to
1210 /// populate a HashMap directly from C.
1211 #[must_use]
1212 #[no_mangle]
1213 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 {
1214         let mut local_channel_monitors = Vec::new(); for mut item in channel_monitors.into_rust().drain(..) { local_channel_monitors.push( { unsafe { &mut *item.inner } }); };
1215         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);
1216         ChannelManagerReadArgs { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1217 }
1218
1219 #[no_mangle]
1220 /// Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_write
1221 pub extern "C" fn C2Tuple_BlockHashChannelManagerZ_read(ser: crate::c_types::u8slice, arg: crate::ln::channelmanager::ChannelManagerReadArgs) -> crate::c_types::derived::CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ {
1222         let arg_conv = *unsafe { Box::from_raw(arg.take_inner()) };
1223         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);
1224         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() };
1225         local_res
1226 }