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 [`find_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).
19 //! [`find_route`]: crate::routing::router::find_route
21 use alloc::str::FromStr;
22 use core::ffi::c_void;
23 use core::convert::Infallible;
24 use bitcoin::hashes::Hash;
25 use crate::c_types::*;
26 #[cfg(feature="no-std")]
27 use alloc::{vec::Vec, boxed::Box};
30 use lightning::ln::channelmanager::ChannelManager as nativeChannelManagerImport;
31 pub(crate) 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>;
33 /// Manager which keeps track of a number of channels and sends messages to the appropriate
34 /// channel, also tracking HTLC preimages and forwarding onion packets appropriately.
36 /// Implements ChannelMessageHandler, handling the multi-channel parts and passing things through
37 /// to individual Channels.
39 /// Implements Writeable to write out all channel state to disk. Implies peer_disconnected() for
40 /// all peers during write/read (though does not modify this instance, only the instance being
41 /// serialized). This will result in any channels which have not yet exchanged funding_created (ie
42 /// called funding_transaction_generated for outbound channels).
44 /// Note that you can be a bit lazier about writing out ChannelManager than you can be with
45 /// ChannelMonitors. With ChannelMonitors you MUST write each monitor update out to disk before
46 /// returning from chain::Watch::watch_/update_channel, with ChannelManagers, writing updates
47 /// happens out-of-band (and will prevent any other ChannelManager operations from occurring during
48 /// the serialization process). If the deserialized version is out-of-date compared to the
49 /// ChannelMonitors passed by reference to read(), those channels will be force-closed based on the
50 /// ChannelMonitor state and no funds will be lost (mod on-chain transaction fees).
52 /// Note that the deserializer is only implemented for (BlockHash, ChannelManager), which
53 /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
54 /// the \"reorg path\" (ie call block_disconnected() until you get to a common block and then call
55 /// block_connected() to step towards your best block) upon deserialization before using the
58 /// Note that ChannelManager is responsible for tracking liveness of its channels and generating
59 /// ChannelUpdate messages informing peers that the channel is temporarily disabled. To avoid
60 /// spam due to quick disconnection/reconnection, updates are not sent until the channel has been
61 /// offline for a full minute. In order to track this, you must call
62 /// timer_tick_occurred roughly once per minute, though it doesn't have to be perfect.
64 /// Rather than using a plain ChannelManager, it is preferable to use either a SimpleArcChannelManager
65 /// a SimpleRefChannelManager, for conciseness. See their documentation for more details, but
66 /// essentially you should default to using a SimpleRefChannelManager, and use a
67 /// SimpleArcChannelManager when you require a ChannelManager with a static lifetime, such as when
68 /// you're using lightning-net-tokio.
71 pub struct ChannelManager {
72 /// A pointer to the opaque Rust object.
74 /// Nearly everywhere, inner must be non-null, however in places where
75 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
76 pub inner: *mut nativeChannelManager,
77 /// Indicates that this is the only struct which contains the same pointer.
79 /// Rust functions which take ownership of an object provided via an argument require
80 /// this to be true and invalidate the object pointed to by inner.
84 impl Drop for ChannelManager {
86 if self.is_owned && !<*mut nativeChannelManager>::is_null(self.inner) {
87 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
91 /// Frees any resources used by the ChannelManager, if is_owned is set and inner is non-NULL.
93 pub extern "C" fn ChannelManager_free(this_obj: ChannelManager) { }
95 /// Used only if an object of this type is returned as a trait impl by a method
96 pub(crate) extern "C" fn ChannelManager_free_void(this_ptr: *mut c_void) {
97 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManager); }
100 impl ChannelManager {
101 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManager {
102 unsafe { &*ObjOps::untweak_ptr(self.inner) }
104 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManager {
105 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
107 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
108 pub(crate) fn take_inner(mut self) -> *mut nativeChannelManager {
109 assert!(self.is_owned);
110 let ret = ObjOps::untweak_ptr(self.inner);
111 self.inner = core::ptr::null_mut();
116 use lightning::ln::channelmanager::ChainParameters as nativeChainParametersImport;
117 pub(crate) type nativeChainParameters = nativeChainParametersImport;
119 /// Chain-related parameters used to construct a new `ChannelManager`.
121 /// Typically, the block-specific parameters are derived from the best block hash for the network,
122 /// as a newly constructed `ChannelManager` will not have created any channels yet. These parameters
123 /// are not needed when deserializing a previously constructed `ChannelManager`.
126 pub struct ChainParameters {
127 /// A pointer to the opaque Rust object.
129 /// Nearly everywhere, inner must be non-null, however in places where
130 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
131 pub inner: *mut nativeChainParameters,
132 /// Indicates that this is the only struct which contains the same pointer.
134 /// Rust functions which take ownership of an object provided via an argument require
135 /// this to be true and invalidate the object pointed to by inner.
139 impl Drop for ChainParameters {
141 if self.is_owned && !<*mut nativeChainParameters>::is_null(self.inner) {
142 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
146 /// Frees any resources used by the ChainParameters, if is_owned is set and inner is non-NULL.
148 pub extern "C" fn ChainParameters_free(this_obj: ChainParameters) { }
150 /// Used only if an object of this type is returned as a trait impl by a method
151 pub(crate) extern "C" fn ChainParameters_free_void(this_ptr: *mut c_void) {
152 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChainParameters); }
155 impl ChainParameters {
156 pub(crate) fn get_native_ref(&self) -> &'static nativeChainParameters {
157 unsafe { &*ObjOps::untweak_ptr(self.inner) }
159 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChainParameters {
160 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
162 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
163 pub(crate) fn take_inner(mut self) -> *mut nativeChainParameters {
164 assert!(self.is_owned);
165 let ret = ObjOps::untweak_ptr(self.inner);
166 self.inner = core::ptr::null_mut();
170 /// The network for determining the `chain_hash` in Lightning messages.
172 pub extern "C" fn ChainParameters_get_network(this_ptr: &ChainParameters) -> crate::bitcoin::network::Network {
173 let mut inner_val = &mut this_ptr.get_native_mut_ref().network;
174 crate::bitcoin::network::Network::from_bitcoin(inner_val)
176 /// The network for determining the `chain_hash` in Lightning messages.
178 pub extern "C" fn ChainParameters_set_network(this_ptr: &mut ChainParameters, mut val: crate::bitcoin::network::Network) {
179 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.network = val.into_bitcoin();
181 /// The hash and height of the latest block successfully connected.
183 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
185 pub extern "C" fn ChainParameters_get_best_block(this_ptr: &ChainParameters) -> crate::lightning::chain::BestBlock {
186 let mut inner_val = &mut this_ptr.get_native_mut_ref().best_block;
187 crate::lightning::chain::BestBlock { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::chain::BestBlock<>) as *mut _) }, is_owned: false }
189 /// The hash and height of the latest block successfully connected.
191 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
193 pub extern "C" fn ChainParameters_set_best_block(this_ptr: &mut ChainParameters, mut val: crate::lightning::chain::BestBlock) {
194 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.best_block = *unsafe { Box::from_raw(val.take_inner()) };
196 /// Constructs a new ChainParameters given each field
199 pub extern "C" fn ChainParameters_new(mut network_arg: crate::bitcoin::network::Network, mut best_block_arg: crate::lightning::chain::BestBlock) -> ChainParameters {
200 ChainParameters { inner: ObjOps::heap_alloc(nativeChainParameters {
201 network: network_arg.into_bitcoin(),
202 best_block: *unsafe { Box::from_raw(best_block_arg.take_inner()) },
205 impl Clone for ChainParameters {
206 fn clone(&self) -> Self {
208 inner: if <*mut nativeChainParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
209 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
215 /// Used only if an object of this type is returned as a trait impl by a method
216 pub(crate) extern "C" fn ChainParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
217 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChainParameters)).clone() })) as *mut c_void
220 /// Creates a copy of the ChainParameters
221 pub extern "C" fn ChainParameters_clone(orig: &ChainParameters) -> ChainParameters {
224 /// The amount of time in blocks we require our counterparty wait to claim their money (ie time
225 /// between when we, or our watchtower, must check for them having broadcast a theft transaction).
227 /// This can be increased (but not decreased) through [`ChannelHandshakeConfig::our_to_self_delay`]
229 /// [`ChannelHandshakeConfig::our_to_self_delay`]: crate::util::config::ChannelHandshakeConfig::our_to_self_delay
232 pub static BREAKDOWN_TIMEOUT: u16 = lightning::ln::channelmanager::BREAKDOWN_TIMEOUT;
233 /// The minimum number of blocks between an inbound HTLC's CLTV and the corresponding outbound
234 /// HTLC's CLTV. The current default represents roughly seven hours of blocks at six blocks/hour.
236 /// This can be increased (but not decreased) through [`ChannelConfig::cltv_expiry_delta`]
238 /// [`ChannelConfig::cltv_expiry_delta`]: crate::util::config::ChannelConfig::cltv_expiry_delta
241 pub static MIN_CLTV_EXPIRY_DELTA: u16 = lightning::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA;
242 /// Minimum CLTV difference between the current block height and received inbound payments.
243 /// Invoices generated for payment to us must set their `min_final_cltv_expiry` field to at least
247 pub static MIN_FINAL_CLTV_EXPIRY: u32 = lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY;
249 use lightning::ln::channelmanager::CounterpartyForwardingInfo as nativeCounterpartyForwardingInfoImport;
250 pub(crate) type nativeCounterpartyForwardingInfo = nativeCounterpartyForwardingInfoImport;
252 /// Information needed for constructing an invoice route hint for this channel.
255 pub struct CounterpartyForwardingInfo {
256 /// A pointer to the opaque Rust object.
258 /// Nearly everywhere, inner must be non-null, however in places where
259 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
260 pub inner: *mut nativeCounterpartyForwardingInfo,
261 /// Indicates that this is the only struct which contains the same pointer.
263 /// Rust functions which take ownership of an object provided via an argument require
264 /// this to be true and invalidate the object pointed to by inner.
268 impl Drop for CounterpartyForwardingInfo {
270 if self.is_owned && !<*mut nativeCounterpartyForwardingInfo>::is_null(self.inner) {
271 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
275 /// Frees any resources used by the CounterpartyForwardingInfo, if is_owned is set and inner is non-NULL.
277 pub extern "C" fn CounterpartyForwardingInfo_free(this_obj: CounterpartyForwardingInfo) { }
279 /// Used only if an object of this type is returned as a trait impl by a method
280 pub(crate) extern "C" fn CounterpartyForwardingInfo_free_void(this_ptr: *mut c_void) {
281 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCounterpartyForwardingInfo); }
284 impl CounterpartyForwardingInfo {
285 pub(crate) fn get_native_ref(&self) -> &'static nativeCounterpartyForwardingInfo {
286 unsafe { &*ObjOps::untweak_ptr(self.inner) }
288 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCounterpartyForwardingInfo {
289 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
291 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
292 pub(crate) fn take_inner(mut self) -> *mut nativeCounterpartyForwardingInfo {
293 assert!(self.is_owned);
294 let ret = ObjOps::untweak_ptr(self.inner);
295 self.inner = core::ptr::null_mut();
299 /// Base routing fee in millisatoshis.
301 pub extern "C" fn CounterpartyForwardingInfo_get_fee_base_msat(this_ptr: &CounterpartyForwardingInfo) -> u32 {
302 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_base_msat;
305 /// Base routing fee in millisatoshis.
307 pub extern "C" fn CounterpartyForwardingInfo_set_fee_base_msat(this_ptr: &mut CounterpartyForwardingInfo, mut val: u32) {
308 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_base_msat = val;
310 /// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
312 pub extern "C" fn CounterpartyForwardingInfo_get_fee_proportional_millionths(this_ptr: &CounterpartyForwardingInfo) -> u32 {
313 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_proportional_millionths;
316 /// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
318 pub extern "C" fn CounterpartyForwardingInfo_set_fee_proportional_millionths(this_ptr: &mut CounterpartyForwardingInfo, mut val: u32) {
319 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_proportional_millionths = val;
321 /// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
322 /// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
323 /// `cltv_expiry_delta` for more details.
325 pub extern "C" fn CounterpartyForwardingInfo_get_cltv_expiry_delta(this_ptr: &CounterpartyForwardingInfo) -> u16 {
326 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
329 /// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
330 /// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
331 /// `cltv_expiry_delta` for more details.
333 pub extern "C" fn CounterpartyForwardingInfo_set_cltv_expiry_delta(this_ptr: &mut CounterpartyForwardingInfo, mut val: u16) {
334 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
336 /// Constructs a new CounterpartyForwardingInfo given each field
339 pub extern "C" fn CounterpartyForwardingInfo_new(mut fee_base_msat_arg: u32, mut fee_proportional_millionths_arg: u32, mut cltv_expiry_delta_arg: u16) -> CounterpartyForwardingInfo {
340 CounterpartyForwardingInfo { inner: ObjOps::heap_alloc(nativeCounterpartyForwardingInfo {
341 fee_base_msat: fee_base_msat_arg,
342 fee_proportional_millionths: fee_proportional_millionths_arg,
343 cltv_expiry_delta: cltv_expiry_delta_arg,
346 impl Clone for CounterpartyForwardingInfo {
347 fn clone(&self) -> Self {
349 inner: if <*mut nativeCounterpartyForwardingInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
350 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
356 /// Used only if an object of this type is returned as a trait impl by a method
357 pub(crate) extern "C" fn CounterpartyForwardingInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
358 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCounterpartyForwardingInfo)).clone() })) as *mut c_void
361 /// Creates a copy of the CounterpartyForwardingInfo
362 pub extern "C" fn CounterpartyForwardingInfo_clone(orig: &CounterpartyForwardingInfo) -> CounterpartyForwardingInfo {
366 use lightning::ln::channelmanager::ChannelCounterparty as nativeChannelCounterpartyImport;
367 pub(crate) type nativeChannelCounterparty = nativeChannelCounterpartyImport;
369 /// Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
370 /// to better separate parameters.
373 pub struct ChannelCounterparty {
374 /// A pointer to the opaque Rust object.
376 /// Nearly everywhere, inner must be non-null, however in places where
377 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
378 pub inner: *mut nativeChannelCounterparty,
379 /// Indicates that this is the only struct which contains the same pointer.
381 /// Rust functions which take ownership of an object provided via an argument require
382 /// this to be true and invalidate the object pointed to by inner.
386 impl Drop for ChannelCounterparty {
388 if self.is_owned && !<*mut nativeChannelCounterparty>::is_null(self.inner) {
389 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
393 /// Frees any resources used by the ChannelCounterparty, if is_owned is set and inner is non-NULL.
395 pub extern "C" fn ChannelCounterparty_free(this_obj: ChannelCounterparty) { }
397 /// Used only if an object of this type is returned as a trait impl by a method
398 pub(crate) extern "C" fn ChannelCounterparty_free_void(this_ptr: *mut c_void) {
399 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelCounterparty); }
402 impl ChannelCounterparty {
403 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelCounterparty {
404 unsafe { &*ObjOps::untweak_ptr(self.inner) }
406 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelCounterparty {
407 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
409 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
410 pub(crate) fn take_inner(mut self) -> *mut nativeChannelCounterparty {
411 assert!(self.is_owned);
412 let ret = ObjOps::untweak_ptr(self.inner);
413 self.inner = core::ptr::null_mut();
417 /// The node_id of our counterparty
419 pub extern "C" fn ChannelCounterparty_get_node_id(this_ptr: &ChannelCounterparty) -> crate::c_types::PublicKey {
420 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_id;
421 crate::c_types::PublicKey::from_rust(&inner_val)
423 /// The node_id of our counterparty
425 pub extern "C" fn ChannelCounterparty_set_node_id(this_ptr: &mut ChannelCounterparty, mut val: crate::c_types::PublicKey) {
426 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_id = val.into_rust();
428 /// The Features the channel counterparty provided upon last connection.
429 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
430 /// many routing-relevant features are present in the init context.
432 pub extern "C" fn ChannelCounterparty_get_features(this_ptr: &ChannelCounterparty) -> crate::lightning::ln::features::InitFeatures {
433 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
434 crate::lightning::ln::features::InitFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::features::InitFeatures<>) as *mut _) }, is_owned: false }
436 /// The Features the channel counterparty provided upon last connection.
437 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
438 /// many routing-relevant features are present in the init context.
440 pub extern "C" fn ChannelCounterparty_set_features(this_ptr: &mut ChannelCounterparty, mut val: crate::lightning::ln::features::InitFeatures) {
441 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
443 /// The value, in satoshis, that must always be held in the channel for our counterparty. This
444 /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
445 /// claiming at least this value on chain.
447 /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
449 /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
451 pub extern "C" fn ChannelCounterparty_get_unspendable_punishment_reserve(this_ptr: &ChannelCounterparty) -> u64 {
452 let mut inner_val = &mut this_ptr.get_native_mut_ref().unspendable_punishment_reserve;
455 /// The value, in satoshis, that must always be held in the channel for our counterparty. This
456 /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
457 /// claiming at least this value on chain.
459 /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
461 /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
463 pub extern "C" fn ChannelCounterparty_set_unspendable_punishment_reserve(this_ptr: &mut ChannelCounterparty, mut val: u64) {
464 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = val;
466 /// Information on the fees and requirements that the counterparty requires when forwarding
467 /// payments to us through this channel.
469 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
471 pub extern "C" fn ChannelCounterparty_get_forwarding_info(this_ptr: &ChannelCounterparty) -> crate::lightning::ln::channelmanager::CounterpartyForwardingInfo {
472 let mut inner_val = &mut this_ptr.get_native_mut_ref().forwarding_info;
473 let mut local_inner_val = crate::lightning::ln::channelmanager::CounterpartyForwardingInfo { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::channelmanager::CounterpartyForwardingInfo<>) as *mut _ }, is_owned: false };
476 /// Information on the fees and requirements that the counterparty requires when forwarding
477 /// payments to us through this channel.
479 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
481 pub extern "C" fn ChannelCounterparty_set_forwarding_info(this_ptr: &mut ChannelCounterparty, mut val: crate::lightning::ln::channelmanager::CounterpartyForwardingInfo) {
482 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
483 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.forwarding_info = local_val;
485 /// The smallest value HTLC (in msat) the remote peer will accept, for this channel. This field
486 /// is only `None` before we have received either the `OpenChannel` or `AcceptChannel` message
487 /// from the remote peer, or for `ChannelCounterparty` objects serialized prior to LDK 0.0.107.
489 pub extern "C" fn ChannelCounterparty_get_outbound_htlc_minimum_msat(this_ptr: &ChannelCounterparty) -> crate::c_types::derived::COption_u64Z {
490 let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_htlc_minimum_msat;
491 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() }) };
494 /// The smallest value HTLC (in msat) the remote peer will accept, for this channel. This field
495 /// is only `None` before we have received either the `OpenChannel` or `AcceptChannel` message
496 /// from the remote peer, or for `ChannelCounterparty` objects serialized prior to LDK 0.0.107.
498 pub extern "C" fn ChannelCounterparty_set_outbound_htlc_minimum_msat(this_ptr: &mut ChannelCounterparty, mut val: crate::c_types::derived::COption_u64Z) {
499 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
500 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_htlc_minimum_msat = local_val;
502 /// The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
504 pub extern "C" fn ChannelCounterparty_get_outbound_htlc_maximum_msat(this_ptr: &ChannelCounterparty) -> crate::c_types::derived::COption_u64Z {
505 let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_htlc_maximum_msat;
506 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() }) };
509 /// The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
511 pub extern "C" fn ChannelCounterparty_set_outbound_htlc_maximum_msat(this_ptr: &mut ChannelCounterparty, mut val: crate::c_types::derived::COption_u64Z) {
512 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
513 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_htlc_maximum_msat = local_val;
515 /// Constructs a new ChannelCounterparty given each field
518 pub extern "C" fn ChannelCounterparty_new(mut node_id_arg: crate::c_types::PublicKey, mut features_arg: crate::lightning::ln::features::InitFeatures, mut unspendable_punishment_reserve_arg: u64, mut forwarding_info_arg: crate::lightning::ln::channelmanager::CounterpartyForwardingInfo, mut outbound_htlc_minimum_msat_arg: crate::c_types::derived::COption_u64Z, mut outbound_htlc_maximum_msat_arg: crate::c_types::derived::COption_u64Z) -> ChannelCounterparty {
519 let mut local_forwarding_info_arg = if forwarding_info_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(forwarding_info_arg.take_inner()) } }) };
520 let mut local_outbound_htlc_minimum_msat_arg = if outbound_htlc_minimum_msat_arg.is_some() { Some( { outbound_htlc_minimum_msat_arg.take() }) } else { None };
521 let mut local_outbound_htlc_maximum_msat_arg = if outbound_htlc_maximum_msat_arg.is_some() { Some( { outbound_htlc_maximum_msat_arg.take() }) } else { None };
522 ChannelCounterparty { inner: ObjOps::heap_alloc(nativeChannelCounterparty {
523 node_id: node_id_arg.into_rust(),
524 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
525 unspendable_punishment_reserve: unspendable_punishment_reserve_arg,
526 forwarding_info: local_forwarding_info_arg,
527 outbound_htlc_minimum_msat: local_outbound_htlc_minimum_msat_arg,
528 outbound_htlc_maximum_msat: local_outbound_htlc_maximum_msat_arg,
531 impl Clone for ChannelCounterparty {
532 fn clone(&self) -> Self {
534 inner: if <*mut nativeChannelCounterparty>::is_null(self.inner) { core::ptr::null_mut() } else {
535 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
541 /// Used only if an object of this type is returned as a trait impl by a method
542 pub(crate) extern "C" fn ChannelCounterparty_clone_void(this_ptr: *const c_void) -> *mut c_void {
543 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelCounterparty)).clone() })) as *mut c_void
546 /// Creates a copy of the ChannelCounterparty
547 pub extern "C" fn ChannelCounterparty_clone(orig: &ChannelCounterparty) -> ChannelCounterparty {
551 use lightning::ln::channelmanager::ChannelDetails as nativeChannelDetailsImport;
552 pub(crate) type nativeChannelDetails = nativeChannelDetailsImport;
554 /// Details of a channel, as returned by ChannelManager::list_channels and ChannelManager::list_usable_channels
557 pub struct ChannelDetails {
558 /// A pointer to the opaque Rust object.
560 /// Nearly everywhere, inner must be non-null, however in places where
561 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
562 pub inner: *mut nativeChannelDetails,
563 /// Indicates that this is the only struct which contains the same pointer.
565 /// Rust functions which take ownership of an object provided via an argument require
566 /// this to be true and invalidate the object pointed to by inner.
570 impl Drop for ChannelDetails {
572 if self.is_owned && !<*mut nativeChannelDetails>::is_null(self.inner) {
573 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
577 /// Frees any resources used by the ChannelDetails, if is_owned is set and inner is non-NULL.
579 pub extern "C" fn ChannelDetails_free(this_obj: ChannelDetails) { }
581 /// Used only if an object of this type is returned as a trait impl by a method
582 pub(crate) extern "C" fn ChannelDetails_free_void(this_ptr: *mut c_void) {
583 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelDetails); }
586 impl ChannelDetails {
587 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelDetails {
588 unsafe { &*ObjOps::untweak_ptr(self.inner) }
590 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelDetails {
591 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
593 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
594 pub(crate) fn take_inner(mut self) -> *mut nativeChannelDetails {
595 assert!(self.is_owned);
596 let ret = ObjOps::untweak_ptr(self.inner);
597 self.inner = core::ptr::null_mut();
601 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
602 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
603 /// Note that this means this value is *not* persistent - it can change once during the
604 /// lifetime of the channel.
606 pub extern "C" fn ChannelDetails_get_channel_id(this_ptr: &ChannelDetails) -> *const [u8; 32] {
607 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id;
610 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
611 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
612 /// Note that this means this value is *not* persistent - it can change once during the
613 /// lifetime of the channel.
615 pub extern "C" fn ChannelDetails_set_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::ThirtyTwoBytes) {
616 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = val.data;
618 /// Parameters which apply to our counterparty. See individual fields for more information.
620 pub extern "C" fn ChannelDetails_get_counterparty(this_ptr: &ChannelDetails) -> crate::lightning::ln::channelmanager::ChannelCounterparty {
621 let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty;
622 crate::lightning::ln::channelmanager::ChannelCounterparty { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::channelmanager::ChannelCounterparty<>) as *mut _) }, is_owned: false }
624 /// Parameters which apply to our counterparty. See individual fields for more information.
626 pub extern "C" fn ChannelDetails_set_counterparty(this_ptr: &mut ChannelDetails, mut val: crate::lightning::ln::channelmanager::ChannelCounterparty) {
627 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty = *unsafe { Box::from_raw(val.take_inner()) };
629 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
630 /// our counterparty already.
632 /// Note that, if this has been set, `channel_id` will be equivalent to
633 /// `funding_txo.unwrap().to_channel_id()`.
635 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
637 pub extern "C" fn ChannelDetails_get_funding_txo(this_ptr: &ChannelDetails) -> crate::lightning::chain::transaction::OutPoint {
638 let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_txo;
639 let mut local_inner_val = crate::lightning::chain::transaction::OutPoint { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::chain::transaction::OutPoint<>) as *mut _ }, is_owned: false };
642 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
643 /// our counterparty already.
645 /// Note that, if this has been set, `channel_id` will be equivalent to
646 /// `funding_txo.unwrap().to_channel_id()`.
648 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
650 pub extern "C" fn ChannelDetails_set_funding_txo(this_ptr: &mut ChannelDetails, mut val: crate::lightning::chain::transaction::OutPoint) {
651 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
652 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_txo = local_val;
654 /// The features which this channel operates with. See individual features for more info.
656 /// `None` until negotiation completes and the channel type is finalized.
658 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
660 pub extern "C" fn ChannelDetails_get_channel_type(this_ptr: &ChannelDetails) -> crate::lightning::ln::features::ChannelTypeFeatures {
661 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_type;
662 let mut local_inner_val = crate::lightning::ln::features::ChannelTypeFeatures { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::features::ChannelTypeFeatures<>) as *mut _ }, is_owned: false };
665 /// The features which this channel operates with. See individual features for more info.
667 /// `None` until negotiation completes and the channel type is finalized.
669 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
671 pub extern "C" fn ChannelDetails_set_channel_type(this_ptr: &mut ChannelDetails, mut val: crate::lightning::ln::features::ChannelTypeFeatures) {
672 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
673 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_type = local_val;
675 /// The position of the funding transaction in the chain. None if the funding transaction has
676 /// not yet been confirmed and the channel fully opened.
678 /// Note that if [`inbound_scid_alias`] is set, it must be used for invoices and inbound
679 /// payments instead of this. See [`get_inbound_payment_scid`].
681 /// For channels with [`confirmations_required`] set to `Some(0)`, [`outbound_scid_alias`] may
682 /// be used in place of this in outbound routes. See [`get_outbound_payment_scid`].
684 /// [`inbound_scid_alias`]: Self::inbound_scid_alias
685 /// [`outbound_scid_alias`]: Self::outbound_scid_alias
686 /// [`get_inbound_payment_scid`]: Self::get_inbound_payment_scid
687 /// [`get_outbound_payment_scid`]: Self::get_outbound_payment_scid
688 /// [`confirmations_required`]: Self::confirmations_required
690 pub extern "C" fn ChannelDetails_get_short_channel_id(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
691 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
692 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() }) };
695 /// The position of the funding transaction in the chain. None if the funding transaction has
696 /// not yet been confirmed and the channel fully opened.
698 /// Note that if [`inbound_scid_alias`] is set, it must be used for invoices and inbound
699 /// payments instead of this. See [`get_inbound_payment_scid`].
701 /// For channels with [`confirmations_required`] set to `Some(0)`, [`outbound_scid_alias`] may
702 /// be used in place of this in outbound routes. See [`get_outbound_payment_scid`].
704 /// [`inbound_scid_alias`]: Self::inbound_scid_alias
705 /// [`outbound_scid_alias`]: Self::outbound_scid_alias
706 /// [`get_inbound_payment_scid`]: Self::get_inbound_payment_scid
707 /// [`get_outbound_payment_scid`]: Self::get_outbound_payment_scid
708 /// [`confirmations_required`]: Self::confirmations_required
710 pub extern "C" fn ChannelDetails_set_short_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
711 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
712 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = local_val;
714 /// An optional [`short_channel_id`] alias for this channel, randomly generated by us and
715 /// usable in place of [`short_channel_id`] to reference the channel in outbound routes when
716 /// the channel has not yet been confirmed (as long as [`confirmations_required`] is
719 /// This will be `None` as long as the channel is not available for routing outbound payments.
721 /// [`short_channel_id`]: Self::short_channel_id
722 /// [`confirmations_required`]: Self::confirmations_required
724 pub extern "C" fn ChannelDetails_get_outbound_scid_alias(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
725 let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_scid_alias;
726 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() }) };
729 /// An optional [`short_channel_id`] alias for this channel, randomly generated by us and
730 /// usable in place of [`short_channel_id`] to reference the channel in outbound routes when
731 /// the channel has not yet been confirmed (as long as [`confirmations_required`] is
734 /// This will be `None` as long as the channel is not available for routing outbound payments.
736 /// [`short_channel_id`]: Self::short_channel_id
737 /// [`confirmations_required`]: Self::confirmations_required
739 pub extern "C" fn ChannelDetails_set_outbound_scid_alias(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
740 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
741 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_scid_alias = local_val;
743 /// An optional [`short_channel_id`] alias for this channel, randomly generated by our
744 /// counterparty and usable in place of [`short_channel_id`] in invoice route hints. Our
745 /// counterparty will recognize the alias provided here in place of the [`short_channel_id`]
746 /// when they see a payment to be routed to us.
748 /// Our counterparty may choose to rotate this value at any time, though will always recognize
749 /// previous values for inbound payment forwarding.
751 /// [`short_channel_id`]: Self::short_channel_id
753 pub extern "C" fn ChannelDetails_get_inbound_scid_alias(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
754 let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_scid_alias;
755 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() }) };
758 /// An optional [`short_channel_id`] alias for this channel, randomly generated by our
759 /// counterparty and usable in place of [`short_channel_id`] in invoice route hints. Our
760 /// counterparty will recognize the alias provided here in place of the [`short_channel_id`]
761 /// when they see a payment to be routed to us.
763 /// Our counterparty may choose to rotate this value at any time, though will always recognize
764 /// previous values for inbound payment forwarding.
766 /// [`short_channel_id`]: Self::short_channel_id
768 pub extern "C" fn ChannelDetails_set_inbound_scid_alias(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
769 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
770 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_scid_alias = local_val;
772 /// The value, in satoshis, of this channel as appears in the funding output
774 pub extern "C" fn ChannelDetails_get_channel_value_satoshis(this_ptr: &ChannelDetails) -> u64 {
775 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
778 /// The value, in satoshis, of this channel as appears in the funding output
780 pub extern "C" fn ChannelDetails_set_channel_value_satoshis(this_ptr: &mut ChannelDetails, mut val: u64) {
781 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
783 /// The value, in satoshis, that must always be held in the channel for us. This value ensures
784 /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
785 /// this value on chain.
787 /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
789 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
791 /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
793 pub extern "C" fn ChannelDetails_get_unspendable_punishment_reserve(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
794 let mut inner_val = &mut this_ptr.get_native_mut_ref().unspendable_punishment_reserve;
795 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() }) };
798 /// The value, in satoshis, that must always be held in the channel for us. This value ensures
799 /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
800 /// this value on chain.
802 /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
804 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
806 /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
808 pub extern "C" fn ChannelDetails_set_unspendable_punishment_reserve(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
809 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
810 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = local_val;
812 /// The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound.
814 pub extern "C" fn ChannelDetails_get_user_channel_id(this_ptr: &ChannelDetails) -> u64 {
815 let mut inner_val = &mut this_ptr.get_native_mut_ref().user_channel_id;
818 /// The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound.
820 pub extern "C" fn ChannelDetails_set_user_channel_id(this_ptr: &mut ChannelDetails, mut val: u64) {
821 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.user_channel_id = val;
823 /// Our total balance. This is the amount we would get if we close the channel.
824 /// This value is not exact. Due to various in-flight changes and feerate changes, exactly this
825 /// amount is not likely to be recoverable on close.
827 /// This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose
828 /// balance is not available for inclusion in new outbound HTLCs). This further does not include
829 /// any pending outgoing HTLCs which are awaiting some other resolution to be sent.
830 /// This does not consider any on-chain fees.
832 /// See also [`ChannelDetails::outbound_capacity_msat`]
834 pub extern "C" fn ChannelDetails_get_balance_msat(this_ptr: &ChannelDetails) -> u64 {
835 let mut inner_val = &mut this_ptr.get_native_mut_ref().balance_msat;
838 /// Our total balance. This is the amount we would get if we close the channel.
839 /// This value is not exact. Due to various in-flight changes and feerate changes, exactly this
840 /// amount is not likely to be recoverable on close.
842 /// This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose
843 /// balance is not available for inclusion in new outbound HTLCs). This further does not include
844 /// any pending outgoing HTLCs which are awaiting some other resolution to be sent.
845 /// This does not consider any on-chain fees.
847 /// See also [`ChannelDetails::outbound_capacity_msat`]
849 pub extern "C" fn ChannelDetails_set_balance_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
850 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.balance_msat = val;
852 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
853 /// any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
854 /// available for inclusion in new outbound HTLCs). This further does not include any pending
855 /// outgoing HTLCs which are awaiting some other resolution to be sent.
857 /// See also [`ChannelDetails::balance_msat`]
859 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
860 /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
861 /// should be able to spend nearly this amount.
863 pub extern "C" fn ChannelDetails_get_outbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
864 let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_capacity_msat;
867 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
868 /// any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
869 /// available for inclusion in new outbound HTLCs). This further does not include any pending
870 /// outgoing HTLCs which are awaiting some other resolution to be sent.
872 /// See also [`ChannelDetails::balance_msat`]
874 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
875 /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
876 /// should be able to spend nearly this amount.
878 pub extern "C" fn ChannelDetails_set_outbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
879 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_capacity_msat = val;
881 /// The available outbound capacity for sending a single HTLC to the remote peer. This is
882 /// similar to [`ChannelDetails::outbound_capacity_msat`] but it may be further restricted by
883 /// the current state and per-HTLC limit(s). This is intended for use when routing, allowing us
884 /// to use a limit as close as possible to the HTLC limit we can currently send.
886 /// See also [`ChannelDetails::balance_msat`] and [`ChannelDetails::outbound_capacity_msat`].
888 pub extern "C" fn ChannelDetails_get_next_outbound_htlc_limit_msat(this_ptr: &ChannelDetails) -> u64 {
889 let mut inner_val = &mut this_ptr.get_native_mut_ref().next_outbound_htlc_limit_msat;
892 /// The available outbound capacity for sending a single HTLC to the remote peer. This is
893 /// similar to [`ChannelDetails::outbound_capacity_msat`] but it may be further restricted by
894 /// the current state and per-HTLC limit(s). This is intended for use when routing, allowing us
895 /// to use a limit as close as possible to the HTLC limit we can currently send.
897 /// See also [`ChannelDetails::balance_msat`] and [`ChannelDetails::outbound_capacity_msat`].
899 pub extern "C" fn ChannelDetails_set_next_outbound_htlc_limit_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
900 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.next_outbound_htlc_limit_msat = val;
902 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
903 /// include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
904 /// available for inclusion in new inbound HTLCs).
905 /// Note that there are some corner cases not fully handled here, so the actual available
906 /// inbound capacity may be slightly higher than this.
908 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
909 /// counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
910 /// However, our counterparty should be able to spend nearly this amount.
912 pub extern "C" fn ChannelDetails_get_inbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
913 let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_capacity_msat;
916 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
917 /// include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
918 /// available for inclusion in new inbound HTLCs).
919 /// Note that there are some corner cases not fully handled here, so the actual available
920 /// inbound capacity may be slightly higher than this.
922 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
923 /// counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
924 /// However, our counterparty should be able to spend nearly this amount.
926 pub extern "C" fn ChannelDetails_set_inbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
927 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_capacity_msat = val;
929 /// The number of required confirmations on the funding transaction before the funding will be
930 /// considered \"locked\". This number is selected by the channel fundee (i.e. us if
931 /// [`is_outbound`] is *not* set), and can be selected for inbound channels with
932 /// [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
933 /// [`ChannelHandshakeLimits::max_minimum_depth`].
935 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
937 /// [`is_outbound`]: ChannelDetails::is_outbound
938 /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
939 /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
941 pub extern "C" fn ChannelDetails_get_confirmations_required(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u32Z {
942 let mut inner_val = &mut this_ptr.get_native_mut_ref().confirmations_required;
943 let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u32Z::None } else { crate::c_types::derived::COption_u32Z::Some( { inner_val.unwrap() }) };
946 /// The number of required confirmations on the funding transaction before the funding will be
947 /// considered \"locked\". This number is selected by the channel fundee (i.e. us if
948 /// [`is_outbound`] is *not* set), and can be selected for inbound channels with
949 /// [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
950 /// [`ChannelHandshakeLimits::max_minimum_depth`].
952 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
954 /// [`is_outbound`]: ChannelDetails::is_outbound
955 /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
956 /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
958 pub extern "C" fn ChannelDetails_set_confirmations_required(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u32Z) {
959 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
960 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.confirmations_required = local_val;
962 /// The number of blocks (after our commitment transaction confirms) that we will need to wait
963 /// until we can claim our funds after we force-close the channel. During this time our
964 /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
965 /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any
966 /// time to claim our non-HTLC-encumbered funds.
968 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
970 pub extern "C" fn ChannelDetails_get_force_close_spend_delay(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u16Z {
971 let mut inner_val = &mut this_ptr.get_native_mut_ref().force_close_spend_delay;
972 let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u16Z::None } else { crate::c_types::derived::COption_u16Z::Some( { inner_val.unwrap() }) };
975 /// The number of blocks (after our commitment transaction confirms) that we will need to wait
976 /// until we can claim our funds after we force-close the channel. During this time our
977 /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
978 /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any
979 /// time to claim our non-HTLC-encumbered funds.
981 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
983 pub extern "C" fn ChannelDetails_set_force_close_spend_delay(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u16Z) {
984 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
985 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.force_close_spend_delay = local_val;
987 /// True if the channel was initiated (and thus funded) by us.
989 pub extern "C" fn ChannelDetails_get_is_outbound(this_ptr: &ChannelDetails) -> bool {
990 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_outbound;
993 /// True if the channel was initiated (and thus funded) by us.
995 pub extern "C" fn ChannelDetails_set_is_outbound(this_ptr: &mut ChannelDetails, mut val: bool) {
996 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_outbound = val;
998 /// True if the channel is confirmed, channel_ready messages have been exchanged, and the
999 /// channel is not currently being shut down. `channel_ready` message exchange implies the
1000 /// required confirmation count has been reached (and we were connected to the peer at some
1001 /// point after the funding transaction received enough confirmations). The required
1002 /// confirmation count is provided in [`confirmations_required`].
1004 /// [`confirmations_required`]: ChannelDetails::confirmations_required
1006 pub extern "C" fn ChannelDetails_get_is_channel_ready(this_ptr: &ChannelDetails) -> bool {
1007 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_channel_ready;
1010 /// True if the channel is confirmed, channel_ready messages have been exchanged, and the
1011 /// channel is not currently being shut down. `channel_ready` message exchange implies the
1012 /// required confirmation count has been reached (and we were connected to the peer at some
1013 /// point after the funding transaction received enough confirmations). The required
1014 /// confirmation count is provided in [`confirmations_required`].
1016 /// [`confirmations_required`]: ChannelDetails::confirmations_required
1018 pub extern "C" fn ChannelDetails_set_is_channel_ready(this_ptr: &mut ChannelDetails, mut val: bool) {
1019 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_channel_ready = val;
1021 /// True if the channel is (a) confirmed and channel_ready messages have been exchanged, (b)
1022 /// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
1024 /// This is a strict superset of `is_channel_ready`.
1026 pub extern "C" fn ChannelDetails_get_is_usable(this_ptr: &ChannelDetails) -> bool {
1027 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_usable;
1030 /// True if the channel is (a) confirmed and channel_ready messages have been exchanged, (b)
1031 /// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
1033 /// This is a strict superset of `is_channel_ready`.
1035 pub extern "C" fn ChannelDetails_set_is_usable(this_ptr: &mut ChannelDetails, mut val: bool) {
1036 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_usable = val;
1038 /// True if this channel is (or will be) publicly-announced.
1040 pub extern "C" fn ChannelDetails_get_is_public(this_ptr: &ChannelDetails) -> bool {
1041 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_public;
1044 /// True if this channel is (or will be) publicly-announced.
1046 pub extern "C" fn ChannelDetails_set_is_public(this_ptr: &mut ChannelDetails, mut val: bool) {
1047 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_public = val;
1049 /// The smallest value HTLC (in msat) we will accept, for this channel. This field
1050 /// is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.107
1052 pub extern "C" fn ChannelDetails_get_inbound_htlc_minimum_msat(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
1053 let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_htlc_minimum_msat;
1054 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() }) };
1057 /// The smallest value HTLC (in msat) we will accept, for this channel. This field
1058 /// is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.107
1060 pub extern "C" fn ChannelDetails_set_inbound_htlc_minimum_msat(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
1061 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1062 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_htlc_minimum_msat = local_val;
1064 /// The largest value HTLC (in msat) we currently will accept, for this channel.
1066 pub extern "C" fn ChannelDetails_get_inbound_htlc_maximum_msat(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
1067 let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_htlc_maximum_msat;
1068 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() }) };
1071 /// The largest value HTLC (in msat) we currently will accept, for this channel.
1073 pub extern "C" fn ChannelDetails_set_inbound_htlc_maximum_msat(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
1074 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1075 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_htlc_maximum_msat = local_val;
1077 /// Set of configurable parameters that affect channel operation.
1079 /// This field is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.109.
1081 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1083 pub extern "C" fn ChannelDetails_get_config(this_ptr: &ChannelDetails) -> crate::lightning::util::config::ChannelConfig {
1084 let mut inner_val = &mut this_ptr.get_native_mut_ref().config;
1085 let mut local_inner_val = crate::lightning::util::config::ChannelConfig { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::util::config::ChannelConfig<>) as *mut _ }, is_owned: false };
1088 /// Set of configurable parameters that affect channel operation.
1090 /// This field is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.109.
1092 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1094 pub extern "C" fn ChannelDetails_set_config(this_ptr: &mut ChannelDetails, mut val: crate::lightning::util::config::ChannelConfig) {
1095 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1096 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.config = local_val;
1098 /// Constructs a new ChannelDetails given each field
1101 pub extern "C" fn ChannelDetails_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut counterparty_arg: crate::lightning::ln::channelmanager::ChannelCounterparty, mut funding_txo_arg: crate::lightning::chain::transaction::OutPoint, mut channel_type_arg: crate::lightning::ln::features::ChannelTypeFeatures, mut short_channel_id_arg: crate::c_types::derived::COption_u64Z, mut outbound_scid_alias_arg: crate::c_types::derived::COption_u64Z, mut inbound_scid_alias_arg: crate::c_types::derived::COption_u64Z, mut channel_value_satoshis_arg: u64, mut unspendable_punishment_reserve_arg: crate::c_types::derived::COption_u64Z, mut user_channel_id_arg: u64, mut balance_msat_arg: u64, mut outbound_capacity_msat_arg: u64, mut next_outbound_htlc_limit_msat_arg: u64, mut inbound_capacity_msat_arg: u64, mut confirmations_required_arg: crate::c_types::derived::COption_u32Z, mut force_close_spend_delay_arg: crate::c_types::derived::COption_u16Z, mut is_outbound_arg: bool, mut is_channel_ready_arg: bool, mut is_usable_arg: bool, mut is_public_arg: bool, mut inbound_htlc_minimum_msat_arg: crate::c_types::derived::COption_u64Z, mut inbound_htlc_maximum_msat_arg: crate::c_types::derived::COption_u64Z, mut config_arg: crate::lightning::util::config::ChannelConfig) -> ChannelDetails {
1102 let mut local_funding_txo_arg = if funding_txo_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(funding_txo_arg.take_inner()) } }) };
1103 let mut local_channel_type_arg = if channel_type_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(channel_type_arg.take_inner()) } }) };
1104 let mut local_short_channel_id_arg = if short_channel_id_arg.is_some() { Some( { short_channel_id_arg.take() }) } else { None };
1105 let mut local_outbound_scid_alias_arg = if outbound_scid_alias_arg.is_some() { Some( { outbound_scid_alias_arg.take() }) } else { None };
1106 let mut local_inbound_scid_alias_arg = if inbound_scid_alias_arg.is_some() { Some( { inbound_scid_alias_arg.take() }) } else { None };
1107 let mut local_unspendable_punishment_reserve_arg = if unspendable_punishment_reserve_arg.is_some() { Some( { unspendable_punishment_reserve_arg.take() }) } else { None };
1108 let mut local_confirmations_required_arg = if confirmations_required_arg.is_some() { Some( { confirmations_required_arg.take() }) } else { None };
1109 let mut local_force_close_spend_delay_arg = if force_close_spend_delay_arg.is_some() { Some( { force_close_spend_delay_arg.take() }) } else { None };
1110 let mut local_inbound_htlc_minimum_msat_arg = if inbound_htlc_minimum_msat_arg.is_some() { Some( { inbound_htlc_minimum_msat_arg.take() }) } else { None };
1111 let mut local_inbound_htlc_maximum_msat_arg = if inbound_htlc_maximum_msat_arg.is_some() { Some( { inbound_htlc_maximum_msat_arg.take() }) } else { None };
1112 let mut local_config_arg = if config_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(config_arg.take_inner()) } }) };
1113 ChannelDetails { inner: ObjOps::heap_alloc(nativeChannelDetails {
1114 channel_id: channel_id_arg.data,
1115 counterparty: *unsafe { Box::from_raw(counterparty_arg.take_inner()) },
1116 funding_txo: local_funding_txo_arg,
1117 channel_type: local_channel_type_arg,
1118 short_channel_id: local_short_channel_id_arg,
1119 outbound_scid_alias: local_outbound_scid_alias_arg,
1120 inbound_scid_alias: local_inbound_scid_alias_arg,
1121 channel_value_satoshis: channel_value_satoshis_arg,
1122 unspendable_punishment_reserve: local_unspendable_punishment_reserve_arg,
1123 user_channel_id: user_channel_id_arg,
1124 balance_msat: balance_msat_arg,
1125 outbound_capacity_msat: outbound_capacity_msat_arg,
1126 next_outbound_htlc_limit_msat: next_outbound_htlc_limit_msat_arg,
1127 inbound_capacity_msat: inbound_capacity_msat_arg,
1128 confirmations_required: local_confirmations_required_arg,
1129 force_close_spend_delay: local_force_close_spend_delay_arg,
1130 is_outbound: is_outbound_arg,
1131 is_channel_ready: is_channel_ready_arg,
1132 is_usable: is_usable_arg,
1133 is_public: is_public_arg,
1134 inbound_htlc_minimum_msat: local_inbound_htlc_minimum_msat_arg,
1135 inbound_htlc_maximum_msat: local_inbound_htlc_maximum_msat_arg,
1136 config: local_config_arg,
1137 }), is_owned: true }
1139 impl Clone for ChannelDetails {
1140 fn clone(&self) -> Self {
1142 inner: if <*mut nativeChannelDetails>::is_null(self.inner) { core::ptr::null_mut() } else {
1143 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1149 /// Used only if an object of this type is returned as a trait impl by a method
1150 pub(crate) extern "C" fn ChannelDetails_clone_void(this_ptr: *const c_void) -> *mut c_void {
1151 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelDetails)).clone() })) as *mut c_void
1154 /// Creates a copy of the ChannelDetails
1155 pub extern "C" fn ChannelDetails_clone(orig: &ChannelDetails) -> ChannelDetails {
1158 /// Gets the current SCID which should be used to identify this channel for inbound payments.
1159 /// This should be used for providing invoice hints or in any other context where our
1160 /// counterparty will forward a payment to us.
1162 /// This is either the [`ChannelDetails::inbound_scid_alias`], if set, or the
1163 /// [`ChannelDetails::short_channel_id`]. See those for more information.
1166 pub extern "C" fn ChannelDetails_get_inbound_payment_scid(this_arg: &crate::lightning::ln::channelmanager::ChannelDetails) -> crate::c_types::derived::COption_u64Z {
1167 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_inbound_payment_scid();
1168 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { ret.unwrap() }) };
1172 /// Gets the current SCID which should be used to identify this channel for outbound payments.
1173 /// This should be used in [`Route`]s to describe the first hop or in other contexts where
1174 /// we're sending or forwarding a payment outbound over this channel.
1176 /// This is either the [`ChannelDetails::short_channel_id`], if set, or the
1177 /// [`ChannelDetails::outbound_scid_alias`]. See those for more information.
1180 pub extern "C" fn ChannelDetails_get_outbound_payment_scid(this_arg: &crate::lightning::ln::channelmanager::ChannelDetails) -> crate::c_types::derived::COption_u64Z {
1181 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_outbound_payment_scid();
1182 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { ret.unwrap() }) };
1186 /// If a payment fails to send, it can be in one of several states. This enum is returned as the
1187 /// Err() type describing which state the payment is in, see the description of individual enum
1188 /// states for more.
1192 pub enum PaymentSendFailure {
1193 /// A parameter which was passed to send_payment was invalid, preventing us from attempting to
1194 /// send the payment at all. No channel state has been changed or messages sent to peers, and
1195 /// once you've changed the parameter at error, you can freely retry the payment in full.
1197 crate::lightning::util::errors::APIError),
1198 /// A parameter in a single path which was passed to send_payment was invalid, preventing us
1199 /// from attempting to send the payment at all. No channel state has been changed or messages
1200 /// sent to peers, and once you've changed the parameter at error, you can freely retry the
1201 /// payment in full.
1203 /// The results here are ordered the same as the paths in the route object which was passed to
1206 crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ),
1207 /// All paths which were attempted failed to send, with no channel state change taking place.
1208 /// You can freely retry the payment in full (though you probably want to do so over different
1209 /// paths than the ones selected).
1211 crate::c_types::derived::CVec_APIErrorZ),
1212 /// Some paths which were attempted failed to send, though possibly not all. At least some
1213 /// paths have irrevocably committed to the HTLC and retrying the payment in full would result
1214 /// in over-/re-payment.
1216 /// The results here are ordered the same as the paths in the route object which was passed to
1217 /// send_payment, and any Errs which are not APIError::MonitorUpdateFailed can be safely
1218 /// retried (though there is currently no API with which to do so).
1220 /// Any entries which contain Err(APIError::MonitorUpdateFailed) or Ok(()) MUST NOT be retried
1221 /// as they will result in over-/re-payment. These HTLCs all either successfully sent (in the
1222 /// case of Ok(())) or will send once channel_monitor_updated is called on the next-hop channel
1223 /// with the latest update_id.
1225 /// The errors themselves, in the same order as the route hops.
1226 results: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ,
1227 /// If some paths failed without irrevocably committing to the new HTLC(s), this will
1228 /// contain a [`RouteParameters`] object which can be used to calculate a new route that
1229 /// will pay all remaining unpaid balance.
1231 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1232 failed_paths_retry: crate::lightning::routing::router::RouteParameters,
1233 /// The payment id for the payment, which is now at least partially pending.
1234 payment_id: crate::c_types::ThirtyTwoBytes,
1237 use lightning::ln::channelmanager::PaymentSendFailure as PaymentSendFailureImport;
1238 pub(crate) type nativePaymentSendFailure = PaymentSendFailureImport;
1240 impl PaymentSendFailure {
1242 pub(crate) fn to_native(&self) -> nativePaymentSendFailure {
1244 PaymentSendFailure::ParameterError (ref a, ) => {
1245 let mut a_nonref = (*a).clone();
1246 nativePaymentSendFailure::ParameterError (
1247 a_nonref.into_native(),
1250 PaymentSendFailure::PathParameterError (ref a, ) => {
1251 let mut a_nonref = (*a).clone();
1252 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 }); };
1253 nativePaymentSendFailure::PathParameterError (
1257 PaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
1258 let mut a_nonref = (*a).clone();
1259 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { item.into_native() }); };
1260 nativePaymentSendFailure::AllFailedRetrySafe (
1264 PaymentSendFailure::PartialFailure {ref results, ref failed_paths_retry, ref payment_id, } => {
1265 let mut results_nonref = (*results).clone();
1266 let mut local_results_nonref = Vec::new(); for mut item in results_nonref.into_rust().drain(..) { local_results_nonref.push( { let mut local_results_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_results_nonref_0 }); };
1267 let mut failed_paths_retry_nonref = (*failed_paths_retry).clone();
1268 let mut local_failed_paths_retry_nonref = if failed_paths_retry_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(failed_paths_retry_nonref.take_inner()) } }) };
1269 let mut payment_id_nonref = (*payment_id).clone();
1270 nativePaymentSendFailure::PartialFailure {
1271 results: local_results_nonref,
1272 failed_paths_retry: local_failed_paths_retry_nonref,
1273 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1279 pub(crate) fn into_native(self) -> nativePaymentSendFailure {
1281 PaymentSendFailure::ParameterError (mut a, ) => {
1282 nativePaymentSendFailure::ParameterError (
1286 PaymentSendFailure::PathParameterError (mut a, ) => {
1287 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 }); };
1288 nativePaymentSendFailure::PathParameterError (
1292 PaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
1293 let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { item.into_native() }); };
1294 nativePaymentSendFailure::AllFailedRetrySafe (
1298 PaymentSendFailure::PartialFailure {mut results, mut failed_paths_retry, mut payment_id, } => {
1299 let mut local_results = Vec::new(); for mut item in results.into_rust().drain(..) { local_results.push( { let mut local_results_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_results_0 }); };
1300 let mut local_failed_paths_retry = if failed_paths_retry.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(failed_paths_retry.take_inner()) } }) };
1301 nativePaymentSendFailure::PartialFailure {
1302 results: local_results,
1303 failed_paths_retry: local_failed_paths_retry,
1304 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1310 pub(crate) fn from_native(native: &nativePaymentSendFailure) -> Self {
1312 nativePaymentSendFailure::ParameterError (ref a, ) => {
1313 let mut a_nonref = (*a).clone();
1314 PaymentSendFailure::ParameterError (
1315 crate::lightning::util::errors::APIError::native_into(a_nonref),
1318 nativePaymentSendFailure::PathParameterError (ref a, ) => {
1319 let mut a_nonref = (*a).clone();
1320 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 }); };
1321 PaymentSendFailure::PathParameterError (
1322 local_a_nonref.into(),
1325 nativePaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
1326 let mut a_nonref = (*a).clone();
1327 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) }); };
1328 PaymentSendFailure::AllFailedRetrySafe (
1329 local_a_nonref.into(),
1332 nativePaymentSendFailure::PartialFailure {ref results, ref failed_paths_retry, ref payment_id, } => {
1333 let mut results_nonref = (*results).clone();
1334 let mut local_results_nonref = Vec::new(); for mut item in results_nonref.drain(..) { local_results_nonref.push( { let mut local_results_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_results_nonref_0 }); };
1335 let mut failed_paths_retry_nonref = (*failed_paths_retry).clone();
1336 let mut local_failed_paths_retry_nonref = crate::lightning::routing::router::RouteParameters { inner: if failed_paths_retry_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((failed_paths_retry_nonref.unwrap())) } }, is_owned: true };
1337 let mut payment_id_nonref = (*payment_id).clone();
1338 PaymentSendFailure::PartialFailure {
1339 results: local_results_nonref.into(),
1340 failed_paths_retry: local_failed_paths_retry_nonref,
1341 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1347 pub(crate) fn native_into(native: nativePaymentSendFailure) -> Self {
1349 nativePaymentSendFailure::ParameterError (mut a, ) => {
1350 PaymentSendFailure::ParameterError (
1351 crate::lightning::util::errors::APIError::native_into(a),
1354 nativePaymentSendFailure::PathParameterError (mut a, ) => {
1355 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 }); };
1356 PaymentSendFailure::PathParameterError (
1360 nativePaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
1361 let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { crate::lightning::util::errors::APIError::native_into(item) }); };
1362 PaymentSendFailure::AllFailedRetrySafe (
1366 nativePaymentSendFailure::PartialFailure {mut results, mut failed_paths_retry, mut payment_id, } => {
1367 let mut local_results = Vec::new(); for mut item in results.drain(..) { local_results.push( { let mut local_results_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_results_0 }); };
1368 let mut local_failed_paths_retry = crate::lightning::routing::router::RouteParameters { inner: if failed_paths_retry.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((failed_paths_retry.unwrap())) } }, is_owned: true };
1369 PaymentSendFailure::PartialFailure {
1370 results: local_results.into(),
1371 failed_paths_retry: local_failed_paths_retry,
1372 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1378 /// Frees any resources used by the PaymentSendFailure
1380 pub extern "C" fn PaymentSendFailure_free(this_ptr: PaymentSendFailure) { }
1381 /// Creates a copy of the PaymentSendFailure
1383 pub extern "C" fn PaymentSendFailure_clone(orig: &PaymentSendFailure) -> PaymentSendFailure {
1387 /// Utility method to constructs a new ParameterError-variant PaymentSendFailure
1388 pub extern "C" fn PaymentSendFailure_parameter_error(a: crate::lightning::util::errors::APIError) -> PaymentSendFailure {
1389 PaymentSendFailure::ParameterError(a, )
1392 /// Utility method to constructs a new PathParameterError-variant PaymentSendFailure
1393 pub extern "C" fn PaymentSendFailure_path_parameter_error(a: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ) -> PaymentSendFailure {
1394 PaymentSendFailure::PathParameterError(a, )
1397 /// Utility method to constructs a new AllFailedRetrySafe-variant PaymentSendFailure
1398 pub extern "C" fn PaymentSendFailure_all_failed_retry_safe(a: crate::c_types::derived::CVec_APIErrorZ) -> PaymentSendFailure {
1399 PaymentSendFailure::AllFailedRetrySafe(a, )
1402 /// Utility method to constructs a new PartialFailure-variant PaymentSendFailure
1403 pub extern "C" fn PaymentSendFailure_partial_failure(results: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ, failed_paths_retry: crate::lightning::routing::router::RouteParameters, payment_id: crate::c_types::ThirtyTwoBytes) -> PaymentSendFailure {
1404 PaymentSendFailure::PartialFailure {
1411 use lightning::ln::channelmanager::PhantomRouteHints as nativePhantomRouteHintsImport;
1412 pub(crate) type nativePhantomRouteHints = nativePhantomRouteHintsImport;
1414 /// Route hints used in constructing invoices for [phantom node payents].
1416 /// [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
1419 pub struct PhantomRouteHints {
1420 /// A pointer to the opaque Rust object.
1422 /// Nearly everywhere, inner must be non-null, however in places where
1423 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1424 pub inner: *mut nativePhantomRouteHints,
1425 /// Indicates that this is the only struct which contains the same pointer.
1427 /// Rust functions which take ownership of an object provided via an argument require
1428 /// this to be true and invalidate the object pointed to by inner.
1432 impl Drop for PhantomRouteHints {
1433 fn drop(&mut self) {
1434 if self.is_owned && !<*mut nativePhantomRouteHints>::is_null(self.inner) {
1435 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1439 /// Frees any resources used by the PhantomRouteHints, if is_owned is set and inner is non-NULL.
1441 pub extern "C" fn PhantomRouteHints_free(this_obj: PhantomRouteHints) { }
1443 /// Used only if an object of this type is returned as a trait impl by a method
1444 pub(crate) extern "C" fn PhantomRouteHints_free_void(this_ptr: *mut c_void) {
1445 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePhantomRouteHints); }
1448 impl PhantomRouteHints {
1449 pub(crate) fn get_native_ref(&self) -> &'static nativePhantomRouteHints {
1450 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1452 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePhantomRouteHints {
1453 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1455 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1456 pub(crate) fn take_inner(mut self) -> *mut nativePhantomRouteHints {
1457 assert!(self.is_owned);
1458 let ret = ObjOps::untweak_ptr(self.inner);
1459 self.inner = core::ptr::null_mut();
1463 /// The list of channels to be included in the invoice route hints.
1465 pub extern "C" fn PhantomRouteHints_get_channels(this_ptr: &PhantomRouteHints) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1466 let mut inner_val = &mut this_ptr.get_native_mut_ref().channels;
1467 let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::ln::channelmanager::ChannelDetails<>) as *mut _) }, is_owned: false } }); };
1468 local_inner_val.into()
1470 /// The list of channels to be included in the invoice route hints.
1472 pub extern "C" fn PhantomRouteHints_set_channels(this_ptr: &mut PhantomRouteHints, mut val: crate::c_types::derived::CVec_ChannelDetailsZ) {
1473 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1474 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val;
1476 /// A fake scid used for representing the phantom node's fake channel in generating the invoice
1479 pub extern "C" fn PhantomRouteHints_get_phantom_scid(this_ptr: &PhantomRouteHints) -> u64 {
1480 let mut inner_val = &mut this_ptr.get_native_mut_ref().phantom_scid;
1483 /// A fake scid used for representing the phantom node's fake channel in generating the invoice
1486 pub extern "C" fn PhantomRouteHints_set_phantom_scid(this_ptr: &mut PhantomRouteHints, mut val: u64) {
1487 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.phantom_scid = val;
1489 /// The pubkey of the real backing node that would ultimately receive the payment.
1491 pub extern "C" fn PhantomRouteHints_get_real_node_pubkey(this_ptr: &PhantomRouteHints) -> crate::c_types::PublicKey {
1492 let mut inner_val = &mut this_ptr.get_native_mut_ref().real_node_pubkey;
1493 crate::c_types::PublicKey::from_rust(&inner_val)
1495 /// The pubkey of the real backing node that would ultimately receive the payment.
1497 pub extern "C" fn PhantomRouteHints_set_real_node_pubkey(this_ptr: &mut PhantomRouteHints, mut val: crate::c_types::PublicKey) {
1498 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.real_node_pubkey = val.into_rust();
1500 /// Constructs a new PhantomRouteHints given each field
1503 pub extern "C" fn PhantomRouteHints_new(mut channels_arg: crate::c_types::derived::CVec_ChannelDetailsZ, mut phantom_scid_arg: u64, mut real_node_pubkey_arg: crate::c_types::PublicKey) -> PhantomRouteHints {
1504 let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1505 PhantomRouteHints { inner: ObjOps::heap_alloc(nativePhantomRouteHints {
1506 channels: local_channels_arg,
1507 phantom_scid: phantom_scid_arg,
1508 real_node_pubkey: real_node_pubkey_arg.into_rust(),
1509 }), is_owned: true }
1511 impl Clone for PhantomRouteHints {
1512 fn clone(&self) -> Self {
1514 inner: if <*mut nativePhantomRouteHints>::is_null(self.inner) { core::ptr::null_mut() } else {
1515 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1521 /// Used only if an object of this type is returned as a trait impl by a method
1522 pub(crate) extern "C" fn PhantomRouteHints_clone_void(this_ptr: *const c_void) -> *mut c_void {
1523 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePhantomRouteHints)).clone() })) as *mut c_void
1526 /// Creates a copy of the PhantomRouteHints
1527 pub extern "C" fn PhantomRouteHints_clone(orig: &PhantomRouteHints) -> PhantomRouteHints {
1530 /// Constructs a new ChannelManager to hold several channels and route between them.
1532 /// This is the main \"logic hub\" for all channel-related actions, and implements
1533 /// ChannelMessageHandler.
1535 /// Non-proportional fees are fixed according to our risk using the provided fee estimator.
1537 /// Users need to notify the new ChannelManager when a new block is connected or
1538 /// disconnected using its `block_connected` and `block_disconnected` methods, starting
1539 /// from after `params.latest_hash`.
1542 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) -> crate::lightning::ln::channelmanager::ChannelManager {
1543 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()) });
1544 crate::lightning::ln::channelmanager::ChannelManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
1547 /// Gets the current configuration applied to all new channels, as
1550 pub extern "C" fn ChannelManager_get_current_default_configuration(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::util::config::UserConfig {
1551 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_current_default_configuration();
1552 crate::lightning::util::config::UserConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::util::config::UserConfig<>) as *mut _) }, is_owned: false }
1555 /// Creates a new outbound channel to the given remote node and with the given value.
1557 /// `user_channel_id` will be provided back as in
1558 /// [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
1559 /// correspond with which `create_channel` call. Note that the `user_channel_id` defaults to 0
1560 /// for inbound channels, so you may wish to avoid using 0 for `user_channel_id` here.
1561 /// `user_channel_id` has no meaning inside of LDK, it is simply copied to events and otherwise
1564 /// Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is
1565 /// greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`.
1567 /// Note that we do not check if you are currently connected to the given peer. If no
1568 /// connection is available, the outbound `open_channel` message may fail to send, resulting in
1569 /// the channel eventually being silently forgotten (dropped on reload).
1571 /// Returns the new Channel's temporary `channel_id`. This ID will appear as
1572 /// [`Event::FundingGenerationReady::temporary_channel_id`] and in
1573 /// [`ChannelDetails::channel_id`] until after
1574 /// [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
1575 /// one derived from the funding transaction's TXID. If the counterparty rejects the channel
1576 /// immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
1578 /// [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
1579 /// [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
1580 /// [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
1582 /// Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
1585 pub extern "C" fn ChannelManager_create_channel(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut their_network_key: crate::c_types::PublicKey, mut channel_value_satoshis: u64, mut push_msat: u64, mut user_channel_id: u64, mut override_config: crate::lightning::util::config::UserConfig) -> crate::c_types::derived::CResult__u832APIErrorZ {
1586 let mut local_override_config = if override_config.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(override_config.take_inner()) } }) };
1587 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_channel(their_network_key.into_rust(), channel_value_satoshis, push_msat, user_channel_id, local_override_config);
1588 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ThirtyTwoBytes { data: o } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
1592 /// Gets the list of open channels, in random order. See ChannelDetail field documentation for
1593 /// more information.
1596 pub extern "C" fn ChannelManager_list_channels(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1597 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_channels();
1598 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1602 /// Gets the list of usable channels, in random order. Useful as an argument to [`find_route`]
1603 /// to ensure non-announced channels are used.
1605 /// These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
1606 /// documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
1609 /// [`find_route`]: crate::routing::router::find_route
1612 pub extern "C" fn ChannelManager_list_usable_channels(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1613 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_usable_channels();
1614 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1618 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
1619 /// will be accepted on the given channel, and after additional timeout/the closing of all
1620 /// pending HTLCs, the channel will be closed on chain.
1622 /// * If we are the channel initiator, we will pay between our [`Background`] and
1623 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
1625 /// * If our counterparty is the channel initiator, we will require a channel closing
1626 /// transaction feerate of at least our [`Background`] feerate or the feerate which
1627 /// would appear on a force-closure transaction, whichever is lower. We will allow our
1628 /// counterparty to pay as much fee as they'd like, however.
1630 /// May generate a SendShutdown message event on success, which should be relayed.
1632 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
1633 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1634 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1637 pub extern "C" fn ChannelManager_close_channel(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, channel_id: *const [u8; 32], mut counterparty_node_id: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1638 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel(unsafe { &*channel_id}, &counterparty_node_id.into_rust());
1639 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() };
1643 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
1644 /// will be accepted on the given channel, and after additional timeout/the closing of all
1645 /// pending HTLCs, the channel will be closed on chain.
1647 /// `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
1648 /// the channel being closed or not:
1649 /// * If we are the channel initiator, we will pay at least this feerate on the closing
1650 /// transaction. The upper-bound is set by
1651 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
1652 /// estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
1653 /// * If our counterparty is the channel initiator, we will refuse to accept a channel closure
1654 /// transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
1655 /// will appear on a force-closure transaction, whichever is lower).
1657 /// May generate a SendShutdown message event on success, which should be relayed.
1659 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
1660 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1661 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1664 pub extern "C" fn ChannelManager_close_channel_with_target_feerate(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, channel_id: *const [u8; 32], mut counterparty_node_id: crate::c_types::PublicKey, mut target_feerate_sats_per_1000_weight: u32) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1665 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel_with_target_feerate(unsafe { &*channel_id}, &counterparty_node_id.into_rust(), target_feerate_sats_per_1000_weight);
1666 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() };
1670 /// Force closes a channel, immediately broadcasting the latest local transaction(s) and
1671 /// rejecting new HTLCs on the given channel. Fails if `channel_id` is unknown to
1672 /// the manager, or if the `counterparty_node_id` isn't the counterparty of the corresponding
1676 pub extern "C" fn ChannelManager_force_close_broadcasting_latest_txn(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, channel_id: *const [u8; 32], mut counterparty_node_id: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1677 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_broadcasting_latest_txn(unsafe { &*channel_id}, &counterparty_node_id.into_rust());
1678 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() };
1682 /// Force closes a channel, rejecting new HTLCs on the given channel but skips broadcasting
1683 /// the latest local transaction(s). Fails if `channel_id` is unknown to the manager, or if the
1684 /// `counterparty_node_id` isn't the counterparty of the corresponding channel.
1686 /// You can always get the latest local transaction(s) to broadcast from
1687 /// [`ChannelMonitor::get_latest_holder_commitment_txn`].
1690 pub extern "C" fn ChannelManager_force_close_without_broadcasting_txn(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, channel_id: *const [u8; 32], mut counterparty_node_id: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1691 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_without_broadcasting_txn(unsafe { &*channel_id}, &counterparty_node_id.into_rust());
1692 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() };
1696 /// Force close all channels, immediately broadcasting the latest local commitment transaction
1697 /// for each to the chain and rejecting new HTLCs on each.
1699 pub extern "C" fn ChannelManager_force_close_all_channels_broadcasting_latest_txn(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
1700 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_all_channels_broadcasting_latest_txn()
1703 /// Force close all channels rejecting new HTLCs on each but without broadcasting the latest
1704 /// local transaction(s).
1706 pub extern "C" fn ChannelManager_force_close_all_channels_without_broadcasting_txn(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
1707 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_all_channels_without_broadcasting_txn()
1710 /// Sends a payment along a given route.
1712 /// Value parameters are provided via the last hop in route, see documentation for RouteHop
1713 /// fields for more info.
1715 /// Note that if the payment_hash already exists elsewhere (eg you're sending a duplicative
1716 /// payment), we don't do anything to stop you! We always try to ensure that if the provided
1717 /// next hop knows the preimage to payment_hash they can claim an additional amount as
1718 /// specified in the last hop in the route! Thus, you should probably do your own
1719 /// payment_preimage tracking (which you should already be doing as they represent \"proof of
1720 /// payment\") and prevent double-sends yourself.
1722 /// May generate SendHTLCs message(s) event on success, which should be relayed.
1724 /// Each path may have a different return value, and PaymentSendValue may return a Vec with
1725 /// each entry matching the corresponding-index entry in the route paths, see
1726 /// PaymentSendFailure for more info.
1728 /// In general, a path may raise:
1729 /// * APIError::RouteError when an invalid route or forwarding parameter (cltv_delta, fee,
1730 /// node public key) is specified.
1731 /// * APIError::ChannelUnavailable if the next-hop channel is not available for updates
1732 /// (including due to previous monitor update failure or new permanent monitor update
1734 /// * APIError::MonitorUpdateFailed if a new monitor update failure prevented sending the
1735 /// relevant updates.
1737 /// Note that depending on the type of the PaymentSendFailure the HTLC may have been
1738 /// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
1739 /// different route unless you intend to pay twice!
1741 /// payment_secret is unrelated to payment_hash (or PaymentPreimage) and exists to authenticate
1742 /// the sender to the recipient and prevent payment-probing (deanonymization) attacks. For
1743 /// newer nodes, it will be provided to you in the invoice. If you do not have one, the Route
1744 /// must not contain multiple paths as multi-path payments require a recipient-provided
1746 /// If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature
1747 /// bit set (either as required or as available). If multiple paths are present in the Route,
1748 /// we assume the invoice had the basic_mpp feature set.
1750 /// Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
1753 pub extern "C" fn ChannelManager_send_payment(this_arg: &crate::lightning::ln::channelmanager::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_PaymentIdPaymentSendFailureZ {
1754 let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentSecret(payment_secret.data) }) };
1755 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_payment(route.get_native_ref(), ::lightning::ln::PaymentHash(payment_hash.data), &local_payment_secret);
1756 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::ln::channelmanager::PaymentSendFailure::native_into(e) }).into() };
1760 /// Retries a payment along the given [`Route`].
1762 /// Errors returned are a superset of those returned from [`send_payment`], so see
1763 /// [`send_payment`] documentation for more details on errors. This method will also error if the
1764 /// retry amount puts the payment more than 10% over the payment's total amount, if the payment
1765 /// for the given `payment_id` cannot be found (likely due to timeout or success), or if
1766 /// further retries have been disabled with [`abandon_payment`].
1768 /// [`send_payment`]: [`ChannelManager::send_payment`]
1769 /// [`abandon_payment`]: [`ChannelManager::abandon_payment`]
1772 pub extern "C" fn ChannelManager_retry_payment(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_NonePaymentSendFailureZ {
1773 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.retry_payment(route.get_native_ref(), ::lightning::ln::channelmanager::PaymentId(payment_id.data));
1774 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() };
1778 /// Signals that no further retries for the given payment will occur.
1780 /// After this method returns, any future calls to [`retry_payment`] for the given `payment_id`
1781 /// will fail with [`PaymentSendFailure::ParameterError`]. If no such event has been generated,
1782 /// an [`Event::PaymentFailed`] event will be generated as soon as there are no remaining
1783 /// pending HTLCs for this payment.
1785 /// Note that calling this method does *not* prevent a payment from succeeding. You must still
1786 /// wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to
1787 /// determine the ultimate status of a payment.
1789 /// [`retry_payment`]: Self::retry_payment
1790 /// [`Event::PaymentFailed`]: events::Event::PaymentFailed
1791 /// [`Event::PaymentSent`]: events::Event::PaymentSent
1793 pub extern "C" fn ChannelManager_abandon_payment(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_id: crate::c_types::ThirtyTwoBytes) {
1794 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.abandon_payment(::lightning::ln::channelmanager::PaymentId(payment_id.data))
1797 /// Send a spontaneous payment, which is a payment that does not require the recipient to have
1798 /// generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
1799 /// the preimage, it must be a cryptographically secure random value that no intermediate node
1800 /// would be able to guess -- otherwise, an intermediate node may claim the payment and it will
1801 /// never reach the recipient.
1803 /// See [`send_payment`] documentation for more details on the return value of this function.
1805 /// Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
1806 /// [`send_payment`] for more information about the risks of duplicate preimage usage.
1808 /// Note that `route` must have exactly one path.
1810 /// [`send_payment`]: Self::send_payment
1812 /// Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None
1815 pub extern "C" fn ChannelManager_send_spontaneous_payment(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_preimage: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ {
1816 let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
1817 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_spontaneous_payment(route.get_native_ref(), local_payment_preimage);
1818 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.0 }, crate::c_types::ThirtyTwoBytes { data: orig_ret_0_1.0 }).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::channelmanager::PaymentSendFailure::native_into(e) }).into() };
1822 /// Send a payment that is probing the given route for liquidity. We calculate the
1823 /// [`PaymentHash`] of probes based on a static secret and a random [`PaymentId`], which allows
1824 /// us to easily discern them from real payments.
1827 pub extern "C" fn ChannelManager_send_probe(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut hops: crate::c_types::derived::CVec_RouteHopZ) -> crate::c_types::derived::CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ {
1828 let mut local_hops = Vec::new(); for mut item in hops.into_rust().drain(..) { local_hops.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1829 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_probe(local_hops);
1830 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.0 }, crate::c_types::ThirtyTwoBytes { data: orig_ret_0_1.0 }).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::channelmanager::PaymentSendFailure::native_into(e) }).into() };
1834 /// Call this upon creation of a funding transaction for the given channel.
1836 /// Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
1837 /// or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
1839 /// Returns [`APIError::APIMisuseError`] if the funding transaction is not final for propagation
1840 /// across the p2p network.
1842 /// Returns [`APIError::ChannelUnavailable`] if a funding transaction has already been provided
1843 /// for the channel or if the channel has been closed as indicated by [`Event::ChannelClosed`].
1845 /// May panic if the output found in the funding transaction is duplicative with some other
1846 /// channel (note that this should be trivially prevented by using unique funding transaction
1847 /// keys per-channel).
1849 /// Do NOT broadcast the funding transaction yourself. When we have safely received our
1850 /// counterparty's signature the funding transaction will automatically be broadcast via the
1851 /// [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
1853 /// Note that this includes RBF or similar transaction replacement strategies - lightning does
1854 /// not currently support replacing a funding transaction on an existing channel. Instead,
1855 /// create a new channel with a conflicting funding transaction.
1857 /// Note to keep the miner incentives aligned in moving the blockchain forward, we recommend
1858 /// the wallet software generating the funding transaction to apply anti-fee sniping as
1859 /// implemented by Bitcoin Core wallet. See <https://bitcoinops.org/en/topics/fee-sniping/>
1860 /// for more details.
1862 /// [`Event::FundingGenerationReady`]: crate::util::events::Event::FundingGenerationReady
1863 /// [`Event::ChannelClosed`]: crate::util::events::Event::ChannelClosed
1866 pub extern "C" fn ChannelManager_funding_transaction_generated(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, temporary_channel_id: *const [u8; 32], mut counterparty_node_id: crate::c_types::PublicKey, mut funding_transaction: crate::c_types::Transaction) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1867 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_transaction_generated(unsafe { &*temporary_channel_id}, &counterparty_node_id.into_rust(), funding_transaction.into_bitcoin());
1868 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() };
1872 /// Regenerates channel_announcements and generates a signed node_announcement from the given
1873 /// arguments, providing them in corresponding events via
1874 /// [`get_and_clear_pending_msg_events`], if at least one public channel has been confirmed
1875 /// on-chain. This effectively re-broadcasts all channel announcements and sends our node
1876 /// announcement to ensure that the lightning P2P network is aware of the channels we have and
1877 /// our network addresses.
1879 /// `rgb` is a node \"color\" and `alias` is a printable human-readable string to describe this
1880 /// node to humans. They carry no in-protocol meaning.
1882 /// `addresses` represent the set (possibly empty) of socket addresses on which this node
1883 /// accepts incoming connections. These will be included in the node_announcement, publicly
1884 /// tying these addresses together and to this node. If you wish to preserve user privacy,
1885 /// addresses should likely contain only Tor Onion addresses.
1887 /// Panics if `addresses` is absurdly large (more than 100).
1889 /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
1891 pub extern "C" fn ChannelManager_broadcast_node_announcement(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut rgb: crate::c_types::ThreeBytes, mut alias: crate::c_types::ThirtyTwoBytes, mut addresses: crate::c_types::derived::CVec_NetAddressZ) {
1892 let mut local_addresses = Vec::new(); for mut item in addresses.into_rust().drain(..) { local_addresses.push( { item.into_native() }); };
1893 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.broadcast_node_announcement(rgb.data, alias.data, local_addresses)
1896 /// Atomically updates the [`ChannelConfig`] for the given channels.
1898 /// Once the updates are applied, each eligible channel (advertised with a known short channel
1899 /// ID and a change in [`forwarding_fee_proportional_millionths`], [`forwarding_fee_base_msat`],
1900 /// or [`cltv_expiry_delta`]) has a [`BroadcastChannelUpdate`] event message generated
1901 /// containing the new [`ChannelUpdate`] message which should be broadcast to the network.
1903 /// Returns [`ChannelUnavailable`] when a channel is not found or an incorrect
1904 /// `counterparty_node_id` is provided.
1906 /// Returns [`APIMisuseError`] when a [`cltv_expiry_delta`] update is to be applied with a value
1907 /// below [`MIN_CLTV_EXPIRY_DELTA`].
1909 /// If an error is returned, none of the updates should be considered applied.
1911 /// [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
1912 /// [`forwarding_fee_base_msat`]: ChannelConfig::forwarding_fee_base_msat
1913 /// [`cltv_expiry_delta`]: ChannelConfig::cltv_expiry_delta
1914 /// [`BroadcastChannelUpdate`]: events::MessageSendEvent::BroadcastChannelUpdate
1915 /// [`ChannelUpdate`]: msgs::ChannelUpdate
1916 /// [`ChannelUnavailable`]: APIError::ChannelUnavailable
1917 /// [`APIMisuseError`]: APIError::APIMisuseError
1920 pub extern "C" fn ChannelManager_update_channel_config(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut counterparty_node_id: crate::c_types::PublicKey, mut channel_ids: crate::c_types::derived::CVec_ThirtyTwoBytesZ, config: &crate::lightning::util::config::ChannelConfig) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1921 let mut local_channel_ids = Vec::new(); for mut item in channel_ids.into_rust().drain(..) { local_channel_ids.push( { item.data }); };
1922 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_config(&counterparty_node_id.into_rust(), &local_channel_ids.iter().map(|a| *a).collect::<Vec<_>>()[..], config.get_native_ref());
1923 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() };
1927 /// Processes HTLCs which are pending waiting on random forward delay.
1929 /// Should only really ever be called in response to a PendingHTLCsForwardable event.
1930 /// Will likely generate further events.
1932 pub extern "C" fn ChannelManager_process_pending_htlc_forwards(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
1933 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_pending_htlc_forwards()
1936 /// Performs actions which should happen on startup and roughly once per minute thereafter.
1938 /// This currently includes:
1939 /// * Increasing or decreasing the on-chain feerate estimates for our outbound channels,
1940 /// * Broadcasting `ChannelUpdate` messages if we've been disconnected from our peer for more
1941 /// than a minute, informing the network that they should no longer attempt to route over
1943 /// * Expiring a channel's previous `ChannelConfig` if necessary to only allow forwarding HTLCs
1944 /// with the current `ChannelConfig`.
1946 /// Note that this may cause reentrancy through `chain::Watch::update_channel` calls or feerate
1947 /// estimate fetches.
1949 pub extern "C" fn ChannelManager_timer_tick_occurred(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
1950 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timer_tick_occurred()
1953 /// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
1954 /// after a PaymentReceived event, failing the HTLC back to its origin and freeing resources
1955 /// along the path (including in our own channel on which we received it).
1957 /// Note that in some cases around unclean shutdown, it is possible the payment may have
1958 /// already been claimed by you via [`ChannelManager::claim_funds`] prior to you seeing (a
1959 /// second copy of) the [`events::Event::PaymentReceived`] event. Alternatively, the payment
1960 /// may have already been failed automatically by LDK if it was nearing its expiration time.
1962 /// While LDK will never claim a payment automatically on your behalf (i.e. without you calling
1963 /// [`ChannelManager::claim_funds`]), you should still monitor for
1964 /// [`events::Event::PaymentClaimed`] events even for payments you intend to fail, especially on
1965 /// startup during which time claims that were in-progress at shutdown may be replayed.
1967 pub extern "C" fn ChannelManager_fail_htlc_backwards(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, payment_hash: *const [u8; 32]) {
1968 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_htlc_backwards(&::lightning::ln::PaymentHash(unsafe { *payment_hash }))
1971 /// Provides a payment preimage in response to [`Event::PaymentReceived`], generating any
1972 /// [`MessageSendEvent`]s needed to claim the payment.
1974 /// Note that calling this method does *not* guarantee that the payment has been claimed. You
1975 /// *must* wait for an [`Event::PaymentClaimed`] event which upon a successful claim will be
1976 /// provided to your [`EventHandler`] when [`process_pending_events`] is next called.
1978 /// Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
1979 /// [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentReceived`
1980 /// event matches your expectation. If you fail to do so and call this method, you may provide
1981 /// the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
1983 /// [`Event::PaymentReceived`]: crate::util::events::Event::PaymentReceived
1984 /// [`Event::PaymentClaimed`]: crate::util::events::Event::PaymentClaimed
1985 /// [`process_pending_events`]: EventsProvider::process_pending_events
1986 /// [`create_inbound_payment`]: Self::create_inbound_payment
1987 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1988 /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
1990 pub extern "C" fn ChannelManager_claim_funds(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_preimage: crate::c_types::ThirtyTwoBytes) {
1991 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.claim_funds(::lightning::ln::PaymentPreimage(payment_preimage.data))
1994 /// Gets the node_id held by this ChannelManager
1997 pub extern "C" fn ChannelManager_get_our_node_id(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::PublicKey {
1998 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_our_node_id();
1999 crate::c_types::PublicKey::from_rust(&ret)
2002 /// Accepts a request to open a channel after a [`Event::OpenChannelRequest`].
2004 /// The `temporary_channel_id` parameter indicates which inbound channel should be accepted,
2005 /// and the `counterparty_node_id` parameter is the id of the peer which has requested to open
2008 /// The `user_channel_id` parameter will be provided back in
2009 /// [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
2010 /// with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
2012 /// Note that this method will return an error and reject the channel, if it requires support
2013 /// for zero confirmations. Instead, `accept_inbound_channel_from_trusted_peer_0conf` must be
2014 /// used to accept such channels.
2016 /// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
2017 /// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
2020 pub extern "C" fn ChannelManager_accept_inbound_channel(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, temporary_channel_id: *const [u8; 32], mut counterparty_node_id: crate::c_types::PublicKey, mut user_channel_id: u64) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
2021 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.accept_inbound_channel(unsafe { &*temporary_channel_id}, &counterparty_node_id.into_rust(), user_channel_id);
2022 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() };
2026 /// Accepts a request to open a channel after a [`events::Event::OpenChannelRequest`], treating
2027 /// it as confirmed immediately.
2029 /// The `user_channel_id` parameter will be provided back in
2030 /// [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
2031 /// with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
2033 /// Unlike [`ChannelManager::accept_inbound_channel`], this method accepts the incoming channel
2034 /// and (if the counterparty agrees), enables forwarding of payments immediately.
2036 /// This fully trusts that the counterparty has honestly and correctly constructed the funding
2037 /// transaction and blindly assumes that it will eventually confirm.
2039 /// If it does not confirm before we decide to close the channel, or if the funding transaction
2040 /// does not pay to the correct script the correct amount, *you will lose funds*.
2042 /// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
2043 /// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
2046 pub extern "C" fn ChannelManager_accept_inbound_channel_from_trusted_peer_0conf(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, temporary_channel_id: *const [u8; 32], mut counterparty_node_id: crate::c_types::PublicKey, mut user_channel_id: u64) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
2047 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.accept_inbound_channel_from_trusted_peer_0conf(unsafe { &*temporary_channel_id}, &counterparty_node_id.into_rust(), user_channel_id);
2048 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() };
2052 /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
2055 /// This differs from [`create_inbound_payment_for_hash`] only in that it generates the
2056 /// [`PaymentHash`] and [`PaymentPreimage`] for you.
2058 /// The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentReceived`], which
2059 /// will have the [`PaymentReceived::payment_preimage`] field filled in. That should then be
2060 /// passed directly to [`claim_funds`].
2062 /// See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
2064 /// Note that a malicious eavesdropper can intuit whether an inbound payment was created by
2065 /// `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
2069 /// If you register an inbound payment with this method, then serialize the `ChannelManager`, then
2070 /// deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
2072 /// Errors if `min_value_msat` is greater than total bitcoin supply.
2074 /// [`claim_funds`]: Self::claim_funds
2075 /// [`PaymentReceived`]: events::Event::PaymentReceived
2076 /// [`PaymentReceived::payment_preimage`]: events::Event::PaymentReceived::payment_preimage
2077 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
2080 pub extern "C" fn ChannelManager_create_inbound_payment(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32) -> crate::c_types::derived::CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ {
2081 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
2082 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment(local_min_value_msat, invoice_expiry_delta_secs);
2083 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.0 }, crate::c_types::ThirtyTwoBytes { data: orig_ret_0_1.0 }).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2087 /// Legacy version of [`create_inbound_payment`]. Use this method if you wish to share
2088 /// serialized state with LDK node(s) running 0.0.103 and earlier.
2090 /// May panic if `invoice_expiry_delta_secs` is greater than one year.
2093 /// This method is deprecated and will be removed soon.
2095 /// [`create_inbound_payment`]: Self::create_inbound_payment
2098 pub extern "C" fn ChannelManager_create_inbound_payment_legacy(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32) -> crate::c_types::derived::CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ {
2099 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
2100 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment_legacy(local_min_value_msat, invoice_expiry_delta_secs);
2101 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.0 }, crate::c_types::ThirtyTwoBytes { data: orig_ret_0_1.0 }).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
2105 /// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
2106 /// stored external to LDK.
2108 /// A [`PaymentReceived`] event will only be generated if the [`PaymentSecret`] matches a
2109 /// payment secret fetched via this method or [`create_inbound_payment`], and which is at least
2110 /// the `min_value_msat` provided here, if one is provided.
2112 /// The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) should be globally unique, though
2113 /// note that LDK will not stop you from registering duplicate payment hashes for inbound
2116 /// `min_value_msat` should be set if the invoice being generated contains a value. Any payment
2117 /// received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
2118 /// before a [`PaymentReceived`] event will be generated, ensuring that we do not provide the
2119 /// sender \"proof-of-payment\" unless they have paid the required amount.
2121 /// `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
2122 /// in excess of the current time. This should roughly match the expiry time set in the invoice.
2123 /// After this many seconds, we will remove the inbound payment, resulting in any attempts to
2124 /// pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
2125 /// invoices when no timeout is set.
2127 /// Note that we use block header time to time-out pending inbound payments (with some margin
2128 /// to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
2129 /// accept a payment and generate a [`PaymentReceived`] event for some time after the expiry.
2130 /// If you need exact expiry semantics, you should enforce them upon receipt of
2131 /// [`PaymentReceived`].
2133 /// Note that invoices generated for inbound payments should have their `min_final_cltv_expiry`
2134 /// set to at least [`MIN_FINAL_CLTV_EXPIRY`].
2136 /// Note that a malicious eavesdropper can intuit whether an inbound payment was created by
2137 /// `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
2141 /// If you register an inbound payment with this method, then serialize the `ChannelManager`, then
2142 /// deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
2144 /// Errors if `min_value_msat` is greater than total bitcoin supply.
2146 /// [`create_inbound_payment`]: Self::create_inbound_payment
2147 /// [`PaymentReceived`]: events::Event::PaymentReceived
2150 pub extern "C" fn ChannelManager_create_inbound_payment_for_hash(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32) -> crate::c_types::derived::CResult_PaymentSecretNoneZ {
2151 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
2152 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment_for_hash(::lightning::ln::PaymentHash(payment_hash.data), local_min_value_msat, invoice_expiry_delta_secs);
2153 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( { () /*e*/ }).into() };
2157 /// Legacy version of [`create_inbound_payment_for_hash`]. Use this method if you wish to share
2158 /// serialized state with LDK node(s) running 0.0.103 and earlier.
2160 /// May panic if `invoice_expiry_delta_secs` is greater than one year.
2163 /// This method is deprecated and will be removed soon.
2165 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
2168 pub extern "C" fn ChannelManager_create_inbound_payment_for_hash_legacy(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32) -> crate::c_types::derived::CResult_PaymentSecretAPIErrorZ {
2169 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
2170 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment_for_hash_legacy(::lightning::ln::PaymentHash(payment_hash.data), local_min_value_msat, invoice_expiry_delta_secs);
2171 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() };
2175 /// Gets an LDK-generated payment preimage from a payment hash and payment secret that were
2176 /// previously returned from [`create_inbound_payment`].
2178 /// [`create_inbound_payment`]: Self::create_inbound_payment
2181 pub extern "C" fn ChannelManager_get_payment_preimage(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut payment_secret: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_PaymentPreimageAPIErrorZ {
2182 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_payment_preimage(::lightning::ln::PaymentHash(payment_hash.data), ::lightning::ln::PaymentSecret(payment_secret.data));
2183 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() };
2187 /// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
2188 /// are used when constructing the phantom invoice's route hints.
2190 /// [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
2193 pub extern "C" fn ChannelManager_get_phantom_scid(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> u64 {
2194 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_phantom_scid();
2198 /// Gets route hints for use in receiving [phantom node payments].
2200 /// [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
2203 pub extern "C" fn ChannelManager_get_phantom_route_hints(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::ln::channelmanager::PhantomRouteHints {
2204 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_phantom_route_hints();
2205 crate::lightning::ln::channelmanager::PhantomRouteHints { inner: ObjOps::heap_alloc(ret), is_owned: true }
2208 impl From<nativeChannelManager> for crate::lightning::util::events::MessageSendEventsProvider {
2209 fn from(obj: nativeChannelManager) -> Self {
2210 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2211 let mut ret = ChannelManager_as_MessageSendEventsProvider(&rust_obj);
2212 // 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
2213 rust_obj.inner = core::ptr::null_mut();
2214 ret.free = Some(ChannelManager_free_void);
2218 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
2219 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
2221 pub extern "C" fn ChannelManager_as_MessageSendEventsProvider(this_arg: &ChannelManager) -> crate::lightning::util::events::MessageSendEventsProvider {
2222 crate::lightning::util::events::MessageSendEventsProvider {
2223 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2225 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
2230 extern "C" fn ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
2231 let mut ret = <nativeChannelManager as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
2232 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
2236 impl From<nativeChannelManager> for crate::lightning::util::events::EventsProvider {
2237 fn from(obj: nativeChannelManager) -> Self {
2238 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2239 let mut ret = ChannelManager_as_EventsProvider(&rust_obj);
2240 // 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
2241 rust_obj.inner = core::ptr::null_mut();
2242 ret.free = Some(ChannelManager_free_void);
2246 /// Constructs a new EventsProvider which calls the relevant methods on this_arg.
2247 /// This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
2249 pub extern "C" fn ChannelManager_as_EventsProvider(this_arg: &ChannelManager) -> crate::lightning::util::events::EventsProvider {
2250 crate::lightning::util::events::EventsProvider {
2251 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2253 process_pending_events: ChannelManager_EventsProvider_process_pending_events,
2257 extern "C" fn ChannelManager_EventsProvider_process_pending_events(this_arg: *const c_void, mut handler: crate::lightning::util::events::EventHandler) {
2258 <nativeChannelManager as lightning::util::events::EventsProvider<>>::process_pending_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, handler)
2261 impl From<nativeChannelManager> for crate::lightning::chain::Listen {
2262 fn from(obj: nativeChannelManager) -> Self {
2263 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2264 let mut ret = ChannelManager_as_Listen(&rust_obj);
2265 // 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
2266 rust_obj.inner = core::ptr::null_mut();
2267 ret.free = Some(ChannelManager_free_void);
2271 /// Constructs a new Listen which calls the relevant methods on this_arg.
2272 /// This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
2274 pub extern "C" fn ChannelManager_as_Listen(this_arg: &ChannelManager) -> crate::lightning::chain::Listen {
2275 crate::lightning::chain::Listen {
2276 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2278 filtered_block_connected: ChannelManager_Listen_filtered_block_connected,
2279 block_connected: ChannelManager_Listen_block_connected,
2280 block_disconnected: ChannelManager_Listen_block_disconnected,
2284 extern "C" fn ChannelManager_Listen_filtered_block_connected(this_arg: *const c_void, header: *const [u8; 80], mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, mut height: u32) {
2285 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 }); };
2286 <nativeChannelManager as lightning::chain::Listen<>>::filtered_block_connected(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)
2288 extern "C" fn ChannelManager_Listen_block_connected(this_arg: *const c_void, mut block: crate::c_types::u8slice, mut height: u32) {
2289 <nativeChannelManager as lightning::chain::Listen<>>::block_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height)
2291 extern "C" fn ChannelManager_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
2292 <nativeChannelManager as lightning::chain::Listen<>>::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
2295 impl From<nativeChannelManager> for crate::lightning::chain::Confirm {
2296 fn from(obj: nativeChannelManager) -> Self {
2297 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2298 let mut ret = ChannelManager_as_Confirm(&rust_obj);
2299 // 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
2300 rust_obj.inner = core::ptr::null_mut();
2301 ret.free = Some(ChannelManager_free_void);
2305 /// Constructs a new Confirm which calls the relevant methods on this_arg.
2306 /// This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
2308 pub extern "C" fn ChannelManager_as_Confirm(this_arg: &ChannelManager) -> crate::lightning::chain::Confirm {
2309 crate::lightning::chain::Confirm {
2310 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2312 transactions_confirmed: ChannelManager_Confirm_transactions_confirmed,
2313 transaction_unconfirmed: ChannelManager_Confirm_transaction_unconfirmed,
2314 best_block_updated: ChannelManager_Confirm_best_block_updated,
2315 get_relevant_txids: ChannelManager_Confirm_get_relevant_txids,
2319 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) {
2320 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 }); };
2321 <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)
2323 extern "C" fn ChannelManager_Confirm_transaction_unconfirmed(this_arg: *const c_void, txid: *const [u8; 32]) {
2324 <nativeChannelManager as lightning::chain::Confirm<>>::transaction_unconfirmed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap())
2326 extern "C" fn ChannelManager_Confirm_best_block_updated(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
2327 <nativeChannelManager as lightning::chain::Confirm<>>::best_block_updated(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
2330 extern "C" fn ChannelManager_Confirm_get_relevant_txids(this_arg: *const c_void) -> crate::c_types::derived::CVec_TxidZ {
2331 let mut ret = <nativeChannelManager as lightning::chain::Confirm<>>::get_relevant_txids(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
2332 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::ThirtyTwoBytes { data: item.into_inner() } }); };
2336 /// Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
2337 /// indicating whether persistence is necessary. Only one listener on
2338 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
2341 /// Note that this method is not available with the `no-std` feature.
2344 pub extern "C" fn ChannelManager_await_persistable_update_timeout(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut max_wait: u64) -> bool {
2345 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.await_persistable_update_timeout(core::time::Duration::from_secs(max_wait));
2349 /// Blocks until ChannelManager needs to be persisted. Only one listener on
2350 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
2353 pub extern "C" fn ChannelManager_await_persistable_update(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) {
2354 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.await_persistable_update()
2357 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
2358 /// [`chain::Confirm`] interfaces.
2361 pub extern "C" fn ChannelManager_current_best_block(this_arg: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::lightning::chain::BestBlock {
2362 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
2363 crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
2366 impl From<nativeChannelManager> for crate::lightning::ln::msgs::ChannelMessageHandler {
2367 fn from(obj: nativeChannelManager) -> Self {
2368 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2369 let mut ret = ChannelManager_as_ChannelMessageHandler(&rust_obj);
2370 // 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
2371 rust_obj.inner = core::ptr::null_mut();
2372 ret.free = Some(ChannelManager_free_void);
2376 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
2377 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
2379 pub extern "C" fn ChannelManager_as_ChannelMessageHandler(this_arg: &ChannelManager) -> crate::lightning::ln::msgs::ChannelMessageHandler {
2380 crate::lightning::ln::msgs::ChannelMessageHandler {
2381 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2383 handle_open_channel: ChannelManager_ChannelMessageHandler_handle_open_channel,
2384 handle_accept_channel: ChannelManager_ChannelMessageHandler_handle_accept_channel,
2385 handle_funding_created: ChannelManager_ChannelMessageHandler_handle_funding_created,
2386 handle_funding_signed: ChannelManager_ChannelMessageHandler_handle_funding_signed,
2387 handle_channel_ready: ChannelManager_ChannelMessageHandler_handle_channel_ready,
2388 handle_shutdown: ChannelManager_ChannelMessageHandler_handle_shutdown,
2389 handle_closing_signed: ChannelManager_ChannelMessageHandler_handle_closing_signed,
2390 handle_update_add_htlc: ChannelManager_ChannelMessageHandler_handle_update_add_htlc,
2391 handle_update_fulfill_htlc: ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc,
2392 handle_update_fail_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_htlc,
2393 handle_update_fail_malformed_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_malformed_htlc,
2394 handle_commitment_signed: ChannelManager_ChannelMessageHandler_handle_commitment_signed,
2395 handle_revoke_and_ack: ChannelManager_ChannelMessageHandler_handle_revoke_and_ack,
2396 handle_update_fee: ChannelManager_ChannelMessageHandler_handle_update_fee,
2397 handle_announcement_signatures: ChannelManager_ChannelMessageHandler_handle_announcement_signatures,
2398 peer_disconnected: ChannelManager_ChannelMessageHandler_peer_disconnected,
2399 peer_connected: ChannelManager_ChannelMessageHandler_peer_connected,
2400 handle_channel_reestablish: ChannelManager_ChannelMessageHandler_handle_channel_reestablish,
2401 handle_channel_update: ChannelManager_ChannelMessageHandler_handle_channel_update,
2402 handle_error: ChannelManager_ChannelMessageHandler_handle_error,
2403 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
2404 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2406 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
2411 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) {
2412 <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()) }, msg.get_native_ref())
2414 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) {
2415 <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()) }, msg.get_native_ref())
2417 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) {
2418 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_created(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2420 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) {
2421 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2423 extern "C" fn ChannelManager_ChannelMessageHandler_handle_channel_ready(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ChannelReady) {
2424 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_channel_ready(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2426 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) {
2427 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_shutdown(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), their_features.get_native_ref(), msg.get_native_ref())
2429 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) {
2430 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_closing_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2432 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) {
2433 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_add_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2435 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) {
2436 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fulfill_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2438 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) {
2439 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fail_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2441 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) {
2442 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fail_malformed_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2444 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) {
2445 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_commitment_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2447 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) {
2448 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_revoke_and_ack(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2450 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) {
2451 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fee(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2453 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) {
2454 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_announcement_signatures(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2456 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) {
2457 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), no_connection_possible)
2459 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) {
2460 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::peer_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), init_msg.get_native_ref())
2462 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) {
2463 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_channel_reestablish(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2465 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) {
2466 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2468 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) {
2469 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
2473 /// Serialize the CounterpartyForwardingInfo object into a byte array which can be read by CounterpartyForwardingInfo_read
2474 pub extern "C" fn CounterpartyForwardingInfo_write(obj: &crate::lightning::ln::channelmanager::CounterpartyForwardingInfo) -> crate::c_types::derived::CVec_u8Z {
2475 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2478 pub(crate) extern "C" fn CounterpartyForwardingInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2479 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCounterpartyForwardingInfo) })
2482 /// Read a CounterpartyForwardingInfo from a byte array, created by CounterpartyForwardingInfo_write
2483 pub extern "C" fn CounterpartyForwardingInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CounterpartyForwardingInfoDecodeErrorZ {
2484 let res: Result<lightning::ln::channelmanager::CounterpartyForwardingInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2485 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channelmanager::CounterpartyForwardingInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
2489 /// Serialize the ChannelCounterparty object into a byte array which can be read by ChannelCounterparty_read
2490 pub extern "C" fn ChannelCounterparty_write(obj: &crate::lightning::ln::channelmanager::ChannelCounterparty) -> crate::c_types::derived::CVec_u8Z {
2491 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2494 pub(crate) extern "C" fn ChannelCounterparty_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2495 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelCounterparty) })
2498 /// Read a ChannelCounterparty from a byte array, created by ChannelCounterparty_write
2499 pub extern "C" fn ChannelCounterparty_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelCounterpartyDecodeErrorZ {
2500 let res: Result<lightning::ln::channelmanager::ChannelCounterparty, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2501 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channelmanager::ChannelCounterparty { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
2505 /// Serialize the ChannelDetails object into a byte array which can be read by ChannelDetails_read
2506 pub extern "C" fn ChannelDetails_write(obj: &crate::lightning::ln::channelmanager::ChannelDetails) -> crate::c_types::derived::CVec_u8Z {
2507 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2510 pub(crate) extern "C" fn ChannelDetails_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2511 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelDetails) })
2514 /// Read a ChannelDetails from a byte array, created by ChannelDetails_write
2515 pub extern "C" fn ChannelDetails_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelDetailsDecodeErrorZ {
2516 let res: Result<lightning::ln::channelmanager::ChannelDetails, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2517 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channelmanager::ChannelDetails { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
2521 /// Serialize the PhantomRouteHints object into a byte array which can be read by PhantomRouteHints_read
2522 pub extern "C" fn PhantomRouteHints_write(obj: &crate::lightning::ln::channelmanager::PhantomRouteHints) -> crate::c_types::derived::CVec_u8Z {
2523 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2526 pub(crate) extern "C" fn PhantomRouteHints_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2527 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePhantomRouteHints) })
2530 /// Read a PhantomRouteHints from a byte array, created by PhantomRouteHints_write
2531 pub extern "C" fn PhantomRouteHints_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PhantomRouteHintsDecodeErrorZ {
2532 let res: Result<lightning::ln::channelmanager::PhantomRouteHints, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2533 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channelmanager::PhantomRouteHints { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
2537 /// Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
2538 pub extern "C" fn ChannelManager_write(obj: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CVec_u8Z {
2539 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2542 pub(crate) extern "C" fn ChannelManager_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2543 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelManager) })
2546 use lightning::ln::channelmanager::ChannelManagerReadArgs as nativeChannelManagerReadArgsImport;
2547 pub(crate) 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>;
2549 /// Arguments for the creation of a ChannelManager that are not deserialized.
2551 /// At a high-level, the process for deserializing a ChannelManager and resuming normal operation
2553 /// 1) Deserialize all stored [`ChannelMonitor`]s.
2554 /// 2) Deserialize the [`ChannelManager`] by filling in this struct and calling:
2555 /// `<(BlockHash, ChannelManager)>::read(reader, args)`
2556 /// This may result in closing some channels if the [`ChannelMonitor`] is newer than the stored
2557 /// [`ChannelManager`] state to ensure no loss of funds. Thus, transactions may be broadcasted.
2558 /// 3) If you are not fetching full blocks, register all relevant [`ChannelMonitor`] outpoints the
2559 /// same way you would handle a [`chain::Filter`] call using
2560 /// [`ChannelMonitor::get_outputs_to_watch`] and [`ChannelMonitor::get_funding_txo`].
2561 /// 4) Reconnect blocks on your [`ChannelMonitor`]s.
2562 /// 5) Disconnect/connect blocks on the [`ChannelManager`].
2563 /// 6) Re-persist the [`ChannelMonitor`]s to ensure the latest state is on disk.
2564 /// Note that if you're using a [`ChainMonitor`] for your [`chain::Watch`] implementation, you
2565 /// will likely accomplish this as a side-effect of calling [`chain::Watch::watch_channel`] in
2567 /// 7) Move the [`ChannelMonitor`]s into your local [`chain::Watch`]. If you're using a
2568 /// [`ChainMonitor`], this is done by calling [`chain::Watch::watch_channel`].
2570 /// Note that the ordering of #4-7 is not of importance, however all four must occur before you
2571 /// call any other methods on the newly-deserialized [`ChannelManager`].
2573 /// Note that because some channels may be closed during deserialization, it is critical that you
2574 /// always deserialize only the latest version of a ChannelManager and ChannelMonitors available to
2575 /// you. If you deserialize an old ChannelManager (during which force-closure transactions may be
2576 /// broadcast), and then later deserialize a newer version of the same ChannelManager (which will
2577 /// not force-close the same channels but consider them live), you may end up revoking a state for
2578 /// which you've already broadcasted the transaction.
2580 /// [`ChainMonitor`]: crate::chain::chainmonitor::ChainMonitor
2583 pub struct ChannelManagerReadArgs {
2584 /// A pointer to the opaque Rust object.
2586 /// Nearly everywhere, inner must be non-null, however in places where
2587 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2588 pub inner: *mut nativeChannelManagerReadArgs,
2589 /// Indicates that this is the only struct which contains the same pointer.
2591 /// Rust functions which take ownership of an object provided via an argument require
2592 /// this to be true and invalidate the object pointed to by inner.
2596 impl Drop for ChannelManagerReadArgs {
2597 fn drop(&mut self) {
2598 if self.is_owned && !<*mut nativeChannelManagerReadArgs>::is_null(self.inner) {
2599 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2603 /// Frees any resources used by the ChannelManagerReadArgs, if is_owned is set and inner is non-NULL.
2605 pub extern "C" fn ChannelManagerReadArgs_free(this_obj: ChannelManagerReadArgs) { }
2607 /// Used only if an object of this type is returned as a trait impl by a method
2608 pub(crate) extern "C" fn ChannelManagerReadArgs_free_void(this_ptr: *mut c_void) {
2609 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManagerReadArgs); }
2612 impl ChannelManagerReadArgs {
2613 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManagerReadArgs {
2614 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2616 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManagerReadArgs {
2617 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2619 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2620 pub(crate) fn take_inner(mut self) -> *mut nativeChannelManagerReadArgs {
2621 assert!(self.is_owned);
2622 let ret = ObjOps::untweak_ptr(self.inner);
2623 self.inner = core::ptr::null_mut();
2627 /// The keys provider which will give us relevant keys. Some keys will be loaded during
2628 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
2631 pub extern "C" fn ChannelManagerReadArgs_get_keys_manager(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::keysinterface::KeysInterface {
2632 let mut inner_val = &mut this_ptr.get_native_mut_ref().keys_manager;
2635 /// The keys provider which will give us relevant keys. Some keys will be loaded during
2636 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
2639 pub extern "C" fn ChannelManagerReadArgs_set_keys_manager(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::keysinterface::KeysInterface) {
2640 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.keys_manager = val;
2642 /// The fee_estimator for use in the ChannelManager in the future.
2644 /// No calls to the FeeEstimator will be made during deserialization.
2646 pub extern "C" fn ChannelManagerReadArgs_get_fee_estimator(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::FeeEstimator {
2647 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_estimator;
2650 /// The fee_estimator for use in the ChannelManager in the future.
2652 /// No calls to the FeeEstimator will be made during deserialization.
2654 pub extern "C" fn ChannelManagerReadArgs_set_fee_estimator(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::FeeEstimator) {
2655 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_estimator = val;
2657 /// The chain::Watch for use in the ChannelManager in the future.
2659 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
2660 /// you have deserialized ChannelMonitors separately and will add them to your
2661 /// chain::Watch after deserializing this ChannelManager.
2663 pub extern "C" fn ChannelManagerReadArgs_get_chain_monitor(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::Watch {
2664 let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_monitor;
2667 /// The chain::Watch for use in the ChannelManager in the future.
2669 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
2670 /// you have deserialized ChannelMonitors separately and will add them to your
2671 /// chain::Watch after deserializing this ChannelManager.
2673 pub extern "C" fn ChannelManagerReadArgs_set_chain_monitor(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::Watch) {
2674 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_monitor = val;
2676 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
2677 /// used to broadcast the latest local commitment transactions of channels which must be
2678 /// force-closed during deserialization.
2680 pub extern "C" fn ChannelManagerReadArgs_get_tx_broadcaster(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::BroadcasterInterface {
2681 let mut inner_val = &mut this_ptr.get_native_mut_ref().tx_broadcaster;
2684 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
2685 /// used to broadcast the latest local commitment transactions of channels which must be
2686 /// force-closed during deserialization.
2688 pub extern "C" fn ChannelManagerReadArgs_set_tx_broadcaster(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::BroadcasterInterface) {
2689 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.tx_broadcaster = val;
2691 /// The Logger for use in the ChannelManager and which may be used to log information during
2692 /// deserialization.
2694 pub extern "C" fn ChannelManagerReadArgs_get_logger(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::util::logger::Logger {
2695 let mut inner_val = &mut this_ptr.get_native_mut_ref().logger;
2698 /// The Logger for use in the ChannelManager and which may be used to log information during
2699 /// deserialization.
2701 pub extern "C" fn ChannelManagerReadArgs_set_logger(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::logger::Logger) {
2702 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.logger = val;
2704 /// Default settings used for new channels. Any existing channels will continue to use the
2705 /// runtime settings which were stored when the ChannelManager was serialized.
2707 pub extern "C" fn ChannelManagerReadArgs_get_default_config(this_ptr: &ChannelManagerReadArgs) -> crate::lightning::util::config::UserConfig {
2708 let mut inner_val = &mut this_ptr.get_native_mut_ref().default_config;
2709 crate::lightning::util::config::UserConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::util::config::UserConfig<>) as *mut _) }, is_owned: false }
2711 /// Default settings used for new channels. Any existing channels will continue to use the
2712 /// runtime settings which were stored when the ChannelManager was serialized.
2714 pub extern "C" fn ChannelManagerReadArgs_set_default_config(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::config::UserConfig) {
2715 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.default_config = *unsafe { Box::from_raw(val.take_inner()) };
2717 /// Simple utility function to create a ChannelManagerReadArgs which creates the monitor
2718 /// HashMap for you. This is primarily useful for C bindings where it is not practical to
2719 /// populate a HashMap directly from C.
2722 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) -> crate::lightning::ln::channelmanager::ChannelManagerReadArgs {
2723 let mut local_channel_monitors = Vec::new(); for mut item in channel_monitors.into_rust().drain(..) { local_channel_monitors.push( { item.get_native_mut_ref() }); };
2724 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);
2725 crate::lightning::ln::channelmanager::ChannelManagerReadArgs { inner: ObjOps::heap_alloc(ret), is_owned: true }
2729 /// Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_write
2730 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 {
2731 let arg_conv = *unsafe { Box::from_raw(arg.take_inner()) };
2732 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);
2733 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: ObjOps::heap_alloc(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: ObjOps::heap_alloc(e), is_owned: true } }).into() };