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