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