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