Skip to content

Commit

Permalink
make every version imply the one before it
Browse files Browse the repository at this point in the history
This allows the library to be compiled with any combination of versions
of Bitcoin Core -- it will just use the highest one.

This won't guarantee compatibility because Bitcoin Core sometimes makes
backward-compatibility breaking changes ... but it is much better than
the current situation where if you specify multiple feature flags, the
library won't compile at all.
  • Loading branch information
apoelstra committed Apr 4, 2023
1 parent 8fbedb4 commit 71e8bb8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 39 deletions.
20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ zip = { version = "0.5", optional = true }
# download is not supposed to be used directly only through selecting one of the version feature
"download" = ["bitcoin_hashes", "flate2", "tar", "minreq", "zip"]

"23_0" = ["download"]
"22_0" = ["download"]
"0_21_1" = ["download"]
"0_21_0" = ["download"]
"0_20_1" = ["download"]
"0_20_0" = ["download"]
"0_19_1" = ["download"]
"0_19_0_1" = ["download"]
"0_18_1" = ["download"]
"0_18_0" = ["download"]
"23_0" = ["download", "22_0"]
"22_0" = ["download", "0_21_1"]
"0_21_1" = ["download", "0_21_0"]
"0_21_0" = ["download", "0_20_1"]
"0_20_1" = ["download", "0_20_0"]
"0_20_0" = ["download", "0_19_1"]
"0_19_1" = ["download", "0_19_0_1"]
"0_19_0_1" = ["download", "0_18_1"]
"0_18_1" = ["download", "0_18_0"]
"0_18_0" = ["download", "0_17_1"]
"0_17_1" = ["download"]

"doc" = [] # used only for documentation building
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ impl BitcoinD {
format!("http://{}", self.params.rpc_socket)
}

#[cfg(not(any(feature = "0_17_1", feature = "0_18_0", feature = "0_18_1")))]
#[cfg(any(feature = "0_19_0_1", not(feature = "download")))]
/// Returns the rpc URL including the schema and the given `wallet_name`
/// eg. http://127.0.0.1:44842/wallet/my_wallet
pub fn rpc_url_with_wallet<T: AsRef<str>>(&self, wallet_name: T) -> String {
Expand All @@ -397,7 +397,7 @@ impl BitcoinD {
Ok(self.process.wait()?)
}

#[cfg(not(any(feature = "0_17_1", feature = "0_18_0", feature = "0_18_1")))]
#[cfg(any(feature = "0_19_0_1", not(feature = "download")))]
/// Create a new wallet in the running node, and return an RPC client connected to the just
/// created wallet
pub fn create_wallet<T: AsRef<str>>(&self, wallet: T) -> anyhow::Result<Client> {
Expand Down Expand Up @@ -545,7 +545,7 @@ mod test {
}

#[test]
#[cfg(any(feature = "0_21_0", feature = "0_21_1"))]
#[cfg(feature = "0_21_0")]
fn test_getindexinfo() {
let exe = init();
let mut conf = Conf::default();
Expand Down Expand Up @@ -639,7 +639,7 @@ mod test {
assert_eq!(node3_peers, 1, "listen false but more than 1 peer");
}

#[cfg(not(any(feature = "0_17_1", feature = "0_18_0", feature = "0_18_1")))]
#[cfg(any(feature = "0_19_0_1", not(feature = "download")))]
#[test]
fn test_multi_wallet() {
use bitcoincore_rpc::bitcoin::Amount;
Expand Down
39 changes: 14 additions & 25 deletions src/versions.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,36 @@
#[cfg(not(any(
feature = "23_0",
feature = "22_0",
feature = "0_21_1",
feature = "0_21_0",
feature = "0_20_1",
feature = "0_20_0",
feature = "0_19_1",
feature = "0_19_0_1",
feature = "0_18_1",
feature = "0_18_0",
feature = "0_17_1",
)))]
pub const VERSION: &str = "N/A";

#[cfg(feature = "23_0")]
pub const VERSION: &str = "23.0";

#[cfg(feature = "22_0")]
#[cfg(all(feature = "22_0", not(feature = "23_0")))]
pub const VERSION: &str = "22.0";

#[cfg(feature = "0_21_1")]
#[cfg(all(feature = "0_21_1", not(feature = "22_0")))]
pub const VERSION: &str = "0.21.1";

#[cfg(feature = "0_21_0")]
#[cfg(all(feature = "0_21_0", not(feature = "0_21_1")))]
pub const VERSION: &str = "0.21.0";

#[cfg(feature = "0_20_1")]
#[cfg(all(feature = "0_20_1", not(feature = "0_20_1")))]
pub const VERSION: &str = "0.20.1";

#[cfg(feature = "0_20_0")]
#[cfg(all(feature = "0_20_0", not(feature = "0_20_1")))]
pub const VERSION: &str = "0.20.0";

#[cfg(feature = "0_19_1")]
#[cfg(all(feature = "0_19_1", not(feature = "0_20_0")))]
pub const VERSION: &str = "0.19.1";

#[cfg(feature = "0_19_0_1")]
#[cfg(all(feature = "0_19_0_1", not(feature = "0_19_1")))]
pub const VERSION: &str = "0.19.0.1";

#[cfg(feature = "0_18_1")]
#[cfg(all(feature = "0_18_1", not(feature = "0_19_0_1")))]
pub const VERSION: &str = "0.18.1";

#[cfg(feature = "0_18_0")]
#[cfg(all(feature = "0_18_0", not(feature = "0_18_1")))]
pub const VERSION: &str = "0.18.0";

#[cfg(feature = "0_17_1")]
#[cfg(all(feature = "0_17_1", not(feature = "0_18_0")))]
pub const VERSION: &str = "0.17.1";

#[cfg(not(feature = "0_17_1"))]
pub const VERSION: &str = "N/A";

0 comments on commit 71e8bb8

Please sign in to comment.