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