Skip to content

Commit 345adc9

Browse files
committed
update namespace and update types
1 parent a8f3873 commit 345adc9

9 files changed

Lines changed: 141 additions & 875 deletions

File tree

src/backend/mod.rs

Lines changed: 0 additions & 172 deletions
This file was deleted.

src/client.rs

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,87 @@
1-
use bdk_bitcoind_rpc::{Emitter, bitcoincore_rpc::RpcApi};
1+
use crate::error::BDKCliError as Error;
2+
#[cfg(feature = "esplora")]
23
use bdk_esplora::EsploraAsyncExt;
34
use bdk_wallet::{
45
bitcoin::{Transaction, Txid},
56
chain::CanonicalizationParams,
67
};
7-
// #[cfg(any(
8-
// feature = "electrum",
9-
// feature = "esplora",
10-
// feature = "rpc",
11-
// feature = "cbf"
12-
// ))]
8+
#[cfg(any(
9+
feature = "electrum",
10+
feature = "esplora",
11+
feature = "rpc",
12+
feature = "cbf"
13+
))]
1314
use {
1415
crate::commands::{ClientType, WalletOpts},
15-
crate::error::BDKCliError as Error,
16+
1617
bdk_wallet::Wallet,
1718
std::path::PathBuf,
1819
};
20+
#[cfg(feature = "rpc")]
21+
use bdk_bitcoind_rpc::{Emitter, bitcoincore_rpc::RpcApi};
1922

20-
// #[cfg(feature = "cbf")]
23+
24+
#[cfg(feature = "cbf")]
2125
use {
2226
crate::utils::trace_logger,
2327
bdk_kyoto::{BuilderExt, LightClient},
2428
};
2529

26-
// #[cfg(any(
27-
// feature = "electrum",
28-
// feature = "esplora",
29-
// feature = "rpc",
30-
// feature = "cbf"
31-
// ))]
30+
#[cfg(any(
31+
feature = "electrum",
32+
feature = "esplora",
33+
feature = "rpc",
34+
feature = "cbf"
35+
))]
3236
pub(crate) enum BlockchainClient {
33-
// #[cfg(feature = "electrum")]
37+
#[cfg(feature = "electrum")]
3438
Electrum {
3539
client: Box<bdk_electrum::BdkElectrumClient<bdk_electrum::electrum_client::Client>>,
3640
batch_size: usize,
3741
},
38-
// #[cfg(feature = "esplora")]
42+
#[cfg(feature = "esplora")]
3943
Esplora {
4044
client: Box<bdk_esplora::esplora_client::AsyncClient>,
4145
parallel_requests: usize,
4246
},
43-
// #[cfg(feature = "rpc")]
47+
#[cfg(feature = "rpc")]
4448
RpcClient {
4549
client: Box<bdk_bitcoind_rpc::bitcoincore_rpc::Client>,
4650
},
4751

48-
// #[cfg(feature = "cbf")]
52+
#[cfg(feature = "cbf")]
4953
KyotoClient {
5054
client: Box<KyotoClientHandle>,
5155
},
5256
}
5357

