Skip to content

Commit

Permalink
Introduce default_config function
Browse files Browse the repository at this point in the history
.. this allows us the retrieve a `Config` prepopulated with default values in
bindings (where `Default::default()` isn't available), even if it
includes complex structures for which we can't set default values in the
UDL file.
  • Loading branch information
tnull committed Feb 5, 2024
1 parent e335f0b commit b06cc07
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ class AndroidLibTest {
val listenAddress1 = "127.0.0.1:2323"
val listenAddress2 = "127.0.0.1:2324"

val config1 = Config()
val config1 = defaultConfig()
config1.storageDirPath = tmpDir1
config1.listeningAddresses = listOf(listenAddress1)
config1.network = Network.REGTEST
config1.logLevel = LogLevel.TRACE

val config2 = Config()
val config2 = defaultConfig()
config2.storageDirPath = tmpDir2
config2.listeningAddresses = listOf(listenAddress2)
config2.network = Network.REGTEST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ class LibraryTest {
val listenAddress1 = "127.0.0.1:2323"
val listenAddress2 = "127.0.0.1:2324"

val config1 = Config()
val config1 = defaultConfig()
config1.storageDirPath = tmpDir1
config1.listeningAddresses = listOf(listenAddress1)
config1.network = Network.REGTEST
config1.logLevel = LogLevel.TRACE

println("Config 1: $config1")

val config2 = Config()
val config2 = defaultConfig()
config2.storageDirPath = tmpDir2
config2.listeningAddresses = listOf(listenAddress2)
config2.network = Network.REGTEST
Expand Down
23 changes: 12 additions & 11 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
namespace ldk_node {
Mnemonic generate_entropy_mnemonic();
Config default_config();
};

dictionary Config {
string storage_dir_path = "/tmp/ldk_node/";
string? log_dir_path = null;
Network network = "Bitcoin";
sequence<SocketAddress>? listening_addresses = null;
u32 default_cltv_expiry_delta = 144;
u64 onchain_wallet_sync_interval_secs = 80;
u64 wallet_sync_interval_secs = 30;
u64 fee_rate_cache_update_interval_secs = 600;
sequence<PublicKey> trusted_peers_0conf = [];
u64 probing_liquidity_limit_multiplier = 3;
LogLevel log_level = "Debug";
string storage_dir_path;
string? log_dir_path;
Network network;
sequence<SocketAddress>? listening_addresses;
u32 default_cltv_expiry_delta;
u64 onchain_wallet_sync_interval_secs;
u64 wallet_sync_interval_secs;
u64 fee_rate_cache_update_interval_secs;
sequence<PublicKey> trusted_peers_0conf;
u64 probing_liquidity_limit_multiplier;
LogLevel log_level;
};

interface Builder {
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/src/ldk_node/test_ldk_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def send_to_address(address, amount_sats):


def setup_node(tmp_dir, esplora_endpoint, listening_addresses):
config = Config()
config = default_config()
builder = Builder.from_config(config)
builder.set_storage_dir_path(tmp_dir)
builder.set_esplora_server(esplora_endpoint)
Expand Down
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,16 @@ impl Default for Config {
}
}

/// Returns a [`Config`] object with default values.
///
/// See the documentation of [`Config`] for more information on the default values.
///
/// This is mostly meant for use in bindings, in Rust this is synonymous with
/// [`Config::default()`].
pub fn default_config() -> Config {
Config::default()
}

/// The main interface object of LDK Node, wrapping the necessary LDK and BDK functionalities.
///
/// Needs to be initialized and instantiated through [`Builder::build`].
Expand Down

0 comments on commit b06cc07

Please sign in to comment.