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 impl Clone for ChannelHandshakeConfig {
49 fn clone(&self) -> Self {
51 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
52 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
58 /// Used only if an object of this type is returned as a trait impl by a method
59 pub(crate) extern "C" fn ChannelHandshakeConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
60 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeConfig)).clone() })) as *mut c_void
63 pub extern "C" fn ChannelHandshakeConfig_clone(orig: &ChannelHandshakeConfig) -> ChannelHandshakeConfig {
66 /// Confirmations we will wait for before considering the channel locked in.
67 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
68 /// equivalent limit applied to outbound channels).
72 pub extern "C" fn ChannelHandshakeConfig_get_minimum_depth(this_ptr: &ChannelHandshakeConfig) -> u32 {
73 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.minimum_depth;
76 /// Confirmations we will wait for before considering the channel locked in.
77 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
78 /// equivalent limit applied to outbound channels).
82 pub extern "C" fn ChannelHandshakeConfig_set_minimum_depth(this_ptr: &mut ChannelHandshakeConfig, mut val: u32) {
83 unsafe { &mut *this_ptr.inner }.minimum_depth = val;
85 /// Set to the amount of time we require our counterparty to wait to claim their money.
87 /// It's one of the main parameter of our security model. We (or one of our watchtowers) MUST
88 /// be online to check for peer having broadcast a revoked transaction to steal our funds
89 /// at least once every our_to_self_delay blocks.
91 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
92 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
95 /// Default value: BREAKDOWN_TIMEOUT (currently 144), we enforce it as a minimum at channel
96 /// opening so you can tweak config to ask for more security, not less.
98 pub extern "C" fn ChannelHandshakeConfig_get_our_to_self_delay(this_ptr: &ChannelHandshakeConfig) -> u16 {
99 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.our_to_self_delay;
102 /// Set to the amount of time we require our counterparty to wait to claim their money.
104 /// It's one of the main parameter of our security model. We (or one of our watchtowers) MUST
105 /// be online to check for peer having broadcast a revoked transaction to steal our funds
106 /// at least once every our_to_self_delay blocks.
108 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
109 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
112 /// Default value: BREAKDOWN_TIMEOUT (currently 144), we enforce it as a minimum at channel
113 /// opening so you can tweak config to ask for more security, not less.
115 pub extern "C" fn ChannelHandshakeConfig_set_our_to_self_delay(this_ptr: &mut ChannelHandshakeConfig, mut val: u16) {
116 unsafe { &mut *this_ptr.inner }.our_to_self_delay = val;
118 /// Set to the smallest value HTLC we will accept to process.
120 /// This value is sent to our counterparty on channel-open and we close the channel any time
121 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
123 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
126 pub extern "C" fn ChannelHandshakeConfig_get_our_htlc_minimum_msat(this_ptr: &ChannelHandshakeConfig) -> u64 {
127 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.our_htlc_minimum_msat;
130 /// Set to the smallest value HTLC we will accept to process.
132 /// This value is sent to our counterparty on channel-open and we close the channel any time
133 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
135 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
138 pub extern "C" fn ChannelHandshakeConfig_set_our_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeConfig, mut val: u64) {
139 unsafe { &mut *this_ptr.inner }.our_htlc_minimum_msat = val;
143 pub extern "C" fn ChannelHandshakeConfig_new(mut minimum_depth_arg: u32, mut our_to_self_delay_arg: u16, mut our_htlc_minimum_msat_arg: u64) -> ChannelHandshakeConfig {
144 ChannelHandshakeConfig { inner: Box::into_raw(Box::new(nativeChannelHandshakeConfig {
145 minimum_depth: minimum_depth_arg,
146 our_to_self_delay: our_to_self_delay_arg,
147 our_htlc_minimum_msat: our_htlc_minimum_msat_arg,
148 })), is_owned: true }
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 impl Clone for ChannelHandshakeLimits {
204 fn clone(&self) -> Self {
206 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
207 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
213 /// Used only if an object of this type is returned as a trait impl by a method
214 pub(crate) extern "C" fn ChannelHandshakeLimits_clone_void(this_ptr: *const c_void) -> *mut c_void {
215 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeLimits)).clone() })) as *mut c_void
218 pub extern "C" fn ChannelHandshakeLimits_clone(orig: &ChannelHandshakeLimits) -> ChannelHandshakeLimits {
221 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
222 /// only applies to inbound channels.
224 /// Default value: 0.
226 pub extern "C" fn ChannelHandshakeLimits_get_min_funding_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
227 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_funding_satoshis;
230 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
231 /// only applies to inbound channels.
233 /// Default value: 0.
235 pub extern "C" fn ChannelHandshakeLimits_set_min_funding_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
236 unsafe { &mut *this_ptr.inner }.min_funding_satoshis = val;
238 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
239 /// you to limit the maximum minimum-size they can require.
241 /// Default value: u64::max_value.
243 pub extern "C" fn ChannelHandshakeLimits_get_max_htlc_minimum_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
244 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_htlc_minimum_msat;
247 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
248 /// you to limit the maximum minimum-size they can require.
250 /// Default value: u64::max_value.
252 pub extern "C" fn ChannelHandshakeLimits_set_max_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
253 unsafe { &mut *this_ptr.inner }.max_htlc_minimum_msat = val;
255 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
256 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
258 /// Default value: 0.
260 pub extern "C" fn ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
261 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_max_htlc_value_in_flight_msat;
264 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
265 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
267 /// Default value: 0.
269 pub extern "C" fn ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
270 unsafe { &mut *this_ptr.inner }.min_max_htlc_value_in_flight_msat = val;
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_get_max_channel_reserve_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
279 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_channel_reserve_satoshis;
282 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
283 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
284 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
286 /// Default value: u64::max_value.
288 pub extern "C" fn ChannelHandshakeLimits_set_max_channel_reserve_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
289 unsafe { &mut *this_ptr.inner }.max_channel_reserve_satoshis = val;
291 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
292 /// time. This allows you to set a minimum such value.
294 /// Default value: 0.
296 pub extern "C" fn ChannelHandshakeLimits_get_min_max_accepted_htlcs(this_ptr: &ChannelHandshakeLimits) -> u16 {
297 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_max_accepted_htlcs;
300 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
301 /// time. This allows you to set a minimum such value.
303 /// Default value: 0.
305 pub extern "C" fn ChannelHandshakeLimits_set_min_max_accepted_htlcs(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
306 unsafe { &mut *this_ptr.inner }.min_max_accepted_htlcs = val;
308 /// Outputs below a certain value will not be added to on-chain transactions. The dust value is
309 /// required to always be higher than this value so this only applies to HTLC outputs (and
310 /// potentially to-self outputs before any payments have been made).
311 /// Thus, HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
312 /// This setting allows you to set a minimum dust limit for their commitment transactions,
313 /// reflecting the reality that tiny outputs are not considered standard transactions and will
314 /// not propagate through the Bitcoin network.
316 /// Default value: 546, the current dust limit on the Bitcoin network.
318 pub extern "C" fn ChannelHandshakeLimits_get_min_dust_limit_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
319 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_dust_limit_satoshis;
322 /// Outputs below a certain value will not be added to on-chain transactions. The dust value is
323 /// required to always be higher than this value so this only applies to HTLC outputs (and
324 /// potentially to-self outputs before any payments have been made).
325 /// Thus, HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
326 /// This setting allows you to set a minimum dust limit for their commitment transactions,
327 /// reflecting the reality that tiny outputs are not considered standard transactions and will
328 /// not propagate through the Bitcoin network.
330 /// Default value: 546, the current dust limit on the Bitcoin network.
332 pub extern "C" fn ChannelHandshakeLimits_set_min_dust_limit_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
333 unsafe { &mut *this_ptr.inner }.min_dust_limit_satoshis = val;
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_get_max_dust_limit_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
342 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_dust_limit_satoshis;
345 /// Maximum allowed threshold above which outputs will not be generated in their commitment
347 /// HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
349 /// Default value: u64::max_value.
351 pub extern "C" fn ChannelHandshakeLimits_set_max_dust_limit_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
352 unsafe { &mut *this_ptr.inner }.max_dust_limit_satoshis = val;
354 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
355 /// certain number of blocks, specified by the node which is not the funder (as the funder can
356 /// assume they aren't going to double-spend themselves).
357 /// This config allows you to set a limit on the maximum amount of time to wait.
359 /// Default value: 144, or roughly one day and only applies to outbound channels.
361 pub extern "C" fn ChannelHandshakeLimits_get_max_minimum_depth(this_ptr: &ChannelHandshakeLimits) -> u32 {
362 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_minimum_depth;
365 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
366 /// certain number of blocks, specified by the node which is not the funder (as the funder can
367 /// assume they aren't going to double-spend themselves).
368 /// This config allows you to set a limit on the maximum amount of time to wait.
370 /// Default value: 144, or roughly one day and only applies to outbound channels.
372 pub extern "C" fn ChannelHandshakeLimits_set_max_minimum_depth(this_ptr: &mut ChannelHandshakeLimits, mut val: u32) {
373 unsafe { &mut *this_ptr.inner }.max_minimum_depth = val;
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_get_force_announced_channel_preference(this_ptr: &ChannelHandshakeLimits) -> bool {
382 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.force_announced_channel_preference;
385 /// Set to force the incoming channel to match our announced channel preference in
388 /// Default value: true, to make the default that no announced channels are possible (which is
389 /// appropriate for any nodes which are not online very reliably).
391 pub extern "C" fn ChannelHandshakeLimits_set_force_announced_channel_preference(this_ptr: &mut ChannelHandshakeLimits, mut val: bool) {
392 unsafe { &mut *this_ptr.inner }.force_announced_channel_preference = val;
394 /// Set to the amount of time we're willing to wait to claim money back to us.
396 /// Not checking this value would be a security issue, as our peer would be able to set it to
397 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
399 /// Default value: MAX_LOCAL_BREAKDOWN_TIMEOUT (1008), which we also enforce as a maximum value
400 /// so you can tweak config to reduce the loss of having useless locked funds (if your peer accepts)
402 pub extern "C" fn ChannelHandshakeLimits_get_their_to_self_delay(this_ptr: &ChannelHandshakeLimits) -> u16 {
403 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.their_to_self_delay;
406 /// Set to the amount of time we're willing to wait to claim money back to us.
408 /// Not checking this value would be a security issue, as our peer would be able to set it to
409 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
411 /// Default value: MAX_LOCAL_BREAKDOWN_TIMEOUT (1008), which we also enforce as a maximum value
412 /// so you can tweak config to reduce the loss of having useless locked funds (if your peer accepts)
414 pub extern "C" fn ChannelHandshakeLimits_set_their_to_self_delay(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
415 unsafe { &mut *this_ptr.inner }.their_to_self_delay = val;
419 pub extern "C" fn ChannelHandshakeLimits_new(mut min_funding_satoshis_arg: u64, mut max_htlc_minimum_msat_arg: u64, mut min_max_htlc_value_in_flight_msat_arg: u64, mut max_channel_reserve_satoshis_arg: u64, mut min_max_accepted_htlcs_arg: u16, mut min_dust_limit_satoshis_arg: u64, mut max_dust_limit_satoshis_arg: u64, mut max_minimum_depth_arg: u32, mut force_announced_channel_preference_arg: bool, mut their_to_self_delay_arg: u16) -> ChannelHandshakeLimits {
420 ChannelHandshakeLimits { inner: Box::into_raw(Box::new(nativeChannelHandshakeLimits {
421 min_funding_satoshis: min_funding_satoshis_arg,
422 max_htlc_minimum_msat: max_htlc_minimum_msat_arg,
423 min_max_htlc_value_in_flight_msat: min_max_htlc_value_in_flight_msat_arg,
424 max_channel_reserve_satoshis: max_channel_reserve_satoshis_arg,
425 min_max_accepted_htlcs: min_max_accepted_htlcs_arg,
426 min_dust_limit_satoshis: min_dust_limit_satoshis_arg,
427 max_dust_limit_satoshis: max_dust_limit_satoshis_arg,
428 max_minimum_depth: max_minimum_depth_arg,
429 force_announced_channel_preference: force_announced_channel_preference_arg,
430 their_to_self_delay: their_to_self_delay_arg,
431 })), is_owned: true }
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 impl Clone for ChannelConfig {
478 fn clone(&self) -> Self {
480 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
481 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
487 /// Used only if an object of this type is returned as a trait impl by a method
488 pub(crate) extern "C" fn ChannelConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
489 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelConfig)).clone() })) as *mut c_void
492 pub extern "C" fn ChannelConfig_clone(orig: &ChannelConfig) -> ChannelConfig {
495 /// Amount (in millionths of a satoshi) the channel will charge per transferred satoshi.
496 /// This may be allowed to change at runtime in a later update, however doing so must result in
497 /// update messages sent to notify all nodes of our updated relay fee.
499 /// Default value: 0.
501 pub extern "C" fn ChannelConfig_get_fee_proportional_millionths(this_ptr: &ChannelConfig) -> u32 {
502 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fee_proportional_millionths;
505 /// Amount (in millionths of a satoshi) the channel will charge per transferred satoshi.
506 /// This may be allowed to change at runtime in a later update, however doing so must result in
507 /// update messages sent to notify all nodes of our updated relay fee.
509 /// Default value: 0.
511 pub extern "C" fn ChannelConfig_set_fee_proportional_millionths(this_ptr: &mut ChannelConfig, mut val: u32) {
512 unsafe { &mut *this_ptr.inner }.fee_proportional_millionths = val;
514 /// Set to announce the channel publicly and notify all nodes that they can route via this
517 /// This should only be set to true for nodes which expect to be online reliably.
519 /// As the node which funds a channel picks this value this will only apply for new outbound
520 /// channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set.
522 /// This cannot be changed after the initial channel handshake.
524 /// Default value: false.
526 pub extern "C" fn ChannelConfig_get_announced_channel(this_ptr: &ChannelConfig) -> bool {
527 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announced_channel;
530 /// Set to announce the channel publicly and notify all nodes that they can route via this
533 /// This should only be set to true for nodes which expect to be online reliably.
535 /// As the node which funds a channel picks this value this will only apply for new outbound
536 /// channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set.
538 /// This cannot be changed after the initial channel handshake.
540 /// Default value: false.
542 pub extern "C" fn ChannelConfig_set_announced_channel(this_ptr: &mut ChannelConfig, mut val: bool) {
543 unsafe { &mut *this_ptr.inner }.announced_channel = val;
545 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
546 /// supports it, they will then enforce the mutual-close output to us matches what we provided
547 /// at intialization, preventing us from closing to an alternate pubkey.
549 /// This is set to true by default to provide a slight increase in security, though ultimately
550 /// any attacker who is able to take control of a channel can just as easily send the funds via
551 /// lightning payments, so we never require that our counterparties support this option.
553 /// This cannot be changed after a channel has been initialized.
555 /// Default value: true.
557 pub extern "C" fn ChannelConfig_get_commit_upfront_shutdown_pubkey(this_ptr: &ChannelConfig) -> bool {
558 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.commit_upfront_shutdown_pubkey;
561 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
562 /// supports it, they will then enforce the mutual-close output to us matches what we provided
563 /// at intialization, preventing us from closing to an alternate pubkey.
565 /// This is set to true by default to provide a slight increase in security, though ultimately
566 /// any attacker who is able to take control of a channel can just as easily send the funds via
567 /// lightning payments, so we never require that our counterparties support this option.
569 /// This cannot be changed after a channel has been initialized.
571 /// Default value: true.
573 pub extern "C" fn ChannelConfig_set_commit_upfront_shutdown_pubkey(this_ptr: &mut ChannelConfig, mut val: bool) {
574 unsafe { &mut *this_ptr.inner }.commit_upfront_shutdown_pubkey = val;
578 pub extern "C" fn ChannelConfig_new(mut fee_proportional_millionths_arg: u32, mut announced_channel_arg: bool, mut commit_upfront_shutdown_pubkey_arg: bool) -> ChannelConfig {
579 ChannelConfig { inner: Box::into_raw(Box::new(nativeChannelConfig {
580 fee_proportional_millionths: fee_proportional_millionths_arg,
581 announced_channel: announced_channel_arg,
582 commit_upfront_shutdown_pubkey: commit_upfront_shutdown_pubkey_arg,
583 })), is_owned: true }
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 { &(*(*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) -> ChannelConfig {
600 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
601 ChannelConfig { inner: Box::into_raw(Box::new(res)), is_owned: true }
603 ChannelConfig { inner: std::ptr::null_mut(), is_owned: true }
607 use lightning::util::config::UserConfig as nativeUserConfigImport;
608 type nativeUserConfig = nativeUserConfigImport;
610 /// Top-level config which holds ChannelHandshakeLimits and ChannelConfig.
612 /// Default::default() provides sane defaults for most configurations
613 /// (but currently with 0 relay fees!)
616 pub struct UserConfig {
617 /// Nearly everywhere, inner must be non-null, however in places where
618 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
619 pub inner: *mut nativeUserConfig,
623 impl Drop for UserConfig {
625 if self.is_owned && !self.inner.is_null() {
626 let _ = unsafe { Box::from_raw(self.inner) };
631 pub extern "C" fn UserConfig_free(this_ptr: UserConfig) { }
633 /// Used only if an object of this type is returned as a trait impl by a method
634 extern "C" fn UserConfig_free_void(this_ptr: *mut c_void) {
635 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUserConfig); }
638 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
640 pub(crate) fn take_inner(mut self) -> *mut nativeUserConfig {
641 assert!(self.is_owned);
642 let ret = self.inner;
643 self.inner = std::ptr::null_mut();
647 impl Clone for UserConfig {
648 fn clone(&self) -> Self {
650 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
651 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
657 /// Used only if an object of this type is returned as a trait impl by a method
658 pub(crate) extern "C" fn UserConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
659 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUserConfig)).clone() })) as *mut c_void
662 pub extern "C" fn UserConfig_clone(orig: &UserConfig) -> UserConfig {
665 /// Channel config that we propose to our counterparty.
667 pub extern "C" fn UserConfig_get_own_channel_config(this_ptr: &UserConfig) -> crate::util::config::ChannelHandshakeConfig {
668 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.own_channel_config;
669 crate::util::config::ChannelHandshakeConfig { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
671 /// Channel config that we propose to our counterparty.
673 pub extern "C" fn UserConfig_set_own_channel_config(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelHandshakeConfig) {
674 unsafe { &mut *this_ptr.inner }.own_channel_config = *unsafe { Box::from_raw(val.take_inner()) };
676 /// Limits applied to our counterparty's proposed channel config settings.
678 pub extern "C" fn UserConfig_get_peer_channel_config_limits(this_ptr: &UserConfig) -> crate::util::config::ChannelHandshakeLimits {
679 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.peer_channel_config_limits;
680 crate::util::config::ChannelHandshakeLimits { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
682 /// Limits applied to our counterparty's proposed channel config settings.
684 pub extern "C" fn UserConfig_set_peer_channel_config_limits(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelHandshakeLimits) {
685 unsafe { &mut *this_ptr.inner }.peer_channel_config_limits = *unsafe { Box::from_raw(val.take_inner()) };
687 /// Channel config which affects behavior during channel lifetime.
689 pub extern "C" fn UserConfig_get_channel_options(this_ptr: &UserConfig) -> crate::util::config::ChannelConfig {
690 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_options;
691 crate::util::config::ChannelConfig { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
693 /// Channel config which affects behavior during channel lifetime.
695 pub extern "C" fn UserConfig_set_channel_options(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelConfig) {
696 unsafe { &mut *this_ptr.inner }.channel_options = *unsafe { Box::from_raw(val.take_inner()) };
700 pub extern "C" fn UserConfig_new(mut own_channel_config_arg: crate::util::config::ChannelHandshakeConfig, mut peer_channel_config_limits_arg: crate::util::config::ChannelHandshakeLimits, mut channel_options_arg: crate::util::config::ChannelConfig) -> UserConfig {
701 UserConfig { inner: Box::into_raw(Box::new(nativeUserConfig {
702 own_channel_config: *unsafe { Box::from_raw(own_channel_config_arg.take_inner()) },
703 peer_channel_config_limits: *unsafe { Box::from_raw(peer_channel_config_limits_arg.take_inner()) },
704 channel_options: *unsafe { Box::from_raw(channel_options_arg.take_inner()) },
705 })), is_owned: true }
709 pub extern "C" fn UserConfig_default() -> UserConfig {
710 UserConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }