//! 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;
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
}
}
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;
}
+/// 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 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,
+ 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,
}
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
}
}
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,
}
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
}
}
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,
}
}
#[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]
#[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<lightning::util::config::ChannelConfig, lightning::ln::msgs::DecodeError> = 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
}
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
}
}
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,
}