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::PaymentId as nativePaymentIdImport;
28 type nativePaymentId = nativePaymentIdImport;
30 /// A payment identifier used to uniquely identify a payment to LDK.
33 pub struct PaymentId {
34 /// A pointer to the opaque Rust object.
36 /// Nearly everywhere, inner must be non-null, however in places where
37 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
38 pub inner: *mut nativePaymentId,
39 /// Indicates that this is the only struct which contains the same pointer.
41 /// Rust functions which take ownership of an object provided via an argument require
42 /// this to be true and invalidate the object pointed to by inner.
46 impl Drop for PaymentId {
48 if self.is_owned && !<*mut nativePaymentId>::is_null(self.inner) {
49 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
53 /// Frees any resources used by the PaymentId, if is_owned is set and inner is non-NULL.
55 pub extern "C" fn PaymentId_free(this_obj: PaymentId) { }
57 /// Used only if an object of this type is returned as a trait impl by a method
58 extern "C" fn PaymentId_free_void(this_ptr: *mut c_void) {
59 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePaymentId); }
63 pub(crate) fn get_native_ref(&self) -> &'static nativePaymentId {
64 unsafe { &*ObjOps::untweak_ptr(self.inner) }
66 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePaymentId {
67 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
69 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
70 pub(crate) fn take_inner(mut self) -> *mut nativePaymentId {
71 assert!(self.is_owned);
72 let ret = ObjOps::untweak_ptr(self.inner);
73 self.inner = std::ptr::null_mut();
77 /// Checks if two PaymentIds contain equal inner contents.
79 pub extern "C" fn PaymentId_hash(o: &PaymentId) -> u64 {
80 if o.inner.is_null() { return 0; }
81 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
83 let mut hasher = core::hash::SipHasher::new();
84 std::hash::Hash::hash(o.get_native_ref(), &mut hasher);
85 std::hash::Hasher::finish(&hasher)
87 impl Clone for PaymentId {
88 fn clone(&self) -> Self {
90 inner: if <*mut nativePaymentId>::is_null(self.inner) { std::ptr::null_mut() } else {
91 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
97 /// Used only if an object of this type is returned as a trait impl by a method
98 pub(crate) extern "C" fn PaymentId_clone_void(this_ptr: *const c_void) -> *mut c_void {
99 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePaymentId)).clone() })) as *mut c_void
102 /// Creates a copy of the PaymentId
103 pub extern "C" fn PaymentId_clone(orig: &PaymentId) -> PaymentId {
106 /// Checks if two PaymentIds contain equal inner contents.
107 /// This ignores pointers and is_owned flags and looks at the values in fields.
108 /// Two objects with NULL inner values will be considered "equal" here.
110 pub extern "C" fn PaymentId_eq(a: &PaymentId, b: &PaymentId) -> bool {
111 if a.inner == b.inner { return true; }
112 if a.inner.is_null() || b.inner.is_null() { return false; }
113 if a.get_native_ref() == b.get_native_ref() { true } else { false }
116 /// Serialize the PaymentId object into a byte array which can be read by PaymentId_read
117 pub extern "C" fn PaymentId_write(obj: &PaymentId) -> crate::c_types::derived::CVec_u8Z {
118 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
121 pub(crate) extern "C" fn PaymentId_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
122 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePaymentId) })
125 /// Read a PaymentId from a byte array, created by PaymentId_write
126 pub extern "C" fn PaymentId_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PaymentIdDecodeErrorZ {
127 let res = crate::c_types::deserialize_obj(ser);
128 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channelmanager::PaymentId { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
132 use lightning::ln::channelmanager::ChannelManager as nativeChannelManagerImport;
133 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>;
135 /// Manager which keeps track of a number of channels and sends messages to the appropriate
136 /// channel, also tracking HTLC preimages and forwarding onion packets appropriately.
138 /// Implements ChannelMessageHandler, handling the multi-channel parts and passing things through
139 /// to individual Channels.
141 /// Implements Writeable to write out all channel state to disk. Implies peer_disconnected() for
142 /// all peers during write/read (though does not modify this instance, only the instance being
143 /// serialized). This will result in any channels which have not yet exchanged funding_created (ie
144 /// called funding_transaction_generated for outbound channels).
146 /// Note that you can be a bit lazier about writing out ChannelManager than you can be with
147 /// ChannelMonitors. With ChannelMonitors you MUST write each monitor update out to disk before
148 /// returning from chain::Watch::watch_/update_channel, with ChannelManagers, writing updates
149 /// happens out-of-band (and will prevent any other ChannelManager operations from occurring during
150 /// the serialization process). If the deserialized version is out-of-date compared to the
151 /// ChannelMonitors passed by reference to read(), those channels will be force-closed based on the
152 /// ChannelMonitor state and no funds will be lost (mod on-chain transaction fees).
154 /// Note that the deserializer is only implemented for (BlockHash, ChannelManager), which
155 /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
156 /// the \"reorg path\" (ie call block_disconnected() until you get to a common block and then call
157 /// block_connected() to step towards your best block) upon deserialization before using the
160 /// Note that ChannelManager is responsible for tracking liveness of its channels and generating
161 /// ChannelUpdate messages informing peers that the channel is temporarily disabled. To avoid
162 /// spam due to quick disconnection/reconnection, updates are not sent until the channel has been
163 /// offline for a full minute. In order to track this, you must call
164 /// timer_tick_occurred roughly once per minute, though it doesn't have to be perfect.
166 /// Rather than using a plain ChannelManager, it is preferable to use either a SimpleArcChannelManager
167 /// a SimpleRefChannelManager, for conciseness. See their documentation for more details, but
168 /// essentially you should default to using a SimpleRefChannelManager, and use a
169 /// SimpleArcChannelManager when you require a ChannelManager with a static lifetime, such as when
170 /// you're using lightning-net-tokio.
173 pub struct ChannelManager {
174 /// A pointer to the opaque Rust object.
176 /// Nearly everywhere, inner must be non-null, however in places where
177 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
178 pub inner: *mut nativeChannelManager,
179 /// Indicates that this is the only struct which contains the same pointer.
181 /// Rust functions which take ownership of an object provided via an argument require
182 /// this to be true and invalidate the object pointed to by inner.
186 impl Drop for ChannelManager {
188 if self.is_owned && !<*mut nativeChannelManager>::is_null(self.inner) {
189 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
193 /// Frees any resources used by the ChannelManager, if is_owned is set and inner is non-NULL.
195 pub extern "C" fn ChannelManager_free(this_obj: ChannelManager) { }
197 /// Used only if an object of this type is returned as a trait impl by a method
198 extern "C" fn ChannelManager_free_void(this_ptr: *mut c_void) {
199 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManager); }
202 impl ChannelManager {
203 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManager {
204 unsafe { &*ObjOps::untweak_ptr(self.inner) }
206 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManager {
207 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
209 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
210 pub(crate) fn take_inner(mut self) -> *mut nativeChannelManager {
211 assert!(self.is_owned);
212 let ret = ObjOps::untweak_ptr(self.inner);
213 self.inner = std::ptr::null_mut();
218 use lightning::ln::channelmanager::ChainParameters as nativeChainParametersImport;
219 type nativeChainParameters = nativeChainParametersImport;
221 /// Chain-related parameters used to construct a new `ChannelManager`.
223 /// Typically, the block-specific parameters are derived from the best block hash for the network,
224 /// as a newly constructed `ChannelManager` will not have created any channels yet. These parameters
225 /// are not needed when deserializing a previously constructed `ChannelManager`.
228 pub struct ChainParameters {
229 /// A pointer to the opaque Rust object.
231 /// Nearly everywhere, inner must be non-null, however in places where
232 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
233 pub inner: *mut nativeChainParameters,
234 /// Indicates that this is the only struct which contains the same pointer.
236 /// Rust functions which take ownership of an object provided via an argument require
237 /// this to be true and invalidate the object pointed to by inner.
241 impl Drop for ChainParameters {
243 if self.is_owned && !<*mut nativeChainParameters>::is_null(self.inner) {
244 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
248 /// Frees any resources used by the ChainParameters, if is_owned is set and inner is non-NULL.
250 pub extern "C" fn ChainParameters_free(this_obj: ChainParameters) { }
252 /// Used only if an object of this type is returned as a trait impl by a method
253 extern "C" fn ChainParameters_free_void(this_ptr: *mut c_void) {
254 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChainParameters); }
257 impl ChainParameters {
258 pub(crate) fn get_native_ref(&self) -> &'static nativeChainParameters {
259 unsafe { &*ObjOps::untweak_ptr(self.inner) }
261 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChainParameters {
262 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
264 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
265 pub(crate) fn take_inner(mut self) -> *mut nativeChainParameters {
266 assert!(self.is_owned);
267 let ret = ObjOps::untweak_ptr(self.inner);
268 self.inner = std::ptr::null_mut();
272 /// The network for determining the `chain_hash` in Lightning messages.
274 pub extern "C" fn ChainParameters_get_network(this_ptr: &ChainParameters) -> crate::bitcoin::network::Network {
275 let mut inner_val = &mut this_ptr.get_native_mut_ref().network;
276 crate::bitcoin::network::Network::from_bitcoin(inner_val)
278 /// The network for determining the `chain_hash` in Lightning messages.
280 pub extern "C" fn ChainParameters_set_network(this_ptr: &mut ChainParameters, mut val: crate::bitcoin::network::Network) {
281 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.network = val.into_bitcoin();
283 /// The hash and height of the latest block successfully connected.
285 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
287 pub extern "C" fn ChainParameters_get_best_block(this_ptr: &ChainParameters) -> crate::lightning::chain::BestBlock {
288 let mut inner_val = &mut this_ptr.get_native_mut_ref().best_block;
289 crate::lightning::chain::BestBlock { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
291 /// The hash and height of the latest block successfully connected.
293 /// Used to track on-chain channel funding outputs and send payments with reliable timelocks.
295 pub extern "C" fn ChainParameters_set_best_block(this_ptr: &mut ChainParameters, mut val: crate::lightning::chain::BestBlock) {
296 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.best_block = *unsafe { Box::from_raw(val.take_inner()) };
298 /// Constructs a new ChainParameters given each field
301 pub extern "C" fn ChainParameters_new(mut network_arg: crate::bitcoin::network::Network, mut best_block_arg: crate::lightning::chain::BestBlock) -> ChainParameters {
302 ChainParameters { inner: ObjOps::heap_alloc(nativeChainParameters {
303 network: network_arg.into_bitcoin(),
304 best_block: *unsafe { Box::from_raw(best_block_arg.take_inner()) },
307 impl Clone for ChainParameters {
308 fn clone(&self) -> Self {
310 inner: if <*mut nativeChainParameters>::is_null(self.inner) { std::ptr::null_mut() } else {
311 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
317 /// Used only if an object of this type is returned as a trait impl by a method
318 pub(crate) extern "C" fn ChainParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
319 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChainParameters)).clone() })) as *mut c_void
322 /// Creates a copy of the ChainParameters
323 pub extern "C" fn ChainParameters_clone(orig: &ChainParameters) -> ChainParameters {
326 /// The amount of time in blocks we require our counterparty wait to claim their money (ie time
327 /// between when we, or our watchtower, must check for them having broadcast a theft transaction).
329 /// This can be increased (but not decreased) through [`ChannelHandshakeConfig::our_to_self_delay`]
331 /// [`ChannelHandshakeConfig::our_to_self_delay`]: crate::util::config::ChannelHandshakeConfig::our_to_self_delay
334 pub static BREAKDOWN_TIMEOUT: u16 = lightning::ln::channelmanager::BREAKDOWN_TIMEOUT;
335 /// The minimum number of blocks between an inbound HTLC's CLTV and the corresponding outbound
336 /// HTLC's CLTV. The current default represents roughly seven hours of blocks at six blocks/hour.
338 /// This can be increased (but not decreased) through [`ChannelConfig::cltv_expiry_delta`]
340 /// [`ChannelConfig::cltv_expiry_delta`]: crate::util::config::ChannelConfig::cltv_expiry_delta
343 pub static MIN_CLTV_EXPIRY_DELTA: u16 = lightning::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA;
344 /// Minimum CLTV difference between the current block height and received inbound payments.
345 /// Invoices generated for payment to us must set their `min_final_cltv_expiry` field to at least
349 pub static MIN_FINAL_CLTV_EXPIRY: u32 = lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY;
351 use lightning::ln::channelmanager::CounterpartyForwardingInfo as nativeCounterpartyForwardingInfoImport;
352 type nativeCounterpartyForwardingInfo = nativeCounterpartyForwardingInfoImport;
354 /// Information needed for constructing an invoice route hint for this channel.
357 pub struct CounterpartyForwardingInfo {
358 /// A pointer to the opaque Rust object.
360 /// Nearly everywhere, inner must be non-null, however in places where
361 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
362 pub inner: *mut nativeCounterpartyForwardingInfo,
363 /// Indicates that this is the only struct which contains the same pointer.
365 /// Rust functions which take ownership of an object provided via an argument require
366 /// this to be true and invalidate the object pointed to by inner.
370 impl Drop for CounterpartyForwardingInfo {
372 if self.is_owned && !<*mut nativeCounterpartyForwardingInfo>::is_null(self.inner) {
373 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
377 /// Frees any resources used by the CounterpartyForwardingInfo, if is_owned is set and inner is non-NULL.
379 pub extern "C" fn CounterpartyForwardingInfo_free(this_obj: CounterpartyForwardingInfo) { }
381 /// Used only if an object of this type is returned as a trait impl by a method
382 extern "C" fn CounterpartyForwardingInfo_free_void(this_ptr: *mut c_void) {
383 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCounterpartyForwardingInfo); }
386 impl CounterpartyForwardingInfo {
387 pub(crate) fn get_native_ref(&self) -> &'static nativeCounterpartyForwardingInfo {
388 unsafe { &*ObjOps::untweak_ptr(self.inner) }
390 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCounterpartyForwardingInfo {
391 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
393 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
394 pub(crate) fn take_inner(mut self) -> *mut nativeCounterpartyForwardingInfo {
395 assert!(self.is_owned);
396 let ret = ObjOps::untweak_ptr(self.inner);
397 self.inner = std::ptr::null_mut();
401 /// Base routing fee in millisatoshis.
403 pub extern "C" fn CounterpartyForwardingInfo_get_fee_base_msat(this_ptr: &CounterpartyForwardingInfo) -> u32 {
404 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_base_msat;
407 /// Base routing fee in millisatoshis.
409 pub extern "C" fn CounterpartyForwardingInfo_set_fee_base_msat(this_ptr: &mut CounterpartyForwardingInfo, mut val: u32) {
410 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_base_msat = val;
412 /// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
414 pub extern "C" fn CounterpartyForwardingInfo_get_fee_proportional_millionths(this_ptr: &CounterpartyForwardingInfo) -> u32 {
415 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_proportional_millionths;
418 /// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
420 pub extern "C" fn CounterpartyForwardingInfo_set_fee_proportional_millionths(this_ptr: &mut CounterpartyForwardingInfo, mut val: u32) {
421 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_proportional_millionths = val;
423 /// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
424 /// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
425 /// `cltv_expiry_delta` for more details.
427 pub extern "C" fn CounterpartyForwardingInfo_get_cltv_expiry_delta(this_ptr: &CounterpartyForwardingInfo) -> u16 {
428 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
431 /// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
432 /// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
433 /// `cltv_expiry_delta` for more details.
435 pub extern "C" fn CounterpartyForwardingInfo_set_cltv_expiry_delta(this_ptr: &mut CounterpartyForwardingInfo, mut val: u16) {
436 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
438 /// Constructs a new CounterpartyForwardingInfo given each field
441 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 {
442 CounterpartyForwardingInfo { inner: ObjOps::heap_alloc(nativeCounterpartyForwardingInfo {
443 fee_base_msat: fee_base_msat_arg,
444 fee_proportional_millionths: fee_proportional_millionths_arg,
445 cltv_expiry_delta: cltv_expiry_delta_arg,
448 impl Clone for CounterpartyForwardingInfo {
449 fn clone(&self) -> Self {
451 inner: if <*mut nativeCounterpartyForwardingInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
452 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
458 /// Used only if an object of this type is returned as a trait impl by a method
459 pub(crate) extern "C" fn CounterpartyForwardingInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
460 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCounterpartyForwardingInfo)).clone() })) as *mut c_void
463 /// Creates a copy of the CounterpartyForwardingInfo
464 pub extern "C" fn CounterpartyForwardingInfo_clone(orig: &CounterpartyForwardingInfo) -> CounterpartyForwardingInfo {
468 use lightning::ln::channelmanager::ChannelCounterparty as nativeChannelCounterpartyImport;
469 type nativeChannelCounterparty = nativeChannelCounterpartyImport;
471 /// Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
472 /// to better separate parameters.
475 pub struct ChannelCounterparty {
476 /// A pointer to the opaque Rust object.
478 /// Nearly everywhere, inner must be non-null, however in places where
479 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
480 pub inner: *mut nativeChannelCounterparty,
481 /// Indicates that this is the only struct which contains the same pointer.
483 /// Rust functions which take ownership of an object provided via an argument require
484 /// this to be true and invalidate the object pointed to by inner.
488 impl Drop for ChannelCounterparty {
490 if self.is_owned && !<*mut nativeChannelCounterparty>::is_null(self.inner) {
491 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
495 /// Frees any resources used by the ChannelCounterparty, if is_owned is set and inner is non-NULL.
497 pub extern "C" fn ChannelCounterparty_free(this_obj: ChannelCounterparty) { }
499 /// Used only if an object of this type is returned as a trait impl by a method
500 extern "C" fn ChannelCounterparty_free_void(this_ptr: *mut c_void) {
501 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelCounterparty); }
504 impl ChannelCounterparty {
505 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelCounterparty {
506 unsafe { &*ObjOps::untweak_ptr(self.inner) }
508 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelCounterparty {
509 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
511 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
512 pub(crate) fn take_inner(mut self) -> *mut nativeChannelCounterparty {
513 assert!(self.is_owned);
514 let ret = ObjOps::untweak_ptr(self.inner);
515 self.inner = std::ptr::null_mut();
519 /// The node_id of our counterparty
521 pub extern "C" fn ChannelCounterparty_get_node_id(this_ptr: &ChannelCounterparty) -> crate::c_types::PublicKey {
522 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_id;
523 crate::c_types::PublicKey::from_rust(&inner_val)
525 /// The node_id of our counterparty
527 pub extern "C" fn ChannelCounterparty_set_node_id(this_ptr: &mut ChannelCounterparty, mut val: crate::c_types::PublicKey) {
528 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_id = val.into_rust();
530 /// The Features the channel counterparty provided upon last connection.
531 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
532 /// many routing-relevant features are present in the init context.
534 pub extern "C" fn ChannelCounterparty_get_features(this_ptr: &ChannelCounterparty) -> crate::lightning::ln::features::InitFeatures {
535 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
536 crate::lightning::ln::features::InitFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
538 /// The Features the channel counterparty provided upon last connection.
539 /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
540 /// many routing-relevant features are present in the init context.
542 pub extern "C" fn ChannelCounterparty_set_features(this_ptr: &mut ChannelCounterparty, mut val: crate::lightning::ln::features::InitFeatures) {
543 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
545 /// The value, in satoshis, that must always be held in the channel for our counterparty. This
546 /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
547 /// claiming at least this value on chain.
549 /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
551 /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
553 pub extern "C" fn ChannelCounterparty_get_unspendable_punishment_reserve(this_ptr: &ChannelCounterparty) -> u64 {
554 let mut inner_val = &mut this_ptr.get_native_mut_ref().unspendable_punishment_reserve;
557 /// The value, in satoshis, that must always be held in the channel for our counterparty. This
558 /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
559 /// claiming at least this value on chain.
561 /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
563 /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
565 pub extern "C" fn ChannelCounterparty_set_unspendable_punishment_reserve(this_ptr: &mut ChannelCounterparty, mut val: u64) {
566 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = val;
568 /// Information on the fees and requirements that the counterparty requires when forwarding
569 /// payments to us through this channel.
571 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
573 pub extern "C" fn ChannelCounterparty_get_forwarding_info(this_ptr: &ChannelCounterparty) -> crate::lightning::ln::channelmanager::CounterpartyForwardingInfo {
574 let mut inner_val = &mut this_ptr.get_native_mut_ref().forwarding_info;
575 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 };
578 /// Information on the fees and requirements that the counterparty requires when forwarding
579 /// payments to us through this channel.
581 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
583 pub extern "C" fn ChannelCounterparty_set_forwarding_info(this_ptr: &mut ChannelCounterparty, mut val: crate::lightning::ln::channelmanager::CounterpartyForwardingInfo) {
584 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
585 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.forwarding_info = local_val;
587 /// Constructs a new ChannelCounterparty given each field
590 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 {
591 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()) } }) };
592 ChannelCounterparty { inner: ObjOps::heap_alloc(nativeChannelCounterparty {
593 node_id: node_id_arg.into_rust(),
594 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
595 unspendable_punishment_reserve: unspendable_punishment_reserve_arg,
596 forwarding_info: local_forwarding_info_arg,
599 impl Clone for ChannelCounterparty {
600 fn clone(&self) -> Self {
602 inner: if <*mut nativeChannelCounterparty>::is_null(self.inner) { std::ptr::null_mut() } else {
603 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
609 /// Used only if an object of this type is returned as a trait impl by a method
610 pub(crate) extern "C" fn ChannelCounterparty_clone_void(this_ptr: *const c_void) -> *mut c_void {
611 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelCounterparty)).clone() })) as *mut c_void
614 /// Creates a copy of the ChannelCounterparty
615 pub extern "C" fn ChannelCounterparty_clone(orig: &ChannelCounterparty) -> ChannelCounterparty {
619 use lightning::ln::channelmanager::ChannelDetails as nativeChannelDetailsImport;
620 type nativeChannelDetails = nativeChannelDetailsImport;
622 /// Details of a channel, as returned by ChannelManager::list_channels and ChannelManager::list_usable_channels
625 pub struct ChannelDetails {
626 /// A pointer to the opaque Rust object.
628 /// Nearly everywhere, inner must be non-null, however in places where
629 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
630 pub inner: *mut nativeChannelDetails,
631 /// Indicates that this is the only struct which contains the same pointer.
633 /// Rust functions which take ownership of an object provided via an argument require
634 /// this to be true and invalidate the object pointed to by inner.
638 impl Drop for ChannelDetails {
640 if self.is_owned && !<*mut nativeChannelDetails>::is_null(self.inner) {
641 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
645 /// Frees any resources used by the ChannelDetails, if is_owned is set and inner is non-NULL.
647 pub extern "C" fn ChannelDetails_free(this_obj: ChannelDetails) { }
649 /// Used only if an object of this type is returned as a trait impl by a method
650 extern "C" fn ChannelDetails_free_void(this_ptr: *mut c_void) {
651 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelDetails); }
654 impl ChannelDetails {
655 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelDetails {
656 unsafe { &*ObjOps::untweak_ptr(self.inner) }
658 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelDetails {
659 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
661 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
662 pub(crate) fn take_inner(mut self) -> *mut nativeChannelDetails {
663 assert!(self.is_owned);
664 let ret = ObjOps::untweak_ptr(self.inner);
665 self.inner = std::ptr::null_mut();
669 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
670 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
671 /// Note that this means this value is *not* persistent - it can change once during the
672 /// lifetime of the channel.
674 pub extern "C" fn ChannelDetails_get_channel_id(this_ptr: &ChannelDetails) -> *const [u8; 32] {
675 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id;
678 /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
679 /// thereafter this is the txid of the funding transaction xor the funding transaction output).
680 /// Note that this means this value is *not* persistent - it can change once during the
681 /// lifetime of the channel.
683 pub extern "C" fn ChannelDetails_set_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::ThirtyTwoBytes) {
684 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = val.data;
686 /// Parameters which apply to our counterparty. See individual fields for more information.
688 pub extern "C" fn ChannelDetails_get_counterparty(this_ptr: &ChannelDetails) -> crate::lightning::ln::channelmanager::ChannelCounterparty {
689 let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty;
690 crate::lightning::ln::channelmanager::ChannelCounterparty { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
692 /// Parameters which apply to our counterparty. See individual fields for more information.
694 pub extern "C" fn ChannelDetails_set_counterparty(this_ptr: &mut ChannelDetails, mut val: crate::lightning::ln::channelmanager::ChannelCounterparty) {
695 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty = *unsafe { Box::from_raw(val.take_inner()) };
697 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
698 /// our counterparty already.
700 /// Note that, if this has been set, `channel_id` will be equivalent to
701 /// `funding_txo.unwrap().to_channel_id()`.
703 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
705 pub extern "C" fn ChannelDetails_get_funding_txo(this_ptr: &ChannelDetails) -> crate::lightning::chain::transaction::OutPoint {
706 let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_txo;
707 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 };
710 /// The Channel's funding transaction output, if we've negotiated the funding transaction with
711 /// our counterparty already.
713 /// Note that, if this has been set, `channel_id` will be equivalent to
714 /// `funding_txo.unwrap().to_channel_id()`.
716 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
718 pub extern "C" fn ChannelDetails_set_funding_txo(this_ptr: &mut ChannelDetails, mut val: crate::lightning::chain::transaction::OutPoint) {
719 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
720 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_txo = local_val;
722 /// The position of the funding transaction in the chain. None if the funding transaction has
723 /// not yet been confirmed and the channel fully opened.
725 pub extern "C" fn ChannelDetails_get_short_channel_id(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
726 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
727 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() }) };
730 /// The position of the funding transaction in the chain. None if the funding transaction has
731 /// not yet been confirmed and the channel fully opened.
733 pub extern "C" fn ChannelDetails_set_short_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
734 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
735 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = local_val;
737 /// The value, in satoshis, of this channel as appears in the funding output
739 pub extern "C" fn ChannelDetails_get_channel_value_satoshis(this_ptr: &ChannelDetails) -> u64 {
740 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
743 /// The value, in satoshis, of this channel as appears in the funding output
745 pub extern "C" fn ChannelDetails_set_channel_value_satoshis(this_ptr: &mut ChannelDetails, mut val: u64) {
746 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
748 /// The value, in satoshis, that must always be held in the channel for us. This value ensures
749 /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
750 /// this value on chain.
752 /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
754 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
756 /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
758 pub extern "C" fn ChannelDetails_get_unspendable_punishment_reserve(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
759 let mut inner_val = &mut this_ptr.get_native_mut_ref().unspendable_punishment_reserve;
760 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() }) };
763 /// The value, in satoshis, that must always be held in the channel for us. This value ensures
764 /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
765 /// this value on chain.
767 /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
769 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
771 /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
773 pub extern "C" fn ChannelDetails_set_unspendable_punishment_reserve(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
774 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
775 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.unspendable_punishment_reserve = local_val;
777 /// The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound.
779 pub extern "C" fn ChannelDetails_get_user_channel_id(this_ptr: &ChannelDetails) -> u64 {
780 let mut inner_val = &mut this_ptr.get_native_mut_ref().user_channel_id;
783 /// The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound.
785 pub extern "C" fn ChannelDetails_set_user_channel_id(this_ptr: &mut ChannelDetails, mut val: u64) {
786 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.user_channel_id = val;
788 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
789 /// any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
790 /// available for inclusion in new outbound HTLCs). This further does not include any pending
791 /// outgoing HTLCs which are awaiting some other resolution to be sent.
793 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
794 /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
795 /// should be able to spend nearly this amount.
797 pub extern "C" fn ChannelDetails_get_outbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
798 let mut inner_val = &mut this_ptr.get_native_mut_ref().outbound_capacity_msat;
801 /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
802 /// any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
803 /// available for inclusion in new outbound HTLCs). This further does not include any pending
804 /// outgoing HTLCs which are awaiting some other resolution to be sent.
806 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
807 /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
808 /// should be able to spend nearly this amount.
810 pub extern "C" fn ChannelDetails_set_outbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
811 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outbound_capacity_msat = val;
813 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
814 /// include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
815 /// available for inclusion in new inbound HTLCs).
816 /// Note that there are some corner cases not fully handled here, so the actual available
817 /// inbound capacity may be slightly higher than this.
819 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
820 /// counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
821 /// However, our counterparty should be able to spend nearly this amount.
823 pub extern "C" fn ChannelDetails_get_inbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 {
824 let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_capacity_msat;
827 /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
828 /// include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
829 /// available for inclusion in new inbound HTLCs).
830 /// Note that there are some corner cases not fully handled here, so the actual available
831 /// inbound capacity may be slightly higher than this.
833 /// This value is not exact. Due to various in-flight changes, feerate changes, and our
834 /// counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
835 /// However, our counterparty should be able to spend nearly this amount.
837 pub extern "C" fn ChannelDetails_set_inbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) {
838 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_capacity_msat = val;
840 /// The number of required confirmations on the funding transaction before the funding will be
841 /// considered \"locked\". This number is selected by the channel fundee (i.e. us if
842 /// [`is_outbound`] is *not* set), and can be selected for inbound channels with
843 /// [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
844 /// [`ChannelHandshakeLimits::max_minimum_depth`].
846 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
848 /// [`is_outbound`]: ChannelDetails::is_outbound
849 /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
850 /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
852 pub extern "C" fn ChannelDetails_get_confirmations_required(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u32Z {
853 let mut inner_val = &mut this_ptr.get_native_mut_ref().confirmations_required;
854 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() }) };
857 /// The number of required confirmations on the funding transaction before the funding will be
858 /// considered \"locked\". This number is selected by the channel fundee (i.e. us if
859 /// [`is_outbound`] is *not* set), and can be selected for inbound channels with
860 /// [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
861 /// [`ChannelHandshakeLimits::max_minimum_depth`].
863 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
865 /// [`is_outbound`]: ChannelDetails::is_outbound
866 /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
867 /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
869 pub extern "C" fn ChannelDetails_set_confirmations_required(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u32Z) {
870 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
871 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.confirmations_required = local_val;
873 /// The number of blocks (after our commitment transaction confirms) that we will need to wait
874 /// until we can claim our funds after we force-close the channel. During this time our
875 /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
876 /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any
877 /// time to claim our non-HTLC-encumbered funds.
879 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
881 pub extern "C" fn ChannelDetails_get_force_close_spend_delay(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u16Z {
882 let mut inner_val = &mut this_ptr.get_native_mut_ref().force_close_spend_delay;
883 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() }) };
886 /// The number of blocks (after our commitment transaction confirms) that we will need to wait
887 /// until we can claim our funds after we force-close the channel. During this time our
888 /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
889 /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any
890 /// time to claim our non-HTLC-encumbered funds.
892 /// This value will be `None` for outbound channels until the counterparty accepts the channel.
894 pub extern "C" fn ChannelDetails_set_force_close_spend_delay(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u16Z) {
895 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
896 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.force_close_spend_delay = local_val;
898 /// True if the channel was initiated (and thus funded) by us.
900 pub extern "C" fn ChannelDetails_get_is_outbound(this_ptr: &ChannelDetails) -> bool {
901 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_outbound;
904 /// True if the channel was initiated (and thus funded) by us.
906 pub extern "C" fn ChannelDetails_set_is_outbound(this_ptr: &mut ChannelDetails, mut val: bool) {
907 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_outbound = val;
909 /// True if the channel is confirmed, funding_locked messages have been exchanged, and the
910 /// channel is not currently being shut down. `funding_locked` message exchange implies the
911 /// required confirmation count has been reached (and we were connected to the peer at some
912 /// point after the funding transaction received enough confirmations). The required
913 /// confirmation count is provided in [`confirmations_required`].
915 /// [`confirmations_required`]: ChannelDetails::confirmations_required
917 pub extern "C" fn ChannelDetails_get_is_funding_locked(this_ptr: &ChannelDetails) -> bool {
918 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_funding_locked;
921 /// True if the channel is confirmed, funding_locked messages have been exchanged, and the
922 /// channel is not currently being shut down. `funding_locked` message exchange implies the
923 /// required confirmation count has been reached (and we were connected to the peer at some
924 /// point after the funding transaction received enough confirmations). The required
925 /// confirmation count is provided in [`confirmations_required`].
927 /// [`confirmations_required`]: ChannelDetails::confirmations_required
929 pub extern "C" fn ChannelDetails_set_is_funding_locked(this_ptr: &mut ChannelDetails, mut val: bool) {
930 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_funding_locked = val;
932 /// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
933 /// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
935 /// This is a strict superset of `is_funding_locked`.
937 pub extern "C" fn ChannelDetails_get_is_usable(this_ptr: &ChannelDetails) -> bool {
938 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_usable;
941 /// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
942 /// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
944 /// This is a strict superset of `is_funding_locked`.
946 pub extern "C" fn ChannelDetails_set_is_usable(this_ptr: &mut ChannelDetails, mut val: bool) {
947 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_usable = val;
949 /// True if this channel is (or will be) publicly-announced.
951 pub extern "C" fn ChannelDetails_get_is_public(this_ptr: &ChannelDetails) -> bool {
952 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_public;
955 /// True if this channel is (or will be) publicly-announced.
957 pub extern "C" fn ChannelDetails_set_is_public(this_ptr: &mut ChannelDetails, mut val: bool) {
958 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_public = val;
960 /// Constructs a new ChannelDetails given each field
963 pub extern "C" fn ChannelDetails_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut counterparty_arg: crate::lightning::ln::channelmanager::ChannelCounterparty, mut funding_txo_arg: crate::lightning::chain::transaction::OutPoint, mut short_channel_id_arg: crate::c_types::derived::COption_u64Z, mut channel_value_satoshis_arg: u64, mut unspendable_punishment_reserve_arg: crate::c_types::derived::COption_u64Z, mut user_channel_id_arg: u64, mut outbound_capacity_msat_arg: u64, mut inbound_capacity_msat_arg: u64, mut confirmations_required_arg: crate::c_types::derived::COption_u32Z, mut force_close_spend_delay_arg: crate::c_types::derived::COption_u16Z, mut is_outbound_arg: bool, mut is_funding_locked_arg: bool, mut is_usable_arg: bool, mut is_public_arg: bool) -> ChannelDetails {
964 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()) } }) };
965 let mut local_short_channel_id_arg = if short_channel_id_arg.is_some() { Some( { short_channel_id_arg.take() }) } else { None };
966 let mut local_unspendable_punishment_reserve_arg = if unspendable_punishment_reserve_arg.is_some() { Some( { unspendable_punishment_reserve_arg.take() }) } else { None };
967 let mut local_confirmations_required_arg = if confirmations_required_arg.is_some() { Some( { confirmations_required_arg.take() }) } else { None };
968 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 };
969 ChannelDetails { inner: ObjOps::heap_alloc(nativeChannelDetails {
970 channel_id: channel_id_arg.data,
971 counterparty: *unsafe { Box::from_raw(counterparty_arg.take_inner()) },
972 funding_txo: local_funding_txo_arg,
973 short_channel_id: local_short_channel_id_arg,
974 channel_value_satoshis: channel_value_satoshis_arg,
975 unspendable_punishment_reserve: local_unspendable_punishment_reserve_arg,
976 user_channel_id: user_channel_id_arg,
977 outbound_capacity_msat: outbound_capacity_msat_arg,
978 inbound_capacity_msat: inbound_capacity_msat_arg,
979 confirmations_required: local_confirmations_required_arg,
980 force_close_spend_delay: local_force_close_spend_delay_arg,
981 is_outbound: is_outbound_arg,
982 is_funding_locked: is_funding_locked_arg,
983 is_usable: is_usable_arg,
984 is_public: is_public_arg,
987 impl Clone for ChannelDetails {
988 fn clone(&self) -> Self {
990 inner: if <*mut nativeChannelDetails>::is_null(self.inner) { std::ptr::null_mut() } else {
991 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
997 /// Used only if an object of this type is returned as a trait impl by a method
998 pub(crate) extern "C" fn ChannelDetails_clone_void(this_ptr: *const c_void) -> *mut c_void {
999 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelDetails)).clone() })) as *mut c_void
1002 /// Creates a copy of the ChannelDetails
1003 pub extern "C" fn ChannelDetails_clone(orig: &ChannelDetails) -> ChannelDetails {
1006 /// If a payment fails to send, it can be in one of several states. This enum is returned as the
1007 /// Err() type describing which state the payment is in, see the description of individual enum
1008 /// states for more.
1012 pub enum PaymentSendFailure {
1013 /// A parameter which was passed to send_payment was invalid, preventing us from attempting to
1014 /// send the payment at all. No channel state has been changed or messages sent to peers, and
1015 /// once you've changed the parameter at error, you can freely retry the payment in full.
1016 ParameterError(crate::lightning::util::errors::APIError),
1017 /// A parameter in a single path which was passed to send_payment was invalid, preventing us
1018 /// from attempting to send the payment at all. No channel state has been changed or messages
1019 /// sent to peers, and once you've changed the parameter at error, you can freely retry the
1020 /// payment in full.
1022 /// The results here are ordered the same as the paths in the route object which was passed to
1024 PathParameterError(crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ),
1025 /// All paths which were attempted failed to send, with no channel state change taking place.
1026 /// You can freely retry the payment in full (though you probably want to do so over different
1027 /// paths than the ones selected).
1028 AllFailedRetrySafe(crate::c_types::derived::CVec_APIErrorZ),
1029 /// Some paths which were attempted failed to send, though possibly not all. At least some
1030 /// paths have irrevocably committed to the HTLC and retrying the payment in full would result
1031 /// in over-/re-payment.
1033 /// The results here are ordered the same as the paths in the route object which was passed to
1034 /// send_payment, and any Errs which are not APIError::MonitorUpdateFailed can be safely
1035 /// retried (though there is currently no API with which to do so).
1037 /// Any entries which contain Err(APIError::MonitorUpdateFailed) or Ok(()) MUST NOT be retried
1038 /// as they will result in over-/re-payment. These HTLCs all either successfully sent (in the
1039 /// case of Ok(())) or will send once channel_monitor_updated is called on the next-hop channel
1040 /// with the latest update_id.
1041 PartialFailure(crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ),
1043 use lightning::ln::channelmanager::PaymentSendFailure as nativePaymentSendFailure;
1044 impl PaymentSendFailure {
1046 pub(crate) fn to_native(&self) -> nativePaymentSendFailure {
1048 PaymentSendFailure::ParameterError (ref a, ) => {
1049 let mut a_nonref = (*a).clone();
1050 nativePaymentSendFailure::ParameterError (
1051 a_nonref.into_native(),
1054 PaymentSendFailure::PathParameterError (ref a, ) => {
1055 let mut a_nonref = (*a).clone();
1056 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 }); };
1057 nativePaymentSendFailure::PathParameterError (
1061 PaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
1062 let mut a_nonref = (*a).clone();
1063 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { item.into_native() }); };
1064 nativePaymentSendFailure::AllFailedRetrySafe (
1068 PaymentSendFailure::PartialFailure (ref a, ) => {
1069 let mut a_nonref = (*a).clone();
1070 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 }); };
1071 nativePaymentSendFailure::PartialFailure (
1078 pub(crate) fn into_native(self) -> nativePaymentSendFailure {
1080 PaymentSendFailure::ParameterError (mut a, ) => {
1081 nativePaymentSendFailure::ParameterError (
1085 PaymentSendFailure::PathParameterError (mut a, ) => {
1086 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 }); };
1087 nativePaymentSendFailure::PathParameterError (
1091 PaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
1092 let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { item.into_native() }); };
1093 nativePaymentSendFailure::AllFailedRetrySafe (
1097 PaymentSendFailure::PartialFailure (mut a, ) => {
1098 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 }); };
1099 nativePaymentSendFailure::PartialFailure (
1106 pub(crate) fn from_native(native: &nativePaymentSendFailure) -> Self {
1108 nativePaymentSendFailure::ParameterError (ref a, ) => {
1109 let mut a_nonref = (*a).clone();
1110 PaymentSendFailure::ParameterError (
1111 crate::lightning::util::errors::APIError::native_into(a_nonref),
1114 nativePaymentSendFailure::PathParameterError (ref a, ) => {
1115 let mut a_nonref = (*a).clone();
1116 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 }); };
1117 PaymentSendFailure::PathParameterError (
1118 local_a_nonref.into(),
1121 nativePaymentSendFailure::AllFailedRetrySafe (ref a, ) => {
1122 let mut a_nonref = (*a).clone();
1123 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) }); };
1124 PaymentSendFailure::AllFailedRetrySafe (
1125 local_a_nonref.into(),
1128 nativePaymentSendFailure::PartialFailure (ref a, ) => {
1129 let mut a_nonref = (*a).clone();
1130 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 }); };
1131 PaymentSendFailure::PartialFailure (
1132 local_a_nonref.into(),
1138 pub(crate) fn native_into(native: nativePaymentSendFailure) -> Self {
1140 nativePaymentSendFailure::ParameterError (mut a, ) => {
1141 PaymentSendFailure::ParameterError (
1142 crate::lightning::util::errors::APIError::native_into(a),
1145 nativePaymentSendFailure::PathParameterError (mut a, ) => {
1146 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 }); };
1147 PaymentSendFailure::PathParameterError (
1151 nativePaymentSendFailure::AllFailedRetrySafe (mut a, ) => {
1152 let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { crate::lightning::util::errors::APIError::native_into(item) }); };
1153 PaymentSendFailure::AllFailedRetrySafe (
1157 nativePaymentSendFailure::PartialFailure (mut a, ) => {
1158 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 }); };
1159 PaymentSendFailure::PartialFailure (
1166 /// Frees any resources used by the PaymentSendFailure
1168 pub extern "C" fn PaymentSendFailure_free(this_ptr: PaymentSendFailure) { }
1169 /// Creates a copy of the PaymentSendFailure
1171 pub extern "C" fn PaymentSendFailure_clone(orig: &PaymentSendFailure) -> PaymentSendFailure {
1175 /// Utility method to constructs a new ParameterError-variant PaymentSendFailure
1176 pub extern "C" fn PaymentSendFailure_parameter_error(a: crate::lightning::util::errors::APIError) -> PaymentSendFailure {
1177 PaymentSendFailure::ParameterError(a, )
1180 /// Utility method to constructs a new PathParameterError-variant PaymentSendFailure
1181 pub extern "C" fn PaymentSendFailure_path_parameter_error(a: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ) -> PaymentSendFailure {
1182 PaymentSendFailure::PathParameterError(a, )
1185 /// Utility method to constructs a new AllFailedRetrySafe-variant PaymentSendFailure
1186 pub extern "C" fn PaymentSendFailure_all_failed_retry_safe(a: crate::c_types::derived::CVec_APIErrorZ) -> PaymentSendFailure {
1187 PaymentSendFailure::AllFailedRetrySafe(a, )
1190 /// Utility method to constructs a new PartialFailure-variant PaymentSendFailure
1191 pub extern "C" fn PaymentSendFailure_partial_failure(a: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ) -> PaymentSendFailure {
1192 PaymentSendFailure::PartialFailure(a, )
1194 /// Constructs a new ChannelManager to hold several channels and route between them.
1196 /// This is the main \"logic hub\" for all channel-related actions, and implements
1197 /// ChannelMessageHandler.
1199 /// Non-proportional fees are fixed according to our risk using the provided fee estimator.
1201 /// panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`!
1203 /// Users need to notify the new ChannelManager when a new block is connected or
1204 /// disconnected using its `block_connected` and `block_disconnected` methods, starting
1205 /// from after `params.latest_hash`.
1208 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 {
1209 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()) });
1210 ChannelManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
1213 /// Gets the current configuration applied to all new channels, as
1216 pub extern "C" fn ChannelManager_get_current_default_configuration(this_arg: &ChannelManager) -> crate::lightning::util::config::UserConfig {
1217 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_current_default_configuration();
1218 crate::lightning::util::config::UserConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const _) as *mut _) }, is_owned: false }
1221 /// Creates a new outbound channel to the given remote node and with the given value.
1223 /// `user_channel_id` will be provided back as in
1224 /// [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
1225 /// correspond with which `create_channel` call. Note that the `user_channel_id` defaults to 0
1226 /// for inbound channels, so you may wish to avoid using 0 for `user_channel_id` here.
1227 /// `user_channel_id` has no meaning inside of LDK, it is simply copied to events and otherwise
1230 /// Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is
1231 /// greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`.
1233 /// Note that we do not check if you are currently connected to the given peer. If no
1234 /// connection is available, the outbound `open_channel` message may fail to send, resulting in
1235 /// the channel eventually being silently forgotten (dropped on reload).
1237 /// Returns the new Channel's temporary `channel_id`. This ID will appear as
1238 /// [`Event::FundingGenerationReady::temporary_channel_id`] and in
1239 /// [`ChannelDetails::channel_id`] until after
1240 /// [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
1241 /// one derived from the funding transaction's TXID. If the counterparty rejects the channel
1242 /// immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
1244 /// [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
1245 /// [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
1246 /// [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
1248 /// Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
1251 pub extern "C" fn ChannelManager_create_channel(this_arg: &ChannelManager, mut their_network_key: crate::c_types::PublicKey, mut channel_value_satoshis: u64, mut push_msat: u64, mut user_channel_id: u64, mut override_config: crate::lightning::util::config::UserConfig) -> crate::c_types::derived::CResult__u832APIErrorZ {
1252 let mut local_override_config = if override_config.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(override_config.take_inner()) } }) };
1253 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_channel(their_network_key.into_rust(), channel_value_satoshis, push_msat, user_channel_id, local_override_config);
1254 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ThirtyTwoBytes { data: o } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
1258 /// Gets the list of open channels, in random order. See ChannelDetail field documentation for
1259 /// more information.
1262 pub extern "C" fn ChannelManager_list_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1263 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_channels();
1264 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 } }); };
1268 /// Gets the list of usable channels, in random order. Useful as an argument to
1269 /// get_route to ensure non-announced channels are used.
1271 /// These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
1272 /// documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
1276 pub extern "C" fn ChannelManager_list_usable_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ {
1277 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_usable_channels();
1278 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 } }); };
1282 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
1283 /// will be accepted on the given channel, and after additional timeout/the closing of all
1284 /// pending HTLCs, the channel will be closed on chain.
1286 /// * If we are the channel initiator, we will pay between our [`Background`] and
1287 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
1289 /// * If our counterparty is the channel initiator, we will require a channel closing
1290 /// transaction feerate of at least our [`Background`] feerate or the feerate which
1291 /// would appear on a force-closure transaction, whichever is lower. We will allow our
1292 /// counterparty to pay as much fee as they'd like, however.
1294 /// May generate a SendShutdown message event on success, which should be relayed.
1296 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
1297 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1298 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1301 pub extern "C" fn ChannelManager_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1302 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel(unsafe { &*channel_id});
1303 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() };
1307 /// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
1308 /// will be accepted on the given channel, and after additional timeout/the closing of all
1309 /// pending HTLCs, the channel will be closed on chain.
1311 /// `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
1312 /// the channel being closed or not:
1313 /// * If we are the channel initiator, we will pay at least this feerate on the closing
1314 /// transaction. The upper-bound is set by
1315 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
1316 /// estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
1317 /// * If our counterparty is the channel initiator, we will refuse to accept a channel closure
1318 /// transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
1319 /// will appear on a force-closure transaction, whichever is lower).
1321 /// May generate a SendShutdown message event on success, which should be relayed.
1323 /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
1324 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1325 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1328 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 {
1329 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel_with_target_feerate(unsafe { &*channel_id}, target_feerate_sats_per_1000_weight);
1330 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() };
1334 /// Force closes a channel, immediately broadcasting the latest local commitment transaction to
1335 /// the chain and rejecting new HTLCs on the given channel. Fails if channel_id is unknown to the manager.
1338 pub extern "C" fn ChannelManager_force_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
1339 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_channel(unsafe { &*channel_id});
1340 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() };
1344 /// Force close all channels, immediately broadcasting the latest local commitment transaction
1345 /// for each to the chain and rejecting new HTLCs on each.
1347 pub extern "C" fn ChannelManager_force_close_all_channels(this_arg: &ChannelManager) {
1348 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_all_channels()
1351 /// Sends a payment along a given route.
1353 /// Value parameters are provided via the last hop in route, see documentation for RouteHop
1354 /// fields for more info.
1356 /// Note that if the payment_hash already exists elsewhere (eg you're sending a duplicative
1357 /// payment), we don't do anything to stop you! We always try to ensure that if the provided
1358 /// next hop knows the preimage to payment_hash they can claim an additional amount as
1359 /// specified in the last hop in the route! Thus, you should probably do your own
1360 /// payment_preimage tracking (which you should already be doing as they represent \"proof of
1361 /// payment\") and prevent double-sends yourself.
1363 /// May generate SendHTLCs message(s) event on success, which should be relayed.
1365 /// Each path may have a different return value, and PaymentSendValue may return a Vec with
1366 /// each entry matching the corresponding-index entry in the route paths, see
1367 /// PaymentSendFailure for more info.
1369 /// In general, a path may raise:
1370 /// * APIError::RouteError when an invalid route or forwarding parameter (cltv_delta, fee,
1371 /// node public key) is specified.
1372 /// * APIError::ChannelUnavailable if the next-hop channel is not available for updates
1373 /// (including due to previous monitor update failure or new permanent monitor update
1375 /// * APIError::MonitorUpdateFailed if a new monitor update failure prevented sending the
1376 /// relevant updates.
1378 /// Note that depending on the type of the PaymentSendFailure the HTLC may have been
1379 /// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
1380 /// different route unless you intend to pay twice!
1382 /// payment_secret is unrelated to payment_hash (or PaymentPreimage) and exists to authenticate
1383 /// the sender to the recipient and prevent payment-probing (deanonymization) attacks. For
1384 /// newer nodes, it will be provided to you in the invoice. If you do not have one, the Route
1385 /// must not contain multiple paths as multi-path payments require a recipient-provided
1387 /// If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature
1388 /// bit set (either as required or as available). If multiple paths are present in the Route,
1389 /// we assume the invoice had the basic_mpp feature set.
1391 /// Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
1394 pub extern "C" fn ChannelManager_send_payment(this_arg: &ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut payment_secret: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_PaymentIdPaymentSendFailureZ {
1395 let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentSecret(payment_secret.data) }) };
1396 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);
1397 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channelmanager::PaymentId { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::channelmanager::PaymentSendFailure::native_into(e) }).into() };
1401 /// Retries a payment along the given [`Route`].
1403 /// Errors returned are a superset of those returned from [`send_payment`], so see
1404 /// [`send_payment`] documentation for more details on errors. This method will also error if the
1405 /// retry amount puts the payment more than 10% over the payment's total amount, or if the payment
1406 /// for the given `payment_id` cannot be found (likely due to timeout or success).
1408 /// [`send_payment`]: [`ChannelManager::send_payment`]
1411 pub extern "C" fn ChannelManager_retry_payment(this_arg: &ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_id: crate::lightning::ln::channelmanager::PaymentId) -> crate::c_types::derived::CResult_NonePaymentSendFailureZ {
1412 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.retry_payment(route.get_native_ref(), *unsafe { Box::from_raw(payment_id.take_inner()) });
1413 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() };
1417 /// Send a spontaneous payment, which is a payment that does not require the recipient to have
1418 /// generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
1419 /// the preimage, it must be a cryptographically secure random value that no intermediate node
1420 /// would be able to guess -- otherwise, an intermediate node may claim the payment and it will
1421 /// never reach the recipient.
1423 /// See [`send_payment`] documentation for more details on the return value of this function.
1425 /// Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
1426 /// [`send_payment`] for more information about the risks of duplicate preimage usage.
1428 /// Note that `route` must have exactly one path.
1430 /// [`send_payment`]: Self::send_payment
1432 /// Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None
1435 pub extern "C" fn ChannelManager_send_spontaneous_payment(this_arg: &ChannelManager, route: &crate::lightning::routing::router::Route, mut payment_preimage: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ {
1436 let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
1437 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_spontaneous_payment(route.get_native_ref(), local_payment_preimage);
1438 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.0 }, crate::lightning::ln::channelmanager::PaymentId { inner: ObjOps::heap_alloc(orig_ret_0_1), is_owned: true }).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::channelmanager::PaymentSendFailure::native_into(e) }).into() };
1442 /// Call this upon creation of a funding transaction for the given channel.
1444 /// Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
1445 /// or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
1447 /// Panics if a funding transaction has already been provided for this channel.
1449 /// May panic if the output found in the funding transaction is duplicative with some other
1450 /// channel (note that this should be trivially prevented by using unique funding transaction
1451 /// keys per-channel).
1453 /// Do NOT broadcast the funding transaction yourself. When we have safely received our
1454 /// counterparty's signature the funding transaction will automatically be broadcast via the
1455 /// [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
1457 /// Note that this includes RBF or similar transaction replacement strategies - lightning does
1458 /// not currently support replacing a funding transaction on an existing channel. Instead,
1459 /// create a new channel with a conflicting funding transaction.
1461 /// [`Event::FundingGenerationReady`]: crate::util::events::Event::FundingGenerationReady
1464 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 {
1465 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_transaction_generated(unsafe { &*temporary_channel_id}, funding_transaction.into_bitcoin());
1466 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() };
1470 /// Regenerates channel_announcements and generates a signed node_announcement from the given
1471 /// arguments, providing them in corresponding events via
1472 /// [`get_and_clear_pending_msg_events`], if at least one public channel has been confirmed
1473 /// on-chain. This effectively re-broadcasts all channel announcements and sends our node
1474 /// announcement to ensure that the lightning P2P network is aware of the channels we have and
1475 /// our network addresses.
1477 /// `rgb` is a node \"color\" and `alias` is a printable human-readable string to describe this
1478 /// node to humans. They carry no in-protocol meaning.
1480 /// `addresses` represent the set (possibly empty) of socket addresses on which this node
1481 /// accepts incoming connections. These will be included in the node_announcement, publicly
1482 /// tying these addresses together and to this node. If you wish to preserve user privacy,
1483 /// addresses should likely contain only Tor Onion addresses.
1485 /// Panics if `addresses` is absurdly large (more than 500).
1487 /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
1489 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) {
1490 let mut local_addresses = Vec::new(); for mut item in addresses.into_rust().drain(..) { local_addresses.push( { item.into_native() }); };
1491 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.broadcast_node_announcement(rgb.data, alias.data, local_addresses)
1494 /// Processes HTLCs which are pending waiting on random forward delay.
1496 /// Should only really ever be called in response to a PendingHTLCsForwardable event.
1497 /// Will likely generate further events.
1499 pub extern "C" fn ChannelManager_process_pending_htlc_forwards(this_arg: &ChannelManager) {
1500 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_pending_htlc_forwards()
1503 /// Performs actions which should happen on startup and roughly once per minute thereafter.
1505 /// This currently includes:
1506 /// * Increasing or decreasing the on-chain feerate estimates for our outbound channels,
1507 /// * Broadcasting `ChannelUpdate` messages if we've been disconnected from our peer for more
1508 /// than a minute, informing the network that they should no longer attempt to route over
1511 /// Note that this may cause reentrancy through `chain::Watch::update_channel` calls or feerate
1512 /// estimate fetches.
1514 pub extern "C" fn ChannelManager_timer_tick_occurred(this_arg: &ChannelManager) {
1515 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timer_tick_occurred()
1518 /// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
1519 /// after a PaymentReceived event, failing the HTLC back to its origin and freeing resources
1520 /// along the path (including in our own channel on which we received it).
1521 /// Returns false if no payment was found to fail backwards, true if the process of failing the
1522 /// HTLC backwards has been started.
1525 pub extern "C" fn ChannelManager_fail_htlc_backwards(this_arg: &ChannelManager, payment_hash: *const [u8; 32]) -> bool {
1526 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_htlc_backwards(&::lightning::ln::PaymentHash(unsafe { *payment_hash }));
1530 /// Provides a payment preimage in response to a PaymentReceived event, returning true and
1531 /// generating message events for the net layer to claim the payment, if possible. Thus, you
1532 /// should probably kick the net layer to go send messages if this returns true!
1534 /// Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
1535 /// [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentReceived`
1536 /// event matches your expectation. If you fail to do so and call this method, you may provide
1537 /// the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
1539 /// May panic if called except in response to a PaymentReceived event.
1541 /// [`create_inbound_payment`]: Self::create_inbound_payment
1542 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1545 pub extern "C" fn ChannelManager_claim_funds(this_arg: &ChannelManager, mut payment_preimage: crate::c_types::ThirtyTwoBytes) -> bool {
1546 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.claim_funds(::lightning::ln::PaymentPreimage(payment_preimage.data));
1550 /// Gets the node_id held by this ChannelManager
1553 pub extern "C" fn ChannelManager_get_our_node_id(this_arg: &ChannelManager) -> crate::c_types::PublicKey {
1554 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_our_node_id();
1555 crate::c_types::PublicKey::from_rust(&ret)
1558 /// Restores a single, given channel to normal operation after a
1559 /// ChannelMonitorUpdateErr::TemporaryFailure was returned from a channel monitor update
1562 /// All ChannelMonitor updates up to and including highest_applied_update_id must have been
1563 /// fully committed in every copy of the given channels' ChannelMonitors.
1565 /// Note that there is no effect to calling with a highest_applied_update_id other than the
1566 /// current latest ChannelMonitorUpdate and one call to this function after multiple
1567 /// ChannelMonitorUpdateErr::TemporaryFailures is fine. The highest_applied_update_id field
1568 /// exists largely only to prevent races between this and concurrent update_monitor calls.
1570 /// Thus, the anticipated use is, at a high level:
1571 /// 1) You register a chain::Watch with this ChannelManager,
1572 /// 2) it stores each update to disk, and begins updating any remote (eg watchtower) copies of
1573 /// said ChannelMonitors as it can, returning ChannelMonitorUpdateErr::TemporaryFailures
1574 /// any time it cannot do so instantly,
1575 /// 3) update(s) are applied to each remote copy of a ChannelMonitor,
1576 /// 4) once all remote copies are updated, you call this function with the update_id that
1577 /// completed, and once it is the latest the Channel will be re-enabled.
1579 pub extern "C" fn ChannelManager_channel_monitor_updated(this_arg: &ChannelManager, funding_txo: &crate::lightning::chain::transaction::OutPoint, mut highest_applied_update_id: u64) {
1580 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_monitor_updated(funding_txo.get_native_ref(), highest_applied_update_id)
1583 /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
1586 /// This differs from [`create_inbound_payment_for_hash`] only in that it generates the
1587 /// [`PaymentHash`] and [`PaymentPreimage`] for you, returning the first and storing the second.
1589 /// The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentReceived`], which
1590 /// will have the [`PaymentReceived::payment_preimage`] field filled in. That should then be
1591 /// passed directly to [`claim_funds`].
1593 /// See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
1595 /// [`claim_funds`]: Self::claim_funds
1596 /// [`PaymentReceived`]: events::Event::PaymentReceived
1597 /// [`PaymentReceived::payment_preimage`]: events::Event::PaymentReceived::payment_preimage
1598 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1601 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 {
1602 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
1603 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.create_inbound_payment(local_min_value_msat, invoice_expiry_delta_secs, user_payment_id);
1604 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();
1608 /// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
1609 /// stored external to LDK.
1611 /// A [`PaymentReceived`] event will only be generated if the [`PaymentSecret`] matches a
1612 /// payment secret fetched via this method or [`create_inbound_payment`], and which is at least
1613 /// the `min_value_msat` provided here, if one is provided.
1615 /// The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) must be globally unique. This
1616 /// method may return an Err if another payment with the same payment_hash is still pending.
1618 /// `user_payment_id` will be provided back in [`PaymentPurpose::InvoicePayment::user_payment_id`] events to
1619 /// allow tracking of which events correspond with which calls to this and
1620 /// [`create_inbound_payment`]. `user_payment_id` has no meaning inside of LDK, it is simply
1621 /// copied to events and otherwise ignored. It may be used to correlate PaymentReceived events
1622 /// with invoice metadata stored elsewhere.
1624 /// `min_value_msat` should be set if the invoice being generated contains a value. Any payment
1625 /// received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
1626 /// before a [`PaymentReceived`] event will be generated, ensuring that we do not provide the
1627 /// sender \"proof-of-payment\" unless they have paid the required amount.
1629 /// `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
1630 /// in excess of the current time. This should roughly match the expiry time set in the invoice.
1631 /// After this many seconds, we will remove the inbound payment, resulting in any attempts to
1632 /// pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
1633 /// invoices when no timeout is set.
1635 /// Note that we use block header time to time-out pending inbound payments (with some margin
1636 /// to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
1637 /// accept a payment and generate a [`PaymentReceived`] event for some time after the expiry.
1638 /// If you need exact expiry semantics, you should enforce them upon receipt of
1639 /// [`PaymentReceived`].
1641 /// Pending inbound payments are stored in memory and in serialized versions of this
1642 /// [`ChannelManager`]. If potentially unbounded numbers of inbound payments may exist and
1643 /// space is limited, you may wish to rate-limit inbound payment creation.
1645 /// May panic if `invoice_expiry_delta_secs` is greater than one year.
1647 /// Note that invoices generated for inbound payments should have their `min_final_cltv_expiry`
1648 /// set to at least [`MIN_FINAL_CLTV_EXPIRY`].
1650 /// [`create_inbound_payment`]: Self::create_inbound_payment
1651 /// [`PaymentReceived`]: events::Event::PaymentReceived
1652 /// [`PaymentPurpose::InvoicePayment::user_payment_id`]: events::PaymentPurpose::InvoicePayment::user_payment_id
1655 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 {
1656 let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
1657 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);
1658 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() };
1662 impl From<nativeChannelManager> for crate::lightning::util::events::MessageSendEventsProvider {
1663 fn from(obj: nativeChannelManager) -> Self {
1664 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1665 let mut ret = ChannelManager_as_MessageSendEventsProvider(&rust_obj);
1666 // 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
1667 rust_obj.inner = std::ptr::null_mut();
1668 ret.free = Some(ChannelManager_free_void);
1672 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
1673 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
1675 pub extern "C" fn ChannelManager_as_MessageSendEventsProvider(this_arg: &ChannelManager) -> crate::lightning::util::events::MessageSendEventsProvider {
1676 crate::lightning::util::events::MessageSendEventsProvider {
1677 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1679 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
1684 extern "C" fn ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
1685 let mut ret = <nativeChannelManager as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
1686 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
1690 impl From<nativeChannelManager> for crate::lightning::util::events::EventsProvider {
1691 fn from(obj: nativeChannelManager) -> Self {
1692 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1693 let mut ret = ChannelManager_as_EventsProvider(&rust_obj);
1694 // 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
1695 rust_obj.inner = std::ptr::null_mut();
1696 ret.free = Some(ChannelManager_free_void);
1700 /// Constructs a new EventsProvider which calls the relevant methods on this_arg.
1701 /// This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
1703 pub extern "C" fn ChannelManager_as_EventsProvider(this_arg: &ChannelManager) -> crate::lightning::util::events::EventsProvider {
1704 crate::lightning::util::events::EventsProvider {
1705 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1707 process_pending_events: ChannelManager_EventsProvider_process_pending_events,
1711 extern "C" fn ChannelManager_EventsProvider_process_pending_events(this_arg: *const c_void, mut handler: crate::lightning::util::events::EventHandler) {
1712 <nativeChannelManager as lightning::util::events::EventsProvider<>>::process_pending_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, handler)
1715 impl From<nativeChannelManager> for crate::lightning::chain::Listen {
1716 fn from(obj: nativeChannelManager) -> Self {
1717 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1718 let mut ret = ChannelManager_as_Listen(&rust_obj);
1719 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
1720 rust_obj.inner = std::ptr::null_mut();
1721 ret.free = Some(ChannelManager_free_void);
1725 /// Constructs a new Listen which calls the relevant methods on this_arg.
1726 /// This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
1728 pub extern "C" fn ChannelManager_as_Listen(this_arg: &ChannelManager) -> crate::lightning::chain::Listen {
1729 crate::lightning::chain::Listen {
1730 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1732 block_connected: ChannelManager_Listen_block_connected,
1733 block_disconnected: ChannelManager_Listen_block_disconnected,
1737 extern "C" fn ChannelManager_Listen_block_connected(this_arg: *const c_void, mut block: crate::c_types::u8slice, mut height: u32) {
1738 <nativeChannelManager as lightning::chain::Listen<>>::block_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height)
1740 extern "C" fn ChannelManager_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
1741 <nativeChannelManager as lightning::chain::Listen<>>::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
1744 impl From<nativeChannelManager> for crate::lightning::chain::Confirm {
1745 fn from(obj: nativeChannelManager) -> Self {
1746 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1747 let mut ret = ChannelManager_as_Confirm(&rust_obj);
1748 // 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
1749 rust_obj.inner = std::ptr::null_mut();
1750 ret.free = Some(ChannelManager_free_void);
1754 /// Constructs a new Confirm which calls the relevant methods on this_arg.
1755 /// This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
1757 pub extern "C" fn ChannelManager_as_Confirm(this_arg: &ChannelManager) -> crate::lightning::chain::Confirm {
1758 crate::lightning::chain::Confirm {
1759 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1761 transactions_confirmed: ChannelManager_Confirm_transactions_confirmed,
1762 transaction_unconfirmed: ChannelManager_Confirm_transaction_unconfirmed,
1763 best_block_updated: ChannelManager_Confirm_best_block_updated,
1764 get_relevant_txids: ChannelManager_Confirm_get_relevant_txids,
1768 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) {
1769 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 }); };
1770 <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)
1772 extern "C" fn ChannelManager_Confirm_best_block_updated(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
1773 <nativeChannelManager as lightning::chain::Confirm<>>::best_block_updated(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
1776 extern "C" fn ChannelManager_Confirm_get_relevant_txids(this_arg: *const c_void) -> crate::c_types::derived::CVec_TxidZ {
1777 let mut ret = <nativeChannelManager as lightning::chain::Confirm<>>::get_relevant_txids(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, );
1778 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::ThirtyTwoBytes { data: item.into_inner() } }); };
1781 extern "C" fn ChannelManager_Confirm_transaction_unconfirmed(this_arg: *const c_void, txid: *const [u8; 32]) {
1782 <nativeChannelManager as lightning::chain::Confirm<>>::transaction_unconfirmed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap())
1785 /// Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
1786 /// indicating whether persistence is necessary. Only one listener on
1787 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
1789 /// Note that the feature `allow_wallclock_use` must be enabled to use this function.
1792 pub extern "C" fn ChannelManager_await_persistable_update_timeout(this_arg: &ChannelManager, mut max_wait: u64) -> bool {
1793 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.await_persistable_update_timeout(std::time::Duration::from_secs(max_wait));
1797 /// Blocks until ChannelManager needs to be persisted. Only one listener on
1798 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
1801 pub extern "C" fn ChannelManager_await_persistable_update(this_arg: &ChannelManager) {
1802 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.await_persistable_update()
1805 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
1806 /// [`chain::Confirm`] interfaces.
1809 pub extern "C" fn ChannelManager_current_best_block(this_arg: &ChannelManager) -> crate::lightning::chain::BestBlock {
1810 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
1811 crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
1814 impl From<nativeChannelManager> for crate::lightning::ln::msgs::ChannelMessageHandler {
1815 fn from(obj: nativeChannelManager) -> Self {
1816 let mut rust_obj = ChannelManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1817 let mut ret = ChannelManager_as_ChannelMessageHandler(&rust_obj);
1818 // 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
1819 rust_obj.inner = std::ptr::null_mut();
1820 ret.free = Some(ChannelManager_free_void);
1824 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
1825 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
1827 pub extern "C" fn ChannelManager_as_ChannelMessageHandler(this_arg: &ChannelManager) -> crate::lightning::ln::msgs::ChannelMessageHandler {
1828 crate::lightning::ln::msgs::ChannelMessageHandler {
1829 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1831 handle_open_channel: ChannelManager_ChannelMessageHandler_handle_open_channel,
1832 handle_accept_channel: ChannelManager_ChannelMessageHandler_handle_accept_channel,
1833 handle_funding_created: ChannelManager_ChannelMessageHandler_handle_funding_created,
1834 handle_funding_signed: ChannelManager_ChannelMessageHandler_handle_funding_signed,
1835 handle_funding_locked: ChannelManager_ChannelMessageHandler_handle_funding_locked,
1836 handle_shutdown: ChannelManager_ChannelMessageHandler_handle_shutdown,
1837 handle_closing_signed: ChannelManager_ChannelMessageHandler_handle_closing_signed,
1838 handle_update_add_htlc: ChannelManager_ChannelMessageHandler_handle_update_add_htlc,
1839 handle_update_fulfill_htlc: ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc,
1840 handle_update_fail_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_htlc,
1841 handle_update_fail_malformed_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_malformed_htlc,
1842 handle_commitment_signed: ChannelManager_ChannelMessageHandler_handle_commitment_signed,
1843 handle_revoke_and_ack: ChannelManager_ChannelMessageHandler_handle_revoke_and_ack,
1844 handle_update_fee: ChannelManager_ChannelMessageHandler_handle_update_fee,
1845 handle_announcement_signatures: ChannelManager_ChannelMessageHandler_handle_announcement_signatures,
1846 peer_disconnected: ChannelManager_ChannelMessageHandler_peer_disconnected,
1847 peer_connected: ChannelManager_ChannelMessageHandler_peer_connected,
1848 handle_channel_reestablish: ChannelManager_ChannelMessageHandler_handle_channel_reestablish,
1849 handle_channel_update: ChannelManager_ChannelMessageHandler_handle_channel_update,
1850 handle_error: ChannelManager_ChannelMessageHandler_handle_error,
1851 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
1852 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1854 get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events,
1859 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) {
1860 <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())
1862 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) {
1863 <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())
1865 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) {
1866 <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())
1868 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) {
1869 <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())
1871 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) {
1872 <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())
1874 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) {
1875 <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())
1877 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) {
1878 <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())
1880 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) {
1881 <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())
1883 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) {
1884 <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())
1886 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) {
1887 <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())
1889 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) {
1890 <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())
1892 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) {
1893 <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())
1895 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) {
1896 <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())
1898 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) {
1899 <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())
1901 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) {
1902 <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())
1904 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) {
1905 <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())
1907 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) {
1908 <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())
1910 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) {
1911 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), no_connection_possible)
1913 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) {
1914 <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())
1916 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) {
1917 <nativeChannelManager as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), msg.get_native_ref())
1921 /// Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
1922 pub extern "C" fn ChannelManager_write(obj: &ChannelManager) -> crate::c_types::derived::CVec_u8Z {
1923 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1926 pub(crate) extern "C" fn ChannelManager_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1927 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelManager) })
1930 use lightning::ln::channelmanager::ChannelManagerReadArgs as nativeChannelManagerReadArgsImport;
1931 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>;
1933 /// Arguments for the creation of a ChannelManager that are not deserialized.
1935 /// At a high-level, the process for deserializing a ChannelManager and resuming normal operation
1937 /// 1) Deserialize all stored ChannelMonitors.
1938 /// 2) Deserialize the ChannelManager by filling in this struct and calling:
1939 /// <(BlockHash, ChannelManager)>::read(reader, args)
1940 /// This may result in closing some Channels if the ChannelMonitor is newer than the stored
1941 /// ChannelManager state to ensure no loss of funds. Thus, transactions may be broadcasted.
1942 /// 3) If you are not fetching full blocks, register all relevant ChannelMonitor outpoints the same
1943 /// way you would handle a `chain::Filter` call using ChannelMonitor::get_outputs_to_watch() and
1944 /// ChannelMonitor::get_funding_txo().
1945 /// 4) Reconnect blocks on your ChannelMonitors.
1946 /// 5) Disconnect/connect blocks on the ChannelManager.
1947 /// 6) Move the ChannelMonitors into your local chain::Watch.
1949 /// Note that the ordering of #4-6 is not of importance, however all three must occur before you
1950 /// call any other methods on the newly-deserialized ChannelManager.
1952 /// Note that because some channels may be closed during deserialization, it is critical that you
1953 /// always deserialize only the latest version of a ChannelManager and ChannelMonitors available to
1954 /// you. If you deserialize an old ChannelManager (during which force-closure transactions may be
1955 /// broadcast), and then later deserialize a newer version of the same ChannelManager (which will
1956 /// not force-close the same channels but consider them live), you may end up revoking a state for
1957 /// which you've already broadcasted the transaction.
1960 pub struct ChannelManagerReadArgs {
1961 /// A pointer to the opaque Rust object.
1963 /// Nearly everywhere, inner must be non-null, however in places where
1964 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1965 pub inner: *mut nativeChannelManagerReadArgs,
1966 /// Indicates that this is the only struct which contains the same pointer.
1968 /// Rust functions which take ownership of an object provided via an argument require
1969 /// this to be true and invalidate the object pointed to by inner.
1973 impl Drop for ChannelManagerReadArgs {
1974 fn drop(&mut self) {
1975 if self.is_owned && !<*mut nativeChannelManagerReadArgs>::is_null(self.inner) {
1976 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1980 /// Frees any resources used by the ChannelManagerReadArgs, if is_owned is set and inner is non-NULL.
1982 pub extern "C" fn ChannelManagerReadArgs_free(this_obj: ChannelManagerReadArgs) { }
1984 /// Used only if an object of this type is returned as a trait impl by a method
1985 extern "C" fn ChannelManagerReadArgs_free_void(this_ptr: *mut c_void) {
1986 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManagerReadArgs); }
1989 impl ChannelManagerReadArgs {
1990 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelManagerReadArgs {
1991 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1993 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelManagerReadArgs {
1994 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1996 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1997 pub(crate) fn take_inner(mut self) -> *mut nativeChannelManagerReadArgs {
1998 assert!(self.is_owned);
1999 let ret = ObjOps::untweak_ptr(self.inner);
2000 self.inner = std::ptr::null_mut();
2004 /// The keys provider which will give us relevant keys. Some keys will be loaded during
2005 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
2008 pub extern "C" fn ChannelManagerReadArgs_get_keys_manager(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::keysinterface::KeysInterface {
2009 let mut inner_val = &mut this_ptr.get_native_mut_ref().keys_manager;
2012 /// The keys provider which will give us relevant keys. Some keys will be loaded during
2013 /// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
2016 pub extern "C" fn ChannelManagerReadArgs_set_keys_manager(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::keysinterface::KeysInterface) {
2017 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.keys_manager = val;
2019 /// The fee_estimator for use in the ChannelManager in the future.
2021 /// No calls to the FeeEstimator will be made during deserialization.
2023 pub extern "C" fn ChannelManagerReadArgs_get_fee_estimator(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::FeeEstimator {
2024 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_estimator;
2027 /// The fee_estimator for use in the ChannelManager in the future.
2029 /// No calls to the FeeEstimator will be made during deserialization.
2031 pub extern "C" fn ChannelManagerReadArgs_set_fee_estimator(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::FeeEstimator) {
2032 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_estimator = val;
2034 /// The chain::Watch for use in the ChannelManager in the future.
2036 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
2037 /// you have deserialized ChannelMonitors separately and will add them to your
2038 /// chain::Watch after deserializing this ChannelManager.
2040 pub extern "C" fn ChannelManagerReadArgs_get_chain_monitor(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::Watch {
2041 let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_monitor;
2044 /// The chain::Watch for use in the ChannelManager in the future.
2046 /// No calls to the chain::Watch will be made during deserialization. It is assumed that
2047 /// you have deserialized ChannelMonitors separately and will add them to your
2048 /// chain::Watch after deserializing this ChannelManager.
2050 pub extern "C" fn ChannelManagerReadArgs_set_chain_monitor(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::Watch) {
2051 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_monitor = val;
2053 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
2054 /// used to broadcast the latest local commitment transactions of channels which must be
2055 /// force-closed during deserialization.
2057 pub extern "C" fn ChannelManagerReadArgs_get_tx_broadcaster(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::chain::chaininterface::BroadcasterInterface {
2058 let mut inner_val = &mut this_ptr.get_native_mut_ref().tx_broadcaster;
2061 /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
2062 /// used to broadcast the latest local commitment transactions of channels which must be
2063 /// force-closed during deserialization.
2065 pub extern "C" fn ChannelManagerReadArgs_set_tx_broadcaster(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::chain::chaininterface::BroadcasterInterface) {
2066 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.tx_broadcaster = val;
2068 /// The Logger for use in the ChannelManager and which may be used to log information during
2069 /// deserialization.
2071 pub extern "C" fn ChannelManagerReadArgs_get_logger(this_ptr: &ChannelManagerReadArgs) -> *const crate::lightning::util::logger::Logger {
2072 let mut inner_val = &mut this_ptr.get_native_mut_ref().logger;
2075 /// The Logger for use in the ChannelManager and which may be used to log information during
2076 /// deserialization.
2078 pub extern "C" fn ChannelManagerReadArgs_set_logger(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::logger::Logger) {
2079 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.logger = val;
2081 /// Default settings used for new channels. Any existing channels will continue to use the
2082 /// runtime settings which were stored when the ChannelManager was serialized.
2084 pub extern "C" fn ChannelManagerReadArgs_get_default_config(this_ptr: &ChannelManagerReadArgs) -> crate::lightning::util::config::UserConfig {
2085 let mut inner_val = &mut this_ptr.get_native_mut_ref().default_config;
2086 crate::lightning::util::config::UserConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
2088 /// Default settings used for new channels. Any existing channels will continue to use the
2089 /// runtime settings which were stored when the ChannelManager was serialized.
2091 pub extern "C" fn ChannelManagerReadArgs_set_default_config(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::lightning::util::config::UserConfig) {
2092 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.default_config = *unsafe { Box::from_raw(val.take_inner()) };
2094 /// Simple utility function to create a ChannelManagerReadArgs which creates the monitor
2095 /// HashMap for you. This is primarily useful for C bindings where it is not practical to
2096 /// populate a HashMap directly from C.
2099 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 {
2100 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() }); };
2101 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);
2102 ChannelManagerReadArgs { inner: ObjOps::heap_alloc(ret), is_owned: true }
2106 /// Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_write
2107 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 {
2108 let arg_conv = *unsafe { Box::from_raw(arg.take_inner()) };
2109 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);
2110 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() };