1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! The top-level channel management and payment tracking stuff lives here.
11 //! The ChannelManager is the main chunk of logic implementing the lightning protocol and is
12 //! responsible for tracking which channels are open, HTLCs are in flight and reestablishing those
13 //! upon reconnect to the relevant peer(s).
15 //! It does not manage routing logic (see routing::router::get_route for that) nor does it manage constructing
16 //! on-chain transactions (it only monitors the chain to watch for any force-closes that might
17 //! imply it needs to fail HTLCs/payments/channels it manages).
20 use alloc::str::FromStr;
21 use core::ffi::c_void;
22 use core::convert::Infallible;
23 use bitcoin::hashes::Hash;
24 use crate::c_types::*;
25 #[cfg(feature="no-std")]
26 use alloc::{vec::Vec, boxed::Box};
30 use alloc::str::FromStr;
31 use core::ffi::c_void;
32 use core::convert::Infallible;
33 use bitcoin::hashes::Hash;
34 use crate::c_types::*;
35 #[cfg(feature="no-std")]
36 use alloc::{vec::Vec, boxed::Box};
40 use lightning::ln::channelmanager::ChannelManager as nativeChannelManagerImport;
41 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>;
43 /// Manager which keeps track of a number of channels and sends messages to the appropriate
44 /// channel, also tracking HTLC preimages and forwarding onion packets appropriately.
46 /// Implements ChannelMessageHandler, handling the multi-channel parts and passing things through
47 /// to individual Channels.
49 /// Implements Writeable to write out all channel state to disk. Implies peer_disconnected() for
50 /// all peers during write/read (though does not modify this instance, only the instance being
51 /// serialized). This will result in any channels which have not yet exchanged funding_created (ie
52 /// called funding_transaction_generated for outbound channels).
54 /// Note that you can be a bit lazier about writing out ChannelManager than you can be with
55 /// ChannelMonitors. With ChannelMonitors you MUST write each monitor update out to disk before
56 /// returning from chain::Watch::watch_/update_channel, with ChannelManagers, writing updates
57 /// happens out-of-band (and will prevent any other ChannelManager operations from occurring during
58 /// the serialization process). If the deserialized version is out-of-date compared to the
59 /// ChannelMonitors passed by reference to read(), those channels will be force-closed based on the
60 /// ChannelMonitor state and no funds will be lost (mod on-chain transaction fees).
62 /// Note that the deserializer is only implemented for (BlockHash, ChannelManager), which
63 /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
64 /// the \"reorg path\" (ie call block_disconnected() until you get to a common block and then call
65 /// block_connected() to step towards your best block) upon deserialization before using the
68 /// Note that ChannelManager is responsible for tracking liveness of its channels and generating
69 /// ChannelUpdate messages informing peers that the channel is temporarily disabled. To avoid
70 /// spam due to quick disconnection/reconnection, updates are not sent until the channel has been
71 /// offline for a full minute. In order to track this, you must call
72 /// timer_tick_occurred roughly once per minute, though it doesn't have to be perfect.
74 /// Rather than using a plain ChannelManager, it is preferable to use either a SimpleArcChannelManager
75 /// a SimpleRefChannelManager, for conciseness. See their documentation for more details, but
76 /// essentially you should default to using a SimpleRefChannelManager, and use a
77 /// SimpleArcChannelManager when you require a ChannelManager with a static lifetime, such as when
78 /// you're using lightning-net-tokio.
81 pub struct ChannelManager {
82 /// A pointer to the opaque Rust object.
84 /// Nearly everywhere, inner must be non-null, however in places where
85 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
86 pub inner: *mut nativeChannelManager,
87 /// Indicates that this is the only struct which contains the same pointer.
89 /// Rust functions which take ownership of an object provided via an argument require
90 /// this to be true and invalidate the object pointed to by inner.
94 impl Drop for ChannelManager {
96 if self.is_owned && !<*mut nativeChannelManager>::is_null(self.inner) {
97 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
101 /// Frees any resources used by the ChannelManager, if is_owned is set and inner is non-NULL.
103 pub extern "C" fn ChannelManager_free(this_obj: ChannelManager) { }
105 /// Used only if an object of this type is returned as a trait impl by a method
106 pub(crate) extern "C" fn ChannelManager_free_void(this_ptr: *mut c_void) {
107 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManager); }
110 impl ChannelManager {
111 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManager {
112 unsafe { &*ObjOps::untweak_ptr(self.inner) }
114 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManager {
115 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
117 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
118 pub(crate) fn take_inner(mut self) -> *mut nativeChannelManager {
119 assert!(self.is_owned);
120 let ret = ObjOps::untweak_ptr(self.inner);
121 self.inner = core::ptr::null_mut();
126 use lightning::ln::channelmanager::ChainParameters as nativeChainParametersImport;
127 pub(crate) type nativeChainParameters = nativeChainParametersImport;
129 /// Chain-related parameters used to construct a new `ChannelManager`.
131 /// Typically, the block-specific parameters are derived from the best block hash for the network,
132 /// as a newly constructed `ChannelManager` will not have created any channels yet. These parameters
133 /// are not needed when deserializing a previously constructed `ChannelManager`.
136 pub struct ChainParameters {
137 /// A pointer to the opaque Rust object.
139 /// Nearly everywhere, inner must be non-null, however in places where
140 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
141 pub inner: *mut nativeChainParameters,
142 /// Indicates that this is the only struct which contains the same pointer.
144 /// Rust functions which take ownership of an object provided via an argument require
145 /// this to be true and invalidate the object pointed to by inner.
149 impl Drop for ChainParameters {
151 if self.is_owned && !<*mut nativeChainParameters>::is_null(self.inner) {
152 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
156 /// Frees any resources used by the ChainParameters, if is_owned is set and inner is non-NULL.
158 pub extern "C" fn ChainParameters_free(this_obj: ChainParameters) { }
160 /// Used only if an object of this type is returned as a trait impl by a method
161 pub(crate) extern "C" fn ChainParameters_free_void(this_ptr: *mut c_void) {
162 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChainParameters); }
165 impl ChainParameters {
166 pub(crate) fn get_native_ref(&self) -> &'static nativeChainParameters {
167 unsafe { &*ObjOps::untweak_ptr(self.inner) }
169 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChainParameters {
170 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
172 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
173 pub(crate) fn take_inner(mut self) -> *mut nativeChainParameters {
174 assert!(self.is_owned);
175 let ret = ObjOps::untweak_ptr(self.inner);
176 self.inner = core::ptr::null_mut();
180 /// The network for determining the `chain_hash` in Lightning messages.
182 pub extern "C" fn ChainParameters_get_network(this_ptr: &ChainParameters) -> crate::bitcoin::network::Network {
183 let mut inner_val = &mut this_ptr.get_native_mut_ref().network;
184 crate::bitcoin::network::Network::from_bitcoin(inner_val)
186 /// The network for determining the `chain_hash` in Lightning messages.
188 pub extern "C" fn ChainParameters_set_network(this_ptr: &mut ChainParameters, mut val: crate::bitcoin::network::Network) {
189 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.network = val.into_bitcoin();
191 /// The hash and height of the latest block successfully connected.
193 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
195 pub extern "C" fn ChainParameters_get_best_block(this_ptr: &ChainParameters) -> crate::lightning::chain::BestBlock {
196 let mut inner_val = &mut this_ptr.get_native_mut_ref().best_block;
197 crate::lightning::chain::BestBlock { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::chain::BestBlock<>) as *mut _) }, is_owned: false }
199 /// The hash and height of the latest block successfully connected.
201 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
203 pub extern "C" fn ChainParameters_set_best_block(this_ptr: &mut ChainParameters, mut val: crate::lightning::chain::BestBlock) {
204 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.best_block = *unsafe { Box::from_raw(val.take_inner()) };
206 /// Constructs a new ChainParameters given each field
209 pub extern "C" fn ChainParameters_new(mut network_arg: crate::bitcoin::network::Network, mut best_block_arg: crate::lightning::chain::BestBlock) -> ChainParameters {
210 ChainParameters { inner: ObjOps::heap_alloc(nativeChainParameters {
211 network: network_arg.into_bitcoin(),
212 best_block: *unsafe { Box::from_raw(best_block_arg.take_inner()) },
215 impl Clone for ChainParameters {
216 fn clone(&self) -> Self {
218 inner: if <*mut nativeChainParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
219 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
225 /// Used only if an object of this type is returned as a trait impl by a method
226 pub(crate) extern "C" fn ChainParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
227 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChainParameters)).clone() })) as *mut c_void
230 /// Creates a copy of the ChainParameters
231 pub extern "C" fn ChainParameters_clone(orig: &ChainParameters) -> ChainParameters {
234 /// The amount of time in blocks we require our counterparty wait to claim their money (ie time
235 /// between when we, or our watchtower, must check for them having broadcast a theft transaction).
237 /// This can be increased (but not decreased) through [`ChannelHandshakeConfig::our_to_self_delay`]
239 /// [`ChannelHandshakeConfig::our_to_self_delay`]: crate::util::config::ChannelHandshakeConfig::our_to_self_delay
242 pub static BREAKDOWN_TIMEOUT: u16 = lightning::ln::channelmanager::BREAKDOWN_TIMEOUT;
243 /// The minimum number of blocks between an inbound HTLC's CLTV and the corresponding outbound
244 /// HTLC's CLTV. The current default represents roughly seven hours of blocks at six blocks/hour.
246 /// This can be increased (but not decreased) through [`ChannelConfig::cltv_expiry_delta`]
248 /// [`ChannelConfig::cltv_expiry_delta`]: crate::util::config::ChannelConfig::cltv_expiry_delta
251 pub static MIN_CLTV_EXPIRY_DELTA: u16 = lightning::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA;
252 /// Minimum CLTV difference between the current block height and received inbound payments.
253 /// Invoices generated for payment to us must set their `min_final_cltv_expiry` field to at least
257 pub static MIN_FINAL_CLTV_EXPIRY: u32 = lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY;
259 use lightning::ln::channelmanager::CounterpartyForwardingInfo as nativeCounterpartyForwardingInfoImport;
260 pub(crate) type nativeCounterpartyForwardingInfo = nativeCounterpartyForwardingInfoImport;
262 /// Information needed for constructing an invoice route hint for this channel.
265 pub struct CounterpartyForwardingInfo {
266 /// A pointer to the opaque Rust object.
268 /// Nearly everywhere, inner must be non-null, however in places where
269 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
270 pub inner: *mut nativeCounterpartyForwardingInfo,
271 /// Indicates that this is the only struct which contains the same pointer.
273 /// Rust functions which take ownership of an object provided via an argument require
274 /// this to be true and invalidate the object pointed to by inner.
278 impl Drop for CounterpartyForwardingInfo {
280 if self.is_owned && !<*mut nativeCounterpartyForwardingInfo>::is_null(self.inner) {
281 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
285 /// Frees any resources used by the CounterpartyForwardingInfo, if is_owned is set and inner is non-NULL.
287 pub extern "C" fn CounterpartyForwardingInfo_free(this_obj: CounterpartyForwardingInfo) { }
289 /// Used only if an object of this type is returned as a trait impl by a method
290 pub(crate) extern "C" fn CounterpartyForwardingInfo_free_void(this_ptr: *mut c_void) {
291 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCounterpartyForwardingInfo); }
294 impl CounterpartyForwardingInfo {
295 pub(crate) fn get_native_ref(&self) -> &'static nativeCounterpartyForwardingInfo {
296 unsafe { &*ObjOps::untweak_ptr(self.inner) }
298 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCounterpartyForwardingInfo {
299 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
301 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
302 pub(crate) fn take_inner(mut self) -> *mut nativeCounterpartyForwardingInfo {
303 assert!(self.is_owned);
304 let ret = ObjOps::untweak_ptr(self.inner);
305 self.inner = core::ptr::null_mut();
309 /// Base routing fee in millisatoshis.
311 pub extern "C" fn CounterpartyForwardingInfo_get_fee_base_msat(this_ptr: &CounterpartyForwardingInfo) -> u32 {
312 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_base_msat;
315 /// Base routing fee in millisatoshis.
317 pub extern "C" fn CounterpartyForwardingInfo_set_fee_base_msat(this_ptr: &mut CounterpartyForwardingInfo, mut val: u32) {
318 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_base_msat = val;
320 /// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
322 pub extern "C" fn CounterpartyForwardingInfo_get_fee_proportional_millionths(this_ptr: &CounterpartyForwardingInfo) -> u32 {
323 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_proportional_millionths;
326 /// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
328 pub extern "C" fn CounterpartyForwardingInfo_set_fee_proportional_millionths(this_ptr: &mut CounterpartyForwardingInfo, mut val: u32) {
329 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_proportional_millionths = val;
331 /// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
332 /// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
333 /// `cltv_expiry_delta` for more details.
335 pub extern "C" fn CounterpartyForwardingInfo_get_cltv_expiry_delta(this_ptr: &CounterpartyForwardingInfo) -> u16 {
336 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
339 /// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
340 /// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
341 /// `cltv_expiry_delta` for more details.
343 pub extern "C" fn CounterpartyForwardingInfo_set_cltv_expiry_delta(this_ptr: &mut CounterpartyForwardingInfo, mut val: u16) {
344 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
346 /// Constructs a new CounterpartyForwardingInfo given each field
349 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 {
350 CounterpartyForwardingInfo { inner: ObjOps::heap_alloc(nativeCounterpartyForwardingInfo {
351 fee_base_msat: fee_base_msat_arg,
352 fee_proportional_millionths: fee_proportional_millionths_arg,
353 cltv_expiry_delta: cltv_expiry_delta_arg,
356 impl Clone for CounterpartyForwardingInfo {
357 fn clone(&self) -> Self {
359 inner: if <*mut nativeCounterpartyForwardingInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
360 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
366 /// Used only if an object of this type is returned as a trait impl by a method
367 pub(crate) extern "C" fn CounterpartyForwardingInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
368 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCounterpartyForwardingInfo)).clone() })) as *mut c_void
371 /// Creates a copy of the CounterpartyForwardingInfo
372 pub extern "C" fn CounterpartyForwardingInfo_clone(orig: &CounterpartyForwardingInfo) -> CounterpartyForwardingInfo {
376 use lightning::ln::channelmanager::ChannelCounterparty as nativeChannelCounterpartyImport;
377 pub(crate) type nativeChannelCounterparty = nativeChannelCounterpartyImport;
379 /// Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
380 /// to better separate parameters.
383 pub struct ChannelCounterparty {
384 /// A pointer to the opaque Rust object.
386 /// Nearly everywhere, inner must be non-null, however in places where
387 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
388 pub inner: *mut nativeChannelCounterparty,
389 /// Indicates that this is the only struct which contains the same pointer.
391 /// Rust functions which take ownership of an object provided via an argument require
392 /// this to be true and invalidate the object pointed to by inner.
396 impl Drop for ChannelCounterparty {
398 if self.is_owned && !<*mut nativeChannelCounterparty>::is_null(self.inner) {
399 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
403 /// Frees any resources used by the ChannelCounterparty, if is_owned is set and inner is non-NULL.
405 pub extern "C" fn ChannelCounterparty_free(this_obj: ChannelCounterparty) { }
407 /// Used only if an object of this type is returned as a trait impl by a method
408 pub(crate) extern "C" fn ChannelCounterparty_free_void(this_ptr: *mut c_void) {
409 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelCounterparty); }
412 impl ChannelCounterparty {
413 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelCounterparty {
414 unsafe { &*ObjOps::untweak_ptr(self.inner) }
416 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelCounterparty {
417 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
419 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
420 pub(crate) fn take_inner(mut self) -> *mut nativeChannelCounterparty {
421 assert!(self.is_owned);
422 let ret = ObjOps::untweak_ptr(self.inner);
423 self.inner = core::ptr::null_mut();
427 /// The node_id of our counterparty
429 pub extern "C" fn ChannelCounterparty_get_node_id(this_ptr: &ChannelCounterparty) -> crate::c_types::PublicKey {
430 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_id;
431 crate::c_types::PublicKey::from_rust(&inner_val)
433 /// The node_id of our counterparty
435 pub extern "C" fn ChannelCounterparty_set_node_id(this_ptr: &mut ChannelCounterparty, mut val: crate::c_types::PublicKey) {
436 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_id = val.into_rust();
438 /// The Features the channel counterparty provided upon last connection.
439 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
440 /// many routing-relevant features are present in the init context.
442 pub extern "C" fn ChannelCounterparty_get_features(this_ptr: &ChannelCounterparty) -> crate::lightning::ln::features::InitFeatures {
443 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
444 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 }
446 /// The Features the channel counterparty provided upon last connection.
447 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
448 /// many routing-relevant features are present in the init context.
450 pub extern "C" fn ChannelCounterparty_set_features(this_ptr: &mut ChannelCounterparty, mut val: crate::lightning::ln::features::InitFeatures) {
451 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
453 /// The value, in satoshis, that must always be held in the channel for our counterparty. This
454 /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
455 /// claiming at least this value on chain.
457 /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
459 /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
461 pub extern "C" fn ChannelCounterparty_get_unspendable_punishment_reserve(this_ptr: &ChannelCounterparty) -> u64 {
462 let mut inner_val = &mut this_ptr.get_native_mut_ref().unspendable_punishment_reserve;
465 /// The value, in satoshis, that must always be held in the channel for our counterparty. This
466 /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
467 /// claiming at least this value on chain.
469 /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
471 /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
473 pub extern "C" fn ChannelCounterparty_set_unspendable_punishment_reserve(this_ptr: &mut ChannelCounterparty, mut val: u64) {
474 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = val;
476 /// Information on the fees and requirements that the counterparty requires when forwarding
477 /// payments to us through this channel.
479 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
481 pub extern "C" fn ChannelCounterparty_get_forwarding_info(this_ptr: &ChannelCounterparty) -> crate::lightning::ln::channelmanager::CounterpartyForwardingInfo {
482 let mut inner_val = &mut this_ptr.get_native_mut_ref().forwarding_info;
483 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 };
486 /// Information on the fees and requirements that the counterparty requires when forwarding
487 /// payments to us through this channel.
489 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
491 pub extern "C" fn ChannelCounterparty_set_forwarding_info(this_ptr: &mut ChannelCounterparty, mut val: crate::lightning::ln::channelmanager::CounterpartyForwardingInfo) {
492 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
493 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.forwarding_info = local_val;
495 /// Constructs a new ChannelCounterparty given each field
498 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) -> ChannelCounterparty {
499 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()) } }) };
500 ChannelCounterparty { inner: ObjOps::heap_alloc(nativeChannelCounterparty {
501 node_id: node_id_arg.into_rust(),
502 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
503 unspendable_punishment_reserve: unspendable_punishment_reserve_arg,
504 forwarding_info: local_forwarding_info_arg,
507 impl Clone for ChannelCounterparty {
508 fn clone(&self) -> Self {
510 inner: if <*mut nativeChannelCounterparty>::is_null(self.inner) { core::ptr::null_mut() } else {
511 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
517 /// Used only if an object of this type is returned as a trait impl by a method
518 pub(crate) extern "C" fn ChannelCounterparty_clone_void(this_ptr: *const c_void) -> *mut c_void {
519 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelCounterparty)).clone() })) as *mut c_void
522 /// Creates a copy of the ChannelCounterparty
523 pub extern "C" fn ChannelCounterparty_clone(orig: &ChannelCounterparty) -> ChannelCounterparty {
527 use lightning::ln::channelmanager::ChannelDetails as nativeChannelDetailsImport;
528 pub(crate) type nativeChannelDetails = nativeChannelDetailsImport;
530 /// Details of a channel, as returned by ChannelManager::list_channels and ChannelManager::list_usable_channels
533 pub struct ChannelDetails {
534 /// A pointer to the opaque Rust object.
536 /// Nearly everywhere, inner must be non-null, however in places where
537 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
538 pub inner: *mut nativeChannelDetails,
539 /// Indicates that this is the only struct which contains the same pointer.
541 /// Rust functions which take ownership of an object provided via an argument require
542 /// this to be true and invalidate the object pointed to by inner.
546 impl Drop for ChannelDetails {
548 if self.is_owned && !<*mut nativeChannelDetails>::is_null(self.inner) {
549 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
553 /// Frees any resources used by the ChannelDetails, if is_owned is set and inner is non-NULL.
555 pub extern "C" fn ChannelDetails_free(this_obj: ChannelDetails) { }
557 /// Used only if an object of this type is returned as a trait impl by a method
558 pub(crate) extern "C" fn ChannelDetails_free_void(this_ptr: *mut c_void) {
559 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelDetails); }
562 impl ChannelDetails {
563 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelDetails {
564 unsafe { &*ObjOps::untweak_ptr(self.inner) }
566 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelDetails {
567 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
569 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
570 pub(crate) fn take_inner(mut self) -> *mut nativeChannelDetails {
571 assert!(self.is_owned);
572 let ret = ObjOps::untweak_ptr(self.inner);
573 self.inner = core::ptr::null_mut();
577 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
578 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
579 /// Note that this means this value is *not* persistent - it can change once during the
580 /// lifetime of the channel.
582 pub extern "C" fn ChannelDetails_get_channel_id(this_ptr: &ChannelDetails) -> *const [u8; 32] {
583 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id;
586 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
587 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
588 /// Note that this means this value is *not* persistent - it can change once during the
589 /// lifetime of the channel.
591 pub extern "C" fn ChannelDetails_set_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::ThirtyTwoBytes) {
592 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = val.data;
594 /// Parameters which apply to our counterparty. See individual fields for more information.
596 pub extern "C" fn ChannelDetails_get_counterparty(this_ptr: &ChannelDetails) -> crate::lightning::ln::channelmanager::ChannelCounterparty {
597 let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty;
598 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 }
600 /// Parameters which apply to our counterparty. See individual fields for more information.
602 pub extern "C" fn ChannelDetails_set_counterparty(this_ptr: &mut ChannelDetails, mut val: crate::lightning::ln::channelmanager::ChannelCounterparty) {
603 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty = *unsafe { Box::from_raw(val.take_inner()) };
605 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
606 /// our counterparty already.
608 /// Note that, if this has been set, `channel_id` will be equivalent to
609 /// `funding_txo.unwrap().to_channel_id()`.
611 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
613 pub extern "C" fn ChannelDetails_get_funding_txo(this_ptr: &ChannelDetails) -> crate::lightning::chain::transaction::OutPoint {
614 let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_txo;
615 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 };
618 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
619 /// our counterparty already.
621 /// Note that, if this has been set, `channel_id` will be equivalent to
622 /// `funding_txo.unwrap().to_channel_id()`.
624 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
626 pub extern "C" fn ChannelDetails_set_funding_txo(this_ptr: &mut ChannelDetails, mut val: crate::lightning::chain::transaction::OutPoint) {
627 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
628 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_txo = local_val;
630 /// The position of the funding transaction in the chain. None if the funding transaction has
631 /// not yet been confirmed and the channel fully opened.
633 pub extern "C" fn ChannelDetails_get_short_channel_id(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
634 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
635 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() }) };
638 /// The position of the funding transaction in the chain. None if the funding transaction has
639 /// not yet been confirmed and the channel fully opened.
641 pub extern "C" fn ChannelDetails_set_short_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
642 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
643 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = local_val;
645 /// The value, in satoshis, of this channel as appears in the funding output
647 pub extern "C" fn ChannelDetails_get_channel_value_satoshis(this_ptr: &ChannelDetails) -> u64 {
648 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
651 /// The value, in satoshis, of this channel as appears in the funding output
653 pub extern "C" fn ChannelDetails_set_channel_value_satoshis(this_ptr: &mut ChannelDetails, mut val: u64) {
654 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
656 /// The value, in satoshis, that must always be held in the channel for us. This value ensures
657 /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
658 /// this value on chain.
660 /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
662 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
664 /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
666 pub extern "C" fn ChannelDetails_get_unspendable_punishment_reserve(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
667 let mut inner_val = &mut this_ptr.get_native_mut_ref().unspendable_punishment_reserve;
668 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() }) };
671 /// The value, in satoshis, that must always be held in the channel for us. This value ensures
672 /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
673 /// this value on chain.
675 /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
677 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
679 /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
681 pub extern "C" fn ChannelDetails_set_unspendable_punishment_reserve(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
682 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
683 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = local_val;
685 /// The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound.
687 pub extern "C" fn ChannelDetails_get_user_channel_id(this_ptr: &ChannelDetails) -> u64 {
688 let mut inner_val = &mut this_ptr.get_native_mut_ref().user_channel_id;
691 /// The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound.
693 pub extern "C" fn ChannelDetails_set_user_channel_id(this_ptr: &mut ChannelDetails, mut val: u64) {
694 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.user_channel_id = val;
696 /// Our total balance. This is the amount we would get if we close the channel.
697 /// This value is not exact. Due to various in-flight changes and feerate changes, exactly this
698 /// amount is not likely to be recoverable on close.
700 /// This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose
701 /// balance is not available for inclusion in new outbound HTLCs). This further does not include
702 /// any pending outgoing HTLCs which are awaiting some other resolution to be sent.
703 /// This does not consider any on-chain fees.
705 /// See also [`ChannelDetails::outbound_capacity_msat`]
707 pub extern "C" fn ChannelDetails_get_balance_msat(this_ptr: &ChannelDetails) -> u64 {
708 let mut inner_val = &mut this_ptr.get_native_mut_ref().balance_msat;
711 /// Our total balance. This is the amount we would get if we close the channel.
712 /// This value is not exact. Due to various in-flight changes and feerate changes, exactly this
713 /// amount is not likely to be recoverable on close.
715 /// This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose
716 /// balance is not available for inclusion in new outbound HTLCs). This further does not include
717 /// any pending outgoing HTLCs which are awaiting some other resolution to be sent.
718 /// This does not consider any on-chain fees.
720 /// See also [`ChannelDetails::outbound_capacity_msat`]
722 pub extern "C" fn ChannelDetails_set_balance_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
723 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.balance_msat = val;
725 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
726 /// any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
727 /// available for inclusion in new outbound HTLCs). This further does not include any pending
728 /// outgoing HTLCs which are awaiting some other resolution to be sent.
730 /// See also [`ChannelDetails::balance_msat`]
732 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
733 /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
734 /// should be able to spend nearly this amount.
736 pub extern "C" fn ChannelDetails_get_outbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
737 let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_capacity_msat;
740 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
741 /// any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
742 /// available for inclusion in new outbound HTLCs). This further does not include any pending
743 /// outgoing HTLCs which are awaiting some other resolution to be sent.
745 /// See also [`ChannelDetails::balance_msat`]
747 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
748 /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
749 /// should be able to spend nearly this amount.
751 pub extern "C" fn ChannelDetails_set_outbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
752 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_capacity_msat = val;
754 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
755 /// include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
756 /// available for inclusion in new inbound HTLCs).
757 /// Note that there are some corner cases not fully handled here, so the actual available
758 /// inbound capacity may be slightly higher than this.
760 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
761 /// counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
762 /// However, our counterparty should be able to spend nearly this amount.
764 pub extern "C" fn ChannelDetails_get_inbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
765 let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_capacity_msat;
768 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
769 /// include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
770 /// available for inclusion in new inbound HTLCs).
771 /// Note that there are some corner cases not fully handled here, so the actual available
772 /// inbound capacity may be slightly higher than this.
774 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
775 /// counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
776 /// However, our counterparty should be able to spend nearly this amount.
778 pub extern "C" fn ChannelDetails_set_inbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
779 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_capacity_msat = val;
781 /// The number of required confirmations on the funding transaction before the funding will be
782 /// considered \"locked\". This number is selected by the channel fundee (i.e. us if
783 /// [`is_outbound`] is *not* set), and can be selected for inbound channels with
784 /// [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
785 /// [`ChannelHandshakeLimits::max_minimum_depth`].
787 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
789 /// [`is_outbound`]: ChannelDetails::is_outbound
790 /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
791 /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
793 pub extern "C" fn ChannelDetails_get_confirmations_required(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u32Z {
794 let mut inner_val = &mut this_ptr.get_native_mut_ref().confirmations_required;
795 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() }) };
798 /// The number of required confirmations on the funding transaction before the funding will be
799 /// considered \"locked\". This number is selected by the channel fundee (i.e. us if
800 /// [`is_outbound`] is *not* set), and can be selected for inbound channels with
801 /// [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
802 /// [`ChannelHandshakeLimits::max_minimum_depth`].
804 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
806 /// [`is_outbound`]: ChannelDetails::is_outbound
807 /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
808 /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
810 pub extern "C" fn ChannelDetails_set_confirmations_required(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u32Z) {
811 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
812 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.confirmations_required = local_val;
814 /// The number of blocks (after our commitment transaction confirms) that we will need to wait
815 /// until we can claim our funds after we force-close the channel. During this time our
816 /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
817 /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any
818 /// time to claim our non-HTLC-encumbered funds.
820 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
822 pub extern "C" fn ChannelDetails_get_force_close_spend_delay(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u16Z {
823 let mut inner_val = &mut this_ptr.get_native_mut_ref().force_close_spend_delay;
824 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() }) };
827 /// The number of blocks (after our commitment transaction confirms) that we will need to wait
828 /// until we can claim our funds after we force-close the channel. During this time our
829 /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
830 /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any
831 /// time to claim our non-HTLC-encumbered funds.
833 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
835 pub extern "C" fn ChannelDetails_set_force_close_spend_delay(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u16Z) {
836 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
837 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.force_close_spend_delay = local_val;
839 /// True if the channel was initiated (and thus funded) by us.
841 pub extern "C" fn ChannelDetails_get_is_outbound(this_ptr: &ChannelDetails) -> bool {
842 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_outbound;
845 /// True if the channel was initiated (and thus funded) by us.
847 pub extern "C" fn ChannelDetails_set_is_outbound(this_ptr: &mut ChannelDetails, mut val: bool) {
848 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_outbound = val;
850 /// True if the channel is confirmed, funding_locked messages have been exchanged, and the
851 /// channel is not currently being shut down. `funding_locked` message exchange implies the
852 /// required confirmation count has been reached (and we were connected to the peer at some
853 /// point after the funding transaction received enough confirmations). The required
854 /// confirmation count is provided in [`confirmations_required`].
856 /// [`confirmations_required`]: ChannelDetails::confirmations_required
858 pub extern "C" fn ChannelDetails_get_is_funding_locked(this_ptr: &ChannelDetails) -> bool {
859 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_funding_locked;
862 /// True if the channel is confirmed, funding_locked messages have been exchanged, and the
863 /// channel is not currently being shut down. `funding_locked` message exchange implies the
864 /// required confirmation count has been reached (and we were connected to the peer at some
865 /// point after the funding transaction received enough confirmations). The required
866 /// confirmation count is provided in [`confirmations_required`].
868 /// [`confirmations_required`]: ChannelDetails::confirmations_required
870 pub extern "C" fn ChannelDetails_set_is_funding_locked(this_ptr: &mut ChannelDetails, mut val: bool) {
871 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_funding_locked = val;
873 /// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
874 /// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
876 /// This is a strict superset of `is_funding_locked`.
878 pub extern "C" fn ChannelDetails_get_is_usable(this_ptr: &ChannelDetails) -> bool {
879 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_usable;
882 /// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
883 /// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
885 /// This is a strict superset of `is_funding_locked`.
887 pub extern "C" fn ChannelDetails_set_is_usable(this_ptr: &mut ChannelDetails, mut val: bool) {
888 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_usable = val;
890 /// True if this channel is (or will be) publicly-announced.
892 pub extern "C" fn ChannelDetails_get_is_public(this_ptr: &ChannelDetails) -> bool {
893 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_public;
896 /// True if this channel is (or will be) publicly-announced.
898 pub extern "C" fn ChannelDetails_set_is_public(this_ptr: &mut ChannelDetails, mut val: bool) {
899 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_public = val;
901 /// Constructs a new ChannelDetails given each field
904 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 short_channel_id_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 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_funding_locked_arg: bool, mut is_usable_arg: bool, mut is_public_arg: bool) -> ChannelDetails {
905 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()) } }) };
906 let mut local_short_channel_id_arg = if short_channel_id_arg.is_some() { Some( { short_channel_id_arg.take() }) } else { None };
907 let mut local_unspendable_punishment_reserve_arg = if unspendable_punishment_reserve_arg.is_some() { Some( { unspendable_punishment_reserve_arg.take() }) } else { None };
908 let mut local_confirmations_required_arg = if confirmations_required_arg.is_some() { Some( { confirmations_required_arg.take() }) } else { None };
909 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 };
910 ChannelDetails { inner: ObjOps::heap_alloc(nativeChannelDetails {
911 channel_id: channel_id_arg.data,
912 counterparty: *unsafe { Box::from_raw(counterparty_arg.take_inner()) },
913 funding_txo: local_funding_txo_arg,
914 short_channel_id: local_short_channel_id_arg,
915 channel_value_satoshis: channel_value_satoshis_arg,
916 unspendable_punishment_reserve: local_unspendable_punishment_reserve_arg,
917 user_channel_id: user_channel_id_arg,
918 balance_msat: balance_msat_arg,
919 outbound_capacity_msat: outbound_capacity_msat_arg,
920 inbound_capacity_msat: inbound_capacity_msat_arg,
921 confirmations_required: local_confirmations_required_arg,
922 force_close_spend_delay: local_force_close_spend_delay_arg,
923 is_outbound: is_outbound_arg,
924 is_funding_locked: is_funding_locked_arg,
925 is_usable: is_usable_arg,
926 is_public: is_public_arg,
929 impl Clone for ChannelDetails {
930 fn clone(&self) -> Self {
932 inner: if <*mut nativeChannelDetails>::is_null(self.inner) { core::ptr::null_mut() } else {
933 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
939 /// Used only if an object of this type is returned as a trait impl by a method
940 pub(crate) extern "C" fn ChannelDetails_clone_void(this_ptr: *const c_void) -> *mut c_void {
941 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelDetails)).clone() })) as *mut c_void
944 /// Creates a copy of the ChannelDetails
945 pub extern "C" fn ChannelDetails_clone(orig: &ChannelDetails) -> ChannelDetails {
948 /// If a payment fails to send, it can be in one of several states. This enum is returned as the
949 /// Err() type describing which state the payment is in, see the description of individual enum
954 pub enum PaymentSendFailure {
955 /// A parameter which was passed to send_payment was invalid, preventing us from attempting to
956 /// send the payment at all. No channel state has been changed or messages sent to peers, and
957 /// once you've changed the parameter at error, you can freely retry the payment in full.
958 ParameterError(crate::lightning::util::errors::APIError),
959 /// A parameter in a single path which was passed to send_payment was invalid, preventing us
960 /// from attempting to send the payment at all. No channel state has been changed or messages
961 /// sent to peers, and once you've changed the parameter at error, you can freely retry the
964 /// The results here are ordered the same as the paths in the route object which was passed to
966 PathParameterError(crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ),
967 /// All paths which were attempted failed to send, with no channel state change taking place.
968 /// You can freely retry the payment in full (though you probably want to do so over different
969 /// paths than the ones selected).
970 AllFailedRetrySafe(crate::c_types::derived::CVec_APIErrorZ),
971 /// Some paths which were attempted failed to send, though possibly not all. At least some
972 /// paths have irrevocably committed to the HTLC and retrying the payment in full would result
973 /// in over-/re-payment.
975 /// The results here are ordered the same as the paths in the route object which was passed to
976 /// send_payment, and any Errs which are not APIError::MonitorUpdateFailed can be safely
977 /// retried (though there is currently no API with which to do so).
979 /// Any entries which contain Err(APIError::MonitorUpdateFailed) or Ok(()) MUST NOT be retried
980 /// as they will result in over-/re-payment. These HTLCs all either successfully sent (in the
981 /// case of Ok(())) or will send once channel_monitor_updated is called on the next-hop channel
982 /// with the latest update_id.
984 /// The errors themselves, in the same order as the route hops.
985 results: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ,
986 /// If some paths failed without irrevocably committing to the new HTLC(s), this will
987 /// contain a [`RouteParameters`] object which can be used to calculate a new route that
988 /// will pay all remaining unpaid balance.
990 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
991 failed_paths_retry: crate::lightning::routing::router::RouteParameters,
992 /// The payment id for the payment, which is now at least partially pending.
993 payment_id: crate::c_types::ThirtyTwoBytes,
996 use lightning::ln::channelmanager::PaymentSendFailure as nativePaymentSendFailure;
997 impl PaymentSendFailure {
999 pub(crate) fn to_native(&self) -> nativePaymentSendFailure {
1001 PaymentSendFailure::ParameterError (ref a, ) => {
1002 let mut a_nonref = (*a).clone();
1003 nativePaymentSendFailure::ParameterError (
1004 a_nonref.into_native(),
1007 PaymentSendFailure::PathParameterError (ref a, ) => {
1008 let mut a_nonref = (*a).clone();
1009 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 }); };
1010 nativePaymentSendFailure::PathParameterError (
1014 PaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
1015 let mut a_nonref = (*a).clone();
1016 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { item.into_native() }); };
1017 nativePaymentSendFailure::AllFailedRetrySafe (
1021 PaymentSendFailure::PartialFailure {ref results, ref failed_paths_retry, ref payment_id, } => {
1022 let mut results_nonref = (*results).clone();
1023 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 }); };
1024 let mut failed_paths_retry_nonref = (*failed_paths_retry).clone();
1025 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()) } }) };
1026 let mut payment_id_nonref = (*payment_id).clone();
1027 nativePaymentSendFailure::PartialFailure {
1028 results: local_results_nonref,
1029 failed_paths_retry: local_failed_paths_retry_nonref,
1030 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1036 pub(crate) fn into_native(self) -> nativePaymentSendFailure {
1038 PaymentSendFailure::ParameterError (mut a, ) => {
1039 nativePaymentSendFailure::ParameterError (
1043 PaymentSendFailure::PathParameterError (mut a, ) => {
1044 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 }); };
1045 nativePaymentSendFailure::PathParameterError (
1049 PaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
1050 let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { item.into_native() }); };
1051 nativePaymentSendFailure::AllFailedRetrySafe (
1055 PaymentSendFailure::PartialFailure {mut results, mut failed_paths_retry, mut payment_id, } => {
1056 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 }); };
1057 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()) } }) };
1058 nativePaymentSendFailure::PartialFailure {
1059 results: local_results,
1060 failed_paths_retry: local_failed_paths_retry,
1061 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1067 pub(crate) fn from_native(native: &nativePaymentSendFailure) -> Self {
1069 nativePaymentSendFailure::ParameterError (ref a, ) => {
1070 let mut a_nonref = (*a).clone();
1071 PaymentSendFailure::ParameterError (
1072 crate::lightning::util::errors::APIError::native_into(a_nonref),
1075 nativePaymentSendFailure::PathParameterError (ref a, ) => {
1076 let mut a_nonref = (*a).clone();
1077 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 }); };
1078 PaymentSendFailure::PathParameterError (
1079 local_a_nonref.into(),
1082 nativePaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
1083 let mut a_nonref = (*a).clone();
1084 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) }); };
1085 PaymentSendFailure::AllFailedRetrySafe (
1086 local_a_nonref.into(),
1089 nativePaymentSendFailure::PartialFailure {ref results, ref failed_paths_retry, ref payment_id, } => {
1090 let mut results_nonref = (*results).clone();
1091 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 }); };
1092 let mut failed_paths_retry_nonref = (*failed_paths_retry).clone();
1093 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 };
1094 let mut payment_id_nonref = (*payment_id).clone();
1095 PaymentSendFailure::PartialFailure {
1096 results: local_results_nonref.into(),
1097 failed_paths_retry: local_failed_paths_retry_nonref,
1098 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1104 pub(crate) fn native_into(native: nativePaymentSendFailure) -> Self {
1106 nativePaymentSendFailure::ParameterError (mut a, ) => {
1107 PaymentSendFailure::ParameterError (
1108 crate::lightning::util::errors::APIError::native_into(a),
1111 nativePaymentSendFailure::PathParameterError (mut a, ) => {
1112 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 }); };
1113 PaymentSendFailure::PathParameterError (
1117 nativePaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
1118 let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { crate::lightning::util::errors::APIError::native_into(item) }); };
1119 PaymentSendFailure::AllFailedRetrySafe (
1123 nativePaymentSendFailure::PartialFailure {mut results, mut failed_paths_retry, mut payment_id, } => {
1124 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 }); };
1125 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 };
1126 PaymentSendFailure::PartialFailure {
1127 results: local_results.into(),
1128 failed_paths_retry: local_failed_paths_retry,
1129 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1135 /// Frees any resources used by the PaymentSendFailure
1137 pub extern "C" fn PaymentSendFailure_free(this_ptr: PaymentSendFailure) { }
1138 /// Creates a copy of the PaymentSendFailure
1140 pub extern "C" fn PaymentSendFailure_clone(orig: &PaymentSendFailure) -> PaymentSendFailure {
1144 /// Utility method to constructs a new ParameterError-variant PaymentSendFailure
1145 pub extern "C" fn PaymentSendFailure_parameter_error(a: crate::lightning::util::errors::APIError) -> PaymentSendFailure {
1146 PaymentSendFailure::ParameterError(a, )
1149 /// Utility method to constructs a new PathParameterError-variant PaymentSendFailure
1150 pub extern "C" fn PaymentSendFailure_path_parameter_error(a: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ) -> PaymentSendFailure {
1151 PaymentSendFailure::PathParameterError(a, )
1154 /// Utility method to constructs a new AllFailedRetrySafe-variant PaymentSendFailure
1155 pub extern "C" fn PaymentSendFailure_all_failed_retry_safe(a: crate::c_types::derived::CVec_APIErrorZ) -> PaymentSendFailure {
1156 PaymentSendFailure::AllFailedRetrySafe(a, )
1159 /// Utility method to constructs a new PartialFailure-variant PaymentSendFailure
1160 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 {
1161 PaymentSendFailure::PartialFailure {
1167 /// Constructs a new ChannelManager to hold several channels and route between them.
1169 /// This is the main \"logic hub\" for all channel-related actions, and implements
1170 /// ChannelMessageHandler.
1172 /// Non-proportional fees are fixed according to our risk using the provided fee estimator.
1174 /// panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`!
1176 /// Users need to notify the new ChannelManager when a new block is connected or
1177 /// disconnected using its `block_connected` and `block_disconnected` methods, starting
1178 /// from after `params.latest_hash`.
1181 pub extern "C" fn ChannelManager_new(mut fee_est: crate::lightning::chain::chaininterface::FeeEstimator, mut chain_monitor: crate::lightning::chain::Watch, mut tx_broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut logger: crate::lightning::util::logger::Logger, mut keys_manager: crate::lightning::chain::keysinterface::KeysInterface, mut config: crate::lightning::util::config::UserConfig, mut params: crate::lightning::ln::channelmanager::ChainParameters) -> ChannelManager {
1182 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()) });
1183 ChannelManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
1186 /// Gets the current configuration applied to all new channels, as
1189 pub extern "C" fn ChannelManager_get_current_default_configuration(this_arg: &ChannelManager) -> crate::lightning::util::config::UserConfig {
1190 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_current_default_configuration();
1191 crate::lightning::util::config::UserConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::util::config::UserConfig<>) as *mut _) }, is_owned: false }
1194 /// Creates a new outbound channel to the given remote node and with the given value.
1196 /// `user_channel_id` will be provided back as in
1197 /// [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
1198 /// correspond with which `create_channel` call. Note that the `user_channel_id` defaults to 0
1199 /// for inbound channels, so you may wish to avoid using 0 for `user_channel_id` here.
1200 /// `user_channel_id` has no meaning inside of LDK, it is simply copied to events and otherwise
1203 /// Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is
1204 /// greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`.
1206 /// Note that we do not check if you are currently connected to the given peer. If no
1207 /// connection is available, the outbound `open_channel` message may fail to send, resulting in
1208 /// the channel eventually being silently forgotten (dropped on reload).
1210 /// Returns the new Channel's temporary `channel_id`. This ID will appear as
1211 /// [`Event::FundingGenerationReady::temporary_channel_id`] and in
1212 /// [`ChannelDetails::channel_id`] until after
1213 /// [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
1214 /// one derived from the funding transaction's TXID. If the counterparty rejects the channel
1215 /// immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
1217 /// [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
1218 /// [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
1219 /// [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
1221 /// Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
1224 pub extern "C" fn ChannelManager_create_channel(this_arg: &ChannelManager, mut their_network_key: crate::c_types::PublicKey, mut channel_value_satoshis: u64, mut push_msat: u64, mut user_channel_id: u64, mut override_config: crate::lightning::util::config::UserConfig) -> crate::c_types::derived::CResult__u832APIErrorZ {
1225 let mut local_override_config = if override_config.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(override_config.take_inner()) } }) };
1226 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);
1227 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() };
1231 /// Gets the list of open channels, in random order. See ChannelDetail field documentation for
1232 /// more information.
1235 pub extern "C" fn ChannelManager_list_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1236 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_channels();
1237 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 } }); };
1241 /// Gets the list of usable channels, in random order. Useful as an argument to
1242 /// get_route to ensure non-announced channels are used.
1244 /// These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
1245 /// documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
1249 pub extern "C" fn ChannelManager_list_usable_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1250 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_usable_channels();
1251 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 } }); };
1255 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
1256 /// will be accepted on the given channel, and after additional timeout/the closing of all
1257 /// pending HTLCs, the channel will be closed on chain.
1259 /// * If we are the channel initiator, we will pay between our [`Background`] and
1260 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
1262 /// * If our counterparty is the channel initiator, we will require a channel closing
1263 /// transaction feerate of at least our [`Background`] feerate or the feerate which
1264 /// would appear on a force-closure transaction, whichever is lower. We will allow our
1265 /// counterparty to pay as much fee as they'd like, however.
1267 /// May generate a SendShutdown message event on success, which should be relayed.
1269 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
1270 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1271 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1274 pub extern "C" fn ChannelManager_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1275 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel(unsafe { &*channel_id});
1276 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() };
1280 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
1281 /// will be accepted on the given channel, and after additional timeout/the closing of all
1282 /// pending HTLCs, the channel will be closed on chain.
1284 /// `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
1285 /// the channel being closed or not:
1286 /// * If we are the channel initiator, we will pay at least this feerate on the closing
1287 /// transaction. The upper-bound is set by
1288 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
1289 /// estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
1290 /// * If our counterparty is the channel initiator, we will refuse to accept a channel closure
1291 /// transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
1292 /// will appear on a force-closure transaction, whichever is lower).
1294 /// May generate a SendShutdown message event on success, which should be relayed.
1296 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
1297 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1298 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1301 pub extern "C" fn ChannelManager_close_channel_with_target_feerate(this_arg: &ChannelManager, channel_id: *const [u8; 32], mut target_feerate_sats_per_1000_weight: u32) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1302 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel_with_target_feerate(unsafe { &*channel_id}, target_feerate_sats_per_1000_weight);
1303 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() };
1307 /// Force closes a channel, immediately broadcasting the latest local commitment transaction to
1308 /// the chain and rejecting new HTLCs on the given channel. Fails if channel_id is unknown to the manager.
1311 pub extern "C" fn ChannelManager_force_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1312 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_channel(unsafe { &*channel_id});
1313 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() };
1317 /// Force close all channels, immediately broadcasting the latest local commitment transaction
1318 /// for each to the chain and rejecting new HTLCs on each.
1320 pub extern "C" fn ChannelManager_force_close_all_channels(this_arg: &ChannelManager) {
1321 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_all_channels()
1324 /// Sends a payment along a given route.
1326 /// Value parameters are provided via the last hop in route, see documentation for RouteHop
1327 /// fields for more info.
1329 /// Note that if the payment_hash already exists elsewhere (eg you're sending a duplicative
1330 /// payment), we don't do anything to stop you! We always try to ensure that if the provided
1331 /// next hop knows the preimage to payment_hash they can claim an additional amount as
1332 /// specified in the last hop in the route! Thus, you should probably do your own
1333 /// payment_preimage tracking (which you should already be doing as they represent \"proof of
1334 /// payment\") and prevent double-sends yourself.
1336 /// May generate SendHTLCs message(s) event on success, which should be relayed.
1338 /// Each path may have a different return value, and PaymentSendValue may return a Vec with
1339 /// each entry matching the corresponding-index entry in the route paths, see
1340 /// PaymentSendFailure for more info.
1342 /// In general, a path may raise:
1343 /// * APIError::RouteError when an invalid route or forwarding parameter (cltv_delta, fee,
1344 /// node public key) is specified.
1345 /// * APIError::ChannelUnavailable if the next-hop channel is not available for updates
1346 /// (including due to previous monitor update failure or new permanent monitor update
1348 /// * APIError::MonitorUpdateFailed if a new monitor update failure prevented sending the
1349 /// relevant updates.
1351 /// Note that depending on the type of the PaymentSendFailure the HTLC may have been
1352 /// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
1353 /// different route unless you intend to pay twice!
1355 /// payment_secret is unrelated to payment_hash (or PaymentPreimage) and exists to authenticate
1356 /// the sender to the recipient and prevent payment-probing (deanonymization) attacks. For
1357 /// newer nodes, it will be provided to you in the invoice. If you do not have one, the Route
1358 /// must not contain multiple paths as multi-path payments require a recipient-provided
1360 /// If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature
1361 /// bit set (either as required or as available). If multiple paths are present in the Route,
1362 /// we assume the invoice had the basic_mpp feature set.
1364 /// Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
1367 pub extern "C" fn ChannelManager_send_payment(this_arg: &ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut payment_secret: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_PaymentIdPaymentSendFailureZ {
1368 let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentSecret(payment_secret.data) }) };
1369 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);
1370 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() };
1374 /// Retries a payment along the given [`Route`].
1376 /// Errors returned are a superset of those returned from [`send_payment`], so see
1377 /// [`send_payment`] documentation for more details on errors. This method will also error if the
1378 /// retry amount puts the payment more than 10% over the payment's total amount, if the payment
1379 /// for the given `payment_id` cannot be found (likely due to timeout or success), or if
1380 /// further retries have been disabled with [`abandon_payment`].
1382 /// [`send_payment`]: [`ChannelManager::send_payment`]
1383 /// [`abandon_payment`]: [`ChannelManager::abandon_payment`]
1386 pub extern "C" fn ChannelManager_retry_payment(this_arg: &ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_NonePaymentSendFailureZ {
1387 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.retry_payment(route.get_native_ref(), ::lightning::ln::channelmanager::PaymentId(payment_id.data));
1388 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() };
1392 /// Signals that no further retries for the given payment will occur.
1394 /// After this method returns, any future calls to [`retry_payment`] for the given `payment_id`
1395 /// will fail with [`PaymentSendFailure::ParameterError`]. If no such event has been generated,
1396 /// an [`Event::PaymentFailed`] event will be generated as soon as there are no remaining
1397 /// pending HTLCs for this payment.
1399 /// Note that calling this method does *not* prevent a payment from succeeding. You must still
1400 /// wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to
1401 /// determine the ultimate status of a payment.
1403 /// [`retry_payment`]: Self::retry_payment
1404 /// [`Event::PaymentFailed`]: events::Event::PaymentFailed
1405 /// [`Event::PaymentSent`]: events::Event::PaymentSent
1407 pub extern "C" fn ChannelManager_abandon_payment(this_arg: &ChannelManager, mut payment_id: crate::c_types::ThirtyTwoBytes) {
1408 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.abandon_payment(::lightning::ln::channelmanager::PaymentId(payment_id.data))
1411 /// Send a spontaneous payment, which is a payment that does not require the recipient to have
1412 /// generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
1413 /// the preimage, it must be a cryptographically secure random value that no intermediate node
1414 /// would be able to guess -- otherwise, an intermediate node may claim the payment and it will
1415 /// never reach the recipient.
1417 /// See [`send_payment`] documentation for more details on the return value of this function.
1419 /// Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
1420 /// [`send_payment`] for more information about the risks of duplicate preimage usage.
1422 /// Note that `route` must have exactly one path.
1424 /// [`send_payment`]: Self::send_payment
1426 /// Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None
1429 pub extern "C" fn ChannelManager_send_spontaneous_payment(this_arg: &ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_preimage: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ {
1430 let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
1431 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_spontaneous_payment(route.get_native_ref(), local_payment_preimage);
1432 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() };
1436 /// Call this upon creation of a funding transaction for the given channel.
1438 /// Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
1439 /// or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
1441 /// Returns [`APIError::ChannelUnavailable`] if a funding transaction has already been provided
1442 /// for the channel or if the channel has been closed as indicated by [`Event::ChannelClosed`].
1444 /// May panic if the output found in the funding transaction is duplicative with some other
1445 /// channel (note that this should be trivially prevented by using unique funding transaction
1446 /// keys per-channel).
1448 /// Do NOT broadcast the funding transaction yourself. When we have safely received our
1449 /// counterparty's signature the funding transaction will automatically be broadcast via the
1450 /// [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
1452 /// Note that this includes RBF or similar transaction replacement strategies - lightning does
1453 /// not currently support replacing a funding transaction on an existing channel. Instead,
1454 /// create a new channel with a conflicting funding transaction.
1456 /// [`Event::FundingGenerationReady`]: crate::util::events::Event::FundingGenerationReady
1457 /// [`Event::ChannelClosed`]: crate::util::events::Event::ChannelClosed
1460 pub extern "C" fn ChannelManager_funding_transaction_generated(this_arg: &ChannelManager, temporary_channel_id: *const [u8; 32], mut funding_transaction: crate::c_types::Transaction) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1461 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_transaction_generated(unsafe { &*temporary_channel_id}, funding_transaction.into_bitcoin());
1462 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() };
1466 /// Regenerates channel_announcements and generates a signed node_announcement from the given
1467 /// arguments, providing them in corresponding events via
1468 /// [`get_and_clear_pending_msg_events`], if at least one public channel has been confirmed
1469 /// on-chain. This effectively re-broadcasts all channel announcements and sends our node
1470 /// announcement to ensure that the lightning P2P network is aware of the channels we have and
1471 /// our network addresses.
1473 /// `rgb` is a node \"color\" and `alias` is a printable human-readable string to describe this
1474 /// node to humans. They carry no in-protocol meaning.
1476 /// `addresses` represent the set (possibly empty) of socket addresses on which this node
1477 /// accepts incoming connections. These will be included in the node_announcement, publicly
1478 /// tying these addresses together and to this node. If you wish to preserve user privacy,
1479 /// addresses should likely contain only Tor Onion addresses.
1481 /// Panics if `addresses` is absurdly large (more than 500).
1483 /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
1485 pub extern "C" fn ChannelManager_broadcast_node_announcement(this_arg: &ChannelManager, mut rgb: crate::c_types::ThreeBytes, mut alias: crate::c_types::ThirtyTwoBytes, mut addresses: crate::c_types::derived::CVec_NetAddressZ) {
1486 let mut local_addresses = Vec::new(); for mut item in addresses.into_rust().drain(..) { local_addresses.push( { item.into_native() }); };
1487 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.broadcast_node_announcement(rgb.data, alias.data, local_addresses)
1490 /// Processes HTLCs which are pending waiting on random forward delay.
1492 /// Should only really ever be called in response to a PendingHTLCsForwardable event.
1493 /// Will likely generate further events.
1495 pub extern "C" fn ChannelManager_process_pending_htlc_forwards(this_arg: &ChannelManager) {
1496 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_pending_htlc_forwards()
1499 /// Performs actions which should happen on startup and roughly once per minute thereafter.
1501 /// This currently includes:
1502 /// * Increasing or decreasing the on-chain feerate estimates for our outbound channels,
1503 /// * Broadcasting `ChannelUpdate` messages if we've been disconnected from our peer for more
1504 /// than a minute, informing the network that they should no longer attempt to route over
1507 /// Note that this may cause reentrancy through `chain::Watch::update_channel` calls or feerate
1508 /// estimate fetches.
1510 pub extern "C" fn ChannelManager_timer_tick_occurred(this_arg: &ChannelManager) {
1511 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timer_tick_occurred()
1514 /// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
1515 /// after a PaymentReceived event, failing the HTLC back to its origin and freeing resources
1516 /// along the path (including in our own channel on which we received it).
1517 /// Returns false if no payment was found to fail backwards, true if the process of failing the
1518 /// HTLC backwards has been started.
1521 pub extern "C" fn ChannelManager_fail_htlc_backwards(this_arg: &ChannelManager, payment_hash: *const [u8; 32]) -> bool {
1522 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_htlc_backwards(&::lightning::ln::PaymentHash(unsafe { *payment_hash }));
1526 /// Provides a payment preimage in response to [`Event::PaymentReceived`], generating any
1527 /// [`MessageSendEvent`]s needed to claim the payment.
1529 /// Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
1530 /// [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentReceived`
1531 /// event matches your expectation. If you fail to do so and call this method, you may provide
1532 /// the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
1534 /// Returns whether any HTLCs were claimed, and thus if any new [`MessageSendEvent`]s are now
1535 /// pending for processing via [`get_and_clear_pending_msg_events`].
1537 /// [`Event::PaymentReceived`]: crate::util::events::Event::PaymentReceived
1538 /// [`create_inbound_payment`]: Self::create_inbound_payment
1539 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1540 /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
1543 pub extern "C" fn ChannelManager_claim_funds(this_arg: &ChannelManager, mut payment_preimage: crate::c_types::ThirtyTwoBytes) -> bool {
1544 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.claim_funds(::lightning::ln::PaymentPreimage(payment_preimage.data));
1548 /// Gets the node_id held by this ChannelManager
1551 pub extern "C" fn ChannelManager_get_our_node_id(this_arg: &ChannelManager) -> crate::c_types::PublicKey {
1552 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_our_node_id();
1553 crate::c_types::PublicKey::from_rust(&ret)
1556 /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
1559 /// This differs from [`create_inbound_payment_for_hash`] only in that it generates the
1560 /// [`PaymentHash`] and [`PaymentPreimage`] for you.
1562 /// The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentReceived`], which
1563 /// will have the [`PaymentReceived::payment_preimage`] field filled in. That should then be
1564 /// passed directly to [`claim_funds`].
1566 /// See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
1568 /// Note that a malicious eavesdropper can intuit whether an inbound payment was created by
1569 /// `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
1573 /// If you register an inbound payment with this method, then serialize the `ChannelManager`, then
1574 /// deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
1576 /// Errors if `min_value_msat` is greater than total bitcoin supply.
1578 /// [`claim_funds`]: Self::claim_funds
1579 /// [`PaymentReceived`]: events::Event::PaymentReceived
1580 /// [`PaymentReceived::payment_preimage`]: events::Event::PaymentReceived::payment_preimage
1581 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1584 pub extern "C" fn ChannelManager_create_inbound_payment(this_arg: &ChannelManager, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32) -> crate::c_types::derived::CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ {
1585 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
1586 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment(local_min_value_msat, invoice_expiry_delta_secs);
1587 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() };
1591 /// Legacy version of [`create_inbound_payment`]. Use this method if you wish to share
1592 /// serialized state with LDK node(s) running 0.0.103 and earlier.
1595 /// This method is deprecated and will be removed soon.
1597 /// [`create_inbound_payment`]: Self::create_inbound_payment
1600 pub extern "C" fn ChannelManager_create_inbound_payment_legacy(this_arg: &ChannelManager, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32) -> crate::c_types::derived::CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ {
1601 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
1602 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment_legacy(local_min_value_msat, invoice_expiry_delta_secs);
1603 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() };
1607 /// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
1608 /// stored external to LDK.
1610 /// A [`PaymentReceived`] event will only be generated if the [`PaymentSecret`] matches a
1611 /// payment secret fetched via this method or [`create_inbound_payment`], and which is at least
1612 /// the `min_value_msat` provided here, if one is provided.
1614 /// The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) should be globally unique, though
1615 /// note that LDK will not stop you from registering duplicate payment hashes for inbound
1618 /// `min_value_msat` should be set if the invoice being generated contains a value. Any payment
1619 /// received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
1620 /// before a [`PaymentReceived`] event will be generated, ensuring that we do not provide the
1621 /// sender \"proof-of-payment\" unless they have paid the required amount.
1623 /// `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
1624 /// in excess of the current time. This should roughly match the expiry time set in the invoice.
1625 /// After this many seconds, we will remove the inbound payment, resulting in any attempts to
1626 /// pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
1627 /// invoices when no timeout is set.
1629 /// Note that we use block header time to time-out pending inbound payments (with some margin
1630 /// to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
1631 /// accept a payment and generate a [`PaymentReceived`] event for some time after the expiry.
1632 /// If you need exact expiry semantics, you should enforce them upon receipt of
1633 /// [`PaymentReceived`].
1635 /// May panic if `invoice_expiry_delta_secs` is greater than one year.
1637 /// Note that invoices generated for inbound payments should have their `min_final_cltv_expiry`
1638 /// set to at least [`MIN_FINAL_CLTV_EXPIRY`].
1640 /// Note that a malicious eavesdropper can intuit whether an inbound payment was created by
1641 /// `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
1645 /// If you register an inbound payment with this method, then serialize the `ChannelManager`, then
1646 /// deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
1648 /// Errors if `min_value_msat` is greater than total bitcoin supply.
1650 /// [`create_inbound_payment`]: Self::create_inbound_payment
1651 /// [`PaymentReceived`]: events::Event::PaymentReceived
1654 pub extern "C" fn ChannelManager_create_inbound_payment_for_hash(this_arg: &ChannelManager, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32) -> crate::c_types::derived::CResult_PaymentSecretNoneZ {
1655 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
1656 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);
1657 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() };
1661 /// Legacy version of [`create_inbound_payment_for_hash`]. Use this method if you wish to share
1662 /// serialized state with LDK node(s) running 0.0.103 and earlier.
1665 /// This method is deprecated and will be removed soon.
1667 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1670 pub extern "C" fn ChannelManager_create_inbound_payment_for_hash_legacy(this_arg: &ChannelManager, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32) -> crate::c_types::derived::CResult_PaymentSecretAPIErrorZ {
1671 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
1672 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);
1673 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() };
1677 /// Gets an LDK-generated payment preimage from a payment hash and payment secret that were
1678 /// previously returned from [`create_inbound_payment`].
1680 /// [`create_inbound_payment`]: Self::create_inbound_payment
1683 pub extern "C" fn ChannelManager_get_payment_preimage(this_arg: &ChannelManager, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut payment_secret: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_PaymentPreimageAPIErrorZ {
1684 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));
1685 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() };
1689 impl From<nativeChannelManager> for crate::lightning::util::events::MessageSendEventsProvider {
1690 fn from(obj: nativeChannelManager) -> Self {
1691 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1692 let mut ret = ChannelManager_as_MessageSendEventsProvider(&rust_obj);
1693 // 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
1694 rust_obj.inner = core::ptr::null_mut();
1695 ret.free = Some(ChannelManager_free_void);
1699 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
1700 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
1702 pub extern "C" fn ChannelManager_as_MessageSendEventsProvider(this_arg: &ChannelManager) -> crate::lightning::util::events::MessageSendEventsProvider {
1703 crate::lightning::util::events::MessageSendEventsProvider {
1704 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1706 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
1711 extern "C" fn ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
1712 let mut ret = <nativeChannelManager as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
1713 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
1717 impl From<nativeChannelManager> for crate::lightning::util::events::EventsProvider {
1718 fn from(obj: nativeChannelManager) -> Self {
1719 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1720 let mut ret = ChannelManager_as_EventsProvider(&rust_obj);
1721 // 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
1722 rust_obj.inner = core::ptr::null_mut();
1723 ret.free = Some(ChannelManager_free_void);
1727 /// Constructs a new EventsProvider which calls the relevant methods on this_arg.
1728 /// This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
1730 pub extern "C" fn ChannelManager_as_EventsProvider(this_arg: &ChannelManager) -> crate::lightning::util::events::EventsProvider {
1731 crate::lightning::util::events::EventsProvider {
1732 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1734 process_pending_events: ChannelManager_EventsProvider_process_pending_events,
1738 extern "C" fn ChannelManager_EventsProvider_process_pending_events(this_arg: *const c_void, mut handler: crate::lightning::util::events::EventHandler) {
1739 <nativeChannelManager as lightning::util::events::EventsProvider<>>::process_pending_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, handler)
1742 impl From<nativeChannelManager> for crate::lightning::chain::Listen {
1743 fn from(obj: nativeChannelManager) -> Self {
1744 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1745 let mut ret = ChannelManager_as_Listen(&rust_obj);
1746 // 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
1747 rust_obj.inner = core::ptr::null_mut();
1748 ret.free = Some(ChannelManager_free_void);
1752 /// Constructs a new Listen which calls the relevant methods on this_arg.
1753 /// This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
1755 pub extern "C" fn ChannelManager_as_Listen(this_arg: &ChannelManager) -> crate::lightning::chain::Listen {
1756 crate::lightning::chain::Listen {
1757 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1759 block_connected: ChannelManager_Listen_block_connected,
1760 block_disconnected: ChannelManager_Listen_block_disconnected,
1764 extern "C" fn ChannelManager_Listen_block_connected(this_arg: *const c_void, mut block: crate::c_types::u8slice, mut height: u32) {
1765 <nativeChannelManager as lightning::chain::Listen<>>::block_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height)
1767 extern "C" fn ChannelManager_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
1768 <nativeChannelManager as lightning::chain::Listen<>>::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
1771 impl From<nativeChannelManager> for crate::lightning::chain::Confirm {
1772 fn from(obj: nativeChannelManager) -> Self {
1773 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1774 let mut ret = ChannelManager_as_Confirm(&rust_obj);
1775 // 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
1776 rust_obj.inner = core::ptr::null_mut();
1777 ret.free = Some(ChannelManager_free_void);
1781 /// Constructs a new Confirm which calls the relevant methods on this_arg.
1782 /// This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
1784 pub extern "C" fn ChannelManager_as_Confirm(this_arg: &ChannelManager) -> crate::lightning::chain::Confirm {
1785 crate::lightning::chain::Confirm {
1786 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1788 transactions_confirmed: ChannelManager_Confirm_transactions_confirmed,
1789 transaction_unconfirmed: ChannelManager_Confirm_transaction_unconfirmed,
1790 best_block_updated: ChannelManager_Confirm_best_block_updated,
1791 get_relevant_txids: ChannelManager_Confirm_get_relevant_txids,
1795 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) {
1796 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 }); };
1797 <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)
1799 extern "C" fn ChannelManager_Confirm_best_block_updated(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
1800 <nativeChannelManager as lightning::chain::Confirm<>>::best_block_updated(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
1803 extern "C" fn ChannelManager_Confirm_get_relevant_txids(this_arg: *const c_void) -> crate::c_types::derived::CVec_TxidZ {
1804 let mut ret = <nativeChannelManager as lightning::chain::Confirm<>>::get_relevant_txids(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
1805 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::ThirtyTwoBytes { data: item.into_inner() } }); };
1808 extern "C" fn ChannelManager_Confirm_transaction_unconfirmed(this_arg: *const c_void, txid: *const [u8; 32]) {
1809 <nativeChannelManager as lightning::chain::Confirm<>>::transaction_unconfirmed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap())
1812 /// Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
1813 /// indicating whether persistence is necessary. Only one listener on
1814 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
1817 /// Note that this method is not available with the `no-std` feature.
1820 pub extern "C" fn ChannelManager_await_persistable_update_timeout(this_arg: &ChannelManager, mut max_wait: u64) -> bool {
1821 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.await_persistable_update_timeout(core::time::Duration::from_secs(max_wait));
1825 /// Blocks until ChannelManager needs to be persisted. Only one listener on
1826 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
1829 pub extern "C" fn ChannelManager_await_persistable_update(this_arg: &ChannelManager) {
1830 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.await_persistable_update()
1833 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
1834 /// [`chain::Confirm`] interfaces.
1837 pub extern "C" fn ChannelManager_current_best_block(this_arg: &ChannelManager) -> crate::lightning::chain::BestBlock {
1838 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
1839 crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
1842 impl From<nativeChannelManager> for crate::lightning::ln::msgs::ChannelMessageHandler {
1843 fn from(obj: nativeChannelManager) -> Self {
1844 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1845 let mut ret = ChannelManager_as_ChannelMessageHandler(&rust_obj);
1846 // 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
1847 rust_obj.inner = core::ptr::null_mut();
1848 ret.free = Some(ChannelManager_free_void);
1852 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
1853 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
1855 pub extern "C" fn ChannelManager_as_ChannelMessageHandler(this_arg: &ChannelManager) -> crate::lightning::ln::msgs::ChannelMessageHandler {
1856 crate::lightning::ln::msgs::ChannelMessageHandler {
1857 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1859 handle_open_channel: ChannelManager_ChannelMessageHandler_handle_open_channel,
1860 handle_accept_channel: ChannelManager_ChannelMessageHandler_handle_accept_channel,
1861 handle_funding_created: ChannelManager_ChannelMessageHandler_handle_funding_created,
1862 handle_funding_signed: ChannelManager_ChannelMessageHandler_handle_funding_signed,
1863 handle_funding_locked: ChannelManager_ChannelMessageHandler_handle_funding_locked,
1864 handle_shutdown: ChannelManager_ChannelMessageHandler_handle_shutdown,
1865 handle_closing_signed: ChannelManager_ChannelMessageHandler_handle_closing_signed,
1866 handle_update_add_htlc: ChannelManager_ChannelMessageHandler_handle_update_add_htlc,
1867 handle_update_fulfill_htlc: ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc,
1868 handle_update_fail_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_htlc,
1869 handle_update_fail_malformed_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_malformed_htlc,
1870 handle_commitment_signed: ChannelManager_ChannelMessageHandler_handle_commitment_signed,
1871 handle_revoke_and_ack: ChannelManager_ChannelMessageHandler_handle_revoke_and_ack,
1872 handle_update_fee: ChannelManager_ChannelMessageHandler_handle_update_fee,
1873 handle_announcement_signatures: ChannelManager_ChannelMessageHandler_handle_announcement_signatures,
1874 peer_disconnected: ChannelManager_ChannelMessageHandler_peer_disconnected,
1875 peer_connected: ChannelManager_ChannelMessageHandler_peer_connected,
1876 handle_channel_reestablish: ChannelManager_ChannelMessageHandler_handle_channel_reestablish,
1877 handle_channel_update: ChannelManager_ChannelMessageHandler_handle_channel_update,
1878 handle_error: ChannelManager_ChannelMessageHandler_handle_error,
1879 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
1880 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1882 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
1887 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) {
1888 <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())
1890 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) {
1891 <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())
1893 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) {
1894 <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())
1896 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) {
1897 <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())
1899 extern "C" fn ChannelManager_ChannelMessageHandler_handle_funding_locked(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::FundingLocked) {
1900 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_locked(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
1902 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) {
1903 <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())
1905 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) {
1906 <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())
1908 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) {
1909 <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())
1911 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) {
1912 <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())
1914 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) {
1915 <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())
1917 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) {
1918 <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())
1920 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) {
1921 <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())
1923 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) {
1924 <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())
1926 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) {
1927 <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())
1929 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) {
1930 <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())
1932 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) {
1933 <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())
1935 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) {
1936 <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())
1938 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) {
1939 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), no_connection_possible)
1941 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) {
1942 <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())
1944 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) {
1945 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
1949 /// Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
1950 pub extern "C" fn ChannelManager_write(obj: &ChannelManager) -> crate::c_types::derived::CVec_u8Z {
1951 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1954 pub(crate) extern "C" fn ChannelManager_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1955 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelManager) })
1958 use lightning::ln::channelmanager::ChannelManagerReadArgs as nativeChannelManagerReadArgsImport;
1959 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>;
1961 /// Arguments for the creation of a ChannelManager that are not deserialized.
1963 /// At a high-level, the process for deserializing a ChannelManager and resuming normal operation
1965 /// 1) Deserialize all stored [`ChannelMonitor`]s.
1966 /// 2) Deserialize the [`ChannelManager`] by filling in this struct and calling:
1967 /// `<(BlockHash, ChannelManager)>::read(reader, args)`
1968 /// This may result in closing some channels if the [`ChannelMonitor`] is newer than the stored
1969 /// [`ChannelManager`] state to ensure no loss of funds. Thus, transactions may be broadcasted.
1970 /// 3) If you are not fetching full blocks, register all relevant [`ChannelMonitor`] outpoints the
1971 /// same way you would handle a [`chain::Filter`] call using
1972 /// [`ChannelMonitor::get_outputs_to_watch`] and [`ChannelMonitor::get_funding_txo`].
1973 /// 4) Reconnect blocks on your [`ChannelMonitor`]s.
1974 /// 5) Disconnect/connect blocks on the [`ChannelManager`].
1975 /// 6) Re-persist the [`ChannelMonitor`]s to ensure the latest state is on disk.
1976 /// Note that if you're using a [`ChainMonitor`] for your [`chain::Watch`] implementation, you
1977 /// will likely accomplish this as a side-effect of calling [`chain::Watch::watch_channel`] in
1979 /// 7) Move the [`ChannelMonitor`]s into your local [`chain::Watch`]. If you're using a
1980 /// [`ChainMonitor`], this is done by calling [`chain::Watch::watch_channel`].
1982 /// Note that the ordering of #4-7 is not of importance, however all four must occur before you
1983 /// call any other methods on the newly-deserialized [`ChannelManager`].
1985 /// Note that because some channels may be closed during deserialization, it is critical that you
1986 /// always deserialize only the latest version of a ChannelManager and ChannelMonitors available to
1987 /// you. If you deserialize an old ChannelManager (during which force-closure transactions may be
1988 /// broadcast), and then later deserialize a newer version of the same ChannelManager (which will
1989 /// not force-close the same channels but consider them live), you may end up revoking a state for
1990 /// which you've already broadcasted the transaction.
1992 /// [`ChainMonitor`]: crate::chain::chainmonitor::ChainMonitor
1995 pub struct ChannelManagerReadArgs {
1996 /// A pointer to the opaque Rust object.
1998 /// Nearly everywhere, inner must be non-null, however in places where
1999 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2000 pub inner: *mut nativeChannelManagerReadArgs,
2001 /// Indicates that this is the only struct which contains the same pointer.
2003 /// Rust functions which take ownership of an object provided via an argument require
2004 /// this to be true and invalidate the object pointed to by inner.
2008 impl Drop for ChannelManagerReadArgs {
2009 fn drop(&mut self) {
2010 if self.is_owned && !<*mut nativeChannelManagerReadArgs>::is_null(self.inner) {
2011 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2015 /// Frees any resources used by the ChannelManagerReadArgs, if is_owned is set and inner is non-NULL.
2017 pub extern "C" fn ChannelManagerReadArgs_free(this_obj: ChannelManagerReadArgs) { }
2019 /// Used only if an object of this type is returned as a trait impl by a method
2020 pub(crate) extern "C" fn ChannelManagerReadArgs_free_void(this_ptr: *mut c_void) {
2021 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManagerReadArgs); }
2024 impl ChannelManagerReadArgs {
2025 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManagerReadArgs {
2026 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2028 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManagerReadArgs {
2029 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2031 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2032 pub(crate) fn take_inner(mut self) -> *mut nativeChannelManagerReadArgs {
2033 assert!(self.is_owned);
2034 let ret = ObjOps::untweak_ptr(self.inner);
2035 self.inner = core::ptr::null_mut();
2039 /// The keys provider which will give us relevant keys. Some keys will be loaded during
2040 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
2043 pub extern "C" fn ChannelManagerReadArgs_get_keys_manager(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::keysinterface::KeysInterface {
2044 let mut inner_val = &mut this_ptr.get_native_mut_ref().keys_manager;
2047 /// The keys provider which will give us relevant keys. Some keys will be loaded during
2048 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
2051 pub extern "C" fn ChannelManagerReadArgs_set_keys_manager(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::keysinterface::KeysInterface) {
2052 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.keys_manager = val;
2054 /// The fee_estimator for use in the ChannelManager in the future.
2056 /// No calls to the FeeEstimator will be made during deserialization.
2058 pub extern "C" fn ChannelManagerReadArgs_get_fee_estimator(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::FeeEstimator {
2059 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_estimator;
2062 /// The fee_estimator for use in the ChannelManager in the future.
2064 /// No calls to the FeeEstimator will be made during deserialization.
2066 pub extern "C" fn ChannelManagerReadArgs_set_fee_estimator(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::FeeEstimator) {
2067 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_estimator = val;
2069 /// The chain::Watch for use in the ChannelManager in the future.
2071 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
2072 /// you have deserialized ChannelMonitors separately and will add them to your
2073 /// chain::Watch after deserializing this ChannelManager.
2075 pub extern "C" fn ChannelManagerReadArgs_get_chain_monitor(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::Watch {
2076 let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_monitor;
2079 /// The chain::Watch for use in the ChannelManager in the future.
2081 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
2082 /// you have deserialized ChannelMonitors separately and will add them to your
2083 /// chain::Watch after deserializing this ChannelManager.
2085 pub extern "C" fn ChannelManagerReadArgs_set_chain_monitor(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::Watch) {
2086 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_monitor = val;
2088 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
2089 /// used to broadcast the latest local commitment transactions of channels which must be
2090 /// force-closed during deserialization.
2092 pub extern "C" fn ChannelManagerReadArgs_get_tx_broadcaster(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::BroadcasterInterface {
2093 let mut inner_val = &mut this_ptr.get_native_mut_ref().tx_broadcaster;
2096 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
2097 /// used to broadcast the latest local commitment transactions of channels which must be
2098 /// force-closed during deserialization.
2100 pub extern "C" fn ChannelManagerReadArgs_set_tx_broadcaster(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::BroadcasterInterface) {
2101 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.tx_broadcaster = val;
2103 /// The Logger for use in the ChannelManager and which may be used to log information during
2104 /// deserialization.
2106 pub extern "C" fn ChannelManagerReadArgs_get_logger(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::util::logger::Logger {
2107 let mut inner_val = &mut this_ptr.get_native_mut_ref().logger;
2110 /// The Logger for use in the ChannelManager and which may be used to log information during
2111 /// deserialization.
2113 pub extern "C" fn ChannelManagerReadArgs_set_logger(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::logger::Logger) {
2114 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.logger = val;
2116 /// Default settings used for new channels. Any existing channels will continue to use the
2117 /// runtime settings which were stored when the ChannelManager was serialized.
2119 pub extern "C" fn ChannelManagerReadArgs_get_default_config(this_ptr: &ChannelManagerReadArgs) -> crate::lightning::util::config::UserConfig {
2120 let mut inner_val = &mut this_ptr.get_native_mut_ref().default_config;
2121 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 }
2123 /// Default settings used for new channels. Any existing channels will continue to use the
2124 /// runtime settings which were stored when the ChannelManager was serialized.
2126 pub extern "C" fn ChannelManagerReadArgs_set_default_config(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::config::UserConfig) {
2127 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.default_config = *unsafe { Box::from_raw(val.take_inner()) };
2129 /// Simple utility function to create a ChannelManagerReadArgs which creates the monitor
2130 /// HashMap for you. This is primarily useful for C bindings where it is not practical to
2131 /// populate a HashMap directly from C.
2134 pub extern "C" fn ChannelManagerReadArgs_new(mut keys_manager: crate::lightning::chain::keysinterface::KeysInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, mut chain_monitor: crate::lightning::chain::Watch, mut tx_broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut logger: crate::lightning::util::logger::Logger, mut default_config: crate::lightning::util::config::UserConfig, mut channel_monitors: crate::c_types::derived::CVec_ChannelMonitorZ) -> ChannelManagerReadArgs {
2135 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() }); };
2136 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);
2137 ChannelManagerReadArgs { inner: ObjOps::heap_alloc(ret), is_owned: true }
2141 /// Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_write
2142 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 {
2143 let arg_conv = *unsafe { Box::from_raw(arg.take_inner()) };
2144 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);
2145 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() };