Update auto-generated bindings with lightning-invoice
[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(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 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
56 impl ChannelHandshakeConfig {
57         pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeConfig {
58                 assert!(self.is_owned);
59                 let ret = self.inner;
60                 self.inner = std::ptr::null_mut();
61                 ret
62         }
63 }
64 /// Confirmations we will wait for before considering the channel locked in.
65 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
66 /// equivalent limit applied to outbound channels).
67 ///
68 /// Default value: 6.
69 #[no_mangle]
70 pub extern "C" fn ChannelHandshakeConfig_get_minimum_depth(this_ptr: &ChannelHandshakeConfig) -> u32 {
71         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.minimum_depth;
72         *inner_val
73 }
74 /// Confirmations we will wait for before considering the channel locked in.
75 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
76 /// equivalent limit applied to outbound channels).
77 ///
78 /// Default value: 6.
79 #[no_mangle]
80 pub extern "C" fn ChannelHandshakeConfig_set_minimum_depth(this_ptr: &mut ChannelHandshakeConfig, mut val: u32) {
81         unsafe { &mut *this_ptr.inner }.minimum_depth = val;
82 }
83 /// Set to the number of blocks we require our counterparty to wait to claim their money (ie
84 /// the number of blocks we have to punish our counterparty if they broadcast a revoked
85 /// transaction).
86 ///
87 /// This is one of the main parameters of our security model. We (or one of our watchtowers) MUST
88 /// be online to check for revoked transactions on-chain at least once every our_to_self_delay
89 /// blocks (minus some margin to allow us enough time to broadcast and confirm a transaction,
90 /// possibly with time in between to RBF the spending transaction).
91 ///
92 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
93 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
94 /// our channel.
95 ///
96 /// Default value: [`BREAKDOWN_TIMEOUT`], we enforce it as a minimum at channel opening so you
97 /// can tweak config to ask for more security, not less.
98 #[no_mangle]
99 pub extern "C" fn ChannelHandshakeConfig_get_our_to_self_delay(this_ptr: &ChannelHandshakeConfig) -> u16 {
100         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.our_to_self_delay;
101         *inner_val
102 }
103 /// Set to the number of blocks we require our counterparty to wait to claim their money (ie
104 /// the number of blocks we have to punish our counterparty if they broadcast a revoked
105 /// transaction).
106 ///
107 /// This is one of the main parameters of our security model. We (or one of our watchtowers) MUST
108 /// be online to check for revoked transactions on-chain at least once every our_to_self_delay
109 /// blocks (minus some margin to allow us enough time to broadcast and confirm a transaction,
110 /// possibly with time in between to RBF the spending transaction).
111 ///
112 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
113 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
114 /// our channel.
115 ///
116 /// Default value: [`BREAKDOWN_TIMEOUT`], we enforce it as a minimum at channel opening so you
117 /// can tweak config to ask for more security, not less.
118 #[no_mangle]
119 pub extern "C" fn ChannelHandshakeConfig_set_our_to_self_delay(this_ptr: &mut ChannelHandshakeConfig, mut val: u16) {
120         unsafe { &mut *this_ptr.inner }.our_to_self_delay = val;
121 }
122 /// Set to the smallest value HTLC we will accept to process.
123 ///
124 /// This value is sent to our counterparty on channel-open and we close the channel any time
125 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
126 ///
127 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
128 /// by the protocol.
129 #[no_mangle]
130 pub extern "C" fn ChannelHandshakeConfig_get_our_htlc_minimum_msat(this_ptr: &ChannelHandshakeConfig) -> u64 {
131         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.our_htlc_minimum_msat;
132         *inner_val
133 }
134 /// Set to the smallest value HTLC we will accept to process.
135 ///
136 /// This value is sent to our counterparty on channel-open and we close the channel any time
137 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
138 ///
139 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
140 /// by the protocol.
141 #[no_mangle]
142 pub extern "C" fn ChannelHandshakeConfig_set_our_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeConfig, mut val: u64) {
143         unsafe { &mut *this_ptr.inner }.our_htlc_minimum_msat = val;
144 }
145 /// Constructs a new ChannelHandshakeConfig given each field
146 #[must_use]
147 #[no_mangle]
148 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 {
149         ChannelHandshakeConfig { inner: Box::into_raw(Box::new(nativeChannelHandshakeConfig {
150                 minimum_depth: minimum_depth_arg,
151                 our_to_self_delay: our_to_self_delay_arg,
152                 our_htlc_minimum_msat: our_htlc_minimum_msat_arg,
153         })), is_owned: true }
154 }
155 impl Clone for ChannelHandshakeConfig {
156         fn clone(&self) -> Self {
157                 Self {
158                         inner: if <*mut nativeChannelHandshakeConfig>::is_null(self.inner) { std::ptr::null_mut() } else {
159                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
160                         is_owned: true,
161                 }
162         }
163 }
164 #[allow(unused)]
165 /// Used only if an object of this type is returned as a trait impl by a method
166 pub(crate) extern "C" fn ChannelHandshakeConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
167         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeConfig)).clone() })) as *mut c_void
168 }
169 #[no_mangle]
170 /// Creates a copy of the ChannelHandshakeConfig
171 pub extern "C" fn ChannelHandshakeConfig_clone(orig: &ChannelHandshakeConfig) -> ChannelHandshakeConfig {
172         orig.clone()
173 }
174 /// Creates a "default" ChannelHandshakeConfig. See struct and individual field documentaiton for details on which values are used.
175 #[must_use]
176 #[no_mangle]
177 pub extern "C" fn ChannelHandshakeConfig_default() -> ChannelHandshakeConfig {
178         ChannelHandshakeConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
179 }
180
181 use lightning::util::config::ChannelHandshakeLimits as nativeChannelHandshakeLimitsImport;
182 type nativeChannelHandshakeLimits = nativeChannelHandshakeLimitsImport;
183
184 /// Optional channel limits which are applied during channel creation.
185 ///
186 /// These limits are only applied to our counterparty's limits, not our own.
187 ///
188 /// Use 0/<type>::max_value() as appropriate to skip checking.
189 ///
190 /// Provides sane defaults for most configurations.
191 ///
192 /// Most additional limits are disabled except those with which specify a default in individual
193 /// field documentation. Note that this may result in barely-usable channels, but since they
194 /// are applied mostly only to incoming channels that's not much of a problem.
195 #[must_use]
196 #[repr(C)]
197 pub struct ChannelHandshakeLimits {
198         /// A pointer to the opaque Rust object.
199
200         /// Nearly everywhere, inner must be non-null, however in places where
201         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
202         pub inner: *mut nativeChannelHandshakeLimits,
203         /// Indicates that this is the only struct which contains the same pointer.
204
205         /// Rust functions which take ownership of an object provided via an argument require
206         /// this to be true and invalidate the object pointed to by inner.
207         pub is_owned: bool,
208 }
209
210 impl Drop for ChannelHandshakeLimits {
211         fn drop(&mut self) {
212                 if self.is_owned && !<*mut nativeChannelHandshakeLimits>::is_null(self.inner) {
213                         let _ = unsafe { Box::from_raw(self.inner) };
214                 }
215         }
216 }
217 /// Frees any resources used by the ChannelHandshakeLimits, if is_owned is set and inner is non-NULL.
218 #[no_mangle]
219 pub extern "C" fn ChannelHandshakeLimits_free(this_obj: ChannelHandshakeLimits) { }
220 #[allow(unused)]
221 /// Used only if an object of this type is returned as a trait impl by a method
222 extern "C" fn ChannelHandshakeLimits_free_void(this_ptr: *mut c_void) {
223         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelHandshakeLimits); }
224 }
225 #[allow(unused)]
226 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
227 impl ChannelHandshakeLimits {
228         pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeLimits {
229                 assert!(self.is_owned);
230                 let ret = self.inner;
231                 self.inner = std::ptr::null_mut();
232                 ret
233         }
234 }
235 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
236 /// only applies to inbound channels.
237 ///
238 /// Default value: 0.
239 #[no_mangle]
240 pub extern "C" fn ChannelHandshakeLimits_get_min_funding_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
241         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_funding_satoshis;
242         *inner_val
243 }
244 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
245 /// only applies to inbound channels.
246 ///
247 /// Default value: 0.
248 #[no_mangle]
249 pub extern "C" fn ChannelHandshakeLimits_set_min_funding_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
250         unsafe { &mut *this_ptr.inner }.min_funding_satoshis = val;
251 }
252 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
253 /// you to limit the maximum minimum-size they can require.
254 ///
255 /// Default value: u64::max_value.
256 #[no_mangle]
257 pub extern "C" fn ChannelHandshakeLimits_get_max_htlc_minimum_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
258         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_htlc_minimum_msat;
259         *inner_val
260 }
261 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
262 /// you to limit the maximum minimum-size they can require.
263 ///
264 /// Default value: u64::max_value.
265 #[no_mangle]
266 pub extern "C" fn ChannelHandshakeLimits_set_max_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
267         unsafe { &mut *this_ptr.inner }.max_htlc_minimum_msat = val;
268 }
269 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
270 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
271 ///
272 /// Default value: 0.
273 #[no_mangle]
274 pub extern "C" fn ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
275         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_max_htlc_value_in_flight_msat;
276         *inner_val
277 }
278 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
279 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
280 ///
281 /// Default value: 0.
282 #[no_mangle]
283 pub extern "C" fn ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
284         unsafe { &mut *this_ptr.inner }.min_max_htlc_value_in_flight_msat = val;
285 }
286 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
287 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
288 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
289 ///
290 /// Default value: u64::max_value.
291 #[no_mangle]
292 pub extern "C" fn ChannelHandshakeLimits_get_max_channel_reserve_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
293         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_channel_reserve_satoshis;
294         *inner_val
295 }
296 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
297 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
298 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
299 ///
300 /// Default value: u64::max_value.
301 #[no_mangle]
302 pub extern "C" fn ChannelHandshakeLimits_set_max_channel_reserve_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
303         unsafe { &mut *this_ptr.inner }.max_channel_reserve_satoshis = val;
304 }
305 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
306 /// time. This allows you to set a minimum such value.
307 ///
308 /// Default value: 0.
309 #[no_mangle]
310 pub extern "C" fn ChannelHandshakeLimits_get_min_max_accepted_htlcs(this_ptr: &ChannelHandshakeLimits) -> u16 {
311         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_max_accepted_htlcs;
312         *inner_val
313 }
314 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
315 /// time. This allows you to set a minimum such value.
316 ///
317 /// Default value: 0.
318 #[no_mangle]
319 pub extern "C" fn ChannelHandshakeLimits_set_min_max_accepted_htlcs(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
320         unsafe { &mut *this_ptr.inner }.min_max_accepted_htlcs = val;
321 }
322 /// Outputs below a certain value will not be added to on-chain transactions. The dust value is
323 /// required to always be higher than this value so this only applies to HTLC outputs (and
324 /// potentially to-self outputs before any payments have been made).
325 /// Thus, HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
326 /// This setting allows you to set a minimum dust limit for their commitment transactions,
327 /// reflecting the reality that tiny outputs are not considered standard transactions and will
328 /// not propagate through the Bitcoin network.
329 ///
330 /// Default value: 546, the current dust limit on the Bitcoin network.
331 #[no_mangle]
332 pub extern "C" fn ChannelHandshakeLimits_get_min_dust_limit_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
333         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_dust_limit_satoshis;
334         *inner_val
335 }
336 /// Outputs below a certain value will not be added to on-chain transactions. The dust value is
337 /// required to always be higher than this value so this only applies to HTLC outputs (and
338 /// potentially to-self outputs before any payments have been made).
339 /// Thus, HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
340 /// This setting allows you to set a minimum dust limit for their commitment transactions,
341 /// reflecting the reality that tiny outputs are not considered standard transactions and will
342 /// not propagate through the Bitcoin network.
343 ///
344 /// Default value: 546, the current dust limit on the Bitcoin network.
345 #[no_mangle]
346 pub extern "C" fn ChannelHandshakeLimits_set_min_dust_limit_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
347         unsafe { &mut *this_ptr.inner }.min_dust_limit_satoshis = val;
348 }
349 /// Maximum allowed threshold above which outputs will not be generated in their commitment
350 /// transactions.
351 /// HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
352 ///
353 /// Default value: u64::max_value.
354 #[no_mangle]
355 pub extern "C" fn ChannelHandshakeLimits_get_max_dust_limit_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
356         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_dust_limit_satoshis;
357         *inner_val
358 }
359 /// Maximum allowed threshold above which outputs will not be generated in their commitment
360 /// transactions.
361 /// HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
362 ///
363 /// Default value: u64::max_value.
364 #[no_mangle]
365 pub extern "C" fn ChannelHandshakeLimits_set_max_dust_limit_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
366         unsafe { &mut *this_ptr.inner }.max_dust_limit_satoshis = val;
367 }
368 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
369 /// certain number of blocks, specified by the node which is not the funder (as the funder can
370 /// assume they aren't going to double-spend themselves).
371 /// This config allows you to set a limit on the maximum amount of time to wait.
372 ///
373 /// Default value: 144, or roughly one day and only applies to outbound channels.
374 #[no_mangle]
375 pub extern "C" fn ChannelHandshakeLimits_get_max_minimum_depth(this_ptr: &ChannelHandshakeLimits) -> u32 {
376         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_minimum_depth;
377         *inner_val
378 }
379 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
380 /// certain number of blocks, specified by the node which is not the funder (as the funder can
381 /// assume they aren't going to double-spend themselves).
382 /// This config allows you to set a limit on the maximum amount of time to wait.
383 ///
384 /// Default value: 144, or roughly one day and only applies to outbound channels.
385 #[no_mangle]
386 pub extern "C" fn ChannelHandshakeLimits_set_max_minimum_depth(this_ptr: &mut ChannelHandshakeLimits, mut val: u32) {
387         unsafe { &mut *this_ptr.inner }.max_minimum_depth = val;
388 }
389 /// Set to force the incoming channel to match our announced channel preference in
390 /// ChannelConfig.
391 ///
392 /// Default value: true, to make the default that no announced channels are possible (which is
393 /// appropriate for any nodes which are not online very reliably).
394 #[no_mangle]
395 pub extern "C" fn ChannelHandshakeLimits_get_force_announced_channel_preference(this_ptr: &ChannelHandshakeLimits) -> bool {
396         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.force_announced_channel_preference;
397         *inner_val
398 }
399 /// Set to force the incoming channel to match our announced channel preference in
400 /// ChannelConfig.
401 ///
402 /// Default value: true, to make the default that no announced channels are possible (which is
403 /// appropriate for any nodes which are not online very reliably).
404 #[no_mangle]
405 pub extern "C" fn ChannelHandshakeLimits_set_force_announced_channel_preference(this_ptr: &mut ChannelHandshakeLimits, mut val: bool) {
406         unsafe { &mut *this_ptr.inner }.force_announced_channel_preference = val;
407 }
408 /// Set to the amount of time we're willing to wait to claim money back to us.
409 ///
410 /// Not checking this value would be a security issue, as our peer would be able to set it to
411 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
412 ///
413 /// Default value: 2016, which we also enforce as a maximum value so you can tweak config to
414 /// reduce the loss of having useless locked funds (if your peer accepts)
415 #[no_mangle]
416 pub extern "C" fn ChannelHandshakeLimits_get_their_to_self_delay(this_ptr: &ChannelHandshakeLimits) -> u16 {
417         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.their_to_self_delay;
418         *inner_val
419 }
420 /// Set to the amount of time we're willing to wait to claim money back to us.
421 ///
422 /// Not checking this value would be a security issue, as our peer would be able to set it to
423 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
424 ///
425 /// Default value: 2016, which we also enforce as a maximum value so you can tweak config to
426 /// reduce the loss of having useless locked funds (if your peer accepts)
427 #[no_mangle]
428 pub extern "C" fn ChannelHandshakeLimits_set_their_to_self_delay(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
429         unsafe { &mut *this_ptr.inner }.their_to_self_delay = val;
430 }
431 /// Constructs a new ChannelHandshakeLimits given each field
432 #[must_use]
433 #[no_mangle]
434 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 min_dust_limit_satoshis_arg: u64, mut max_dust_limit_satoshis_arg: u64, mut max_minimum_depth_arg: u32, mut force_announced_channel_preference_arg: bool, mut their_to_self_delay_arg: u16) -> ChannelHandshakeLimits {
435         ChannelHandshakeLimits { inner: Box::into_raw(Box::new(nativeChannelHandshakeLimits {
436                 min_funding_satoshis: min_funding_satoshis_arg,
437                 max_htlc_minimum_msat: max_htlc_minimum_msat_arg,
438                 min_max_htlc_value_in_flight_msat: min_max_htlc_value_in_flight_msat_arg,
439                 max_channel_reserve_satoshis: max_channel_reserve_satoshis_arg,
440                 min_max_accepted_htlcs: min_max_accepted_htlcs_arg,
441                 min_dust_limit_satoshis: min_dust_limit_satoshis_arg,
442                 max_dust_limit_satoshis: max_dust_limit_satoshis_arg,
443                 max_minimum_depth: max_minimum_depth_arg,
444                 force_announced_channel_preference: force_announced_channel_preference_arg,
445                 their_to_self_delay: their_to_self_delay_arg,
446         })), is_owned: true }
447 }
448 impl Clone for ChannelHandshakeLimits {
449         fn clone(&self) -> Self {
450                 Self {
451                         inner: if <*mut nativeChannelHandshakeLimits>::is_null(self.inner) { std::ptr::null_mut() } else {
452                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
453                         is_owned: true,
454                 }
455         }
456 }
457 #[allow(unused)]
458 /// Used only if an object of this type is returned as a trait impl by a method
459 pub(crate) extern "C" fn ChannelHandshakeLimits_clone_void(this_ptr: *const c_void) -> *mut c_void {
460         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeLimits)).clone() })) as *mut c_void
461 }
462 #[no_mangle]
463 /// Creates a copy of the ChannelHandshakeLimits
464 pub extern "C" fn ChannelHandshakeLimits_clone(orig: &ChannelHandshakeLimits) -> ChannelHandshakeLimits {
465         orig.clone()
466 }
467 /// Creates a "default" ChannelHandshakeLimits. See struct and individual field documentaiton for details on which values are used.
468 #[must_use]
469 #[no_mangle]
470 pub extern "C" fn ChannelHandshakeLimits_default() -> ChannelHandshakeLimits {
471         ChannelHandshakeLimits { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
472 }
473
474 use lightning::util::config::ChannelConfig as nativeChannelConfigImport;
475 type nativeChannelConfig = nativeChannelConfigImport;
476
477 /// Options which apply on a per-channel basis and may change at runtime or based on negotiation
478 /// with our counterparty.
479 #[must_use]
480 #[repr(C)]
481 pub struct ChannelConfig {
482         /// A pointer to the opaque Rust object.
483
484         /// Nearly everywhere, inner must be non-null, however in places where
485         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
486         pub inner: *mut nativeChannelConfig,
487         /// Indicates that this is the only struct which contains the same pointer.
488
489         /// Rust functions which take ownership of an object provided via an argument require
490         /// this to be true and invalidate the object pointed to by inner.
491         pub is_owned: bool,
492 }
493
494 impl Drop for ChannelConfig {
495         fn drop(&mut self) {
496                 if self.is_owned && !<*mut nativeChannelConfig>::is_null(self.inner) {
497                         let _ = unsafe { Box::from_raw(self.inner) };
498                 }
499         }
500 }
501 /// Frees any resources used by the ChannelConfig, if is_owned is set and inner is non-NULL.
502 #[no_mangle]
503 pub extern "C" fn ChannelConfig_free(this_obj: ChannelConfig) { }
504 #[allow(unused)]
505 /// Used only if an object of this type is returned as a trait impl by a method
506 extern "C" fn ChannelConfig_free_void(this_ptr: *mut c_void) {
507         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelConfig); }
508 }
509 #[allow(unused)]
510 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
511 impl ChannelConfig {
512         pub(crate) fn take_inner(mut self) -> *mut nativeChannelConfig {
513                 assert!(self.is_owned);
514                 let ret = self.inner;
515                 self.inner = std::ptr::null_mut();
516                 ret
517         }
518 }
519 /// Amount (in millionths of a satoshi) the channel will charge per transferred satoshi.
520 /// This may be allowed to change at runtime in a later update, however doing so must result in
521 /// update messages sent to notify all nodes of our updated relay fee.
522 ///
523 /// Default value: 0.
524 #[no_mangle]
525 pub extern "C" fn ChannelConfig_get_fee_proportional_millionths(this_ptr: &ChannelConfig) -> u32 {
526         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fee_proportional_millionths;
527         *inner_val
528 }
529 /// Amount (in millionths of a satoshi) the channel will charge per transferred satoshi.
530 /// This may be allowed to change at runtime in a later update, however doing so must result in
531 /// update messages sent to notify all nodes of our updated relay fee.
532 ///
533 /// Default value: 0.
534 #[no_mangle]
535 pub extern "C" fn ChannelConfig_set_fee_proportional_millionths(this_ptr: &mut ChannelConfig, mut val: u32) {
536         unsafe { &mut *this_ptr.inner }.fee_proportional_millionths = val;
537 }
538 /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
539 /// the channel this config applies to.
540 ///
541 /// This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
542 /// HTLC balance when a channel appears on-chain whereas
543 /// [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
544 /// (non-HTLC-encumbered) balance.
545 ///
546 /// Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
547 /// we (or one of our watchtowers) MUST be online to check for broadcast of the current
548 /// commitment transaction at least once per this many blocks (minus some margin to allow us
549 /// enough time to broadcast and confirm a transaction, possibly with time in between to RBF
550 /// the spending transaction).
551 ///
552 /// Default value: 72 (12 hours at an average of 6 blocks/hour).
553 /// Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
554 ///                [`MIN_CLTV_EXPIRY_DELTA`] instead.
555 ///
556 /// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
557 #[no_mangle]
558 pub extern "C" fn ChannelConfig_get_cltv_expiry_delta(this_ptr: &ChannelConfig) -> u16 {
559         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry_delta;
560         *inner_val
561 }
562 /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
563 /// the channel this config applies to.
564 ///
565 /// This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
566 /// HTLC balance when a channel appears on-chain whereas
567 /// [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
568 /// (non-HTLC-encumbered) balance.
569 ///
570 /// Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
571 /// we (or one of our watchtowers) MUST be online to check for broadcast of the current
572 /// commitment transaction at least once per this many blocks (minus some margin to allow us
573 /// enough time to broadcast and confirm a transaction, possibly with time in between to RBF
574 /// the spending transaction).
575 ///
576 /// Default value: 72 (12 hours at an average of 6 blocks/hour).
577 /// Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
578 ///                [`MIN_CLTV_EXPIRY_DELTA`] instead.
579 ///
580 /// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
581 #[no_mangle]
582 pub extern "C" fn ChannelConfig_set_cltv_expiry_delta(this_ptr: &mut ChannelConfig, mut val: u16) {
583         unsafe { &mut *this_ptr.inner }.cltv_expiry_delta = val;
584 }
585 /// Set to announce the channel publicly and notify all nodes that they can route via this
586 /// channel.
587 ///
588 /// This should only be set to true for nodes which expect to be online reliably.
589 ///
590 /// As the node which funds a channel picks this value this will only apply for new outbound
591 /// channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set.
592 ///
593 /// This cannot be changed after the initial channel handshake.
594 ///
595 /// Default value: false.
596 #[no_mangle]
597 pub extern "C" fn ChannelConfig_get_announced_channel(this_ptr: &ChannelConfig) -> bool {
598         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announced_channel;
599         *inner_val
600 }
601 /// Set to announce the channel publicly and notify all nodes that they can route via this
602 /// channel.
603 ///
604 /// This should only be set to true for nodes which expect to be online reliably.
605 ///
606 /// As the node which funds a channel picks this value this will only apply for new outbound
607 /// channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set.
608 ///
609 /// This cannot be changed after the initial channel handshake.
610 ///
611 /// Default value: false.
612 #[no_mangle]
613 pub extern "C" fn ChannelConfig_set_announced_channel(this_ptr: &mut ChannelConfig, mut val: bool) {
614         unsafe { &mut *this_ptr.inner }.announced_channel = val;
615 }
616 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
617 /// supports it, they will then enforce the mutual-close output to us matches what we provided
618 /// at intialization, preventing us from closing to an alternate pubkey.
619 ///
620 /// This is set to true by default to provide a slight increase in security, though ultimately
621 /// any attacker who is able to take control of a channel can just as easily send the funds via
622 /// lightning payments, so we never require that our counterparties support this option.
623 ///
624 /// This cannot be changed after a channel has been initialized.
625 ///
626 /// Default value: true.
627 #[no_mangle]
628 pub extern "C" fn ChannelConfig_get_commit_upfront_shutdown_pubkey(this_ptr: &ChannelConfig) -> bool {
629         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.commit_upfront_shutdown_pubkey;
630         *inner_val
631 }
632 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
633 /// supports it, they will then enforce the mutual-close output to us matches what we provided
634 /// at intialization, preventing us from closing to an alternate pubkey.
635 ///
636 /// This is set to true by default to provide a slight increase in security, though ultimately
637 /// any attacker who is able to take control of a channel can just as easily send the funds via
638 /// lightning payments, so we never require that our counterparties support this option.
639 ///
640 /// This cannot be changed after a channel has been initialized.
641 ///
642 /// Default value: true.
643 #[no_mangle]
644 pub extern "C" fn ChannelConfig_set_commit_upfront_shutdown_pubkey(this_ptr: &mut ChannelConfig, mut val: bool) {
645         unsafe { &mut *this_ptr.inner }.commit_upfront_shutdown_pubkey = val;
646 }
647 /// Constructs a new ChannelConfig given each field
648 #[must_use]
649 #[no_mangle]
650 pub extern "C" fn ChannelConfig_new(mut fee_proportional_millionths_arg: u32, mut cltv_expiry_delta_arg: u16, mut announced_channel_arg: bool, mut commit_upfront_shutdown_pubkey_arg: bool) -> ChannelConfig {
651         ChannelConfig { inner: Box::into_raw(Box::new(nativeChannelConfig {
652                 fee_proportional_millionths: fee_proportional_millionths_arg,
653                 cltv_expiry_delta: cltv_expiry_delta_arg,
654                 announced_channel: announced_channel_arg,
655                 commit_upfront_shutdown_pubkey: commit_upfront_shutdown_pubkey_arg,
656         })), is_owned: true }
657 }
658 impl Clone for ChannelConfig {
659         fn clone(&self) -> Self {
660                 Self {
661                         inner: if <*mut nativeChannelConfig>::is_null(self.inner) { std::ptr::null_mut() } else {
662                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
663                         is_owned: true,
664                 }
665         }
666 }
667 #[allow(unused)]
668 /// Used only if an object of this type is returned as a trait impl by a method
669 pub(crate) extern "C" fn ChannelConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
670         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelConfig)).clone() })) as *mut c_void
671 }
672 #[no_mangle]
673 /// Creates a copy of the ChannelConfig
674 pub extern "C" fn ChannelConfig_clone(orig: &ChannelConfig) -> ChannelConfig {
675         orig.clone()
676 }
677 /// Creates a "default" ChannelConfig. See struct and individual field documentaiton for details on which values are used.
678 #[must_use]
679 #[no_mangle]
680 pub extern "C" fn ChannelConfig_default() -> ChannelConfig {
681         ChannelConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
682 }
683 #[no_mangle]
684 /// Serialize the ChannelConfig object into a byte array which can be read by ChannelConfig_read
685 pub extern "C" fn ChannelConfig_write(obj: &ChannelConfig) -> crate::c_types::derived::CVec_u8Z {
686         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
687 }
688 #[no_mangle]
689 pub(crate) extern "C" fn ChannelConfig_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
690         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelConfig) })
691 }
692 #[no_mangle]
693 /// Read a ChannelConfig from a byte array, created by ChannelConfig_write
694 pub extern "C" fn ChannelConfig_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelConfigDecodeErrorZ {
695         let res = crate::c_types::deserialize_obj(ser);
696         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::util::config::ChannelConfig { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
697         local_res
698 }
699
700 use lightning::util::config::UserConfig as nativeUserConfigImport;
701 type nativeUserConfig = nativeUserConfigImport;
702
703 /// Top-level config which holds ChannelHandshakeLimits and ChannelConfig.
704 ///
705 /// Default::default() provides sane defaults for most configurations
706 /// (but currently with 0 relay fees!)
707 #[must_use]
708 #[repr(C)]
709 pub struct UserConfig {
710         /// A pointer to the opaque Rust object.
711
712         /// Nearly everywhere, inner must be non-null, however in places where
713         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
714         pub inner: *mut nativeUserConfig,
715         /// Indicates that this is the only struct which contains the same pointer.
716
717         /// Rust functions which take ownership of an object provided via an argument require
718         /// this to be true and invalidate the object pointed to by inner.
719         pub is_owned: bool,
720 }
721
722 impl Drop for UserConfig {
723         fn drop(&mut self) {
724                 if self.is_owned && !<*mut nativeUserConfig>::is_null(self.inner) {
725                         let _ = unsafe { Box::from_raw(self.inner) };
726                 }
727         }
728 }
729 /// Frees any resources used by the UserConfig, if is_owned is set and inner is non-NULL.
730 #[no_mangle]
731 pub extern "C" fn UserConfig_free(this_obj: UserConfig) { }
732 #[allow(unused)]
733 /// Used only if an object of this type is returned as a trait impl by a method
734 extern "C" fn UserConfig_free_void(this_ptr: *mut c_void) {
735         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUserConfig); }
736 }
737 #[allow(unused)]
738 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
739 impl UserConfig {
740         pub(crate) fn take_inner(mut self) -> *mut nativeUserConfig {
741                 assert!(self.is_owned);
742                 let ret = self.inner;
743                 self.inner = std::ptr::null_mut();
744                 ret
745         }
746 }
747 /// Channel config that we propose to our counterparty.
748 #[no_mangle]
749 pub extern "C" fn UserConfig_get_own_channel_config(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelHandshakeConfig {
750         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.own_channel_config;
751         crate::lightning::util::config::ChannelHandshakeConfig { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
752 }
753 /// Channel config that we propose to our counterparty.
754 #[no_mangle]
755 pub extern "C" fn UserConfig_set_own_channel_config(this_ptr: &mut UserConfig, mut val: crate::lightning::util::config::ChannelHandshakeConfig) {
756         unsafe { &mut *this_ptr.inner }.own_channel_config = *unsafe { Box::from_raw(val.take_inner()) };
757 }
758 /// Limits applied to our counterparty's proposed channel config settings.
759 #[no_mangle]
760 pub extern "C" fn UserConfig_get_peer_channel_config_limits(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelHandshakeLimits {
761         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.peer_channel_config_limits;
762         crate::lightning::util::config::ChannelHandshakeLimits { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
763 }
764 /// Limits applied to our counterparty's proposed channel config settings.
765 #[no_mangle]
766 pub extern "C" fn UserConfig_set_peer_channel_config_limits(this_ptr: &mut UserConfig, mut val: crate::lightning::util::config::ChannelHandshakeLimits) {
767         unsafe { &mut *this_ptr.inner }.peer_channel_config_limits = *unsafe { Box::from_raw(val.take_inner()) };
768 }
769 /// Channel config which affects behavior during channel lifetime.
770 #[no_mangle]
771 pub extern "C" fn UserConfig_get_channel_options(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelConfig {
772         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_options;
773         crate::lightning::util::config::ChannelConfig { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
774 }
775 /// Channel config which affects behavior during channel lifetime.
776 #[no_mangle]
777 pub extern "C" fn UserConfig_set_channel_options(this_ptr: &mut UserConfig, mut val: crate::lightning::util::config::ChannelConfig) {
778         unsafe { &mut *this_ptr.inner }.channel_options = *unsafe { Box::from_raw(val.take_inner()) };
779 }
780 /// Constructs a new UserConfig given each field
781 #[must_use]
782 #[no_mangle]
783 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) -> UserConfig {
784         UserConfig { inner: Box::into_raw(Box::new(nativeUserConfig {
785                 own_channel_config: *unsafe { Box::from_raw(own_channel_config_arg.take_inner()) },
786                 peer_channel_config_limits: *unsafe { Box::from_raw(peer_channel_config_limits_arg.take_inner()) },
787                 channel_options: *unsafe { Box::from_raw(channel_options_arg.take_inner()) },
788         })), is_owned: true }
789 }
790 impl Clone for UserConfig {
791         fn clone(&self) -> Self {
792                 Self {
793                         inner: if <*mut nativeUserConfig>::is_null(self.inner) { std::ptr::null_mut() } else {
794                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
795                         is_owned: true,
796                 }
797         }
798 }
799 #[allow(unused)]
800 /// Used only if an object of this type is returned as a trait impl by a method
801 pub(crate) extern "C" fn UserConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
802         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUserConfig)).clone() })) as *mut c_void
803 }
804 #[no_mangle]
805 /// Creates a copy of the UserConfig
806 pub extern "C" fn UserConfig_clone(orig: &UserConfig) -> UserConfig {
807         orig.clone()
808 }
809 /// Creates a "default" UserConfig. See struct and individual field documentaiton for details on which values are used.
810 #[must_use]
811 #[no_mangle]
812 pub extern "C" fn UserConfig_default() -> UserConfig {
813         UserConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
814 }