1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! The top-level channel management and payment tracking stuff lives here.
11 //! The ChannelManager is the main chunk of logic implementing the lightning protocol and is
12 //! responsible for tracking which channels are open, HTLCs are in flight and reestablishing those
13 //! upon reconnect to the relevant peer(s).
15 //! It does not manage routing logic (see routing::router::get_route for that) nor does it manage constructing
16 //! on-chain transactions (it only monitors the chain to watch for any force-closes that might
17 //! imply it needs to fail HTLCs/payments/channels it manages).
20 use std::str::FromStr;
22 use bitcoin::hashes::Hash;
23 use crate::c_types::*;
26 use lightning::ln::channelmanager::ChannelManager as nativeChannelManagerImport;
27 type nativeChannelManager = nativeChannelManagerImport<crate::lightning::chain::keysinterface::Sign, crate::lightning::chain::Watch, crate::lightning::chain::chaininterface::BroadcasterInterface, crate::lightning::chain::keysinterface::KeysInterface, crate::lightning::chain::chaininterface::FeeEstimator, crate::lightning::util::logger::Logger>;
29 /// Manager which keeps track of a number of channels and sends messages to the appropriate
30 /// channel, also tracking HTLC preimages and forwarding onion packets appropriately.
32 /// Implements ChannelMessageHandler, handling the multi-channel parts and passing things through
33 /// to individual Channels.
35 /// Implements Writeable to write out all channel state to disk. Implies peer_disconnected() for
36 /// all peers during write/read (though does not modify this instance, only the instance being
37 /// serialized). This will result in any channels which have not yet exchanged funding_created (ie
38 /// called funding_transaction_generated for outbound channels).
40 /// Note that you can be a bit lazier about writing out ChannelManager than you can be with
41 /// ChannelMonitors. With ChannelMonitors you MUST write each monitor update out to disk before
42 /// returning from chain::Watch::watch_/update_channel, with ChannelManagers, writing updates
43 /// happens out-of-band (and will prevent any other ChannelManager operations from occurring during
44 /// the serialization process). If the deserialized version is out-of-date compared to the
45 /// ChannelMonitors passed by reference to read(), those channels will be force-closed based on the
46 /// ChannelMonitor state and no funds will be lost (mod on-chain transaction fees).
48 /// Note that the deserializer is only implemented for (BlockHash, ChannelManager), which
49 /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
50 /// the \"reorg path\" (ie call block_disconnected() until you get to a common block and then call
51 /// block_connected() to step towards your best block) upon deserialization before using the
54 /// Note that ChannelManager is responsible for tracking liveness of its channels and generating
55 /// ChannelUpdate messages informing peers that the channel is temporarily disabled. To avoid
56 /// spam due to quick disconnection/reconnection, updates are not sent until the channel has been
57 /// offline for a full minute. In order to track this, you must call
58 /// timer_tick_occurred roughly once per minute, though it doesn't have to be perfect.
60 /// Rather than using a plain ChannelManager, it is preferable to use either a SimpleArcChannelManager
61 /// a SimpleRefChannelManager, for conciseness. See their documentation for more details, but
62 /// essentially you should default to using a SimpleRefChannelManager, and use a
63 /// SimpleArcChannelManager when you require a ChannelManager with a static lifetime, such as when
64 /// you're using lightning-net-tokio.
67 pub struct ChannelManager {
68 /// A pointer to the opaque Rust object.
70 /// Nearly everywhere, inner must be non-null, however in places where
71 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
72 pub inner: *mut nativeChannelManager,
73 /// Indicates that this is the only struct which contains the same pointer.
75 /// Rust functions which take ownership of an object provided via an argument require
76 /// this to be true and invalidate the object pointed to by inner.
80 impl Drop for ChannelManager {
82 if self.is_owned && !<*mut nativeChannelManager>::is_null(self.inner) {
83 let _ = unsafe { Box::from_raw(self.inner) };
87 /// Frees any resources used by the ChannelManager, if is_owned is set and inner is non-NULL.
89 pub extern "C" fn ChannelManager_free(this_obj: ChannelManager) { }
91 /// Used only if an object of this type is returned as a trait impl by a method
92 extern "C" fn ChannelManager_free_void(this_ptr: *mut c_void) {
93 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManager); }
96 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
98 pub(crate) fn take_inner(mut self) -> *mut nativeChannelManager {
99 assert!(self.is_owned);
100 let ret = self.inner;
101 self.inner = std::ptr::null_mut();
106 use lightning::ln::channelmanager::ChainParameters as nativeChainParametersImport;
107 type nativeChainParameters = nativeChainParametersImport;
109 /// Chain-related parameters used to construct a new `ChannelManager`.
111 /// Typically, the block-specific parameters are derived from the best block hash for the network,
112 /// as a newly constructed `ChannelManager` will not have created any channels yet. These parameters
113 /// are not needed when deserializing a previously constructed `ChannelManager`.
116 pub struct ChainParameters {
117 /// A pointer to the opaque Rust object.
119 /// Nearly everywhere, inner must be non-null, however in places where
120 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
121 pub inner: *mut nativeChainParameters,
122 /// Indicates that this is the only struct which contains the same pointer.
124 /// Rust functions which take ownership of an object provided via an argument require
125 /// this to be true and invalidate the object pointed to by inner.
129 impl Drop for ChainParameters {
131 if self.is_owned && !<*mut nativeChainParameters>::is_null(self.inner) {
132 let _ = unsafe { Box::from_raw(self.inner) };
136 /// Frees any resources used by the ChainParameters, if is_owned is set and inner is non-NULL.
138 pub extern "C" fn ChainParameters_free(this_obj: ChainParameters) { }
140 /// Used only if an object of this type is returned as a trait impl by a method
141 extern "C" fn ChainParameters_free_void(this_ptr: *mut c_void) {
142 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChainParameters); }
145 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
146 impl ChainParameters {
147 pub(crate) fn take_inner(mut self) -> *mut nativeChainParameters {
148 assert!(self.is_owned);
149 let ret = self.inner;
150 self.inner = std::ptr::null_mut();
154 /// The network for determining the `chain_hash` in Lightning messages.
156 pub extern "C" fn ChainParameters_get_network(this_ptr: &ChainParameters) -> crate::bitcoin::network::Network {
157 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.network;
158 crate::bitcoin::network::Network::from_bitcoin(inner_val)
160 /// The network for determining the `chain_hash` in Lightning messages.
162 pub extern "C" fn ChainParameters_set_network(this_ptr: &mut ChainParameters, mut val: crate::bitcoin::network::Network) {
163 unsafe { &mut *this_ptr.inner }.network = val.into_bitcoin();
165 /// The hash and height of the latest block successfully connected.
167 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
169 pub extern "C" fn ChainParameters_get_best_block(this_ptr: &ChainParameters) -> crate::lightning::ln::channelmanager::BestBlock {
170 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.best_block;
171 crate::lightning::ln::channelmanager::BestBlock { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
173 /// The hash and height of the latest block successfully connected.
175 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
177 pub extern "C" fn ChainParameters_set_best_block(this_ptr: &mut ChainParameters, mut val: crate::lightning::ln::channelmanager::BestBlock) {
178 unsafe { &mut *this_ptr.inner }.best_block = *unsafe { Box::from_raw(val.take_inner()) };
180 /// Constructs a new ChainParameters given each field
183 pub extern "C" fn ChainParameters_new(mut network_arg: crate::bitcoin::network::Network, mut best_block_arg: crate::lightning::ln::channelmanager::BestBlock) -> ChainParameters {
184 ChainParameters { inner: Box::into_raw(Box::new(nativeChainParameters {
185 network: network_arg.into_bitcoin(),
186 best_block: *unsafe { Box::from_raw(best_block_arg.take_inner()) },
187 })), is_owned: true }
189 impl Clone for ChainParameters {
190 fn clone(&self) -> Self {
192 inner: if <*mut nativeChainParameters>::is_null(self.inner) { std::ptr::null_mut() } else {
193 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
199 /// Used only if an object of this type is returned as a trait impl by a method
200 pub(crate) extern "C" fn ChainParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
201 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChainParameters)).clone() })) as *mut c_void
204 /// Creates a copy of the ChainParameters
205 pub extern "C" fn ChainParameters_clone(orig: &ChainParameters) -> ChainParameters {
209 use lightning::ln::channelmanager::BestBlock as nativeBestBlockImport;
210 type nativeBestBlock = nativeBestBlockImport;
212 /// The best known block as identified by its hash and height.
215 pub struct BestBlock {
216 /// A pointer to the opaque Rust object.
218 /// Nearly everywhere, inner must be non-null, however in places where
219 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
220 pub inner: *mut nativeBestBlock,
221 /// Indicates that this is the only struct which contains the same pointer.
223 /// Rust functions which take ownership of an object provided via an argument require
224 /// this to be true and invalidate the object pointed to by inner.
228 impl Drop for BestBlock {
230 if self.is_owned && !<*mut nativeBestBlock>::is_null(self.inner) {
231 let _ = unsafe { Box::from_raw(self.inner) };
235 /// Frees any resources used by the BestBlock, if is_owned is set and inner is non-NULL.
237 pub extern "C" fn BestBlock_free(this_obj: BestBlock) { }
239 /// Used only if an object of this type is returned as a trait impl by a method
240 extern "C" fn BestBlock_free_void(this_ptr: *mut c_void) {
241 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeBestBlock); }
244 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
246 pub(crate) fn take_inner(mut self) -> *mut nativeBestBlock {
247 assert!(self.is_owned);
248 let ret = self.inner;
249 self.inner = std::ptr::null_mut();
253 impl Clone for BestBlock {
254 fn clone(&self) -> Self {
256 inner: if <*mut nativeBestBlock>::is_null(self.inner) { std::ptr::null_mut() } else {
257 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
263 /// Used only if an object of this type is returned as a trait impl by a method
264 pub(crate) extern "C" fn BestBlock_clone_void(this_ptr: *const c_void) -> *mut c_void {
265 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBestBlock)).clone() })) as *mut c_void
268 /// Creates a copy of the BestBlock
269 pub extern "C" fn BestBlock_clone(orig: &BestBlock) -> BestBlock {
272 /// Returns the best block from the genesis of the given network.
275 pub extern "C" fn BestBlock_from_genesis(mut network: crate::bitcoin::network::Network) -> BestBlock {
276 let mut ret = lightning::ln::channelmanager::BestBlock::from_genesis(network.into_bitcoin());
277 BestBlock { inner: Box::into_raw(Box::new(ret)), is_owned: true }
280 /// Returns the best block as identified by the given block hash and height.
283 pub extern "C" fn BestBlock_new(mut block_hash: crate::c_types::ThirtyTwoBytes, mut height: u32) -> BestBlock {
284 let mut ret = lightning::ln::channelmanager::BestBlock::new(::bitcoin::hash_types::BlockHash::from_slice(&block_hash.data[..]).unwrap(), height);
285 BestBlock { inner: Box::into_raw(Box::new(ret)), is_owned: true }
288 /// Returns the best block hash.
291 pub extern "C" fn BestBlock_block_hash(this_arg: &BestBlock) -> crate::c_types::ThirtyTwoBytes {
292 let mut ret = unsafe { &*this_arg.inner }.block_hash();
293 crate::c_types::ThirtyTwoBytes { data: ret.into_inner() }
296 /// Returns the best block height.
299 pub extern "C" fn BestBlock_height(this_arg: &BestBlock) -> u32 {
300 let mut ret = unsafe { &*this_arg.inner }.height();
304 /// The amount of time in blocks we require our counterparty wait to claim their money (ie time
305 /// between when we, or our watchtower, must check for them having broadcast a theft transaction).
307 /// This can be increased (but not decreased) through [`ChannelHandshakeConfig::our_to_self_delay`]
309 /// [`ChannelHandshakeConfig::our_to_self_delay`]: crate::util::config::ChannelHandshakeConfig::our_to_self_delay
312 pub static BREAKDOWN_TIMEOUT: u16 = lightning::ln::channelmanager::BREAKDOWN_TIMEOUT;
313 /// The minimum number of blocks between an inbound HTLC's CLTV and the corresponding outbound
314 /// HTLC's CLTV. The current default represents roughly seven hours of blocks at six blocks/hour.
316 /// This can be increased (but not decreased) through [`ChannelConfig::cltv_expiry_delta`]
318 /// [`ChannelConfig::cltv_expiry_delta`]: crate::util::config::ChannelConfig::cltv_expiry_delta
321 pub static MIN_CLTV_EXPIRY_DELTA: u16 = lightning::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA;
322 /// Minimum CLTV difference between the current block height and received inbound payments.
323 /// Invoices generated for payment to us must set their `min_final_cltv_expiry` field to at least
327 pub static MIN_FINAL_CLTV_EXPIRY: u32 = lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY;
329 use lightning::ln::channelmanager::ChannelDetails as nativeChannelDetailsImport;
330 type nativeChannelDetails = nativeChannelDetailsImport;
332 /// Details of a channel, as returned by ChannelManager::list_channels and ChannelManager::list_usable_channels
335 pub struct ChannelDetails {
336 /// A pointer to the opaque Rust object.
338 /// Nearly everywhere, inner must be non-null, however in places where
339 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
340 pub inner: *mut nativeChannelDetails,
341 /// Indicates that this is the only struct which contains the same pointer.
343 /// Rust functions which take ownership of an object provided via an argument require
344 /// this to be true and invalidate the object pointed to by inner.
348 impl Drop for ChannelDetails {
350 if self.is_owned && !<*mut nativeChannelDetails>::is_null(self.inner) {
351 let _ = unsafe { Box::from_raw(self.inner) };
355 /// Frees any resources used by the ChannelDetails, if is_owned is set and inner is non-NULL.
357 pub extern "C" fn ChannelDetails_free(this_obj: ChannelDetails) { }
359 /// Used only if an object of this type is returned as a trait impl by a method
360 extern "C" fn ChannelDetails_free_void(this_ptr: *mut c_void) {
361 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelDetails); }
364 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
365 impl ChannelDetails {
366 pub(crate) fn take_inner(mut self) -> *mut nativeChannelDetails {
367 assert!(self.is_owned);
368 let ret = self.inner;
369 self.inner = std::ptr::null_mut();
373 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
374 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
375 /// Note that this means this value is *not* persistent - it can change once during the
376 /// lifetime of the channel.
378 pub extern "C" fn ChannelDetails_get_channel_id(this_ptr: &ChannelDetails) -> *const [u8; 32] {
379 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_id;
382 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
383 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
384 /// Note that this means this value is *not* persistent - it can change once during the
385 /// lifetime of the channel.
387 pub extern "C" fn ChannelDetails_set_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::ThirtyTwoBytes) {
388 unsafe { &mut *this_ptr.inner }.channel_id = val.data;
390 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
391 /// our counterparty already.
393 /// Note that, if this has been set, `channel_id` will be equivalent to
394 /// `funding_txo.unwrap().to_channel_id()`.
396 pub extern "C" fn ChannelDetails_get_funding_txo(this_ptr: &ChannelDetails) -> crate::lightning::chain::transaction::OutPoint {
397 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.funding_txo;
398 let mut local_inner_val = crate::lightning::chain::transaction::OutPoint { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
401 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
402 /// our counterparty already.
404 /// Note that, if this has been set, `channel_id` will be equivalent to
405 /// `funding_txo.unwrap().to_channel_id()`.
407 pub extern "C" fn ChannelDetails_set_funding_txo(this_ptr: &mut ChannelDetails, mut val: crate::lightning::chain::transaction::OutPoint) {
408 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
409 unsafe { &mut *this_ptr.inner }.funding_txo = local_val;
411 /// The position of the funding transaction in the chain. None if the funding transaction has
412 /// not yet been confirmed and the channel fully opened.
414 pub extern "C" fn ChannelDetails_get_short_channel_id(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
415 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.short_channel_id;
416 let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { { crate::c_types::derived::COption_u64Z::Some(inner_val.unwrap()) } };
419 /// The position of the funding transaction in the chain. None if the funding transaction has
420 /// not yet been confirmed and the channel fully opened.
422 pub extern "C" fn ChannelDetails_set_short_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
423 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
424 unsafe { &mut *this_ptr.inner }.short_channel_id = local_val;
426 /// The node_id of our counterparty
428 pub extern "C" fn ChannelDetails_get_remote_network_id(this_ptr: &ChannelDetails) -> crate::c_types::PublicKey {
429 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.remote_network_id;
430 crate::c_types::PublicKey::from_rust(&inner_val)
432 /// The node_id of our counterparty
434 pub extern "C" fn ChannelDetails_set_remote_network_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::PublicKey) {
435 unsafe { &mut *this_ptr.inner }.remote_network_id = val.into_rust();
437 /// The Features the channel counterparty provided upon last connection.
438 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
439 /// many routing-relevant features are present in the init context.
441 pub extern "C" fn ChannelDetails_get_counterparty_features(this_ptr: &ChannelDetails) -> crate::lightning::ln::features::InitFeatures {
442 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.counterparty_features;
443 crate::lightning::ln::features::InitFeatures { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
445 /// The Features the channel counterparty provided upon last connection.
446 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
447 /// many routing-relevant features are present in the init context.
449 pub extern "C" fn ChannelDetails_set_counterparty_features(this_ptr: &mut ChannelDetails, mut val: crate::lightning::ln::features::InitFeatures) {
450 unsafe { &mut *this_ptr.inner }.counterparty_features = *unsafe { Box::from_raw(val.take_inner()) };
452 /// The value, in satoshis, of this channel as appears in the funding output
454 pub extern "C" fn ChannelDetails_get_channel_value_satoshis(this_ptr: &ChannelDetails) -> u64 {
455 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_value_satoshis;
458 /// The value, in satoshis, of this channel as appears in the funding output
460 pub extern "C" fn ChannelDetails_set_channel_value_satoshis(this_ptr: &mut ChannelDetails, mut val: u64) {
461 unsafe { &mut *this_ptr.inner }.channel_value_satoshis = val;
463 /// The user_id passed in to create_channel, or 0 if the channel was inbound.
465 pub extern "C" fn ChannelDetails_get_user_id(this_ptr: &ChannelDetails) -> u64 {
466 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.user_id;
469 /// The user_id passed in to create_channel, or 0 if the channel was inbound.
471 pub extern "C" fn ChannelDetails_set_user_id(this_ptr: &mut ChannelDetails, mut val: u64) {
472 unsafe { &mut *this_ptr.inner }.user_id = val;
474 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
475 /// any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
476 /// available for inclusion in new outbound HTLCs). This further does not include any pending
477 /// outgoing HTLCs which are awaiting some other resolution to be sent.
479 pub extern "C" fn ChannelDetails_get_outbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
480 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.outbound_capacity_msat;
483 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
484 /// any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
485 /// available for inclusion in new outbound HTLCs). This further does not include any pending
486 /// outgoing HTLCs which are awaiting some other resolution to be sent.
488 pub extern "C" fn ChannelDetails_set_outbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
489 unsafe { &mut *this_ptr.inner }.outbound_capacity_msat = val;
491 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
492 /// include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
493 /// available for inclusion in new inbound HTLCs).
494 /// Note that there are some corner cases not fully handled here, so the actual available
495 /// inbound capacity may be slightly higher than this.
497 pub extern "C" fn ChannelDetails_get_inbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
498 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.inbound_capacity_msat;
501 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
502 /// include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
503 /// available for inclusion in new inbound HTLCs).
504 /// Note that there are some corner cases not fully handled here, so the actual available
505 /// inbound capacity may be slightly higher than this.
507 pub extern "C" fn ChannelDetails_set_inbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
508 unsafe { &mut *this_ptr.inner }.inbound_capacity_msat = val;
510 /// True if the channel was initiated (and thus funded) by us.
512 pub extern "C" fn ChannelDetails_get_is_outbound(this_ptr: &ChannelDetails) -> bool {
513 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.is_outbound;
516 /// True if the channel was initiated (and thus funded) by us.
518 pub extern "C" fn ChannelDetails_set_is_outbound(this_ptr: &mut ChannelDetails, mut val: bool) {
519 unsafe { &mut *this_ptr.inner }.is_outbound = val;
521 /// True if the channel is confirmed, funding_locked messages have been exchanged, and the
522 /// channel is not currently being shut down. `funding_locked` message exchange implies the
523 /// required confirmation count has been reached (and we were connected to the peer at some
524 /// point after the funding transaction received enough confirmations).
526 pub extern "C" fn ChannelDetails_get_is_funding_locked(this_ptr: &ChannelDetails) -> bool {
527 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.is_funding_locked;
530 /// True if the channel is confirmed, funding_locked messages have been exchanged, and the
531 /// channel is not currently being shut down. `funding_locked` message exchange implies the
532 /// required confirmation count has been reached (and we were connected to the peer at some
533 /// point after the funding transaction received enough confirmations).
535 pub extern "C" fn ChannelDetails_set_is_funding_locked(this_ptr: &mut ChannelDetails, mut val: bool) {
536 unsafe { &mut *this_ptr.inner }.is_funding_locked = val;
538 /// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
539 /// the peer is connected, (c) no monitor update failure is pending resolution, and (d) the
540 /// channel is not currently negotiating a shutdown.
542 /// This is a strict superset of `is_funding_locked`.
544 pub extern "C" fn ChannelDetails_get_is_usable(this_ptr: &ChannelDetails) -> bool {
545 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.is_usable;
548 /// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
549 /// the peer is connected, (c) no monitor update failure is pending resolution, and (d) the
550 /// channel is not currently negotiating a shutdown.
552 /// This is a strict superset of `is_funding_locked`.
554 pub extern "C" fn ChannelDetails_set_is_usable(this_ptr: &mut ChannelDetails, mut val: bool) {
555 unsafe { &mut *this_ptr.inner }.is_usable = val;
557 /// True if this channel is (or will be) publicly-announced.
559 pub extern "C" fn ChannelDetails_get_is_public(this_ptr: &ChannelDetails) -> bool {
560 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.is_public;
563 /// True if this channel is (or will be) publicly-announced.
565 pub extern "C" fn ChannelDetails_set_is_public(this_ptr: &mut ChannelDetails, mut val: bool) {
566 unsafe { &mut *this_ptr.inner }.is_public = val;
568 impl Clone for ChannelDetails {
569 fn clone(&self) -> Self {
571 inner: if <*mut nativeChannelDetails>::is_null(self.inner) { std::ptr::null_mut() } else {
572 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
578 /// Used only if an object of this type is returned as a trait impl by a method
579 pub(crate) extern "C" fn ChannelDetails_clone_void(this_ptr: *const c_void) -> *mut c_void {
580 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelDetails)).clone() })) as *mut c_void
583 /// Creates a copy of the ChannelDetails
584 pub extern "C" fn ChannelDetails_clone(orig: &ChannelDetails) -> ChannelDetails {
587 /// If a payment fails to send, it can be in one of several states. This enum is returned as the
588 /// Err() type describing which state the payment is in, see the description of individual enum
593 pub enum PaymentSendFailure {
594 /// A parameter which was passed to send_payment was invalid, preventing us from attempting to
595 /// send the payment at all. No channel state has been changed or messages sent to peers, and
596 /// once you've changed the parameter at error, you can freely retry the payment in full.
597 ParameterError(crate::lightning::util::errors::APIError),
598 /// A parameter in a single path which was passed to send_payment was invalid, preventing us
599 /// from attempting to send the payment at all. No channel state has been changed or messages
600 /// sent to peers, and once you've changed the parameter at error, you can freely retry the
603 /// The results here are ordered the same as the paths in the route object which was passed to
605 PathParameterError(crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ),
606 /// All paths which were attempted failed to send, with no channel state change taking place.
607 /// You can freely retry the payment in full (though you probably want to do so over different
608 /// paths than the ones selected).
609 AllFailedRetrySafe(crate::c_types::derived::CVec_APIErrorZ),
610 /// Some paths which were attempted failed to send, though possibly not all. At least some
611 /// paths have irrevocably committed to the HTLC and retrying the payment in full would result
612 /// in over-/re-payment.
614 /// The results here are ordered the same as the paths in the route object which was passed to
615 /// send_payment, and any Errs which are not APIError::MonitorUpdateFailed can be safely
616 /// retried (though there is currently no API with which to do so).
618 /// Any entries which contain Err(APIError::MonitorUpdateFailed) or Ok(()) MUST NOT be retried
619 /// as they will result in over-/re-payment. These HTLCs all either successfully sent (in the
620 /// case of Ok(())) or will send once channel_monitor_updated is called on the next-hop channel
621 /// with the latest update_id.
622 PartialFailure(crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ),
624 use lightning::ln::channelmanager::PaymentSendFailure as nativePaymentSendFailure;
625 impl PaymentSendFailure {
627 pub(crate) fn to_native(&self) -> nativePaymentSendFailure {
629 PaymentSendFailure::ParameterError (ref a, ) => {
630 let mut a_nonref = (*a).clone();
631 nativePaymentSendFailure::ParameterError (
632 a_nonref.into_native(),
635 PaymentSendFailure::PathParameterError (ref a, ) => {
636 let mut a_nonref = (*a).clone();
637 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { let mut local_a_nonref_0 = match item.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.err)) }).into_native() })}; local_a_nonref_0 }); };
638 nativePaymentSendFailure::PathParameterError (
642 PaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
643 let mut a_nonref = (*a).clone();
644 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { item.into_native() }); };
645 nativePaymentSendFailure::AllFailedRetrySafe (
649 PaymentSendFailure::PartialFailure (ref a, ) => {
650 let mut a_nonref = (*a).clone();
651 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { let mut local_a_nonref_0 = match item.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.err)) }).into_native() })}; local_a_nonref_0 }); };
652 nativePaymentSendFailure::PartialFailure (
659 pub(crate) fn into_native(self) -> nativePaymentSendFailure {
661 PaymentSendFailure::ParameterError (mut a, ) => {
662 nativePaymentSendFailure::ParameterError (
666 PaymentSendFailure::PathParameterError (mut a, ) => {
667 let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { let mut local_a_0 = match item.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.err)) }).into_native() })}; local_a_0 }); };
668 nativePaymentSendFailure::PathParameterError (
672 PaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
673 let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { item.into_native() }); };
674 nativePaymentSendFailure::AllFailedRetrySafe (
678 PaymentSendFailure::PartialFailure (mut a, ) => {
679 let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { let mut local_a_0 = match item.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.err)) }).into_native() })}; local_a_0 }); };
680 nativePaymentSendFailure::PartialFailure (
687 pub(crate) fn from_native(native: &nativePaymentSendFailure) -> Self {
689 nativePaymentSendFailure::ParameterError (ref a, ) => {
690 let mut a_nonref = (*a).clone();
691 PaymentSendFailure::ParameterError (
692 crate::lightning::util::errors::APIError::native_into(a_nonref),
695 nativePaymentSendFailure::PathParameterError (ref a, ) => {
696 let mut a_nonref = (*a).clone();
697 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.drain(..) { local_a_nonref.push( { let mut local_a_nonref_0 = match item { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() }; local_a_nonref_0 }); };
698 PaymentSendFailure::PathParameterError (
699 local_a_nonref.into(),
702 nativePaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
703 let mut a_nonref = (*a).clone();
704 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.drain(..) { local_a_nonref.push( { crate::lightning::util::errors::APIError::native_into(item) }); };
705 PaymentSendFailure::AllFailedRetrySafe (
706 local_a_nonref.into(),
709 nativePaymentSendFailure::PartialFailure (ref a, ) => {
710 let mut a_nonref = (*a).clone();
711 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.drain(..) { local_a_nonref.push( { let mut local_a_nonref_0 = match item { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() }; local_a_nonref_0 }); };
712 PaymentSendFailure::PartialFailure (
713 local_a_nonref.into(),
719 pub(crate) fn native_into(native: nativePaymentSendFailure) -> Self {
721 nativePaymentSendFailure::ParameterError (mut a, ) => {
722 PaymentSendFailure::ParameterError (
723 crate::lightning::util::errors::APIError::native_into(a),
726 nativePaymentSendFailure::PathParameterError (mut a, ) => {
727 let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { let mut local_a_0 = match item { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() }; local_a_0 }); };
728 PaymentSendFailure::PathParameterError (
732 nativePaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
733 let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { crate::lightning::util::errors::APIError::native_into(item) }); };
734 PaymentSendFailure::AllFailedRetrySafe (
738 nativePaymentSendFailure::PartialFailure (mut a, ) => {
739 let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { let mut local_a_0 = match item { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() }; local_a_0 }); };
740 PaymentSendFailure::PartialFailure (
747 /// Frees any resources used by the PaymentSendFailure
749 pub extern "C" fn PaymentSendFailure_free(this_ptr: PaymentSendFailure) { }
750 /// Creates a copy of the PaymentSendFailure
752 pub extern "C" fn PaymentSendFailure_clone(orig: &PaymentSendFailure) -> PaymentSendFailure {
755 /// Constructs a new ChannelManager to hold several channels and route between them.
757 /// This is the main \"logic hub\" for all channel-related actions, and implements
758 /// ChannelMessageHandler.
760 /// Non-proportional fees are fixed according to our risk using the provided fee estimator.
762 /// panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`!
764 /// Users need to notify the new ChannelManager when a new block is connected or
765 /// disconnected using its `block_connected` and `block_disconnected` methods, starting
766 /// from after `params.latest_hash`.
769 pub extern "C" fn ChannelManager_new(mut fee_est: crate::lightning::chain::chaininterface::FeeEstimator, mut chain_monitor: crate::lightning::chain::Watch, mut tx_broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut logger: crate::lightning::util::logger::Logger, mut keys_manager: crate::lightning::chain::keysinterface::KeysInterface, mut config: crate::lightning::util::config::UserConfig, mut params: crate::lightning::ln::channelmanager::ChainParameters) -> ChannelManager {
770 let mut ret = lightning::ln::channelmanager::ChannelManager::new(fee_est, chain_monitor, tx_broadcaster, logger, keys_manager, *unsafe { Box::from_raw(config.take_inner()) }, *unsafe { Box::from_raw(params.take_inner()) });
771 ChannelManager { inner: Box::into_raw(Box::new(ret)), is_owned: true }
774 /// Gets the current configuration applied to all new channels, as
777 pub extern "C" fn ChannelManager_get_current_default_configuration(this_arg: &ChannelManager) -> crate::lightning::util::config::UserConfig {
778 let mut ret = unsafe { &*this_arg.inner }.get_current_default_configuration();
779 crate::lightning::util::config::UserConfig { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
782 /// Creates a new outbound channel to the given remote node and with the given value.
784 /// user_id will be provided back as user_channel_id in FundingGenerationReady events to allow
785 /// tracking of which events correspond with which create_channel call. Note that the
786 /// user_channel_id defaults to 0 for inbound channels, so you may wish to avoid using 0 for
787 /// user_id here. user_id has no meaning inside of LDK, it is simply copied to events and
788 /// otherwise ignored.
790 /// If successful, will generate a SendOpenChannel message event, so you should probably poll
791 /// PeerManager::process_events afterwards.
793 /// Raises APIError::APIMisuseError when channel_value_satoshis > 2**24 or push_msat is
794 /// greater than channel_value_satoshis * 1k or channel_value_satoshis is < 1000.
797 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::lightning::util::config::UserConfig) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
798 let mut local_override_config = if override_config.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(override_config.take_inner()) } }) };
799 let mut ret = unsafe { &*this_arg.inner }.create_channel(their_network_key.into_rust(), channel_value_satoshis, push_msat, user_id, local_override_config);
800 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
804 /// Gets the list of open channels, in random order. See ChannelDetail field documentation for
805 /// more information.
808 pub extern "C" fn ChannelManager_list_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
809 let mut ret = unsafe { &*this_arg.inner }.list_channels();
810 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: Box::into_raw(Box::new(item)), is_owned: true } }); };
814 /// Gets the list of usable channels, in random order. Useful as an argument to
815 /// get_route to ensure non-announced channels are used.
817 /// These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
818 /// documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
822 pub extern "C" fn ChannelManager_list_usable_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
823 let mut ret = unsafe { &*this_arg.inner }.list_usable_channels();
824 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: Box::into_raw(Box::new(item)), is_owned: true } }); };
828 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
829 /// will be accepted on the given channel, and after additional timeout/the closing of all
830 /// pending HTLCs, the channel will be closed on chain.
832 /// May generate a SendShutdown message event on success, which should be relayed.
835 pub extern "C" fn ChannelManager_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
836 let mut ret = unsafe { &*this_arg.inner }.close_channel(unsafe { &*channel_id});
837 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
841 /// Force closes a channel, immediately broadcasting the latest local commitment transaction to
842 /// the chain and rejecting new HTLCs on the given channel. Fails if channel_id is unknown to the manager.
845 pub extern "C" fn ChannelManager_force_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
846 let mut ret = unsafe { &*this_arg.inner }.force_close_channel(unsafe { &*channel_id});
847 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
851 /// Force close all channels, immediately broadcasting the latest local commitment transaction
852 /// for each to the chain and rejecting new HTLCs on each.
854 pub extern "C" fn ChannelManager_force_close_all_channels(this_arg: &ChannelManager) {
855 unsafe { &*this_arg.inner }.force_close_all_channels()
858 /// Sends a payment along a given route.
860 /// Value parameters are provided via the last hop in route, see documentation for RouteHop
861 /// fields for more info.
863 /// Note that if the payment_hash already exists elsewhere (eg you're sending a duplicative
864 /// payment), we don't do anything to stop you! We always try to ensure that if the provided
865 /// next hop knows the preimage to payment_hash they can claim an additional amount as
866 /// specified in the last hop in the route! Thus, you should probably do your own
867 /// payment_preimage tracking (which you should already be doing as they represent \"proof of
868 /// payment\") and prevent double-sends yourself.
870 /// May generate SendHTLCs message(s) event on success, which should be relayed.
872 /// Each path may have a different return value, and PaymentSendValue may return a Vec with
873 /// each entry matching the corresponding-index entry in the route paths, see
874 /// PaymentSendFailure for more info.
876 /// In general, a path may raise:
877 /// * APIError::RouteError when an invalid route or forwarding parameter (cltv_delta, fee,
878 /// node public key) is specified.
879 /// * APIError::ChannelUnavailable if the next-hop channel is not available for updates
880 /// (including due to previous monitor update failure or new permanent monitor update
882 /// * APIError::MonitorUpdateFailed if a new monitor update failure prevented sending the
883 /// relevant updates.
885 /// Note that depending on the type of the PaymentSendFailure the HTLC may have been
886 /// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
887 /// different route unless you intend to pay twice!
889 /// payment_secret is unrelated to payment_hash (or PaymentPreimage) and exists to authenticate
890 /// the sender to the recipient and prevent payment-probing (deanonymization) attacks. For
891 /// newer nodes, it will be provided to you in the invoice. If you do not have one, the Route
892 /// must not contain multiple paths as multi-path payments require a recipient-provided
894 /// If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature
895 /// bit set (either as required or as available). If multiple paths are present in the Route,
896 /// we assume the invoice had the basic_mpp feature set.
899 pub extern "C" fn ChannelManager_send_payment(this_arg: &ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut payment_secret: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_NonePaymentSendFailureZ {
900 let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentSecret(payment_secret.data) }) };
901 let mut ret = unsafe { &*this_arg.inner }.send_payment(unsafe { &*route.inner }, ::lightning::ln::PaymentHash(payment_hash.data), &local_payment_secret);
902 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::channelmanager::PaymentSendFailure::native_into(e) }).into() };
906 /// Call this upon creation of a funding transaction for the given channel.
908 /// Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
909 /// or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
911 /// Panics if a funding transaction has already been provided for this channel.
913 /// May panic if the output found in the funding transaction is duplicative with some other
914 /// channel (note that this should be trivially prevented by using unique funding transaction
915 /// keys per-channel).
917 /// Do NOT broadcast the funding transaction yourself. When we have safely received our
918 /// counterparty's signature the funding transaction will automatically be broadcast via the
919 /// [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
921 /// Note that this includes RBF or similar transaction replacement strategies - lightning does
922 /// not currently support replacing a funding transaction on an existing channel. Instead,
923 /// create a new channel with a conflicting funding transaction.
925 /// [`Event::FundingGenerationReady`]: crate::util::events::Event::FundingGenerationReady
928 pub extern "C" fn ChannelManager_funding_transaction_generated(this_arg: &ChannelManager, temporary_channel_id: *const [u8; 32], mut funding_transaction: crate::c_types::Transaction) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
929 let mut ret = unsafe { &*this_arg.inner }.funding_transaction_generated(unsafe { &*temporary_channel_id}, funding_transaction.into_bitcoin());
930 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
934 /// Regenerates channel_announcements and generates a signed node_announcement from the given
935 /// arguments, providing them in corresponding events via
936 /// [`get_and_clear_pending_msg_events`], if at least one public channel has been confirmed
937 /// on-chain. This effectively re-broadcasts all channel announcements and sends our node
938 /// announcement to ensure that the lightning P2P network is aware of the channels we have and
939 /// our network addresses.
941 /// `rgb` is a node \"color\" and `alias` is a printable human-readable string to describe this
942 /// node to humans. They carry no in-protocol meaning.
944 /// `addresses` represent the set (possibly empty) of socket addresses on which this node
945 /// accepts incoming connections. These will be included in the node_announcement, publicly
946 /// tying these addresses together and to this node. If you wish to preserve user privacy,
947 /// addresses should likely contain only Tor Onion addresses.
949 /// Panics if `addresses` is absurdly large (more than 500).
951 /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
953 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) {
954 let mut local_addresses = Vec::new(); for mut item in addresses.into_rust().drain(..) { local_addresses.push( { item.into_native() }); };
955 unsafe { &*this_arg.inner }.broadcast_node_announcement(rgb.data, alias.data, local_addresses)
958 /// Processes HTLCs which are pending waiting on random forward delay.
960 /// Should only really ever be called in response to a PendingHTLCsForwardable event.
961 /// Will likely generate further events.
963 pub extern "C" fn ChannelManager_process_pending_htlc_forwards(this_arg: &ChannelManager) {
964 unsafe { &*this_arg.inner }.process_pending_htlc_forwards()
967 /// If a peer is disconnected we mark any channels with that peer as 'disabled'.
968 /// After some time, if channels are still disabled we need to broadcast a ChannelUpdate
969 /// to inform the network about the uselessness of these channels.
971 /// This method handles all the details, and must be called roughly once per minute.
973 /// Note that in some rare cases this may generate a `chain::Watch::update_channel` call.
975 pub extern "C" fn ChannelManager_timer_tick_occurred(this_arg: &ChannelManager) {
976 unsafe { &*this_arg.inner }.timer_tick_occurred()
979 /// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
980 /// after a PaymentReceived event, failing the HTLC back to its origin and freeing resources
981 /// along the path (including in our own channel on which we received it).
982 /// Returns false if no payment was found to fail backwards, true if the process of failing the
983 /// HTLC backwards has been started.
986 pub extern "C" fn ChannelManager_fail_htlc_backwards(this_arg: &ChannelManager, payment_hash: *const [u8; 32]) -> bool {
987 let mut ret = unsafe { &*this_arg.inner }.fail_htlc_backwards(&::lightning::ln::PaymentHash(unsafe { *payment_hash }));
991 /// Provides a payment preimage in response to a PaymentReceived event, returning true and
992 /// generating message events for the net layer to claim the payment, if possible. Thus, you
993 /// should probably kick the net layer to go send messages if this returns true!
995 /// Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
996 /// [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentReceived`
997 /// event matches your expectation. If you fail to do so and call this method, you may provide
998 /// the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
1000 /// May panic if called except in response to a PaymentReceived event.
1002 /// [`create_inbound_payment`]: Self::create_inbound_payment
1003 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1006 pub extern "C" fn ChannelManager_claim_funds(this_arg: &ChannelManager, mut payment_preimage: crate::c_types::ThirtyTwoBytes) -> bool {
1007 let mut ret = unsafe { &*this_arg.inner }.claim_funds(::lightning::ln::PaymentPreimage(payment_preimage.data));
1011 /// Gets the node_id held by this ChannelManager
1014 pub extern "C" fn ChannelManager_get_our_node_id(this_arg: &ChannelManager) -> crate::c_types::PublicKey {
1015 let mut ret = unsafe { &*this_arg.inner }.get_our_node_id();
1016 crate::c_types::PublicKey::from_rust(&ret)
1019 /// Restores a single, given channel to normal operation after a
1020 /// ChannelMonitorUpdateErr::TemporaryFailure was returned from a channel monitor update
1023 /// All ChannelMonitor updates up to and including highest_applied_update_id must have been
1024 /// fully committed in every copy of the given channels' ChannelMonitors.
1026 /// Note that there is no effect to calling with a highest_applied_update_id other than the
1027 /// current latest ChannelMonitorUpdate and one call to this function after multiple
1028 /// ChannelMonitorUpdateErr::TemporaryFailures is fine. The highest_applied_update_id field
1029 /// exists largely only to prevent races between this and concurrent update_monitor calls.
1031 /// Thus, the anticipated use is, at a high level:
1032 /// 1) You register a chain::Watch with this ChannelManager,
1033 /// 2) it stores each update to disk, and begins updating any remote (eg watchtower) copies of
1034 /// said ChannelMonitors as it can, returning ChannelMonitorUpdateErr::TemporaryFailures
1035 /// any time it cannot do so instantly,
1036 /// 3) update(s) are applied to each remote copy of a ChannelMonitor,
1037 /// 4) once all remote copies are updated, you call this function with the update_id that
1038 /// completed, and once it is the latest the Channel will be re-enabled.
1040 pub extern "C" fn ChannelManager_channel_monitor_updated(this_arg: &ChannelManager, funding_txo: &crate::lightning::chain::transaction::OutPoint, mut highest_applied_update_id: u64) {
1041 unsafe { &*this_arg.inner }.channel_monitor_updated(unsafe { &*funding_txo.inner }, highest_applied_update_id)
1044 /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
1047 /// This differs from [`create_inbound_payment_for_hash`] only in that it generates the
1048 /// [`PaymentHash`] and [`PaymentPreimage`] for you, returning the first and storing the second.
1050 /// The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentReceived`], which
1051 /// will have the [`PaymentReceived::payment_preimage`] field filled in. That should then be
1052 /// passed directly to [`claim_funds`].
1054 /// See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
1056 /// [`claim_funds`]: Self::claim_funds
1057 /// [`PaymentReceived`]: events::Event::PaymentReceived
1058 /// [`PaymentReceived::payment_preimage`]: events::Event::PaymentReceived::payment_preimage
1059 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1062 pub extern "C" fn ChannelManager_create_inbound_payment(this_arg: &ChannelManager, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32, mut user_payment_id: u64) -> crate::c_types::derived::C2Tuple_PaymentHashPaymentSecretZ {
1063 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
1064 let mut ret = unsafe { &*this_arg.inner }.create_inbound_payment(local_min_value_msat, invoice_expiry_delta_secs, user_payment_id);
1065 let (mut orig_ret_0, mut orig_ret_1) = ret; let mut local_ret = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0.0 }, crate::c_types::ThirtyTwoBytes { data: orig_ret_1.0 }).into();
1069 /// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
1070 /// stored external to LDK.
1072 /// A [`PaymentReceived`] event will only be generated if the [`PaymentSecret`] matches a
1073 /// payment secret fetched via this method or [`create_inbound_payment`], and which is at least
1074 /// the `min_value_msat` provided here, if one is provided.
1076 /// The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) must be globally unique. This
1077 /// method may return an Err if another payment with the same payment_hash is still pending.
1079 /// `user_payment_id` will be provided back in [`PaymentReceived::user_payment_id`] events to
1080 /// allow tracking of which events correspond with which calls to this and
1081 /// [`create_inbound_payment`]. `user_payment_id` has no meaning inside of LDK, it is simply
1082 /// copied to events and otherwise ignored. It may be used to correlate PaymentReceived events
1083 /// with invoice metadata stored elsewhere.
1085 /// `min_value_msat` should be set if the invoice being generated contains a value. Any payment
1086 /// received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
1087 /// before a [`PaymentReceived`] event will be generated, ensuring that we do not provide the
1088 /// sender \"proof-of-payment\" unless they have paid the required amount.
1090 /// `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
1091 /// in excess of the current time. This should roughly match the expiry time set in the invoice.
1092 /// After this many seconds, we will remove the inbound payment, resulting in any attempts to
1093 /// pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
1094 /// invoices when no timeout is set.
1096 /// Note that we use block header time to time-out pending inbound payments (with some margin
1097 /// to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
1098 /// accept a payment and generate a [`PaymentReceived`] event for some time after the expiry.
1099 /// If you need exact expiry semantics, you should enforce them upon receipt of
1100 /// [`PaymentReceived`].
1102 /// Pending inbound payments are stored in memory and in serialized versions of this
1103 /// [`ChannelManager`]. If potentially unbounded numbers of inbound payments may exist and
1104 /// space is limited, you may wish to rate-limit inbound payment creation.
1106 /// May panic if `invoice_expiry_delta_secs` is greater than one year.
1108 /// Note that invoices generated for inbound payments should have their `min_final_cltv_expiry`
1109 /// set to at least [`MIN_FINAL_CLTV_EXPIRY`].
1111 /// [`create_inbound_payment`]: Self::create_inbound_payment
1112 /// [`PaymentReceived`]: events::Event::PaymentReceived
1113 /// [`PaymentReceived::user_payment_id`]: events::Event::PaymentReceived::user_payment_id
1116 pub extern "C" fn ChannelManager_create_inbound_payment_for_hash(this_arg: &ChannelManager, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32, mut user_payment_id: u64) -> crate::c_types::derived::CResult_PaymentSecretAPIErrorZ {
1117 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
1118 let mut ret = unsafe { &*this_arg.inner }.create_inbound_payment_for_hash(::lightning::ln::PaymentHash(payment_hash.data), local_min_value_msat, invoice_expiry_delta_secs, user_payment_id);
1119 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ThirtyTwoBytes { data: o.0 } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
1123 impl From<nativeChannelManager> for crate::lightning::util::events::MessageSendEventsProvider {
1124 fn from(obj: nativeChannelManager) -> Self {
1125 let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true };
1126 let mut ret = ChannelManager_as_MessageSendEventsProvider(&rust_obj);
1127 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
1128 rust_obj.inner = std::ptr::null_mut();
1129 ret.free = Some(ChannelManager_free_void);
1133 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
1134 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
1136 pub extern "C" fn ChannelManager_as_MessageSendEventsProvider(this_arg: &ChannelManager) -> crate::lightning::util::events::MessageSendEventsProvider {
1137 crate::lightning::util::events::MessageSendEventsProvider {
1138 this_arg: unsafe { (*this_arg).inner as *mut c_void },
1140 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
1145 extern "C" fn ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
1146 let mut ret = <nativeChannelManager as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
1147 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
1151 impl From<nativeChannelManager> for crate::lightning::util::events::EventsProvider {
1152 fn from(obj: nativeChannelManager) -> Self {
1153 let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true };
1154 let mut ret = ChannelManager_as_EventsProvider(&rust_obj);
1155 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
1156 rust_obj.inner = std::ptr::null_mut();
1157 ret.free = Some(ChannelManager_free_void);
1161 /// Constructs a new EventsProvider which calls the relevant methods on this_arg.
1162 /// This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
1164 pub extern "C" fn ChannelManager_as_EventsProvider(this_arg: &ChannelManager) -> crate::lightning::util::events::EventsProvider {
1165 crate::lightning::util::events::EventsProvider {
1166 this_arg: unsafe { (*this_arg).inner as *mut c_void },
1168 process_pending_events: ChannelManager_EventsProvider_process_pending_events,
1172 extern "C" fn ChannelManager_EventsProvider_process_pending_events(this_arg: *const c_void, mut handler: crate::lightning::util::events::EventHandler) {
1173 <nativeChannelManager as lightning::util::events::EventsProvider<>>::process_pending_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, handler)
1176 impl From<nativeChannelManager> for crate::lightning::chain::Listen {
1177 fn from(obj: nativeChannelManager) -> Self {
1178 let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true };
1179 let mut ret = ChannelManager_as_Listen(&rust_obj);
1180 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
1181 rust_obj.inner = std::ptr::null_mut();
1182 ret.free = Some(ChannelManager_free_void);
1186 /// Constructs a new Listen which calls the relevant methods on this_arg.
1187 /// This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
1189 pub extern "C" fn ChannelManager_as_Listen(this_arg: &ChannelManager) -> crate::lightning::chain::Listen {
1190 crate::lightning::chain::Listen {
1191 this_arg: unsafe { (*this_arg).inner as *mut c_void },
1193 block_connected: ChannelManager_Listen_block_connected,
1194 block_disconnected: ChannelManager_Listen_block_disconnected,
1198 extern "C" fn ChannelManager_Listen_block_connected(this_arg: *const c_void, mut block: crate::c_types::u8slice, mut height: u32) {
1199 <nativeChannelManager as lightning::chain::Listen<>>::block_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height)
1201 extern "C" fn ChannelManager_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
1202 <nativeChannelManager as lightning::chain::Listen<>>::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
1205 impl From<nativeChannelManager> for crate::lightning::chain::Confirm {
1206 fn from(obj: nativeChannelManager) -> Self {
1207 let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true };
1208 let mut ret = ChannelManager_as_Confirm(&rust_obj);
1209 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
1210 rust_obj.inner = std::ptr::null_mut();
1211 ret.free = Some(ChannelManager_free_void);
1215 /// Constructs a new Confirm which calls the relevant methods on this_arg.
1216 /// This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
1218 pub extern "C" fn ChannelManager_as_Confirm(this_arg: &ChannelManager) -> crate::lightning::chain::Confirm {
1219 crate::lightning::chain::Confirm {
1220 this_arg: unsafe { (*this_arg).inner as *mut c_void },
1222 transactions_confirmed: ChannelManager_Confirm_transactions_confirmed,
1223 transaction_unconfirmed: ChannelManager_Confirm_transaction_unconfirmed,
1224 best_block_updated: ChannelManager_Confirm_best_block_updated,
1225 get_relevant_txids: ChannelManager_Confirm_get_relevant_txids,
1229 extern "C" fn ChannelManager_Confirm_transactions_confirmed(this_arg: *const c_void, header: *const [u8; 80], mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, mut height: u32) {
1230 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 }); };
1231 <nativeChannelManager as lightning::chain::Confirm<>>::transactions_confirmed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), &local_txdata.iter().map(|(a, b)| (*a, b)).collect::<Vec<_>>()[..], height)
1233 extern "C" fn ChannelManager_Confirm_best_block_updated(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
1234 <nativeChannelManager as lightning::chain::Confirm<>>::best_block_updated(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
1237 extern "C" fn ChannelManager_Confirm_get_relevant_txids(this_arg: *const c_void) -> crate::c_types::derived::CVec_TxidZ {
1238 let mut ret = <nativeChannelManager as lightning::chain::Confirm<>>::get_relevant_txids(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
1239 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::ThirtyTwoBytes { data: item.into_inner() } }); };
1242 extern "C" fn ChannelManager_Confirm_transaction_unconfirmed(this_arg: *const c_void, txid: *const [u8; 32]) {
1243 <nativeChannelManager as lightning::chain::Confirm<>>::transaction_unconfirmed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap())
1246 /// Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
1247 /// indicating whether persistence is necessary. Only one listener on
1248 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
1250 /// Note that the feature `allow_wallclock_use` must be enabled to use this function.
1253 pub extern "C" fn ChannelManager_await_persistable_update_timeout(this_arg: &ChannelManager, mut max_wait: u64) -> bool {
1254 let mut ret = unsafe { &*this_arg.inner }.await_persistable_update_timeout(std::time::Duration::from_secs(max_wait));
1258 /// Blocks until ChannelManager needs to be persisted. Only one listener on
1259 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
1262 pub extern "C" fn ChannelManager_await_persistable_update(this_arg: &ChannelManager) {
1263 unsafe { &*this_arg.inner }.await_persistable_update()
1266 impl From<nativeChannelManager> for crate::lightning::ln::msgs::ChannelMessageHandler {
1267 fn from(obj: nativeChannelManager) -> Self {
1268 let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true };
1269 let mut ret = ChannelManager_as_ChannelMessageHandler(&rust_obj);
1270 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
1271 rust_obj.inner = std::ptr::null_mut();
1272 ret.free = Some(ChannelManager_free_void);
1276 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
1277 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
1279 pub extern "C" fn ChannelManager_as_ChannelMessageHandler(this_arg: &ChannelManager) -> crate::lightning::ln::msgs::ChannelMessageHandler {
1280 crate::lightning::ln::msgs::ChannelMessageHandler {
1281 this_arg: unsafe { (*this_arg).inner as *mut c_void },
1283 handle_open_channel: ChannelManager_ChannelMessageHandler_handle_open_channel,
1284 handle_accept_channel: ChannelManager_ChannelMessageHandler_handle_accept_channel,
1285 handle_funding_created: ChannelManager_ChannelMessageHandler_handle_funding_created,
1286 handle_funding_signed: ChannelManager_ChannelMessageHandler_handle_funding_signed,
1287 handle_funding_locked: ChannelManager_ChannelMessageHandler_handle_funding_locked,
1288 handle_shutdown: ChannelManager_ChannelMessageHandler_handle_shutdown,
1289 handle_closing_signed: ChannelManager_ChannelMessageHandler_handle_closing_signed,
1290 handle_update_add_htlc: ChannelManager_ChannelMessageHandler_handle_update_add_htlc,
1291 handle_update_fulfill_htlc: ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc,
1292 handle_update_fail_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_htlc,
1293 handle_update_fail_malformed_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_malformed_htlc,
1294 handle_commitment_signed: ChannelManager_ChannelMessageHandler_handle_commitment_signed,
1295 handle_revoke_and_ack: ChannelManager_ChannelMessageHandler_handle_revoke_and_ack,
1296 handle_update_fee: ChannelManager_ChannelMessageHandler_handle_update_fee,
1297 handle_announcement_signatures: ChannelManager_ChannelMessageHandler_handle_announcement_signatures,
1298 peer_disconnected: ChannelManager_ChannelMessageHandler_peer_disconnected,
1299 peer_connected: ChannelManager_ChannelMessageHandler_peer_connected,
1300 handle_channel_reestablish: ChannelManager_ChannelMessageHandler_handle_channel_reestablish,
1301 handle_channel_update: ChannelManager_ChannelMessageHandler_handle_channel_update,
1302 handle_error: ChannelManager_ChannelMessageHandler_handle_error,
1303 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
1304 this_arg: unsafe { (*this_arg).inner as *mut c_void },
1306 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
1311 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::lightning::ln::features::InitFeatures, msg: &crate::lightning::ln::msgs::OpenChannel) {
1312 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_open_channel(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), *unsafe { Box::from_raw(their_features.take_inner()) }, unsafe { &*msg.inner })
1314 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::lightning::ln::features::InitFeatures, msg: &crate::lightning::ln::msgs::AcceptChannel) {
1315 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_accept_channel(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), *unsafe { Box::from_raw(their_features.take_inner()) }, unsafe { &*msg.inner })
1317 extern "C" fn ChannelManager_ChannelMessageHandler_handle_funding_created(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::FundingCreated) {
1318 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_created(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1320 extern "C" fn ChannelManager_ChannelMessageHandler_handle_funding_signed(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::FundingSigned) {
1321 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1323 extern "C" fn ChannelManager_ChannelMessageHandler_handle_funding_locked(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::FundingLocked) {
1324 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_locked(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1326 extern "C" fn ChannelManager_ChannelMessageHandler_handle_shutdown(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, their_features: &crate::lightning::ln::features::InitFeatures, msg: &crate::lightning::ln::msgs::Shutdown) {
1327 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_shutdown(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*their_features.inner }, unsafe { &*msg.inner })
1329 extern "C" fn ChannelManager_ChannelMessageHandler_handle_closing_signed(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ClosingSigned) {
1330 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_closing_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1332 extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_add_htlc(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateAddHTLC) {
1333 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_add_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1335 extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateFulfillHTLC) {
1336 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fulfill_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1338 extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_fail_htlc(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateFailHTLC) {
1339 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fail_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1341 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::lightning::ln::msgs::UpdateFailMalformedHTLC) {
1342 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fail_malformed_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1344 extern "C" fn ChannelManager_ChannelMessageHandler_handle_commitment_signed(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::CommitmentSigned) {
1345 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_commitment_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1347 extern "C" fn ChannelManager_ChannelMessageHandler_handle_revoke_and_ack(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::RevokeAndACK) {
1348 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_revoke_and_ack(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1350 extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_fee(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateFee) {
1351 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fee(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1353 extern "C" fn ChannelManager_ChannelMessageHandler_handle_announcement_signatures(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::AnnouncementSignatures) {
1354 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_announcement_signatures(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1356 extern "C" fn ChannelManager_ChannelMessageHandler_handle_channel_update(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ChannelUpdate) {
1357 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1359 extern "C" fn ChannelManager_ChannelMessageHandler_handle_channel_reestablish(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ChannelReestablish) {
1360 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_channel_reestablish(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1362 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) {
1363 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), no_connection_possible)
1365 extern "C" fn ChannelManager_ChannelMessageHandler_peer_connected(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, init_msg: &crate::lightning::ln::msgs::Init) {
1366 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::peer_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*init_msg.inner })
1368 extern "C" fn ChannelManager_ChannelMessageHandler_handle_error(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ErrorMessage) {
1369 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner })
1373 /// Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
1374 pub extern "C" fn ChannelManager_write(obj: &ChannelManager) -> crate::c_types::derived::CVec_u8Z {
1375 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1378 pub(crate) extern "C" fn ChannelManager_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1379 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelManager) })
1382 use lightning::ln::channelmanager::ChannelManagerReadArgs as nativeChannelManagerReadArgsImport;
1383 type nativeChannelManagerReadArgs = nativeChannelManagerReadArgsImport<'static, crate::lightning::chain::keysinterface::Sign, crate::lightning::chain::Watch, crate::lightning::chain::chaininterface::BroadcasterInterface, crate::lightning::chain::keysinterface::KeysInterface, crate::lightning::chain::chaininterface::FeeEstimator, crate::lightning::util::logger::Logger>;
1385 /// Arguments for the creation of a ChannelManager that are not deserialized.
1387 /// At a high-level, the process for deserializing a ChannelManager and resuming normal operation
1389 /// 1) Deserialize all stored ChannelMonitors.
1390 /// 2) Deserialize the ChannelManager by filling in this struct and calling:
1391 /// <(BlockHash, ChannelManager)>::read(reader, args)
1392 /// This may result in closing some Channels if the ChannelMonitor is newer than the stored
1393 /// ChannelManager state to ensure no loss of funds. Thus, transactions may be broadcasted.
1394 /// 3) If you are not fetching full blocks, register all relevant ChannelMonitor outpoints the same
1395 /// way you would handle a `chain::Filter` call using ChannelMonitor::get_outputs_to_watch() and
1396 /// ChannelMonitor::get_funding_txo().
1397 /// 4) Reconnect blocks on your ChannelMonitors.
1398 /// 5) Disconnect/connect blocks on the ChannelManager.
1399 /// 6) Move the ChannelMonitors into your local chain::Watch.
1401 /// Note that the ordering of #4-6 is not of importance, however all three must occur before you
1402 /// call any other methods on the newly-deserialized ChannelManager.
1404 /// Note that because some channels may be closed during deserialization, it is critical that you
1405 /// always deserialize only the latest version of a ChannelManager and ChannelMonitors available to
1406 /// you. If you deserialize an old ChannelManager (during which force-closure transactions may be
1407 /// broadcast), and then later deserialize a newer version of the same ChannelManager (which will
1408 /// not force-close the same channels but consider them live), you may end up revoking a state for
1409 /// which you've already broadcasted the transaction.
1412 pub struct ChannelManagerReadArgs {
1413 /// A pointer to the opaque Rust object.
1415 /// Nearly everywhere, inner must be non-null, however in places where
1416 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1417 pub inner: *mut nativeChannelManagerReadArgs,
1418 /// Indicates that this is the only struct which contains the same pointer.
1420 /// Rust functions which take ownership of an object provided via an argument require
1421 /// this to be true and invalidate the object pointed to by inner.
1425 impl Drop for ChannelManagerReadArgs {
1426 fn drop(&mut self) {
1427 if self.is_owned && !<*mut nativeChannelManagerReadArgs>::is_null(self.inner) {
1428 let _ = unsafe { Box::from_raw(self.inner) };
1432 /// Frees any resources used by the ChannelManagerReadArgs, if is_owned is set and inner is non-NULL.
1434 pub extern "C" fn ChannelManagerReadArgs_free(this_obj: ChannelManagerReadArgs) { }
1436 /// Used only if an object of this type is returned as a trait impl by a method
1437 extern "C" fn ChannelManagerReadArgs_free_void(this_ptr: *mut c_void) {
1438 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManagerReadArgs); }
1441 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1442 impl ChannelManagerReadArgs {
1443 pub(crate) fn take_inner(mut self) -> *mut nativeChannelManagerReadArgs {
1444 assert!(self.is_owned);
1445 let ret = self.inner;
1446 self.inner = std::ptr::null_mut();
1450 /// The keys provider which will give us relevant keys. Some keys will be loaded during
1451 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
1454 pub extern "C" fn ChannelManagerReadArgs_get_keys_manager(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::keysinterface::KeysInterface {
1455 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.keys_manager;
1458 /// The keys provider which will give us relevant keys. Some keys will be loaded during
1459 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
1462 pub extern "C" fn ChannelManagerReadArgs_set_keys_manager(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::keysinterface::KeysInterface) {
1463 unsafe { &mut *this_ptr.inner }.keys_manager = val;
1465 /// The fee_estimator for use in the ChannelManager in the future.
1467 /// No calls to the FeeEstimator will be made during deserialization.
1469 pub extern "C" fn ChannelManagerReadArgs_get_fee_estimator(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::FeeEstimator {
1470 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fee_estimator;
1473 /// The fee_estimator for use in the ChannelManager in the future.
1475 /// No calls to the FeeEstimator will be made during deserialization.
1477 pub extern "C" fn ChannelManagerReadArgs_set_fee_estimator(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::FeeEstimator) {
1478 unsafe { &mut *this_ptr.inner }.fee_estimator = val;
1480 /// The chain::Watch for use in the ChannelManager in the future.
1482 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
1483 /// you have deserialized ChannelMonitors separately and will add them to your
1484 /// chain::Watch after deserializing this ChannelManager.
1486 pub extern "C" fn ChannelManagerReadArgs_get_chain_monitor(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::Watch {
1487 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.chain_monitor;
1490 /// The chain::Watch for use in the ChannelManager in the future.
1492 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
1493 /// you have deserialized ChannelMonitors separately and will add them to your
1494 /// chain::Watch after deserializing this ChannelManager.
1496 pub extern "C" fn ChannelManagerReadArgs_set_chain_monitor(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::Watch) {
1497 unsafe { &mut *this_ptr.inner }.chain_monitor = val;
1499 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
1500 /// used to broadcast the latest local commitment transactions of channels which must be
1501 /// force-closed during deserialization.
1503 pub extern "C" fn ChannelManagerReadArgs_get_tx_broadcaster(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::BroadcasterInterface {
1504 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.tx_broadcaster;
1507 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
1508 /// used to broadcast the latest local commitment transactions of channels which must be
1509 /// force-closed during deserialization.
1511 pub extern "C" fn ChannelManagerReadArgs_set_tx_broadcaster(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::BroadcasterInterface) {
1512 unsafe { &mut *this_ptr.inner }.tx_broadcaster = val;
1514 /// The Logger for use in the ChannelManager and which may be used to log information during
1515 /// deserialization.
1517 pub extern "C" fn ChannelManagerReadArgs_get_logger(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::util::logger::Logger {
1518 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.logger;
1521 /// The Logger for use in the ChannelManager and which may be used to log information during
1522 /// deserialization.
1524 pub extern "C" fn ChannelManagerReadArgs_set_logger(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::logger::Logger) {
1525 unsafe { &mut *this_ptr.inner }.logger = val;
1527 /// Default settings used for new channels. Any existing channels will continue to use the
1528 /// runtime settings which were stored when the ChannelManager was serialized.
1530 pub extern "C" fn ChannelManagerReadArgs_get_default_config(this_ptr: &ChannelManagerReadArgs) -> crate::lightning::util::config::UserConfig {
1531 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.default_config;
1532 crate::lightning::util::config::UserConfig { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
1534 /// Default settings used for new channels. Any existing channels will continue to use the
1535 /// runtime settings which were stored when the ChannelManager was serialized.
1537 pub extern "C" fn ChannelManagerReadArgs_set_default_config(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::config::UserConfig) {
1538 unsafe { &mut *this_ptr.inner }.default_config = *unsafe { Box::from_raw(val.take_inner()) };
1540 /// Simple utility function to create a ChannelManagerReadArgs which creates the monitor
1541 /// HashMap for you. This is primarily useful for C bindings where it is not practical to
1542 /// populate a HashMap directly from C.
1545 pub extern "C" fn ChannelManagerReadArgs_new(mut keys_manager: crate::lightning::chain::keysinterface::KeysInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, mut chain_monitor: crate::lightning::chain::Watch, mut tx_broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut logger: crate::lightning::util::logger::Logger, mut default_config: crate::lightning::util::config::UserConfig, mut channel_monitors: crate::c_types::derived::CVec_ChannelMonitorZ) -> ChannelManagerReadArgs {
1546 let mut local_channel_monitors = Vec::new(); for mut item in channel_monitors.into_rust().drain(..) { local_channel_monitors.push( { unsafe { &mut *item.inner } }); };
1547 let mut ret = lightning::ln::channelmanager::ChannelManagerReadArgs::new(keys_manager, fee_estimator, chain_monitor, tx_broadcaster, logger, *unsafe { Box::from_raw(default_config.take_inner()) }, local_channel_monitors);
1548 ChannelManagerReadArgs { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1552 /// Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_write
1553 pub extern "C" fn C2Tuple_BlockHashChannelManagerZ_read(ser: crate::c_types::u8slice, arg: crate::lightning::ln::channelmanager::ChannelManagerReadArgs) -> crate::c_types::derived::CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ {
1554 let arg_conv = *unsafe { Box::from_raw(arg.take_inner()) };
1555 let res: Result<(bitcoin::hash_types::BlockHash, lightning::ln::channelmanager::ChannelManager<crate::lightning::chain::keysinterface::Sign, crate::lightning::chain::Watch, crate::lightning::chain::chaininterface::BroadcasterInterface, crate::lightning::chain::keysinterface::KeysInterface, crate::lightning::chain::chaininterface::FeeEstimator, crate::lightning::util::logger::Logger>), lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
1556 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_res_0_0, mut orig_res_0_1) = o; let mut local_res_0 = (crate::c_types::ThirtyTwoBytes { data: orig_res_0_0.into_inner() }, crate::lightning::ln::channelmanager::ChannelManager { inner: Box::into_raw(Box::new(orig_res_0_1)), is_owned: true }).into(); local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };