]> Untitled Git - bdk-cli/commitdiff
Add build.rs to abort if more than one blockchain client feature
authorSteve Myers <steve@notmandatory.org>
Fri, 6 Aug 2021 20:20:18 +0000 (13:20 -0700)
committerSteve Myers <steve@notmandatory.org>
Thu, 12 Aug 2021 14:10:42 +0000 (16:10 +0200)
build.rs [new file with mode: 0644]
src/bdk_cli.rs
src/lib.rs

diff --git a/build.rs b/build.rs
new file mode 100644 (file)
index 0000000..4287730
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,17 @@
+use std::env;
+
+fn main() {
+    let electrum = env::var_os("CARGO_FEATURE_ELECTRUM").map(|_| "electrum".to_string());
+    let esplora = env::var_os("CARGO_FEATURE_ESPLORA").map(|_| "esplora".to_string());
+    let compact_filters = env::var_os("CARGO_FEATURE_COMPACT_FILTERS").map(|_| "compact_filters".to_string());
+
+    let blockchain_features : Vec<String> = vec!(electrum, esplora, compact_filters)
+        .iter()
+        .map(|f| f.to_owned())
+        .flatten()
+        .collect();
+    
+    if blockchain_features.len() > 1 {
+        panic!("At most one blockchain client feature can be enabled but these features were enabled: {:?}", blockchain_features)
+    }
+}
index be19a7fa366698dfa796a4067b3ea4b2abb5f684..9a5723288097d64a233fd106001024bfd7721cc0 100644 (file)
@@ -116,12 +116,6 @@ fn new_online_wallet<D>(
 where
     D: BatchDatabase,
 {
-    #[cfg(all(
-        feature = "electrum",
-        any(feature = "esplora", feature = "compact_filters")
-    ))]
-    compile_error!("Only one blockchain client feature can be enabled at a time.");
-
     #[cfg(feature = "electrum")]
     let config = AnyBlockchainConfig::Electrum(ElectrumBlockchainConfig {
         url: wallet_opts.electrum_opts.electrum.clone(),
@@ -130,24 +124,12 @@ where
         timeout: wallet_opts.electrum_opts.timeout,
     });
 
-    #[cfg(all(
-        feature = "esplora",
-        any(feature = "electrum", feature = "compact_filters")
-    ))]
-    compile_error!("Only one blockchain client feature can be enabled at a time.");
-
     #[cfg(feature = "esplora")]
     let config = AnyBlockchainConfig::Esplora(EsploraBlockchainConfig {
         base_url: wallet_opts.esplora_opts.server.clone(),
         concurrency: Some(wallet_opts.esplora_opts.concurrency),
     });
 
-    #[cfg(all(
-        feature = "compact_filters",
-        any(feature = "electrum", feature = "esplora")
-    ))]
-    compile_error!("Only one blockchain client feature can be enabled at a time.");
-
     #[cfg(feature = "compact_filters")]
     let config = {
         let mut peers = vec![];
index ea68a7d5ea420fdbfabaacfd68534b8f220168df..99091c229ec7751bedf4cbb294fea84fefa2c162 100644 (file)
@@ -107,13 +107,16 @@ pub use structopt;
 use structopt::StructOpt;
 
 use crate::OfflineWalletSubCommand::*;
+#[cfg(any(feature = "electrum", feature = "esplora", feature = "compact_filters"))]
 use crate::OnlineWalletSubCommand::*;
 use bdk::bitcoin::consensus::encode::{deserialize, serialize, serialize_hex};
+#[cfg(any(feature = "electrum", feature = "esplora", feature = "compact_filters"))]
 use bdk::bitcoin::hashes::hex::FromHex;
 use bdk::bitcoin::secp256k1::Secp256k1;
 use bdk::bitcoin::util::bip32::{DerivationPath, ExtendedPrivKey, KeySource};
 use bdk::bitcoin::util::psbt::PartiallySignedTransaction;
 use bdk::bitcoin::{Address, Network, OutPoint, Script, Txid};
+#[cfg(any(feature = "electrum", feature = "esplora", feature = "compact_filters"))]
 use bdk::blockchain::{log_progress, Blockchain};
 use bdk::database::BatchDatabase;
 use bdk::descriptor::Segwitv0;
@@ -635,6 +638,7 @@ blockchain client and network connection.
 )]
 #[derive(Debug, StructOpt, Clone, PartialEq)]
 #[structopt(rename_all = "snake")]
+#[cfg(any(feature = "electrum", feature = "esplora", feature = "compact_filters"))]
 pub enum OnlineWalletSubCommand {
     /// Syncs with the chosen blockchain server
     Sync {
@@ -890,6 +894,7 @@ where
 ///
 /// Online wallet sub-commands are described in [`OnlineWalletSubCommand`]. See [`crate`] for
 /// example usage.
+#[cfg(any(feature = "electrum", feature = "esplora", feature = "compact_filters"))]
 #[maybe_async]
 pub fn handle_online_wallet_subcommand<C, D>(
     wallet: &Wallet<C, D>,