-
Notifications
You must be signed in to change notification settings - Fork 103
Break builder pattern to expose all setters via bindings #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Break builder pattern to expose all setters via bindings #88
Conversation
96a70ae
to
e0cc6f8
Compare
acfcd7c
to
0f1e7ed
Compare
Rebased on main. |
0dbd449
to
070314f
Compare
Rebased on main after #70 has landed. We now also expose the RGS setter methods via bindings. Moreover, since we already have Additionally, we document the set defaults and switch our default config to |
070314f
to
3b3a775
Compare
3b3a775
to
a9da44a
Compare
a9da44a
to
49baa90
Compare
Rebased after #85 landed. |
cdefbe6
to
b5db6d0
Compare
b5db6d0
to
7a56598
Compare
Rebased on main after #101 landed. |
7a56598
to
bb02755
Compare
bindings/kotlin/ldk-node-jvm/lib/src/test/kotlin/org/lightningdevkit/ldknode/LibraryTest.kt
Show resolved
Hide resolved
bb02755
to
b2afd61
Compare
I now included another commit that moves all UniFFI-specific types and trait impls to a dedicated module, which is now feature-gated behind the
However, I'll look into actually lowering the MSRV separately, as it may require downgrading UniFFI, and IIRC there was good reason why I had upgraded to 0.23.0 in the first place... |
Unfortunately there is no good way of exposing the builder pattern via Uniffi bindings currenlty. We therefore resort to internal mutability and using setters on the `Builder` object.
b2afd61
to
f6c4117
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good minus a couple easy comments.
f6c4117
to
1b4b47a
Compare
After we already have `EntropySourceConfig` and `GossipSourceConfig`, we here move the esplora server URL to a corresponding `enum ChainDataSourceConfig`, which will us to add further variants (e.g., `Electrum`) in the future without breaking the API. Additionally, we document the set default values.
As we're getting ready for release
While we need quite a bit of dependencies and custom impls for UniFFI support, there is no reason to pull them in for Rust-only builds. Here we move the UniFFI-specific types and trait impls to a dedicated module and hide it behind a new `uniffi` feature.
1b4b47a
to
de94a54
Compare
Updated the commits to address feedback and included: diff --git a/src/lib.rs b/src/lib.rs
index b9b75ca..3a0526f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -375,22 +375,18 @@ impl Builder {
// Initialize the on-chain wallet and chain access
- let seed_bytes = if let Some(entropy_source_config) =
- &*self.entropy_source_config.read().unwrap()
- {
- // Use the configured entropy source, if the user set one.
- match entropy_source_config {
- EntropySourceConfig::SeedBytes(bytes) => bytes.clone(),
- EntropySourceConfig::SeedFile(seed_path) => {
- io::utils::read_or_generate_seed_file(seed_path)
- }
- EntropySourceConfig::Bip39Mnemonic { mnemonic, passphrase } => match passphrase {
- Some(passphrase) => mnemonic.to_seed(passphrase),
- None => mnemonic.to_seed(""),
- },
+ let seed_bytes = match &*self.entropy_source_config.read().unwrap() {
+ Some(EntropySourceConfig::SeedBytes(bytes)) => bytes.clone(),
+ Some(EntropySourceConfig::SeedFile(seed_path)) => {
+ io::utils::read_or_generate_seed_file(seed_path)
+ }
+ Some(EntropySourceConfig::Bip39Mnemonic { mnemonic, passphrase }) => match passphrase {
+ Some(passphrase) => mnemonic.to_seed(passphrase),
+ None => mnemonic.to_seed(""),
+ },
+ None => {
+ // Default to read or generate from the default location generate a seed file.
+ let seed_path = format!("{}/keys_seed", config.storage_dir_path);
+ io::utils::read_or_generate_seed_file(&seed_path)
}
- } else {
- // Default to read or generate from the default location generate a seed file.
- let seed_path = format!("{}/keys_seed", config.storage_dir_path);
- io::utils::read_or_generate_seed_file(&seed_path)
};
@@ -417,27 +413,22 @@ impl Builder {
.expect("Failed to set up on-chain wallet");
- let (blockchain, tx_sync) = if let Some(chain_data_source_config) =
- &*self.chain_data_source_config.read().unwrap()
- {
- match chain_data_source_config {
- ChainDataSourceConfig::Esplora(server_url) => {
- let tx_sync =
- Arc::new(EsploraSyncClient::new(server_url.clone(), Arc::clone(&logger)));
- let blockchain = EsploraBlockchain::from_client(
- tx_sync.client().clone(),
- BDK_CLIENT_STOP_GAP,
- )
- .with_concurrency(BDK_CLIENT_CONCURRENCY);
- (blockchain, tx_sync)
- }
+ let (blockchain, tx_sync) = match &*self.chain_data_source_config.read().unwrap() {
+ Some(ChainDataSourceConfig::Esplora(server_url)) => {
+ let tx_sync =
+ Arc::new(EsploraSyncClient::new(server_url.clone(), Arc::clone(&logger)));
+ let blockchain =
+ EsploraBlockchain::from_client(tx_sync.client().clone(), BDK_CLIENT_STOP_GAP)
+ .with_concurrency(BDK_CLIENT_CONCURRENCY);
+ (blockchain, tx_sync)
+ }
+ None => {
+ // Default to Esplora client.
+ let server_url = DEFAULT_ESPLORA_SERVER_URL.to_string();
+ let tx_sync = Arc::new(EsploraSyncClient::new(server_url, Arc::clone(&logger)));
+ let blockchain =
+ EsploraBlockchain::from_client(tx_sync.client().clone(), BDK_CLIENT_STOP_GAP)
+ .with_concurrency(BDK_CLIENT_CONCURRENCY);
+ (blockchain, tx_sync)
}
- } else {
- // Default to Esplora client with blockstream endpoint.
- let server_url = DEFAULT_ESPLORA_SERVER_URL.to_string();
- let tx_sync = Arc::new(EsploraSyncClient::new(server_url, Arc::clone(&logger)));
- let blockchain =
- EsploraBlockchain::from_client(tx_sync.client().clone(), BDK_CLIENT_STOP_GAP)
- .with_concurrency(BDK_CLIENT_CONCURRENCY);
- (blockchain, tx_sync)
};
|
Closes #65
Unfortunately there is no good way of exposing the builder pattern via Uniffi bindings currently. We therefore resort to internal mutability and using setters on the
Builder
object.