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