1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! The top-level channel management and payment tracking stuff lives here.
11 //! The ChannelManager is the main chunk of logic implementing the lightning protocol and is
12 //! responsible for tracking which channels are open, HTLCs are in flight and reestablishing those
13 //! upon reconnect to the relevant peer(s).
15 //! It does not manage routing logic (see routing::router::get_route for that) nor does it manage constructing
16 //! on-chain transactions (it only monitors the chain to watch for any force-closes that might
17 //! imply it needs to fail HTLCs/payments/channels it manages).
20 use std::str::FromStr;
22 use core::convert::Infallible;
23 use bitcoin::hashes::Hash;
24 use crate::c_types::*;
28 use std::str::FromStr;
30 use core::convert::Infallible;
31 use bitcoin::hashes::Hash;
32 use crate::c_types::*;
36 use lightning::ln::channelmanager::ChannelManager as nativeChannelManagerImport;
37 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>;
39 /// Manager which keeps track of a number of channels and sends messages to the appropriate
40 /// channel, also tracking HTLC preimages and forwarding onion packets appropriately.
42 /// Implements ChannelMessageHandler, handling the multi-channel parts and passing things through
43 /// to individual Channels.
45 /// Implements Writeable to write out all channel state to disk. Implies peer_disconnected() for
46 /// all peers during write/read (though does not modify this instance, only the instance being
47 /// serialized). This will result in any channels which have not yet exchanged funding_created (ie
48 /// called funding_transaction_generated for outbound channels).
50 /// Note that you can be a bit lazier about writing out ChannelManager than you can be with
51 /// ChannelMonitors. With ChannelMonitors you MUST write each monitor update out to disk before
52 /// returning from chain::Watch::watch_/update_channel, with ChannelManagers, writing updates
53 /// happens out-of-band (and will prevent any other ChannelManager operations from occurring during
54 /// the serialization process). If the deserialized version is out-of-date compared to the
55 /// ChannelMonitors passed by reference to read(), those channels will be force-closed based on the
56 /// ChannelMonitor state and no funds will be lost (mod on-chain transaction fees).
58 /// Note that the deserializer is only implemented for (BlockHash, ChannelManager), which
59 /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
60 /// the \"reorg path\" (ie call block_disconnected() until you get to a common block and then call
61 /// block_connected() to step towards your best block) upon deserialization before using the
64 /// Note that ChannelManager is responsible for tracking liveness of its channels and generating
65 /// ChannelUpdate messages informing peers that the channel is temporarily disabled. To avoid
66 /// spam due to quick disconnection/reconnection, updates are not sent until the channel has been
67 /// offline for a full minute. In order to track this, you must call
68 /// timer_tick_occurred roughly once per minute, though it doesn't have to be perfect.
70 /// Rather than using a plain ChannelManager, it is preferable to use either a SimpleArcChannelManager
71 /// a SimpleRefChannelManager, for conciseness. See their documentation for more details, but
72 /// essentially you should default to using a SimpleRefChannelManager, and use a
73 /// SimpleArcChannelManager when you require a ChannelManager with a static lifetime, such as when
74 /// you're using lightning-net-tokio.
77 pub struct ChannelManager {
78 /// A pointer to the opaque Rust object.
80 /// Nearly everywhere, inner must be non-null, however in places where
81 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
82 pub inner: *mut nativeChannelManager,
83 /// Indicates that this is the only struct which contains the same pointer.
85 /// Rust functions which take ownership of an object provided via an argument require
86 /// this to be true and invalidate the object pointed to by inner.
90 impl Drop for ChannelManager {
92 if self.is_owned && !<*mut nativeChannelManager>::is_null(self.inner) {
93 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
97 /// Frees any resources used by the ChannelManager, if is_owned is set and inner is non-NULL.
99 pub extern "C" fn ChannelManager_free(this_obj: ChannelManager) { }
101 /// Used only if an object of this type is returned as a trait impl by a method
102 pub(crate) extern "C" fn ChannelManager_free_void(this_ptr: *mut c_void) {
103 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManager); }
106 impl ChannelManager {
107 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManager {
108 unsafe { &*ObjOps::untweak_ptr(self.inner) }
110 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManager {
111 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
113 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
114 pub(crate) fn take_inner(mut self) -> *mut nativeChannelManager {
115 assert!(self.is_owned);
116 let ret = ObjOps::untweak_ptr(self.inner);
117 self.inner = std::ptr::null_mut();
122 use lightning::ln::channelmanager::ChainParameters as nativeChainParametersImport;
123 pub(crate) type nativeChainParameters = nativeChainParametersImport;
125 /// Chain-related parameters used to construct a new `ChannelManager`.
127 /// Typically, the block-specific parameters are derived from the best block hash for the network,
128 /// as a newly constructed `ChannelManager` will not have created any channels yet. These parameters
129 /// are not needed when deserializing a previously constructed `ChannelManager`.
132 pub struct ChainParameters {
133 /// A pointer to the opaque Rust object.
135 /// Nearly everywhere, inner must be non-null, however in places where
136 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
137 pub inner: *mut nativeChainParameters,
138 /// Indicates that this is the only struct which contains the same pointer.
140 /// Rust functions which take ownership of an object provided via an argument require
141 /// this to be true and invalidate the object pointed to by inner.
145 impl Drop for ChainParameters {
147 if self.is_owned && !<*mut nativeChainParameters>::is_null(self.inner) {
148 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
152 /// Frees any resources used by the ChainParameters, if is_owned is set and inner is non-NULL.
154 pub extern "C" fn ChainParameters_free(this_obj: ChainParameters) { }
156 /// Used only if an object of this type is returned as a trait impl by a method
157 pub(crate) extern "C" fn ChainParameters_free_void(this_ptr: *mut c_void) {
158 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChainParameters); }
161 impl ChainParameters {
162 pub(crate) fn get_native_ref(&self) -> &'static nativeChainParameters {
163 unsafe { &*ObjOps::untweak_ptr(self.inner) }
165 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChainParameters {
166 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
168 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
169 pub(crate) fn take_inner(mut self) -> *mut nativeChainParameters {
170 assert!(self.is_owned);
171 let ret = ObjOps::untweak_ptr(self.inner);
172 self.inner = std::ptr::null_mut();
176 /// The network for determining the `chain_hash` in Lightning messages.
178 pub extern "C" fn ChainParameters_get_network(this_ptr: &ChainParameters) -> crate::bitcoin::network::Network {
179 let mut inner_val = &mut this_ptr.get_native_mut_ref().network;
180 crate::bitcoin::network::Network::from_bitcoin(inner_val)
182 /// The network for determining the `chain_hash` in Lightning messages.
184 pub extern "C" fn ChainParameters_set_network(this_ptr: &mut ChainParameters, mut val: crate::bitcoin::network::Network) {
185 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.network = val.into_bitcoin();
187 /// The hash and height of the latest block successfully connected.
189 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
191 pub extern "C" fn ChainParameters_get_best_block(this_ptr: &ChainParameters) -> crate::lightning::chain::BestBlock {
192 let mut inner_val = &mut this_ptr.get_native_mut_ref().best_block;
193 crate::lightning::chain::BestBlock { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::chain::BestBlock<>) as *mut _) }, is_owned: false }
195 /// The hash and height of the latest block successfully connected.
197 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
199 pub extern "C" fn ChainParameters_set_best_block(this_ptr: &mut ChainParameters, mut val: crate::lightning::chain::BestBlock) {
200 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.best_block = *unsafe { Box::from_raw(val.take_inner()) };
202 /// Constructs a new ChainParameters given each field
205 pub extern "C" fn ChainParameters_new(mut network_arg: crate::bitcoin::network::Network, mut best_block_arg: crate::lightning::chain::BestBlock) -> ChainParameters {
206 ChainParameters { inner: ObjOps::heap_alloc(nativeChainParameters {
207 network: network_arg.into_bitcoin(),
208 best_block: *unsafe { Box::from_raw(best_block_arg.take_inner()) },
211 impl Clone for ChainParameters {
212 fn clone(&self) -> Self {
214 inner: if <*mut nativeChainParameters>::is_null(self.inner) { std::ptr::null_mut() } else {
215 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
221 /// Used only if an object of this type is returned as a trait impl by a method
222 pub(crate) extern "C" fn ChainParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
223 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChainParameters)).clone() })) as *mut c_void
226 /// Creates a copy of the ChainParameters
227 pub extern "C" fn ChainParameters_clone(orig: &ChainParameters) -> ChainParameters {
230 /// The amount of time in blocks we require our counterparty wait to claim their money (ie time
231 /// between when we, or our watchtower, must check for them having broadcast a theft transaction).
233 /// This can be increased (but not decreased) through [`ChannelHandshakeConfig::our_to_self_delay`]
235 /// [`ChannelHandshakeConfig::our_to_self_delay`]: crate::util::config::ChannelHandshakeConfig::our_to_self_delay
238 pub static BREAKDOWN_TIMEOUT: u16 = lightning::ln::channelmanager::BREAKDOWN_TIMEOUT;
239 /// The minimum number of blocks between an inbound HTLC's CLTV and the corresponding outbound
240 /// HTLC's CLTV. The current default represents roughly seven hours of blocks at six blocks/hour.
242 /// This can be increased (but not decreased) through [`ChannelConfig::cltv_expiry_delta`]
244 /// [`ChannelConfig::cltv_expiry_delta`]: crate::util::config::ChannelConfig::cltv_expiry_delta
247 pub static MIN_CLTV_EXPIRY_DELTA: u16 = lightning::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA;
248 /// Minimum CLTV difference between the current block height and received inbound payments.
249 /// Invoices generated for payment to us must set their `min_final_cltv_expiry` field to at least
253 pub static MIN_FINAL_CLTV_EXPIRY: u32 = lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY;
255 use lightning::ln::channelmanager::CounterpartyForwardingInfo as nativeCounterpartyForwardingInfoImport;
256 pub(crate) type nativeCounterpartyForwardingInfo = nativeCounterpartyForwardingInfoImport;
258 /// Information needed for constructing an invoice route hint for this channel.
261 pub struct CounterpartyForwardingInfo {
262 /// A pointer to the opaque Rust object.
264 /// Nearly everywhere, inner must be non-null, however in places where
265 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
266 pub inner: *mut nativeCounterpartyForwardingInfo,
267 /// Indicates that this is the only struct which contains the same pointer.
269 /// Rust functions which take ownership of an object provided via an argument require
270 /// this to be true and invalidate the object pointed to by inner.
274 impl Drop for CounterpartyForwardingInfo {
276 if self.is_owned && !<*mut nativeCounterpartyForwardingInfo>::is_null(self.inner) {
277 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
281 /// Frees any resources used by the CounterpartyForwardingInfo, if is_owned is set and inner is non-NULL.
283 pub extern "C" fn CounterpartyForwardingInfo_free(this_obj: CounterpartyForwardingInfo) { }
285 /// Used only if an object of this type is returned as a trait impl by a method
286 pub(crate) extern "C" fn CounterpartyForwardingInfo_free_void(this_ptr: *mut c_void) {
287 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCounterpartyForwardingInfo); }
290 impl CounterpartyForwardingInfo {
291 pub(crate) fn get_native_ref(&self) -> &'static nativeCounterpartyForwardingInfo {
292 unsafe { &*ObjOps::untweak_ptr(self.inner) }
294 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCounterpartyForwardingInfo {
295 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
297 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
298 pub(crate) fn take_inner(mut self) -> *mut nativeCounterpartyForwardingInfo {
299 assert!(self.is_owned);
300 let ret = ObjOps::untweak_ptr(self.inner);
301 self.inner = std::ptr::null_mut();
305 /// Base routing fee in millisatoshis.
307 pub extern "C" fn CounterpartyForwardingInfo_get_fee_base_msat(this_ptr: &CounterpartyForwardingInfo) -> u32 {
308 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_base_msat;
311 /// Base routing fee in millisatoshis.
313 pub extern "C" fn CounterpartyForwardingInfo_set_fee_base_msat(this_ptr: &mut CounterpartyForwardingInfo, mut val: u32) {
314 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_base_msat = val;
316 /// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
318 pub extern "C" fn CounterpartyForwardingInfo_get_fee_proportional_millionths(this_ptr: &CounterpartyForwardingInfo) -> u32 {
319 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_proportional_millionths;
322 /// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
324 pub extern "C" fn CounterpartyForwardingInfo_set_fee_proportional_millionths(this_ptr: &mut CounterpartyForwardingInfo, mut val: u32) {
325 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_proportional_millionths = val;
327 /// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
328 /// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
329 /// `cltv_expiry_delta` for more details.
331 pub extern "C" fn CounterpartyForwardingInfo_get_cltv_expiry_delta(this_ptr: &CounterpartyForwardingInfo) -> u16 {
332 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
335 /// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
336 /// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
337 /// `cltv_expiry_delta` for more details.
339 pub extern "C" fn CounterpartyForwardingInfo_set_cltv_expiry_delta(this_ptr: &mut CounterpartyForwardingInfo, mut val: u16) {
340 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
342 /// Constructs a new CounterpartyForwardingInfo given each field
345 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 {
346 CounterpartyForwardingInfo { inner: ObjOps::heap_alloc(nativeCounterpartyForwardingInfo {
347 fee_base_msat: fee_base_msat_arg,
348 fee_proportional_millionths: fee_proportional_millionths_arg,
349 cltv_expiry_delta: cltv_expiry_delta_arg,
352 impl Clone for CounterpartyForwardingInfo {
353 fn clone(&self) -> Self {
355 inner: if <*mut nativeCounterpartyForwardingInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
356 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
362 /// Used only if an object of this type is returned as a trait impl by a method
363 pub(crate) extern "C" fn CounterpartyForwardingInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
364 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCounterpartyForwardingInfo)).clone() })) as *mut c_void
367 /// Creates a copy of the CounterpartyForwardingInfo
368 pub extern "C" fn CounterpartyForwardingInfo_clone(orig: &CounterpartyForwardingInfo) -> CounterpartyForwardingInfo {
372 use lightning::ln::channelmanager::ChannelCounterparty as nativeChannelCounterpartyImport;
373 pub(crate) type nativeChannelCounterparty = nativeChannelCounterpartyImport;
375 /// Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
376 /// to better separate parameters.
379 pub struct ChannelCounterparty {
380 /// A pointer to the opaque Rust object.
382 /// Nearly everywhere, inner must be non-null, however in places where
383 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
384 pub inner: *mut nativeChannelCounterparty,
385 /// Indicates that this is the only struct which contains the same pointer.
387 /// Rust functions which take ownership of an object provided via an argument require
388 /// this to be true and invalidate the object pointed to by inner.
392 impl Drop for ChannelCounterparty {
394 if self.is_owned && !<*mut nativeChannelCounterparty>::is_null(self.inner) {
395 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
399 /// Frees any resources used by the ChannelCounterparty, if is_owned is set and inner is non-NULL.
401 pub extern "C" fn ChannelCounterparty_free(this_obj: ChannelCounterparty) { }
403 /// Used only if an object of this type is returned as a trait impl by a method
404 pub(crate) extern "C" fn ChannelCounterparty_free_void(this_ptr: *mut c_void) {
405 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelCounterparty); }
408 impl ChannelCounterparty {
409 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelCounterparty {
410 unsafe { &*ObjOps::untweak_ptr(self.inner) }
412 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelCounterparty {
413 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
415 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
416 pub(crate) fn take_inner(mut self) -> *mut nativeChannelCounterparty {
417 assert!(self.is_owned);
418 let ret = ObjOps::untweak_ptr(self.inner);
419 self.inner = std::ptr::null_mut();
423 /// The node_id of our counterparty
425 pub extern "C" fn ChannelCounterparty_get_node_id(this_ptr: &ChannelCounterparty) -> crate::c_types::PublicKey {
426 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_id;
427 crate::c_types::PublicKey::from_rust(&inner_val)
429 /// The node_id of our counterparty
431 pub extern "C" fn ChannelCounterparty_set_node_id(this_ptr: &mut ChannelCounterparty, mut val: crate::c_types::PublicKey) {
432 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_id = val.into_rust();
434 /// The Features the channel counterparty provided upon last connection.
435 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
436 /// many routing-relevant features are present in the init context.
438 pub extern "C" fn ChannelCounterparty_get_features(this_ptr: &ChannelCounterparty) -> crate::lightning::ln::features::InitFeatures {
439 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
440 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 }
442 /// The Features the channel counterparty provided upon last connection.
443 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
444 /// many routing-relevant features are present in the init context.
446 pub extern "C" fn ChannelCounterparty_set_features(this_ptr: &mut ChannelCounterparty, mut val: crate::lightning::ln::features::InitFeatures) {
447 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
449 /// The value, in satoshis, that must always be held in the channel for our counterparty. This
450 /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
451 /// claiming at least this value on chain.
453 /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
455 /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
457 pub extern "C" fn ChannelCounterparty_get_unspendable_punishment_reserve(this_ptr: &ChannelCounterparty) -> u64 {
458 let mut inner_val = &mut this_ptr.get_native_mut_ref().unspendable_punishment_reserve;
461 /// The value, in satoshis, that must always be held in the channel for our counterparty. This
462 /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
463 /// claiming at least this value on chain.
465 /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
467 /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
469 pub extern "C" fn ChannelCounterparty_set_unspendable_punishment_reserve(this_ptr: &mut ChannelCounterparty, mut val: u64) {
470 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = val;
472 /// Information on the fees and requirements that the counterparty requires when forwarding
473 /// payments to us through this channel.
475 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
477 pub extern "C" fn ChannelCounterparty_get_forwarding_info(this_ptr: &ChannelCounterparty) -> crate::lightning::ln::channelmanager::CounterpartyForwardingInfo {
478 let mut inner_val = &mut this_ptr.get_native_mut_ref().forwarding_info;
479 let mut local_inner_val = crate::lightning::ln::channelmanager::CounterpartyForwardingInfo { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::channelmanager::CounterpartyForwardingInfo<>) as *mut _ }, is_owned: false };
482 /// Information on the fees and requirements that the counterparty requires when forwarding
483 /// payments to us through this channel.
485 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
487 pub extern "C" fn ChannelCounterparty_set_forwarding_info(this_ptr: &mut ChannelCounterparty, mut val: crate::lightning::ln::channelmanager::CounterpartyForwardingInfo) {
488 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
489 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.forwarding_info = local_val;
491 /// Constructs a new ChannelCounterparty given each field
494 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 {
495 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()) } }) };
496 ChannelCounterparty { inner: ObjOps::heap_alloc(nativeChannelCounterparty {
497 node_id: node_id_arg.into_rust(),
498 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
499 unspendable_punishment_reserve: unspendable_punishment_reserve_arg,
500 forwarding_info: local_forwarding_info_arg,
503 impl Clone for ChannelCounterparty {
504 fn clone(&self) -> Self {
506 inner: if <*mut nativeChannelCounterparty>::is_null(self.inner) { std::ptr::null_mut() } else {
507 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
513 /// Used only if an object of this type is returned as a trait impl by a method
514 pub(crate) extern "C" fn ChannelCounterparty_clone_void(this_ptr: *const c_void) -> *mut c_void {
515 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelCounterparty)).clone() })) as *mut c_void
518 /// Creates a copy of the ChannelCounterparty
519 pub extern "C" fn ChannelCounterparty_clone(orig: &ChannelCounterparty) -> ChannelCounterparty {
523 use lightning::ln::channelmanager::ChannelDetails as nativeChannelDetailsImport;
524 pub(crate) type nativeChannelDetails = nativeChannelDetailsImport;
526 /// Details of a channel, as returned by ChannelManager::list_channels and ChannelManager::list_usable_channels
529 pub struct ChannelDetails {
530 /// A pointer to the opaque Rust object.
532 /// Nearly everywhere, inner must be non-null, however in places where
533 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
534 pub inner: *mut nativeChannelDetails,
535 /// Indicates that this is the only struct which contains the same pointer.
537 /// Rust functions which take ownership of an object provided via an argument require
538 /// this to be true and invalidate the object pointed to by inner.
542 impl Drop for ChannelDetails {
544 if self.is_owned && !<*mut nativeChannelDetails>::is_null(self.inner) {
545 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
549 /// Frees any resources used by the ChannelDetails, if is_owned is set and inner is non-NULL.
551 pub extern "C" fn ChannelDetails_free(this_obj: ChannelDetails) { }
553 /// Used only if an object of this type is returned as a trait impl by a method
554 pub(crate) extern "C" fn ChannelDetails_free_void(this_ptr: *mut c_void) {
555 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelDetails); }
558 impl ChannelDetails {
559 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelDetails {
560 unsafe { &*ObjOps::untweak_ptr(self.inner) }
562 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelDetails {
563 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
565 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
566 pub(crate) fn take_inner(mut self) -> *mut nativeChannelDetails {
567 assert!(self.is_owned);
568 let ret = ObjOps::untweak_ptr(self.inner);
569 self.inner = std::ptr::null_mut();
573 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
574 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
575 /// Note that this means this value is *not* persistent - it can change once during the
576 /// lifetime of the channel.
578 pub extern "C" fn ChannelDetails_get_channel_id(this_ptr: &ChannelDetails) -> *const [u8; 32] {
579 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id;
582 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
583 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
584 /// Note that this means this value is *not* persistent - it can change once during the
585 /// lifetime of the channel.
587 pub extern "C" fn ChannelDetails_set_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::ThirtyTwoBytes) {
588 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = val.data;
590 /// Parameters which apply to our counterparty. See individual fields for more information.
592 pub extern "C" fn ChannelDetails_get_counterparty(this_ptr: &ChannelDetails) -> crate::lightning::ln::channelmanager::ChannelCounterparty {
593 let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty;
594 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 }
596 /// Parameters which apply to our counterparty. See individual fields for more information.
598 pub extern "C" fn ChannelDetails_set_counterparty(this_ptr: &mut ChannelDetails, mut val: crate::lightning::ln::channelmanager::ChannelCounterparty) {
599 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty = *unsafe { Box::from_raw(val.take_inner()) };
601 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
602 /// our counterparty already.
604 /// Note that, if this has been set, `channel_id` will be equivalent to
605 /// `funding_txo.unwrap().to_channel_id()`.
607 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
609 pub extern "C" fn ChannelDetails_get_funding_txo(this_ptr: &ChannelDetails) -> crate::lightning::chain::transaction::OutPoint {
610 let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_txo;
611 let mut local_inner_val = crate::lightning::chain::transaction::OutPoint { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::chain::transaction::OutPoint<>) as *mut _ }, is_owned: false };
614 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
615 /// our counterparty already.
617 /// Note that, if this has been set, `channel_id` will be equivalent to
618 /// `funding_txo.unwrap().to_channel_id()`.
620 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
622 pub extern "C" fn ChannelDetails_set_funding_txo(this_ptr: &mut ChannelDetails, mut val: crate::lightning::chain::transaction::OutPoint) {
623 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
624 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_txo = local_val;
626 /// The position of the funding transaction in the chain. None if the funding transaction has
627 /// not yet been confirmed and the channel fully opened.
629 pub extern "C" fn ChannelDetails_get_short_channel_id(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
630 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
631 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() }) };
634 /// The position of the funding transaction in the chain. None if the funding transaction has
635 /// not yet been confirmed and the channel fully opened.
637 pub extern "C" fn ChannelDetails_set_short_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
638 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
639 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = local_val;
641 /// The value, in satoshis, of this channel as appears in the funding output
643 pub extern "C" fn ChannelDetails_get_channel_value_satoshis(this_ptr: &ChannelDetails) -> u64 {
644 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
647 /// The value, in satoshis, of this channel as appears in the funding output
649 pub extern "C" fn ChannelDetails_set_channel_value_satoshis(this_ptr: &mut ChannelDetails, mut val: u64) {
650 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
652 /// The value, in satoshis, that must always be held in the channel for us. This value ensures
653 /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
654 /// this value on chain.
656 /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
658 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
660 /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
662 pub extern "C" fn ChannelDetails_get_unspendable_punishment_reserve(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
663 let mut inner_val = &mut this_ptr.get_native_mut_ref().unspendable_punishment_reserve;
664 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() }) };
667 /// The value, in satoshis, that must always be held in the channel for us. This value ensures
668 /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
669 /// this value on chain.
671 /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
673 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
675 /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
677 pub extern "C" fn ChannelDetails_set_unspendable_punishment_reserve(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
678 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
679 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = local_val;
681 /// The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound.
683 pub extern "C" fn ChannelDetails_get_user_channel_id(this_ptr: &ChannelDetails) -> u64 {
684 let mut inner_val = &mut this_ptr.get_native_mut_ref().user_channel_id;
687 /// The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound.
689 pub extern "C" fn ChannelDetails_set_user_channel_id(this_ptr: &mut ChannelDetails, mut val: u64) {
690 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.user_channel_id = val;
692 /// Our total balance. This is the amount we would get if we close the channel.
693 /// This value is not exact. Due to various in-flight changes and feerate changes, exactly this
694 /// amount is not likely to be recoverable on close.
696 /// This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose
697 /// balance is not available for inclusion in new outbound HTLCs). This further does not include
698 /// any pending outgoing HTLCs which are awaiting some other resolution to be sent.
699 /// This does not consider any on-chain fees.
701 /// See also [`ChannelDetails::outbound_capacity_msat`]
703 pub extern "C" fn ChannelDetails_get_balance_msat(this_ptr: &ChannelDetails) -> u64 {
704 let mut inner_val = &mut this_ptr.get_native_mut_ref().balance_msat;
707 /// Our total balance. This is the amount we would get if we close the channel.
708 /// This value is not exact. Due to various in-flight changes and feerate changes, exactly this
709 /// amount is not likely to be recoverable on close.
711 /// This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose
712 /// balance is not available for inclusion in new outbound HTLCs). This further does not include
713 /// any pending outgoing HTLCs which are awaiting some other resolution to be sent.
714 /// This does not consider any on-chain fees.
716 /// See also [`ChannelDetails::outbound_capacity_msat`]
718 pub extern "C" fn ChannelDetails_set_balance_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
719 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.balance_msat = val;
721 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
722 /// any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
723 /// available for inclusion in new outbound HTLCs). This further does not include any pending
724 /// outgoing HTLCs which are awaiting some other resolution to be sent.
726 /// See also [`ChannelDetails::balance_msat`]
728 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
729 /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
730 /// should be able to spend nearly this amount.
732 pub extern "C" fn ChannelDetails_get_outbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
733 let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_capacity_msat;
736 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
737 /// any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
738 /// available for inclusion in new outbound HTLCs). This further does not include any pending
739 /// outgoing HTLCs which are awaiting some other resolution to be sent.
741 /// See also [`ChannelDetails::balance_msat`]
743 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
744 /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
745 /// should be able to spend nearly this amount.
747 pub extern "C" fn ChannelDetails_set_outbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
748 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_capacity_msat = val;
750 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
751 /// include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
752 /// available for inclusion in new inbound HTLCs).
753 /// Note that there are some corner cases not fully handled here, so the actual available
754 /// inbound capacity may be slightly higher than this.
756 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
757 /// counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
758 /// However, our counterparty should be able to spend nearly this amount.
760 pub extern "C" fn ChannelDetails_get_inbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
761 let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_capacity_msat;
764 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
765 /// include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
766 /// available for inclusion in new inbound HTLCs).
767 /// Note that there are some corner cases not fully handled here, so the actual available
768 /// inbound capacity may be slightly higher than this.
770 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
771 /// counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
772 /// However, our counterparty should be able to spend nearly this amount.
774 pub extern "C" fn ChannelDetails_set_inbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
775 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_capacity_msat = val;
777 /// The number of required confirmations on the funding transaction before the funding will be
778 /// considered \"locked\". This number is selected by the channel fundee (i.e. us if
779 /// [`is_outbound`] is *not* set), and can be selected for inbound channels with
780 /// [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
781 /// [`ChannelHandshakeLimits::max_minimum_depth`].
783 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
785 /// [`is_outbound`]: ChannelDetails::is_outbound
786 /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
787 /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
789 pub extern "C" fn ChannelDetails_get_confirmations_required(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u32Z {
790 let mut inner_val = &mut this_ptr.get_native_mut_ref().confirmations_required;
791 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() }) };
794 /// The number of required confirmations on the funding transaction before the funding will be
795 /// considered \"locked\". This number is selected by the channel fundee (i.e. us if
796 /// [`is_outbound`] is *not* set), and can be selected for inbound channels with
797 /// [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
798 /// [`ChannelHandshakeLimits::max_minimum_depth`].
800 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
802 /// [`is_outbound`]: ChannelDetails::is_outbound
803 /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
804 /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
806 pub extern "C" fn ChannelDetails_set_confirmations_required(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u32Z) {
807 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
808 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.confirmations_required = local_val;
810 /// The number of blocks (after our commitment transaction confirms) that we will need to wait
811 /// until we can claim our funds after we force-close the channel. During this time our
812 /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
813 /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any
814 /// time to claim our non-HTLC-encumbered funds.
816 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
818 pub extern "C" fn ChannelDetails_get_force_close_spend_delay(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u16Z {
819 let mut inner_val = &mut this_ptr.get_native_mut_ref().force_close_spend_delay;
820 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() }) };
823 /// The number of blocks (after our commitment transaction confirms) that we will need to wait
824 /// until we can claim our funds after we force-close the channel. During this time our
825 /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
826 /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any
827 /// time to claim our non-HTLC-encumbered funds.
829 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
831 pub extern "C" fn ChannelDetails_set_force_close_spend_delay(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u16Z) {
832 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
833 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.force_close_spend_delay = local_val;
835 /// True if the channel was initiated (and thus funded) by us.
837 pub extern "C" fn ChannelDetails_get_is_outbound(this_ptr: &ChannelDetails) -> bool {
838 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_outbound;
841 /// True if the channel was initiated (and thus funded) by us.
843 pub extern "C" fn ChannelDetails_set_is_outbound(this_ptr: &mut ChannelDetails, mut val: bool) {
844 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_outbound = val;
846 /// True if the channel is confirmed, funding_locked messages have been exchanged, and the
847 /// channel is not currently being shut down. `funding_locked` message exchange implies the
848 /// required confirmation count has been reached (and we were connected to the peer at some
849 /// point after the funding transaction received enough confirmations). The required
850 /// confirmation count is provided in [`confirmations_required`].
852 /// [`confirmations_required`]: ChannelDetails::confirmations_required
854 pub extern "C" fn ChannelDetails_get_is_funding_locked(this_ptr: &ChannelDetails) -> bool {
855 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_funding_locked;
858 /// True if the channel is confirmed, funding_locked messages have been exchanged, and the
859 /// channel is not currently being shut down. `funding_locked` message exchange implies the
860 /// required confirmation count has been reached (and we were connected to the peer at some
861 /// point after the funding transaction received enough confirmations). The required
862 /// confirmation count is provided in [`confirmations_required`].
864 /// [`confirmations_required`]: ChannelDetails::confirmations_required
866 pub extern "C" fn ChannelDetails_set_is_funding_locked(this_ptr: &mut ChannelDetails, mut val: bool) {
867 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_funding_locked = val;
869 /// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
870 /// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
872 /// This is a strict superset of `is_funding_locked`.
874 pub extern "C" fn ChannelDetails_get_is_usable(this_ptr: &ChannelDetails) -> bool {
875 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_usable;
878 /// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
879 /// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
881 /// This is a strict superset of `is_funding_locked`.
883 pub extern "C" fn ChannelDetails_set_is_usable(this_ptr: &mut ChannelDetails, mut val: bool) {
884 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_usable = val;
886 /// True if this channel is (or will be) publicly-announced.
888 pub extern "C" fn ChannelDetails_get_is_public(this_ptr: &ChannelDetails) -> bool {
889 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_public;
892 /// True if this channel is (or will be) publicly-announced.
894 pub extern "C" fn ChannelDetails_set_is_public(this_ptr: &mut ChannelDetails, mut val: bool) {
895 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_public = val;
897 /// Constructs a new ChannelDetails given each field
900 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 {
901 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()) } }) };
902 let mut local_short_channel_id_arg = if short_channel_id_arg.is_some() { Some( { short_channel_id_arg.take() }) } else { None };
903 let mut local_unspendable_punishment_reserve_arg = if unspendable_punishment_reserve_arg.is_some() { Some( { unspendable_punishment_reserve_arg.take() }) } else { None };
904 let mut local_confirmations_required_arg = if confirmations_required_arg.is_some() { Some( { confirmations_required_arg.take() }) } else { None };
905 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 };
906 ChannelDetails { inner: ObjOps::heap_alloc(nativeChannelDetails {
907 channel_id: channel_id_arg.data,
908 counterparty: *unsafe { Box::from_raw(counterparty_arg.take_inner()) },
909 funding_txo: local_funding_txo_arg,
910 short_channel_id: local_short_channel_id_arg,
911 channel_value_satoshis: channel_value_satoshis_arg,
912 unspendable_punishment_reserve: local_unspendable_punishment_reserve_arg,
913 user_channel_id: user_channel_id_arg,
914 balance_msat: balance_msat_arg,
915 outbound_capacity_msat: outbound_capacity_msat_arg,
916 inbound_capacity_msat: inbound_capacity_msat_arg,
917 confirmations_required: local_confirmations_required_arg,
918 force_close_spend_delay: local_force_close_spend_delay_arg,
919 is_outbound: is_outbound_arg,
920 is_funding_locked: is_funding_locked_arg,
921 is_usable: is_usable_arg,
922 is_public: is_public_arg,
925 impl Clone for ChannelDetails {
926 fn clone(&self) -> Self {
928 inner: if <*mut nativeChannelDetails>::is_null(self.inner) { std::ptr::null_mut() } else {
929 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
935 /// Used only if an object of this type is returned as a trait impl by a method
936 pub(crate) extern "C" fn ChannelDetails_clone_void(this_ptr: *const c_void) -> *mut c_void {
937 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelDetails)).clone() })) as *mut c_void
940 /// Creates a copy of the ChannelDetails
941 pub extern "C" fn ChannelDetails_clone(orig: &ChannelDetails) -> ChannelDetails {
944 /// If a payment fails to send, it can be in one of several states. This enum is returned as the
945 /// Err() type describing which state the payment is in, see the description of individual enum
950 pub enum PaymentSendFailure {
951 /// A parameter which was passed to send_payment was invalid, preventing us from attempting to
952 /// send the payment at all. No channel state has been changed or messages sent to peers, and
953 /// once you've changed the parameter at error, you can freely retry the payment in full.
954 ParameterError(crate::lightning::util::errors::APIError),
955 /// A parameter in a single path which was passed to send_payment was invalid, preventing us
956 /// from attempting to send the payment at all. No channel state has been changed or messages
957 /// sent to peers, and once you've changed the parameter at error, you can freely retry the
960 /// The results here are ordered the same as the paths in the route object which was passed to
962 PathParameterError(crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ),
963 /// All paths which were attempted failed to send, with no channel state change taking place.
964 /// You can freely retry the payment in full (though you probably want to do so over different
965 /// paths than the ones selected).
966 AllFailedRetrySafe(crate::c_types::derived::CVec_APIErrorZ),
967 /// Some paths which were attempted failed to send, though possibly not all. At least some
968 /// paths have irrevocably committed to the HTLC and retrying the payment in full would result
969 /// in over-/re-payment.
971 /// The results here are ordered the same as the paths in the route object which was passed to
972 /// send_payment, and any Errs which are not APIError::MonitorUpdateFailed can be safely
973 /// retried (though there is currently no API with which to do so).
975 /// Any entries which contain Err(APIError::MonitorUpdateFailed) or Ok(()) MUST NOT be retried
976 /// as they will result in over-/re-payment. These HTLCs all either successfully sent (in the
977 /// case of Ok(())) or will send once channel_monitor_updated is called on the next-hop channel
978 /// with the latest update_id.
980 /// The errors themselves, in the same order as the route hops.
981 results: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ,
982 /// If some paths failed without irrevocably committing to the new HTLC(s), this will
983 /// contain a [`RouteParameters`] object which can be used to calculate a new route that
984 /// will pay all remaining unpaid balance.
986 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
987 failed_paths_retry: crate::lightning::routing::router::RouteParameters,
988 /// The payment id for the payment, which is now at least partially pending.
989 payment_id: crate::c_types::ThirtyTwoBytes,
992 use lightning::ln::channelmanager::PaymentSendFailure as nativePaymentSendFailure;
993 impl PaymentSendFailure {
995 pub(crate) fn to_native(&self) -> nativePaymentSendFailure {
997 PaymentSendFailure::ParameterError (ref a, ) => {
998 let mut a_nonref = (*a).clone();
999 nativePaymentSendFailure::ParameterError (
1000 a_nonref.into_native(),
1003 PaymentSendFailure::PathParameterError (ref a, ) => {
1004 let mut a_nonref = (*a).clone();
1005 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 }); };
1006 nativePaymentSendFailure::PathParameterError (
1010 PaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
1011 let mut a_nonref = (*a).clone();
1012 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { item.into_native() }); };
1013 nativePaymentSendFailure::AllFailedRetrySafe (
1017 PaymentSendFailure::PartialFailure {ref results, ref failed_paths_retry, ref payment_id, } => {
1018 let mut results_nonref = (*results).clone();
1019 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 }); };
1020 let mut failed_paths_retry_nonref = (*failed_paths_retry).clone();
1021 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()) } }) };
1022 let mut payment_id_nonref = (*payment_id).clone();
1023 nativePaymentSendFailure::PartialFailure {
1024 results: local_results_nonref,
1025 failed_paths_retry: local_failed_paths_retry_nonref,
1026 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1032 pub(crate) fn into_native(self) -> nativePaymentSendFailure {
1034 PaymentSendFailure::ParameterError (mut a, ) => {
1035 nativePaymentSendFailure::ParameterError (
1039 PaymentSendFailure::PathParameterError (mut a, ) => {
1040 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 }); };
1041 nativePaymentSendFailure::PathParameterError (
1045 PaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
1046 let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { item.into_native() }); };
1047 nativePaymentSendFailure::AllFailedRetrySafe (
1051 PaymentSendFailure::PartialFailure {mut results, mut failed_paths_retry, mut payment_id, } => {
1052 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 }); };
1053 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()) } }) };
1054 nativePaymentSendFailure::PartialFailure {
1055 results: local_results,
1056 failed_paths_retry: local_failed_paths_retry,
1057 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1063 pub(crate) fn from_native(native: &nativePaymentSendFailure) -> Self {
1065 nativePaymentSendFailure::ParameterError (ref a, ) => {
1066 let mut a_nonref = (*a).clone();
1067 PaymentSendFailure::ParameterError (
1068 crate::lightning::util::errors::APIError::native_into(a_nonref),
1071 nativePaymentSendFailure::PathParameterError (ref a, ) => {
1072 let mut a_nonref = (*a).clone();
1073 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 }); };
1074 PaymentSendFailure::PathParameterError (
1075 local_a_nonref.into(),
1078 nativePaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
1079 let mut a_nonref = (*a).clone();
1080 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) }); };
1081 PaymentSendFailure::AllFailedRetrySafe (
1082 local_a_nonref.into(),
1085 nativePaymentSendFailure::PartialFailure {ref results, ref failed_paths_retry, ref payment_id, } => {
1086 let mut results_nonref = (*results).clone();
1087 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 }); };
1088 let mut failed_paths_retry_nonref = (*failed_paths_retry).clone();
1089 let mut local_failed_paths_retry_nonref = crate::lightning::routing::router::RouteParameters { inner: if failed_paths_retry_nonref.is_none() { std::ptr::null_mut() } else { { ObjOps::heap_alloc((failed_paths_retry_nonref.unwrap())) } }, is_owned: true };
1090 let mut payment_id_nonref = (*payment_id).clone();
1091 PaymentSendFailure::PartialFailure {
1092 results: local_results_nonref.into(),
1093 failed_paths_retry: local_failed_paths_retry_nonref,
1094 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1100 pub(crate) fn native_into(native: nativePaymentSendFailure) -> Self {
1102 nativePaymentSendFailure::ParameterError (mut a, ) => {
1103 PaymentSendFailure::ParameterError (
1104 crate::lightning::util::errors::APIError::native_into(a),
1107 nativePaymentSendFailure::PathParameterError (mut a, ) => {
1108 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 }); };
1109 PaymentSendFailure::PathParameterError (
1113 nativePaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
1114 let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { crate::lightning::util::errors::APIError::native_into(item) }); };
1115 PaymentSendFailure::AllFailedRetrySafe (
1119 nativePaymentSendFailure::PartialFailure {mut results, mut failed_paths_retry, mut payment_id, } => {
1120 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 }); };
1121 let mut local_failed_paths_retry = crate::lightning::routing::router::RouteParameters { inner: if failed_paths_retry.is_none() { std::ptr::null_mut() } else { { ObjOps::heap_alloc((failed_paths_retry.unwrap())) } }, is_owned: true };
1122 PaymentSendFailure::PartialFailure {
1123 results: local_results.into(),
1124 failed_paths_retry: local_failed_paths_retry,
1125 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1131 /// Frees any resources used by the PaymentSendFailure
1133 pub extern "C" fn PaymentSendFailure_free(this_ptr: PaymentSendFailure) { }
1134 /// Creates a copy of the PaymentSendFailure
1136 pub extern "C" fn PaymentSendFailure_clone(orig: &PaymentSendFailure) -> PaymentSendFailure {
1140 /// Utility method to constructs a new ParameterError-variant PaymentSendFailure
1141 pub extern "C" fn PaymentSendFailure_parameter_error(a: crate::lightning::util::errors::APIError) -> PaymentSendFailure {
1142 PaymentSendFailure::ParameterError(a, )
1145 /// Utility method to constructs a new PathParameterError-variant PaymentSendFailure
1146 pub extern "C" fn PaymentSendFailure_path_parameter_error(a: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ) -> PaymentSendFailure {
1147 PaymentSendFailure::PathParameterError(a, )
1150 /// Utility method to constructs a new AllFailedRetrySafe-variant PaymentSendFailure
1151 pub extern "C" fn PaymentSendFailure_all_failed_retry_safe(a: crate::c_types::derived::CVec_APIErrorZ) -> PaymentSendFailure {
1152 PaymentSendFailure::AllFailedRetrySafe(a, )
1155 /// Utility method to constructs a new PartialFailure-variant PaymentSendFailure
1156 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 {
1157 PaymentSendFailure::PartialFailure {
1163 /// Constructs a new ChannelManager to hold several channels and route between them.
1165 /// This is the main \"logic hub\" for all channel-related actions, and implements
1166 /// ChannelMessageHandler.
1168 /// Non-proportional fees are fixed according to our risk using the provided fee estimator.
1170 /// panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`!
1172 /// Users need to notify the new ChannelManager when a new block is connected or
1173 /// disconnected using its `block_connected` and `block_disconnected` methods, starting
1174 /// from after `params.latest_hash`.
1177 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 {
1178 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()) });
1179 ChannelManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
1182 /// Gets the current configuration applied to all new channels, as
1185 pub extern "C" fn ChannelManager_get_current_default_configuration(this_arg: &ChannelManager) -> crate::lightning::util::config::UserConfig {
1186 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_current_default_configuration();
1187 crate::lightning::util::config::UserConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::util::config::UserConfig<>) as *mut _) }, is_owned: false }
1190 /// Creates a new outbound channel to the given remote node and with the given value.
1192 /// `user_channel_id` will be provided back as in
1193 /// [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
1194 /// correspond with which `create_channel` call. Note that the `user_channel_id` defaults to 0
1195 /// for inbound channels, so you may wish to avoid using 0 for `user_channel_id` here.
1196 /// `user_channel_id` has no meaning inside of LDK, it is simply copied to events and otherwise
1199 /// Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is
1200 /// greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`.
1202 /// Note that we do not check if you are currently connected to the given peer. If no
1203 /// connection is available, the outbound `open_channel` message may fail to send, resulting in
1204 /// the channel eventually being silently forgotten (dropped on reload).
1206 /// Returns the new Channel's temporary `channel_id`. This ID will appear as
1207 /// [`Event::FundingGenerationReady::temporary_channel_id`] and in
1208 /// [`ChannelDetails::channel_id`] until after
1209 /// [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
1210 /// one derived from the funding transaction's TXID. If the counterparty rejects the channel
1211 /// immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
1213 /// [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
1214 /// [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
1215 /// [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
1217 /// Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
1220 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 {
1221 let mut local_override_config = if override_config.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(override_config.take_inner()) } }) };
1222 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);
1223 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() };
1227 /// Gets the list of open channels, in random order. See ChannelDetail field documentation for
1228 /// more information.
1231 pub extern "C" fn ChannelManager_list_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1232 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_channels();
1233 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 } }); };
1237 /// Gets the list of usable channels, in random order. Useful as an argument to
1238 /// get_route to ensure non-announced channels are used.
1240 /// These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
1241 /// documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
1245 pub extern "C" fn ChannelManager_list_usable_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1246 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_usable_channels();
1247 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 } }); };
1251 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
1252 /// will be accepted on the given channel, and after additional timeout/the closing of all
1253 /// pending HTLCs, the channel will be closed on chain.
1255 /// * If we are the channel initiator, we will pay between our [`Background`] and
1256 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
1258 /// * If our counterparty is the channel initiator, we will require a channel closing
1259 /// transaction feerate of at least our [`Background`] feerate or the feerate which
1260 /// would appear on a force-closure transaction, whichever is lower. We will allow our
1261 /// counterparty to pay as much fee as they'd like, however.
1263 /// May generate a SendShutdown message event on success, which should be relayed.
1265 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
1266 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1267 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1270 pub extern "C" fn ChannelManager_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1271 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel(unsafe { &*channel_id});
1272 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() };
1276 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
1277 /// will be accepted on the given channel, and after additional timeout/the closing of all
1278 /// pending HTLCs, the channel will be closed on chain.
1280 /// `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
1281 /// the channel being closed or not:
1282 /// * If we are the channel initiator, we will pay at least this feerate on the closing
1283 /// transaction. The upper-bound is set by
1284 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
1285 /// estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
1286 /// * If our counterparty is the channel initiator, we will refuse to accept a channel closure
1287 /// transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
1288 /// will appear on a force-closure transaction, whichever is lower).
1290 /// May generate a SendShutdown message event on success, which should be relayed.
1292 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
1293 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1294 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1297 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 {
1298 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel_with_target_feerate(unsafe { &*channel_id}, target_feerate_sats_per_1000_weight);
1299 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() };
1303 /// Force closes a channel, immediately broadcasting the latest local commitment transaction to
1304 /// the chain and rejecting new HTLCs on the given channel. Fails if channel_id is unknown to the manager.
1307 pub extern "C" fn ChannelManager_force_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1308 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_channel(unsafe { &*channel_id});
1309 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() };
1313 /// Force close all channels, immediately broadcasting the latest local commitment transaction
1314 /// for each to the chain and rejecting new HTLCs on each.
1316 pub extern "C" fn ChannelManager_force_close_all_channels(this_arg: &ChannelManager) {
1317 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_all_channels()
1320 /// Sends a payment along a given route.
1322 /// Value parameters are provided via the last hop in route, see documentation for RouteHop
1323 /// fields for more info.
1325 /// Note that if the payment_hash already exists elsewhere (eg you're sending a duplicative
1326 /// payment), we don't do anything to stop you! We always try to ensure that if the provided
1327 /// next hop knows the preimage to payment_hash they can claim an additional amount as
1328 /// specified in the last hop in the route! Thus, you should probably do your own
1329 /// payment_preimage tracking (which you should already be doing as they represent \"proof of
1330 /// payment\") and prevent double-sends yourself.
1332 /// May generate SendHTLCs message(s) event on success, which should be relayed.
1334 /// Each path may have a different return value, and PaymentSendValue may return a Vec with
1335 /// each entry matching the corresponding-index entry in the route paths, see
1336 /// PaymentSendFailure for more info.
1338 /// In general, a path may raise:
1339 /// * APIError::RouteError when an invalid route or forwarding parameter (cltv_delta, fee,
1340 /// node public key) is specified.
1341 /// * APIError::ChannelUnavailable if the next-hop channel is not available for updates
1342 /// (including due to previous monitor update failure or new permanent monitor update
1344 /// * APIError::MonitorUpdateFailed if a new monitor update failure prevented sending the
1345 /// relevant updates.
1347 /// Note that depending on the type of the PaymentSendFailure the HTLC may have been
1348 /// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
1349 /// different route unless you intend to pay twice!
1351 /// payment_secret is unrelated to payment_hash (or PaymentPreimage) and exists to authenticate
1352 /// the sender to the recipient and prevent payment-probing (deanonymization) attacks. For
1353 /// newer nodes, it will be provided to you in the invoice. If you do not have one, the Route
1354 /// must not contain multiple paths as multi-path payments require a recipient-provided
1356 /// If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature
1357 /// bit set (either as required or as available). If multiple paths are present in the Route,
1358 /// we assume the invoice had the basic_mpp feature set.
1360 /// Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
1363 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 {
1364 let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentSecret(payment_secret.data) }) };
1365 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);
1366 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() };
1370 /// Retries a payment along the given [`Route`].
1372 /// Errors returned are a superset of those returned from [`send_payment`], so see
1373 /// [`send_payment`] documentation for more details on errors. This method will also error if the
1374 /// retry amount puts the payment more than 10% over the payment's total amount, if the payment
1375 /// for the given `payment_id` cannot be found (likely due to timeout or success), or if
1376 /// further retries have been disabled with [`abandon_payment`].
1378 /// [`send_payment`]: [`ChannelManager::send_payment`]
1379 /// [`abandon_payment`]: [`ChannelManager::abandon_payment`]
1382 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 {
1383 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.retry_payment(route.get_native_ref(), ::lightning::ln::channelmanager::PaymentId(payment_id.data));
1384 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() };
1388 /// Signals that no further retries for the given payment will occur.
1390 /// After this method returns, any future calls to [`retry_payment`] for the given `payment_id`
1391 /// will fail with [`PaymentSendFailure::ParameterError`]. If no such event has been generated,
1392 /// an [`Event::PaymentFailed`] event will be generated as soon as there are no remaining
1393 /// pending HTLCs for this payment.
1395 /// Note that calling this method does *not* prevent a payment from succeeding. You must still
1396 /// wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to
1397 /// determine the ultimate status of a payment.
1399 /// [`retry_payment`]: Self::retry_payment
1400 /// [`Event::PaymentFailed`]: events::Event::PaymentFailed
1401 /// [`Event::PaymentSent`]: events::Event::PaymentSent
1403 pub extern "C" fn ChannelManager_abandon_payment(this_arg: &ChannelManager, mut payment_id: crate::c_types::ThirtyTwoBytes) {
1404 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.abandon_payment(::lightning::ln::channelmanager::PaymentId(payment_id.data))
1407 /// Send a spontaneous payment, which is a payment that does not require the recipient to have
1408 /// generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
1409 /// the preimage, it must be a cryptographically secure random value that no intermediate node
1410 /// would be able to guess -- otherwise, an intermediate node may claim the payment and it will
1411 /// never reach the recipient.
1413 /// See [`send_payment`] documentation for more details on the return value of this function.
1415 /// Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
1416 /// [`send_payment`] for more information about the risks of duplicate preimage usage.
1418 /// Note that `route` must have exactly one path.
1420 /// [`send_payment`]: Self::send_payment
1422 /// Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None
1425 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 {
1426 let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
1427 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_spontaneous_payment(route.get_native_ref(), local_payment_preimage);
1428 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() };
1432 /// Call this upon creation of a funding transaction for the given channel.
1434 /// Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
1435 /// or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
1437 /// Returns [`APIError::ChannelUnavailable`] if a funding transaction has already been provided
1438 /// for the channel or if the channel has been closed as indicated by [`Event::ChannelClosed`].
1440 /// May panic if the output found in the funding transaction is duplicative with some other
1441 /// channel (note that this should be trivially prevented by using unique funding transaction
1442 /// keys per-channel).
1444 /// Do NOT broadcast the funding transaction yourself. When we have safely received our
1445 /// counterparty's signature the funding transaction will automatically be broadcast via the
1446 /// [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
1448 /// Note that this includes RBF or similar transaction replacement strategies - lightning does
1449 /// not currently support replacing a funding transaction on an existing channel. Instead,
1450 /// create a new channel with a conflicting funding transaction.
1452 /// [`Event::FundingGenerationReady`]: crate::util::events::Event::FundingGenerationReady
1453 /// [`Event::ChannelClosed`]: crate::util::events::Event::ChannelClosed
1456 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 {
1457 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_transaction_generated(unsafe { &*temporary_channel_id}, funding_transaction.into_bitcoin());
1458 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() };
1462 /// Regenerates channel_announcements and generates a signed node_announcement from the given
1463 /// arguments, providing them in corresponding events via
1464 /// [`get_and_clear_pending_msg_events`], if at least one public channel has been confirmed
1465 /// on-chain. This effectively re-broadcasts all channel announcements and sends our node
1466 /// announcement to ensure that the lightning P2P network is aware of the channels we have and
1467 /// our network addresses.
1469 /// `rgb` is a node \"color\" and `alias` is a printable human-readable string to describe this
1470 /// node to humans. They carry no in-protocol meaning.
1472 /// `addresses` represent the set (possibly empty) of socket addresses on which this node
1473 /// accepts incoming connections. These will be included in the node_announcement, publicly
1474 /// tying these addresses together and to this node. If you wish to preserve user privacy,
1475 /// addresses should likely contain only Tor Onion addresses.
1477 /// Panics if `addresses` is absurdly large (more than 500).
1479 /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
1481 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) {
1482 let mut local_addresses = Vec::new(); for mut item in addresses.into_rust().drain(..) { local_addresses.push( { item.into_native() }); };
1483 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.broadcast_node_announcement(rgb.data, alias.data, local_addresses)
1486 /// Processes HTLCs which are pending waiting on random forward delay.
1488 /// Should only really ever be called in response to a PendingHTLCsForwardable event.
1489 /// Will likely generate further events.
1491 pub extern "C" fn ChannelManager_process_pending_htlc_forwards(this_arg: &ChannelManager) {
1492 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_pending_htlc_forwards()
1495 /// Performs actions which should happen on startup and roughly once per minute thereafter.
1497 /// This currently includes:
1498 /// * Increasing or decreasing the on-chain feerate estimates for our outbound channels,
1499 /// * Broadcasting `ChannelUpdate` messages if we've been disconnected from our peer for more
1500 /// than a minute, informing the network that they should no longer attempt to route over
1503 /// Note that this may cause reentrancy through `chain::Watch::update_channel` calls or feerate
1504 /// estimate fetches.
1506 pub extern "C" fn ChannelManager_timer_tick_occurred(this_arg: &ChannelManager) {
1507 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timer_tick_occurred()
1510 /// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
1511 /// after a PaymentReceived event, failing the HTLC back to its origin and freeing resources
1512 /// along the path (including in our own channel on which we received it).
1513 /// Returns false if no payment was found to fail backwards, true if the process of failing the
1514 /// HTLC backwards has been started.
1517 pub extern "C" fn ChannelManager_fail_htlc_backwards(this_arg: &ChannelManager, payment_hash: *const [u8; 32]) -> bool {
1518 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_htlc_backwards(&::lightning::ln::PaymentHash(unsafe { *payment_hash }));
1522 /// Provides a payment preimage in response to [`Event::PaymentReceived`], generating any
1523 /// [`MessageSendEvent`]s needed to claim the payment.
1525 /// Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
1526 /// [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentReceived`
1527 /// event matches your expectation. If you fail to do so and call this method, you may provide
1528 /// the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
1530 /// Returns whether any HTLCs were claimed, and thus if any new [`MessageSendEvent`]s are now
1531 /// pending for processing via [`get_and_clear_pending_msg_events`].
1533 /// [`Event::PaymentReceived`]: crate::util::events::Event::PaymentReceived
1534 /// [`create_inbound_payment`]: Self::create_inbound_payment
1535 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1536 /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
1539 pub extern "C" fn ChannelManager_claim_funds(this_arg: &ChannelManager, mut payment_preimage: crate::c_types::ThirtyTwoBytes) -> bool {
1540 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.claim_funds(::lightning::ln::PaymentPreimage(payment_preimage.data));
1544 /// Gets the node_id held by this ChannelManager
1547 pub extern "C" fn ChannelManager_get_our_node_id(this_arg: &ChannelManager) -> crate::c_types::PublicKey {
1548 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_our_node_id();
1549 crate::c_types::PublicKey::from_rust(&ret)
1552 /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
1555 /// This differs from [`create_inbound_payment_for_hash`] only in that it generates the
1556 /// [`PaymentHash`] and [`PaymentPreimage`] for you.
1558 /// The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentReceived`], which
1559 /// will have the [`PaymentReceived::payment_preimage`] field filled in. That should then be
1560 /// passed directly to [`claim_funds`].
1562 /// See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
1564 /// Note that a malicious eavesdropper can intuit whether an inbound payment was created by
1565 /// `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
1569 /// If you register an inbound payment with this method, then serialize the `ChannelManager`, then
1570 /// deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
1572 /// Errors if `min_value_msat` is greater than total bitcoin supply.
1574 /// [`claim_funds`]: Self::claim_funds
1575 /// [`PaymentReceived`]: events::Event::PaymentReceived
1576 /// [`PaymentReceived::payment_preimage`]: events::Event::PaymentReceived::payment_preimage
1577 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1580 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 {
1581 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
1582 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment(local_min_value_msat, invoice_expiry_delta_secs);
1583 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() };
1587 /// Legacy version of [`create_inbound_payment`]. Use this method if you wish to share
1588 /// serialized state with LDK node(s) running 0.0.103 and earlier.
1591 /// This method is deprecated and will be removed soon.
1593 /// [`create_inbound_payment`]: Self::create_inbound_payment
1596 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 {
1597 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
1598 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment_legacy(local_min_value_msat, invoice_expiry_delta_secs);
1599 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() };
1603 /// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
1604 /// stored external to LDK.
1606 /// A [`PaymentReceived`] event will only be generated if the [`PaymentSecret`] matches a
1607 /// payment secret fetched via this method or [`create_inbound_payment`], and which is at least
1608 /// the `min_value_msat` provided here, if one is provided.
1610 /// The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) should be globally unique, though
1611 /// note that LDK will not stop you from registering duplicate payment hashes for inbound
1614 /// `min_value_msat` should be set if the invoice being generated contains a value. Any payment
1615 /// received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
1616 /// before a [`PaymentReceived`] event will be generated, ensuring that we do not provide the
1617 /// sender \"proof-of-payment\" unless they have paid the required amount.
1619 /// `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
1620 /// in excess of the current time. This should roughly match the expiry time set in the invoice.
1621 /// After this many seconds, we will remove the inbound payment, resulting in any attempts to
1622 /// pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
1623 /// invoices when no timeout is set.
1625 /// Note that we use block header time to time-out pending inbound payments (with some margin
1626 /// to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
1627 /// accept a payment and generate a [`PaymentReceived`] event for some time after the expiry.
1628 /// If you need exact expiry semantics, you should enforce them upon receipt of
1629 /// [`PaymentReceived`].
1631 /// May panic if `invoice_expiry_delta_secs` is greater than one year.
1633 /// Note that invoices generated for inbound payments should have their `min_final_cltv_expiry`
1634 /// set to at least [`MIN_FINAL_CLTV_EXPIRY`].
1636 /// Note that a malicious eavesdropper can intuit whether an inbound payment was created by
1637 /// `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
1641 /// If you register an inbound payment with this method, then serialize the `ChannelManager`, then
1642 /// deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
1644 /// Errors if `min_value_msat` is greater than total bitcoin supply.
1646 /// [`create_inbound_payment`]: Self::create_inbound_payment
1647 /// [`PaymentReceived`]: events::Event::PaymentReceived
1650 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 {
1651 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
1652 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);
1653 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() };
1657 /// Legacy version of [`create_inbound_payment_for_hash`]. Use this method if you wish to share
1658 /// serialized state with LDK node(s) running 0.0.103 and earlier.
1661 /// This method is deprecated and will be removed soon.
1663 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1666 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 {
1667 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
1668 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);
1669 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() };
1673 /// Gets an LDK-generated payment preimage from a payment hash and payment secret that were
1674 /// previously returned from [`create_inbound_payment`].
1676 /// [`create_inbound_payment`]: Self::create_inbound_payment
1679 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 {
1680 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));
1681 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() };
1685 impl From<nativeChannelManager> for crate::lightning::util::events::MessageSendEventsProvider {
1686 fn from(obj: nativeChannelManager) -> Self {
1687 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1688 let mut ret = ChannelManager_as_MessageSendEventsProvider(&rust_obj);
1689 // 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
1690 rust_obj.inner = std::ptr::null_mut();
1691 ret.free = Some(ChannelManager_free_void);
1695 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
1696 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
1698 pub extern "C" fn ChannelManager_as_MessageSendEventsProvider(this_arg: &ChannelManager) -> crate::lightning::util::events::MessageSendEventsProvider {
1699 crate::lightning::util::events::MessageSendEventsProvider {
1700 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1702 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
1707 extern "C" fn ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
1708 let mut ret = <nativeChannelManager as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
1709 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
1713 impl From<nativeChannelManager> for crate::lightning::util::events::EventsProvider {
1714 fn from(obj: nativeChannelManager) -> Self {
1715 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1716 let mut ret = ChannelManager_as_EventsProvider(&rust_obj);
1717 // 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
1718 rust_obj.inner = std::ptr::null_mut();
1719 ret.free = Some(ChannelManager_free_void);
1723 /// Constructs a new EventsProvider which calls the relevant methods on this_arg.
1724 /// This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
1726 pub extern "C" fn ChannelManager_as_EventsProvider(this_arg: &ChannelManager) -> crate::lightning::util::events::EventsProvider {
1727 crate::lightning::util::events::EventsProvider {
1728 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1730 process_pending_events: ChannelManager_EventsProvider_process_pending_events,
1734 extern "C" fn ChannelManager_EventsProvider_process_pending_events(this_arg: *const c_void, mut handler: crate::lightning::util::events::EventHandler) {
1735 <nativeChannelManager as lightning::util::events::EventsProvider<>>::process_pending_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, handler)
1738 impl From<nativeChannelManager> for crate::lightning::chain::Listen {
1739 fn from(obj: nativeChannelManager) -> Self {
1740 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1741 let mut ret = ChannelManager_as_Listen(&rust_obj);
1742 // 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
1743 rust_obj.inner = std::ptr::null_mut();
1744 ret.free = Some(ChannelManager_free_void);
1748 /// Constructs a new Listen which calls the relevant methods on this_arg.
1749 /// This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
1751 pub extern "C" fn ChannelManager_as_Listen(this_arg: &ChannelManager) -> crate::lightning::chain::Listen {
1752 crate::lightning::chain::Listen {
1753 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1755 block_connected: ChannelManager_Listen_block_connected,
1756 block_disconnected: ChannelManager_Listen_block_disconnected,
1760 extern "C" fn ChannelManager_Listen_block_connected(this_arg: *const c_void, mut block: crate::c_types::u8slice, mut height: u32) {
1761 <nativeChannelManager as lightning::chain::Listen<>>::block_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height)
1763 extern "C" fn ChannelManager_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
1764 <nativeChannelManager as lightning::chain::Listen<>>::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
1767 impl From<nativeChannelManager> for crate::lightning::chain::Confirm {
1768 fn from(obj: nativeChannelManager) -> Self {
1769 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1770 let mut ret = ChannelManager_as_Confirm(&rust_obj);
1771 // 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
1772 rust_obj.inner = std::ptr::null_mut();
1773 ret.free = Some(ChannelManager_free_void);
1777 /// Constructs a new Confirm which calls the relevant methods on this_arg.
1778 /// This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
1780 pub extern "C" fn ChannelManager_as_Confirm(this_arg: &ChannelManager) -> crate::lightning::chain::Confirm {
1781 crate::lightning::chain::Confirm {
1782 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1784 transactions_confirmed: ChannelManager_Confirm_transactions_confirmed,
1785 transaction_unconfirmed: ChannelManager_Confirm_transaction_unconfirmed,
1786 best_block_updated: ChannelManager_Confirm_best_block_updated,
1787 get_relevant_txids: ChannelManager_Confirm_get_relevant_txids,
1791 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) {
1792 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 }); };
1793 <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)
1795 extern "C" fn ChannelManager_Confirm_best_block_updated(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
1796 <nativeChannelManager as lightning::chain::Confirm<>>::best_block_updated(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
1799 extern "C" fn ChannelManager_Confirm_get_relevant_txids(this_arg: *const c_void) -> crate::c_types::derived::CVec_TxidZ {
1800 let mut ret = <nativeChannelManager as lightning::chain::Confirm<>>::get_relevant_txids(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
1801 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::ThirtyTwoBytes { data: item.into_inner() } }); };
1804 extern "C" fn ChannelManager_Confirm_transaction_unconfirmed(this_arg: *const c_void, txid: *const [u8; 32]) {
1805 <nativeChannelManager as lightning::chain::Confirm<>>::transaction_unconfirmed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap())
1808 /// Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
1809 /// indicating whether persistence is necessary. Only one listener on
1810 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
1813 /// Note that this method is not available with the `no-std` feature.
1816 pub extern "C" fn ChannelManager_await_persistable_update_timeout(this_arg: &ChannelManager, mut max_wait: u64) -> bool {
1817 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.await_persistable_update_timeout(std::time::Duration::from_secs(max_wait));
1821 /// Blocks until ChannelManager needs to be persisted. Only one listener on
1822 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
1825 pub extern "C" fn ChannelManager_await_persistable_update(this_arg: &ChannelManager) {
1826 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.await_persistable_update()
1829 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
1830 /// [`chain::Confirm`] interfaces.
1833 pub extern "C" fn ChannelManager_current_best_block(this_arg: &ChannelManager) -> crate::lightning::chain::BestBlock {
1834 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
1835 crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
1838 impl From<nativeChannelManager> for crate::lightning::ln::msgs::ChannelMessageHandler {
1839 fn from(obj: nativeChannelManager) -> Self {
1840 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1841 let mut ret = ChannelManager_as_ChannelMessageHandler(&rust_obj);
1842 // 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
1843 rust_obj.inner = std::ptr::null_mut();
1844 ret.free = Some(ChannelManager_free_void);
1848 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
1849 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
1851 pub extern "C" fn ChannelManager_as_ChannelMessageHandler(this_arg: &ChannelManager) -> crate::lightning::ln::msgs::ChannelMessageHandler {
1852 crate::lightning::ln::msgs::ChannelMessageHandler {
1853 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1855 handle_open_channel: ChannelManager_ChannelMessageHandler_handle_open_channel,
1856 handle_accept_channel: ChannelManager_ChannelMessageHandler_handle_accept_channel,
1857 handle_funding_created: ChannelManager_ChannelMessageHandler_handle_funding_created,
1858 handle_funding_signed: ChannelManager_ChannelMessageHandler_handle_funding_signed,
1859 handle_funding_locked: ChannelManager_ChannelMessageHandler_handle_funding_locked,
1860 handle_shutdown: ChannelManager_ChannelMessageHandler_handle_shutdown,
1861 handle_closing_signed: ChannelManager_ChannelMessageHandler_handle_closing_signed,
1862 handle_update_add_htlc: ChannelManager_ChannelMessageHandler_handle_update_add_htlc,
1863 handle_update_fulfill_htlc: ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc,
1864 handle_update_fail_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_htlc,
1865 handle_update_fail_malformed_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_malformed_htlc,
1866 handle_commitment_signed: ChannelManager_ChannelMessageHandler_handle_commitment_signed,
1867 handle_revoke_and_ack: ChannelManager_ChannelMessageHandler_handle_revoke_and_ack,
1868 handle_update_fee: ChannelManager_ChannelMessageHandler_handle_update_fee,
1869 handle_announcement_signatures: ChannelManager_ChannelMessageHandler_handle_announcement_signatures,
1870 peer_disconnected: ChannelManager_ChannelMessageHandler_peer_disconnected,
1871 peer_connected: ChannelManager_ChannelMessageHandler_peer_connected,
1872 handle_channel_reestablish: ChannelManager_ChannelMessageHandler_handle_channel_reestablish,
1873 handle_channel_update: ChannelManager_ChannelMessageHandler_handle_channel_update,
1874 handle_error: ChannelManager_ChannelMessageHandler_handle_error,
1875 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
1876 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1878 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
1883 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) {
1884 <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())
1886 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) {
1887 <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())
1889 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) {
1890 <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())
1892 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) {
1893 <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())
1895 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) {
1896 <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())
1898 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) {
1899 <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())
1901 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) {
1902 <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())
1904 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) {
1905 <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())
1907 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) {
1908 <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())
1910 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) {
1911 <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())
1913 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) {
1914 <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())
1916 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) {
1917 <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())
1919 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) {
1920 <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())
1922 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) {
1923 <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())
1925 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) {
1926 <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())
1928 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) {
1929 <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())
1931 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) {
1932 <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())
1934 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) {
1935 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), no_connection_possible)
1937 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) {
1938 <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())
1940 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) {
1941 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
1945 /// Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
1946 pub extern "C" fn ChannelManager_write(obj: &ChannelManager) -> crate::c_types::derived::CVec_u8Z {
1947 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1950 pub(crate) extern "C" fn ChannelManager_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1951 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelManager) })
1954 use lightning::ln::channelmanager::ChannelManagerReadArgs as nativeChannelManagerReadArgsImport;
1955 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>;
1957 /// Arguments for the creation of a ChannelManager that are not deserialized.
1959 /// At a high-level, the process for deserializing a ChannelManager and resuming normal operation
1961 /// 1) Deserialize all stored [`ChannelMonitor`]s.
1962 /// 2) Deserialize the [`ChannelManager`] by filling in this struct and calling:
1963 /// `<(BlockHash, ChannelManager)>::read(reader, args)`
1964 /// This may result in closing some channels if the [`ChannelMonitor`] is newer than the stored
1965 /// [`ChannelManager`] state to ensure no loss of funds. Thus, transactions may be broadcasted.
1966 /// 3) If you are not fetching full blocks, register all relevant [`ChannelMonitor`] outpoints the
1967 /// same way you would handle a [`chain::Filter`] call using
1968 /// [`ChannelMonitor::get_outputs_to_watch`] and [`ChannelMonitor::get_funding_txo`].
1969 /// 4) Reconnect blocks on your [`ChannelMonitor`]s.
1970 /// 5) Disconnect/connect blocks on the [`ChannelManager`].
1971 /// 6) Re-persist the [`ChannelMonitor`]s to ensure the latest state is on disk.
1972 /// Note that if you're using a [`ChainMonitor`] for your [`chain::Watch`] implementation, you
1973 /// will likely accomplish this as a side-effect of calling [`chain::Watch::watch_channel`] in
1975 /// 7) Move the [`ChannelMonitor`]s into your local [`chain::Watch`]. If you're using a
1976 /// [`ChainMonitor`], this is done by calling [`chain::Watch::watch_channel`].
1978 /// Note that the ordering of #4-7 is not of importance, however all four must occur before you
1979 /// call any other methods on the newly-deserialized [`ChannelManager`].
1981 /// Note that because some channels may be closed during deserialization, it is critical that you
1982 /// always deserialize only the latest version of a ChannelManager and ChannelMonitors available to
1983 /// you. If you deserialize an old ChannelManager (during which force-closure transactions may be
1984 /// broadcast), and then later deserialize a newer version of the same ChannelManager (which will
1985 /// not force-close the same channels but consider them live), you may end up revoking a state for
1986 /// which you've already broadcasted the transaction.
1988 /// [`ChainMonitor`]: crate::chain::chainmonitor::ChainMonitor
1991 pub struct ChannelManagerReadArgs {
1992 /// A pointer to the opaque Rust object.
1994 /// Nearly everywhere, inner must be non-null, however in places where
1995 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1996 pub inner: *mut nativeChannelManagerReadArgs,
1997 /// Indicates that this is the only struct which contains the same pointer.
1999 /// Rust functions which take ownership of an object provided via an argument require
2000 /// this to be true and invalidate the object pointed to by inner.
2004 impl Drop for ChannelManagerReadArgs {
2005 fn drop(&mut self) {
2006 if self.is_owned && !<*mut nativeChannelManagerReadArgs>::is_null(self.inner) {
2007 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2011 /// Frees any resources used by the ChannelManagerReadArgs, if is_owned is set and inner is non-NULL.
2013 pub extern "C" fn ChannelManagerReadArgs_free(this_obj: ChannelManagerReadArgs) { }
2015 /// Used only if an object of this type is returned as a trait impl by a method
2016 pub(crate) extern "C" fn ChannelManagerReadArgs_free_void(this_ptr: *mut c_void) {
2017 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManagerReadArgs); }
2020 impl ChannelManagerReadArgs {
2021 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManagerReadArgs {
2022 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2024 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManagerReadArgs {
2025 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2027 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2028 pub(crate) fn take_inner(mut self) -> *mut nativeChannelManagerReadArgs {
2029 assert!(self.is_owned);
2030 let ret = ObjOps::untweak_ptr(self.inner);
2031 self.inner = std::ptr::null_mut();
2035 /// The keys provider which will give us relevant keys. Some keys will be loaded during
2036 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
2039 pub extern "C" fn ChannelManagerReadArgs_get_keys_manager(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::keysinterface::KeysInterface {
2040 let mut inner_val = &mut this_ptr.get_native_mut_ref().keys_manager;
2043 /// The keys provider which will give us relevant keys. Some keys will be loaded during
2044 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
2047 pub extern "C" fn ChannelManagerReadArgs_set_keys_manager(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::keysinterface::KeysInterface) {
2048 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.keys_manager = val;
2050 /// The fee_estimator for use in the ChannelManager in the future.
2052 /// No calls to the FeeEstimator will be made during deserialization.
2054 pub extern "C" fn ChannelManagerReadArgs_get_fee_estimator(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::FeeEstimator {
2055 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_estimator;
2058 /// The fee_estimator for use in the ChannelManager in the future.
2060 /// No calls to the FeeEstimator will be made during deserialization.
2062 pub extern "C" fn ChannelManagerReadArgs_set_fee_estimator(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::FeeEstimator) {
2063 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_estimator = val;
2065 /// The chain::Watch for use in the ChannelManager in the future.
2067 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
2068 /// you have deserialized ChannelMonitors separately and will add them to your
2069 /// chain::Watch after deserializing this ChannelManager.
2071 pub extern "C" fn ChannelManagerReadArgs_get_chain_monitor(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::Watch {
2072 let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_monitor;
2075 /// The chain::Watch for use in the ChannelManager in the future.
2077 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
2078 /// you have deserialized ChannelMonitors separately and will add them to your
2079 /// chain::Watch after deserializing this ChannelManager.
2081 pub extern "C" fn ChannelManagerReadArgs_set_chain_monitor(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::Watch) {
2082 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_monitor = val;
2084 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
2085 /// used to broadcast the latest local commitment transactions of channels which must be
2086 /// force-closed during deserialization.
2088 pub extern "C" fn ChannelManagerReadArgs_get_tx_broadcaster(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::BroadcasterInterface {
2089 let mut inner_val = &mut this_ptr.get_native_mut_ref().tx_broadcaster;
2092 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
2093 /// used to broadcast the latest local commitment transactions of channels which must be
2094 /// force-closed during deserialization.
2096 pub extern "C" fn ChannelManagerReadArgs_set_tx_broadcaster(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::BroadcasterInterface) {
2097 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.tx_broadcaster = val;
2099 /// The Logger for use in the ChannelManager and which may be used to log information during
2100 /// deserialization.
2102 pub extern "C" fn ChannelManagerReadArgs_get_logger(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::util::logger::Logger {
2103 let mut inner_val = &mut this_ptr.get_native_mut_ref().logger;
2106 /// The Logger for use in the ChannelManager and which may be used to log information during
2107 /// deserialization.
2109 pub extern "C" fn ChannelManagerReadArgs_set_logger(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::logger::Logger) {
2110 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.logger = val;
2112 /// Default settings used for new channels. Any existing channels will continue to use the
2113 /// runtime settings which were stored when the ChannelManager was serialized.
2115 pub extern "C" fn ChannelManagerReadArgs_get_default_config(this_ptr: &ChannelManagerReadArgs) -> crate::lightning::util::config::UserConfig {
2116 let mut inner_val = &mut this_ptr.get_native_mut_ref().default_config;
2117 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 }
2119 /// Default settings used for new channels. Any existing channels will continue to use the
2120 /// runtime settings which were stored when the ChannelManager was serialized.
2122 pub extern "C" fn ChannelManagerReadArgs_set_default_config(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::config::UserConfig) {
2123 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.default_config = *unsafe { Box::from_raw(val.take_inner()) };
2125 /// Simple utility function to create a ChannelManagerReadArgs which creates the monitor
2126 /// HashMap for you. This is primarily useful for C bindings where it is not practical to
2127 /// populate a HashMap directly from C.
2130 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 {
2131 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() }); };
2132 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);
2133 ChannelManagerReadArgs { inner: ObjOps::heap_alloc(ret), is_owned: true }
2137 /// Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_write
2138 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 {
2139 let arg_conv = *unsafe { Box::from_raw(arg.take_inner()) };
2140 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);
2141 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() };