1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! Various user-configurable channel limits and settings which ChannelManager
13 use bitcoin::hashes::Hash;
14 use crate::c_types::*;
17 use lightning::util::config::ChannelHandshakeConfig as nativeChannelHandshakeConfigImport;
18 type nativeChannelHandshakeConfig = nativeChannelHandshakeConfigImport;
20 /// Configuration we set when applicable.
22 /// Default::default() provides sane defaults.
25 pub struct ChannelHandshakeConfig {
26 /// A pointer to the opaque Rust object.
28 /// Nearly everywhere, inner must be non-null, however in places where
29 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
30 pub inner: *mut nativeChannelHandshakeConfig,
31 /// Indicates that this is the only struct which contains the same pointer.
33 /// Rust functions which take ownership of an object provided via an argument require
34 /// this to be true and invalidate the object pointed to by inner.
38 impl Drop for ChannelHandshakeConfig {
40 if self.is_owned && !<*mut nativeChannelHandshakeConfig>::is_null(self.inner) {
41 let _ = unsafe { Box::from_raw(self.inner) };
45 /// Frees any resources used by the ChannelHandshakeConfig, if is_owned is set and inner is non-NULL.
47 pub extern "C" fn ChannelHandshakeConfig_free(this_obj: ChannelHandshakeConfig) { }
49 /// Used only if an object of this type is returned as a trait impl by a method
50 extern "C" fn ChannelHandshakeConfig_free_void(this_ptr: *mut c_void) {
51 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelHandshakeConfig); }
54 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
55 impl ChannelHandshakeConfig {
56 pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeConfig {
57 assert!(self.is_owned);
59 self.inner = std::ptr::null_mut();
63 /// Confirmations we will wait for before considering the channel locked in.
64 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
65 /// equivalent limit applied to outbound channels).
69 pub extern "C" fn ChannelHandshakeConfig_get_minimum_depth(this_ptr: &ChannelHandshakeConfig) -> u32 {
70 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.minimum_depth;
73 /// Confirmations we will wait for before considering the channel locked in.
74 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
75 /// equivalent limit applied to outbound channels).
79 pub extern "C" fn ChannelHandshakeConfig_set_minimum_depth(this_ptr: &mut ChannelHandshakeConfig, mut val: u32) {
80 unsafe { &mut *this_ptr.inner }.minimum_depth = val;
82 /// Set to the amount of time we require our counterparty to wait to claim their money.
84 /// It's one of the main parameter of our security model. We (or one of our watchtowers) MUST
85 /// be online to check for peer having broadcast a revoked transaction to steal our funds
86 /// at least once every our_to_self_delay blocks.
88 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
89 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
92 /// Default value: [`BREAKDOWN_TIMEOUT`] (currently 144), we enforce it as a minimum at channel
93 /// opening so you can tweak config to ask for more security, not less.
95 pub extern "C" fn ChannelHandshakeConfig_get_our_to_self_delay(this_ptr: &ChannelHandshakeConfig) -> u16 {
96 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.our_to_self_delay;
99 /// Set to the amount of time we require our counterparty to wait to claim their money.
101 /// It's one of the main parameter of our security model. We (or one of our watchtowers) MUST
102 /// be online to check for peer having broadcast a revoked transaction to steal our funds
103 /// at least once every our_to_self_delay blocks.
105 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
106 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
109 /// Default value: [`BREAKDOWN_TIMEOUT`] (currently 144), we enforce it as a minimum at channel
110 /// opening so you can tweak config to ask for more security, not less.
112 pub extern "C" fn ChannelHandshakeConfig_set_our_to_self_delay(this_ptr: &mut ChannelHandshakeConfig, mut val: u16) {
113 unsafe { &mut *this_ptr.inner }.our_to_self_delay = val;
115 /// Set to the smallest value HTLC we will accept to process.
117 /// This value is sent to our counterparty on channel-open and we close the channel any time
118 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
120 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
123 pub extern "C" fn ChannelHandshakeConfig_get_our_htlc_minimum_msat(this_ptr: &ChannelHandshakeConfig) -> u64 {
124 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.our_htlc_minimum_msat;
127 /// Set to the smallest value HTLC we will accept to process.
129 /// This value is sent to our counterparty on channel-open and we close the channel any time
130 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
132 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
135 pub extern "C" fn ChannelHandshakeConfig_set_our_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeConfig, mut val: u64) {
136 unsafe { &mut *this_ptr.inner }.our_htlc_minimum_msat = val;
138 /// Constructs a new ChannelHandshakeConfig given each field
141 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 {
142 ChannelHandshakeConfig { inner: Box::into_raw(Box::new(nativeChannelHandshakeConfig {
143 minimum_depth: minimum_depth_arg,
144 our_to_self_delay: our_to_self_delay_arg,
145 our_htlc_minimum_msat: our_htlc_minimum_msat_arg,
146 })), is_owned: true }
148 impl Clone for ChannelHandshakeConfig {
149 fn clone(&self) -> Self {
151 inner: if <*mut nativeChannelHandshakeConfig>::is_null(self.inner) { std::ptr::null_mut() } else {
152 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
158 /// Used only if an object of this type is returned as a trait impl by a method
159 pub(crate) extern "C" fn ChannelHandshakeConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
160 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeConfig)).clone() })) as *mut c_void
163 /// Creates a copy of the ChannelHandshakeConfig
164 pub extern "C" fn ChannelHandshakeConfig_clone(orig: &ChannelHandshakeConfig) -> ChannelHandshakeConfig {
167 /// Creates a "default" ChannelHandshakeConfig. See struct and individual field documentaiton for details on which values are used.
170 pub extern "C" fn ChannelHandshakeConfig_default() -> ChannelHandshakeConfig {
171 ChannelHandshakeConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
174 use lightning::util::config::ChannelHandshakeLimits as nativeChannelHandshakeLimitsImport;
175 type nativeChannelHandshakeLimits = nativeChannelHandshakeLimitsImport;
177 /// Optional channel limits which are applied during channel creation.
179 /// These limits are only applied to our counterparty's limits, not our own.
181 /// Use 0/<type>::max_value() as appropriate to skip checking.
183 /// Provides sane defaults for most configurations.
185 /// Most additional limits are disabled except those with which specify a default in individual
186 /// field documentation. Note that this may result in barely-usable channels, but since they
187 /// are applied mostly only to incoming channels that's not much of a problem.
190 pub struct ChannelHandshakeLimits {
191 /// A pointer to the opaque Rust object.
193 /// Nearly everywhere, inner must be non-null, however in places where
194 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
195 pub inner: *mut nativeChannelHandshakeLimits,
196 /// Indicates that this is the only struct which contains the same pointer.
198 /// Rust functions which take ownership of an object provided via an argument require
199 /// this to be true and invalidate the object pointed to by inner.
203 impl Drop for ChannelHandshakeLimits {
205 if self.is_owned && !<*mut nativeChannelHandshakeLimits>::is_null(self.inner) {
206 let _ = unsafe { Box::from_raw(self.inner) };
210 /// Frees any resources used by the ChannelHandshakeLimits, if is_owned is set and inner is non-NULL.
212 pub extern "C" fn ChannelHandshakeLimits_free(this_obj: ChannelHandshakeLimits) { }
214 /// Used only if an object of this type is returned as a trait impl by a method
215 extern "C" fn ChannelHandshakeLimits_free_void(this_ptr: *mut c_void) {
216 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelHandshakeLimits); }
219 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
220 impl ChannelHandshakeLimits {
221 pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeLimits {
222 assert!(self.is_owned);
223 let ret = self.inner;
224 self.inner = std::ptr::null_mut();
228 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
229 /// only applies to inbound channels.
231 /// Default value: 0.
233 pub extern "C" fn ChannelHandshakeLimits_get_min_funding_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
234 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_funding_satoshis;
237 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
238 /// only applies to inbound channels.
240 /// Default value: 0.
242 pub extern "C" fn ChannelHandshakeLimits_set_min_funding_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
243 unsafe { &mut *this_ptr.inner }.min_funding_satoshis = val;
245 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
246 /// you to limit the maximum minimum-size they can require.
248 /// Default value: u64::max_value.
250 pub extern "C" fn ChannelHandshakeLimits_get_max_htlc_minimum_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
251 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_htlc_minimum_msat;
254 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
255 /// you to limit the maximum minimum-size they can require.
257 /// Default value: u64::max_value.
259 pub extern "C" fn ChannelHandshakeLimits_set_max_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
260 unsafe { &mut *this_ptr.inner }.max_htlc_minimum_msat = val;
262 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
263 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
265 /// Default value: 0.
267 pub extern "C" fn ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
268 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_max_htlc_value_in_flight_msat;
271 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
272 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
274 /// Default value: 0.
276 pub extern "C" fn ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
277 unsafe { &mut *this_ptr.inner }.min_max_htlc_value_in_flight_msat = val;
279 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
280 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
281 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
283 /// Default value: u64::max_value.
285 pub extern "C" fn ChannelHandshakeLimits_get_max_channel_reserve_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
286 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_channel_reserve_satoshis;
289 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
290 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
291 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
293 /// Default value: u64::max_value.
295 pub extern "C" fn ChannelHandshakeLimits_set_max_channel_reserve_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
296 unsafe { &mut *this_ptr.inner }.max_channel_reserve_satoshis = val;
298 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
299 /// time. This allows you to set a minimum such value.
301 /// Default value: 0.
303 pub extern "C" fn ChannelHandshakeLimits_get_min_max_accepted_htlcs(this_ptr: &ChannelHandshakeLimits) -> u16 {
304 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_max_accepted_htlcs;
307 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
308 /// time. This allows you to set a minimum such value.
310 /// Default value: 0.
312 pub extern "C" fn ChannelHandshakeLimits_set_min_max_accepted_htlcs(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
313 unsafe { &mut *this_ptr.inner }.min_max_accepted_htlcs = val;
315 /// Outputs below a certain value will not be added to on-chain transactions. The dust value is
316 /// required to always be higher than this value so this only applies to HTLC outputs (and
317 /// potentially to-self outputs before any payments have been made).
318 /// Thus, HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
319 /// This setting allows you to set a minimum dust limit for their commitment transactions,
320 /// reflecting the reality that tiny outputs are not considered standard transactions and will
321 /// not propagate through the Bitcoin network.
323 /// Default value: 546, the current dust limit on the Bitcoin network.
325 pub extern "C" fn ChannelHandshakeLimits_get_min_dust_limit_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
326 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_dust_limit_satoshis;
329 /// Outputs below a certain value will not be added to on-chain transactions. The dust value is
330 /// required to always be higher than this value so this only applies to HTLC outputs (and
331 /// potentially to-self outputs before any payments have been made).
332 /// Thus, HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
333 /// This setting allows you to set a minimum dust limit for their commitment transactions,
334 /// reflecting the reality that tiny outputs are not considered standard transactions and will
335 /// not propagate through the Bitcoin network.
337 /// Default value: 546, the current dust limit on the Bitcoin network.
339 pub extern "C" fn ChannelHandshakeLimits_set_min_dust_limit_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
340 unsafe { &mut *this_ptr.inner }.min_dust_limit_satoshis = val;
342 /// Maximum allowed threshold above which outputs will not be generated in their commitment
344 /// HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
346 /// Default value: u64::max_value.
348 pub extern "C" fn ChannelHandshakeLimits_get_max_dust_limit_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
349 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_dust_limit_satoshis;
352 /// Maximum allowed threshold above which outputs will not be generated in their commitment
354 /// HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
356 /// Default value: u64::max_value.
358 pub extern "C" fn ChannelHandshakeLimits_set_max_dust_limit_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
359 unsafe { &mut *this_ptr.inner }.max_dust_limit_satoshis = val;
361 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
362 /// certain number of blocks, specified by the node which is not the funder (as the funder can
363 /// assume they aren't going to double-spend themselves).
364 /// This config allows you to set a limit on the maximum amount of time to wait.
366 /// Default value: 144, or roughly one day and only applies to outbound channels.
368 pub extern "C" fn ChannelHandshakeLimits_get_max_minimum_depth(this_ptr: &ChannelHandshakeLimits) -> u32 {
369 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_minimum_depth;
372 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
373 /// certain number of blocks, specified by the node which is not the funder (as the funder can
374 /// assume they aren't going to double-spend themselves).
375 /// This config allows you to set a limit on the maximum amount of time to wait.
377 /// Default value: 144, or roughly one day and only applies to outbound channels.
379 pub extern "C" fn ChannelHandshakeLimits_set_max_minimum_depth(this_ptr: &mut ChannelHandshakeLimits, mut val: u32) {
380 unsafe { &mut *this_ptr.inner }.max_minimum_depth = val;
382 /// Set to force the incoming channel to match our announced channel preference in
385 /// Default value: true, to make the default that no announced channels are possible (which is
386 /// appropriate for any nodes which are not online very reliably).
388 pub extern "C" fn ChannelHandshakeLimits_get_force_announced_channel_preference(this_ptr: &ChannelHandshakeLimits) -> bool {
389 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.force_announced_channel_preference;
392 /// Set to force the incoming channel to match our announced channel preference in
395 /// Default value: true, to make the default that no announced channels are possible (which is
396 /// appropriate for any nodes which are not online very reliably).
398 pub extern "C" fn ChannelHandshakeLimits_set_force_announced_channel_preference(this_ptr: &mut ChannelHandshakeLimits, mut val: bool) {
399 unsafe { &mut *this_ptr.inner }.force_announced_channel_preference = val;
401 /// Set to the amount of time we're willing to wait to claim money back to us.
403 /// Not checking this value would be a security issue, as our peer would be able to set it to
404 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
406 /// Default value: 2016, which we also enforce as a maximum value so you can tweak config to
407 /// reduce the loss of having useless locked funds (if your peer accepts)
409 pub extern "C" fn ChannelHandshakeLimits_get_their_to_self_delay(this_ptr: &ChannelHandshakeLimits) -> u16 {
410 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.their_to_self_delay;
413 /// Set to the amount of time we're willing to wait to claim money back to us.
415 /// Not checking this value would be a security issue, as our peer would be able to set it to
416 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
418 /// Default value: 2016, which we also enforce as a maximum value so you can tweak config to
419 /// reduce the loss of having useless locked funds (if your peer accepts)
421 pub extern "C" fn ChannelHandshakeLimits_set_their_to_self_delay(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
422 unsafe { &mut *this_ptr.inner }.their_to_self_delay = val;
424 /// Constructs a new ChannelHandshakeLimits given each field
427 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 {
428 ChannelHandshakeLimits { inner: Box::into_raw(Box::new(nativeChannelHandshakeLimits {
429 min_funding_satoshis: min_funding_satoshis_arg,
430 max_htlc_minimum_msat: max_htlc_minimum_msat_arg,
431 min_max_htlc_value_in_flight_msat: min_max_htlc_value_in_flight_msat_arg,
432 max_channel_reserve_satoshis: max_channel_reserve_satoshis_arg,
433 min_max_accepted_htlcs: min_max_accepted_htlcs_arg,
434 min_dust_limit_satoshis: min_dust_limit_satoshis_arg,
435 max_dust_limit_satoshis: max_dust_limit_satoshis_arg,
436 max_minimum_depth: max_minimum_depth_arg,
437 force_announced_channel_preference: force_announced_channel_preference_arg,
438 their_to_self_delay: their_to_self_delay_arg,
439 })), is_owned: true }
441 impl Clone for ChannelHandshakeLimits {
442 fn clone(&self) -> Self {
444 inner: if <*mut nativeChannelHandshakeLimits>::is_null(self.inner) { std::ptr::null_mut() } else {
445 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
451 /// Used only if an object of this type is returned as a trait impl by a method
452 pub(crate) extern "C" fn ChannelHandshakeLimits_clone_void(this_ptr: *const c_void) -> *mut c_void {
453 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeLimits)).clone() })) as *mut c_void
456 /// Creates a copy of the ChannelHandshakeLimits
457 pub extern "C" fn ChannelHandshakeLimits_clone(orig: &ChannelHandshakeLimits) -> ChannelHandshakeLimits {
460 /// Creates a "default" ChannelHandshakeLimits. See struct and individual field documentaiton for details on which values are used.
463 pub extern "C" fn ChannelHandshakeLimits_default() -> ChannelHandshakeLimits {
464 ChannelHandshakeLimits { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
467 use lightning::util::config::ChannelConfig as nativeChannelConfigImport;
468 type nativeChannelConfig = nativeChannelConfigImport;
470 /// Options which apply on a per-channel basis and may change at runtime or based on negotiation
471 /// with our counterparty.
474 pub struct ChannelConfig {
475 /// A pointer to the opaque Rust object.
477 /// Nearly everywhere, inner must be non-null, however in places where
478 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
479 pub inner: *mut nativeChannelConfig,
480 /// Indicates that this is the only struct which contains the same pointer.
482 /// Rust functions which take ownership of an object provided via an argument require
483 /// this to be true and invalidate the object pointed to by inner.
487 impl Drop for ChannelConfig {
489 if self.is_owned && !<*mut nativeChannelConfig>::is_null(self.inner) {
490 let _ = unsafe { Box::from_raw(self.inner) };
494 /// Frees any resources used by the ChannelConfig, if is_owned is set and inner is non-NULL.
496 pub extern "C" fn ChannelConfig_free(this_obj: ChannelConfig) { }
498 /// Used only if an object of this type is returned as a trait impl by a method
499 extern "C" fn ChannelConfig_free_void(this_ptr: *mut c_void) {
500 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelConfig); }
503 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
505 pub(crate) fn take_inner(mut self) -> *mut nativeChannelConfig {
506 assert!(self.is_owned);
507 let ret = self.inner;
508 self.inner = std::ptr::null_mut();
512 /// Amount (in millionths of a satoshi) the channel will charge per transferred satoshi.
513 /// This may be allowed to change at runtime in a later update, however doing so must result in
514 /// update messages sent to notify all nodes of our updated relay fee.
516 /// Default value: 0.
518 pub extern "C" fn ChannelConfig_get_fee_proportional_millionths(this_ptr: &ChannelConfig) -> u32 {
519 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fee_proportional_millionths;
522 /// Amount (in millionths of a satoshi) the channel will charge per transferred satoshi.
523 /// This may be allowed to change at runtime in a later update, however doing so must result in
524 /// update messages sent to notify all nodes of our updated relay fee.
526 /// Default value: 0.
528 pub extern "C" fn ChannelConfig_set_fee_proportional_millionths(this_ptr: &mut ChannelConfig, mut val: u32) {
529 unsafe { &mut *this_ptr.inner }.fee_proportional_millionths = val;
531 /// Set to announce the channel publicly and notify all nodes that they can route via this
534 /// This should only be set to true for nodes which expect to be online reliably.
536 /// As the node which funds a channel picks this value this will only apply for new outbound
537 /// channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set.
539 /// This cannot be changed after the initial channel handshake.
541 /// Default value: false.
543 pub extern "C" fn ChannelConfig_get_announced_channel(this_ptr: &ChannelConfig) -> bool {
544 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announced_channel;
547 /// Set to announce the channel publicly and notify all nodes that they can route via this
550 /// This should only be set to true for nodes which expect to be online reliably.
552 /// As the node which funds a channel picks this value this will only apply for new outbound
553 /// channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set.
555 /// This cannot be changed after the initial channel handshake.
557 /// Default value: false.
559 pub extern "C" fn ChannelConfig_set_announced_channel(this_ptr: &mut ChannelConfig, mut val: bool) {
560 unsafe { &mut *this_ptr.inner }.announced_channel = val;
562 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
563 /// supports it, they will then enforce the mutual-close output to us matches what we provided
564 /// at intialization, preventing us from closing to an alternate pubkey.
566 /// This is set to true by default to provide a slight increase in security, though ultimately
567 /// any attacker who is able to take control of a channel can just as easily send the funds via
568 /// lightning payments, so we never require that our counterparties support this option.
570 /// This cannot be changed after a channel has been initialized.
572 /// Default value: true.
574 pub extern "C" fn ChannelConfig_get_commit_upfront_shutdown_pubkey(this_ptr: &ChannelConfig) -> bool {
575 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.commit_upfront_shutdown_pubkey;
578 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
579 /// supports it, they will then enforce the mutual-close output to us matches what we provided
580 /// at intialization, preventing us from closing to an alternate pubkey.
582 /// This is set to true by default to provide a slight increase in security, though ultimately
583 /// any attacker who is able to take control of a channel can just as easily send the funds via
584 /// lightning payments, so we never require that our counterparties support this option.
586 /// This cannot be changed after a channel has been initialized.
588 /// Default value: true.
590 pub extern "C" fn ChannelConfig_set_commit_upfront_shutdown_pubkey(this_ptr: &mut ChannelConfig, mut val: bool) {
591 unsafe { &mut *this_ptr.inner }.commit_upfront_shutdown_pubkey = val;
593 /// Constructs a new ChannelConfig given each field
596 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 {
597 ChannelConfig { inner: Box::into_raw(Box::new(nativeChannelConfig {
598 fee_proportional_millionths: fee_proportional_millionths_arg,
599 announced_channel: announced_channel_arg,
600 commit_upfront_shutdown_pubkey: commit_upfront_shutdown_pubkey_arg,
601 })), is_owned: true }
603 impl Clone for ChannelConfig {
604 fn clone(&self) -> Self {
606 inner: if <*mut nativeChannelConfig>::is_null(self.inner) { std::ptr::null_mut() } else {
607 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
613 /// Used only if an object of this type is returned as a trait impl by a method
614 pub(crate) extern "C" fn ChannelConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
615 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelConfig)).clone() })) as *mut c_void
618 /// Creates a copy of the ChannelConfig
619 pub extern "C" fn ChannelConfig_clone(orig: &ChannelConfig) -> ChannelConfig {
622 /// Creates a "default" ChannelConfig. See struct and individual field documentaiton for details on which values are used.
625 pub extern "C" fn ChannelConfig_default() -> ChannelConfig {
626 ChannelConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
629 /// Serialize the ChannelConfig object into a byte array which can be read by ChannelConfig_read
630 pub extern "C" fn ChannelConfig_write(obj: &ChannelConfig) -> crate::c_types::derived::CVec_u8Z {
631 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
634 pub(crate) extern "C" fn ChannelConfig_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
635 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelConfig) })
638 /// Read a ChannelConfig from a byte array, created by ChannelConfig_write
639 pub extern "C" fn ChannelConfig_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelConfigDecodeErrorZ {
640 let res = crate::c_types::deserialize_obj(ser);
641 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() };
645 use lightning::util::config::UserConfig as nativeUserConfigImport;
646 type nativeUserConfig = nativeUserConfigImport;
648 /// Top-level config which holds ChannelHandshakeLimits and ChannelConfig.
650 /// Default::default() provides sane defaults for most configurations
651 /// (but currently with 0 relay fees!)
654 pub struct UserConfig {
655 /// A pointer to the opaque Rust object.
657 /// Nearly everywhere, inner must be non-null, however in places where
658 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
659 pub inner: *mut nativeUserConfig,
660 /// Indicates that this is the only struct which contains the same pointer.
662 /// Rust functions which take ownership of an object provided via an argument require
663 /// this to be true and invalidate the object pointed to by inner.
667 impl Drop for UserConfig {
669 if self.is_owned && !<*mut nativeUserConfig>::is_null(self.inner) {
670 let _ = unsafe { Box::from_raw(self.inner) };
674 /// Frees any resources used by the UserConfig, if is_owned is set and inner is non-NULL.
676 pub extern "C" fn UserConfig_free(this_obj: UserConfig) { }
678 /// Used only if an object of this type is returned as a trait impl by a method
679 extern "C" fn UserConfig_free_void(this_ptr: *mut c_void) {
680 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUserConfig); }
683 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
685 pub(crate) fn take_inner(mut self) -> *mut nativeUserConfig {
686 assert!(self.is_owned);
687 let ret = self.inner;
688 self.inner = std::ptr::null_mut();
692 /// Channel config that we propose to our counterparty.
694 pub extern "C" fn UserConfig_get_own_channel_config(this_ptr: &UserConfig) -> crate::util::config::ChannelHandshakeConfig {
695 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.own_channel_config;
696 crate::util::config::ChannelHandshakeConfig { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
698 /// Channel config that we propose to our counterparty.
700 pub extern "C" fn UserConfig_set_own_channel_config(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelHandshakeConfig) {
701 unsafe { &mut *this_ptr.inner }.own_channel_config = *unsafe { Box::from_raw(val.take_inner()) };
703 /// Limits applied to our counterparty's proposed channel config settings.
705 pub extern "C" fn UserConfig_get_peer_channel_config_limits(this_ptr: &UserConfig) -> crate::util::config::ChannelHandshakeLimits {
706 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.peer_channel_config_limits;
707 crate::util::config::ChannelHandshakeLimits { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
709 /// Limits applied to our counterparty's proposed channel config settings.
711 pub extern "C" fn UserConfig_set_peer_channel_config_limits(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelHandshakeLimits) {
712 unsafe { &mut *this_ptr.inner }.peer_channel_config_limits = *unsafe { Box::from_raw(val.take_inner()) };
714 /// Channel config which affects behavior during channel lifetime.
716 pub extern "C" fn UserConfig_get_channel_options(this_ptr: &UserConfig) -> crate::util::config::ChannelConfig {
717 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_options;
718 crate::util::config::ChannelConfig { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
720 /// Channel config which affects behavior during channel lifetime.
722 pub extern "C" fn UserConfig_set_channel_options(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelConfig) {
723 unsafe { &mut *this_ptr.inner }.channel_options = *unsafe { Box::from_raw(val.take_inner()) };
725 /// Constructs a new UserConfig given each field
728 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 {
729 UserConfig { inner: Box::into_raw(Box::new(nativeUserConfig {
730 own_channel_config: *unsafe { Box::from_raw(own_channel_config_arg.take_inner()) },
731 peer_channel_config_limits: *unsafe { Box::from_raw(peer_channel_config_limits_arg.take_inner()) },
732 channel_options: *unsafe { Box::from_raw(channel_options_arg.take_inner()) },
733 })), is_owned: true }
735 impl Clone for UserConfig {
736 fn clone(&self) -> Self {
738 inner: if <*mut nativeUserConfig>::is_null(self.inner) { std::ptr::null_mut() } else {
739 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
745 /// Used only if an object of this type is returned as a trait impl by a method
746 pub(crate) extern "C" fn UserConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
747 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUserConfig)).clone() })) as *mut c_void
750 /// Creates a copy of the UserConfig
751 pub extern "C" fn UserConfig_clone(orig: &UserConfig) -> UserConfig {
754 /// Creates a "default" UserConfig. See struct and individual field documentaiton for details on which values are used.
757 pub extern "C" fn UserConfig_default() -> UserConfig {
758 UserConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }