diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index 6cad605c..c549e548 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -48,6 +48,9 @@ jobs: run: rustup component add clippy - name: Update toolchain run: rustup update + - name: pin dependencies + if: matrix.rust.version == '1.57.0' + run: cargo update -p log --precise 0.4.18 && cargo update -p rustls:0.21.2 --precise 0.21.1 && cargo update -p time:0.3.15 --precise 0.3.13 - name: Build run: cargo build --features ${{ matrix.features }} --no-default-features - name: Clippy diff --git a/Cargo.toml b/Cargo.toml index c19b1069..3ff00a87 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,9 @@ path = "src/lib.rs" [dependencies] serde = { version = "1.0", features = ["derive"] } -bitcoin = { version = "0.29.1", features = ["serde"], default-features = false } +bitcoin = { version = "0.30.0", features = ["serde", "std"], default-features = false } +# Temporary dependency on internals until the rust-bitcoin devs release the hex-conservative crate. +bitcoin-internals = { version = "0.1.0", features = ["alloc"] } log = "^0.4" ureq = { version = "2.5.0", features = ["json"], optional = true } reqwest = { version = "0.11", optional = true, default-features = false, features = ["json"] } @@ -25,8 +27,8 @@ reqwest = { version = "0.11", optional = true, default-features = false, feature [dev-dependencies] serde_json = "1.0" tokio = { version = "1.20.1", features = ["full"] } -electrsd = { version = "0.22.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_22_0"] } -electrum-client = "0.12.0" +electrsd = { version = "0.24.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_22_0"] } +electrum-client = "0.16.0" lazy_static = "1.4.0" # zip versions after 0.6.3 don't work with our MSRV 1.57.0 zip = "=0.6.3" diff --git a/src/api.rs b/src/api.rs index 5c2fce86..1a3d2395 100644 --- a/src/api.rs +++ b/src/api.rs @@ -4,14 +4,14 @@ pub use bitcoin::consensus::{deserialize, serialize}; pub use bitcoin::hashes::hex::FromHex; -pub use bitcoin::{BlockHash, OutPoint, Script, Transaction, TxIn, TxOut, Txid, Witness}; +pub use bitcoin::{BlockHash, OutPoint, ScriptBuf, Transaction, TxIn, TxOut, Txid, Witness}; use serde::Deserialize; #[derive(Deserialize, Clone, Debug, PartialEq, Eq)] pub struct PrevOut { pub value: u64, - pub scriptpubkey: Script, + pub scriptpubkey: ScriptBuf, } #[derive(Deserialize, Clone, Debug, PartialEq, Eq)] @@ -20,7 +20,7 @@ pub struct Vin { pub vout: u32, // None if coinbase pub prevout: Option, - pub scriptsig: Script, + pub scriptsig: ScriptBuf, #[serde(deserialize_with = "deserialize_witness", default)] pub witness: Vec>, pub sequence: u32, @@ -30,7 +30,7 @@ pub struct Vin { #[derive(Deserialize, Clone, Debug, PartialEq, Eq)] pub struct Vout { pub value: u64, - pub scriptpubkey: Script, + pub scriptpubkey: ScriptBuf, } #[derive(Deserialize, Clone, Debug, PartialEq, Eq)] @@ -87,14 +87,14 @@ pub struct BlockSummary { pub time: BlockTime, /// Hash of the previous block, will be `None` for the genesis block. pub previousblockhash: Option, - pub merkle_root: bitcoin::TxMerkleNode, + pub merkle_root: bitcoin::hash_types::TxMerkleNode, } impl Tx { pub fn to_tx(&self) -> Transaction { Transaction { version: self.version, - lock_time: bitcoin::PackedLockTime(self.locktime), + lock_time: bitcoin::absolute::LockTime::from_consensus(self.locktime), input: self .vin .iter() @@ -106,7 +106,7 @@ impl Tx { }, script_sig: vin.scriptsig, sequence: bitcoin::Sequence(vin.sequence), - witness: Witness::from_vec(vin.witness), + witness: Witness::from_slice(&vin.witness), }) .collect(), output: self diff --git a/src/async.rs b/src/async.rs index bc1012fc..5778e823 100644 --- a/src/async.rs +++ b/src/async.rs @@ -15,9 +15,10 @@ use std::collections::HashMap; use std::str::FromStr; use bitcoin::consensus::{deserialize, serialize}; -use bitcoin::hashes::hex::{FromHex, ToHex}; +use bitcoin::hashes::hex::FromHex; use bitcoin::hashes::{sha256, Hash}; -use bitcoin::{Block, BlockHash, BlockHeader, MerkleBlock, Script, Transaction, Txid}; +use bitcoin::{Block, BlockHash, block::Header as BlockHeader, MerkleBlock, Script, Transaction, Txid}; +use bitcoin_internals::hex::display::DisplayHex; #[allow(unused_imports)] use log::{debug, error, info, trace}; @@ -212,7 +213,7 @@ impl AsyncClient { pub async fn broadcast(&self, transaction: &Transaction) -> Result<(), Error> { self.client .post(&format!("{}/tx", self.url)) - .body(serialize(transaction).to_hex()) + .body(serialize(transaction).to_lower_hex_string()) .send() .await? .error_for_status()?; @@ -269,13 +270,13 @@ impl AsyncClient { script: &Script, last_seen: Option, ) -> Result, Error> { - let script_hash = sha256::Hash::hash(script.as_bytes()).into_inner().to_hex(); + let script_hash = sha256::Hash::hash(script.as_bytes()); let url = match last_seen { Some(last_seen) => format!( - "{}/scripthash/{}/txs/chain/{}", + "{}/scripthash/{:x}/txs/chain/{}", self.url, script_hash, last_seen ), - None => format!("{}/scripthash/{}/txs", self.url, script_hash), + None => format!("{}/scripthash/{:x}/txs", self.url, script_hash), }; Ok(self .client diff --git a/src/blocking.rs b/src/blocking.rs index 8c56c4b4..51f5be5d 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -23,9 +23,11 @@ use log::{debug, error, info, trace}; use ureq::{Agent, Proxy, Response}; use bitcoin::consensus::{deserialize, serialize}; -use bitcoin::hashes::hex::{FromHex, ToHex}; +use bitcoin::hashes::hex::FromHex; use bitcoin::hashes::{sha256, Hash}; -use bitcoin::{Block, BlockHash, BlockHeader, MerkleBlock, Script, Transaction, Txid}; +use bitcoin::{Block, BlockHash, block::Header as BlockHeader, MerkleBlock, Script, Transaction, Txid}; + +use bitcoin_internals::hex::display::DisplayHex; use crate::{BlockStatus, BlockSummary, Builder, Error, MerkleProof, OutputStatus, Tx, TxStatus}; @@ -244,7 +246,7 @@ impl BlockingClient { let resp = self .agent .post(&format!("{}/tx", self.url)) - .send_string(&serialize(transaction).to_hex()); + .send_string(&serialize(transaction).to_lower_hex_string()); match resp { Ok(_) => Ok(()), // We do not return the txid? @@ -329,13 +331,13 @@ impl BlockingClient { script: &Script, last_seen: Option, ) -> Result, Error> { - let script_hash = sha256::Hash::hash(script.as_bytes()).into_inner().to_hex(); + let script_hash = sha256::Hash::hash(script.as_bytes()); let url = match last_seen { Some(last_seen) => format!( - "{}/scripthash/{}/txs/chain/{}", + "{}/scripthash/{:x}/txs/chain/{}", self.url, script_hash, last_seen ), - None => format!("{}/scripthash/{}/txs", self.url, script_hash), + None => format!("{}/scripthash/{:x}/txs", self.url, script_hash), }; Ok(self.agent.get(&url).call()?.into_json()?) } diff --git a/src/lib.rs b/src/lib.rs index 574618ad..f4fe6444 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -64,7 +64,6 @@ use std::fmt; use std::io; use bitcoin::consensus; -use bitcoin::{BlockHash, Txid}; pub mod api; @@ -224,10 +223,10 @@ mod test { bitcoin::hashes::Hash, bitcoin::Amount, electrsd::{ - bitcoind::bitcoincore_rpc::bitcoincore_rpc_json::AddressType, + bitcoind::bitcoincore_rpc::json::AddressType, bitcoind::bitcoincore_rpc::RpcApi, + electrum_client::ElectrumApi, }, - electrum_client::ElectrumApi, std::time::Duration, tokio::sync::OnceCell, }; @@ -292,7 +291,8 @@ mod test { let address = BITCOIND .client .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap(); + .unwrap() + .assume_checked(); let _block_hashes = BITCOIND .client .generate_to_address(num as u64, &address) @@ -383,7 +383,8 @@ mod test { let address = BITCOIND .client .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap(); + .unwrap() + .assume_checked(); let txid = BITCOIND .client .send_to_address( @@ -413,7 +414,8 @@ mod test { let address = BITCOIND .client .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap(); + .unwrap() + .assume_checked(); let txid = BITCOIND .client .send_to_address( @@ -443,7 +445,8 @@ mod test { let address = BITCOIND .client .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap(); + .unwrap() + .assume_checked(); let txid = BITCOIND .client .send_to_address( @@ -572,7 +575,8 @@ mod test { let address = BITCOIND .client .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap(); + .unwrap() + .assume_checked(); let txid = BITCOIND .client .send_to_address( @@ -603,7 +607,8 @@ mod test { let address = BITCOIND .client .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap(); + .unwrap() + .assume_checked(); let txid = BITCOIND .client .send_to_address( @@ -643,7 +648,8 @@ mod test { let address = BITCOIND .client .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap(); + .unwrap() + .assume_checked(); let txid = BITCOIND .client .send_to_address( @@ -741,7 +747,8 @@ mod test { let address = BITCOIND .client .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap(); + .unwrap() + .assume_checked(); let txid = BITCOIND .client .send_to_address(