58+
#[cfg(any(
59+
feature = "electrum",
60+
feature = "esplora",
61+
feature = "rpc",
62+
feature = "cbf"
63+
))]
5464
impl BlockchainClient {
5565
pub async fn broadcast(&self, tx: Transaction) -> Result<Txid, Error> {
5666
match self {
57-
// #[cfg(feature = "electrum")]
67+
#[cfg(feature = "electrum")]
5868
Self::Electrum { client, .. } => client
5969
.transaction_broadcast(&tx)
6070
.map_err(|e| Error::Generic(e.to_string())),
6171

62-
// #[cfg(feature = "esplora")]
72+
#[cfg(feature = "esplora")]
6373
Self::Esplora { client, .. } => client
6474
.broadcast(&tx)
6575
.await
6676
.map(|()| tx.compute_txid())
6777
.map_err(|e| Error::Generic(e.to_string())),
6878

69-
// #[cfg(feature = "rpc")]
79+
#[cfg(feature = "rpc")]
7080
Self::RpcClient { client } => client
7181
.send_raw_transaction(&tx)
7282
.map_err(|e| Error::Generic(e.to_string())),
7383

74-
// #[cfg(feature = "cbf")]
84+
#[cfg(feature = "cbf")]
7585
Self::KyotoClient { client } => {
7686
// ... (Kyoto broadcast logic from your online.rs) ...
7787
Ok(tx.compute_txid())
@@ -166,28 +176,28 @@ impl BlockchainClient {
166176

167177
/// Handle for the Kyoto client after the node has been started.
168178
/// Contains only the components needed for sync and broadcast operations.
169-
// #[cfg(feature = "cbf")]
179+
#[cfg(feature = "cbf")]
170180
pub struct KyotoClientHandle {
171181
pub requester: bdk_kyoto::Requester,
172182
pub update_subscriber: tokio::sync::Mutex<bdk_kyoto::UpdateSubscriber>,
173183
}
174184

175-
// #[cfg(any(
176-
// feature = "electrum",
177-
// feature = "esplora",
178-
// feature = "rpc",
179-
// feature = "cbf",
180-
// ))]
185+
#[cfg(any(
186+
feature = "electrum",
187+
feature = "esplora",
188+
feature = "rpc",
189+
feature = "cbf",
190+
))]
181191
/// Create a new blockchain from the wallet configuration options.
182192
pub(crate) fn new_blockchain_client(
183193
wallet_opts: &WalletOpts,
184194
_wallet: &Wallet,
185195
_datadir: PathBuf,
186196
) -> Result<BlockchainClient, Error> {
187-
// #[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))]
197+
#[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))]
188198
let url = &wallet_opts.url;
189199
let client = match wallet_opts.client_type {
190-
// #[cfg(feature = "electrum")]
200+
#[cfg(feature = "electrum")]
191201
ClientType::Electrum => {
192202
let client = bdk_electrum::electrum_client::Client::new(url)
193203
.map(bdk_electrum::BdkElectrumClient::new)?;
@@ -196,7 +206,7 @@ pub(crate) fn new_blockchain_client(
196206
batch_size: wallet_opts.batch_size,
197207
}
198208
}
199-
// #[cfg(feature = "esplora")]
209+
#[cfg(feature = "esplora")]
200210
ClientType::Esplora => {
201211
let client = bdk_esplora::esplora_client::Builder::new(url).build_async()?;
202212
BlockchainClient::Esplora {
@@ -205,7 +215,7 @@ pub(crate) fn new_blockchain_client(
205215
}
206216
}
207217

208-
// #[cfg(feature = "rpc")]
218+
#[cfg(feature = "rpc")]
209219
ClientType::Rpc => {
210220
let auth = match &wallet_opts.cookie {
211221
Some(cookie) => bdk_bitcoind_rpc::bitcoincore_rpc::Auth::CookieFile(cookie.into()),
@@ -221,7 +231,7 @@ pub(crate) fn new_blockchain_client(
221231
}
222232
}
223233

224-
// #[cfg(feature = "cbf")]
234+
#[cfg(feature = "cbf")]
225235
ClientType::Cbf => {
226236
let scan_type = bdk_kyoto::ScanType::Sync;
227237
let builder = bdk_kyoto::builder::Builder::new(_wallet.network());
@@ -259,7 +269,7 @@ pub(crate) fn new_blockchain_client(
259269
}
260270

261271
// Handle Kyoto Client sync
262-
// #[cfg(feature = "cbf")]
272+
#[cfg(feature = "cbf")]
263273
pub async fn sync_kyoto_client(
264274
wallet: &mut Wallet,
265275
handle: &KyotoClientHandle,

0 commit comments

Comments
 (0)