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