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