1 //! Various user-configurable channel limits and settings which ChannelManager
5 use bitcoin::hashes::Hash;
9 use lightning::util::config::ChannelHandshakeConfig as nativeChannelHandshakeConfigImport;
10 type nativeChannelHandshakeConfig = nativeChannelHandshakeConfigImport;
12 /// Configuration we set when applicable.
14 /// Default::default() provides sane defaults.
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,
24 impl Drop for ChannelHandshakeConfig {
26 if self.is_owned && !self.inner.is_null() {
27 let _ = unsafe { Box::from_raw(self.inner) };
32 pub extern "C" fn ChannelHandshakeConfig_free(this_ptr: ChannelHandshakeConfig) { }
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); }
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);
44 self.inner = std::ptr::null_mut();
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).
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;
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).
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;
67 /// Set to the amount of time we require our counterparty to wait to claim their money.
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.
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
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.
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;
84 /// Set to the amount of time we require our counterparty to wait to claim their money.
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.
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
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.
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;
100 /// Set to the smallest value HTLC we will accept to process.
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.
105 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
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;
112 /// Set to the smallest value HTLC we will accept to process.
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.
117 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
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;
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 }
132 impl Clone for ChannelHandshakeConfig {
133 fn clone(&self) -> Self {
135 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
136 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
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
147 pub extern "C" fn ChannelHandshakeConfig_clone(orig: &ChannelHandshakeConfig) -> ChannelHandshakeConfig {
152 pub extern "C" fn ChannelHandshakeConfig_default() -> ChannelHandshakeConfig {
153 ChannelHandshakeConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
156 use lightning::util::config::ChannelHandshakeLimits as nativeChannelHandshakeLimitsImport;
157 type nativeChannelHandshakeLimits = nativeChannelHandshakeLimitsImport;
159 /// Optional channel limits which are applied during channel creation.
161 /// These limits are only applied to our counterparty's limits, not our own.
163 /// Use 0/<type>::max_value() as appropriate to skip checking.
165 /// Provides sane defaults for most configurations.
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.
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,
179 impl Drop for ChannelHandshakeLimits {
181 if self.is_owned && !self.inner.is_null() {
182 let _ = unsafe { Box::from_raw(self.inner) };
187 pub extern "C" fn ChannelHandshakeLimits_free(this_ptr: ChannelHandshakeLimits) { }
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); }
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();
203 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
204 /// only applies to inbound channels.
206 /// Default value: 0.
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;
212 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
213 /// only applies to inbound channels.
215 /// Default value: 0.
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;
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.
223 /// Default value: u64::max_value.
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;
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.
232 /// Default value: u64::max_value.
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;
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.
240 /// Default value: 0.
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;
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.
249 /// Default value: 0.
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;
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).
258 /// Default value: u64::max_value.
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;
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).
268 /// Default value: u64::max_value.
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;
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.
276 /// Default value: 0.
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;
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.
285 /// Default value: 0.
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;
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.
298 /// Default value: 546, the current dust limit on the Bitcoin network.
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;
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.
312 /// Default value: 546, the current dust limit on the Bitcoin network.
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;
317 /// Maximum allowed threshold above which outputs will not be generated in their commitment
319 /// HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
321 /// Default value: u64::max_value.
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;
327 /// Maximum allowed threshold above which outputs will not be generated in their commitment
329 /// HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
331 /// Default value: u64::max_value.
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;
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.
341 /// Default value: 144, or roughly one day and only applies to outbound channels.
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;
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.
352 /// Default value: 144, or roughly one day and only applies to outbound channels.
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;
357 /// Set to force the incoming channel to match our announced channel preference in
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).
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;
367 /// Set to force the incoming channel to match our announced channel preference in
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).
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;
376 /// Set to the amount of time we're willing to wait to claim money back to us.
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.
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)
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;
388 /// Set to the amount of time we're willing to wait to claim money back to us.
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.
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)
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;
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 }
415 impl Clone for ChannelHandshakeLimits {
416 fn clone(&self) -> Self {
418 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
419 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
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
430 pub extern "C" fn ChannelHandshakeLimits_clone(orig: &ChannelHandshakeLimits) -> ChannelHandshakeLimits {
435 pub extern "C" fn ChannelHandshakeLimits_default() -> ChannelHandshakeLimits {
436 ChannelHandshakeLimits { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
439 use lightning::util::config::ChannelConfig as nativeChannelConfigImport;
440 type nativeChannelConfig = nativeChannelConfigImport;
442 /// Options which apply on a per-channel basis and may change at runtime or based on negotiation
443 /// with our counterparty.
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,
453 impl Drop for ChannelConfig {
455 if self.is_owned && !self.inner.is_null() {
456 let _ = unsafe { Box::from_raw(self.inner) };
461 pub extern "C" fn ChannelConfig_free(this_ptr: ChannelConfig) { }
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); }
468 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
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();
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.
481 /// Default value: 0.
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;
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.
491 /// Default value: 0.
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;
496 /// Set to announce the channel publicly and notify all nodes that they can route via this
499 /// This should only be set to true for nodes which expect to be online reliably.
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.
504 /// This cannot be changed after the initial channel handshake.
506 /// Default value: false.
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;
512 /// Set to announce the channel publicly and notify all nodes that they can route via this
515 /// This should only be set to true for nodes which expect to be online reliably.
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.
520 /// This cannot be changed after the initial channel handshake.
522 /// Default value: false.
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;
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.
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.
535 /// This cannot be changed after a channel has been initialized.
537 /// Default value: true.
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;
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.
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.
551 /// This cannot be changed after a channel has been initialized.
553 /// Default value: true.
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;
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 }
567 impl Clone for ChannelConfig {
568 fn clone(&self) -> Self {
570 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
571 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
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
582 pub extern "C" fn ChannelConfig_clone(orig: &ChannelConfig) -> ChannelConfig {
587 pub extern "C" fn ChannelConfig_default() -> ChannelConfig {
588 ChannelConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
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 })
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) })
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() };
605 use lightning::util::config::UserConfig as nativeUserConfigImport;
606 type nativeUserConfig = nativeUserConfigImport;
608 /// Top-level config which holds ChannelHandshakeLimits and ChannelConfig.
610 /// Default::default() provides sane defaults for most configurations
611 /// (but currently with 0 relay fees!)
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,
621 impl Drop for UserConfig {
623 if self.is_owned && !self.inner.is_null() {
624 let _ = unsafe { Box::from_raw(self.inner) };
629 pub extern "C" fn UserConfig_free(this_ptr: UserConfig) { }
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); }
636 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
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();
645 /// Channel config that we propose to our counterparty.
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 }
651 /// Channel config that we propose to our counterparty.
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()) };
656 /// Limits applied to our counterparty's proposed channel config settings.
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 }
662 /// Limits applied to our counterparty's proposed channel config settings.
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()) };
667 /// Channel config which affects behavior during channel lifetime.
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 }
673 /// Channel config which affects behavior during channel lifetime.
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()) };
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 }
687 impl Clone for UserConfig {
688 fn clone(&self) -> Self {
690 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
691 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
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
702 pub extern "C" fn UserConfig_clone(orig: &UserConfig) -> UserConfig {
707 pub extern "C" fn UserConfig_default() -> UserConfig {
708 UserConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }