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