Skip to content

Commit 1c076bd

Browse files
committed
Add ChainSource enum
.. which will allow us to switch between different chain sources.
1 parent 5f1379d commit 1c076bd

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

src/builder.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
66
// accordance with one or both of these licenses.
77

8-
use crate::config::{
9-
default_user_config, Config, DEFAULT_ESPLORA_CLIENT_TIMEOUT_SECS, DEFAULT_ESPLORA_SERVER_URL,
10-
WALLET_KEYS_SEED_LEN,
11-
};
8+
use crate::chain::{DEFAULT_ESPLORA_CLIENT_TIMEOUT_SECS, DEFAULT_ESPLORA_SERVER_URL};
9+
use crate::config::{default_user_config, Config, WALLET_KEYS_SEED_LEN};
10+
1211
use crate::connection::ConnectionManager;
1312
use crate::event::EventQueue;
1413
use crate::fee_estimator::OnchainFeeEstimator;

src/chain/mod.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// This file is Copyright its original authors, visible in version control history.
2+
//
3+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5+
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
6+
// accordance with one or both of these licenses.
7+
8+
use crate::logger::FilesystemLogger;
9+
10+
use esplora_client::AsyncClient as EsploraAsyncClient;
11+
12+
use std::sync::Arc;
13+
14+
// The default Esplora server we're using.
15+
pub(crate) const DEFAULT_ESPLORA_SERVER_URL: &str = "https://blockstream.info/api";
16+
17+
// The default Esplora client timeout we're using.
18+
pub(crate) const DEFAULT_ESPLORA_CLIENT_TIMEOUT_SECS: u64 = 10;
19+
20+
pub(crate) enum ChainSource {
21+
Esplora { esplora_client: EsploraAsyncClient, logger: Arc<FilesystemLogger> },
22+
}
23+
24+
impl ChainSource {
25+
pub(crate) fn new_esplora(server_url: String, logger: Arc<FilesystemLogger>) -> Self {
26+
let mut client_builder = esplora_client::Builder::new(&server_url.clone());
27+
client_builder = client_builder.timeout(DEFAULT_ESPLORA_CLIENT_TIMEOUT_SECS);
28+
let esplora_client = client_builder.build_async().unwrap();
29+
Self::Esplora { esplora_client, logger }
30+
}
31+
}

src/config.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ pub(crate) const BDK_CLIENT_STOP_GAP: usize = 20;
3434
// The number of concurrent requests made against the API provider.
3535
pub(crate) const BDK_CLIENT_CONCURRENCY: usize = 4;
3636

37-
// The default Esplora server we're using.
38-
pub(crate) const DEFAULT_ESPLORA_SERVER_URL: &str = "https://blockstream.info/api";
39-
40-
// The default Esplora client timeout we're using.
41-
pub(crate) const DEFAULT_ESPLORA_CLIENT_TIMEOUT_SECS: u64 = 10;
42-
4337
// The timeout after which we abandon retrying failed payments.
4438
pub(crate) const LDK_PAYMENT_RETRY_TIMEOUT: Duration = Duration::from_secs(10);
4539

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474

7575
mod balance;
7676
mod builder;
77+
mod chain;
7778
mod config;
7879
mod connection;
7980
mod error;

0 commit comments

Comments
 (0)