Skip to content

Commit 5720e38

Browse files
committed
Merge #770: Upgrade to rust-bitcoin 0.29
c7a43d9 Remove unused code (Alekos Filini) 1ffd59d Upgrade to rust-bitcoin 0.29 (Alekos Filini) ae4f4e5 Upgrade `rand` to `0.8` (Alekos Filini) 9854fd3 Remove deprecated address validators (Alekos Filini) Pull request description: ### Description Upgrade BDK to rust-bitcoin 0.29 Missing pieces: - [x] rust-miniscript `update_output_with_descriptor` - rust-bitcoin/rust-miniscript#465 - [x] rust-miniscript 8.0.0 release - rust-bitcoin/rust-miniscript#462 - [x] Upgrade rust-hwi to bitcoin 0.29 bitcoindevkit/rust-hwi#50 - [x] Upgrade esplora-client to bitcoin 0.29 bitcoindevkit/rust-esplora-client#20 - [x] Upgrade rand to 0.8 like secp256k1 did ### Notes to the reviewers The commits still need to be reordered and cleaned up ### Changelog notice - Upgrade rust-bitcoin to 0.29 - Remove deprecated "address validators" ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing ACKs for top commit: notmandatory: ACK c7a43d9 Tree-SHA512: 718a1baf3613b31ec1de39fe63467ebee38617963a4ce0670a617e20fe4f46a57c5786933cdde6cfad9fc76ce0af08843f58844fb4a89f5948cb42c697f802ef
2 parents ea47d7a + c7a43d9 commit 5720e38

33 files changed

+586
-1179
lines changed

.github/workflows/cont_integration.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ jobs:
154154
- name: Update toolchain
155155
run: rustup update
156156
- name: Check
157-
run: cargo check --target wasm32-unknown-unknown --features use-esplora-async --no-default-features
157+
run: cargo check --target wasm32-unknown-unknown --features use-esplora-async,dev-getrandom-wasm --no-default-features
158158

159159
fmt:
160160
name: Rust fmt

Cargo.toml

+16-11
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,39 @@ license = "MIT OR Apache-2.0"
1414
[dependencies]
1515
bdk-macros = "^0.6"
1616
log = "^0.4"
17-
miniscript = { version = "7.0", features = ["use-serde"] }
18-
bitcoin = { version = "0.28.1", features = ["use-serde", "base64", "rand"] }
17+
miniscript = { version = "8.0", features = ["serde"] }
18+
bitcoin = { version = "0.29.1", features = ["serde", "base64", "rand"] }
1919
serde = { version = "^1.0", features = ["derive"] }
2020
serde_json = { version = "^1.0" }
21-
rand = "^0.7"
21+
rand = "^0.8"
2222

2323
# Optional dependencies
2424
sled = { version = "0.34", optional = true }
25-
electrum-client = { version = "0.11", optional = true }
26-
esplora-client = { version = "0.1.1", default-features = false, optional = true }
25+
electrum-client = { version = "0.12", optional = true }
26+
esplora-client = { version = "0.2", default-features = false, optional = true }
2727
rusqlite = { version = "0.27.0", optional = true }
2828
ahash = { version = "0.7.6", optional = true }
2929
futures = { version = "0.3", optional = true }
3030
async-trait = { version = "0.1", optional = true }
3131
rocksdb = { version = "0.14", default-features = false, features = ["snappy"], optional = true }
3232
cc = { version = ">=1.0.64", optional = true }
3333
socks = { version = "0.3", optional = true }
34-
hwi = { version = "0.2.3", optional = true }
34+
hwi = { version = "0.3.0", optional = true }
3535

3636
bip39 = { version = "1.0.1", optional = true }
3737
bitcoinconsensus = { version = "0.19.0-3", optional = true }
3838

3939
# Needed by bdk_blockchain_tests macro and the `rpc` feature
40-
bitcoincore-rpc = { version = "0.15", optional = true }
40+
bitcoincore-rpc = { version = "0.16", optional = true }
4141

4242
# Platform-specific dependencies
4343
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
4444
tokio = { version = "1", features = ["rt"] }
4545

4646
[target.'cfg(target_arch = "wasm32")'.dependencies]
47+
getrandom = "0.2"
4748
async-trait = "0.1"
4849
js-sys = "0.3"
49-
rand = { version = "^0.7", features = ["wasm-bindgen"] }
5050

