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