Skip to content

Commit 1ffd59d

Browse files
committed
Upgrade to rust-bitcoin 0.29
1 parent ae4f4e5 commit 1ffd59d

File tree

29 files changed

+562
-888
lines changed

29 files changed

+562
-888
lines changed

Cargo.toml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@ 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" }
2121
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]
@@ -106,7 +106,9 @@ dev-getrandom-wasm = ["getrandom/js"]
106106
[dev-dependencies]
107107
lazy_static = "1.4"
108108
env_logger = "0.7"
109-
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"
110112

111113
[[example]]
112114
name = "compact_filters_balance"

README.md

Lines changed: 2 additions & 2 deletions
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> {

examples/psbt_signer.rs

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 33 additions & 27 deletions
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

Lines changed: 3 additions & 2 deletions
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)))?

src/blockchain/electrum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl<'a, 'b, D: Database> TxCache<'a, 'b, D> {
296296
}
297297

298298
/// Configuration for an [`ElectrumBlockchain`]
299-
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq)]
299+
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq, Eq)]
300300
pub struct ElectrumBlockchainConfig {
301301
/// URL of the Electrum server (such as ElectrumX, Esplora, BWT) may start with `ssl://` or `tcp://` and include a port
302302
///

src/blockchain/esplora/async.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ impl GetTx for EsploraBlockchain {
125125
#[maybe_async]
126126
impl GetBlockHash for EsploraBlockchain {
127127
fn get_block_hash(&self, height: u64) -> Result<BlockHash, Error> {
128-
let block_header = await_or_block!(self.url_client.get_header(height as u32))?;
129-
Ok(block_header.block_hash())
128+
Ok(await_or_block!(self
129+
.url_client
130+
.get_block_hash(height as u32))?)
130131
}
131132
}
132133

src/blockchain/esplora/blocking.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ impl GetTx for EsploraBlockchain {
110110

111111
impl GetBlockHash for EsploraBlockchain {
112112
fn get_block_hash(&self, height: u64) -> Result<BlockHash, Error> {
113-
let block_header = self.url_client.get_header(height as u32)?;
114-
Ok(block_header.block_hash())
113+
Ok(self.url_client.get_block_hash(height as u32)?)
115114
}
116115
}
117116

src/blockchain/esplora/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ mod blocking;
3333
pub use self::blocking::*;
3434

3535
/// Configuration for an [`EsploraBlockchain`]
36-
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq)]
36+
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq, Eq)]
3737
pub struct EsploraBlockchainConfig {
3838
/// Base URL of the esplora service
3939
///

0 commit comments

Comments
 (0)