aaed7c4f49978f09db1bdadd3aef72f8f3e5baa8
[ldk-c-bindings] / lightning-c-bindings / src / lightning / util / config.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
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.
8
9 //! Various user-configurable channel limits and settings which ChannelManager
10 //! applies for you.
11
12 use alloc::str::FromStr;
13 use core::ffi::c_void;
14 use core::convert::Infallible;
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
17 #[cfg(feature="no-std")]
18 use alloc::{vec::Vec, boxed::Box};
19
20
21 use lightning::util::config::ChannelHandshakeConfig as nativeChannelHandshakeConfigImport;
22 pub(crate) type nativeChannelHandshakeConfig = nativeChannelHandshakeConfigImport;
23
24 /// Configuration we set when applicable.
25 ///
26 /// Default::default() provides sane defaults.
27 #[must_use]
28 #[repr(C)]
29 pub struct ChannelHandshakeConfig {
30         /// A pointer to the opaque Rust object.
31
32         /// Nearly everywhere, inner must be non-null, however in places where
33         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
34         pub inner: *mut nativeChannelHandshakeConfig,
35         /// Indicates that this is the only struct which contains the same pointer.
36
37         /// Rust functions which take ownership of an object provided via an argument require
38         /// this to be true and invalidate the object pointed to by inner.
39         pub is_owned: bool,
40 }
41
42 impl Drop for ChannelHandshakeConfig {
43         fn drop(&mut self) {
44                 if self.is_owned && !<*mut nativeChannelHandshakeConfig>::is_null(self.inner) {
45                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
46                 }
47         }
48 }
49 /// Frees any resources used by the ChannelHandshakeConfig, if is_owned is set and inner is non-NULL.
50 #[no_mangle]
51 pub extern "C" fn ChannelHandshakeConfig_free(this_obj: ChannelHandshakeConfig) { }
52 #[allow(unused)]
53 /// Used only if an object of this type is returned as a trait impl by a method
54 pub(crate) extern "C" fn ChannelHandshakeConfig_free_void(this_ptr: *mut c_void) {
55         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelHandshakeConfig); }
56 }
57 #[allow(unused)]
58 impl ChannelHandshakeConfig {
59         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelHandshakeConfig {
60                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
61         }
62         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelHandshakeConfig {
63                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
64         }
65         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
66         pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeConfig {
67                 assert!(self.is_owned);
68                 let ret = ObjOps::untweak_ptr(self.inner);
69                 self.inner = core::ptr::null_mut();
70                 ret
71         }
72 }
73 /// Confirmations we will wait for before considering the channel locked in.
74 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
75 /// equivalent limit applied to outbound channels).
76 ///
77 /// A lower-bound of 1 is applied, requiring all channels to have a confirmed commitment
78 /// transaction before operation. If you wish to accept channels with zero confirmations, see
79 /// [`UserConfig::manually_accept_inbound_channels`] and
80 /// [`ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`].
81 ///
82 /// Default value: 6.
83 ///
84 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
85 /// [`ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf
86 #[no_mangle]
87 pub extern "C" fn ChannelHandshakeConfig_get_minimum_depth(this_ptr: &ChannelHandshakeConfig) -> u32 {
88         let mut inner_val = &mut this_ptr.get_native_mut_ref().minimum_depth;
89         *inner_val
90 }
91 /// Confirmations we will wait for before considering the channel locked in.
92 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
93 /// equivalent limit applied to outbound channels).
94 ///
95 /// A lower-bound of 1 is applied, requiring all channels to have a confirmed commitment
96 /// transaction before operation. If you wish to accept channels with zero confirmations, see
97 /// [`UserConfig::manually_accept_inbound_channels`] and
98 /// [`ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`].
99 ///
100 /// Default value: 6.
101 ///
102 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
103 /// [`ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf
104 #[no_mangle]
105 pub extern "C" fn ChannelHandshakeConfig_set_minimum_depth(this_ptr: &mut ChannelHandshakeConfig, mut val: u32) {
106         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.minimum_depth = val;
107 }
108 /// Set to the number of blocks we require our counterparty to wait to claim their money (ie
109 /// the number of blocks we have to punish our counterparty if they broadcast a revoked
110 /// transaction).
111 ///
112 /// This is one of the main parameters of our security model. We (or one of our watchtowers) MUST
113 /// be online to check for revoked transactions on-chain at least once every our_to_self_delay
114 /// blocks (minus some margin to allow us enough time to broadcast and confirm a transaction,
115 /// possibly with time in between to RBF the spending transaction).
116 ///
117 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
118 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
119 /// our channel.
120 ///
121 /// Default value: [`BREAKDOWN_TIMEOUT`], we enforce it as a minimum at channel opening so you
122 /// can tweak config to ask for more security, not less.
123 #[no_mangle]
124 pub extern "C" fn ChannelHandshakeConfig_get_our_to_self_delay(this_ptr: &ChannelHandshakeConfig) -> u16 {
125         let mut inner_val = &mut this_ptr.get_native_mut_ref().our_to_self_delay;
126         *inner_val
127 }
128 /// Set to the number of blocks we require our counterparty to wait to claim their money (ie
129 /// the number of blocks we have to punish our counterparty if they broadcast a revoked
130 /// transaction).
131 ///
132 /// This is one of the main parameters of our security model. We (or one of our watchtowers) MUST
133 /// be online to check for revoked transactions on-chain at least once every our_to_self_delay
134 /// blocks (minus some margin to allow us enough time to broadcast and confirm a transaction,
135 /// possibly with time in between to RBF the spending transaction).
136 ///
137 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
138 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
139 /// our channel.
140 ///
141 /// Default value: [`BREAKDOWN_TIMEOUT`], we enforce it as a minimum at channel opening so you
142 /// can tweak config to ask for more security, not less.
143 #[no_mangle]
144 pub extern "C" fn ChannelHandshakeConfig_set_our_to_self_delay(this_ptr: &mut ChannelHandshakeConfig, mut val: u16) {
145         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.our_to_self_delay = val;
146 }
147 /// Set to the smallest value HTLC we will accept to process.
148 ///
149 /// This value is sent to our counterparty on channel-open and we close the channel any time
150 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
151 ///
152 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
153 /// by the protocol.
154 #[no_mangle]
155 pub extern "C" fn ChannelHandshakeConfig_get_our_htlc_minimum_msat(this_ptr: &ChannelHandshakeConfig) -> u64 {
156         let mut inner_val = &mut this_ptr.get_native_mut_ref().our_htlc_minimum_msat;
157         *inner_val
158 }
159 /// Set to the smallest value HTLC we will accept to process.
160 ///
161 /// This value is sent to our counterparty on channel-open and we close the channel any time
162 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
163 ///
164 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
165 /// by the protocol.
166 #[no_mangle]
167 pub extern "C" fn ChannelHandshakeConfig_set_our_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeConfig, mut val: u64) {
168         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.our_htlc_minimum_msat = val;
169 }
170 /// Sets the percentage of the channel value we will cap the total value of outstanding inbound
171 /// HTLCs to.
172 ///
173 /// This can be set to a value between 1-100, where the value corresponds to the percent of the
174 /// channel value in whole percentages.
175 ///
176 /// Note that:
177 /// * If configured to another value than the default value 10, any new channels created with
178 /// the non default value will cause versions of LDK prior to 0.0.104 to refuse to read the
179 /// `ChannelManager`.
180 ///
181 /// * This caps the total value for inbound HTLCs in-flight only, and there's currently
182 /// no way to configure the cap for the total value of outbound HTLCs in-flight.
183 ///
184 /// * The requirements for your node being online to ensure the safety of HTLC-encumbered funds
185 /// are different from the non-HTLC-encumbered funds. This makes this an important knob to
186 /// restrict exposure to loss due to being offline for too long.
187 /// See [`ChannelHandshakeConfig::our_to_self_delay`] and [`ChannelConfig::cltv_expiry_delta`]
188 /// for more information.
189 ///
190 /// Default value: 10.
191 /// Minimum value: 1, any values less than 1 will be treated as 1 instead.
192 /// Maximum value: 100, any values larger than 100 will be treated as 100 instead.
193 #[no_mangle]
194 pub extern "C" fn ChannelHandshakeConfig_get_max_inbound_htlc_value_in_flight_percent_of_channel(this_ptr: &ChannelHandshakeConfig) -> u8 {
195         let mut inner_val = &mut this_ptr.get_native_mut_ref().max_inbound_htlc_value_in_flight_percent_of_channel;
196         *inner_val
197 }
198 /// Sets the percentage of the channel value we will cap the total value of outstanding inbound
199 /// HTLCs to.
200 ///
201 /// This can be set to a value between 1-100, where the value corresponds to the percent of the
202 /// channel value in whole percentages.
203 ///
204 /// Note that:
205 /// * If configured to another value than the default value 10, any new channels created with
206 /// the non default value will cause versions of LDK prior to 0.0.104 to refuse to read the
207 /// `ChannelManager`.
208 ///
209 /// * This caps the total value for inbound HTLCs in-flight only, and there's currently
210 /// no way to configure the cap for the total value of outbound HTLCs in-flight.
211 ///
212 /// * The requirements for your node being online to ensure the safety of HTLC-encumbered funds
213 /// are different from the non-HTLC-encumbered funds. This makes this an important knob to
214 /// restrict exposure to loss due to being offline for too long.
215 /// See [`ChannelHandshakeConfig::our_to_self_delay`] and [`ChannelConfig::cltv_expiry_delta`]
216 /// for more information.
217 ///
218 /// Default value: 10.
219 /// Minimum value: 1, any values less than 1 will be treated as 1 instead.
220 /// Maximum value: 100, any values larger than 100 will be treated as 100 instead.
221 #[no_mangle]
222 pub extern "C" fn ChannelHandshakeConfig_set_max_inbound_htlc_value_in_flight_percent_of_channel(this_ptr: &mut ChannelHandshakeConfig, mut val: u8) {
223         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_inbound_htlc_value_in_flight_percent_of_channel = val;
224 }
225 /// If set, we attempt to negotiate the `scid_privacy` (referred to as `scid_alias` in the
226 /// BOLTs) option for outbound private channels. This provides better privacy by not including
227 /// our real on-chain channel UTXO in each invoice and requiring that our counterparty only
228 /// relay HTLCs to us using the channel's SCID alias.
229 ///
230 /// If this option is set, channels may be created that will not be readable by LDK versions
231 /// prior to 0.0.106, causing [`ChannelManager`]'s read method to return a
232 /// [`DecodeError::InvalidValue`].
233 ///
234 /// Note that setting this to true does *not* prevent us from opening channels with
235 /// counterparties that do not support the `scid_alias` option; we will simply fall back to a
236 /// private channel without that option.
237 ///
238 /// Ignored if the channel is negotiated to be announced, see
239 /// [`ChannelHandshakeConfig::announced_channel`] and
240 /// [`ChannelHandshakeLimits::force_announced_channel_preference`] for more.
241 ///
242 /// Default value: false. This value is likely to change to true in the future.
243 ///
244 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
245 /// [`DecodeError::InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue
246 #[no_mangle]
247 pub extern "C" fn ChannelHandshakeConfig_get_negotiate_scid_privacy(this_ptr: &ChannelHandshakeConfig) -> bool {
248         let mut inner_val = &mut this_ptr.get_native_mut_ref().negotiate_scid_privacy;
249         *inner_val
250 }
251 /// If set, we attempt to negotiate the `scid_privacy` (referred to as `scid_alias` in the
252 /// BOLTs) option for outbound private channels. This provides better privacy by not including
253 /// our real on-chain channel UTXO in each invoice and requiring that our counterparty only
254 /// relay HTLCs to us using the channel's SCID alias.
255 ///
256 /// If this option is set, channels may be created that will not be readable by LDK versions
257 /// prior to 0.0.106, causing [`ChannelManager`]'s read method to return a
258 /// [`DecodeError::InvalidValue`].
259 ///
260 /// Note that setting this to true does *not* prevent us from opening channels with
261 /// counterparties that do not support the `scid_alias` option; we will simply fall back to a
262 /// private channel without that option.
263 ///
264 /// Ignored if the channel is negotiated to be announced, see
265 /// [`ChannelHandshakeConfig::announced_channel`] and
266 /// [`ChannelHandshakeLimits::force_announced_channel_preference`] for more.
267 ///
268 /// Default value: false. This value is likely to change to true in the future.
269 ///
270 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
271 /// [`DecodeError::InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue
272 #[no_mangle]
273 pub extern "C" fn ChannelHandshakeConfig_set_negotiate_scid_privacy(this_ptr: &mut ChannelHandshakeConfig, mut val: bool) {
274         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.negotiate_scid_privacy = val;
275 }
276 /// Set to announce the channel publicly and notify all nodes that they can route via this
277 /// channel.
278 ///
279 /// This should only be set to true for nodes which expect to be online reliably.
280 ///
281 /// As the node which funds a channel picks this value this will only apply for new outbound
282 /// channels unless [`ChannelHandshakeLimits::force_announced_channel_preference`] is set.
283 ///
284 /// Default value: false.
285 #[no_mangle]
286 pub extern "C" fn ChannelHandshakeConfig_get_announced_channel(this_ptr: &ChannelHandshakeConfig) -> bool {
287         let mut inner_val = &mut this_ptr.get_native_mut_ref().announced_channel;
288         *inner_val
289 }
290 /// Set to announce the channel publicly and notify all nodes that they can route via this
291 /// channel.
292 ///
293 /// This should only be set to true for nodes which expect to be online reliably.
294 ///
295 /// As the node which funds a channel picks this value this will only apply for new outbound
296 /// channels unless [`ChannelHandshakeLimits::force_announced_channel_preference`] is set.
297 ///
298 /// Default value: false.
299 #[no_mangle]
300 pub extern "C" fn ChannelHandshakeConfig_set_announced_channel(this_ptr: &mut ChannelHandshakeConfig, mut val: bool) {
301         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announced_channel = val;
302 }
303 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
304 /// supports it, they will then enforce the mutual-close output to us matches what we provided
305 /// at intialization, preventing us from closing to an alternate pubkey.
306 ///
307 /// This is set to true by default to provide a slight increase in security, though ultimately
308 /// any attacker who is able to take control of a channel can just as easily send the funds via
309 /// lightning payments, so we never require that our counterparties support this option.
310 ///
311 /// The upfront key committed is provided from [`KeysInterface::get_shutdown_scriptpubkey`].
312 ///
313 /// Default value: true.
314 ///
315 /// [`KeysInterface::get_shutdown_scriptpubkey`]: crate::chain::keysinterface::KeysInterface::get_shutdown_scriptpubkey
316 #[no_mangle]
317 pub extern "C" fn ChannelHandshakeConfig_get_commit_upfront_shutdown_pubkey(this_ptr: &ChannelHandshakeConfig) -> bool {
318         let mut inner_val = &mut this_ptr.get_native_mut_ref().commit_upfront_shutdown_pubkey;
319         *inner_val
320 }
321 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
322 /// supports it, they will then enforce the mutual-close output to us matches what we provided
323 /// at intialization, preventing us from closing to an alternate pubkey.
324 ///
325 /// This is set to true by default to provide a slight increase in security, though ultimately
326 /// any attacker who is able to take control of a channel can just as easily send the funds via
327 /// lightning payments, so we never require that our counterparties support this option.
328 ///
329 /// The upfront key committed is provided from [`KeysInterface::get_shutdown_scriptpubkey`].
330 ///
331 /// Default value: true.
332 ///
333 /// [`KeysInterface::get_shutdown_scriptpubkey`]: crate::chain::keysinterface::KeysInterface::get_shutdown_scriptpubkey
334 #[no_mangle]
335 pub extern "C" fn ChannelHandshakeConfig_set_commit_upfront_shutdown_pubkey(this_ptr: &mut ChannelHandshakeConfig, mut val: bool) {
336         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.commit_upfront_shutdown_pubkey = val;
337 }
338 /// Constructs a new ChannelHandshakeConfig given each field
339 #[must_use]
340 #[no_mangle]
341 pub extern "C" fn ChannelHandshakeConfig_new(mut minimum_depth_arg: u32, mut our_to_self_delay_arg: u16, mut our_htlc_minimum_msat_arg: u64, mut max_inbound_htlc_value_in_flight_percent_of_channel_arg: u8, mut negotiate_scid_privacy_arg: bool, mut announced_channel_arg: bool, mut commit_upfront_shutdown_pubkey_arg: bool) -> ChannelHandshakeConfig {
342         ChannelHandshakeConfig { inner: ObjOps::heap_alloc(nativeChannelHandshakeConfig {
343                 minimum_depth: minimum_depth_arg,
344                 our_to_self_delay: our_to_self_delay_arg,
345                 our_htlc_minimum_msat: our_htlc_minimum_msat_arg,
346                 max_inbound_htlc_value_in_flight_percent_of_channel: max_inbound_htlc_value_in_flight_percent_of_channel_arg,
347                 negotiate_scid_privacy: negotiate_scid_privacy_arg,
348                 announced_channel: announced_channel_arg,
349                 commit_upfront_shutdown_pubkey: commit_upfront_shutdown_pubkey_arg,
350         }), is_owned: true }
351 }
352 impl Clone for ChannelHandshakeConfig {
353         fn clone(&self) -> Self {
354                 Self {
355                         inner: if <*mut nativeChannelHandshakeConfig>::is_null(self.inner) { core::ptr::null_mut() } else {
356                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
357                         is_owned: true,
358                 }
359         }
360 }
361 #[allow(unused)]
362 /// Used only if an object of this type is returned as a trait impl by a method
363 pub(crate) extern "C" fn ChannelHandshakeConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
364         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeConfig)).clone() })) as *mut c_void
365 }
366 #[no_mangle]
367 /// Creates a copy of the ChannelHandshakeConfig
368 pub extern "C" fn ChannelHandshakeConfig_clone(orig: &ChannelHandshakeConfig) -> ChannelHandshakeConfig {
369         orig.clone()
370 }
371 /// Creates a "default" ChannelHandshakeConfig. See struct and individual field documentaiton for details on which values are used.
372 #[must_use]
373 #[no_mangle]
374 pub extern "C" fn ChannelHandshakeConfig_default() -> ChannelHandshakeConfig {
375         ChannelHandshakeConfig { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
376 }
377
378 use lightning::util::config::ChannelHandshakeLimits as nativeChannelHandshakeLimitsImport;
379 pub(crate) type nativeChannelHandshakeLimits = nativeChannelHandshakeLimitsImport;
380
381 /// Optional channel limits which are applied during channel creation.
382 ///
383 /// These limits are only applied to our counterparty's limits, not our own.
384 ///
385 /// Use 0/<type>::max_value() as appropriate to skip checking.
386 ///
387 /// Provides sane defaults for most configurations.
388 ///
389 /// Most additional limits are disabled except those with which specify a default in individual
390 /// field documentation. Note that this may result in barely-usable channels, but since they
391 /// are applied mostly only to incoming channels that's not much of a problem.
392 #[must_use]
393 #[repr(C)]
394 pub struct ChannelHandshakeLimits {
395         /// A pointer to the opaque Rust object.
396
397         /// Nearly everywhere, inner must be non-null, however in places where
398         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
399         pub inner: *mut nativeChannelHandshakeLimits,
400         /// Indicates that this is the only struct which contains the same pointer.
401
402         /// Rust functions which take ownership of an object provided via an argument require
403         /// this to be true and invalidate the object pointed to by inner.
404         pub is_owned: bool,
405 }
406
407 impl Drop for ChannelHandshakeLimits {
408         fn drop(&mut self) {
409                 if self.is_owned && !<*mut nativeChannelHandshakeLimits>::is_null(self.inner) {
410                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
411                 }
412         }
413 }
414 /// Frees any resources used by the ChannelHandshakeLimits, if is_owned is set and inner is non-NULL.
415 #[no_mangle]
416 pub extern "C" fn ChannelHandshakeLimits_free(this_obj: ChannelHandshakeLimits) { }
417 #[allow(unused)]
418 /// Used only if an object of this type is returned as a trait impl by a method
419 pub(crate) extern "C" fn ChannelHandshakeLimits_free_void(this_ptr: *mut c_void) {
420         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelHandshakeLimits); }
421 }
422 #[allow(unused)]
423 impl ChannelHandshakeLimits {
424         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelHandshakeLimits {
425                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
426         }
427         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelHandshakeLimits {
428                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
429         }
430         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
431         pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeLimits {
432                 assert!(self.is_owned);
433                 let ret = ObjOps::untweak_ptr(self.inner);
434                 self.inner = core::ptr::null_mut();
435                 ret
436         }
437 }
438 /// Minimum allowed satoshis when a channel is funded. This is supplied by the sender and so
439 /// only applies to inbound channels.
440 ///
441 /// Default value: 0.
442 #[no_mangle]
443 pub extern "C" fn ChannelHandshakeLimits_get_min_funding_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
444         let mut inner_val = &mut this_ptr.get_native_mut_ref().min_funding_satoshis;
445         *inner_val
446 }
447 /// Minimum allowed satoshis when a channel is funded. This is supplied by the sender and so
448 /// only applies to inbound channels.
449 ///
450 /// Default value: 0.
451 #[no_mangle]
452 pub extern "C" fn ChannelHandshakeLimits_set_min_funding_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
453         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.min_funding_satoshis = val;
454 }
455 /// Maximum allowed satoshis when a channel is funded. This is supplied by the sender and so
456 /// only applies to inbound channels.
457 ///
458 /// Default value: 2^24 - 1.
459 #[no_mangle]
460 pub extern "C" fn ChannelHandshakeLimits_get_max_funding_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
461         let mut inner_val = &mut this_ptr.get_native_mut_ref().max_funding_satoshis;
462         *inner_val
463 }
464 /// Maximum allowed satoshis when a channel is funded. This is supplied by the sender and so
465 /// only applies to inbound channels.
466 ///
467 /// Default value: 2^24 - 1.
468 #[no_mangle]
469 pub extern "C" fn ChannelHandshakeLimits_set_max_funding_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
470         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_funding_satoshis = val;
471 }
472 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
473 /// you to limit the maximum minimum-size they can require.
474 ///
475 /// Default value: u64::max_value.
476 #[no_mangle]
477 pub extern "C" fn ChannelHandshakeLimits_get_max_htlc_minimum_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
478         let mut inner_val = &mut this_ptr.get_native_mut_ref().max_htlc_minimum_msat;
479         *inner_val
480 }
481 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
482 /// you to limit the maximum minimum-size they can require.
483 ///
484 /// Default value: u64::max_value.
485 #[no_mangle]
486 pub extern "C" fn ChannelHandshakeLimits_set_max_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
487         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_htlc_minimum_msat = val;
488 }
489 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
490 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
491 ///
492 /// Default value: 0.
493 #[no_mangle]
494 pub extern "C" fn ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
495         let mut inner_val = &mut this_ptr.get_native_mut_ref().min_max_htlc_value_in_flight_msat;
496         *inner_val
497 }
498 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
499 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
500 ///
501 /// Default value: 0.
502 #[no_mangle]
503 pub extern "C" fn ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
504         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.min_max_htlc_value_in_flight_msat = val;
505 }
506 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
507 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
508 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
509 ///
510 /// Default value: u64::max_value.
511 #[no_mangle]
512 pub extern "C" fn ChannelHandshakeLimits_get_max_channel_reserve_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
513         let mut inner_val = &mut this_ptr.get_native_mut_ref().max_channel_reserve_satoshis;
514         *inner_val
515 }
516 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
517 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
518 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
519 ///
520 /// Default value: u64::max_value.
521 #[no_mangle]
522 pub extern "C" fn ChannelHandshakeLimits_set_max_channel_reserve_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
523         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_channel_reserve_satoshis = val;
524 }
525 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
526 /// time. This allows you to set a minimum such value.
527 ///
528 /// Default value: 0.
529 #[no_mangle]
530 pub extern "C" fn ChannelHandshakeLimits_get_min_max_accepted_htlcs(this_ptr: &ChannelHandshakeLimits) -> u16 {
531         let mut inner_val = &mut this_ptr.get_native_mut_ref().min_max_accepted_htlcs;
532         *inner_val
533 }
534 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
535 /// time. This allows you to set a minimum such value.
536 ///
537 /// Default value: 0.
538 #[no_mangle]
539 pub extern "C" fn ChannelHandshakeLimits_set_min_max_accepted_htlcs(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
540         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.min_max_accepted_htlcs = val;
541 }
542 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
543 /// certain number of blocks, specified by the node which is not the funder (as the funder can
544 /// assume they aren't going to double-spend themselves).
545 /// This config allows you to set a limit on the maximum amount of time to wait.
546 ///
547 /// Default value: 144, or roughly one day and only applies to outbound channels.
548 #[no_mangle]
549 pub extern "C" fn ChannelHandshakeLimits_get_max_minimum_depth(this_ptr: &ChannelHandshakeLimits) -> u32 {
550         let mut inner_val = &mut this_ptr.get_native_mut_ref().max_minimum_depth;
551         *inner_val
552 }
553 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
554 /// certain number of blocks, specified by the node which is not the funder (as the funder can
555 /// assume they aren't going to double-spend themselves).
556 /// This config allows you to set a limit on the maximum amount of time to wait.
557 ///
558 /// Default value: 144, or roughly one day and only applies to outbound channels.
559 #[no_mangle]
560 pub extern "C" fn ChannelHandshakeLimits_set_max_minimum_depth(this_ptr: &mut ChannelHandshakeLimits, mut val: u32) {
561         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_minimum_depth = val;
562 }
563 /// Whether we implicitly trust funding transactions generated by us for our own outbound
564 /// channels to not be double-spent.
565 ///
566 /// If this is set, we assume that our own funding transactions are *never* double-spent, and
567 /// thus we can trust them without any confirmations. This is generally a reasonable
568 /// assumption, given we're the only ones who could ever double-spend it (assuming we have sole
569 /// control of the signing keys).
570 ///
571 /// You may wish to un-set this if you allow the user to (or do in an automated fashion)
572 /// double-spend the funding transaction to RBF with an alternative channel open.
573 ///
574 /// This only applies if our counterparty set their confirmations-required value to 0, and we
575 /// always trust our own funding transaction at 1 confirmation irrespective of this value.
576 /// Thus, this effectively acts as a `min_minimum_depth`, with the only possible values being
577 /// `true` (0) and `false` (1).
578 ///
579 /// Default value: true
580 #[no_mangle]
581 pub extern "C" fn ChannelHandshakeLimits_get_trust_own_funding_0conf(this_ptr: &ChannelHandshakeLimits) -> bool {
582         let mut inner_val = &mut this_ptr.get_native_mut_ref().trust_own_funding_0conf;
583         *inner_val
584 }
585 /// Whether we implicitly trust funding transactions generated by us for our own outbound
586 /// channels to not be double-spent.
587 ///
588 /// If this is set, we assume that our own funding transactions are *never* double-spent, and
589 /// thus we can trust them without any confirmations. This is generally a reasonable
590 /// assumption, given we're the only ones who could ever double-spend it (assuming we have sole
591 /// control of the signing keys).
592 ///
593 /// You may wish to un-set this if you allow the user to (or do in an automated fashion)
594 /// double-spend the funding transaction to RBF with an alternative channel open.
595 ///
596 /// This only applies if our counterparty set their confirmations-required value to 0, and we
597 /// always trust our own funding transaction at 1 confirmation irrespective of this value.
598 /// Thus, this effectively acts as a `min_minimum_depth`, with the only possible values being
599 /// `true` (0) and `false` (1).
600 ///
601 /// Default value: true
602 #[no_mangle]
603 pub extern "C" fn ChannelHandshakeLimits_set_trust_own_funding_0conf(this_ptr: &mut ChannelHandshakeLimits, mut val: bool) {
604         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.trust_own_funding_0conf = val;
605 }
606 /// Set to force an incoming channel to match our announced channel preference in
607 /// [`ChannelHandshakeConfig::announced_channel`].
608 ///
609 /// For a node which is not online reliably, this should be set to true and
610 /// [`ChannelHandshakeConfig::announced_channel`] set to false, ensuring that no announced (aka public)
611 /// channels will ever be opened.
612 ///
613 /// Default value: true.
614 #[no_mangle]
615 pub extern "C" fn ChannelHandshakeLimits_get_force_announced_channel_preference(this_ptr: &ChannelHandshakeLimits) -> bool {
616         let mut inner_val = &mut this_ptr.get_native_mut_ref().force_announced_channel_preference;
617         *inner_val
618 }
619 /// Set to force an incoming channel to match our announced channel preference in
620 /// [`ChannelHandshakeConfig::announced_channel`].
621 ///
622 /// For a node which is not online reliably, this should be set to true and
623 /// [`ChannelHandshakeConfig::announced_channel`] set to false, ensuring that no announced (aka public)
624 /// channels will ever be opened.
625 ///
626 /// Default value: true.
627 #[no_mangle]
628 pub extern "C" fn ChannelHandshakeLimits_set_force_announced_channel_preference(this_ptr: &mut ChannelHandshakeLimits, mut val: bool) {
629         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.force_announced_channel_preference = val;
630 }
631 /// Set to the amount of time we're willing to wait to claim money back to us.
632 ///
633 /// Not checking this value would be a security issue, as our peer would be able to set it to
634 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
635 ///
636 /// Default value: 2016, which we also enforce as a maximum value so you can tweak config to
637 /// reduce the loss of having useless locked funds (if your peer accepts)
638 #[no_mangle]
639 pub extern "C" fn ChannelHandshakeLimits_get_their_to_self_delay(this_ptr: &ChannelHandshakeLimits) -> u16 {
640         let mut inner_val = &mut this_ptr.get_native_mut_ref().their_to_self_delay;
641         *inner_val
642 }
643 /// Set to the amount of time we're willing to wait to claim money back to us.
644 ///
645 /// Not checking this value would be a security issue, as our peer would be able to set it to
646 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
647 ///
648 /// Default value: 2016, which we also enforce as a maximum value so you can tweak config to
649 /// reduce the loss of having useless locked funds (if your peer accepts)
650 #[no_mangle]
651 pub extern "C" fn ChannelHandshakeLimits_set_their_to_self_delay(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
652         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.their_to_self_delay = val;
653 }
654 /// Constructs a new ChannelHandshakeLimits given each field
655 #[must_use]
656 #[no_mangle]
657 pub extern "C" fn ChannelHandshakeLimits_new(mut min_funding_satoshis_arg: u64, mut max_funding_satoshis_arg: u64, mut max_htlc_minimum_msat_arg: u64, mut min_max_htlc_value_in_flight_msat_arg: u64, mut max_channel_reserve_satoshis_arg: u64, mut min_max_accepted_htlcs_arg: u16, mut max_minimum_depth_arg: u32, mut trust_own_funding_0conf_arg: bool, mut force_announced_channel_preference_arg: bool, mut their_to_self_delay_arg: u16) -> ChannelHandshakeLimits {
658         ChannelHandshakeLimits { inner: ObjOps::heap_alloc(nativeChannelHandshakeLimits {
659                 min_funding_satoshis: min_funding_satoshis_arg,
660                 max_funding_satoshis: max_funding_satoshis_arg,
661                 max_htlc_minimum_msat: max_htlc_minimum_msat_arg,
662                 min_max_htlc_value_in_flight_msat: min_max_htlc_value_in_flight_msat_arg,
663                 max_channel_reserve_satoshis: max_channel_reserve_satoshis_arg,
664                 min_max_accepted_htlcs: min_max_accepted_htlcs_arg,
665                 max_minimum_depth: max_minimum_depth_arg,
666                 trust_own_funding_0conf: trust_own_funding_0conf_arg,
667                 force_announced_channel_preference: force_announced_channel_preference_arg,
668                 their_to_self_delay: their_to_self_delay_arg,
669         }), is_owned: true }
670 }
671 impl Clone for ChannelHandshakeLimits {
672         fn clone(&self) -> Self {
673                 Self {
674                         inner: if <*mut nativeChannelHandshakeLimits>::is_null(self.inner) { core::ptr::null_mut() } else {
675                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
676                         is_owned: true,
677                 }
678         }
679 }
680 #[allow(unused)]
681 /// Used only if an object of this type is returned as a trait impl by a method
682 pub(crate) extern "C" fn ChannelHandshakeLimits_clone_void(this_ptr: *const c_void) -> *mut c_void {
683         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeLimits)).clone() })) as *mut c_void
684 }
685 #[no_mangle]
686 /// Creates a copy of the ChannelHandshakeLimits
687 pub extern "C" fn ChannelHandshakeLimits_clone(orig: &ChannelHandshakeLimits) -> ChannelHandshakeLimits {
688         orig.clone()
689 }
690 /// Creates a "default" ChannelHandshakeLimits. See struct and individual field documentaiton for details on which values are used.
691 #[must_use]
692 #[no_mangle]
693 pub extern "C" fn ChannelHandshakeLimits_default() -> ChannelHandshakeLimits {
694         ChannelHandshakeLimits { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
695 }
696
697 use lightning::util::config::ChannelConfig as nativeChannelConfigImport;
698 pub(crate) type nativeChannelConfig = nativeChannelConfigImport;
699
700 /// Options which apply on a per-channel basis and may change at runtime or based on negotiation
701 /// with our counterparty.
702 #[must_use]
703 #[repr(C)]
704 pub struct ChannelConfig {
705         /// A pointer to the opaque Rust object.
706
707         /// Nearly everywhere, inner must be non-null, however in places where
708         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
709         pub inner: *mut nativeChannelConfig,
710         /// Indicates that this is the only struct which contains the same pointer.
711
712         /// Rust functions which take ownership of an object provided via an argument require
713         /// this to be true and invalidate the object pointed to by inner.
714         pub is_owned: bool,
715 }
716
717 impl Drop for ChannelConfig {
718         fn drop(&mut self) {
719                 if self.is_owned && !<*mut nativeChannelConfig>::is_null(self.inner) {
720                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
721                 }
722         }
723 }
724 /// Frees any resources used by the ChannelConfig, if is_owned is set and inner is non-NULL.
725 #[no_mangle]
726 pub extern "C" fn ChannelConfig_free(this_obj: ChannelConfig) { }
727 #[allow(unused)]
728 /// Used only if an object of this type is returned as a trait impl by a method
729 pub(crate) extern "C" fn ChannelConfig_free_void(this_ptr: *mut c_void) {
730         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelConfig); }
731 }
732 #[allow(unused)]
733 impl ChannelConfig {
734         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelConfig {
735                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
736         }
737         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelConfig {
738                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
739         }
740         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
741         pub(crate) fn take_inner(mut self) -> *mut nativeChannelConfig {
742                 assert!(self.is_owned);
743                 let ret = ObjOps::untweak_ptr(self.inner);
744                 self.inner = core::ptr::null_mut();
745                 ret
746         }
747 }
748 /// Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
749 /// over the channel.
750 /// This may be allowed to change at runtime in a later update, however doing so must result in
751 /// update messages sent to notify all nodes of our updated relay fee.
752 ///
753 /// Default value: 0.
754 #[no_mangle]
755 pub extern "C" fn ChannelConfig_get_forwarding_fee_proportional_millionths(this_ptr: &ChannelConfig) -> u32 {
756         let mut inner_val = &mut this_ptr.get_native_mut_ref().forwarding_fee_proportional_millionths;
757         *inner_val
758 }
759 /// Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
760 /// over the channel.
761 /// This may be allowed to change at runtime in a later update, however doing so must result in
762 /// update messages sent to notify all nodes of our updated relay fee.
763 ///
764 /// Default value: 0.
765 #[no_mangle]
766 pub extern "C" fn ChannelConfig_set_forwarding_fee_proportional_millionths(this_ptr: &mut ChannelConfig, mut val: u32) {
767         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.forwarding_fee_proportional_millionths = val;
768 }
769 /// Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, in
770 /// excess of [`forwarding_fee_proportional_millionths`].
771 /// This may be allowed to change at runtime in a later update, however doing so must result in
772 /// update messages sent to notify all nodes of our updated relay fee.
773 ///
774 /// The default value of a single satoshi roughly matches the market rate on many routing nodes
775 /// as of July 2021. Adjusting it upwards or downwards may change whether nodes route through
776 /// this node.
777 ///
778 /// Default value: 1000.
779 ///
780 /// [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
781 #[no_mangle]
782 pub extern "C" fn ChannelConfig_get_forwarding_fee_base_msat(this_ptr: &ChannelConfig) -> u32 {
783         let mut inner_val = &mut this_ptr.get_native_mut_ref().forwarding_fee_base_msat;
784         *inner_val
785 }
786 /// Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, in
787 /// excess of [`forwarding_fee_proportional_millionths`].
788 /// This may be allowed to change at runtime in a later update, however doing so must result in
789 /// update messages sent to notify all nodes of our updated relay fee.
790 ///
791 /// The default value of a single satoshi roughly matches the market rate on many routing nodes
792 /// as of July 2021. Adjusting it upwards or downwards may change whether nodes route through
793 /// this node.
794 ///
795 /// Default value: 1000.
796 ///
797 /// [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
798 #[no_mangle]
799 pub extern "C" fn ChannelConfig_set_forwarding_fee_base_msat(this_ptr: &mut ChannelConfig, mut val: u32) {
800         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.forwarding_fee_base_msat = val;
801 }
802 /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
803 /// the channel this config applies to.
804 ///
805 /// This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
806 /// HTLC balance when a channel appears on-chain whereas
807 /// [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
808 /// (non-HTLC-encumbered) balance.
809 ///
810 /// Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
811 /// we (or one of our watchtowers) MUST be online to check for broadcast of the current
812 /// commitment transaction at least once per this many blocks (minus some margin to allow us
813 /// enough time to broadcast and confirm a transaction, possibly with time in between to RBF
814 /// the spending transaction).
815 ///
816 /// Default value: 72 (12 hours at an average of 6 blocks/hour).
817 /// Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
818 ///                [`MIN_CLTV_EXPIRY_DELTA`] instead.
819 ///
820 /// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
821 #[no_mangle]
822 pub extern "C" fn ChannelConfig_get_cltv_expiry_delta(this_ptr: &ChannelConfig) -> u16 {
823         let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
824         *inner_val
825 }
826 /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
827 /// the channel this config applies to.
828 ///
829 /// This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
830 /// HTLC balance when a channel appears on-chain whereas
831 /// [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
832 /// (non-HTLC-encumbered) balance.
833 ///
834 /// Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
835 /// we (or one of our watchtowers) MUST be online to check for broadcast of the current
836 /// commitment transaction at least once per this many blocks (minus some margin to allow us
837 /// enough time to broadcast and confirm a transaction, possibly with time in between to RBF
838 /// the spending transaction).
839 ///
840 /// Default value: 72 (12 hours at an average of 6 blocks/hour).
841 /// Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
842 ///                [`MIN_CLTV_EXPIRY_DELTA`] instead.
843 ///
844 /// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
845 #[no_mangle]
846 pub extern "C" fn ChannelConfig_set_cltv_expiry_delta(this_ptr: &mut ChannelConfig, mut val: u16) {
847         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
848 }
849 /// Limit our total exposure to in-flight HTLCs which are burned to fees as they are too
850 /// small to claim on-chain.
851 ///
852 /// When an HTLC present in one of our channels is below a \"dust\" threshold, the HTLC will
853 /// not be claimable on-chain, instead being turned into additional miner fees if either
854 /// party force-closes the channel. Because the threshold is per-HTLC, our total exposure
855 /// to such payments may be sustantial if there are many dust HTLCs present when the
856 /// channel is force-closed.
857 ///
858 /// This limit is applied for sent, forwarded, and received HTLCs and limits the total
859 /// exposure across all three types per-channel. Setting this too low may prevent the
860 /// sending or receipt of low-value HTLCs on high-traffic nodes, and this limit is very
861 /// important to prevent stealing of dust HTLCs by miners.
862 ///
863 /// Default value: 5_000_000 msat.
864 #[no_mangle]
865 pub extern "C" fn ChannelConfig_get_max_dust_htlc_exposure_msat(this_ptr: &ChannelConfig) -> u64 {
866         let mut inner_val = &mut this_ptr.get_native_mut_ref().max_dust_htlc_exposure_msat;
867         *inner_val
868 }
869 /// Limit our total exposure to in-flight HTLCs which are burned to fees as they are too
870 /// small to claim on-chain.
871 ///
872 /// When an HTLC present in one of our channels is below a \"dust\" threshold, the HTLC will
873 /// not be claimable on-chain, instead being turned into additional miner fees if either
874 /// party force-closes the channel. Because the threshold is per-HTLC, our total exposure
875 /// to such payments may be sustantial if there are many dust HTLCs present when the
876 /// channel is force-closed.
877 ///
878 /// This limit is applied for sent, forwarded, and received HTLCs and limits the total
879 /// exposure across all three types per-channel. Setting this too low may prevent the
880 /// sending or receipt of low-value HTLCs on high-traffic nodes, and this limit is very
881 /// important to prevent stealing of dust HTLCs by miners.
882 ///
883 /// Default value: 5_000_000 msat.
884 #[no_mangle]
885 pub extern "C" fn ChannelConfig_set_max_dust_htlc_exposure_msat(this_ptr: &mut ChannelConfig, mut val: u64) {
886         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_dust_htlc_exposure_msat = val;
887 }
888 /// The additional fee we're willing to pay to avoid waiting for the counterparty's
889 /// `to_self_delay` to reclaim funds.
890 ///
891 /// When we close a channel cooperatively with our counterparty, we negotiate a fee for the
892 /// closing transaction which both sides find acceptable, ultimately paid by the channel
893 /// funder/initiator.
894 ///
895 /// When we are the funder, because we have to pay the channel closing fee, we bound the
896 /// acceptable fee by our [`Background`] and [`Normal`] fees, with the upper bound increased by
897 /// this value. Because the on-chain fee we'd pay to force-close the channel is kept near our
898 /// [`Normal`] feerate during normal operation, this value represents the additional fee we're
899 /// willing to pay in order to avoid waiting for our counterparty's to_self_delay to reclaim our
900 /// funds.
901 ///
902 /// When we are not the funder, we require the closing transaction fee pay at least our
903 /// [`Background`] fee estimate, but allow our counterparty to pay as much fee as they like.
904 /// Thus, this value is ignored when we are not the funder.
905 ///
906 /// Default value: 1000 satoshis.
907 ///
908 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
909 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
910 #[no_mangle]
911 pub extern "C" fn ChannelConfig_get_force_close_avoidance_max_fee_satoshis(this_ptr: &ChannelConfig) -> u64 {
912         let mut inner_val = &mut this_ptr.get_native_mut_ref().force_close_avoidance_max_fee_satoshis;
913         *inner_val
914 }
915 /// The additional fee we're willing to pay to avoid waiting for the counterparty's
916 /// `to_self_delay` to reclaim funds.
917 ///
918 /// When we close a channel cooperatively with our counterparty, we negotiate a fee for the
919 /// closing transaction which both sides find acceptable, ultimately paid by the channel
920 /// funder/initiator.
921 ///
922 /// When we are the funder, because we have to pay the channel closing fee, we bound the
923 /// acceptable fee by our [`Background`] and [`Normal`] fees, with the upper bound increased by
924 /// this value. Because the on-chain fee we'd pay to force-close the channel is kept near our
925 /// [`Normal`] feerate during normal operation, this value represents the additional fee we're
926 /// willing to pay in order to avoid waiting for our counterparty's to_self_delay to reclaim our
927 /// funds.
928 ///
929 /// When we are not the funder, we require the closing transaction fee pay at least our
930 /// [`Background`] fee estimate, but allow our counterparty to pay as much fee as they like.
931 /// Thus, this value is ignored when we are not the funder.
932 ///
933 /// Default value: 1000 satoshis.
934 ///
935 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
936 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
937 #[no_mangle]
938 pub extern "C" fn ChannelConfig_set_force_close_avoidance_max_fee_satoshis(this_ptr: &mut ChannelConfig, mut val: u64) {
939         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.force_close_avoidance_max_fee_satoshis = val;
940 }
941 /// Constructs a new ChannelConfig given each field
942 #[must_use]
943 #[no_mangle]
944 pub extern "C" fn ChannelConfig_new(mut forwarding_fee_proportional_millionths_arg: u32, mut forwarding_fee_base_msat_arg: u32, mut cltv_expiry_delta_arg: u16, mut max_dust_htlc_exposure_msat_arg: u64, mut force_close_avoidance_max_fee_satoshis_arg: u64) -> ChannelConfig {
945         ChannelConfig { inner: ObjOps::heap_alloc(nativeChannelConfig {
946                 forwarding_fee_proportional_millionths: forwarding_fee_proportional_millionths_arg,
947                 forwarding_fee_base_msat: forwarding_fee_base_msat_arg,
948                 cltv_expiry_delta: cltv_expiry_delta_arg,
949                 max_dust_htlc_exposure_msat: max_dust_htlc_exposure_msat_arg,
950                 force_close_avoidance_max_fee_satoshis: force_close_avoidance_max_fee_satoshis_arg,
951         }), is_owned: true }
952 }
953 impl Clone for ChannelConfig {
954         fn clone(&self) -> Self {
955                 Self {
956                         inner: if <*mut nativeChannelConfig>::is_null(self.inner) { core::ptr::null_mut() } else {
957                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
958                         is_owned: true,
959                 }
960         }
961 }
962 #[allow(unused)]
963 /// Used only if an object of this type is returned as a trait impl by a method
964 pub(crate) extern "C" fn ChannelConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
965         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelConfig)).clone() })) as *mut c_void
966 }
967 #[no_mangle]
968 /// Creates a copy of the ChannelConfig
969 pub extern "C" fn ChannelConfig_clone(orig: &ChannelConfig) -> ChannelConfig {
970         orig.clone()
971 }
972 /// Creates a "default" ChannelConfig. See struct and individual field documentaiton for details on which values are used.
973 #[must_use]
974 #[no_mangle]
975 pub extern "C" fn ChannelConfig_default() -> ChannelConfig {
976         ChannelConfig { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
977 }
978 #[no_mangle]
979 /// Serialize the ChannelConfig object into a byte array which can be read by ChannelConfig_read
980 pub extern "C" fn ChannelConfig_write(obj: &crate::lightning::util::config::ChannelConfig) -> crate::c_types::derived::CVec_u8Z {
981         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
982 }
983 #[no_mangle]
984 pub(crate) extern "C" fn ChannelConfig_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
985         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelConfig) })
986 }
987 #[no_mangle]
988 /// Read a ChannelConfig from a byte array, created by ChannelConfig_write
989 pub extern "C" fn ChannelConfig_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelConfigDecodeErrorZ {
990         let res: Result<lightning::util::config::ChannelConfig, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
991         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::util::config::ChannelConfig { 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() };
992         local_res
993 }
994
995 use lightning::util::config::UserConfig as nativeUserConfigImport;
996 pub(crate) type nativeUserConfig = nativeUserConfigImport;
997
998 /// Top-level config which holds ChannelHandshakeLimits and ChannelConfig.
999 ///
1000 /// Default::default() provides sane defaults for most configurations
1001 /// (but currently with 0 relay fees!)
1002 #[must_use]
1003 #[repr(C)]
1004 pub struct UserConfig {
1005         /// A pointer to the opaque Rust object.
1006
1007         /// Nearly everywhere, inner must be non-null, however in places where
1008         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1009         pub inner: *mut nativeUserConfig,
1010         /// Indicates that this is the only struct which contains the same pointer.
1011
1012         /// Rust functions which take ownership of an object provided via an argument require
1013         /// this to be true and invalidate the object pointed to by inner.
1014         pub is_owned: bool,
1015 }
1016
1017 impl Drop for UserConfig {
1018         fn drop(&mut self) {
1019                 if self.is_owned && !<*mut nativeUserConfig>::is_null(self.inner) {
1020                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1021                 }
1022         }
1023 }
1024 /// Frees any resources used by the UserConfig, if is_owned is set and inner is non-NULL.
1025 #[no_mangle]
1026 pub extern "C" fn UserConfig_free(this_obj: UserConfig) { }
1027 #[allow(unused)]
1028 /// Used only if an object of this type is returned as a trait impl by a method
1029 pub(crate) extern "C" fn UserConfig_free_void(this_ptr: *mut c_void) {
1030         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUserConfig); }
1031 }
1032 #[allow(unused)]
1033 impl UserConfig {
1034         pub(crate) fn get_native_ref(&self) -> &'static nativeUserConfig {
1035                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1036         }
1037         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeUserConfig {
1038                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1039         }
1040         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1041         pub(crate) fn take_inner(mut self) -> *mut nativeUserConfig {
1042                 assert!(self.is_owned);
1043                 let ret = ObjOps::untweak_ptr(self.inner);
1044                 self.inner = core::ptr::null_mut();
1045                 ret
1046         }
1047 }
1048 /// Channel handshake config that we propose to our counterparty.
1049 #[no_mangle]
1050 pub extern "C" fn UserConfig_get_channel_handshake_config(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelHandshakeConfig {
1051         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_handshake_config;
1052         crate::lightning::util::config::ChannelHandshakeConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::util::config::ChannelHandshakeConfig<>) as *mut _) }, is_owned: false }
1053 }
1054 /// Channel handshake config that we propose to our counterparty.
1055 #[no_mangle]
1056 pub extern "C" fn UserConfig_set_channel_handshake_config(this_ptr: &mut UserConfig, mut val: crate::lightning::util::config::ChannelHandshakeConfig) {
1057         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_handshake_config = *unsafe { Box::from_raw(val.take_inner()) };
1058 }
1059 /// Limits applied to our counterparty's proposed channel handshake config settings.
1060 #[no_mangle]
1061 pub extern "C" fn UserConfig_get_channel_handshake_limits(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelHandshakeLimits {
1062         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_handshake_limits;
1063         crate::lightning::util::config::ChannelHandshakeLimits { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::util::config::ChannelHandshakeLimits<>) as *mut _) }, is_owned: false }
1064 }
1065 /// Limits applied to our counterparty's proposed channel handshake config settings.
1066 #[no_mangle]
1067 pub extern "C" fn UserConfig_set_channel_handshake_limits(this_ptr: &mut UserConfig, mut val: crate::lightning::util::config::ChannelHandshakeLimits) {
1068         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_handshake_limits = *unsafe { Box::from_raw(val.take_inner()) };
1069 }
1070 /// Channel config which affects behavior during channel lifetime.
1071 #[no_mangle]
1072 pub extern "C" fn UserConfig_get_channel_config(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelConfig {
1073         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_config;
1074         crate::lightning::util::config::ChannelConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::util::config::ChannelConfig<>) as *mut _) }, is_owned: false }
1075 }
1076 /// Channel config which affects behavior during channel lifetime.
1077 #[no_mangle]
1078 pub extern "C" fn UserConfig_set_channel_config(this_ptr: &mut UserConfig, mut val: crate::lightning::util::config::ChannelConfig) {
1079         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_config = *unsafe { Box::from_raw(val.take_inner()) };
1080 }
1081 /// If this is set to false, we will reject any HTLCs which were to be forwarded over private
1082 /// channels. This prevents us from taking on HTLC-forwarding risk when we intend to run as a
1083 /// node which is not online reliably.
1084 ///
1085 /// For nodes which are not online reliably, you should set all channels to *not* be announced
1086 /// (using [`ChannelHandshakeConfig::announced_channel`] and
1087 /// [`ChannelHandshakeLimits::force_announced_channel_preference`]) and set this to false to
1088 /// ensure you are not exposed to any forwarding risk.
1089 ///
1090 /// Note that because you cannot change a channel's announced state after creation, there is no
1091 /// way to disable forwarding on public channels retroactively. Thus, in order to change a node
1092 /// from a publicly-announced forwarding node to a private non-forwarding node you must close
1093 /// all your channels and open new ones. For privacy, you should also change your node_id
1094 /// (swapping all private and public key material for new ones) at that time.
1095 ///
1096 /// Default value: false.
1097 #[no_mangle]
1098 pub extern "C" fn UserConfig_get_accept_forwards_to_priv_channels(this_ptr: &UserConfig) -> bool {
1099         let mut inner_val = &mut this_ptr.get_native_mut_ref().accept_forwards_to_priv_channels;
1100         *inner_val
1101 }
1102 /// If this is set to false, we will reject any HTLCs which were to be forwarded over private
1103 /// channels. This prevents us from taking on HTLC-forwarding risk when we intend to run as a
1104 /// node which is not online reliably.
1105 ///
1106 /// For nodes which are not online reliably, you should set all channels to *not* be announced
1107 /// (using [`ChannelHandshakeConfig::announced_channel`] and
1108 /// [`ChannelHandshakeLimits::force_announced_channel_preference`]) and set this to false to
1109 /// ensure you are not exposed to any forwarding risk.
1110 ///
1111 /// Note that because you cannot change a channel's announced state after creation, there is no
1112 /// way to disable forwarding on public channels retroactively. Thus, in order to change a node
1113 /// from a publicly-announced forwarding node to a private non-forwarding node you must close
1114 /// all your channels and open new ones. For privacy, you should also change your node_id
1115 /// (swapping all private and public key material for new ones) at that time.
1116 ///
1117 /// Default value: false.
1118 #[no_mangle]
1119 pub extern "C" fn UserConfig_set_accept_forwards_to_priv_channels(this_ptr: &mut UserConfig, mut val: bool) {
1120         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.accept_forwards_to_priv_channels = val;
1121 }
1122 /// If this is set to false, we do not accept inbound requests to open a new channel.
1123 /// Default value: true.
1124 #[no_mangle]
1125 pub extern "C" fn UserConfig_get_accept_inbound_channels(this_ptr: &UserConfig) -> bool {
1126         let mut inner_val = &mut this_ptr.get_native_mut_ref().accept_inbound_channels;
1127         *inner_val
1128 }
1129 /// If this is set to false, we do not accept inbound requests to open a new channel.
1130 /// Default value: true.
1131 #[no_mangle]
1132 pub extern "C" fn UserConfig_set_accept_inbound_channels(this_ptr: &mut UserConfig, mut val: bool) {
1133         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.accept_inbound_channels = val;
1134 }
1135 /// If this is set to true, the user needs to manually accept inbound requests to open a new
1136 /// channel.
1137 ///
1138 /// When set to true, [`Event::OpenChannelRequest`] will be triggered once a request to open a
1139 /// new inbound channel is received through a [`msgs::OpenChannel`] message. In that case, a
1140 /// [`msgs::AcceptChannel`] message will not be sent back to the counterparty node unless the
1141 /// user explicitly chooses to accept the request.
1142 ///
1143 /// Default value: false.
1144 ///
1145 /// [`Event::OpenChannelRequest`]: crate::util::events::Event::OpenChannelRequest
1146 /// [`msgs::OpenChannel`]: crate::ln::msgs::OpenChannel
1147 /// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
1148 #[no_mangle]
1149 pub extern "C" fn UserConfig_get_manually_accept_inbound_channels(this_ptr: &UserConfig) -> bool {
1150         let mut inner_val = &mut this_ptr.get_native_mut_ref().manually_accept_inbound_channels;
1151         *inner_val
1152 }
1153 /// If this is set to true, the user needs to manually accept inbound requests to open a new
1154 /// channel.
1155 ///
1156 /// When set to true, [`Event::OpenChannelRequest`] will be triggered once a request to open a
1157 /// new inbound channel is received through a [`msgs::OpenChannel`] message. In that case, a
1158 /// [`msgs::AcceptChannel`] message will not be sent back to the counterparty node unless the
1159 /// user explicitly chooses to accept the request.
1160 ///
1161 /// Default value: false.
1162 ///
1163 /// [`Event::OpenChannelRequest`]: crate::util::events::Event::OpenChannelRequest
1164 /// [`msgs::OpenChannel`]: crate::ln::msgs::OpenChannel
1165 /// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
1166 #[no_mangle]
1167 pub extern "C" fn UserConfig_set_manually_accept_inbound_channels(this_ptr: &mut UserConfig, mut val: bool) {
1168         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.manually_accept_inbound_channels = val;
1169 }
1170 /// Constructs a new UserConfig given each field
1171 #[must_use]
1172 #[no_mangle]
1173 pub extern "C" fn UserConfig_new(mut channel_handshake_config_arg: crate::lightning::util::config::ChannelHandshakeConfig, mut channel_handshake_limits_arg: crate::lightning::util::config::ChannelHandshakeLimits, mut channel_config_arg: crate::lightning::util::config::ChannelConfig, mut accept_forwards_to_priv_channels_arg: bool, mut accept_inbound_channels_arg: bool, mut manually_accept_inbound_channels_arg: bool) -> UserConfig {
1174         UserConfig { inner: ObjOps::heap_alloc(nativeUserConfig {
1175                 channel_handshake_config: *unsafe { Box::from_raw(channel_handshake_config_arg.take_inner()) },
1176                 channel_handshake_limits: *unsafe { Box::from_raw(channel_handshake_limits_arg.take_inner()) },
1177                 channel_config: *unsafe { Box::from_raw(channel_config_arg.take_inner()) },
1178                 accept_forwards_to_priv_channels: accept_forwards_to_priv_channels_arg,
1179                 accept_inbound_channels: accept_inbound_channels_arg,
1180                 manually_accept_inbound_channels: manually_accept_inbound_channels_arg,
1181         }), is_owned: true }
1182 }
1183 impl Clone for UserConfig {
1184         fn clone(&self) -> Self {
1185                 Self {
1186                         inner: if <*mut nativeUserConfig>::is_null(self.inner) { core::ptr::null_mut() } else {
1187                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1188                         is_owned: true,
1189                 }
1190         }
1191 }
1192 #[allow(unused)]
1193 /// Used only if an object of this type is returned as a trait impl by a method
1194 pub(crate) extern "C" fn UserConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
1195         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUserConfig)).clone() })) as *mut c_void
1196 }
1197 #[no_mangle]
1198 /// Creates a copy of the UserConfig
1199 pub extern "C" fn UserConfig_clone(orig: &UserConfig) -> UserConfig {
1200         orig.clone()
1201 }
1202 /// Creates a "default" UserConfig. See struct and individual field documentaiton for details on which values are used.
1203 #[must_use]
1204 #[no_mangle]
1205 pub extern "C" fn UserConfig_default() -> UserConfig {
1206         UserConfig { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
1207 }