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