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