Skip to content

Commit

Permalink
Upgrade bitcoin
Browse files Browse the repository at this point in the history
Upgrade bitcoin dependency to `rust-bitcoin v0.31.0-rc1`:

Allows us to remove the dependency on `bitcoin-private` because the
`hex` stuff is exposed by `bitcoin` now.
  • Loading branch information
tcharding committed Oct 16, 2023
1 parent 5ecb26f commit be333cf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ path = "src/lib.rs"

[dependencies]
log = "^0.4"
bitcoin = { version = "^0.30", features = ["serde"] }
bitcoin-private = "0.1.0"
bitcoin = { version = "0.31.0-rc1", features = ["serde"] }
serde = { version = "^1.0", features = ["derive"] }
serde_json = { version = "^1.0" }

Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
//! ```
pub extern crate bitcoin;
extern crate bitcoin_private;
extern crate core;
extern crate log;
#[cfg(feature = "use-openssl")]
Expand Down
21 changes: 10 additions & 11 deletions src/raw_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ use std::time::Duration;
use log::{debug, error, info, trace, warn};

use bitcoin::consensus::encode::deserialize;
use bitcoin::hashes::hex::FromHex;
use bitcoin::hex::{DisplayHex, FromHex};
use bitcoin::{Script, Txid};
use bitcoin_private::hex::exts::DisplayHex;

#[cfg(feature = "use-openssl")]
use openssl::ssl::{SslConnector, SslMethod, SslStream, SslVerifyMode};
Expand Down Expand Up @@ -1179,9 +1178,9 @@ mod test {
let client = RawClient::new(get_test_server(), None).unwrap();

// Mt.Gox hack address
let addr = bitcoin::Address::from_str("1FeexV6bAHb8ybZjqQMjJrcCrHGW9sb6uF").unwrap();
let addr = bitcoin::Address::from_str("1FeexV6bAHb8ybZjqQMjJrcCrHGW9sb6uF").unwrap().assume_checked();
let resp = client
.script_get_history(&addr.payload.script_pubkey())
.script_get_history(&addr.script_pubkey())
.unwrap();

assert!(resp.len() >= 328);
Expand All @@ -1200,9 +1199,9 @@ mod test {
let client = RawClient::new(get_test_server(), None).unwrap();

// Peter todd's sha256 bounty address https://bitcointalk.org/index.php?topic=293382.0
let addr = bitcoin::Address::from_str("35Snmmy3uhaer2gTboc81ayCip4m9DT4ko").unwrap();
let addr = bitcoin::Address::from_str("35Snmmy3uhaer2gTboc81ayCip4m9DT4ko").unwrap().assume_checked();
let resp = client
.script_list_unspent(&addr.payload.script_pubkey())
.script_list_unspent(&addr.script_pubkey())
.unwrap();

assert!(resp.len() >= 9);
Expand All @@ -1224,7 +1223,7 @@ mod test {
// Peter todd's sha256 bounty address https://bitcointalk.org/index.php?topic=293382.0
let script_1 = bitcoin::Address::from_str("35Snmmy3uhaer2gTboc81ayCip4m9DT4ko")
.unwrap()
.payload
.assume_checked()
.script_pubkey();

let resp = client
Expand All @@ -1246,7 +1245,7 @@ mod test {

#[test]
fn test_transaction_get() {
use bitcoin::Txid;
use bitcoin::{transaction, Txid};

let client = RawClient::new(get_test_server(), None).unwrap();

Expand All @@ -1256,7 +1255,7 @@ mod test {
.unwrap(),
)
.unwrap();
assert_eq!(resp.version, 1);
assert_eq!(resp.version, transaction::Version::ONE);
assert_eq!(resp.lock_time.to_consensus_u32(), 0);
}

Expand Down Expand Up @@ -1340,11 +1339,11 @@ mod test {
let client = RawClient::new(get_test_server(), None).unwrap();

// Mt.Gox hack address
let addr = bitcoin::Address::from_str("1FeexV6bAHb8ybZjqQMjJrcCrHGW9sb6uF").unwrap();
let addr = bitcoin::Address::from_str("1FeexV6bAHb8ybZjqQMjJrcCrHGW9sb6uF").unwrap().assume_checked();

// Just make sure that the call returns Ok(something)
client
.script_subscribe(&addr.payload.script_pubkey())
.script_subscribe(&addr.script_pubkey())
.unwrap();
}

Expand Down
9 changes: 4 additions & 5 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ use std::sync::Arc;

use bitcoin::blockdata::block;
use bitcoin::consensus::encode::deserialize;
use bitcoin::hashes::hex::FromHex;
use bitcoin::hex::{DisplayHex, FromHex};
use bitcoin::hashes::{sha256, Hash};
use bitcoin::{Script, Txid};

use bitcoin_private::hex::exts::DisplayHex;
use serde::{de, Deserialize, Serialize};

static JSONRPC_2_0: &str = "2.0";
Expand Down Expand Up @@ -288,8 +287,8 @@ pub enum Error {
IOError(std::io::Error),
/// Wraps `serde_json::error::Error`
JSON(serde_json::error::Error),
/// Wraps `bitcoin::hashes::hex::Error`
Hex(bitcoin::hashes::hex::Error),
/// Wraps `bitcoin::hex::HexToBytesError`
Hex(bitcoin::hex::HexToBytesError),
/// Error returned by the Electrum server
Protocol(serde_json::Value),
/// Error during the deserialization of a Bitcoin data structure
Expand Down Expand Up @@ -382,7 +381,7 @@ macro_rules! impl_error {

impl_error!(std::io::Error, IOError);
impl_error!(serde_json::Error, JSON);
impl_error!(bitcoin::hashes::hex::Error, Hex);
impl_error!(bitcoin::hex::HexToBytesError, Hex);
impl_error!(bitcoin::consensus::encode::Error, Bitcoin);

impl<T> From<std::sync::PoisonError<T>> for Error {
Expand Down

0 comments on commit be333cf

Please sign in to comment.