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 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 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 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 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 _) 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 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 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 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 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 _) 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 _) 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 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 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 _) 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 _) 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_id passed in to create_channel, or 0 if the channel was inbound.
674 pub extern "C" fn ChannelDetails_get_user_id(this_ptr: &ChannelDetails) -> u64 {
675 let mut inner_val = &mut this_ptr.get_native_mut_ref().user_id;
678 /// The user_id passed in to create_channel, or 0 if the channel was inbound.
680 pub extern "C" fn ChannelDetails_set_user_id(this_ptr: &mut ChannelDetails, mut val: u64) {
681 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.user_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_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_id: user_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.
936 PartialFailure(crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ),
938 use lightning::ln::channelmanager::PaymentSendFailure as nativePaymentSendFailure;
939 impl PaymentSendFailure {
941 pub(crate) fn to_native(&self) -> nativePaymentSendFailure {
943 PaymentSendFailure::ParameterError (ref a, ) => {
944 let mut a_nonref = (*a).clone();
945 nativePaymentSendFailure::ParameterError (
946 a_nonref.into_native(),
949 PaymentSendFailure::PathParameterError (ref a, ) => {
950 let mut a_nonref = (*a).clone();
951 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 }); };
952 nativePaymentSendFailure::PathParameterError (
956 PaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
957 let mut a_nonref = (*a).clone();
958 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { item.into_native() }); };
959 nativePaymentSendFailure::AllFailedRetrySafe (
963 PaymentSendFailure::PartialFailure (ref a, ) => {
964 let mut a_nonref = (*a).clone();
965 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 }); };
966 nativePaymentSendFailure::PartialFailure (
973 pub(crate) fn into_native(self) -> nativePaymentSendFailure {
975 PaymentSendFailure::ParameterError (mut a, ) => {
976 nativePaymentSendFailure::ParameterError (
980 PaymentSendFailure::PathParameterError (mut a, ) => {
981 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 }); };
982 nativePaymentSendFailure::PathParameterError (
986 PaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
987 let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { item.into_native() }); };
988 nativePaymentSendFailure::AllFailedRetrySafe (
992 PaymentSendFailure::PartialFailure (mut a, ) => {
993 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 }); };
994 nativePaymentSendFailure::PartialFailure (
1001 pub(crate) fn from_native(native: &nativePaymentSendFailure) -> Self {
1003 nativePaymentSendFailure::ParameterError (ref a, ) => {
1004 let mut a_nonref = (*a).clone();
1005 PaymentSendFailure::ParameterError (
1006 crate::lightning::util::errors::APIError::native_into(a_nonref),
1009 nativePaymentSendFailure::PathParameterError (ref a, ) => {
1010 let mut a_nonref = (*a).clone();
1011 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 }); };
1012 PaymentSendFailure::PathParameterError (
1013 local_a_nonref.into(),
1016 nativePaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
1017 let mut a_nonref = (*a).clone();
1018 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) }); };
1019 PaymentSendFailure::AllFailedRetrySafe (
1020 local_a_nonref.into(),
1023 nativePaymentSendFailure::PartialFailure (ref a, ) => {
1024 let mut a_nonref = (*a).clone();
1025 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 }); };
1026 PaymentSendFailure::PartialFailure (
1027 local_a_nonref.into(),
1033 pub(crate) fn native_into(native: nativePaymentSendFailure) -> Self {
1035 nativePaymentSendFailure::ParameterError (mut a, ) => {
1036 PaymentSendFailure::ParameterError (
1037 crate::lightning::util::errors::APIError::native_into(a),
1040 nativePaymentSendFailure::PathParameterError (mut a, ) => {
1041 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 }); };
1042 PaymentSendFailure::PathParameterError (
1046 nativePaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
1047 let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { crate::lightning::util::errors::APIError::native_into(item) }); };
1048 PaymentSendFailure::AllFailedRetrySafe (
1052 nativePaymentSendFailure::PartialFailure (mut a, ) => {
1053 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 }); };
1054 PaymentSendFailure::PartialFailure (
1061 /// Frees any resources used by the PaymentSendFailure
1063 pub extern "C" fn PaymentSendFailure_free(this_ptr: PaymentSendFailure) { }
1064 /// Creates a copy of the PaymentSendFailure
1066 pub extern "C" fn PaymentSendFailure_clone(orig: &PaymentSendFailure) -> PaymentSendFailure {
1070 /// Utility method to constructs a new ParameterError-variant PaymentSendFailure
1071 pub extern "C" fn PaymentSendFailure_parameter_error(a: crate::lightning::util::errors::APIError) -> PaymentSendFailure {
1072 PaymentSendFailure::ParameterError(a, )
1075 /// Utility method to constructs a new PathParameterError-variant PaymentSendFailure
1076 pub extern "C" fn PaymentSendFailure_path_parameter_error(a: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ) -> PaymentSendFailure {
1077 PaymentSendFailure::PathParameterError(a, )
1080 /// Utility method to constructs a new AllFailedRetrySafe-variant PaymentSendFailure
1081 pub extern "C" fn PaymentSendFailure_all_failed_retry_safe(a: crate::c_types::derived::CVec_APIErrorZ) -> PaymentSendFailure {
1082 PaymentSendFailure::AllFailedRetrySafe(a, )
1085 /// Utility method to constructs a new PartialFailure-variant PaymentSendFailure
1086 pub extern "C" fn PaymentSendFailure_partial_failure(a: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ) -> PaymentSendFailure {
1087 PaymentSendFailure::PartialFailure(a, )
1089 /// Constructs a new ChannelManager to hold several channels and route between them.
1091 /// This is the main \"logic hub\" for all channel-related actions, and implements
1092 /// ChannelMessageHandler.
1094 /// Non-proportional fees are fixed according to our risk using the provided fee estimator.
1096 /// panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`!
1098 /// Users need to notify the new ChannelManager when a new block is connected or
1099 /// disconnected using its `block_connected` and `block_disconnected` methods, starting
1100 /// from after `params.latest_hash`.
1103 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 {
1104 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()) });
1105 ChannelManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
1108 /// Gets the current configuration applied to all new channels, as
1111 pub extern "C" fn ChannelManager_get_current_default_configuration(this_arg: &ChannelManager) -> crate::lightning::util::config::UserConfig {
1112 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_current_default_configuration();
1113 crate::lightning::util::config::UserConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const _) as *mut _) }, is_owned: false }
1116 /// Creates a new outbound channel to the given remote node and with the given value.
1118 /// user_id will be provided back as user_channel_id in FundingGenerationReady events to allow
1119 /// tracking of which events correspond with which create_channel call. Note that the
1120 /// user_channel_id defaults to 0 for inbound channels, so you may wish to avoid using 0 for
1121 /// user_id here. user_id has no meaning inside of LDK, it is simply copied to events and
1122 /// otherwise ignored.
1124 /// If successful, will generate a SendOpenChannel message event, so you should probably poll
1125 /// PeerManager::process_events afterwards.
1127 /// Raises APIError::APIMisuseError when channel_value_satoshis > 2**24 or push_msat is
1128 /// greater than channel_value_satoshis * 1k or channel_value_satoshis is < 1000.
1130 /// Note that we do not check if you are currently connected to the given peer. If no
1131 /// connection is available, the outbound `open_channel` message may fail to send, resulting in
1132 /// the channel eventually being silently forgotten.
1134 /// Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
1137 pub extern "C" fn ChannelManager_create_channel(this_arg: &ChannelManager, mut their_network_key: crate::c_types::PublicKey, mut channel_value_satoshis: u64, mut push_msat: u64, mut user_id: u64, mut override_config: crate::lightning::util::config::UserConfig) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1138 let mut local_override_config = if override_config.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(override_config.take_inner()) } }) };
1139 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_channel(their_network_key.into_rust(), channel_value_satoshis, push_msat, user_id, local_override_config);
1140 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() };
1144 /// Gets the list of open channels, in random order. See ChannelDetail field documentation for
1145 /// more information.
1148 pub extern "C" fn ChannelManager_list_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1149 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_channels();
1150 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 } }); };
1154 /// Gets the list of usable channels, in random order. Useful as an argument to
1155 /// get_route to ensure non-announced channels are used.
1157 /// These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
1158 /// documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
1162 pub extern "C" fn ChannelManager_list_usable_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1163 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_usable_channels();
1164 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 } }); };
1168 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
1169 /// will be accepted on the given channel, and after additional timeout/the closing of all
1170 /// pending HTLCs, the channel will be closed on chain.
1172 /// * If we are the channel initiator, we will pay between our [`Background`] and
1173 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
1175 /// * If our counterparty is the channel initiator, we will require a channel closing
1176 /// transaction feerate of at least our [`Background`] feerate or the feerate which
1177 /// would appear on a force-closure transaction, whichever is lower. We will allow our
1178 /// counterparty to pay as much fee as they'd like, however.
1180 /// May generate a SendShutdown message event on success, which should be relayed.
1182 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
1183 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1184 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1187 pub extern "C" fn ChannelManager_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1188 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel(unsafe { &*channel_id});
1189 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() };
1193 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
1194 /// will be accepted on the given channel, and after additional timeout/the closing of all
1195 /// pending HTLCs, the channel will be closed on chain.
1197 /// `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
1198 /// the channel being closed or not:
1199 /// * If we are the channel initiator, we will pay at least this feerate on the closing
1200 /// transaction. The upper-bound is set by
1201 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
1202 /// estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
1203 /// * If our counterparty is the channel initiator, we will refuse to accept a channel closure
1204 /// transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
1205 /// will appear on a force-closure transaction, whichever is lower).
1207 /// May generate a SendShutdown message event on success, which should be relayed.
1209 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
1210 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1211 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1214 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 {
1215 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel_with_target_feerate(unsafe { &*channel_id}, target_feerate_sats_per_1000_weight);
1216 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() };
1220 /// Force closes a channel, immediately broadcasting the latest local commitment transaction to
1221 /// the chain and rejecting new HTLCs on the given channel. Fails if channel_id is unknown to the manager.
1224 pub extern "C" fn ChannelManager_force_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1225 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_channel(unsafe { &*channel_id});
1226 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() };
1230 /// Force close all channels, immediately broadcasting the latest local commitment transaction
1231 /// for each to the chain and rejecting new HTLCs on each.
1233 pub extern "C" fn ChannelManager_force_close_all_channels(this_arg: &ChannelManager) {
1234 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_all_channels()
1237 /// Sends a payment along a given route.
1239 /// Value parameters are provided via the last hop in route, see documentation for RouteHop
1240 /// fields for more info.
1242 /// Note that if the payment_hash already exists elsewhere (eg you're sending a duplicative
1243 /// payment), we don't do anything to stop you! We always try to ensure that if the provided
1244 /// next hop knows the preimage to payment_hash they can claim an additional amount as
1245 /// specified in the last hop in the route! Thus, you should probably do your own
1246 /// payment_preimage tracking (which you should already be doing as they represent \"proof of
1247 /// payment\") and prevent double-sends yourself.
1249 /// May generate SendHTLCs message(s) event on success, which should be relayed.
1251 /// Each path may have a different return value, and PaymentSendValue may return a Vec with
1252 /// each entry matching the corresponding-index entry in the route paths, see
1253 /// PaymentSendFailure for more info.
1255 /// In general, a path may raise:
1256 /// * APIError::RouteError when an invalid route or forwarding parameter (cltv_delta, fee,
1257 /// node public key) is specified.
1258 /// * APIError::ChannelUnavailable if the next-hop channel is not available for updates
1259 /// (including due to previous monitor update failure or new permanent monitor update
1261 /// * APIError::MonitorUpdateFailed if a new monitor update failure prevented sending the
1262 /// relevant updates.
1264 /// Note that depending on the type of the PaymentSendFailure the HTLC may have been
1265 /// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
1266 /// different route unless you intend to pay twice!
1268 /// payment_secret is unrelated to payment_hash (or PaymentPreimage) and exists to authenticate
1269 /// the sender to the recipient and prevent payment-probing (deanonymization) attacks. For
1270 /// newer nodes, it will be provided to you in the invoice. If you do not have one, the Route
1271 /// must not contain multiple paths as multi-path payments require a recipient-provided
1273 /// If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature
1274 /// bit set (either as required or as available). If multiple paths are present in the Route,
1275 /// we assume the invoice had the basic_mpp feature set.
1277 /// Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
1280 pub extern "C" fn ChannelManager_send_payment(this_arg: &ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut payment_secret: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_NonePaymentSendFailureZ {
1281 let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentSecret(payment_secret.data) }) };
1282 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);
1283 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() };
1287 /// Send a spontaneous payment, which is a payment that does not require the recipient to have
1288 /// generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
1289 /// the preimage, it must be a cryptographically secure random value that no intermediate node
1290 /// would be able to guess -- otherwise, an intermediate node may claim the payment and it will
1291 /// never reach the recipient.
1293 /// See [`send_payment`] documentation for more details on the return value of this function.
1295 /// Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
1296 /// [`send_payment`] for more information about the risks of duplicate preimage usage.
1298 /// Note that `route` must have exactly one path.
1300 /// [`send_payment`]: Self::send_payment
1302 /// Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None
1305 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_PaymentHashPaymentSendFailureZ {
1306 let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
1307 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_spontaneous_payment(route.get_native_ref(), local_payment_preimage);
1308 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() };
1312 /// Call this upon creation of a funding transaction for the given channel.
1314 /// Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
1315 /// or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
1317 /// Panics if a funding transaction has already been provided for this channel.
1319 /// May panic if the output found in the funding transaction is duplicative with some other
1320 /// channel (note that this should be trivially prevented by using unique funding transaction
1321 /// keys per-channel).
1323 /// Do NOT broadcast the funding transaction yourself. When we have safely received our
1324 /// counterparty's signature the funding transaction will automatically be broadcast via the
1325 /// [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
1327 /// Note that this includes RBF or similar transaction replacement strategies - lightning does
1328 /// not currently support replacing a funding transaction on an existing channel. Instead,
1329 /// create a new channel with a conflicting funding transaction.
1331 /// [`Event::FundingGenerationReady`]: crate::util::events::Event::FundingGenerationReady
1334 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 {
1335 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_transaction_generated(unsafe { &*temporary_channel_id}, funding_transaction.into_bitcoin());
1336 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() };
1340 /// Regenerates channel_announcements and generates a signed node_announcement from the given
1341 /// arguments, providing them in corresponding events via
1342 /// [`get_and_clear_pending_msg_events`], if at least one public channel has been confirmed
1343 /// on-chain. This effectively re-broadcasts all channel announcements and sends our node
1344 /// announcement to ensure that the lightning P2P network is aware of the channels we have and
1345 /// our network addresses.
1347 /// `rgb` is a node \"color\" and `alias` is a printable human-readable string to describe this
1348 /// node to humans. They carry no in-protocol meaning.
1350 /// `addresses` represent the set (possibly empty) of socket addresses on which this node
1351 /// accepts incoming connections. These will be included in the node_announcement, publicly
1352 /// tying these addresses together and to this node. If you wish to preserve user privacy,
1353 /// addresses should likely contain only Tor Onion addresses.
1355 /// Panics if `addresses` is absurdly large (more than 500).
1357 /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
1359 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) {
1360 let mut local_addresses = Vec::new(); for mut item in addresses.into_rust().drain(..) { local_addresses.push( { item.into_native() }); };
1361 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.broadcast_node_announcement(rgb.data, alias.data, local_addresses)
1364 /// Processes HTLCs which are pending waiting on random forward delay.
1366 /// Should only really ever be called in response to a PendingHTLCsForwardable event.
1367 /// Will likely generate further events.
1369 pub extern "C" fn ChannelManager_process_pending_htlc_forwards(this_arg: &ChannelManager) {
1370 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_pending_htlc_forwards()
1373 /// Performs actions which should happen on startup and roughly once per minute thereafter.
1375 /// This currently includes:
1376 /// * Increasing or decreasing the on-chain feerate estimates for our outbound channels,
1377 /// * Broadcasting `ChannelUpdate` messages if we've been disconnected from our peer for more
1378 /// than a minute, informing the network that they should no longer attempt to route over
1381 /// Note that this may cause reentrancy through `chain::Watch::update_channel` calls or feerate
1382 /// estimate fetches.
1384 pub extern "C" fn ChannelManager_timer_tick_occurred(this_arg: &ChannelManager) {
1385 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timer_tick_occurred()
1388 /// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
1389 /// after a PaymentReceived event, failing the HTLC back to its origin and freeing resources
1390 /// along the path (including in our own channel on which we received it).
1391 /// Returns false if no payment was found to fail backwards, true if the process of failing the
1392 /// HTLC backwards has been started.
1395 pub extern "C" fn ChannelManager_fail_htlc_backwards(this_arg: &ChannelManager, payment_hash: *const [u8; 32]) -> bool {
1396 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_htlc_backwards(&::lightning::ln::PaymentHash(unsafe { *payment_hash }));
1400 /// Provides a payment preimage in response to a PaymentReceived event, returning true and
1401 /// generating message events for the net layer to claim the payment, if possible. Thus, you
1402 /// should probably kick the net layer to go send messages if this returns true!
1404 /// Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
1405 /// [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentReceived`
1406 /// event matches your expectation. If you fail to do so and call this method, you may provide
1407 /// the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
1409 /// May panic if called except in response to a PaymentReceived event.
1411 /// [`create_inbound_payment`]: Self::create_inbound_payment
1412 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1415 pub extern "C" fn ChannelManager_claim_funds(this_arg: &ChannelManager, mut payment_preimage: crate::c_types::ThirtyTwoBytes) -> bool {
1416 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.claim_funds(::lightning::ln::PaymentPreimage(payment_preimage.data));
1420 /// Gets the node_id held by this ChannelManager
1423 pub extern "C" fn ChannelManager_get_our_node_id(this_arg: &ChannelManager) -> crate::c_types::PublicKey {
1424 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_our_node_id();
1425 crate::c_types::PublicKey::from_rust(&ret)
1428 /// Restores a single, given channel to normal operation after a
1429 /// ChannelMonitorUpdateErr::TemporaryFailure was returned from a channel monitor update
1432 /// All ChannelMonitor updates up to and including highest_applied_update_id must have been
1433 /// fully committed in every copy of the given channels' ChannelMonitors.
1435 /// Note that there is no effect to calling with a highest_applied_update_id other than the
1436 /// current latest ChannelMonitorUpdate and one call to this function after multiple
1437 /// ChannelMonitorUpdateErr::TemporaryFailures is fine. The highest_applied_update_id field
1438 /// exists largely only to prevent races between this and concurrent update_monitor calls.
1440 /// Thus, the anticipated use is, at a high level:
1441 /// 1) You register a chain::Watch with this ChannelManager,
1442 /// 2) it stores each update to disk, and begins updating any remote (eg watchtower) copies of
1443 /// said ChannelMonitors as it can, returning ChannelMonitorUpdateErr::TemporaryFailures
1444 /// any time it cannot do so instantly,
1445 /// 3) update(s) are applied to each remote copy of a ChannelMonitor,
1446 /// 4) once all remote copies are updated, you call this function with the update_id that
1447 /// completed, and once it is the latest the Channel will be re-enabled.
1449 pub extern "C" fn ChannelManager_channel_monitor_updated(this_arg: &ChannelManager, funding_txo: &crate::lightning::chain::transaction::OutPoint, mut highest_applied_update_id: u64) {
1450 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_monitor_updated(funding_txo.get_native_ref(), highest_applied_update_id)
1453 /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
1456 /// This differs from [`create_inbound_payment_for_hash`] only in that it generates the
1457 /// [`PaymentHash`] and [`PaymentPreimage`] for you, returning the first and storing the second.
1459 /// The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentReceived`], which
1460 /// will have the [`PaymentReceived::payment_preimage`] field filled in. That should then be
1461 /// passed directly to [`claim_funds`].
1463 /// See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
1465 /// [`claim_funds`]: Self::claim_funds
1466 /// [`PaymentReceived`]: events::Event::PaymentReceived
1467 /// [`PaymentReceived::payment_preimage`]: events::Event::PaymentReceived::payment_preimage
1468 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1471 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 {
1472 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
1473 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment(local_min_value_msat, invoice_expiry_delta_secs, user_payment_id);
1474 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();
1478 /// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
1479 /// stored external to LDK.
1481 /// A [`PaymentReceived`] event will only be generated if the [`PaymentSecret`] matches a
1482 /// payment secret fetched via this method or [`create_inbound_payment`], and which is at least
1483 /// the `min_value_msat` provided here, if one is provided.
1485 /// The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) must be globally unique. This
1486 /// method may return an Err if another payment with the same payment_hash is still pending.
1488 /// `user_payment_id` will be provided back in [`PaymentPurpose::InvoicePayment::user_payment_id`] events to
1489 /// allow tracking of which events correspond with which calls to this and
1490 /// [`create_inbound_payment`]. `user_payment_id` has no meaning inside of LDK, it is simply
1491 /// copied to events and otherwise ignored. It may be used to correlate PaymentReceived events
1492 /// with invoice metadata stored elsewhere.
1494 /// `min_value_msat` should be set if the invoice being generated contains a value. Any payment
1495 /// received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
1496 /// before a [`PaymentReceived`] event will be generated, ensuring that we do not provide the
1497 /// sender \"proof-of-payment\" unless they have paid the required amount.
1499 /// `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
1500 /// in excess of the current time. This should roughly match the expiry time set in the invoice.
1501 /// After this many seconds, we will remove the inbound payment, resulting in any attempts to
1502 /// pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
1503 /// invoices when no timeout is set.
1505 /// Note that we use block header time to time-out pending inbound payments (with some margin
1506 /// to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
1507 /// accept a payment and generate a [`PaymentReceived`] event for some time after the expiry.
1508 /// If you need exact expiry semantics, you should enforce them upon receipt of
1509 /// [`PaymentReceived`].
1511 /// Pending inbound payments are stored in memory and in serialized versions of this
1512 /// [`ChannelManager`]. If potentially unbounded numbers of inbound payments may exist and
1513 /// space is limited, you may wish to rate-limit inbound payment creation.
1515 /// May panic if `invoice_expiry_delta_secs` is greater than one year.
1517 /// Note that invoices generated for inbound payments should have their `min_final_cltv_expiry`
1518 /// set to at least [`MIN_FINAL_CLTV_EXPIRY`].
1520 /// [`create_inbound_payment`]: Self::create_inbound_payment
1521 /// [`PaymentReceived`]: events::Event::PaymentReceived
1522 /// [`PaymentPurpose::InvoicePayment::user_payment_id`]: events::PaymentPurpose::InvoicePayment::user_payment_id
1525 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 {
1526 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
1527 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);
1528 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() };
1532 impl From<nativeChannelManager> for crate::lightning::util::events::MessageSendEventsProvider {
1533 fn from(obj: nativeChannelManager) -> Self {
1534 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1535 let mut ret = ChannelManager_as_MessageSendEventsProvider(&rust_obj);
1536 // 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
1537 rust_obj.inner = std::ptr::null_mut();
1538 ret.free = Some(ChannelManager_free_void);
1542 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
1543 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
1545 pub extern "C" fn ChannelManager_as_MessageSendEventsProvider(this_arg: &ChannelManager) -> crate::lightning::util::events::MessageSendEventsProvider {
1546 crate::lightning::util::events::MessageSendEventsProvider {
1547 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1549 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
1554 extern "C" fn ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
1555 let mut ret = <nativeChannelManager as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
1556 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
1560 impl From<nativeChannelManager> for crate::lightning::util::events::EventsProvider {
1561 fn from(obj: nativeChannelManager) -> Self {
1562 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1563 let mut ret = ChannelManager_as_EventsProvider(&rust_obj);
1564 // 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
1565 rust_obj.inner = std::ptr::null_mut();
1566 ret.free = Some(ChannelManager_free_void);
1570 /// Constructs a new EventsProvider which calls the relevant methods on this_arg.
1571 /// This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
1573 pub extern "C" fn ChannelManager_as_EventsProvider(this_arg: &ChannelManager) -> crate::lightning::util::events::EventsProvider {
1574 crate::lightning::util::events::EventsProvider {
1575 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1577 process_pending_events: ChannelManager_EventsProvider_process_pending_events,
1581 extern "C" fn ChannelManager_EventsProvider_process_pending_events(this_arg: *const c_void, mut handler: crate::lightning::util::events::EventHandler) {
1582 <nativeChannelManager as lightning::util::events::EventsProvider<>>::process_pending_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, handler)
1585 impl From<nativeChannelManager> for crate::lightning::chain::Listen {
1586 fn from(obj: nativeChannelManager) -> Self {
1587 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1588 let mut ret = ChannelManager_as_Listen(&rust_obj);
1589 // 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
1590 rust_obj.inner = std::ptr::null_mut();
1591 ret.free = Some(ChannelManager_free_void);
1595 /// Constructs a new Listen which calls the relevant methods on this_arg.
1596 /// This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
1598 pub extern "C" fn ChannelManager_as_Listen(this_arg: &ChannelManager) -> crate::lightning::chain::Listen {
1599 crate::lightning::chain::Listen {
1600 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1602 block_connected: ChannelManager_Listen_block_connected,
1603 block_disconnected: ChannelManager_Listen_block_disconnected,
1607 extern "C" fn ChannelManager_Listen_block_connected(this_arg: *const c_void, mut block: crate::c_types::u8slice, mut height: u32) {
1608 <nativeChannelManager as lightning::chain::Listen<>>::block_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height)
1610 extern "C" fn ChannelManager_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
1611 <nativeChannelManager as lightning::chain::Listen<>>::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
1614 impl From<nativeChannelManager> for crate::lightning::chain::Confirm {
1615 fn from(obj: nativeChannelManager) -> Self {
1616 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1617 let mut ret = ChannelManager_as_Confirm(&rust_obj);
1618 // 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
1619 rust_obj.inner = std::ptr::null_mut();
1620 ret.free = Some(ChannelManager_free_void);
1624 /// Constructs a new Confirm which calls the relevant methods on this_arg.
1625 /// This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
1627 pub extern "C" fn ChannelManager_as_Confirm(this_arg: &ChannelManager) -> crate::lightning::chain::Confirm {
1628 crate::lightning::chain::Confirm {
1629 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1631 transactions_confirmed: ChannelManager_Confirm_transactions_confirmed,
1632 transaction_unconfirmed: ChannelManager_Confirm_transaction_unconfirmed,
1633 best_block_updated: ChannelManager_Confirm_best_block_updated,
1634 get_relevant_txids: ChannelManager_Confirm_get_relevant_txids,
1638 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) {
1639 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 }); };
1640 <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)
1642 extern "C" fn ChannelManager_Confirm_best_block_updated(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
1643 <nativeChannelManager as lightning::chain::Confirm<>>::best_block_updated(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
1646 extern "C" fn ChannelManager_Confirm_get_relevant_txids(this_arg: *const c_void) -> crate::c_types::derived::CVec_TxidZ {
1647 let mut ret = <nativeChannelManager as lightning::chain::Confirm<>>::get_relevant_txids(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
1648 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::ThirtyTwoBytes { data: item.into_inner() } }); };
1651 extern "C" fn ChannelManager_Confirm_transaction_unconfirmed(this_arg: *const c_void, txid: *const [u8; 32]) {
1652 <nativeChannelManager as lightning::chain::Confirm<>>::transaction_unconfirmed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap())
1655 /// Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
1656 /// indicating whether persistence is necessary. Only one listener on
1657 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
1659 /// Note that the feature `allow_wallclock_use` must be enabled to use this function.
1662 pub extern "C" fn ChannelManager_await_persistable_update_timeout(this_arg: &ChannelManager, mut max_wait: u64) -> bool {
1663 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.await_persistable_update_timeout(std::time::Duration::from_secs(max_wait));
1667 /// Blocks until ChannelManager needs to be persisted. Only one listener on
1668 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
1671 pub extern "C" fn ChannelManager_await_persistable_update(this_arg: &ChannelManager) {
1672 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.await_persistable_update()
1675 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
1676 /// [`chain::Confirm`] interfaces.
1679 pub extern "C" fn ChannelManager_current_best_block(this_arg: &ChannelManager) -> crate::lightning::chain::BestBlock {
1680 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
1681 crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
1684 impl From<nativeChannelManager> for crate::lightning::ln::msgs::ChannelMessageHandler {
1685 fn from(obj: nativeChannelManager) -> Self {
1686 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1687 let mut ret = ChannelManager_as_ChannelMessageHandler(&rust_obj);
1688 // 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
1689 rust_obj.inner = std::ptr::null_mut();
1690 ret.free = Some(ChannelManager_free_void);
1694 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
1695 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
1697 pub extern "C" fn ChannelManager_as_ChannelMessageHandler(this_arg: &ChannelManager) -> crate::lightning::ln::msgs::ChannelMessageHandler {
1698 crate::lightning::ln::msgs::ChannelMessageHandler {
1699 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1701 handle_open_channel: ChannelManager_ChannelMessageHandler_handle_open_channel,
1702 handle_accept_channel: ChannelManager_ChannelMessageHandler_handle_accept_channel,
1703 handle_funding_created: ChannelManager_ChannelMessageHandler_handle_funding_created,
1704 handle_funding_signed: ChannelManager_ChannelMessageHandler_handle_funding_signed,
1705 handle_funding_locked: ChannelManager_ChannelMessageHandler_handle_funding_locked,
1706 handle_shutdown: ChannelManager_ChannelMessageHandler_handle_shutdown,
1707 handle_closing_signed: ChannelManager_ChannelMessageHandler_handle_closing_signed,
1708 handle_update_add_htlc: ChannelManager_ChannelMessageHandler_handle_update_add_htlc,
1709 handle_update_fulfill_htlc: ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc,
1710 handle_update_fail_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_htlc,
1711 handle_update_fail_malformed_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_malformed_htlc,
1712 handle_commitment_signed: ChannelManager_ChannelMessageHandler_handle_commitment_signed,
1713 handle_revoke_and_ack: ChannelManager_ChannelMessageHandler_handle_revoke_and_ack,
1714 handle_update_fee: ChannelManager_ChannelMessageHandler_handle_update_fee,
1715 handle_announcement_signatures: ChannelManager_ChannelMessageHandler_handle_announcement_signatures,
1716 peer_disconnected: ChannelManager_ChannelMessageHandler_peer_disconnected,
1717 peer_connected: ChannelManager_ChannelMessageHandler_peer_connected,
1718 handle_channel_reestablish: ChannelManager_ChannelMessageHandler_handle_channel_reestablish,
1719 handle_channel_update: ChannelManager_ChannelMessageHandler_handle_channel_update,
1720 handle_error: ChannelManager_ChannelMessageHandler_handle_error,
1721 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
1722 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1724 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
1729 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) {
1730 <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())
1732 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) {
1733 <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())
1735 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) {
1736 <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())
1738 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) {
1739 <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())
1741 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) {
1742 <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())
1744 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) {
1745 <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())
1747 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) {
1748 <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())
1750 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) {
1751 <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())
1753 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) {
1754 <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())
1756 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) {
1757 <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())
1759 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) {
1760 <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())
1762 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) {
1763 <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())
1765 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) {
1766 <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())
1768 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) {
1769 <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())
1771 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) {
1772 <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())
1774 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) {
1775 <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())
1777 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) {
1778 <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())
1780 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) {
1781 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), no_connection_possible)
1783 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) {
1784 <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())
1786 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) {
1787 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
1791 /// Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
1792 pub extern "C" fn ChannelManager_write(obj: &ChannelManager) -> crate::c_types::derived::CVec_u8Z {
1793 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1796 pub(crate) extern "C" fn ChannelManager_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1797 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelManager) })
1800 use lightning::ln::channelmanager::ChannelManagerReadArgs as nativeChannelManagerReadArgsImport;
1801 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>;
1803 /// Arguments for the creation of a ChannelManager that are not deserialized.
1805 /// At a high-level, the process for deserializing a ChannelManager and resuming normal operation
1807 /// 1) Deserialize all stored ChannelMonitors.
1808 /// 2) Deserialize the ChannelManager by filling in this struct and calling:
1809 /// <(BlockHash, ChannelManager)>::read(reader, args)
1810 /// This may result in closing some Channels if the ChannelMonitor is newer than the stored
1811 /// ChannelManager state to ensure no loss of funds. Thus, transactions may be broadcasted.
1812 /// 3) If you are not fetching full blocks, register all relevant ChannelMonitor outpoints the same
1813 /// way you would handle a `chain::Filter` call using ChannelMonitor::get_outputs_to_watch() and
1814 /// ChannelMonitor::get_funding_txo().
1815 /// 4) Reconnect blocks on your ChannelMonitors.
1816 /// 5) Disconnect/connect blocks on the ChannelManager.
1817 /// 6) Move the ChannelMonitors into your local chain::Watch.
1819 /// Note that the ordering of #4-6 is not of importance, however all three must occur before you
1820 /// call any other methods on the newly-deserialized ChannelManager.
1822 /// Note that because some channels may be closed during deserialization, it is critical that you
1823 /// always deserialize only the latest version of a ChannelManager and ChannelMonitors available to
1824 /// you. If you deserialize an old ChannelManager (during which force-closure transactions may be
1825 /// broadcast), and then later deserialize a newer version of the same ChannelManager (which will
1826 /// not force-close the same channels but consider them live), you may end up revoking a state for
1827 /// which you've already broadcasted the transaction.
1830 pub struct ChannelManagerReadArgs {
1831 /// A pointer to the opaque Rust object.
1833 /// Nearly everywhere, inner must be non-null, however in places where
1834 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1835 pub inner: *mut nativeChannelManagerReadArgs,
1836 /// Indicates that this is the only struct which contains the same pointer.
1838 /// Rust functions which take ownership of an object provided via an argument require
1839 /// this to be true and invalidate the object pointed to by inner.
1843 impl Drop for ChannelManagerReadArgs {
1844 fn drop(&mut self) {
1845 if self.is_owned && !<*mut nativeChannelManagerReadArgs>::is_null(self.inner) {
1846 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1850 /// Frees any resources used by the ChannelManagerReadArgs, if is_owned is set and inner is non-NULL.
1852 pub extern "C" fn ChannelManagerReadArgs_free(this_obj: ChannelManagerReadArgs) { }
1854 /// Used only if an object of this type is returned as a trait impl by a method
1855 extern "C" fn ChannelManagerReadArgs_free_void(this_ptr: *mut c_void) {
1856 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManagerReadArgs); }
1859 impl ChannelManagerReadArgs {
1860 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManagerReadArgs {
1861 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1863 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManagerReadArgs {
1864 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1866 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1867 pub(crate) fn take_inner(mut self) -> *mut nativeChannelManagerReadArgs {
1868 assert!(self.is_owned);
1869 let ret = ObjOps::untweak_ptr(self.inner);
1870 self.inner = std::ptr::null_mut();
1874 /// The keys provider which will give us relevant keys. Some keys will be loaded during
1875 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
1878 pub extern "C" fn ChannelManagerReadArgs_get_keys_manager(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::keysinterface::KeysInterface {
1879 let mut inner_val = &mut this_ptr.get_native_mut_ref().keys_manager;
1882 /// The keys provider which will give us relevant keys. Some keys will be loaded during
1883 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
1886 pub extern "C" fn ChannelManagerReadArgs_set_keys_manager(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::keysinterface::KeysInterface) {
1887 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.keys_manager = val;
1889 /// The fee_estimator for use in the ChannelManager in the future.
1891 /// No calls to the FeeEstimator will be made during deserialization.
1893 pub extern "C" fn ChannelManagerReadArgs_get_fee_estimator(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::FeeEstimator {
1894 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_estimator;
1897 /// The fee_estimator for use in the ChannelManager in the future.
1899 /// No calls to the FeeEstimator will be made during deserialization.
1901 pub extern "C" fn ChannelManagerReadArgs_set_fee_estimator(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::FeeEstimator) {
1902 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_estimator = val;
1904 /// The chain::Watch for use in the ChannelManager in the future.
1906 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
1907 /// you have deserialized ChannelMonitors separately and will add them to your
1908 /// chain::Watch after deserializing this ChannelManager.
1910 pub extern "C" fn ChannelManagerReadArgs_get_chain_monitor(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::Watch {
1911 let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_monitor;
1914 /// The chain::Watch for use in the ChannelManager in the future.
1916 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
1917 /// you have deserialized ChannelMonitors separately and will add them to your
1918 /// chain::Watch after deserializing this ChannelManager.
1920 pub extern "C" fn ChannelManagerReadArgs_set_chain_monitor(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::Watch) {
1921 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_monitor = val;
1923 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
1924 /// used to broadcast the latest local commitment transactions of channels which must be
1925 /// force-closed during deserialization.
1927 pub extern "C" fn ChannelManagerReadArgs_get_tx_broadcaster(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::BroadcasterInterface {
1928 let mut inner_val = &mut this_ptr.get_native_mut_ref().tx_broadcaster;
1931 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
1932 /// used to broadcast the latest local commitment transactions of channels which must be
1933 /// force-closed during deserialization.
1935 pub extern "C" fn ChannelManagerReadArgs_set_tx_broadcaster(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::BroadcasterInterface) {
1936 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.tx_broadcaster = val;
1938 /// The Logger for use in the ChannelManager and which may be used to log information during
1939 /// deserialization.
1941 pub extern "C" fn ChannelManagerReadArgs_get_logger(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::util::logger::Logger {
1942 let mut inner_val = &mut this_ptr.get_native_mut_ref().logger;
1945 /// The Logger for use in the ChannelManager and which may be used to log information during
1946 /// deserialization.
1948 pub extern "C" fn ChannelManagerReadArgs_set_logger(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::logger::Logger) {
1949 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.logger = val;
1951 /// Default settings used for new channels. Any existing channels will continue to use the
1952 /// runtime settings which were stored when the ChannelManager was serialized.
1954 pub extern "C" fn ChannelManagerReadArgs_get_default_config(this_ptr: &ChannelManagerReadArgs) -> crate::lightning::util::config::UserConfig {
1955 let mut inner_val = &mut this_ptr.get_native_mut_ref().default_config;
1956 crate::lightning::util::config::UserConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
1958 /// Default settings used for new channels. Any existing channels will continue to use the
1959 /// runtime settings which were stored when the ChannelManager was serialized.
1961 pub extern "C" fn ChannelManagerReadArgs_set_default_config(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::config::UserConfig) {
1962 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.default_config = *unsafe { Box::from_raw(val.take_inner()) };
1964 /// Simple utility function to create a ChannelManagerReadArgs which creates the monitor
1965 /// HashMap for you. This is primarily useful for C bindings where it is not practical to
1966 /// populate a HashMap directly from C.
1969 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 {
1970 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() }); };
1971 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);
1972 ChannelManagerReadArgs { inner: ObjOps::heap_alloc(ret), is_owned: true }
1976 /// Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_write
1977 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 {
1978 let arg_conv = *unsafe { Box::from_raw(arg.take_inner()) };
1979 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);
1980 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() };