X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Futil%2Fconfig.rs;h=e43312b9f139fef866d5cc0704dc5c0daf44333b;hb=ae39d0e5a34ef021db50b12a7be96f0694fd1b18;hp=0bec9636f839bb152c6bb34dc28abaf03c2f989e;hpb=4ed52804d3cd73f05bba6a705528d0d43495aa88;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/lightning/util/config.rs b/lightning-c-bindings/src/lightning/util/config.rs index 0bec963..e43312b 100644 --- a/lightning-c-bindings/src/lightning/util/config.rs +++ b/lightning-c-bindings/src/lightning/util/config.rs @@ -9,15 +9,17 @@ //! Various user-configurable channel limits and settings which ChannelManager //! applies for you. -use std::str::FromStr; -use std::ffi::c_void; +use alloc::str::FromStr; +use core::ffi::c_void; use core::convert::Infallible; use bitcoin::hashes::Hash; use crate::c_types::*; +#[cfg(feature="no-std")] +use alloc::{vec::Vec, boxed::Box}; use lightning::util::config::ChannelHandshakeConfig as nativeChannelHandshakeConfigImport; -type nativeChannelHandshakeConfig = nativeChannelHandshakeConfigImport; +pub(crate) type nativeChannelHandshakeConfig = nativeChannelHandshakeConfigImport; /// Configuration we set when applicable. /// @@ -49,7 +51,7 @@ impl Drop for ChannelHandshakeConfig { pub extern "C" fn ChannelHandshakeConfig_free(this_obj: ChannelHandshakeConfig) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ChannelHandshakeConfig_free_void(this_ptr: *mut c_void) { +pub(crate) extern "C" fn ChannelHandshakeConfig_free_void(this_ptr: *mut c_void) { unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelHandshakeConfig); } } #[allow(unused)] @@ -64,7 +66,7 @@ impl ChannelHandshakeConfig { pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeConfig { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } @@ -72,7 +74,15 @@ impl ChannelHandshakeConfig { /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the /// equivalent limit applied to outbound channels). /// +/// A lower-bound of 1 is applied, requiring all channels to have a confirmed commitment +/// transaction before operation. If you wish to accept channels with zero confirmations, see +/// [`UserConfig::manually_accept_inbound_channels`] and +/// [`ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`]. +/// /// Default value: 6. +/// +/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel +/// [`ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf #[no_mangle] pub extern "C" fn ChannelHandshakeConfig_get_minimum_depth(this_ptr: &ChannelHandshakeConfig) -> u32 { let mut inner_val = &mut this_ptr.get_native_mut_ref().minimum_depth; @@ -82,7 +92,15 @@ pub extern "C" fn ChannelHandshakeConfig_get_minimum_depth(this_ptr: &ChannelHan /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the /// equivalent limit applied to outbound channels). /// +/// A lower-bound of 1 is applied, requiring all channels to have a confirmed commitment +/// transaction before operation. If you wish to accept channels with zero confirmations, see +/// [`UserConfig::manually_accept_inbound_channels`] and +/// [`ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`]. +/// /// Default value: 6. +/// +/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel +/// [`ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf #[no_mangle] pub extern "C" fn ChannelHandshakeConfig_set_minimum_depth(this_ptr: &mut ChannelHandshakeConfig, mut val: u32) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.minimum_depth = val; @@ -149,20 +167,128 @@ pub extern "C" fn ChannelHandshakeConfig_get_our_htlc_minimum_msat(this_ptr: &Ch pub extern "C" fn ChannelHandshakeConfig_set_our_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeConfig, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.our_htlc_minimum_msat = val; } +/// Sets the percentage of the channel value we will cap the total value of outstanding inbound +/// HTLCs to. +/// +/// This can be set to a value between 1-100, where the value corresponds to the percent of the +/// channel value in whole percentages. +/// +/// Note that: +/// * If configured to another value than the default value 10, any new channels created with +/// the non default value will cause versions of LDK prior to 0.0.104 to refuse to read the +/// `ChannelManager`. +/// +/// * This caps the total value for inbound HTLCs in-flight only, and there's currently +/// no way to configure the cap for the total value of outbound HTLCs in-flight. +/// +/// * The requirements for your node being online to ensure the safety of HTLC-encumbered funds +/// are different from the non-HTLC-encumbered funds. This makes this an important knob to +/// restrict exposure to loss due to being offline for too long. +/// See [`ChannelHandshakeConfig::our_to_self_delay`] and [`ChannelConfig::cltv_expiry_delta`] +/// for more information. +/// +/// Default value: 10. +/// Minimum value: 1, any values less than 1 will be treated as 1 instead. +/// Maximum value: 100, any values larger than 100 will be treated as 100 instead. +#[no_mangle] +pub extern "C" fn ChannelHandshakeConfig_get_max_inbound_htlc_value_in_flight_percent_of_channel(this_ptr: &ChannelHandshakeConfig) -> u8 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().max_inbound_htlc_value_in_flight_percent_of_channel; + *inner_val +} +/// Sets the percentage of the channel value we will cap the total value of outstanding inbound +/// HTLCs to. +/// +/// This can be set to a value between 1-100, where the value corresponds to the percent of the +/// channel value in whole percentages. +/// +/// Note that: +/// * If configured to another value than the default value 10, any new channels created with +/// the non default value will cause versions of LDK prior to 0.0.104 to refuse to read the +/// `ChannelManager`. +/// +/// * This caps the total value for inbound HTLCs in-flight only, and there's currently +/// no way to configure the cap for the total value of outbound HTLCs in-flight. +/// +/// * The requirements for your node being online to ensure the safety of HTLC-encumbered funds +/// are different from the non-HTLC-encumbered funds. This makes this an important knob to +/// restrict exposure to loss due to being offline for too long. +/// See [`ChannelHandshakeConfig::our_to_self_delay`] and [`ChannelConfig::cltv_expiry_delta`] +/// for more information. +/// +/// Default value: 10. +/// Minimum value: 1, any values less than 1 will be treated as 1 instead. +/// Maximum value: 100, any values larger than 100 will be treated as 100 instead. +#[no_mangle] +pub extern "C" fn ChannelHandshakeConfig_set_max_inbound_htlc_value_in_flight_percent_of_channel(this_ptr: &mut ChannelHandshakeConfig, mut val: u8) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_inbound_htlc_value_in_flight_percent_of_channel = val; +} +/// If set, we attempt to negotiate the `scid_privacy` (referred to as `scid_alias` in the +/// BOLTs) option for outbound private channels. This provides better privacy by not including +/// our real on-chain channel UTXO in each invoice and requiring that our counterparty only +/// relay HTLCs to us using the channel's SCID alias. +/// +/// If this option is set, channels may be created that will not be readable by LDK versions +/// prior to 0.0.106, causing [`ChannelManager`]'s read method to return a +/// [`DecodeError:InvalidValue`]. +/// +/// Note that setting this to true does *not* prevent us from opening channels with +/// counterparties that do not support the `scid_alias` option; we will simply fall back to a +/// private channel without that option. +/// +/// Ignored if the channel is negotiated to be announced, see +/// [`ChannelConfig::announced_channel`] and +/// [`ChannelHandshakeLimits::force_announced_channel_preference`] for more. +/// +/// Default value: false. This value is likely to change to true in the future. +/// +/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager +/// [`DecodeError:InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue +#[no_mangle] +pub extern "C" fn ChannelHandshakeConfig_get_negotiate_scid_privacy(this_ptr: &ChannelHandshakeConfig) -> bool { + let mut inner_val = &mut this_ptr.get_native_mut_ref().negotiate_scid_privacy; + *inner_val +} +/// If set, we attempt to negotiate the `scid_privacy` (referred to as `scid_alias` in the +/// BOLTs) option for outbound private channels. This provides better privacy by not including +/// our real on-chain channel UTXO in each invoice and requiring that our counterparty only +/// relay HTLCs to us using the channel's SCID alias. +/// +/// If this option is set, channels may be created that will not be readable by LDK versions +/// prior to 0.0.106, causing [`ChannelManager`]'s read method to return a +/// [`DecodeError:InvalidValue`]. +/// +/// Note that setting this to true does *not* prevent us from opening channels with +/// counterparties that do not support the `scid_alias` option; we will simply fall back to a +/// private channel without that option. +/// +/// Ignored if the channel is negotiated to be announced, see +/// [`ChannelConfig::announced_channel`] and +/// [`ChannelHandshakeLimits::force_announced_channel_preference`] for more. +/// +/// Default value: false. This value is likely to change to true in the future. +/// +/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager +/// [`DecodeError:InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue +#[no_mangle] +pub extern "C" fn ChannelHandshakeConfig_set_negotiate_scid_privacy(this_ptr: &mut ChannelHandshakeConfig, mut val: bool) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.negotiate_scid_privacy = val; +} /// Constructs a new ChannelHandshakeConfig given each field #[must_use] #[no_mangle] -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 { +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, mut max_inbound_htlc_value_in_flight_percent_of_channel_arg: u8, mut negotiate_scid_privacy_arg: bool) -> ChannelHandshakeConfig { ChannelHandshakeConfig { inner: ObjOps::heap_alloc(nativeChannelHandshakeConfig { minimum_depth: minimum_depth_arg, our_to_self_delay: our_to_self_delay_arg, our_htlc_minimum_msat: our_htlc_minimum_msat_arg, + max_inbound_htlc_value_in_flight_percent_of_channel: max_inbound_htlc_value_in_flight_percent_of_channel_arg, + negotiate_scid_privacy: negotiate_scid_privacy_arg, }), is_owned: true } } impl Clone for ChannelHandshakeConfig { fn clone(&self) -> Self { Self { - inner: if <*mut nativeChannelHandshakeConfig>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeChannelHandshakeConfig>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -186,7 +312,7 @@ pub extern "C" fn ChannelHandshakeConfig_default() -> ChannelHandshakeConfig { } use lightning::util::config::ChannelHandshakeLimits as nativeChannelHandshakeLimitsImport; -type nativeChannelHandshakeLimits = nativeChannelHandshakeLimitsImport; +pub(crate) type nativeChannelHandshakeLimits = nativeChannelHandshakeLimitsImport; /// Optional channel limits which are applied during channel creation. /// @@ -226,7 +352,7 @@ impl Drop for ChannelHandshakeLimits { pub extern "C" fn ChannelHandshakeLimits_free(this_obj: ChannelHandshakeLimits) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ChannelHandshakeLimits_free_void(this_ptr: *mut c_void) { +pub(crate) extern "C" fn ChannelHandshakeLimits_free_void(this_ptr: *mut c_void) { unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelHandshakeLimits); } } #[allow(unused)] @@ -241,11 +367,11 @@ impl ChannelHandshakeLimits { pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeLimits { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } -/// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so +/// Minimum allowed satoshis when a channel is funded. This is supplied by the sender and so /// only applies to inbound channels. /// /// Default value: 0. @@ -254,7 +380,7 @@ pub extern "C" fn ChannelHandshakeLimits_get_min_funding_satoshis(this_ptr: &Cha let mut inner_val = &mut this_ptr.get_native_mut_ref().min_funding_satoshis; *inner_val } -/// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so +/// Minimum allowed satoshis when a channel is funded. This is supplied by the sender and so /// only applies to inbound channels. /// /// Default value: 0. @@ -262,6 +388,23 @@ pub extern "C" fn ChannelHandshakeLimits_get_min_funding_satoshis(this_ptr: &Cha pub extern "C" fn ChannelHandshakeLimits_set_min_funding_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.min_funding_satoshis = val; } +/// Maximum allowed satoshis when a channel is funded. This is supplied by the sender and so +/// only applies to inbound channels. +/// +/// Default value: 2^24 - 1. +#[no_mangle] +pub extern "C" fn ChannelHandshakeLimits_get_max_funding_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().max_funding_satoshis; + *inner_val +} +/// Maximum allowed satoshis when a channel is funded. This is supplied by the sender and so +/// only applies to inbound channels. +/// +/// Default value: 2^24 - 1. +#[no_mangle] +pub extern "C" fn ChannelHandshakeLimits_set_max_funding_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_funding_satoshis = val; +} /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows /// you to limit the maximum minimum-size they can require. /// @@ -353,6 +496,49 @@ pub extern "C" fn ChannelHandshakeLimits_get_max_minimum_depth(this_ptr: &Channe pub extern "C" fn ChannelHandshakeLimits_set_max_minimum_depth(this_ptr: &mut ChannelHandshakeLimits, mut val: u32) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_minimum_depth = val; } +/// Whether we implicitly trust funding transactions generated by us for our own outbound +/// channels to not be double-spent. +/// +/// If this is set, we assume that our own funding transactions are *never* double-spent, and +/// thus we can trust them without any confirmations. This is generally a reasonable +/// assumption, given we're the only ones who could ever double-spend it (assuming we have sole +/// control of the signing keys). +/// +/// You may wish to un-set this if you allow the user to (or do in an automated fashion) +/// double-spend the funding transaction to RBF with an alternative channel open. +/// +/// This only applies if our counterparty set their confirmations-required value to 0, and we +/// always trust our own funding transaction at 1 confirmation irrespective of this value. +/// Thus, this effectively acts as a `min_minimum_depth`, with the only possible values being +/// `true` (0) and `false` (1). +/// +/// Default value: true +#[no_mangle] +pub extern "C" fn ChannelHandshakeLimits_get_trust_own_funding_0conf(this_ptr: &ChannelHandshakeLimits) -> bool { + let mut inner_val = &mut this_ptr.get_native_mut_ref().trust_own_funding_0conf; + *inner_val +} +/// Whether we implicitly trust funding transactions generated by us for our own outbound +/// channels to not be double-spent. +/// +/// If this is set, we assume that our own funding transactions are *never* double-spent, and +/// thus we can trust them without any confirmations. This is generally a reasonable +/// assumption, given we're the only ones who could ever double-spend it (assuming we have sole +/// control of the signing keys). +/// +/// You may wish to un-set this if you allow the user to (or do in an automated fashion) +/// double-spend the funding transaction to RBF with an alternative channel open. +/// +/// This only applies if our counterparty set their confirmations-required value to 0, and we +/// always trust our own funding transaction at 1 confirmation irrespective of this value. +/// Thus, this effectively acts as a `min_minimum_depth`, with the only possible values being +/// `true` (0) and `false` (1). +/// +/// Default value: true +#[no_mangle] +pub extern "C" fn ChannelHandshakeLimits_set_trust_own_funding_0conf(this_ptr: &mut ChannelHandshakeLimits, mut val: bool) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.trust_own_funding_0conf = val; +} /// Set to force an incoming channel to match our announced channel preference in /// [`ChannelConfig::announced_channel`]. /// @@ -404,14 +590,16 @@ pub extern "C" fn ChannelHandshakeLimits_set_their_to_self_delay(this_ptr: &mut /// Constructs a new ChannelHandshakeLimits given each field #[must_use] #[no_mangle] -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 max_minimum_depth_arg: u32, mut force_announced_channel_preference_arg: bool, mut their_to_self_delay_arg: u16) -> ChannelHandshakeLimits { +pub extern "C" fn ChannelHandshakeLimits_new(mut min_funding_satoshis_arg: u64, mut max_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 max_minimum_depth_arg: u32, mut trust_own_funding_0conf_arg: bool, mut force_announced_channel_preference_arg: bool, mut their_to_self_delay_arg: u16) -> ChannelHandshakeLimits { ChannelHandshakeLimits { inner: ObjOps::heap_alloc(nativeChannelHandshakeLimits { min_funding_satoshis: min_funding_satoshis_arg, + max_funding_satoshis: max_funding_satoshis_arg, max_htlc_minimum_msat: max_htlc_minimum_msat_arg, min_max_htlc_value_in_flight_msat: min_max_htlc_value_in_flight_msat_arg, max_channel_reserve_satoshis: max_channel_reserve_satoshis_arg, min_max_accepted_htlcs: min_max_accepted_htlcs_arg, max_minimum_depth: max_minimum_depth_arg, + trust_own_funding_0conf: trust_own_funding_0conf_arg, force_announced_channel_preference: force_announced_channel_preference_arg, their_to_self_delay: their_to_self_delay_arg, }), is_owned: true } @@ -419,7 +607,7 @@ pub extern "C" fn ChannelHandshakeLimits_new(mut min_funding_satoshis_arg: u64, impl Clone for ChannelHandshakeLimits { fn clone(&self) -> Self { Self { - inner: if <*mut nativeChannelHandshakeLimits>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeChannelHandshakeLimits>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -443,7 +631,7 @@ pub extern "C" fn ChannelHandshakeLimits_default() -> ChannelHandshakeLimits { } use lightning::util::config::ChannelConfig as nativeChannelConfigImport; -type nativeChannelConfig = nativeChannelConfigImport; +pub(crate) type nativeChannelConfig = nativeChannelConfigImport; /// Options which apply on a per-channel basis and may change at runtime or based on negotiation /// with our counterparty. @@ -474,7 +662,7 @@ impl Drop for ChannelConfig { pub extern "C" fn ChannelConfig_free(this_obj: ChannelConfig) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ChannelConfig_free_void(this_ptr: *mut c_void) { +pub(crate) extern "C" fn ChannelConfig_free_void(this_ptr: *mut c_void) { unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelConfig); } } #[allow(unused)] @@ -489,7 +677,7 @@ impl ChannelConfig { pub(crate) fn take_inner(mut self) -> *mut nativeChannelConfig { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } @@ -765,7 +953,7 @@ pub extern "C" fn ChannelConfig_new(mut forwarding_fee_proportional_millionths_a impl Clone for ChannelConfig { fn clone(&self) -> Self { Self { - inner: if <*mut nativeChannelConfig>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeChannelConfig>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -789,7 +977,7 @@ pub extern "C" fn ChannelConfig_default() -> ChannelConfig { } #[no_mangle] /// Serialize the ChannelConfig object into a byte array which can be read by ChannelConfig_read -pub extern "C" fn ChannelConfig_write(obj: &ChannelConfig) -> crate::c_types::derived::CVec_u8Z { +pub extern "C" fn ChannelConfig_write(obj: &crate::lightning::util::config::ChannelConfig) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } #[no_mangle] @@ -799,13 +987,13 @@ pub(crate) extern "C" fn ChannelConfig_write_void(obj: *const c_void) -> crate:: #[no_mangle] /// Read a ChannelConfig from a byte array, created by ChannelConfig_write pub extern "C" fn ChannelConfig_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelConfigDecodeErrorZ { - let res = crate::c_types::deserialize_obj(ser); + let res: Result = crate::c_types::deserialize_obj(ser); let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::util::config::ChannelConfig { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; local_res } use lightning::util::config::UserConfig as nativeUserConfigImport; -type nativeUserConfig = nativeUserConfigImport; +pub(crate) type nativeUserConfig = nativeUserConfigImport; /// Top-level config which holds ChannelHandshakeLimits and ChannelConfig. /// @@ -838,7 +1026,7 @@ impl Drop for UserConfig { pub extern "C" fn UserConfig_free(this_obj: UserConfig) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn UserConfig_free_void(this_ptr: *mut c_void) { +pub(crate) extern "C" fn UserConfig_free_void(this_ptr: *mut c_void) { unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUserConfig); } } #[allow(unused)] @@ -853,7 +1041,7 @@ impl UserConfig { pub(crate) fn take_inner(mut self) -> *mut nativeUserConfig { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } @@ -861,7 +1049,7 @@ impl UserConfig { #[no_mangle] pub extern "C" fn UserConfig_get_own_channel_config(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelHandshakeConfig { let mut inner_val = &mut this_ptr.get_native_mut_ref().own_channel_config; - crate::lightning::util::config::ChannelHandshakeConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false } + crate::lightning::util::config::ChannelHandshakeConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::util::config::ChannelHandshakeConfig<>) as *mut _) }, is_owned: false } } /// Channel config that we propose to our counterparty. #[no_mangle] @@ -872,7 +1060,7 @@ pub extern "C" fn UserConfig_set_own_channel_config(this_ptr: &mut UserConfig, m #[no_mangle] pub extern "C" fn UserConfig_get_peer_channel_config_limits(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelHandshakeLimits { let mut inner_val = &mut this_ptr.get_native_mut_ref().peer_channel_config_limits; - crate::lightning::util::config::ChannelHandshakeLimits { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false } + crate::lightning::util::config::ChannelHandshakeLimits { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::util::config::ChannelHandshakeLimits<>) as *mut _) }, is_owned: false } } /// Limits applied to our counterparty's proposed channel config settings. #[no_mangle] @@ -883,7 +1071,7 @@ pub extern "C" fn UserConfig_set_peer_channel_config_limits(this_ptr: &mut UserC #[no_mangle] pub extern "C" fn UserConfig_get_channel_options(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelConfig { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_options; - crate::lightning::util::config::ChannelConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false } + crate::lightning::util::config::ChannelConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::util::config::ChannelConfig<>) as *mut _) }, is_owned: false } } /// Channel config which affects behavior during channel lifetime. #[no_mangle] @@ -931,21 +1119,71 @@ pub extern "C" fn UserConfig_get_accept_forwards_to_priv_channels(this_ptr: &Use pub extern "C" fn UserConfig_set_accept_forwards_to_priv_channels(this_ptr: &mut UserConfig, mut val: bool) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.accept_forwards_to_priv_channels = val; } +/// If this is set to false, we do not accept inbound requests to open a new channel. +/// Default value: true. +#[no_mangle] +pub extern "C" fn UserConfig_get_accept_inbound_channels(this_ptr: &UserConfig) -> bool { + let mut inner_val = &mut this_ptr.get_native_mut_ref().accept_inbound_channels; + *inner_val +} +/// If this is set to false, we do not accept inbound requests to open a new channel. +/// Default value: true. +#[no_mangle] +pub extern "C" fn UserConfig_set_accept_inbound_channels(this_ptr: &mut UserConfig, mut val: bool) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.accept_inbound_channels = val; +} +/// If this is set to true, the user needs to manually accept inbound requests to open a new +/// channel. +/// +/// When set to true, [`Event::OpenChannelRequest`] will be triggered once a request to open a +/// new inbound channel is received through a [`msgs::OpenChannel`] message. In that case, a +/// [`msgs::AcceptChannel`] message will not be sent back to the counterparty node unless the +/// user explicitly chooses to accept the request. +/// +/// Default value: false. +/// +/// [`Event::OpenChannelRequest`]: crate::util::events::Event::OpenChannelRequest +/// [`msgs::OpenChannel`]: crate::ln::msgs::OpenChannel +/// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel +#[no_mangle] +pub extern "C" fn UserConfig_get_manually_accept_inbound_channels(this_ptr: &UserConfig) -> bool { + let mut inner_val = &mut this_ptr.get_native_mut_ref().manually_accept_inbound_channels; + *inner_val +} +/// If this is set to true, the user needs to manually accept inbound requests to open a new +/// channel. +/// +/// When set to true, [`Event::OpenChannelRequest`] will be triggered once a request to open a +/// new inbound channel is received through a [`msgs::OpenChannel`] message. In that case, a +/// [`msgs::AcceptChannel`] message will not be sent back to the counterparty node unless the +/// user explicitly chooses to accept the request. +/// +/// Default value: false. +/// +/// [`Event::OpenChannelRequest`]: crate::util::events::Event::OpenChannelRequest +/// [`msgs::OpenChannel`]: crate::ln::msgs::OpenChannel +/// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel +#[no_mangle] +pub extern "C" fn UserConfig_set_manually_accept_inbound_channels(this_ptr: &mut UserConfig, mut val: bool) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.manually_accept_inbound_channels = val; +} /// Constructs a new UserConfig given each field #[must_use] #[no_mangle] -pub extern "C" fn UserConfig_new(mut own_channel_config_arg: crate::lightning::util::config::ChannelHandshakeConfig, mut peer_channel_config_limits_arg: crate::lightning::util::config::ChannelHandshakeLimits, mut channel_options_arg: crate::lightning::util::config::ChannelConfig, mut accept_forwards_to_priv_channels_arg: bool) -> UserConfig { +pub extern "C" fn UserConfig_new(mut own_channel_config_arg: crate::lightning::util::config::ChannelHandshakeConfig, mut peer_channel_config_limits_arg: crate::lightning::util::config::ChannelHandshakeLimits, mut channel_options_arg: crate::lightning::util::config::ChannelConfig, mut accept_forwards_to_priv_channels_arg: bool, mut accept_inbound_channels_arg: bool, mut manually_accept_inbound_channels_arg: bool) -> UserConfig { UserConfig { inner: ObjOps::heap_alloc(nativeUserConfig { own_channel_config: *unsafe { Box::from_raw(own_channel_config_arg.take_inner()) }, peer_channel_config_limits: *unsafe { Box::from_raw(peer_channel_config_limits_arg.take_inner()) }, channel_options: *unsafe { Box::from_raw(channel_options_arg.take_inner()) }, accept_forwards_to_priv_channels: accept_forwards_to_priv_channels_arg, + accept_inbound_channels: accept_inbound_channels_arg, + manually_accept_inbound_channels: manually_accept_inbound_channels_arg, }), is_owned: true } } impl Clone for UserConfig { fn clone(&self) -> Self { Self { - inner: if <*mut nativeUserConfig>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeUserConfig>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, }