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