Skip to content

Commit c06ee2f

Browse files
committed
make every version imply the one before it
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.
1 parent 8fbedb4 commit c06ee2f

4 files changed

Lines changed: 29 additions & 62 deletions

File tree

Cargo.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ zip = { version = "0.5", optional = true }
3131
# download is not supposed to be used directly only through selecting one of the version feature
3232
"download" = ["bitcoin_hashes", "flate2", "tar", "minreq", "zip"]
3333

34-
"23_0" = ["download"]
35-
"22_0" = ["download"]
36-
"0_21_1" = ["download"]
37-
"0_21_0" = ["download"]
38-
"0_20_1" = ["download"]
39-
"0_20_0" = ["download"]
40-
"0_19_1" = ["download"]
41-
"0_19_0_1" = ["download"]
42-
"0_18_1" = ["download"]
43-
"0_18_0" = ["download"]
34+
"23_0" = ["download", "22_0"]
35+
"22_0" = ["download", "0_21_1"]
36+
"0_21_1" = ["download", "0_21_0"]
37+
"0_21_0" = ["download", "0_20_1"]
38+
"0_20_1" = ["download", "0_20_0"]
39+
"0_20_0" = ["download", "0_19_1"]
40+
"0_19_1" = ["download", "0_19_0_1"]
41+
"0_19_0_1" = ["download", "0_18_1"]
42+
"0_18_1" = ["download", "0_18_0"]
43+
"0_18_0" = ["download", "0_17_1"]
4444
"0_17_1" = ["download"]
4545

4646
"doc" = [] # used only for documentation building

build.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,7 @@ mod download {
2727
any(target_arch = "x86_64", target_arch = "aarch64"),
2828
))]
2929
fn download_filename() -> String {
30-
if cfg!(any(
31-
feature = "22_0",
32-
feature = "0_21_1",
33-
feature = "0_21_0",
34-
feature = "0_20_1",
35-
feature = "0_20_0",
36-
feature = "0_19_1",
37-
feature = "0_19_0_1",
38-
feature = "0_18_1",
39-
feature = "0_18_0",
40-
feature = "0_17_1",
41-
)) {
30+
if cfg!(not(feature = "23_0")) {
4231
format!("bitcoin-{}-osx64.tar.gz", &VERSION)
4332
} else {
4433
format!("bitcoin-{}-x86_64-apple-darwin.tar.gz", &VERSION)
@@ -62,17 +51,7 @@ mod download {
6251

6352
fn get_expected_sha256(filename: &str) -> sha256::Hash {
6453
let sha256sums_filename = format!("sha256/bitcoin-core-{}-SHA256SUMS", &VERSION);
65-
#[cfg(any(
66-
feature = "0_21_1",
67-
feature = "0_21_0",
68-
feature = "0_20_1",
69-
feature = "0_20_0",
70-
feature = "0_19_1",
71-
feature = "0_19_0_1",
72-
feature = "0_18_1",
73-
feature = "0_18_0",
74-
feature = "0_17_1",
75-
))]
54+
#[cfg(not(feature = "22_0"))]
7655
let sha256sums_filename = format!("{}.asc", sha256sums_filename);
7756
let file = File::open(&sha256sums_filename).unwrap();
7857
for line in BufReader::new(file).lines().flatten() {

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ impl BitcoinD {
370370
format!("http://{}", self.params.rpc_socket)
371371
}
372372

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

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

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

642-
#[cfg(not(any(feature = "0_17_1", feature = "0_18_0", feature = "0_18_1")))]
642+
#[cfg(any(feature = "0_19_0_1", not(feature = "download")))]
643643
#[test]
644644
fn test_multi_wallet() {
645645
use bitcoincore_rpc::bitcoin::Amount;

src/versions.rs

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,35 @@
1-
#[cfg(not(any(
2-
feature = "23_0",
3-
feature = "22_0",
4-
feature = "0_21_1",
5-
feature = "0_21_0",
6-
feature = "0_20_1",
7-
feature = "0_20_0",
8-
feature = "0_19_1",
9-
feature = "0_19_0_1",
10-
feature = "0_18_1",
11-
feature = "0_18_0",
12-
feature = "0_17_1",
13-
)))]
14-
pub const VERSION: &str = "N/A";
15-
161
#[cfg(feature = "23_0")]
172
pub const VERSION: &str = "23.0";
183

19-
#[cfg(feature = "22_0")]
4+
#[cfg(all(feature = "22_0", not(feature = "23_0")))]
205
pub const VERSION: &str = "22.0";
216

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

25-
#[cfg(feature = "0_21_0")]
10+
#[cfg(all(feature = "0_21_0", not(feature = "0_21_1")))]
2611
pub const VERSION: &str = "0.21.0";
2712

28-
#[cfg(feature = "0_20_1")]
13+
#[cfg(all(feature = "0_20_1", not(feature = "0_21_0")))]
2914
pub const VERSION: &str = "0.20.1";
3015

31-
#[cfg(feature = "0_20_0")]
16+
#[cfg(all(feature = "0_20_0", not(feature = "0_20_1")))]
3217
pub const VERSION: &str = "0.20.0";
3318

34-
#[cfg(feature = "0_19_1")]
19+
#[cfg(all(feature = "0_19_1", not(feature = "0_20_0")))]
3520
pub const VERSION: &str = "0.19.1";
3621

37-
#[cfg(feature = "0_19_0_1")]
22+
#[cfg(all(feature = "0_19_0_1", not(feature = "0_19_1")))]
3823
pub const VERSION: &str = "0.19.0.1";
3924

40-
#[cfg(feature = "0_18_1")]
25+
#[cfg(all(feature = "0_18_1", not(feature = "0_19_0_1")))]
4126
pub const VERSION: &str = "0.18.1";
4227

43-
#[cfg(feature = "0_18_0")]
28+
#[cfg(all(feature = "0_18_0", not(feature = "0_18_1")))]
4429
pub const VERSION: &str = "0.18.0";
4530

46-
#[cfg(feature = "0_17_1")]
31+
#[cfg(all(feature = "0_17_1", not(feature = "0_18_0")))]
4732
pub const VERSION: &str = "0.17.1";
33+
34+
#[cfg(not(feature = "0_17_1"))]
35+
pub const VERSION: &str = "N/A";

0 commit comments

Comments
 (0)