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::*;
27 use lightning::ln::channelmanager::ChannelManager as nativeChannelManagerImport;
28 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>;
30 /// Manager which keeps track of a number of channels and sends messages to the appropriate
31 /// channel, also tracking HTLC preimages and forwarding onion packets appropriately.
33 /// Implements ChannelMessageHandler, handling the multi-channel parts and passing things through
34 /// to individual Channels.
36 /// Implements Writeable to write out all channel state to disk. Implies peer_disconnected() for
37 /// all peers during write/read (though does not modify this instance, only the instance being
38 /// serialized). This will result in any channels which have not yet exchanged funding_created (ie
39 /// called funding_transaction_generated for outbound channels).
41 /// Note that you can be a bit lazier about writing out ChannelManager than you can be with
42 /// ChannelMonitors. With ChannelMonitors you MUST write each monitor update out to disk before
43 /// returning from chain::Watch::watch_/update_channel, with ChannelManagers, writing updates
44 /// happens out-of-band (and will prevent any other ChannelManager operations from occurring during
45 /// the serialization process). If the deserialized version is out-of-date compared to the
46 /// ChannelMonitors passed by reference to read(), those channels will be force-closed based on the
47 /// ChannelMonitor state and no funds will be lost (mod on-chain transaction fees).
49 /// Note that the deserializer is only implemented for (BlockHash, ChannelManager), which
50 /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
51 /// the \"reorg path\" (ie call block_disconnected() until you get to a common block and then call
52 /// block_connected() to step towards your best block) upon deserialization before using the
55 /// Note that ChannelManager is responsible for tracking liveness of its channels and generating
56 /// ChannelUpdate messages informing peers that the channel is temporarily disabled. To avoid
57 /// spam due to quick disconnection/reconnection, updates are not sent until the channel has been
58 /// offline for a full minute. In order to track this, you must call
59 /// timer_tick_occurred roughly once per minute, though it doesn't have to be perfect.
61 /// Rather than using a plain ChannelManager, it is preferable to use either a SimpleArcChannelManager
62 /// a SimpleRefChannelManager, for conciseness. See their documentation for more details, but
63 /// essentially you should default to using a SimpleRefChannelManager, and use a
64 /// SimpleArcChannelManager when you require a ChannelManager with a static lifetime, such as when
65 /// you're using lightning-net-tokio.
68 pub struct ChannelManager {
69 /// A pointer to the opaque Rust object.
71 /// Nearly everywhere, inner must be non-null, however in places where
72 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
73 pub inner: *mut nativeChannelManager,
74 /// Indicates that this is the only struct which contains the same pointer.
76 /// Rust functions which take ownership of an object provided via an argument require
77 /// this to be true and invalidate the object pointed to by inner.
81 impl Drop for ChannelManager {
83 if self.is_owned && !<*mut nativeChannelManager>::is_null(self.inner) {
84 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
88 /// Frees any resources used by the ChannelManager, if is_owned is set and inner is non-NULL.
90 pub extern "C" fn ChannelManager_free(this_obj: ChannelManager) { }
92 /// Used only if an object of this type is returned as a trait impl by a method
93 pub(crate) extern "C" fn ChannelManager_free_void(this_ptr: *mut c_void) {
94 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManager); }
98 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManager {
99 unsafe { &*ObjOps::untweak_ptr(self.inner) }
101 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManager {
102 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
104 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
105 pub(crate) fn take_inner(mut self) -> *mut nativeChannelManager {
106 assert!(self.is_owned);
107 let ret = ObjOps::untweak_ptr(self.inner);
108 self.inner = std::ptr::null_mut();
113 use lightning::ln::channelmanager::ChainParameters as nativeChainParametersImport;
114 pub(crate) type nativeChainParameters = nativeChainParametersImport;
116 /// Chain-related parameters used to construct a new `ChannelManager`.
118 /// Typically, the block-specific parameters are derived from the best block hash for the network,
119 /// as a newly constructed `ChannelManager` will not have created any channels yet. These parameters
120 /// are not needed when deserializing a previously constructed `ChannelManager`.
123 pub struct ChainParameters {
124 /// A pointer to the opaque Rust object.
126 /// Nearly everywhere, inner must be non-null, however in places where
127 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
128 pub inner: *mut nativeChainParameters,
129 /// Indicates that this is the only struct which contains the same pointer.
131 /// Rust functions which take ownership of an object provided via an argument require
132 /// this to be true and invalidate the object pointed to by inner.
136 impl Drop for ChainParameters {
138 if self.is_owned && !<*mut nativeChainParameters>::is_null(self.inner) {
139 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
143 /// Frees any resources used by the ChainParameters, if is_owned is set and inner is non-NULL.
145 pub extern "C" fn ChainParameters_free(this_obj: ChainParameters) { }
147 /// Used only if an object of this type is returned as a trait impl by a method
148 pub(crate) extern "C" fn ChainParameters_free_void(this_ptr: *mut c_void) {
149 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChainParameters); }
152 impl ChainParameters {
153 pub(crate) fn get_native_ref(&self) -> &'static nativeChainParameters {
154 unsafe { &*ObjOps::untweak_ptr(self.inner) }
156 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChainParameters {
157 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
159 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
160 pub(crate) fn take_inner(mut self) -> *mut nativeChainParameters {
161 assert!(self.is_owned);
162 let ret = ObjOps::untweak_ptr(self.inner);
163 self.inner = std::ptr::null_mut();
167 /// The network for determining the `chain_hash` in Lightning messages.
169 pub extern "C" fn ChainParameters_get_network(this_ptr: &ChainParameters) -> crate::bitcoin::network::Network {
170 let mut inner_val = &mut this_ptr.get_native_mut_ref().network;
171 crate::bitcoin::network::Network::from_bitcoin(inner_val)
173 /// The network for determining the `chain_hash` in Lightning messages.
175 pub extern "C" fn ChainParameters_set_network(this_ptr: &mut ChainParameters, mut val: crate::bitcoin::network::Network) {
176 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.network = val.into_bitcoin();
178 /// The hash and height of the latest block successfully connected.
180 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
182 pub extern "C" fn ChainParameters_get_best_block(this_ptr: &ChainParameters) -> crate::lightning::chain::BestBlock {
183 let mut inner_val = &mut this_ptr.get_native_mut_ref().best_block;
184 crate::lightning::chain::BestBlock { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::chain::BestBlock<>) as *mut _) }, is_owned: false }
186 /// The hash and height of the latest block successfully connected.
188 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
190 pub extern "C" fn ChainParameters_set_best_block(this_ptr: &mut ChainParameters, mut val: crate::lightning::chain::BestBlock) {
191 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.best_block = *unsafe { Box::from_raw(val.take_inner()) };
193 /// Constructs a new ChainParameters given each field
196 pub extern "C" fn ChainParameters_new(mut network_arg: crate::bitcoin::network::Network, mut best_block_arg: crate::lightning::chain::BestBlock) -> ChainParameters {
197 ChainParameters { inner: ObjOps::heap_alloc(nativeChainParameters {
198 network: network_arg.into_bitcoin(),
199 best_block: *unsafe { Box::from_raw(best_block_arg.take_inner()) },
202 impl Clone for ChainParameters {
203 fn clone(&self) -> Self {
205 inner: if <*mut nativeChainParameters>::is_null(self.inner) { std::ptr::null_mut() } else {
206 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
212 /// Used only if an object of this type is returned as a trait impl by a method
213 pub(crate) extern "C" fn ChainParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
214 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChainParameters)).clone() })) as *mut c_void
217 /// Creates a copy of the ChainParameters
218 pub extern "C" fn ChainParameters_clone(orig: &ChainParameters) -> ChainParameters {
221 /// The amount of time in blocks we require our counterparty wait to claim their money (ie time
222 /// between when we, or our watchtower, must check for them having broadcast a theft transaction).
224 /// This can be increased (but not decreased) through [`ChannelHandshakeConfig::our_to_self_delay`]
226 /// [`ChannelHandshakeConfig::our_to_self_delay`]: crate::util::config::ChannelHandshakeConfig::our_to_self_delay
229 pub static BREAKDOWN_TIMEOUT: u16 = lightning::ln::channelmanager::BREAKDOWN_TIMEOUT;
230 /// The minimum number of blocks between an inbound HTLC's CLTV and the corresponding outbound
231 /// HTLC's CLTV. The current default represents roughly seven hours of blocks at six blocks/hour.
233 /// This can be increased (but not decreased) through [`ChannelConfig::cltv_expiry_delta`]
235 /// [`ChannelConfig::cltv_expiry_delta`]: crate::util::config::ChannelConfig::cltv_expiry_delta
238 pub static MIN_CLTV_EXPIRY_DELTA: u16 = lightning::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA;
239 /// Minimum CLTV difference between the current block height and received inbound payments.
240 /// Invoices generated for payment to us must set their `min_final_cltv_expiry` field to at least
244 pub static MIN_FINAL_CLTV_EXPIRY: u32 = lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY;
246 use lightning::ln::channelmanager::CounterpartyForwardingInfo as nativeCounterpartyForwardingInfoImport;
247 pub(crate) type nativeCounterpartyForwardingInfo = nativeCounterpartyForwardingInfoImport;
249 /// Information needed for constructing an invoice route hint for this channel.
252 pub struct CounterpartyForwardingInfo {
253 /// A pointer to the opaque Rust object.
255 /// Nearly everywhere, inner must be non-null, however in places where
256 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
257 pub inner: *mut nativeCounterpartyForwardingInfo,
258 /// Indicates that this is the only struct which contains the same pointer.
260 /// Rust functions which take ownership of an object provided via an argument require
261 /// this to be true and invalidate the object pointed to by inner.
265 impl Drop for CounterpartyForwardingInfo {
267 if self.is_owned && !<*mut nativeCounterpartyForwardingInfo>::is_null(self.inner) {
268 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
272 /// Frees any resources used by the CounterpartyForwardingInfo, if is_owned is set and inner is non-NULL.
274 pub extern "C" fn CounterpartyForwardingInfo_free(this_obj: CounterpartyForwardingInfo) { }
276 /// Used only if an object of this type is returned as a trait impl by a method
277 pub(crate) extern "C" fn CounterpartyForwardingInfo_free_void(this_ptr: *mut c_void) {
278 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCounterpartyForwardingInfo); }
281 impl CounterpartyForwardingInfo {
282 pub(crate) fn get_native_ref(&self) -> &'static nativeCounterpartyForwardingInfo {
283 unsafe { &*ObjOps::untweak_ptr(self.inner) }
285 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCounterpartyForwardingInfo {
286 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
288 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
289 pub(crate) fn take_inner(mut self) -> *mut nativeCounterpartyForwardingInfo {
290 assert!(self.is_owned);
291 let ret = ObjOps::untweak_ptr(self.inner);
292 self.inner = std::ptr::null_mut();
296 /// Base routing fee in millisatoshis.
298 pub extern "C" fn CounterpartyForwardingInfo_get_fee_base_msat(this_ptr: &CounterpartyForwardingInfo) -> u32 {
299 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_base_msat;
302 /// Base routing fee in millisatoshis.
304 pub extern "C" fn CounterpartyForwardingInfo_set_fee_base_msat(this_ptr: &mut CounterpartyForwardingInfo, mut val: u32) {
305 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_base_msat = val;
307 /// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
309 pub extern "C" fn CounterpartyForwardingInfo_get_fee_proportional_millionths(this_ptr: &CounterpartyForwardingInfo) -> u32 {
310 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_proportional_millionths;
313 /// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
315 pub extern "C" fn CounterpartyForwardingInfo_set_fee_proportional_millionths(this_ptr: &mut CounterpartyForwardingInfo, mut val: u32) {
316 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_proportional_millionths = val;
318 /// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
319 /// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
320 /// `cltv_expiry_delta` for more details.
322 pub extern "C" fn CounterpartyForwardingInfo_get_cltv_expiry_delta(this_ptr: &CounterpartyForwardingInfo) -> u16 {
323 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
326 /// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
327 /// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
328 /// `cltv_expiry_delta` for more details.
330 pub extern "C" fn CounterpartyForwardingInfo_set_cltv_expiry_delta(this_ptr: &mut CounterpartyForwardingInfo, mut val: u16) {
331 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
333 /// Constructs a new CounterpartyForwardingInfo given each field
336 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 {
337 CounterpartyForwardingInfo { inner: ObjOps::heap_alloc(nativeCounterpartyForwardingInfo {
338 fee_base_msat: fee_base_msat_arg,
339 fee_proportional_millionths: fee_proportional_millionths_arg,
340 cltv_expiry_delta: cltv_expiry_delta_arg,
343 impl Clone for CounterpartyForwardingInfo {
344 fn clone(&self) -> Self {
346 inner: if <*mut nativeCounterpartyForwardingInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
347 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
353 /// Used only if an object of this type is returned as a trait impl by a method
354 pub(crate) extern "C" fn CounterpartyForwardingInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
355 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCounterpartyForwardingInfo)).clone() })) as *mut c_void
358 /// Creates a copy of the CounterpartyForwardingInfo
359 pub extern "C" fn CounterpartyForwardingInfo_clone(orig: &CounterpartyForwardingInfo) -> CounterpartyForwardingInfo {
363 use lightning::ln::channelmanager::ChannelCounterparty as nativeChannelCounterpartyImport;
364 pub(crate) type nativeChannelCounterparty = nativeChannelCounterpartyImport;
366 /// Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
367 /// to better separate parameters.
370 pub struct ChannelCounterparty {
371 /// A pointer to the opaque Rust object.
373 /// Nearly everywhere, inner must be non-null, however in places where
374 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
375 pub inner: *mut nativeChannelCounterparty,
376 /// Indicates that this is the only struct which contains the same pointer.
378 /// Rust functions which take ownership of an object provided via an argument require
379 /// this to be true and invalidate the object pointed to by inner.
383 impl Drop for ChannelCounterparty {
385 if self.is_owned && !<*mut nativeChannelCounterparty>::is_null(self.inner) {
386 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
390 /// Frees any resources used by the ChannelCounterparty, if is_owned is set and inner is non-NULL.
392 pub extern "C" fn ChannelCounterparty_free(this_obj: ChannelCounterparty) { }
394 /// Used only if an object of this type is returned as a trait impl by a method
395 pub(crate) extern "C" fn ChannelCounterparty_free_void(this_ptr: *mut c_void) {
396 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelCounterparty); }
399 impl ChannelCounterparty {
400 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelCounterparty {
401 unsafe { &*ObjOps::untweak_ptr(self.inner) }
403 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelCounterparty {
404 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
406 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
407 pub(crate) fn take_inner(mut self) -> *mut nativeChannelCounterparty {
408 assert!(self.is_owned);
409 let ret = ObjOps::untweak_ptr(self.inner);
410 self.inner = std::ptr::null_mut();
414 /// The node_id of our counterparty
416 pub extern "C" fn ChannelCounterparty_get_node_id(this_ptr: &ChannelCounterparty) -> crate::c_types::PublicKey {
417 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_id;
418 crate::c_types::PublicKey::from_rust(&inner_val)
420 /// The node_id of our counterparty
422 pub extern "C" fn ChannelCounterparty_set_node_id(this_ptr: &mut ChannelCounterparty, mut val: crate::c_types::PublicKey) {
423 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_id = val.into_rust();
425 /// The Features the channel counterparty provided upon last connection.
426 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
427 /// many routing-relevant features are present in the init context.
429 pub extern "C" fn ChannelCounterparty_get_features(this_ptr: &ChannelCounterparty) -> crate::lightning::ln::features::InitFeatures {
430 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
431 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 }
433 /// The Features the channel counterparty provided upon last connection.
434 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
435 /// many routing-relevant features are present in the init context.
437 pub extern "C" fn ChannelCounterparty_set_features(this_ptr: &mut ChannelCounterparty, mut val: crate::lightning::ln::features::InitFeatures) {
438 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
440 /// The value, in satoshis, that must always be held in the channel for our counterparty. This
441 /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
442 /// claiming at least this value on chain.
444 /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
446 /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
448 pub extern "C" fn ChannelCounterparty_get_unspendable_punishment_reserve(this_ptr: &ChannelCounterparty) -> u64 {
449 let mut inner_val = &mut this_ptr.get_native_mut_ref().unspendable_punishment_reserve;
452 /// The value, in satoshis, that must always be held in the channel for our counterparty. This
453 /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
454 /// claiming at least this value on chain.
456 /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
458 /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
460 pub extern "C" fn ChannelCounterparty_set_unspendable_punishment_reserve(this_ptr: &mut ChannelCounterparty, mut val: u64) {
461 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = val;
463 /// Information on the fees and requirements that the counterparty requires when forwarding
464 /// payments to us through this channel.
466 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
468 pub extern "C" fn ChannelCounterparty_get_forwarding_info(this_ptr: &ChannelCounterparty) -> crate::lightning::ln::channelmanager::CounterpartyForwardingInfo {
469 let mut inner_val = &mut this_ptr.get_native_mut_ref().forwarding_info;
470 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 };
473 /// Information on the fees and requirements that the counterparty requires when forwarding
474 /// payments to us through this channel.
476 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
478 pub extern "C" fn ChannelCounterparty_set_forwarding_info(this_ptr: &mut ChannelCounterparty, mut val: crate::lightning::ln::channelmanager::CounterpartyForwardingInfo) {
479 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
480 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.forwarding_info = local_val;
482 /// Constructs a new ChannelCounterparty given each field
485 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 {
486 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()) } }) };
487 ChannelCounterparty { inner: ObjOps::heap_alloc(nativeChannelCounterparty {
488 node_id: node_id_arg.into_rust(),
489 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
490 unspendable_punishment_reserve: unspendable_punishment_reserve_arg,
491 forwarding_info: local_forwarding_info_arg,
494 impl Clone for ChannelCounterparty {
495 fn clone(&self) -> Self {
497 inner: if <*mut nativeChannelCounterparty>::is_null(self.inner) { std::ptr::null_mut() } else {
498 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
504 /// Used only if an object of this type is returned as a trait impl by a method
505 pub(crate) extern "C" fn ChannelCounterparty_clone_void(this_ptr: *const c_void) -> *mut c_void {
506 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelCounterparty)).clone() })) as *mut c_void
509 /// Creates a copy of the ChannelCounterparty
510 pub extern "C" fn ChannelCounterparty_clone(orig: &ChannelCounterparty) -> ChannelCounterparty {
514 use lightning::ln::channelmanager::ChannelDetails as nativeChannelDetailsImport;
515 pub(crate) type nativeChannelDetails = nativeChannelDetailsImport;
517 /// Details of a channel, as returned by ChannelManager::list_channels and ChannelManager::list_usable_channels
520 pub struct ChannelDetails {
521 /// A pointer to the opaque Rust object.
523 /// Nearly everywhere, inner must be non-null, however in places where
524 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
525 pub inner: *mut nativeChannelDetails,
526 /// Indicates that this is the only struct which contains the same pointer.
528 /// Rust functions which take ownership of an object provided via an argument require
529 /// this to be true and invalidate the object pointed to by inner.
533 impl Drop for ChannelDetails {
535 if self.is_owned && !<*mut nativeChannelDetails>::is_null(self.inner) {
536 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
540 /// Frees any resources used by the ChannelDetails, if is_owned is set and inner is non-NULL.
542 pub extern "C" fn ChannelDetails_free(this_obj: ChannelDetails) { }
544 /// Used only if an object of this type is returned as a trait impl by a method
545 pub(crate) extern "C" fn ChannelDetails_free_void(this_ptr: *mut c_void) {
546 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelDetails); }
549 impl ChannelDetails {
550 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelDetails {
551 unsafe { &*ObjOps::untweak_ptr(self.inner) }
553 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelDetails {
554 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
556 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
557 pub(crate) fn take_inner(mut self) -> *mut nativeChannelDetails {
558 assert!(self.is_owned);
559 let ret = ObjOps::untweak_ptr(self.inner);
560 self.inner = std::ptr::null_mut();
564 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
565 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
566 /// Note that this means this value is *not* persistent - it can change once during the
567 /// lifetime of the channel.
569 pub extern "C" fn ChannelDetails_get_channel_id(this_ptr: &ChannelDetails) -> *const [u8; 32] {
570 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id;
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_set_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::ThirtyTwoBytes) {
579 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = val.data;
581 /// Parameters which apply to our counterparty. See individual fields for more information.
583 pub extern "C" fn ChannelDetails_get_counterparty(this_ptr: &ChannelDetails) -> crate::lightning::ln::channelmanager::ChannelCounterparty {
584 let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty;
585 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 }
587 /// Parameters which apply to our counterparty. See individual fields for more information.
589 pub extern "C" fn ChannelDetails_set_counterparty(this_ptr: &mut ChannelDetails, mut val: crate::lightning::ln::channelmanager::ChannelCounterparty) {
590 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty = *unsafe { Box::from_raw(val.take_inner()) };
592 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
593 /// our counterparty already.
595 /// Note that, if this has been set, `channel_id` will be equivalent to
596 /// `funding_txo.unwrap().to_channel_id()`.
598 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
600 pub extern "C" fn ChannelDetails_get_funding_txo(this_ptr: &ChannelDetails) -> crate::lightning::chain::transaction::OutPoint {
601 let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_txo;
602 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 };
605 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
606 /// our counterparty already.
608 /// Note that, if this has been set, `channel_id` will be equivalent to
609 /// `funding_txo.unwrap().to_channel_id()`.
611 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
613 pub extern "C" fn ChannelDetails_set_funding_txo(this_ptr: &mut ChannelDetails, mut val: crate::lightning::chain::transaction::OutPoint) {
614 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
615 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_txo = local_val;
617 /// The position of the funding transaction in the chain. None if the funding transaction has
618 /// not yet been confirmed and the channel fully opened.
620 pub extern "C" fn ChannelDetails_get_short_channel_id(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
621 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
622 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() }) };
625 /// The position of the funding transaction in the chain. None if the funding transaction has
626 /// not yet been confirmed and the channel fully opened.
628 pub extern "C" fn ChannelDetails_set_short_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
629 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
630 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = local_val;
632 /// The value, in satoshis, of this channel as appears in the funding output
634 pub extern "C" fn ChannelDetails_get_channel_value_satoshis(this_ptr: &ChannelDetails) -> u64 {
635 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
638 /// The value, in satoshis, of this channel as appears in the funding output
640 pub extern "C" fn ChannelDetails_set_channel_value_satoshis(this_ptr: &mut ChannelDetails, mut val: u64) {
641 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
643 /// The value, in satoshis, that must always be held in the channel for us. This value ensures
644 /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
645 /// this value on chain.
647 /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
649 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
651 /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
653 pub extern "C" fn ChannelDetails_get_unspendable_punishment_reserve(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
654 let mut inner_val = &mut this_ptr.get_native_mut_ref().unspendable_punishment_reserve;
655 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() }) };
658 /// The value, in satoshis, that must always be held in the channel for us. This value ensures
659 /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
660 /// this value on chain.
662 /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
664 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
666 /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
668 pub extern "C" fn ChannelDetails_set_unspendable_punishment_reserve(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
669 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
670 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = local_val;
672 /// The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound.
674 pub extern "C" fn ChannelDetails_get_user_channel_id(this_ptr: &ChannelDetails) -> u64 {
675 let mut inner_val = &mut this_ptr.get_native_mut_ref().user_channel_id;
678 /// The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound.
680 pub extern "C" fn ChannelDetails_set_user_channel_id(this_ptr: &mut ChannelDetails, mut val: u64) {
681 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.user_channel_id = val;
683 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
684 /// any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
685 /// available for inclusion in new outbound HTLCs). This further does not include any pending
686 /// outgoing HTLCs which are awaiting some other resolution to be sent.
688 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
689 /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
690 /// should be able to spend nearly this amount.
692 pub extern "C" fn ChannelDetails_get_outbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
693 let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_capacity_msat;
696 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
697 /// any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
698 /// available for inclusion in new outbound HTLCs). This further does not include any pending
699 /// outgoing HTLCs which are awaiting some other resolution to be sent.
701 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
702 /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
703 /// should be able to spend nearly this amount.
705 pub extern "C" fn ChannelDetails_set_outbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
706 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_capacity_msat = val;
708 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
709 /// include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
710 /// available for inclusion in new inbound HTLCs).
711 /// Note that there are some corner cases not fully handled here, so the actual available
712 /// inbound capacity may be slightly higher than this.
714 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
715 /// counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
716 /// However, our counterparty should be able to spend nearly this amount.
718 pub extern "C" fn ChannelDetails_get_inbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
719 let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_capacity_msat;
722 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
723 /// include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
724 /// available for inclusion in new inbound HTLCs).
725 /// Note that there are some corner cases not fully handled here, so the actual available
726 /// inbound capacity may be slightly higher than this.
728 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
729 /// counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
730 /// However, our counterparty should be able to spend nearly this amount.
732 pub extern "C" fn ChannelDetails_set_inbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
733 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_capacity_msat = val;
735 /// The number of required confirmations on the funding transaction before the funding will be
736 /// considered \"locked\". This number is selected by the channel fundee (i.e. us if
737 /// [`is_outbound`] is *not* set), and can be selected for inbound channels with
738 /// [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
739 /// [`ChannelHandshakeLimits::max_minimum_depth`].
741 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
743 /// [`is_outbound`]: ChannelDetails::is_outbound
744 /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
745 /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
747 pub extern "C" fn ChannelDetails_get_confirmations_required(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u32Z {
748 let mut inner_val = &mut this_ptr.get_native_mut_ref().confirmations_required;
749 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() }) };
752 /// The number of required confirmations on the funding transaction before the funding will be
753 /// considered \"locked\". This number is selected by the channel fundee (i.e. us if
754 /// [`is_outbound`] is *not* set), and can be selected for inbound channels with
755 /// [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
756 /// [`ChannelHandshakeLimits::max_minimum_depth`].
758 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
760 /// [`is_outbound`]: ChannelDetails::is_outbound
761 /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
762 /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
764 pub extern "C" fn ChannelDetails_set_confirmations_required(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u32Z) {
765 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
766 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.confirmations_required = local_val;
768 /// The number of blocks (after our commitment transaction confirms) that we will need to wait
769 /// until we can claim our funds after we force-close the channel. During this time our
770 /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
771 /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any
772 /// time to claim our non-HTLC-encumbered funds.
774 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
776 pub extern "C" fn ChannelDetails_get_force_close_spend_delay(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u16Z {
777 let mut inner_val = &mut this_ptr.get_native_mut_ref().force_close_spend_delay;
778 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() }) };
781 /// The number of blocks (after our commitment transaction confirms) that we will need to wait
782 /// until we can claim our funds after we force-close the channel. During this time our
783 /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
784 /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any
785 /// time to claim our non-HTLC-encumbered funds.
787 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
789 pub extern "C" fn ChannelDetails_set_force_close_spend_delay(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u16Z) {
790 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
791 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.force_close_spend_delay = local_val;
793 /// True if the channel was initiated (and thus funded) by us.
795 pub extern "C" fn ChannelDetails_get_is_outbound(this_ptr: &ChannelDetails) -> bool {
796 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_outbound;
799 /// True if the channel was initiated (and thus funded) by us.
801 pub extern "C" fn ChannelDetails_set_is_outbound(this_ptr: &mut ChannelDetails, mut val: bool) {
802 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_outbound = val;
804 /// True if the channel is confirmed, funding_locked messages have been exchanged, and the
805 /// channel is not currently being shut down. `funding_locked` message exchange implies the
806 /// required confirmation count has been reached (and we were connected to the peer at some
807 /// point after the funding transaction received enough confirmations). The required
808 /// confirmation count is provided in [`confirmations_required`].
810 /// [`confirmations_required`]: ChannelDetails::confirmations_required
812 pub extern "C" fn ChannelDetails_get_is_funding_locked(this_ptr: &ChannelDetails) -> bool {
813 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_funding_locked;
816 /// True if the channel is confirmed, funding_locked messages have been exchanged, and the
817 /// channel is not currently being shut down. `funding_locked` message exchange implies the
818 /// required confirmation count has been reached (and we were connected to the peer at some
819 /// point after the funding transaction received enough confirmations). The required
820 /// confirmation count is provided in [`confirmations_required`].
822 /// [`confirmations_required`]: ChannelDetails::confirmations_required
824 pub extern "C" fn ChannelDetails_set_is_funding_locked(this_ptr: &mut ChannelDetails, mut val: bool) {
825 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_funding_locked = val;
827 /// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
828 /// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
830 /// This is a strict superset of `is_funding_locked`.
832 pub extern "C" fn ChannelDetails_get_is_usable(this_ptr: &ChannelDetails) -> bool {
833 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_usable;
836 /// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
837 /// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
839 /// This is a strict superset of `is_funding_locked`.
841 pub extern "C" fn ChannelDetails_set_is_usable(this_ptr: &mut ChannelDetails, mut val: bool) {
842 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_usable = val;
844 /// True if this channel is (or will be) publicly-announced.
846 pub extern "C" fn ChannelDetails_get_is_public(this_ptr: &ChannelDetails) -> bool {
847 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_public;
850 /// True if this channel is (or will be) publicly-announced.
852 pub extern "C" fn ChannelDetails_set_is_public(this_ptr: &mut ChannelDetails, mut val: bool) {
853 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_public = val;
855 /// Constructs a new ChannelDetails given each field
858 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 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 {
859 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()) } }) };
860 let mut local_short_channel_id_arg = if short_channel_id_arg.is_some() { Some( { short_channel_id_arg.take() }) } else { None };
861 let mut local_unspendable_punishment_reserve_arg = if unspendable_punishment_reserve_arg.is_some() { Some( { unspendable_punishment_reserve_arg.take() }) } else { None };
862 let mut local_confirmations_required_arg = if confirmations_required_arg.is_some() { Some( { confirmations_required_arg.take() }) } else { None };
863 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 };
864 ChannelDetails { inner: ObjOps::heap_alloc(nativeChannelDetails {
865 channel_id: channel_id_arg.data,
866 counterparty: *unsafe { Box::from_raw(counterparty_arg.take_inner()) },
867 funding_txo: local_funding_txo_arg,
868 short_channel_id: local_short_channel_id_arg,
869 channel_value_satoshis: channel_value_satoshis_arg,
870 unspendable_punishment_reserve: local_unspendable_punishment_reserve_arg,
871 user_channel_id: user_channel_id_arg,
872 outbound_capacity_msat: outbound_capacity_msat_arg,
873 inbound_capacity_msat: inbound_capacity_msat_arg,
874 confirmations_required: local_confirmations_required_arg,
875 force_close_spend_delay: local_force_close_spend_delay_arg,
876 is_outbound: is_outbound_arg,
877 is_funding_locked: is_funding_locked_arg,
878 is_usable: is_usable_arg,
879 is_public: is_public_arg,
882 impl Clone for ChannelDetails {
883 fn clone(&self) -> Self {
885 inner: if <*mut nativeChannelDetails>::is_null(self.inner) { std::ptr::null_mut() } else {
886 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
892 /// Used only if an object of this type is returned as a trait impl by a method
893 pub(crate) extern "C" fn ChannelDetails_clone_void(this_ptr: *const c_void) -> *mut c_void {
894 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelDetails)).clone() })) as *mut c_void
897 /// Creates a copy of the ChannelDetails
898 pub extern "C" fn ChannelDetails_clone(orig: &ChannelDetails) -> ChannelDetails {
901 /// If a payment fails to send, it can be in one of several states. This enum is returned as the
902 /// Err() type describing which state the payment is in, see the description of individual enum
907 pub enum PaymentSendFailure {
908 /// A parameter which was passed to send_payment was invalid, preventing us from attempting to
909 /// send the payment at all. No channel state has been changed or messages sent to peers, and
910 /// once you've changed the parameter at error, you can freely retry the payment in full.
911 ParameterError(crate::lightning::util::errors::APIError),
912 /// A parameter in a single path which was passed to send_payment was invalid, preventing us
913 /// from attempting to send the payment at all. No channel state has been changed or messages
914 /// sent to peers, and once you've changed the parameter at error, you can freely retry the
917 /// The results here are ordered the same as the paths in the route object which was passed to
919 PathParameterError(crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ),
920 /// All paths which were attempted failed to send, with no channel state change taking place.
921 /// You can freely retry the payment in full (though you probably want to do so over different
922 /// paths than the ones selected).
923 AllFailedRetrySafe(crate::c_types::derived::CVec_APIErrorZ),
924 /// Some paths which were attempted failed to send, though possibly not all. At least some
925 /// paths have irrevocably committed to the HTLC and retrying the payment in full would result
926 /// in over-/re-payment.
928 /// The results here are ordered the same as the paths in the route object which was passed to
929 /// send_payment, and any Errs which are not APIError::MonitorUpdateFailed can be safely
930 /// retried (though there is currently no API with which to do so).
932 /// Any entries which contain Err(APIError::MonitorUpdateFailed) or Ok(()) MUST NOT be retried
933 /// as they will result in over-/re-payment. These HTLCs all either successfully sent (in the
934 /// case of Ok(())) or will send once channel_monitor_updated is called on the next-hop channel
935 /// with the latest update_id.
937 /// The errors themselves, in the same order as the route hops.
938 results: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ,
939 /// If some paths failed without irrevocably committing to the new HTLC(s), this will
940 /// contain a [`RouteParameters`] object which can be used to calculate a new route that
941 /// will pay all remaining unpaid balance.
943 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
944 failed_paths_retry: crate::lightning::routing::router::RouteParameters,
945 /// The payment id for the payment, which is now at least partially pending.
946 payment_id: crate::c_types::ThirtyTwoBytes,
949 use lightning::ln::channelmanager::PaymentSendFailure as nativePaymentSendFailure;
950 impl PaymentSendFailure {
952 pub(crate) fn to_native(&self) -> nativePaymentSendFailure {
954 PaymentSendFailure::ParameterError (ref a, ) => {
955 let mut a_nonref = (*a).clone();
956 nativePaymentSendFailure::ParameterError (
957 a_nonref.into_native(),
960 PaymentSendFailure::PathParameterError (ref a, ) => {
961 let mut a_nonref = (*a).clone();
962 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 }); };
963 nativePaymentSendFailure::PathParameterError (
967 PaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
968 let mut a_nonref = (*a).clone();
969 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { item.into_native() }); };
970 nativePaymentSendFailure::AllFailedRetrySafe (
974 PaymentSendFailure::PartialFailure {ref results, ref failed_paths_retry, ref payment_id, } => {
975 let mut results_nonref = (*results).clone();
976 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 }); };
977 let mut failed_paths_retry_nonref = (*failed_paths_retry).clone();
978 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()) } }) };
979 let mut payment_id_nonref = (*payment_id).clone();
980 nativePaymentSendFailure::PartialFailure {
981 results: local_results_nonref,
982 failed_paths_retry: local_failed_paths_retry_nonref,
983 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
989 pub(crate) fn into_native(self) -> nativePaymentSendFailure {
991 PaymentSendFailure::ParameterError (mut a, ) => {
992 nativePaymentSendFailure::ParameterError (
996 PaymentSendFailure::PathParameterError (mut a, ) => {
997 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 }); };
998 nativePaymentSendFailure::PathParameterError (
1002 PaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
1003 let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { item.into_native() }); };
1004 nativePaymentSendFailure::AllFailedRetrySafe (
1008 PaymentSendFailure::PartialFailure {mut results, mut failed_paths_retry, mut payment_id, } => {
1009 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 }); };
1010 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()) } }) };
1011 nativePaymentSendFailure::PartialFailure {
1012 results: local_results,
1013 failed_paths_retry: local_failed_paths_retry,
1014 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1020 pub(crate) fn from_native(native: &nativePaymentSendFailure) -> Self {
1022 nativePaymentSendFailure::ParameterError (ref a, ) => {
1023 let mut a_nonref = (*a).clone();
1024 PaymentSendFailure::ParameterError (
1025 crate::lightning::util::errors::APIError::native_into(a_nonref),
1028 nativePaymentSendFailure::PathParameterError (ref a, ) => {
1029 let mut a_nonref = (*a).clone();
1030 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 }); };
1031 PaymentSendFailure::PathParameterError (
1032 local_a_nonref.into(),
1035 nativePaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
1036 let mut a_nonref = (*a).clone();
1037 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) }); };
1038 PaymentSendFailure::AllFailedRetrySafe (
1039 local_a_nonref.into(),
1042 nativePaymentSendFailure::PartialFailure {ref results, ref failed_paths_retry, ref payment_id, } => {
1043 let mut results_nonref = (*results).clone();
1044 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 }); };
1045 let mut failed_paths_retry_nonref = (*failed_paths_retry).clone();
1046 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 };
1047 let mut payment_id_nonref = (*payment_id).clone();
1048 PaymentSendFailure::PartialFailure {
1049 results: local_results_nonref.into(),
1050 failed_paths_retry: local_failed_paths_retry_nonref,
1051 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1057 pub(crate) fn native_into(native: nativePaymentSendFailure) -> Self {
1059 nativePaymentSendFailure::ParameterError (mut a, ) => {
1060 PaymentSendFailure::ParameterError (
1061 crate::lightning::util::errors::APIError::native_into(a),
1064 nativePaymentSendFailure::PathParameterError (mut a, ) => {
1065 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 }); };
1066 PaymentSendFailure::PathParameterError (
1070 nativePaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
1071 let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { crate::lightning::util::errors::APIError::native_into(item) }); };
1072 PaymentSendFailure::AllFailedRetrySafe (
1076 nativePaymentSendFailure::PartialFailure {mut results, mut failed_paths_retry, mut payment_id, } => {
1077 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 }); };
1078 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 };
1079 PaymentSendFailure::PartialFailure {
1080 results: local_results.into(),
1081 failed_paths_retry: local_failed_paths_retry,
1082 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1088 /// Frees any resources used by the PaymentSendFailure
1090 pub extern "C" fn PaymentSendFailure_free(this_ptr: PaymentSendFailure) { }
1091 /// Creates a copy of the PaymentSendFailure
1093 pub extern "C" fn PaymentSendFailure_clone(orig: &PaymentSendFailure) -> PaymentSendFailure {
1097 /// Utility method to constructs a new ParameterError-variant PaymentSendFailure
1098 pub extern "C" fn PaymentSendFailure_parameter_error(a: crate::lightning::util::errors::APIError) -> PaymentSendFailure {
1099 PaymentSendFailure::ParameterError(a, )
1102 /// Utility method to constructs a new PathParameterError-variant PaymentSendFailure
1103 pub extern "C" fn PaymentSendFailure_path_parameter_error(a: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ) -> PaymentSendFailure {
1104 PaymentSendFailure::PathParameterError(a, )
1107 /// Utility method to constructs a new AllFailedRetrySafe-variant PaymentSendFailure
1108 pub extern "C" fn PaymentSendFailure_all_failed_retry_safe(a: crate::c_types::derived::CVec_APIErrorZ) -> PaymentSendFailure {
1109 PaymentSendFailure::AllFailedRetrySafe(a, )
1112 /// Utility method to constructs a new PartialFailure-variant PaymentSendFailure
1113 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 {
1114 PaymentSendFailure::PartialFailure {
1120 /// Constructs a new ChannelManager to hold several channels and route between them.
1122 /// This is the main \"logic hub\" for all channel-related actions, and implements
1123 /// ChannelMessageHandler.
1125 /// Non-proportional fees are fixed according to our risk using the provided fee estimator.
1127 /// panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`!
1129 /// Users need to notify the new ChannelManager when a new block is connected or
1130 /// disconnected using its `block_connected` and `block_disconnected` methods, starting
1131 /// from after `params.latest_hash`.
1134 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 {
1135 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()) });
1136 ChannelManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
1139 /// Gets the current configuration applied to all new channels, as
1142 pub extern "C" fn ChannelManager_get_current_default_configuration(this_arg: &ChannelManager) -> crate::lightning::util::config::UserConfig {
1143 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_current_default_configuration();
1144 crate::lightning::util::config::UserConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::util::config::UserConfig<>) as *mut _) }, is_owned: false }
1147 /// Creates a new outbound channel to the given remote node and with the given value.
1149 /// `user_channel_id` will be provided back as in
1150 /// [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
1151 /// correspond with which `create_channel` call. Note that the `user_channel_id` defaults to 0
1152 /// for inbound channels, so you may wish to avoid using 0 for `user_channel_id` here.
1153 /// `user_channel_id` has no meaning inside of LDK, it is simply copied to events and otherwise
1156 /// Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is
1157 /// greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`.
1159 /// Note that we do not check if you are currently connected to the given peer. If no
1160 /// connection is available, the outbound `open_channel` message may fail to send, resulting in
1161 /// the channel eventually being silently forgotten (dropped on reload).
1163 /// Returns the new Channel's temporary `channel_id`. This ID will appear as
1164 /// [`Event::FundingGenerationReady::temporary_channel_id`] and in
1165 /// [`ChannelDetails::channel_id`] until after
1166 /// [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
1167 /// one derived from the funding transaction's TXID. If the counterparty rejects the channel
1168 /// immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
1170 /// [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
1171 /// [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
1172 /// [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
1174 /// Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
1177 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 {
1178 let mut local_override_config = if override_config.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(override_config.take_inner()) } }) };
1179 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);
1180 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() };
1184 /// Gets the list of open channels, in random order. See ChannelDetail field documentation for
1185 /// more information.
1188 pub extern "C" fn ChannelManager_list_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1189 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_channels();
1190 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 } }); };
1194 /// Gets the list of usable channels, in random order. Useful as an argument to
1195 /// get_route to ensure non-announced channels are used.
1197 /// These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
1198 /// documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
1202 pub extern "C" fn ChannelManager_list_usable_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1203 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_usable_channels();
1204 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 } }); };
1208 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
1209 /// will be accepted on the given channel, and after additional timeout/the closing of all
1210 /// pending HTLCs, the channel will be closed on chain.
1212 /// * If we are the channel initiator, we will pay between our [`Background`] and
1213 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
1215 /// * If our counterparty is the channel initiator, we will require a channel closing
1216 /// transaction feerate of at least our [`Background`] feerate or the feerate which
1217 /// would appear on a force-closure transaction, whichever is lower. We will allow our
1218 /// counterparty to pay as much fee as they'd like, however.
1220 /// May generate a SendShutdown message event on success, which should be relayed.
1222 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
1223 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1224 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1227 pub extern "C" fn ChannelManager_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1228 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel(unsafe { &*channel_id});
1229 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() };
1233 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
1234 /// will be accepted on the given channel, and after additional timeout/the closing of all
1235 /// pending HTLCs, the channel will be closed on chain.
1237 /// `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
1238 /// the channel being closed or not:
1239 /// * If we are the channel initiator, we will pay at least this feerate on the closing
1240 /// transaction. The upper-bound is set by
1241 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
1242 /// estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
1243 /// * If our counterparty is the channel initiator, we will refuse to accept a channel closure
1244 /// transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
1245 /// will appear on a force-closure transaction, whichever is lower).
1247 /// May generate a SendShutdown message event on success, which should be relayed.
1249 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
1250 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1251 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1254 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 {
1255 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel_with_target_feerate(unsafe { &*channel_id}, target_feerate_sats_per_1000_weight);
1256 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() };
1260 /// Force closes a channel, immediately broadcasting the latest local commitment transaction to
1261 /// the chain and rejecting new HTLCs on the given channel. Fails if channel_id is unknown to the manager.
1264 pub extern "C" fn ChannelManager_force_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1265 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_channel(unsafe { &*channel_id});
1266 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() };
1270 /// Force close all channels, immediately broadcasting the latest local commitment transaction
1271 /// for each to the chain and rejecting new HTLCs on each.
1273 pub extern "C" fn ChannelManager_force_close_all_channels(this_arg: &ChannelManager) {
1274 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_all_channels()
1277 /// Sends a payment along a given route.
1279 /// Value parameters are provided via the last hop in route, see documentation for RouteHop
1280 /// fields for more info.
1282 /// Note that if the payment_hash already exists elsewhere (eg you're sending a duplicative
1283 /// payment), we don't do anything to stop you! We always try to ensure that if the provided
1284 /// next hop knows the preimage to payment_hash they can claim an additional amount as
1285 /// specified in the last hop in the route! Thus, you should probably do your own
1286 /// payment_preimage tracking (which you should already be doing as they represent \"proof of
1287 /// payment\") and prevent double-sends yourself.
1289 /// May generate SendHTLCs message(s) event on success, which should be relayed.
1291 /// Each path may have a different return value, and PaymentSendValue may return a Vec with
1292 /// each entry matching the corresponding-index entry in the route paths, see
1293 /// PaymentSendFailure for more info.
1295 /// In general, a path may raise:
1296 /// * APIError::RouteError when an invalid route or forwarding parameter (cltv_delta, fee,
1297 /// node public key) is specified.
1298 /// * APIError::ChannelUnavailable if the next-hop channel is not available for updates
1299 /// (including due to previous monitor update failure or new permanent monitor update
1301 /// * APIError::MonitorUpdateFailed if a new monitor update failure prevented sending the
1302 /// relevant updates.
1304 /// Note that depending on the type of the PaymentSendFailure the HTLC may have been
1305 /// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
1306 /// different route unless you intend to pay twice!
1308 /// payment_secret is unrelated to payment_hash (or PaymentPreimage) and exists to authenticate
1309 /// the sender to the recipient and prevent payment-probing (deanonymization) attacks. For
1310 /// newer nodes, it will be provided to you in the invoice. If you do not have one, the Route
1311 /// must not contain multiple paths as multi-path payments require a recipient-provided
1313 /// If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature
1314 /// bit set (either as required or as available). If multiple paths are present in the Route,
1315 /// we assume the invoice had the basic_mpp feature set.
1317 /// Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
1320 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 {
1321 let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentSecret(payment_secret.data) }) };
1322 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);
1323 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() };
1327 /// Retries a payment along the given [`Route`].
1329 /// Errors returned are a superset of those returned from [`send_payment`], so see
1330 /// [`send_payment`] documentation for more details on errors. This method will also error if the
1331 /// retry amount puts the payment more than 10% over the payment's total amount, or if the payment
1332 /// for the given `payment_id` cannot be found (likely due to timeout or success).
1334 /// [`send_payment`]: [`ChannelManager::send_payment`]
1337 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 {
1338 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.retry_payment(route.get_native_ref(), ::lightning::ln::channelmanager::PaymentId(payment_id.data));
1339 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() };
1343 /// Send a spontaneous payment, which is a payment that does not require the recipient to have
1344 /// generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
1345 /// the preimage, it must be a cryptographically secure random value that no intermediate node
1346 /// would be able to guess -- otherwise, an intermediate node may claim the payment and it will
1347 /// never reach the recipient.
1349 /// See [`send_payment`] documentation for more details on the return value of this function.
1351 /// Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
1352 /// [`send_payment`] for more information about the risks of duplicate preimage usage.
1354 /// Note that `route` must have exactly one path.
1356 /// [`send_payment`]: Self::send_payment
1358 /// Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None
1361 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 {
1362 let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
1363 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_spontaneous_payment(route.get_native_ref(), local_payment_preimage);
1364 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() };
1368 /// Call this upon creation of a funding transaction for the given channel.
1370 /// Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
1371 /// or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
1373 /// Panics if a funding transaction has already been provided for this channel.
1375 /// May panic if the output found in the funding transaction is duplicative with some other
1376 /// channel (note that this should be trivially prevented by using unique funding transaction
1377 /// keys per-channel).
1379 /// Do NOT broadcast the funding transaction yourself. When we have safely received our
1380 /// counterparty's signature the funding transaction will automatically be broadcast via the
1381 /// [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
1383 /// Note that this includes RBF or similar transaction replacement strategies - lightning does
1384 /// not currently support replacing a funding transaction on an existing channel. Instead,
1385 /// create a new channel with a conflicting funding transaction.
1387 /// [`Event::FundingGenerationReady`]: crate::util::events::Event::FundingGenerationReady
1390 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 {
1391 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_transaction_generated(unsafe { &*temporary_channel_id}, funding_transaction.into_bitcoin());
1392 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() };
1396 /// Regenerates channel_announcements and generates a signed node_announcement from the given
1397 /// arguments, providing them in corresponding events via
1398 /// [`get_and_clear_pending_msg_events`], if at least one public channel has been confirmed
1399 /// on-chain. This effectively re-broadcasts all channel announcements and sends our node
1400 /// announcement to ensure that the lightning P2P network is aware of the channels we have and
1401 /// our network addresses.
1403 /// `rgb` is a node \"color\" and `alias` is a printable human-readable string to describe this
1404 /// node to humans. They carry no in-protocol meaning.
1406 /// `addresses` represent the set (possibly empty) of socket addresses on which this node
1407 /// accepts incoming connections. These will be included in the node_announcement, publicly
1408 /// tying these addresses together and to this node. If you wish to preserve user privacy,
1409 /// addresses should likely contain only Tor Onion addresses.
1411 /// Panics if `addresses` is absurdly large (more than 500).
1413 /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
1415 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) {
1416 let mut local_addresses = Vec::new(); for mut item in addresses.into_rust().drain(..) { local_addresses.push( { item.into_native() }); };
1417 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.broadcast_node_announcement(rgb.data, alias.data, local_addresses)
1420 /// Processes HTLCs which are pending waiting on random forward delay.
1422 /// Should only really ever be called in response to a PendingHTLCsForwardable event.
1423 /// Will likely generate further events.
1425 pub extern "C" fn ChannelManager_process_pending_htlc_forwards(this_arg: &ChannelManager) {
1426 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_pending_htlc_forwards()
1429 /// Performs actions which should happen on startup and roughly once per minute thereafter.
1431 /// This currently includes:
1432 /// * Increasing or decreasing the on-chain feerate estimates for our outbound channels,
1433 /// * Broadcasting `ChannelUpdate` messages if we've been disconnected from our peer for more
1434 /// than a minute, informing the network that they should no longer attempt to route over
1437 /// Note that this may cause reentrancy through `chain::Watch::update_channel` calls or feerate
1438 /// estimate fetches.
1440 pub extern "C" fn ChannelManager_timer_tick_occurred(this_arg: &ChannelManager) {
1441 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timer_tick_occurred()
1444 /// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
1445 /// after a PaymentReceived event, failing the HTLC back to its origin and freeing resources
1446 /// along the path (including in our own channel on which we received it).
1447 /// Returns false if no payment was found to fail backwards, true if the process of failing the
1448 /// HTLC backwards has been started.
1451 pub extern "C" fn ChannelManager_fail_htlc_backwards(this_arg: &ChannelManager, payment_hash: *const [u8; 32]) -> bool {
1452 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_htlc_backwards(&::lightning::ln::PaymentHash(unsafe { *payment_hash }));
1456 /// Provides a payment preimage in response to a PaymentReceived event, returning true and
1457 /// generating message events for the net layer to claim the payment, if possible. Thus, you
1458 /// should probably kick the net layer to go send messages if this returns true!
1460 /// Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
1461 /// [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentReceived`
1462 /// event matches your expectation. If you fail to do so and call this method, you may provide
1463 /// the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
1465 /// May panic if called except in response to a PaymentReceived event.
1467 /// [`create_inbound_payment`]: Self::create_inbound_payment
1468 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1471 pub extern "C" fn ChannelManager_claim_funds(this_arg: &ChannelManager, mut payment_preimage: crate::c_types::ThirtyTwoBytes) -> bool {
1472 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.claim_funds(::lightning::ln::PaymentPreimage(payment_preimage.data));
1476 /// Gets the node_id held by this ChannelManager
1479 pub extern "C" fn ChannelManager_get_our_node_id(this_arg: &ChannelManager) -> crate::c_types::PublicKey {
1480 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_our_node_id();
1481 crate::c_types::PublicKey::from_rust(&ret)
1484 /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
1487 /// This differs from [`create_inbound_payment_for_hash`] only in that it generates the
1488 /// [`PaymentHash`] and [`PaymentPreimage`] for you, returning the first and storing the second.
1490 /// The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentReceived`], which
1491 /// will have the [`PaymentReceived::payment_preimage`] field filled in. That should then be
1492 /// passed directly to [`claim_funds`].
1494 /// See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
1496 /// [`claim_funds`]: Self::claim_funds
1497 /// [`PaymentReceived`]: events::Event::PaymentReceived
1498 /// [`PaymentReceived::payment_preimage`]: events::Event::PaymentReceived::payment_preimage
1499 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1502 pub extern "C" fn ChannelManager_create_inbound_payment(this_arg: &ChannelManager, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32, mut user_payment_id: u64) -> crate::c_types::derived::C2Tuple_PaymentHashPaymentSecretZ {
1503 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
1504 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment(local_min_value_msat, invoice_expiry_delta_secs, user_payment_id);
1505 let (mut orig_ret_0, mut orig_ret_1) = ret; let mut local_ret = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0.0 }, crate::c_types::ThirtyTwoBytes { data: orig_ret_1.0 }).into();
1509 /// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
1510 /// stored external to LDK.
1512 /// A [`PaymentReceived`] event will only be generated if the [`PaymentSecret`] matches a
1513 /// payment secret fetched via this method or [`create_inbound_payment`], and which is at least
1514 /// the `min_value_msat` provided here, if one is provided.
1516 /// The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) must be globally unique. This
1517 /// method may return an Err if another payment with the same payment_hash is still pending.
1519 /// `user_payment_id` will be provided back in [`PaymentPurpose::InvoicePayment::user_payment_id`] events to
1520 /// allow tracking of which events correspond with which calls to this and
1521 /// [`create_inbound_payment`]. `user_payment_id` has no meaning inside of LDK, it is simply
1522 /// copied to events and otherwise ignored. It may be used to correlate PaymentReceived events
1523 /// with invoice metadata stored elsewhere.
1525 /// `min_value_msat` should be set if the invoice being generated contains a value. Any payment
1526 /// received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
1527 /// before a [`PaymentReceived`] event will be generated, ensuring that we do not provide the
1528 /// sender \"proof-of-payment\" unless they have paid the required amount.
1530 /// `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
1531 /// in excess of the current time. This should roughly match the expiry time set in the invoice.
1532 /// After this many seconds, we will remove the inbound payment, resulting in any attempts to
1533 /// pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
1534 /// invoices when no timeout is set.
1536 /// Note that we use block header time to time-out pending inbound payments (with some margin
1537 /// to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
1538 /// accept a payment and generate a [`PaymentReceived`] event for some time after the expiry.
1539 /// If you need exact expiry semantics, you should enforce them upon receipt of
1540 /// [`PaymentReceived`].
1542 /// Pending inbound payments are stored in memory and in serialized versions of this
1543 /// [`ChannelManager`]. If potentially unbounded numbers of inbound payments may exist and
1544 /// space is limited, you may wish to rate-limit inbound payment creation.
1546 /// May panic if `invoice_expiry_delta_secs` is greater than one year.
1548 /// Note that invoices generated for inbound payments should have their `min_final_cltv_expiry`
1549 /// set to at least [`MIN_FINAL_CLTV_EXPIRY`].
1551 /// [`create_inbound_payment`]: Self::create_inbound_payment
1552 /// [`PaymentReceived`]: events::Event::PaymentReceived
1553 /// [`PaymentPurpose::InvoicePayment::user_payment_id`]: events::PaymentPurpose::InvoicePayment::user_payment_id
1556 pub extern "C" fn ChannelManager_create_inbound_payment_for_hash(this_arg: &ChannelManager, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32, mut user_payment_id: u64) -> crate::c_types::derived::CResult_PaymentSecretAPIErrorZ {
1557 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
1558 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, user_payment_id);
1559 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() };
1563 impl From<nativeChannelManager> for crate::lightning::util::events::MessageSendEventsProvider {
1564 fn from(obj: nativeChannelManager) -> Self {
1565 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1566 let mut ret = ChannelManager_as_MessageSendEventsProvider(&rust_obj);
1567 // 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
1568 rust_obj.inner = std::ptr::null_mut();
1569 ret.free = Some(ChannelManager_free_void);
1573 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
1574 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
1576 pub extern "C" fn ChannelManager_as_MessageSendEventsProvider(this_arg: &ChannelManager) -> crate::lightning::util::events::MessageSendEventsProvider {
1577 crate::lightning::util::events::MessageSendEventsProvider {
1578 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1580 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
1585 extern "C" fn ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
1586 let mut ret = <nativeChannelManager as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
1587 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
1591 impl From<nativeChannelManager> for crate::lightning::util::events::EventsProvider {
1592 fn from(obj: nativeChannelManager) -> Self {
1593 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1594 let mut ret = ChannelManager_as_EventsProvider(&rust_obj);
1595 // 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
1596 rust_obj.inner = std::ptr::null_mut();
1597 ret.free = Some(ChannelManager_free_void);
1601 /// Constructs a new EventsProvider which calls the relevant methods on this_arg.
1602 /// This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
1604 pub extern "C" fn ChannelManager_as_EventsProvider(this_arg: &ChannelManager) -> crate::lightning::util::events::EventsProvider {
1605 crate::lightning::util::events::EventsProvider {
1606 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1608 process_pending_events: ChannelManager_EventsProvider_process_pending_events,
1612 extern "C" fn ChannelManager_EventsProvider_process_pending_events(this_arg: *const c_void, mut handler: crate::lightning::util::events::EventHandler) {
1613 <nativeChannelManager as lightning::util::events::EventsProvider<>>::process_pending_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, handler)
1616 impl From<nativeChannelManager> for crate::lightning::chain::Listen {
1617 fn from(obj: nativeChannelManager) -> Self {
1618 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1619 let mut ret = ChannelManager_as_Listen(&rust_obj);
1620 // 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
1621 rust_obj.inner = std::ptr::null_mut();
1622 ret.free = Some(ChannelManager_free_void);
1626 /// Constructs a new Listen which calls the relevant methods on this_arg.
1627 /// This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
1629 pub extern "C" fn ChannelManager_as_Listen(this_arg: &ChannelManager) -> crate::lightning::chain::Listen {
1630 crate::lightning::chain::Listen {
1631 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1633 block_connected: ChannelManager_Listen_block_connected,
1634 block_disconnected: ChannelManager_Listen_block_disconnected,
1638 extern "C" fn ChannelManager_Listen_block_connected(this_arg: *const c_void, mut block: crate::c_types::u8slice, mut height: u32) {
1639 <nativeChannelManager as lightning::chain::Listen<>>::block_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height)
1641 extern "C" fn ChannelManager_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
1642 <nativeChannelManager as lightning::chain::Listen<>>::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
1645 impl From<nativeChannelManager> for crate::lightning::chain::Confirm {
1646 fn from(obj: nativeChannelManager) -> Self {
1647 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1648 let mut ret = ChannelManager_as_Confirm(&rust_obj);
1649 // 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
1650 rust_obj.inner = std::ptr::null_mut();
1651 ret.free = Some(ChannelManager_free_void);
1655 /// Constructs a new Confirm which calls the relevant methods on this_arg.
1656 /// This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
1658 pub extern "C" fn ChannelManager_as_Confirm(this_arg: &ChannelManager) -> crate::lightning::chain::Confirm {
1659 crate::lightning::chain::Confirm {
1660 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1662 transactions_confirmed: ChannelManager_Confirm_transactions_confirmed,
1663 transaction_unconfirmed: ChannelManager_Confirm_transaction_unconfirmed,
1664 best_block_updated: ChannelManager_Confirm_best_block_updated,
1665 get_relevant_txids: ChannelManager_Confirm_get_relevant_txids,
1669 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) {
1670 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 }); };
1671 <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)
1673 extern "C" fn ChannelManager_Confirm_best_block_updated(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
1674 <nativeChannelManager as lightning::chain::Confirm<>>::best_block_updated(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
1677 extern "C" fn ChannelManager_Confirm_get_relevant_txids(this_arg: *const c_void) -> crate::c_types::derived::CVec_TxidZ {
1678 let mut ret = <nativeChannelManager as lightning::chain::Confirm<>>::get_relevant_txids(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
1679 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::ThirtyTwoBytes { data: item.into_inner() } }); };
1682 extern "C" fn ChannelManager_Confirm_transaction_unconfirmed(this_arg: *const c_void, txid: *const [u8; 32]) {
1683 <nativeChannelManager as lightning::chain::Confirm<>>::transaction_unconfirmed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap())
1686 /// Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
1687 /// indicating whether persistence is necessary. Only one listener on
1688 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
1690 /// Note that the feature `allow_wallclock_use` must be enabled to use this function.
1693 pub extern "C" fn ChannelManager_await_persistable_update_timeout(this_arg: &ChannelManager, mut max_wait: u64) -> bool {
1694 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.await_persistable_update_timeout(std::time::Duration::from_secs(max_wait));
1698 /// Blocks until ChannelManager needs to be persisted. Only one listener on
1699 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
1702 pub extern "C" fn ChannelManager_await_persistable_update(this_arg: &ChannelManager) {
1703 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.await_persistable_update()
1706 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
1707 /// [`chain::Confirm`] interfaces.
1710 pub extern "C" fn ChannelManager_current_best_block(this_arg: &ChannelManager) -> crate::lightning::chain::BestBlock {
1711 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
1712 crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
1715 impl From<nativeChannelManager> for crate::lightning::ln::msgs::ChannelMessageHandler {
1716 fn from(obj: nativeChannelManager) -> Self {
1717 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1718 let mut ret = ChannelManager_as_ChannelMessageHandler(&rust_obj);
1719 // 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
1720 rust_obj.inner = std::ptr::null_mut();
1721 ret.free = Some(ChannelManager_free_void);
1725 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
1726 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
1728 pub extern "C" fn ChannelManager_as_ChannelMessageHandler(this_arg: &ChannelManager) -> crate::lightning::ln::msgs::ChannelMessageHandler {
1729 crate::lightning::ln::msgs::ChannelMessageHandler {
1730 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1732 handle_open_channel: ChannelManager_ChannelMessageHandler_handle_open_channel,
1733 handle_accept_channel: ChannelManager_ChannelMessageHandler_handle_accept_channel,
1734 handle_funding_created: ChannelManager_ChannelMessageHandler_handle_funding_created,
1735 handle_funding_signed: ChannelManager_ChannelMessageHandler_handle_funding_signed,
1736 handle_funding_locked: ChannelManager_ChannelMessageHandler_handle_funding_locked,
1737 handle_shutdown: ChannelManager_ChannelMessageHandler_handle_shutdown,
1738 handle_closing_signed: ChannelManager_ChannelMessageHandler_handle_closing_signed,
1739 handle_update_add_htlc: ChannelManager_ChannelMessageHandler_handle_update_add_htlc,
1740 handle_update_fulfill_htlc: ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc,
1741 handle_update_fail_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_htlc,
1742 handle_update_fail_malformed_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_malformed_htlc,
1743 handle_commitment_signed: ChannelManager_ChannelMessageHandler_handle_commitment_signed,
1744 handle_revoke_and_ack: ChannelManager_ChannelMessageHandler_handle_revoke_and_ack,
1745 handle_update_fee: ChannelManager_ChannelMessageHandler_handle_update_fee,
1746 handle_announcement_signatures: ChannelManager_ChannelMessageHandler_handle_announcement_signatures,
1747 peer_disconnected: ChannelManager_ChannelMessageHandler_peer_disconnected,
1748 peer_connected: ChannelManager_ChannelMessageHandler_peer_connected,
1749 handle_channel_reestablish: ChannelManager_ChannelMessageHandler_handle_channel_reestablish,
1750 handle_channel_update: ChannelManager_ChannelMessageHandler_handle_channel_update,
1751 handle_error: ChannelManager_ChannelMessageHandler_handle_error,
1752 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
1753 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1755 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
1760 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) {
1761 <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())
1763 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) {
1764 <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())
1766 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) {
1767 <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())
1769 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) {
1770 <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())
1772 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) {
1773 <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())
1775 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) {
1776 <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())
1778 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) {
1779 <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())
1781 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) {
1782 <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())
1784 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) {
1785 <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())
1787 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) {
1788 <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())
1790 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) {
1791 <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())
1793 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) {
1794 <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())
1796 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) {
1797 <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())
1799 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) {
1800 <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())
1802 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) {
1803 <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())
1805 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) {
1806 <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())
1808 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) {
1809 <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())
1811 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) {
1812 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), no_connection_possible)
1814 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) {
1815 <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())
1817 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) {
1818 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
1822 /// Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
1823 pub extern "C" fn ChannelManager_write(obj: &ChannelManager) -> crate::c_types::derived::CVec_u8Z {
1824 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1827 pub(crate) extern "C" fn ChannelManager_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1828 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelManager) })
1831 use lightning::ln::channelmanager::ChannelManagerReadArgs as nativeChannelManagerReadArgsImport;
1832 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>;
1834 /// Arguments for the creation of a ChannelManager that are not deserialized.
1836 /// At a high-level, the process for deserializing a ChannelManager and resuming normal operation
1838 /// 1) Deserialize all stored [`ChannelMonitor`]s.
1839 /// 2) Deserialize the [`ChannelManager`] by filling in this struct and calling:
1840 /// `<(BlockHash, ChannelManager)>::read(reader, args)`
1841 /// This may result in closing some channels if the [`ChannelMonitor`] is newer than the stored
1842 /// [`ChannelManager`] state to ensure no loss of funds. Thus, transactions may be broadcasted.
1843 /// 3) If you are not fetching full blocks, register all relevant [`ChannelMonitor`] outpoints the
1844 /// same way you would handle a [`chain::Filter`] call using
1845 /// [`ChannelMonitor::get_outputs_to_watch`] and [`ChannelMonitor::get_funding_txo`].
1846 /// 4) Reconnect blocks on your [`ChannelMonitor`]s.
1847 /// 5) Disconnect/connect blocks on the [`ChannelManager`].
1848 /// 6) Re-persist the [`ChannelMonitor`]s to ensure the latest state is on disk.
1849 /// Note that if you're using a [`ChainMonitor`] for your [`chain::Watch`] implementation, you
1850 /// will likely accomplish this as a side-effect of calling [`chain::Watch::watch_channel`] in
1852 /// 7) Move the [`ChannelMonitor`]s into your local [`chain::Watch`]. If you're using a
1853 /// [`ChainMonitor`], this is done by calling [`chain::Watch::watch_channel`].
1855 /// Note that the ordering of #4-7 is not of importance, however all four must occur before you
1856 /// call any other methods on the newly-deserialized [`ChannelManager`].
1858 /// Note that because some channels may be closed during deserialization, it is critical that you
1859 /// always deserialize only the latest version of a ChannelManager and ChannelMonitors available to
1860 /// you. If you deserialize an old ChannelManager (during which force-closure transactions may be
1861 /// broadcast), and then later deserialize a newer version of the same ChannelManager (which will
1862 /// not force-close the same channels but consider them live), you may end up revoking a state for
1863 /// which you've already broadcasted the transaction.
1865 /// [`ChainMonitor`]: crate::chain::chainmonitor::ChainMonitor
1868 pub struct ChannelManagerReadArgs {
1869 /// A pointer to the opaque Rust object.
1871 /// Nearly everywhere, inner must be non-null, however in places where
1872 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1873 pub inner: *mut nativeChannelManagerReadArgs,
1874 /// Indicates that this is the only struct which contains the same pointer.
1876 /// Rust functions which take ownership of an object provided via an argument require
1877 /// this to be true and invalidate the object pointed to by inner.
1881 impl Drop for ChannelManagerReadArgs {
1882 fn drop(&mut self) {
1883 if self.is_owned && !<*mut nativeChannelManagerReadArgs>::is_null(self.inner) {
1884 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1888 /// Frees any resources used by the ChannelManagerReadArgs, if is_owned is set and inner is non-NULL.
1890 pub extern "C" fn ChannelManagerReadArgs_free(this_obj: ChannelManagerReadArgs) { }
1892 /// Used only if an object of this type is returned as a trait impl by a method
1893 pub(crate) extern "C" fn ChannelManagerReadArgs_free_void(this_ptr: *mut c_void) {
1894 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManagerReadArgs); }
1897 impl ChannelManagerReadArgs {
1898 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManagerReadArgs {
1899 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1901 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManagerReadArgs {
1902 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1904 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1905 pub(crate) fn take_inner(mut self) -> *mut nativeChannelManagerReadArgs {
1906 assert!(self.is_owned);
1907 let ret = ObjOps::untweak_ptr(self.inner);
1908 self.inner = std::ptr::null_mut();
1912 /// The keys provider which will give us relevant keys. Some keys will be loaded during
1913 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
1916 pub extern "C" fn ChannelManagerReadArgs_get_keys_manager(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::keysinterface::KeysInterface {
1917 let mut inner_val = &mut this_ptr.get_native_mut_ref().keys_manager;
1920 /// The keys provider which will give us relevant keys. Some keys will be loaded during
1921 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
1924 pub extern "C" fn ChannelManagerReadArgs_set_keys_manager(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::keysinterface::KeysInterface) {
1925 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.keys_manager = val;
1927 /// The fee_estimator for use in the ChannelManager in the future.
1929 /// No calls to the FeeEstimator will be made during deserialization.
1931 pub extern "C" fn ChannelManagerReadArgs_get_fee_estimator(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::FeeEstimator {
1932 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_estimator;
1935 /// The fee_estimator for use in the ChannelManager in the future.
1937 /// No calls to the FeeEstimator will be made during deserialization.
1939 pub extern "C" fn ChannelManagerReadArgs_set_fee_estimator(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::FeeEstimator) {
1940 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_estimator = val;
1942 /// The chain::Watch for use in the ChannelManager in the future.
1944 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
1945 /// you have deserialized ChannelMonitors separately and will add them to your
1946 /// chain::Watch after deserializing this ChannelManager.
1948 pub extern "C" fn ChannelManagerReadArgs_get_chain_monitor(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::Watch {
1949 let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_monitor;
1952 /// The chain::Watch for use in the ChannelManager in the future.
1954 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
1955 /// you have deserialized ChannelMonitors separately and will add them to your
1956 /// chain::Watch after deserializing this ChannelManager.
1958 pub extern "C" fn ChannelManagerReadArgs_set_chain_monitor(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::Watch) {
1959 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_monitor = val;
1961 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
1962 /// used to broadcast the latest local commitment transactions of channels which must be
1963 /// force-closed during deserialization.
1965 pub extern "C" fn ChannelManagerReadArgs_get_tx_broadcaster(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::BroadcasterInterface {
1966 let mut inner_val = &mut this_ptr.get_native_mut_ref().tx_broadcaster;
1969 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
1970 /// used to broadcast the latest local commitment transactions of channels which must be
1971 /// force-closed during deserialization.
1973 pub extern "C" fn ChannelManagerReadArgs_set_tx_broadcaster(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::BroadcasterInterface) {
1974 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.tx_broadcaster = val;
1976 /// The Logger for use in the ChannelManager and which may be used to log information during
1977 /// deserialization.
1979 pub extern "C" fn ChannelManagerReadArgs_get_logger(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::util::logger::Logger {
1980 let mut inner_val = &mut this_ptr.get_native_mut_ref().logger;
1983 /// The Logger for use in the ChannelManager and which may be used to log information during
1984 /// deserialization.
1986 pub extern "C" fn ChannelManagerReadArgs_set_logger(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::logger::Logger) {
1987 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.logger = val;
1989 /// Default settings used for new channels. Any existing channels will continue to use the
1990 /// runtime settings which were stored when the ChannelManager was serialized.
1992 pub extern "C" fn ChannelManagerReadArgs_get_default_config(this_ptr: &ChannelManagerReadArgs) -> crate::lightning::util::config::UserConfig {
1993 let mut inner_val = &mut this_ptr.get_native_mut_ref().default_config;
1994 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 }
1996 /// Default settings used for new channels. Any existing channels will continue to use the
1997 /// runtime settings which were stored when the ChannelManager was serialized.
1999 pub extern "C" fn ChannelManagerReadArgs_set_default_config(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::config::UserConfig) {
2000 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.default_config = *unsafe { Box::from_raw(val.take_inner()) };
2002 /// Simple utility function to create a ChannelManagerReadArgs which creates the monitor
2003 /// HashMap for you. This is primarily useful for C bindings where it is not practical to
2004 /// populate a HashMap directly from C.
2007 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 {
2008 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() }); };
2009 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);
2010 ChannelManagerReadArgs { inner: ObjOps::heap_alloc(ret), is_owned: true }
2014 /// Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_write
2015 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 {
2016 let arg_conv = *unsafe { Box::from_raw(arg.take_inner()) };
2017 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);
2018 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() };