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