Skip to content

Commit ea1b6d1

Browse files
committed
Upgrade bitcoin to v0.30.0
Upgrade `rust-bitcoin` to v0.30.3, including: - bitcoin - electrsd - electrum-client Also includes addition of a dependency on `bitcoin-internals` for the `DisplayHex` trait. This is a temporary fix while we wait for release of the new `github.com/rust-bitcoin/hex-conservative` crate.
1 parent d48ac22 commit ea1b6d1

File tree

5 files changed

+45
-32
lines changed

5 files changed

+45
-32
lines changed

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ path = "src/lib.rs"
1717

1818
[dependencies]
1919
serde = { version = "1.0", features = ["derive"] }
20-
bitcoin = { version = "0.29.1", features = ["serde"], default-features = false }
20+
bitcoin = { version = "0.30.0", features = ["serde", "std"], default-features = false }
21+
# Temporary dependency on internals until the rust-bitcoin devs release the hex-conservative crate.
22+
bitcoin-internals = { version = "0.1.0", features = ["alloc"] }
2123
log = "^0.4"
2224
ureq = { version = "2.5.0", features = ["json"], optional = true }
2325
reqwest = { version = "0.11", optional = true, default-features = false, features = ["json"] }
2426

2527
[dev-dependencies]
2628
serde_json = "1.0"
2729
tokio = { version = "1.20.1", features = ["full"] }
28-
electrsd = { version = "0.22.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_22_0"] }
29-
electrum-client = "0.12.0"
30+
electrsd = { version = "0.24.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_22_0"] }
31+
electrum-client = "0.15.1"
3032
lazy_static = "1.4.0"
3133
# zip versions after 0.6.3 don't work with our MSRV 1.57.0
3234
zip = "=0.6.3"

src/api.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
55
pub use bitcoin::consensus::{deserialize, serialize};
66
pub use bitcoin::hashes::hex::FromHex;
7-
pub use bitcoin::{BlockHash, OutPoint, Script, Transaction, TxIn, TxOut, Txid, Witness};
7+
pub use bitcoin::{BlockHash, OutPoint, ScriptBuf, Transaction, TxIn, TxOut, Txid, Witness};
88

99
use serde::Deserialize;
1010

1111
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
1212
pub struct PrevOut {
1313
pub value: u64,
14-
pub scriptpubkey: Script,
14+
pub scriptpubkey: ScriptBuf,
1515
}
1616

