Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ 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"] }

[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"
Expand Down
14 changes: 7 additions & 7 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -20,7 +20,7 @@ pub struct Vin {
pub vout: u32,
// None if coinbase
pub prevout: Option<PrevOut>,
pub scriptsig: Script,
pub scriptsig: ScriptBuf,
#[serde(deserialize_with = "deserialize_witness", default)]
pub witness: Vec<Vec<u8>>,
pub sequence: u32,
Expand All @@ -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)]
Expand Down Expand Up @@ -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<bitcoin::BlockHash>,
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()
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions src/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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()?;
Expand Down Expand Up @@ -269,13 +270,13 @@ impl AsyncClient {
script: &Script,
last_seen: Option<Txid>,
) -> Result<Vec<Tx>, 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
Expand Down
14 changes: 8 additions & 6 deletions src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -329,13 +331,13 @@ impl BlockingClient {
script: &Script,
last_seen: Option<Txid>,
) -> Result<Vec<Tx>, 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()?)
}
Expand Down
29 changes: 18 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ use std::fmt;
use std::io;

use bitcoin::consensus;
use bitcoin::{BlockHash, Txid};

pub mod api;

Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down