5151
[features]
5252
minimal = []
@@ -98,13 +98,18 @@ test-esplora = ["electrsd/legacy", "electrsd/esplora_a33e97e1", "electrsd/bitcoi
9898
test-md-docs = ["electrum"]
9999
test-hardware-signer = ["hardware-signer"]
100100

101+
# This feature is used to run `cargo check` in our CI targeting wasm. It's not recommended
102+
# for libraries to explicitly include the "getrandom/js" feature, so we only do it when
103+
# necessary for running our CI. See: https://docs.rs/getrandom/0.2.8/getrandom/#webassembly-support
104+
dev-getrandom-wasm = ["getrandom/js"]
105+
101106
[dev-dependencies]
102107
lazy_static = "1.4"
103108
env_logger = "0.7"
104-
electrsd = "0.20"
109+
electrsd = "0.21"
110+
# Move back to importing from rust-bitcoin once https://github.com/rust-bitcoin/rust-bitcoin/pull/1342 is released
111+
base64 = "^0.13"
105112

106-
[[example]]
107-
name = "address_validator"
108113
[[example]]
109114
name = "compact_filters_balance"
110115
required-features = ["compact_filters"]

README.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ use bdk::blockchain::ElectrumBlockchain;
9595
use bdk::electrum_client::Client;
9696
use bdk::wallet::AddressIndex::New;
9797
98-
use bitcoin::base64;
98+
use base64;
9999
use bitcoin::consensus::serialize;
100100
101101
fn main() -> Result<(), bdk::Error> {
@@ -132,7 +132,7 @@ fn main() -> Result<(), bdk::Error> {
132132
```rust,no_run
133133
use bdk::{Wallet, SignOptions, database::MemoryDatabase};
134134
135-
use bitcoin::base64;
135+
use base64;
136136
use bitcoin::consensus::deserialize;
137137
138138
fn main() -> Result<(), bdk::Error> {
@@ -171,6 +171,17 @@ cargo test --features test-electrum
171171
The other options are `test-esplora`, `test-rpc` or `test-rpc-legacy` which runs against an older version of Bitcoin Core.
172172
Note that `electrs` and `bitcoind` binaries are automatically downloaded (on mac and linux), to specify you already have installed binaries you must use `--no-default-features` and provide `BITCOIND_EXE` and `ELECTRS_EXE` as environment variables.
173173

174+
## Running under WASM
175+
176+
If you want to run this library under WASM you will probably have to add the following lines to you `Cargo.toml`:
177+
178+
```toml
179+
[dependencies]
180+
getrandom = { version = "0.2", features = ["js"] }
181+
```
182+
183+
This enables the `rand` crate to work in environments where JavaScript is available. See [this link](https://docs.rs/getrandom/0.2.8/getrandom/#webassembly-support) to learn more.
184+
174185
## License
175186

176187
Licensed under either of

examples/address_validator.rs

-63
This file was deleted.

examples/psbt_signer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ fn main() -> Result<(), Box<dyn Error>> {
3333
let internal_secret_xkey = DescriptorSecretKey::from_str("[e9824965/84'/1'/0']tprv8fvem7qWxY3SGCQczQpRpqTKg455wf1zgixn6MZ4ze8gRfHjov5gXBQTadNfDgqs9ERbZZ3Bi1PNYrCCusFLucT39K525MWLpeURjHwUsfX/1/*").unwrap();
3434

3535
let secp = Secp256k1::new();
36-
let external_public_xkey = external_secret_xkey.as_public(&secp).unwrap();
37-
let internal_public_xkey = internal_secret_xkey.as_public(&secp).unwrap();
36+
let external_public_xkey = external_secret_xkey.to_public(&secp).unwrap();
37+
let internal_public_xkey = internal_secret_xkey.to_public(&secp).unwrap();
3838

3939
let signing_external_descriptor = descriptor!(wpkh(external_secret_xkey)).unwrap();
4040
let signing_internal_descriptor = descriptor!(wpkh(internal_secret_xkey)).unwrap();

src/blockchain/any.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl_from!(boxed rpc::RpcBlockchain, AnyBlockchain, Rpc, #[cfg(feature = "rpc")]
194194
/// );
195195
/// # }
196196
/// ```
197-
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq)]
197+
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq)]
198198
#[serde(tag = "type", rename_all = "snake_case")]
199199
pub enum AnyBlockchainConfig {
200200
#[cfg(feature = "electrum")]

src/blockchain/compact_filters/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ impl WalletSync for CompactFiltersBlockchain {
479479
}
480480

481481
/// Data to connect to a Bitcoin P2P peer
482-
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq)]
482+
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq, Eq)]
483483
pub struct BitcoinPeerConfig {
484484
/// Peer address such as 127.0.0.1:18333
485485
pub address: String,
@@ -490,7 +490,7 @@ pub struct BitcoinPeerConfig {
490490
}
491491

492492
/// Configuration for a [`CompactFiltersBlockchain`]
493-
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq)]
493+
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq, Eq)]
494494
pub struct CompactFiltersBlockchainConfig {
495495
/// List of peers to try to connect to for asking headers and filters
496496
pub peers: Vec<BitcoinPeerConfig>,

src/blockchain/compact_filters/peer.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ impl Mempool {
7575
/// Look-up a transaction in the mempool given an [`Inventory`] request
7676
pub fn get_tx(&self, inventory: &Inventory) -> Option<Transaction> {
7777
let identifer = match inventory {
78-
Inventory::Error | Inventory::Block(_) | Inventory::WitnessBlock(_) => return None,
78+
Inventory::Error
79+
| Inventory::Block(_)
80+
| Inventory::WitnessBlock(_)
81+
| Inventory::CompactBlock(_) => return None,
7982
Inventory::Transaction(txid) => TxIdentifier::Txid(*txid),
8083
Inventory::WitnessTransaction(txid) => TxIdentifier::Txid(*txid),
8184
Inventory::WTx(wtxid) => TxIdentifier::Wtxid(*wtxid),

src/blockchain/compact_filters/store.rs

+33-27
Original file line numberDiff line numberDiff line change
@@ -103,42 +103,42 @@ where
103103
}
104104

105105
impl Encodable for BundleStatus {
106-
fn consensus_encode<W: Write>(&self, mut e: W) -> Result<usize, std::io::Error> {
106+
fn consensus_encode<W: Write + ?Sized>(&self, e: &mut W) -> Result<usize, std::io::Error> {
107107
let mut written = 0;
108108

109109
match self {
110110
BundleStatus::Init => {
111-
written += 0x00u8.consensus_encode(&mut e)?;
111+
written += 0x00u8.consensus_encode(e)?;
112112
}
113113
BundleStatus::CfHeaders { cf_headers } => {
114-
written += 0x01u8.consensus_encode(&mut e)?;
115-
written += VarInt(cf_headers.len() as u64).consensus_encode(&mut e)?;
114+
written += 0x01u8.consensus_encode(e)?;
115+
written += VarInt(cf_headers.len() as u64).consensus_encode(e)?;
116116
for header in cf_headers {
117-
written += header.consensus_encode(&mut e)?;
117+
written += header.consensus_encode(e)?;
118118
}
119119
}
120120
BundleStatus::CFilters { cf_filters } => {
121-
written += 0x02u8.consensus_encode(&mut e)?;
122-
written += VarInt(cf_filters.len() as u64).consensus_encode(&mut e)?;
121+
written += 0x02u8.consensus_encode(e)?;
122+
written += VarInt(cf_filters.len() as u64).consensus_encode(e)?;
123123
for filter in cf_filters {
124-
written += filter.consensus_encode(&mut e)?;
124+
written += filter.consensus_encode(e)?;
125125
}
126126
}
127127
BundleStatus::Processed { cf_filters } => {
128-
written += 0x03u8.consensus_encode(&mut e)?;
129-
written += VarInt(cf_filters.len() as u64).consensus_encode(&mut e)?;
128+
written += 0x03u8.consensus_encode(e)?;
129+
written += VarInt(cf_filters.len() as u64).consensus_encode(e)?;
130130
for filter in cf_filters {
131-
written += filter.consensus_encode(&mut e)?;
131+
written += filter.consensus_encode(e)?;
132132
}
133133
}
134134
BundleStatus::Pruned => {
135-
written += 0x04u8.consensus_encode(&mut e)?;
135+
written += 0x04u8.consensus_encode(e)?;
136136
}
137137
BundleStatus::Tip { cf_filters } => {
138-
written += 0x05u8.consensus_encode(&mut e)?;
139-
written += VarInt(cf_filters.len() as u64).consensus_encode(&mut e)?;
138+
written += 0x05u8.consensus_encode(e)?;
139+
written += VarInt(cf_filters.len() as u64).consensus_encode(e)?;
140140
for filter in cf_filters {
141-
written += filter.consensus_encode(&mut e)?;
141+
written += filter.consensus_encode(e)?;
142142
}
143143
}
144144
}
@@ -148,51 +148,53 @@ impl Encodable for BundleStatus {
148148
}
149149

150150
impl Decodable for BundleStatus {
151-
fn consensus_decode<D: Read>(mut d: D) -> Result<Self, bitcoin::consensus::encode::Error> {
152-
let byte_type = u8::consensus_decode(&mut d)?;
151+
fn consensus_decode<D: Read + ?Sized>(
152+
d: &mut D,
153+
) -> Result<Self, bitcoin::consensus::encode::Error> {
154+
let byte_type = u8::consensus_decode(d)?;
153155
match byte_type {
154156
0x00 => Ok(BundleStatus::Init),
155157
0x01 => {
156-
let num = VarInt::consensus_decode(&mut d)?;
158+
let num = VarInt::consensus_decode(d)?;
157159
let num = num.0 as usize;
158160

159161
let mut cf_headers = Vec::with_capacity(num);
160162
for _ in 0..num {
161-
cf_headers.push(FilterHeader::consensus_decode(&mut d)?);
163+
cf_headers.push(FilterHeader::consensus_decode(d)?);
162164
}
163165

164166
Ok(BundleStatus::CfHeaders { cf_headers })
165167
}
166168
0x02 => {
167-
let num = VarInt::consensus_decode(&mut d)?;
169+
let num = VarInt::consensus_decode(d)?;
168170
let num = num.0 as usize;
169171

170172
let mut cf_filters = Vec::with_capacity(num);
171173
for _ in 0..num {
172-
cf_filters.push(Vec::<u8>::consensus_decode(&mut d)?);
174+
cf_filters.push(Vec::<u8>::consensus_decode(d)?);
173175
}
174176

175177
Ok(BundleStatus::CFilters { cf_filters })
176178
}
177179
0x03 => {
178-
let num = VarInt::consensus_decode(&mut d)?;
180+
let num = VarInt::consensus_decode(d)?;
179181
let num = num.0 as usize;
180182

181183
let mut cf_filters = Vec::with_capacity(num);
182184
for _ in 0..num {
183-
cf_filters.push(Vec::<u8>::consensus_decode(&mut d)?);
185+
cf_filters.push(Vec::<u8>::consensus_decode(d)?);
184186
}
185187

186188
Ok(BundleStatus::Processed { cf_filters })
187189
}
188190
0x04 => Ok(BundleStatus::Pruned),
189191
0x05 => {
190-
let num = VarInt::consensus_decode(&mut d)?;
192+
let num = VarInt::consensus_decode(d)?;
191193
let num = num.0 as usize;
192194

193195
let mut cf_filters = Vec::with_capacity(num);
194196
for _ in 0..num {
195-
cf_filters.push(Vec::<u8>::consensus_decode(&mut d)?);
197+
cf_filters.push(Vec::<u8>::consensus_decode(d)?);
196198
}
197199

198200
Ok(BundleStatus::Tip { cf_filters })
@@ -276,7 +278,11 @@ impl ChainStore<Full> {
276278
}
277279

278280
pub fn start_snapshot(&self, from: usize) -> Result<ChainStore<Snapshot>, CompactFiltersError> {
279-
let new_cf_name: String = thread_rng().sample_iter(&Alphanumeric).take(16).collect();
281+
let new_cf_name: String = thread_rng()
282+
.sample_iter(&Alphanumeric)
283+
.map(|byte| byte as char)
284+
.take(16)
285+
.collect();
280286
let new_cf_name = format!("_headers:{}", new_cf_name);
281287

282288
let mut write_store = self.store.write().unwrap();
@@ -647,7 +653,7 @@ impl CfStore {
647653
&first_key,
648654
(
649655
BundleStatus::Init,
650-
filter.filter_header(&FilterHeader::from_hash(Default::default())),
656+
filter.filter_header(&FilterHeader::from_hash(Hash::all_zeros())),
651657
)
652658
.serialize(),
653659
)?;

src/blockchain/compact_filters/sync.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::sync::{Arc, Mutex};
1414
use std::time::Duration;
1515

1616
use bitcoin::hash_types::{BlockHash, FilterHeader};
17+
use bitcoin::hashes::Hash;
1718
use bitcoin::network::message::NetworkMessage;
1819
use bitcoin::network::message_blockdata::GetHeadersMessage;
1920
use bitcoin::util::bip158::BlockFilter;
@@ -254,7 +255,7 @@ where
254255

255256
peer.send(NetworkMessage::GetHeaders(GetHeadersMessage::new(
256257
locators_vec,
257-
Default::default(),
258+
Hash::all_zeros(),
258259
)))?;
259260
let (mut snapshot, mut last_hash) = if let NetworkMessage::Headers(headers) = peer
260261
.recv("headers", Some(Duration::from_secs(TIMEOUT_SECS)))?
@@ -276,7 +277,7 @@ where
276277
while sync_height < peer.get_version().start_height as usize {
277278
peer.send(NetworkMessage::GetHeaders(GetHeadersMessage::new(
278279
vec![last_hash],
279-
Default::default(),
280+
Hash::all_zeros(),
280281
)))?;
281282
if let NetworkMessage::Headers(headers) = peer
282283
.recv("headers", Some(Duration::from_secs(TIMEOUT_SECS)))?

0 commit comments

Comments
 (0)