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_ptr(mut self) -> *mut nativeChannelHandshakeConfig {
42 assert!(self.is_owned);
44 self.inner = std::ptr::null_mut();
48 impl Clone for ChannelHandshakeConfig {
49 fn clone(&self) -> Self {
51 inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
57 /// Used only if an object of this type is returned as a trait impl by a method
58 pub(crate) extern "C" fn ChannelHandshakeConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
59 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeConfig)).clone() })) as *mut c_void
61 /// Confirmations we will wait for before considering the channel locked in.
62 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
63 /// equivalent limit applied to outbound channels).
67 pub extern "C" fn ChannelHandshakeConfig_get_minimum_depth(this_ptr: &ChannelHandshakeConfig) -> u32 {
68 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.minimum_depth;
71 /// Confirmations we will wait for before considering the channel locked in.
72 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
73 /// equivalent limit applied to outbound channels).
77 pub extern "C" fn ChannelHandshakeConfig_set_minimum_depth(this_ptr: &mut ChannelHandshakeConfig, mut val: u32) {
78 unsafe { &mut *this_ptr.inner }.minimum_depth = val;
80 /// Set to the amount of time we require our counterparty to wait to claim their money.
82 /// It's one of the main parameter of our security model. We (or one of our watchtowers) MUST
83 /// be online to check for peer having broadcast a revoked transaction to steal our funds
84 /// at least once every our_to_self_delay blocks.
86 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
87 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
90 /// Default value: BREAKDOWN_TIMEOUT (currently 144), we enforce it as a minimum at channel
91 /// opening so you can tweak config to ask for more security, not less.
93 pub extern "C" fn ChannelHandshakeConfig_get_our_to_self_delay(this_ptr: &ChannelHandshakeConfig) -> u16 {
94 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.our_to_self_delay;
97 /// Set to the amount of time we require our counterparty to wait to claim their money.
99 /// It's one of the main parameter of our security model. We (or one of our watchtowers) MUST
100 /// be online to check for peer having broadcast a revoked transaction to steal our funds
101 /// at least once every our_to_self_delay blocks.
103 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
104 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
107 /// Default value: BREAKDOWN_TIMEOUT (currently 144), we enforce it as a minimum at channel
108 /// opening so you can tweak config to ask for more security, not less.
110 pub extern "C" fn ChannelHandshakeConfig_set_our_to_self_delay(this_ptr: &mut ChannelHandshakeConfig, mut val: u16) {
111 unsafe { &mut *this_ptr.inner }.our_to_self_delay = val;
113 /// Set to the smallest value HTLC we will accept to process.
115 /// This value is sent to our counterparty on channel-open and we close the channel any time
116 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
118 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
121 pub extern "C" fn ChannelHandshakeConfig_get_our_htlc_minimum_msat(this_ptr: &ChannelHandshakeConfig) -> u64 {
122 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.our_htlc_minimum_msat;
125 /// Set to the smallest value HTLC we will accept to process.
127 /// This value is sent to our counterparty on channel-open and we close the channel any time
128 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
130 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
133 pub extern "C" fn ChannelHandshakeConfig_set_our_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeConfig, mut val: u64) {
134 unsafe { &mut *this_ptr.inner }.our_htlc_minimum_msat = val;
138 pub extern "C" fn ChannelHandshakeConfig_new(mut minimum_depth_arg: u32, mut our_to_self_delay_arg: u16, mut our_htlc_minimum_msat_arg: u64) -> ChannelHandshakeConfig {
139 ChannelHandshakeConfig { inner: Box::into_raw(Box::new(nativeChannelHandshakeConfig {
140 minimum_depth: minimum_depth_arg,
141 our_to_self_delay: our_to_self_delay_arg,
142 our_htlc_minimum_msat: our_htlc_minimum_msat_arg,
143 })), is_owned: true }
147 pub extern "C" fn ChannelHandshakeConfig_default() -> ChannelHandshakeConfig {
148 ChannelHandshakeConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
151 use lightning::util::config::ChannelHandshakeLimits as nativeChannelHandshakeLimitsImport;
152 type nativeChannelHandshakeLimits = nativeChannelHandshakeLimitsImport;
154 /// Optional channel limits which are applied during channel creation.
156 /// These limits are only applied to our counterparty's limits, not our own.
158 /// Use 0/<type>::max_value() as appropriate to skip checking.
160 /// Provides sane defaults for most configurations.
162 /// Most additional limits are disabled except those with which specify a default in individual
163 /// field documentation. Note that this may result in barely-usable channels, but since they
164 /// are applied mostly only to incoming channels that's not much of a problem.
167 pub struct ChannelHandshakeLimits {
168 /// Nearly everywhere, inner must be non-null, however in places where
169 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
170 pub inner: *mut nativeChannelHandshakeLimits,
174 impl Drop for ChannelHandshakeLimits {
176 if self.is_owned && !self.inner.is_null() {
177 let _ = unsafe { Box::from_raw(self.inner) };
182 pub extern "C" fn ChannelHandshakeLimits_free(this_ptr: ChannelHandshakeLimits) { }
184 /// Used only if an object of this type is returned as a trait impl by a method
185 extern "C" fn ChannelHandshakeLimits_free_void(this_ptr: *mut c_void) {
186 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelHandshakeLimits); }
189 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
190 impl ChannelHandshakeLimits {
191 pub(crate) fn take_ptr(mut self) -> *mut nativeChannelHandshakeLimits {
192 assert!(self.is_owned);
193 let ret = self.inner;
194 self.inner = std::ptr::null_mut();
198 impl Clone for ChannelHandshakeLimits {
199 fn clone(&self) -> Self {
201 inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
207 /// Used only if an object of this type is returned as a trait impl by a method
208 pub(crate) extern "C" fn ChannelHandshakeLimits_clone_void(this_ptr: *const c_void) -> *mut c_void {
209 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeLimits)).clone() })) as *mut c_void
211 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
212 /// only applies to inbound channels.
214 /// Default value: 0.
216 pub extern "C" fn ChannelHandshakeLimits_get_min_funding_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
217 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_funding_satoshis;
220 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
221 /// only applies to inbound channels.
223 /// Default value: 0.
225 pub extern "C" fn ChannelHandshakeLimits_set_min_funding_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
226 unsafe { &mut *this_ptr.inner }.min_funding_satoshis = val;
228 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
229 /// you to limit the maximum minimum-size they can require.
231 /// Default value: u64::max_value.
233 pub extern "C" fn ChannelHandshakeLimits_get_max_htlc_minimum_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
234 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_htlc_minimum_msat;
237 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
238 /// you to limit the maximum minimum-size they can require.
240 /// Default value: u64::max_value.
242 pub extern "C" fn ChannelHandshakeLimits_set_max_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
243 unsafe { &mut *this_ptr.inner }.max_htlc_minimum_msat = val;
245 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
246 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
248 /// Default value: 0.
250 pub extern "C" fn ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
251 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_max_htlc_value_in_flight_msat;
254 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
255 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
257 /// Default value: 0.
259 pub extern "C" fn ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
260 unsafe { &mut *this_ptr.inner }.min_max_htlc_value_in_flight_msat = val;
262 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
263 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
264 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
266 /// Default value: u64::max_value.
268 pub extern "C" fn ChannelHandshakeLimits_get_max_channel_reserve_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
269 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_channel_reserve_satoshis;
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).
276 /// Default value: u64::max_value.
278 pub extern "C" fn ChannelHandshakeLimits_set_max_channel_reserve_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
279 unsafe { &mut *this_ptr.inner }.max_channel_reserve_satoshis = val;
281 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
282 /// time. This allows you to set a minimum such value.
284 /// Default value: 0.
286 pub extern "C" fn ChannelHandshakeLimits_get_min_max_accepted_htlcs(this_ptr: &ChannelHandshakeLimits) -> u16 {
287 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_max_accepted_htlcs;
290 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
291 /// time. This allows you to set a minimum such value.
293 /// Default value: 0.
295 pub extern "C" fn ChannelHandshakeLimits_set_min_max_accepted_htlcs(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
296 unsafe { &mut *this_ptr.inner }.min_max_accepted_htlcs = val;
298 /// Outputs below a certain value will not be added to on-chain transactions. The dust value is
299 /// required to always be higher than this value so this only applies to HTLC outputs (and
300 /// potentially to-self outputs before any payments have been made).
301 /// Thus, HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
302 /// This setting allows you to set a minimum dust limit for their commitment transactions,
303 /// reflecting the reality that tiny outputs are not considered standard transactions and will
304 /// not propagate through the Bitcoin network.
306 /// Default value: 546, the current dust limit on the Bitcoin network.
308 pub extern "C" fn ChannelHandshakeLimits_get_min_dust_limit_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
309 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_dust_limit_satoshis;
312 /// Outputs below a certain value will not be added to on-chain transactions. The dust value is
313 /// required to always be higher than this value so this only applies to HTLC outputs (and
314 /// potentially to-self outputs before any payments have been made).
315 /// Thus, HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
316 /// This setting allows you to set a minimum dust limit for their commitment transactions,
317 /// reflecting the reality that tiny outputs are not considered standard transactions and will
318 /// not propagate through the Bitcoin network.
320 /// Default value: 546, the current dust limit on the Bitcoin network.
322 pub extern "C" fn ChannelHandshakeLimits_set_min_dust_limit_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
323 unsafe { &mut *this_ptr.inner }.min_dust_limit_satoshis = val;
325 /// Maximum allowed threshold above which outputs will not be generated in their commitment
327 /// HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
329 /// Default value: u64::max_value.
331 pub extern "C" fn ChannelHandshakeLimits_get_max_dust_limit_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
332 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_dust_limit_satoshis;
335 /// Maximum allowed threshold above which outputs will not be generated in their commitment
337 /// HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
339 /// Default value: u64::max_value.
341 pub extern "C" fn ChannelHandshakeLimits_set_max_dust_limit_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
342 unsafe { &mut *this_ptr.inner }.max_dust_limit_satoshis = val;
344 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
345 /// certain number of blocks, specified by the node which is not the funder (as the funder can
346 /// assume they aren't going to double-spend themselves).
347 /// This config allows you to set a limit on the maximum amount of time to wait.
349 /// Default value: 144, or roughly one day and only applies to outbound channels.
351 pub extern "C" fn ChannelHandshakeLimits_get_max_minimum_depth(this_ptr: &ChannelHandshakeLimits) -> u32 {
352 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_minimum_depth;
355 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
356 /// certain number of blocks, specified by the node which is not the funder (as the funder can
357 /// assume they aren't going to double-spend themselves).
358 /// This config allows you to set a limit on the maximum amount of time to wait.
360 /// Default value: 144, or roughly one day and only applies to outbound channels.
362 pub extern "C" fn ChannelHandshakeLimits_set_max_minimum_depth(this_ptr: &mut ChannelHandshakeLimits, mut val: u32) {
363 unsafe { &mut *this_ptr.inner }.max_minimum_depth = val;
365 /// Set to force the incoming channel to match our announced channel preference in
368 /// Default value: true, to make the default that no announced channels are possible (which is
369 /// appropriate for any nodes which are not online very reliably).
371 pub extern "C" fn ChannelHandshakeLimits_get_force_announced_channel_preference(this_ptr: &ChannelHandshakeLimits) -> bool {
372 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.force_announced_channel_preference;
375 /// Set to force the incoming channel to match our announced channel preference in
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).
381 pub extern "C" fn ChannelHandshakeLimits_set_force_announced_channel_preference(this_ptr: &mut ChannelHandshakeLimits, mut val: bool) {
382 unsafe { &mut *this_ptr.inner }.force_announced_channel_preference = val;
384 /// Set to the amount of time we're willing to wait to claim money back to us.
386 /// Not checking this value would be a security issue, as our peer would be able to set it to
387 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
389 /// Default value: MAX_LOCAL_BREAKDOWN_TIMEOUT (1008), which we also enforce as a maximum value
390 /// so you can tweak config to reduce the loss of having useless locked funds (if your peer accepts)
392 pub extern "C" fn ChannelHandshakeLimits_get_their_to_self_delay(this_ptr: &ChannelHandshakeLimits) -> u16 {
393 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.their_to_self_delay;
396 /// Set to the amount of time we're willing to wait to claim money back to us.
398 /// Not checking this value would be a security issue, as our peer would be able to set it to
399 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
401 /// Default value: MAX_LOCAL_BREAKDOWN_TIMEOUT (1008), which we also enforce as a maximum value
402 /// so you can tweak config to reduce the loss of having useless locked funds (if your peer accepts)
404 pub extern "C" fn ChannelHandshakeLimits_set_their_to_self_delay(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
405 unsafe { &mut *this_ptr.inner }.their_to_self_delay = val;
409 pub extern "C" fn ChannelHandshakeLimits_new(mut min_funding_satoshis_arg: u64, mut max_htlc_minimum_msat_arg: u64, mut min_max_htlc_value_in_flight_msat_arg: u64, mut max_channel_reserve_satoshis_arg: u64, mut min_max_accepted_htlcs_arg: u16, mut min_dust_limit_satoshis_arg: u64, mut max_dust_limit_satoshis_arg: u64, mut max_minimum_depth_arg: u32, mut force_announced_channel_preference_arg: bool, mut their_to_self_delay_arg: u16) -> ChannelHandshakeLimits {
410 ChannelHandshakeLimits { inner: Box::into_raw(Box::new(nativeChannelHandshakeLimits {
411 min_funding_satoshis: min_funding_satoshis_arg,
412 max_htlc_minimum_msat: max_htlc_minimum_msat_arg,
413 min_max_htlc_value_in_flight_msat: min_max_htlc_value_in_flight_msat_arg,
414 max_channel_reserve_satoshis: max_channel_reserve_satoshis_arg,
415 min_max_accepted_htlcs: min_max_accepted_htlcs_arg,
416 min_dust_limit_satoshis: min_dust_limit_satoshis_arg,
417 max_dust_limit_satoshis: max_dust_limit_satoshis_arg,
418 max_minimum_depth: max_minimum_depth_arg,
419 force_announced_channel_preference: force_announced_channel_preference_arg,
420 their_to_self_delay: their_to_self_delay_arg,
421 })), is_owned: true }
425 pub extern "C" fn ChannelHandshakeLimits_default() -> ChannelHandshakeLimits {
426 ChannelHandshakeLimits { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
429 use lightning::util::config::ChannelConfig as nativeChannelConfigImport;
430 type nativeChannelConfig = nativeChannelConfigImport;
432 /// Options which apply on a per-channel basis and may change at runtime or based on negotiation
433 /// with our counterparty.
436 pub struct ChannelConfig {
437 /// Nearly everywhere, inner must be non-null, however in places where
438 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
439 pub inner: *mut nativeChannelConfig,
443 impl Drop for ChannelConfig {
445 if self.is_owned && !self.inner.is_null() {
446 let _ = unsafe { Box::from_raw(self.inner) };
451 pub extern "C" fn ChannelConfig_free(this_ptr: ChannelConfig) { }
453 /// Used only if an object of this type is returned as a trait impl by a method
454 extern "C" fn ChannelConfig_free_void(this_ptr: *mut c_void) {
455 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelConfig); }
458 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
460 pub(crate) fn take_ptr(mut self) -> *mut nativeChannelConfig {
461 assert!(self.is_owned);
462 let ret = self.inner;
463 self.inner = std::ptr::null_mut();
467 impl Clone for ChannelConfig {
468 fn clone(&self) -> Self {
470 inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
476 /// Used only if an object of this type is returned as a trait impl by a method
477 pub(crate) extern "C" fn ChannelConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
478 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelConfig)).clone() })) as *mut c_void
480 /// Amount (in millionths of a satoshi) the channel will charge per transferred satoshi.
481 /// This may be allowed to change at runtime in a later update, however doing so must result in
482 /// update messages sent to notify all nodes of our updated relay fee.
484 /// Default value: 0.
486 pub extern "C" fn ChannelConfig_get_fee_proportional_millionths(this_ptr: &ChannelConfig) -> u32 {
487 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fee_proportional_millionths;
490 /// Amount (in millionths of a satoshi) the channel will charge per transferred satoshi.
491 /// This may be allowed to change at runtime in a later update, however doing so must result in
492 /// update messages sent to notify all nodes of our updated relay fee.
494 /// Default value: 0.
496 pub extern "C" fn ChannelConfig_set_fee_proportional_millionths(this_ptr: &mut ChannelConfig, mut val: u32) {
497 unsafe { &mut *this_ptr.inner }.fee_proportional_millionths = val;
499 /// Set to announce the channel publicly and notify all nodes that they can route via this
502 /// This should only be set to true for nodes which expect to be online reliably.
504 /// As the node which funds a channel picks this value this will only apply for new outbound
505 /// channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set.
507 /// This cannot be changed after the initial channel handshake.
509 /// Default value: false.
511 pub extern "C" fn ChannelConfig_get_announced_channel(this_ptr: &ChannelConfig) -> bool {
512 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announced_channel;
515 /// Set to announce the channel publicly and notify all nodes that they can route via this
518 /// This should only be set to true for nodes which expect to be online reliably.
520 /// As the node which funds a channel picks this value this will only apply for new outbound
521 /// channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set.
523 /// This cannot be changed after the initial channel handshake.
525 /// Default value: false.
527 pub extern "C" fn ChannelConfig_set_announced_channel(this_ptr: &mut ChannelConfig, mut val: bool) {
528 unsafe { &mut *this_ptr.inner }.announced_channel = val;
530 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
531 /// supports it, they will then enforce the mutual-close output to us matches what we provided
532 /// at intialization, preventing us from closing to an alternate pubkey.
534 /// This is set to true by default to provide a slight increase in security, though ultimately
535 /// any attacker who is able to take control of a channel can just as easily send the funds via
536 /// lightning payments, so we never require that our counterparties support this option.
538 /// This cannot be changed after a channel has been initialized.
540 /// Default value: true.
542 pub extern "C" fn ChannelConfig_get_commit_upfront_shutdown_pubkey(this_ptr: &ChannelConfig) -> bool {
543 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.commit_upfront_shutdown_pubkey;
546 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
547 /// supports it, they will then enforce the mutual-close output to us matches what we provided
548 /// at intialization, preventing us from closing to an alternate pubkey.
550 /// This is set to true by default to provide a slight increase in security, though ultimately
551 /// any attacker who is able to take control of a channel can just as easily send the funds via
552 /// lightning payments, so we never require that our counterparties support this option.
554 /// This cannot be changed after a channel has been initialized.
556 /// Default value: true.
558 pub extern "C" fn ChannelConfig_set_commit_upfront_shutdown_pubkey(this_ptr: &mut ChannelConfig, mut val: bool) {
559 unsafe { &mut *this_ptr.inner }.commit_upfront_shutdown_pubkey = val;
563 pub extern "C" fn ChannelConfig_new(mut fee_proportional_millionths_arg: u32, mut announced_channel_arg: bool, mut commit_upfront_shutdown_pubkey_arg: bool) -> ChannelConfig {
564 ChannelConfig { inner: Box::into_raw(Box::new(nativeChannelConfig {
565 fee_proportional_millionths: fee_proportional_millionths_arg,
566 announced_channel: announced_channel_arg,
567 commit_upfront_shutdown_pubkey: commit_upfront_shutdown_pubkey_arg,
568 })), is_owned: true }
572 pub extern "C" fn ChannelConfig_default() -> ChannelConfig {
573 ChannelConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
576 pub extern "C" fn ChannelConfig_write(obj: *const ChannelConfig) -> crate::c_types::derived::CVec_u8Z {
577 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
580 pub extern "C" fn ChannelConfig_read(ser: crate::c_types::u8slice) -> ChannelConfig {
581 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
582 ChannelConfig { inner: Box::into_raw(Box::new(res)), is_owned: true }
584 ChannelConfig { inner: std::ptr::null_mut(), is_owned: true }
588 use lightning::util::config::UserConfig as nativeUserConfigImport;
589 type nativeUserConfig = nativeUserConfigImport;
591 /// Top-level config which holds ChannelHandshakeLimits and ChannelConfig.
593 /// Default::default() provides sane defaults for most configurations
594 /// (but currently with 0 relay fees!)
597 pub struct UserConfig {
598 /// Nearly everywhere, inner must be non-null, however in places where
599 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
600 pub inner: *mut nativeUserConfig,
604 impl Drop for UserConfig {
606 if self.is_owned && !self.inner.is_null() {
607 let _ = unsafe { Box::from_raw(self.inner) };
612 pub extern "C" fn UserConfig_free(this_ptr: UserConfig) { }
614 /// Used only if an object of this type is returned as a trait impl by a method
615 extern "C" fn UserConfig_free_void(this_ptr: *mut c_void) {
616 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUserConfig); }
619 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
621 pub(crate) fn take_ptr(mut self) -> *mut nativeUserConfig {
622 assert!(self.is_owned);
623 let ret = self.inner;
624 self.inner = std::ptr::null_mut();
628 impl Clone for UserConfig {
629 fn clone(&self) -> Self {
631 inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
637 /// Used only if an object of this type is returned as a trait impl by a method
638 pub(crate) extern "C" fn UserConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
639 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUserConfig)).clone() })) as *mut c_void
641 /// Channel config that we propose to our counterparty.
643 pub extern "C" fn UserConfig_get_own_channel_config(this_ptr: &UserConfig) -> crate::util::config::ChannelHandshakeConfig {
644 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.own_channel_config;
645 crate::util::config::ChannelHandshakeConfig { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
647 /// Channel config that we propose to our counterparty.
649 pub extern "C" fn UserConfig_set_own_channel_config(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelHandshakeConfig) {
650 unsafe { &mut *this_ptr.inner }.own_channel_config = *unsafe { Box::from_raw(val.take_ptr()) };
652 /// Limits applied to our counterparty's proposed channel config settings.
654 pub extern "C" fn UserConfig_get_peer_channel_config_limits(this_ptr: &UserConfig) -> crate::util::config::ChannelHandshakeLimits {
655 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.peer_channel_config_limits;
656 crate::util::config::ChannelHandshakeLimits { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
658 /// Limits applied to our counterparty's proposed channel config settings.
660 pub extern "C" fn UserConfig_set_peer_channel_config_limits(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelHandshakeLimits) {
661 unsafe { &mut *this_ptr.inner }.peer_channel_config_limits = *unsafe { Box::from_raw(val.take_ptr()) };
663 /// Channel config which affects behavior during channel lifetime.
665 pub extern "C" fn UserConfig_get_channel_options(this_ptr: &UserConfig) -> crate::util::config::ChannelConfig {
666 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_options;
667 crate::util::config::ChannelConfig { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
669 /// Channel config which affects behavior during channel lifetime.
671 pub extern "C" fn UserConfig_set_channel_options(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelConfig) {
672 unsafe { &mut *this_ptr.inner }.channel_options = *unsafe { Box::from_raw(val.take_ptr()) };
676 pub extern "C" fn UserConfig_new(mut own_channel_config_arg: crate::util::config::ChannelHandshakeConfig, mut peer_channel_config_limits_arg: crate::util::config::ChannelHandshakeLimits, mut channel_options_arg: crate::util::config::ChannelConfig) -> UserConfig {
677 UserConfig { inner: Box::into_raw(Box::new(nativeUserConfig {
678 own_channel_config: *unsafe { Box::from_raw(own_channel_config_arg.take_ptr()) },
679 peer_channel_config_limits: *unsafe { Box::from_raw(peer_channel_config_limits_arg.take_ptr()) },
680 channel_options: *unsafe { Box::from_raw(channel_options_arg.take_ptr()) },
681 })), is_owned: true }
685 pub extern "C" fn UserConfig_default() -> UserConfig {
686 UserConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }