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::ChannelKeys, 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
260 use lightning::ln::channelmanager::PaymentSendFailure as nativePaymentSendFailureImport;
261 type nativePaymentSendFailure = nativePaymentSendFailureImport;
262
263 /// If a payment fails to send, it can be in one of several states. This enum is returned as the
264 /// Err() type describing which state the payment is in, see the description of individual enum
265 /// states for more.
266 #[must_use]
267 #[repr(C)]
268 pub struct PaymentSendFailure {
269         /// Nearly everywhere, inner must be non-null, however in places where
270         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
271         pub inner: *mut nativePaymentSendFailure,
272         pub is_owned: bool,
273 }
274
275 impl Drop for PaymentSendFailure {
276         fn drop(&mut self) {
277                 if self.is_owned && !self.inner.is_null() {
278                         let _ = unsafe { Box::from_raw(self.inner) };
279                 }
280         }
281 }
282 #[no_mangle]
283 pub extern "C" fn PaymentSendFailure_free(this_ptr: PaymentSendFailure) { }
284 #[allow(unused)]
285 /// Used only if an object of this type is returned as a trait impl by a method
286 extern "C" fn PaymentSendFailure_free_void(this_ptr: *mut c_void) {
287         unsafe { let _ = Box::from_raw(this_ptr as *mut nativePaymentSendFailure); }
288 }
289 #[allow(unused)]
290 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
291 impl PaymentSendFailure {
292         pub(crate) fn take_inner(mut self) -> *mut nativePaymentSendFailure {
293                 assert!(self.is_owned);
294                 let ret = self.inner;
295                 self.inner = std::ptr::null_mut();
296                 ret
297         }
298 }
299 impl Clone for PaymentSendFailure {
300         fn clone(&self) -> Self {
301                 Self {
302                         inner: if self.inner.is_null() { std::ptr::null_mut() } else {
303                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
304                         is_owned: true,
305                 }
306         }
307 }
308 #[allow(unused)]
309 /// Used only if an object of this type is returned as a trait impl by a method
310 pub(crate) extern "C" fn PaymentSendFailure_clone_void(this_ptr: *const c_void) -> *mut c_void {
311         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePaymentSendFailure)).clone() })) as *mut c_void
312 }
313 #[no_mangle]
314 pub extern "C" fn PaymentSendFailure_clone(orig: &PaymentSendFailure) -> PaymentSendFailure {
315         orig.clone()
316 }
317 /// Constructs a new ChannelManager to hold several channels and route between them.
318 ///
319 /// This is the main \"logic hub\" for all channel-related actions, and implements
320 /// ChannelMessageHandler.
321 ///
322 /// Non-proportional fees are fixed according to our risk using the provided fee estimator.
323 ///
324 /// panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`!
325 ///
326 /// Users must provide the current blockchain height from which to track onchain channel
327 /// funding outpoints and send payments with reliable timelocks.
328 ///
329 /// Users need to notify the new ChannelManager when a new block is connected or
330 /// disconnected using its `block_connected` and `block_disconnected` methods.
331 #[must_use]
332 #[no_mangle]
333 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 {
334         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);
335         ChannelManager { inner: Box::into_raw(Box::new(ret)), is_owned: true }
336 }
337
338 /// Creates a new outbound channel to the given remote node and with the given value.
339 ///
340 /// user_id will be provided back as user_channel_id in FundingGenerationReady and
341 /// FundingBroadcastSafe events to allow tracking of which events correspond with which
342 /// create_channel call. Note that user_channel_id defaults to 0 for inbound channels, so you
343 /// may wish to avoid using 0 for user_id here.
344 ///
345 /// If successful, will generate a SendOpenChannel message event, so you should probably poll
346 /// PeerManager::process_events afterwards.
347 ///
348 /// Raises APIError::APIMisuseError when channel_value_satoshis > 2**24 or push_msat is
349 /// greater than channel_value_satoshis * 1k or channel_value_satoshis is < 1000.
350 #[must_use]
351 #[no_mangle]
352 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 {
353         let mut local_override_config = if override_config.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(override_config.take_inner()) } }) };
354         let mut ret = unsafe { &*this_arg.inner }.create_channel(their_network_key.into_rust(), channel_value_satoshis, push_msat, user_id, local_override_config);
355         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() };
356         local_ret
357 }
358
359 /// Gets the list of open channels, in random order. See ChannelDetail field documentation for
360 /// more information.
361 #[must_use]
362 #[no_mangle]
363 pub extern "C" fn ChannelManager_list_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
364         let mut ret = unsafe { &*this_arg.inner }.list_channels();
365         let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { crate::ln::channelmanager::ChannelDetails { inner: Box::into_raw(Box::new(item)), is_owned: true } }); };
366         local_ret.into()
367 }
368
369 /// Gets the list of usable channels, in random order. Useful as an argument to
370 /// get_route to ensure non-announced channels are used.
371 ///
372 /// These are guaranteed to have their is_live value set to true, see the documentation for
373 /// ChannelDetails::is_live for more info on exactly what the criteria are.
374 #[must_use]
375 #[no_mangle]
376 pub extern "C" fn ChannelManager_list_usable_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
377         let mut ret = unsafe { &*this_arg.inner }.list_usable_channels();
378         let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { crate::ln::channelmanager::ChannelDetails { inner: Box::into_raw(Box::new(item)), is_owned: true } }); };
379         local_ret.into()
380 }
381
382 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
383 /// will be accepted on the given channel, and after additional timeout/the closing of all
384 /// pending HTLCs, the channel will be closed on chain.
385 ///
386 /// May generate a SendShutdown message event on success, which should be relayed.
387 #[must_use]
388 #[no_mangle]
389 pub extern "C" fn ChannelManager_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
390         let mut ret = unsafe { &*this_arg.inner }.close_channel(unsafe { &*channel_id});
391         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() };
392         local_ret
393 }
394
395 /// Force closes a channel, immediately broadcasting the latest local commitment transaction to
396 /// the chain and rejecting new HTLCs on the given channel. Fails if channel_id is unknown to the manager.
397 #[must_use]
398 #[no_mangle]
399 pub extern "C" fn ChannelManager_force_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
400         let mut ret = unsafe { &*this_arg.inner }.force_close_channel(unsafe { &*channel_id});
401         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() };
402         local_ret
403 }
404
405 /// Force close all channels, immediately broadcasting the latest local commitment transaction
406 /// for each to the chain and rejecting new HTLCs on each.
407 #[no_mangle]
408 pub extern "C" fn ChannelManager_force_close_all_channels(this_arg: &ChannelManager) {
409         unsafe { &*this_arg.inner }.force_close_all_channels()
410 }
411
412 /// Sends a payment along a given route.
413 ///
414 /// Value parameters are provided via the last hop in route, see documentation for RouteHop
415 /// fields for more info.
416 ///
417 /// Note that if the payment_hash already exists elsewhere (eg you're sending a duplicative
418 /// payment), we don't do anything to stop you! We always try to ensure that if the provided
419 /// next hop knows the preimage to payment_hash they can claim an additional amount as
420 /// specified in the last hop in the route! Thus, you should probably do your own
421 /// payment_preimage tracking (which you should already be doing as they represent \"proof of
422 /// payment\") and prevent double-sends yourself.
423 ///
424 /// May generate SendHTLCs message(s) event on success, which should be relayed.
425 ///
426 /// Each path may have a different return value, and PaymentSendValue may return a Vec with
427 /// each entry matching the corresponding-index entry in the route paths, see
428 /// PaymentSendFailure for more info.
429 ///
430 /// In general, a path may raise:
431 ///  * APIError::RouteError when an invalid route or forwarding parameter (cltv_delta, fee,
432 ///    node public key) is specified.
433 ///  * APIError::ChannelUnavailable if the next-hop channel is not available for updates
434 ///    (including due to previous monitor update failure or new permanent monitor update
435 ///    failure).
436 ///  * APIError::MonitorUpdateFailed if a new monitor update failure prevented sending the
437 ///    relevant updates.
438 ///
439 /// Note that depending on the type of the PaymentSendFailure the HTLC may have been
440 /// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
441 /// different route unless you intend to pay twice!
442 ///
443 /// payment_secret is unrelated to payment_hash (or PaymentPreimage) and exists to authenticate
444 /// the sender to the recipient and prevent payment-probing (deanonymization) attacks. For
445 /// newer nodes, it will be provided to you in the invoice. If you do not have one, the Route
446 /// must not contain multiple paths as multi-path payments require a recipient-provided
447 /// payment_secret.
448 /// If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature
449 /// bit set (either as required or as available). If multiple paths are present in the Route,
450 /// we assume the invoice had the basic_mpp feature set.
451 #[must_use]
452 #[no_mangle]
453 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 {
454         let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentSecret(payment_secret.data) }) };
455         let mut ret = unsafe { &*this_arg.inner }.send_payment(unsafe { &*route.inner }, ::lightning::ln::channelmanager::PaymentHash(payment_hash.data), &local_payment_secret);
456         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 { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
457         local_ret
458 }
459
460 /// Call this upon creation of a funding transaction for the given channel.
461 ///
462 /// Note that ALL inputs in the transaction pointed to by funding_txo MUST spend SegWit outputs
463 /// or your counterparty can steal your funds!
464 ///
465 /// Panics if a funding transaction has already been provided for this channel.
466 ///
467 /// May panic if the funding_txo is duplicative with some other channel (note that this should
468 /// be trivially prevented by using unique funding transaction keys per-channel).
469 #[no_mangle]
470 pub extern "C" fn ChannelManager_funding_transaction_generated(this_arg: &ChannelManager, temporary_channel_id: *const [u8; 32], mut funding_txo: crate::chain::transaction::OutPoint) {
471         unsafe { &*this_arg.inner }.funding_transaction_generated(unsafe { &*temporary_channel_id}, *unsafe { Box::from_raw(funding_txo.take_inner()) })
472 }
473
474 /// Generates a signed node_announcement from the given arguments and creates a
475 /// BroadcastNodeAnnouncement event. Note that such messages will be ignored unless peers have
476 /// seen a channel_announcement from us (ie unless we have public channels open).
477 ///
478 /// RGB is a node \"color\" and alias is a printable human-readable string to describe this node
479 /// to humans. They carry no in-protocol meaning.
480 ///
481 /// addresses represent the set (possibly empty) of socket addresses on which this node accepts
482 /// incoming connections. These will be broadcast to the network, publicly tying these
483 /// addresses together. If you wish to preserve user privacy, addresses should likely contain
484 /// only Tor Onion addresses.
485 ///
486 /// Panics if addresses is absurdly large (more than 500).
487 #[no_mangle]
488 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) {
489         let mut local_addresses = Vec::new(); for mut item in addresses.into_rust().drain(..) { local_addresses.push( { item.into_native() }); };
490         unsafe { &*this_arg.inner }.broadcast_node_announcement(rgb.data, alias.data, local_addresses)
491 }
492
493 /// Processes HTLCs which are pending waiting on random forward delay.
494 ///
495 /// Should only really ever be called in response to a PendingHTLCsForwardable event.
496 /// Will likely generate further events.
497 #[no_mangle]
498 pub extern "C" fn ChannelManager_process_pending_htlc_forwards(this_arg: &ChannelManager) {
499         unsafe { &*this_arg.inner }.process_pending_htlc_forwards()
500 }
501
502 /// If a peer is disconnected we mark any channels with that peer as 'disabled'.
503 /// After some time, if channels are still disabled we need to broadcast a ChannelUpdate
504 /// to inform the network about the uselessness of these channels.
505 ///
506 /// This method handles all the details, and must be called roughly once per minute.
507 #[no_mangle]
508 pub extern "C" fn ChannelManager_timer_chan_freshness_every_min(this_arg: &ChannelManager) {
509         unsafe { &*this_arg.inner }.timer_chan_freshness_every_min()
510 }
511
512 /// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
513 /// after a PaymentReceived event, failing the HTLC back to its origin and freeing resources
514 /// along the path (including in our own channel on which we received it).
515 /// Returns false if no payment was found to fail backwards, true if the process of failing the
516 /// HTLC backwards has been started.
517 #[must_use]
518 #[no_mangle]
519 pub extern "C" fn ChannelManager_fail_htlc_backwards(this_arg: &ChannelManager, payment_hash: *const [u8; 32], mut payment_secret: crate::c_types::ThirtyTwoBytes) -> bool {
520         let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentSecret(payment_secret.data) }) };
521         let mut ret = unsafe { &*this_arg.inner }.fail_htlc_backwards(&::lightning::ln::channelmanager::PaymentHash(unsafe { *payment_hash }), &local_payment_secret);
522         ret
523 }
524
525 /// Provides a payment preimage in response to a PaymentReceived event, returning true and
526 /// generating message events for the net layer to claim the payment, if possible. Thus, you
527 /// should probably kick the net layer to go send messages if this returns true!
528 ///
529 /// You must specify the expected amounts for this HTLC, and we will only claim HTLCs
530 /// available within a few percent of the expected amount. This is critical for several
531 /// reasons : a) it avoids providing senders with `proof-of-payment` (in the form of the
532 /// payment_preimage without having provided the full value and b) it avoids certain
533 /// privacy-breaking recipient-probing attacks which may reveal payment activity to
534 /// motivated attackers.
535 ///
536 /// Note that the privacy concerns in (b) are not relevant in payments with a payment_secret
537 /// set. Thus, for such payments we will claim any payments which do not under-pay.
538 ///
539 /// May panic if called except in response to a PaymentReceived event.
540 #[must_use]
541 #[no_mangle]
542 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 {
543         let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentSecret(payment_secret.data) }) };
544         let mut ret = unsafe { &*this_arg.inner }.claim_funds(::lightning::ln::channelmanager::PaymentPreimage(payment_preimage.data), &local_payment_secret, expected_amount);
545         ret
546 }
547
548 /// Gets the node_id held by this ChannelManager
549 #[must_use]
550 #[no_mangle]
551 pub extern "C" fn ChannelManager_get_our_node_id(this_arg: &ChannelManager) -> crate::c_types::PublicKey {
552         let mut ret = unsafe { &*this_arg.inner }.get_our_node_id();
553         crate::c_types::PublicKey::from_rust(&ret)
554 }
555
556 /// Restores a single, given channel to normal operation after a
557 /// ChannelMonitorUpdateErr::TemporaryFailure was returned from a channel monitor update
558 /// operation.
559 ///
560 /// All ChannelMonitor updates up to and including highest_applied_update_id must have been
561 /// fully committed in every copy of the given channels' ChannelMonitors.
562 ///
563 /// Note that there is no effect to calling with a highest_applied_update_id other than the
564 /// current latest ChannelMonitorUpdate and one call to this function after multiple
565 /// ChannelMonitorUpdateErr::TemporaryFailures is fine. The highest_applied_update_id field
566 /// exists largely only to prevent races between this and concurrent update_monitor calls.
567 ///
568 /// Thus, the anticipated use is, at a high level:
569 ///  1) You register a chain::Watch with this ChannelManager,
570 ///  2) it stores each update to disk, and begins updating any remote (eg watchtower) copies of
571 ///     said ChannelMonitors as it can, returning ChannelMonitorUpdateErr::TemporaryFailures
572 ///     any time it cannot do so instantly,
573 ///  3) update(s) are applied to each remote copy of a ChannelMonitor,
574 ///  4) once all remote copies are updated, you call this function with the update_id that
575 ///     completed, and once it is the latest the Channel will be re-enabled.
576 #[no_mangle]
577 pub extern "C" fn ChannelManager_channel_monitor_updated(this_arg: &ChannelManager, funding_txo: &crate::chain::transaction::OutPoint, mut highest_applied_update_id: u64) {
578         unsafe { &*this_arg.inner }.channel_monitor_updated(unsafe { &*funding_txo.inner }, highest_applied_update_id)
579 }
580
581 impl From<nativeChannelManager> for crate::util::events::MessageSendEventsProvider {
582         fn from(obj: nativeChannelManager) -> Self {
583                 let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true };
584                 let mut ret = ChannelManager_as_MessageSendEventsProvider(&rust_obj);
585                 // 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
586                 rust_obj.inner = std::ptr::null_mut();
587                 ret.free = Some(ChannelManager_free_void);
588                 ret
589         }
590 }
591 #[no_mangle]
592 pub extern "C" fn ChannelManager_as_MessageSendEventsProvider(this_arg: &ChannelManager) -> crate::util::events::MessageSendEventsProvider {
593         crate::util::events::MessageSendEventsProvider {
594                 this_arg: unsafe { (*this_arg).inner as *mut c_void },
595                 free: None,
596                 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
597         }
598 }
599 use lightning::util::events::MessageSendEventsProvider as MessageSendEventsProviderTraitImport;
600 #[must_use]
601 extern "C" fn ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
602         let mut ret = unsafe { &mut *(this_arg as *mut nativeChannelManager) }.get_and_clear_pending_msg_events();
603         let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); };
604         local_ret.into()
605 }
606
607 impl From<nativeChannelManager> for crate::util::events::EventsProvider {
608         fn from(obj: nativeChannelManager) -> Self {
609                 let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true };
610                 let mut ret = ChannelManager_as_EventsProvider(&rust_obj);
611                 // 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
612                 rust_obj.inner = std::ptr::null_mut();
613                 ret.free = Some(ChannelManager_free_void);
614                 ret
615         }
616 }
617 #[no_mangle]
618 pub extern "C" fn ChannelManager_as_EventsProvider(this_arg: &ChannelManager) -> crate::util::events::EventsProvider {
619         crate::util::events::EventsProvider {
620                 this_arg: unsafe { (*this_arg).inner as *mut c_void },
621                 free: None,
622                 get_and_clear_pending_events: ChannelManager_EventsProvider_get_and_clear_pending_events,
623         }
624 }
625 use lightning::util::events::EventsProvider as EventsProviderTraitImport;
626 #[must_use]
627 extern "C" fn ChannelManager_EventsProvider_get_and_clear_pending_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_EventZ {
628         let mut ret = unsafe { &mut *(this_arg as *mut nativeChannelManager) }.get_and_clear_pending_events();
629         let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { crate::util::events::Event::native_into(item) }); };
630         local_ret.into()
631 }
632
633 /// Updates channel state based on transactions seen in a connected block.
634 #[no_mangle]
635 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) {
636         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 }); };
637         unsafe { &*this_arg.inner }.block_connected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), &local_txdata.iter().map(|(a, b)| (*a, b)).collect::<Vec<_>>()[..], height)
638 }
639
640 /// Updates channel state based on a disconnected block.
641 ///
642 /// If necessary, the channel may be force-closed without letting the counterparty participate
643 /// in the shutdown.
644 #[no_mangle]
645 pub extern "C" fn ChannelManager_block_disconnected(this_arg: &ChannelManager, header: *const [u8; 80]) {
646         unsafe { &*this_arg.inner }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap())
647 }
648
649 impl From<nativeChannelManager> for crate::ln::msgs::ChannelMessageHandler {
650         fn from(obj: nativeChannelManager) -> Self {
651                 let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true };
652                 let mut ret = ChannelManager_as_ChannelMessageHandler(&rust_obj);
653                 // 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
654                 rust_obj.inner = std::ptr::null_mut();
655                 ret.free = Some(ChannelManager_free_void);
656                 ret
657         }
658 }
659 #[no_mangle]
660 pub extern "C" fn ChannelManager_as_ChannelMessageHandler(this_arg: &ChannelManager) -> crate::ln::msgs::ChannelMessageHandler {
661         crate::ln::msgs::ChannelMessageHandler {
662                 this_arg: unsafe { (*this_arg).inner as *mut c_void },
663                 free: None,
664                 handle_open_channel: ChannelManager_ChannelMessageHandler_handle_open_channel,
665                 handle_accept_channel: ChannelManager_ChannelMessageHandler_handle_accept_channel,
666                 handle_funding_created: ChannelManager_ChannelMessageHandler_handle_funding_created,
667                 handle_funding_signed: ChannelManager_ChannelMessageHandler_handle_funding_signed,
668                 handle_funding_locked: ChannelManager_ChannelMessageHandler_handle_funding_locked,
669                 handle_shutdown: ChannelManager_ChannelMessageHandler_handle_shutdown,
670                 handle_closing_signed: ChannelManager_ChannelMessageHandler_handle_closing_signed,
671                 handle_update_add_htlc: ChannelManager_ChannelMessageHandler_handle_update_add_htlc,
672                 handle_update_fulfill_htlc: ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc,
673                 handle_update_fail_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_htlc,
674                 handle_update_fail_malformed_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_malformed_htlc,
675                 handle_commitment_signed: ChannelManager_ChannelMessageHandler_handle_commitment_signed,
676                 handle_revoke_and_ack: ChannelManager_ChannelMessageHandler_handle_revoke_and_ack,
677                 handle_update_fee: ChannelManager_ChannelMessageHandler_handle_update_fee,
678                 handle_announcement_signatures: ChannelManager_ChannelMessageHandler_handle_announcement_signatures,
679                 peer_disconnected: ChannelManager_ChannelMessageHandler_peer_disconnected,
680                 peer_connected: ChannelManager_ChannelMessageHandler_peer_connected,
681                 handle_channel_reestablish: ChannelManager_ChannelMessageHandler_handle_channel_reestablish,
682                 handle_error: ChannelManager_ChannelMessageHandler_handle_error,
683                 MessageSendEventsProvider: crate::util::events::MessageSendEventsProvider {
684                         this_arg: unsafe { (*this_arg).inner as *mut c_void },
685                         free: None,
686                         get_and_clear_pending_msg_events: ChannelManager_ChannelMessageHandler_get_and_clear_pending_msg_events,
687                 },
688         }
689 }
690 use lightning::ln::msgs::ChannelMessageHandler as ChannelMessageHandlerTraitImport;
691 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) {
692         unsafe { &mut *(this_arg as *mut nativeChannelManager) }.handle_open_channel(&counterparty_node_id.into_rust(), *unsafe { Box::from_raw(their_features.take_inner()) }, unsafe { &*msg.inner })
693 }
694 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) {
695         unsafe { &mut *(this_arg as *mut nativeChannelManager) }.handle_accept_channel(&counterparty_node_id.into_rust(), *unsafe { Box::from_raw(their_features.take_inner()) }, unsafe { &*msg.inner })
696 }
697 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) {
698         unsafe { &mut *(this_arg as *mut nativeChannelManager) }.handle_funding_created(&counterparty_node_id.into_rust(), unsafe { &*msg.inner })
699 }
700 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) {
701         unsafe { &mut *(this_arg as *mut nativeChannelManager) }.handle_funding_signed(&counterparty_node_id.into_rust(), unsafe { &*msg.inner })
702 }
703 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) {
704         unsafe { &mut *(this_arg as *mut nativeChannelManager) }.handle_funding_locked(&counterparty_node_id.into_rust(), unsafe { &*msg.inner })
705 }
706 extern "C" fn ChannelManager_ChannelMessageHandler_handle_shutdown(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::Shutdown) {
707         unsafe { &mut *(this_arg as *mut nativeChannelManager) }.handle_shutdown(&counterparty_node_id.into_rust(), unsafe { &*msg.inner })
708 }
709 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) {
710         unsafe { &mut *(this_arg as *mut nativeChannelManager) }.handle_closing_signed(&counterparty_node_id.into_rust(), unsafe { &*msg.inner })
711 }
712 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) {
713         unsafe { &mut *(this_arg as *mut nativeChannelManager) }.handle_update_add_htlc(&counterparty_node_id.into_rust(), unsafe { &*msg.inner })
714 }
715 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) {
716         unsafe { &mut *(this_arg as *mut nativeChannelManager) }.handle_update_fulfill_htlc(&counterparty_node_id.into_rust(), unsafe { &*msg.inner })
717 }
718 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) {
719         unsafe { &mut *(this_arg as *mut nativeChannelManager) }.handle_update_fail_htlc(&counterparty_node_id.into_rust(), unsafe { &*msg.inner })
720 }
721 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) {
722         unsafe { &mut *(this_arg as *mut nativeChannelManager) }.handle_update_fail_malformed_htlc(&counterparty_node_id.into_rust(), unsafe { &*msg.inner })
723 }
724 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) {
725         unsafe { &mut *(this_arg as *mut nativeChannelManager) }.handle_commitment_signed(&counterparty_node_id.into_rust(), unsafe { &*msg.inner })
726 }
727 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) {
728         unsafe { &mut *(this_arg as *mut nativeChannelManager) }.handle_revoke_and_ack(&counterparty_node_id.into_rust(), unsafe { &*msg.inner })
729 }
730 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) {
731         unsafe { &mut *(this_arg as *mut nativeChannelManager) }.handle_update_fee(&counterparty_node_id.into_rust(), unsafe { &*msg.inner })
732 }
733 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) {
734         unsafe { &mut *(this_arg as *mut nativeChannelManager) }.handle_announcement_signatures(&counterparty_node_id.into_rust(), unsafe { &*msg.inner })
735 }
736 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) {
737         unsafe { &mut *(this_arg as *mut nativeChannelManager) }.handle_channel_reestablish(&counterparty_node_id.into_rust(), unsafe { &*msg.inner })
738 }
739 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) {
740         unsafe { &mut *(this_arg as *mut nativeChannelManager) }.peer_disconnected(&counterparty_node_id.into_rust(), no_connection_possible)
741 }
742 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) {
743         unsafe { &mut *(this_arg as *mut nativeChannelManager) }.peer_connected(&counterparty_node_id.into_rust(), unsafe { &*init_msg.inner })
744 }
745 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) {
746         unsafe { &mut *(this_arg as *mut nativeChannelManager) }.handle_error(&counterparty_node_id.into_rust(), unsafe { &*msg.inner })
747 }
748 use lightning::util::events::MessageSendEventsProvider as nativeMessageSendEventsProviderTrait;
749 #[must_use]
750 extern "C" fn ChannelManager_ChannelMessageHandler_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
751         let mut ret = unsafe { &mut *(this_arg as *mut nativeChannelManager) }.get_and_clear_pending_msg_events();
752         let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); };
753         local_ret.into()
754 }
755
756 #[no_mangle]
757 pub extern "C" fn ChannelManager_write(obj: &ChannelManager) -> crate::c_types::derived::CVec_u8Z {
758         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
759 }
760 #[no_mangle]
761 pub(crate) extern "C" fn ChannelManager_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
762         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelManager) })
763 }
764
765 use lightning::ln::channelmanager::ChannelManagerReadArgs as nativeChannelManagerReadArgsImport;
766 type nativeChannelManagerReadArgs = nativeChannelManagerReadArgsImport<'static, crate::chain::keysinterface::ChannelKeys, crate::chain::Watch, crate::chain::chaininterface::BroadcasterInterface, crate::chain::keysinterface::KeysInterface, crate::chain::chaininterface::FeeEstimator, crate::util::logger::Logger>;
767
768 /// Arguments for the creation of a ChannelManager that are not deserialized.
769 ///
770 /// At a high-level, the process for deserializing a ChannelManager and resuming normal operation
771 /// is:
772 /// 1) Deserialize all stored ChannelMonitors.
773 /// 2) Deserialize the ChannelManager by filling in this struct and calling <(Sha256dHash,
774 ///    ChannelManager)>::read(reader, args).
775 ///    This may result in closing some Channels if the ChannelMonitor is newer than the stored
776 ///    ChannelManager state to ensure no loss of funds. Thus, transactions may be broadcasted.
777 /// 3) Register all relevant ChannelMonitor outpoints with your chain watch mechanism using
778 ///    ChannelMonitor::get_outputs_to_watch() and ChannelMonitor::get_funding_txo().
779 /// 4) Reconnect blocks on your ChannelMonitors.
780 /// 5) Move the ChannelMonitors into your local chain::Watch.
781 /// 6) Disconnect/connect blocks on the ChannelManager.
782 #[must_use]
783 #[repr(C)]
784 pub struct ChannelManagerReadArgs {
785         /// Nearly everywhere, inner must be non-null, however in places where
786         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
787         pub inner: *mut nativeChannelManagerReadArgs,
788         pub is_owned: bool,
789 }
790
791 impl Drop for ChannelManagerReadArgs {
792         fn drop(&mut self) {
793                 if self.is_owned && !self.inner.is_null() {
794                         let _ = unsafe { Box::from_raw(self.inner) };
795                 }
796         }
797 }
798 #[no_mangle]
799 pub extern "C" fn ChannelManagerReadArgs_free(this_ptr: ChannelManagerReadArgs) { }
800 #[allow(unused)]
801 /// Used only if an object of this type is returned as a trait impl by a method
802 extern "C" fn ChannelManagerReadArgs_free_void(this_ptr: *mut c_void) {
803         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManagerReadArgs); }
804 }
805 #[allow(unused)]
806 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
807 impl ChannelManagerReadArgs {
808         pub(crate) fn take_inner(mut self) -> *mut nativeChannelManagerReadArgs {
809                 assert!(self.is_owned);
810                 let ret = self.inner;
811                 self.inner = std::ptr::null_mut();
812                 ret
813         }
814 }
815 /// The keys provider which will give us relevant keys. Some keys will be loaded during
816 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
817 /// signing data.
818 #[no_mangle]
819 pub extern "C" fn ChannelManagerReadArgs_get_keys_manager(this_ptr: &ChannelManagerReadArgs) -> *const crate::chain::keysinterface::KeysInterface {
820         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.keys_manager;
821         &(*inner_val)
822 }
823 /// The keys provider which will give us relevant keys. Some keys will be loaded during
824 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
825 /// signing data.
826 #[no_mangle]
827 pub extern "C" fn ChannelManagerReadArgs_set_keys_manager(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::chain::keysinterface::KeysInterface) {
828         unsafe { &mut *this_ptr.inner }.keys_manager = val;
829 }
830 /// The fee_estimator for use in the ChannelManager in the future.
831 ///
832 /// No calls to the FeeEstimator will be made during deserialization.
833 #[no_mangle]
834 pub extern "C" fn ChannelManagerReadArgs_get_fee_estimator(this_ptr: &ChannelManagerReadArgs) -> *const crate::chain::chaininterface::FeeEstimator {
835         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fee_estimator;
836         &(*inner_val)
837 }
838 /// The fee_estimator for use in the ChannelManager in the future.
839 ///
840 /// No calls to the FeeEstimator will be made during deserialization.
841 #[no_mangle]
842 pub extern "C" fn ChannelManagerReadArgs_set_fee_estimator(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::chain::chaininterface::FeeEstimator) {
843         unsafe { &mut *this_ptr.inner }.fee_estimator = val;
844 }
845 /// The chain::Watch for use in the ChannelManager in the future.
846 ///
847 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
848 /// you have deserialized ChannelMonitors separately and will add them to your
849 /// chain::Watch after deserializing this ChannelManager.
850 #[no_mangle]
851 pub extern "C" fn ChannelManagerReadArgs_get_chain_monitor(this_ptr: &ChannelManagerReadArgs) -> *const crate::chain::Watch {
852         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.chain_monitor;
853         &(*inner_val)
854 }
855 /// The chain::Watch for use in the ChannelManager in the future.
856 ///
857 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
858 /// you have deserialized ChannelMonitors separately and will add them to your
859 /// chain::Watch after deserializing this ChannelManager.
860 #[no_mangle]
861 pub extern "C" fn ChannelManagerReadArgs_set_chain_monitor(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::chain::Watch) {
862         unsafe { &mut *this_ptr.inner }.chain_monitor = val;
863 }
864 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
865 /// used to broadcast the latest local commitment transactions of channels which must be
866 /// force-closed during deserialization.
867 #[no_mangle]
868 pub extern "C" fn ChannelManagerReadArgs_get_tx_broadcaster(this_ptr: &ChannelManagerReadArgs) -> *const crate::chain::chaininterface::BroadcasterInterface {
869         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.tx_broadcaster;
870         &(*inner_val)
871 }
872 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
873 /// used to broadcast the latest local commitment transactions of channels which must be
874 /// force-closed during deserialization.
875 #[no_mangle]
876 pub extern "C" fn ChannelManagerReadArgs_set_tx_broadcaster(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::chain::chaininterface::BroadcasterInterface) {
877         unsafe { &mut *this_ptr.inner }.tx_broadcaster = val;
878 }
879 /// The Logger for use in the ChannelManager and which may be used to log information during
880 /// deserialization.
881 #[no_mangle]
882 pub extern "C" fn ChannelManagerReadArgs_get_logger(this_ptr: &ChannelManagerReadArgs) -> *const crate::util::logger::Logger {
883         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.logger;
884         &(*inner_val)
885 }
886 /// The Logger for use in the ChannelManager and which may be used to log information during
887 /// deserialization.
888 #[no_mangle]
889 pub extern "C" fn ChannelManagerReadArgs_set_logger(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::util::logger::Logger) {
890         unsafe { &mut *this_ptr.inner }.logger = val;
891 }
892 /// Default settings used for new channels. Any existing channels will continue to use the
893 /// runtime settings which were stored when the ChannelManager was serialized.
894 #[no_mangle]
895 pub extern "C" fn ChannelManagerReadArgs_get_default_config(this_ptr: &ChannelManagerReadArgs) -> crate::util::config::UserConfig {
896         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.default_config;
897         crate::util::config::UserConfig { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
898 }
899 /// Default settings used for new channels. Any existing channels will continue to use the
900 /// runtime settings which were stored when the ChannelManager was serialized.
901 #[no_mangle]
902 pub extern "C" fn ChannelManagerReadArgs_set_default_config(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::util::config::UserConfig) {
903         unsafe { &mut *this_ptr.inner }.default_config = *unsafe { Box::from_raw(val.take_inner()) };
904 }
905 /// Simple utility function to create a ChannelManagerReadArgs which creates the monitor
906 /// HashMap for you. This is primarily useful for C bindings where it is not practical to
907 /// populate a HashMap directly from C.
908 #[must_use]
909 #[no_mangle]
910 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 {
911         let mut local_channel_monitors = Vec::new(); for mut item in channel_monitors.into_rust().drain(..) { local_channel_monitors.push( { unsafe { &mut *item.inner } }); };
912         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);
913         ChannelManagerReadArgs { inner: Box::into_raw(Box::new(ret)), is_owned: true }
914 }
915
916 #[no_mangle]
917 pub extern "C" fn C2Tuple_BlockHashChannelManagerZ_read(ser: crate::c_types::u8slice, arg: crate::ln::channelmanager::ChannelManagerReadArgs) -> crate::c_types::derived::CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ {
918         let arg_conv = *unsafe { Box::from_raw(arg.take_inner()) };
919         let res: Result<(bitcoin::hash_types::BlockHash, lightning::ln::channelmanager::ChannelManager<crate::chain::keysinterface::ChannelKeys, 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);
920         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() };
921         local_res
922 }