1717
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
@@ -20,7 +20,7 @@ pub struct Vin {
2020
pub vout: u32,
2121
// None if coinbase
2222
pub prevout: Option<PrevOut>,
23-
pub scriptsig: Script,
23+
pub scriptsig: ScriptBuf,
2424
#[serde(deserialize_with = "deserialize_witness", default)]
2525
pub witness: Vec<Vec<u8>>,
2626
pub sequence: u32,
@@ -30,7 +30,7 @@ pub struct Vin {
3030
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
3131
pub struct Vout {
3232
pub value: u64,
33-
pub scriptpubkey: Script,
33+
pub scriptpubkey: ScriptBuf,
3434
}
3535

3636
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
@@ -87,14 +87,14 @@ pub struct BlockSummary {
8787
pub time: BlockTime,
8888
/// Hash of the previous block, will be `None` for the genesis block.
8989
pub previousblockhash: Option<bitcoin::BlockHash>,
90-
pub merkle_root: bitcoin::TxMerkleNode,
90+
pub merkle_root: bitcoin::hash_types::TxMerkleNode,
9191
}
9292

9393
impl Tx {
9494
pub fn to_tx(&self) -> Transaction {
9595
Transaction {
9696
version: self.version,
97-
lock_time: bitcoin::PackedLockTime(self.locktime),
97+
lock_time: bitcoin::absolute::LockTime::from_consensus(self.locktime),
9898
input: self
9999
.vin
100100
.iter()
@@ -106,7 +106,7 @@ impl Tx {
106106
},
107107
script_sig: vin.scriptsig,
108108
sequence: bitcoin::Sequence(vin.sequence),
109-
witness: Witness::from_vec(vin.witness),
109+
witness: Witness::from_slice(&vin.witness),
110110
})
111111
.collect(),
112112
output: self

src/async.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ use std::collections::HashMap;
1515
use std::str::FromStr;
1616

1717
use bitcoin::consensus::{deserialize, serialize};
18-
use bitcoin::hashes::hex::{FromHex, ToHex};
18+
use bitcoin::hashes::hex::FromHex;
1919
use bitcoin::hashes::{sha256, Hash};
20-
use bitcoin::{Block, BlockHash, BlockHeader, MerkleBlock, Script, Transaction, Txid};
20+
use bitcoin::{Block, BlockHash, block::Header as BlockHeader, MerkleBlock, Script, Transaction, Txid};
21+
use bitcoin_internals::hex::display::DisplayHex;
2122

2223
#[allow(unused_imports)]
2324
use log::{debug, error, info, trace};
@@ -212,7 +213,7 @@ impl AsyncClient {
212213
pub async fn broadcast(&self, transaction: &Transaction) -> Result<(), Error> {
213214
self.client
214215
.post(&format!("{}/tx", self.url))
215-
.body(serialize(transaction).to_hex())
216+
.body(serialize(transaction).to_lower_hex_string())
216217
.send()
217218
.await?
218219
.error_for_status()?;
@@ -269,13 +270,13 @@ impl AsyncClient {
269270
script: &Script,
270271
last_seen: Option<Txid>,
271272
) -> Result<Vec<Tx>, Error> {
272-
let script_hash = sha256::Hash::hash(script.as_bytes()).into_inner().to_hex();
273+
let script_hash = sha256::Hash::hash(script.as_bytes());
273274
let url = match last_seen {
274275
Some(last_seen) => format!(
275-
"{}/scripthash/{}/txs/chain/{}",
276+
"{}/scripthash/{:x}/txs/chain/{}",
276277
self.url, script_hash, last_seen
277278
),
278-
None => format!("{}/scripthash/{}/txs", self.url, script_hash),
279+
None => format!("{}/scripthash/{:x}/txs", self.url, script_hash),
279280
};
280281
Ok(self
281282
.client

src/blocking.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ use log::{debug, error, info, trace};
2323
use ureq::{Agent, Proxy, Response};
2424

2525
use bitcoin::consensus::{deserialize, serialize};
26-
use bitcoin::hashes::hex::{FromHex, ToHex};
26+
use bitcoin::hashes::hex::FromHex;
2727
use bitcoin::hashes::{sha256, Hash};
28-
use bitcoin::{Block, BlockHash, BlockHeader, MerkleBlock, Script, Transaction, Txid};
28+
use bitcoin::{Block, BlockHash, block::Header as BlockHeader, MerkleBlock, Script, Transaction, Txid};
29+
30+
use bitcoin_internals::hex::display::DisplayHex;
2931

3032
use crate::{BlockStatus, BlockSummary, Builder, Error, MerkleProof, OutputStatus, Tx, TxStatus};
3133

@@ -244,7 +246,7 @@ impl BlockingClient {
244246
let resp = self
245247
.agent
246248
.post(&format!("{}/tx", self.url))
247-
.send_string(&serialize(transaction).to_hex());
249+
.send_string(&serialize(transaction).to_lower_hex_string());
248250

249251
match resp {
250252
Ok(_) => Ok(()), // We do not return the txid?
@@ -329,13 +331,13 @@ impl BlockingClient {
329331
script: &Script,
330332
last_seen: Option<Txid>,
331333
) -> Result<Vec<Tx>, Error> {
332-
let script_hash = sha256::Hash::hash(script.as_bytes()).into_inner().to_hex();
334+
let script_hash = sha256::Hash::hash(script.as_bytes());
333335
let url = match last_seen {
334336
Some(last_seen) => format!(
335-
"{}/scripthash/{}/txs/chain/{}",
337+
"{}/scripthash/{:x}/txs/chain/{}",
336338
self.url, script_hash, last_seen
337339
),
338-
None => format!("{}/scripthash/{}/txs", self.url, script_hash),
340+
None => format!("{}/scripthash/{:x}/txs", self.url, script_hash),
339341
};
340342
Ok(self.agent.get(&url).call()?.into_json()?)
341343
}

src/lib.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ mod test {
224224
bitcoin::hashes::Hash,
225225
bitcoin::Amount,
226226
electrsd::{
227-
bitcoind::bitcoincore_rpc::bitcoincore_rpc_json::AddressType,
227+
bitcoind::bitcoincore_rpc::json::AddressType,
228228
bitcoind::bitcoincore_rpc::RpcApi,
229+
electrum_client::ElectrumApi,
229230
},
230-
electrum_client::ElectrumApi,
231231
std::time::Duration,
232232
tokio::sync::OnceCell,
233233
};
@@ -292,7 +292,8 @@ mod test {
292292
let address = BITCOIND
293293
.client
294294
.get_new_address(Some("test"), Some(AddressType::Legacy))
295-
.unwrap();
295+
.unwrap()
296+
.assume_checked();
296297
let _block_hashes = BITCOIND
297298
.client
298299
.generate_to_address(num as u64, &address)
@@ -383,7 +384,8 @@ mod test {
383384
let address = BITCOIND
384385
.client
385386
.get_new_address(Some("test"), Some(AddressType::Legacy))
386-
.unwrap();
387+
.unwrap()
388+
.assume_checked();
387389
let txid = BITCOIND
388390
.client
389391
.send_to_address(
@@ -413,7 +415,8 @@ mod test {
413415
let address = BITCOIND
414416
.client
415417
.get_new_address(Some("test"), Some(AddressType::Legacy))
416-
.unwrap();
418+
.unwrap()
419+
.assume_checked();
417420
let txid = BITCOIND
418421
.client
419422
.send_to_address(
@@ -443,7 +446,8 @@ mod test {
443446
let address = BITCOIND
444447
.client
445448
.get_new_address(Some("test"), Some(AddressType::Legacy))
446-
.unwrap();
449+
.unwrap()
450+
.assume_checked();
447451
let txid = BITCOIND
448452
.client
449453
.send_to_address(
@@ -572,7 +576,8 @@ mod test {
572576
let address = BITCOIND
573577
.client
574578
.get_new_address(Some("test"), Some(AddressType::Legacy))
575-
.unwrap();
579+
.unwrap()
580+
.assume_checked();
576581
let txid = BITCOIND
577582
.client
578583
.send_to_address(
@@ -603,7 +608,8 @@ mod test {
603608
let address = BITCOIND
604609
.client
605610
.get_new_address(Some("test"), Some(AddressType::Legacy))
606-
.unwrap();
611+
.unwrap()
612+
.assume_checked();
607613
let txid = BITCOIND
608614
.client
609615
.send_to_address(
@@ -643,7 +649,8 @@ mod test {
643649
let address = BITCOIND
644650
.client
645651
.get_new_address(Some("test"), Some(AddressType::Legacy))
646-
.unwrap();
652+
.unwrap()
653+
.assume_checked();
647654
let txid = BITCOIND
648655
.client
649656
.send_to_address(
@@ -741,7 +748,8 @@ mod test {
741748
let address = BITCOIND
742749
.client
743750
.get_new_address(Some("test"), Some(AddressType::Legacy))
744-
.unwrap();
751+
.unwrap()
752+
.assume_checked();
745753
let txid = BITCOIND
746754
.client
747755
.send_to_address(

0 commit comments

Comments
 (0)