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