Skip to content

Depend on bitcoin v0.32.0-rc #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- rust: nightly
env:
RUSTFMTCHK: false
- rust: 1.48.0
- rust: 1.56.1
env:
RUSTFMTCHK: false
steps:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Unreleased

- MSRV changed from 1.48.0 to 1.56.1

# 0.18.0

- MSRV changed from 1.41.1 to 1.48.0
Expand Down
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ members = [
"client",
"integration_test",
]
resolver = "2"


[patch.crates-io.bitcoin]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "rc1-fixes"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ The following versions are officially supported and automatically tested:
* 0.21.0

# Minimum Supported Rust Version (MSRV)
This library should always compile with any combination of features on **Rust 1.48.0**.
This library should always compile with any combination of features on **Rust 1.56.1**.
4 changes: 2 additions & 2 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bitcoincore-rpc"
version = "0.18.0"
version = "0.19.0"
authors = [
"Steven Roose <[email protected]>",
"Jean Pierre Dudey <[email protected]>",
Expand All @@ -19,7 +19,7 @@ name = "bitcoincore_rpc"
path = "src/lib.rs"

[dependencies]
bitcoincore-rpc-json = { version = "0.18.0", path = "../json" }
bitcoincore-rpc-json = { version = "0.19.0", path = "../json" }

log = "0.4.5"
jsonrpc = "0.14.0"
Expand Down
4 changes: 2 additions & 2 deletions client/examples/test_against_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ fn main_result() -> Result<(), Error> {

let bitcoin_block: bitcoin::Block = rpc.get_by_id(&best_block_hash)?;
println!("best block hash by `get`: {}", bitcoin_block.header.prev_blockhash);
let bitcoin_tx: bitcoin::Transaction = rpc.get_by_id(&bitcoin_block.txdata[0].txid())?;
println!("tx by `get`: {}", bitcoin_tx.txid());
let bitcoin_tx: bitcoin::Transaction = rpc.get_by_id(&bitcoin_block.txdata[0].compute_txid())?;
println!("tx by `get`: {}", bitcoin_tx.compute_txid());

Ok(())
}
Expand Down
13 changes: 7 additions & 6 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use std::iter::FromIterator;
use std::path::PathBuf;
use std::{fmt, result};

use crate::{bitcoin, deserialize_hex};
use crate::bitcoin;
use crate::bitcoin::consensus::encode;
use bitcoin::hex::DisplayHex;
use jsonrpc;
use serde;
Expand Down Expand Up @@ -163,7 +164,7 @@ pub trait RawTx: Sized + Clone {

impl<'a> RawTx for &'a Transaction {
fn raw_hex(self) -> String {
bitcoin::consensus::encode::serialize_hex(self)
encode::serialize_hex(self)
}
}

Expand Down Expand Up @@ -333,7 +334,7 @@ pub trait RpcApi: Sized {

fn get_block(&self, hash: &bitcoin::BlockHash) -> Result<Block> {
let hex: String = self.call("getblock", &[into_json(hash)?, 0.into()])?;
deserialize_hex(&hex)
Ok(encode::deserialize_hex(&hex)?)
}

fn get_block_hex(&self, hash: &bitcoin::BlockHash) -> Result<String> {
Expand All @@ -347,7 +348,7 @@ pub trait RpcApi: Sized {

fn get_block_header(&self, hash: &bitcoin::BlockHash) -> Result<bitcoin::block::Header> {
let hex: String = self.call("getblockheader", &[into_json(hash)?, false.into()])?;
deserialize_hex(&hex)
Ok(encode::deserialize_hex(&hex)?)
}

fn get_block_header_info(
Expand Down Expand Up @@ -491,7 +492,7 @@ pub trait RpcApi: Sized {
) -> Result<Transaction> {
let mut args = [into_json(txid)?, into_json(false)?, opt_into_json(block_hash)?];
let hex: String = self.call("getrawtransaction", handle_defaults(&mut args, &[null()]))?;
deserialize_hex(&hex)
Ok(encode::deserialize_hex(&hex)?)
}

fn get_raw_transaction_hex(
Expand Down Expand Up @@ -788,7 +789,7 @@ pub trait RpcApi: Sized {
replaceable: Option<bool>,
) -> Result<Transaction> {
let hex: String = self.create_raw_transaction_hex(utxos, outs, locktime, replaceable)?;
deserialize_hex(&hex)
Ok(encode::deserialize_hex(&hex)?)
}

fn decode_raw_transaction<R: RawTx>(
Expand Down
6 changes: 3 additions & 3 deletions client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub enum Error {
JsonRpc(jsonrpc::error::Error),
Hex(hex::HexToBytesError),
Json(serde_json::error::Error),
BitcoinSerialization(bitcoin::consensus::encode::Error),
BitcoinSerialization(bitcoin::consensus::encode::FromHexError),
Secp256k1(secp256k1::Error),
Io(io::Error),
InvalidAmount(bitcoin::amount::ParseAmountError),
Expand Down Expand Up @@ -51,8 +51,8 @@ impl From<serde_json::error::Error> for Error {
}
}

impl From<bitcoin::consensus::encode::Error> for Error {
fn from(e: bitcoin::consensus::encode::Error) -> Error {
impl From<bitcoin::consensus::encode::FromHexError> for Error {
fn from(e: bitcoin::consensus::encode::FromHexError) -> Error {
Error::BitcoinSerialization(e)
}
}
Expand Down
14 changes: 0 additions & 14 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ pub extern crate jsonrpc;
pub extern crate bitcoincore_rpc_json;
pub use crate::json::bitcoin;
pub use bitcoincore_rpc_json as json;
use json::bitcoin::consensus::{Decodable, ReadExt};
use json::bitcoin::hex::HexToBytesIter;

mod client;
mod error;
Expand All @@ -37,15 +35,3 @@ mod queryable;
pub use crate::client::*;
pub use crate::error::Error;
pub use crate::queryable::*;

fn deserialize_hex<T: Decodable>(hex: &str) -> Result<T> {
let mut reader = HexToBytesIter::new(&hex)?;
let object = Decodable::consensus_decode(&mut reader)?;
if reader.read_u8().is_ok() {
Err(Error::BitcoinSerialization(bitcoin::consensus::encode::Error::ParseFailed(
"data not consumed entirely when explicitly deserializing",
)))
} else {
Ok(object)
}
}
6 changes: 2 additions & 4 deletions client/src/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ impl<C: RpcApi> Queryable<C> for bitcoin::block::Block {
fn query(rpc: &C, id: &Self::Id) -> Result<Self> {
let rpc_name = "getblock";
let hex: String = rpc.call(rpc_name, &[serde_json::to_value(id)?, 0.into()])?;
let bytes: Vec<u8> = bitcoin::hashes::hex::FromHex::from_hex(&hex)?;
Ok(bitcoin::consensus::encode::deserialize(&bytes)?)
Ok(bitcoin::consensus::encode::deserialize_hex(&hex)?)
}
}

Expand All @@ -39,8 +38,7 @@ impl<C: RpcApi> Queryable<C> for bitcoin::transaction::Transaction {
fn query(rpc: &C, id: &Self::Id) -> Result<Self> {
let rpc_name = "getrawtransaction";
let hex: String = rpc.call(rpc_name, &[serde_json::to_value(id)?])?;
let bytes: Vec<u8> = bitcoin::hashes::hex::FromHex::from_hex(&hex)?;
Ok(bitcoin::consensus::encode::deserialize(&bytes)?)
Ok(bitcoin::consensus::encode::deserialize_hex(&hex)?)
}
}

Expand Down
8 changes: 2 additions & 6 deletions contrib/test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

set -xe

MSRV="1\.48"
MSRV="1\.56"

# Just echo all the relevant env vars to help debug Travis.
echo "RUSTFMTCHECK: \"$RUSTFMTCHECK\""
Expand All @@ -13,14 +13,10 @@ if [ -n "$RUSTFMTCHECK" ]; then
cargo fmt --all -- --check
fi

# Test pinned versions (these are from rust-bitcoin pinning for 1.48).
# Test pinned versions.
if cargo --version | grep ${MSRV}; then
cargo update -p tempfile --precise 3.3.0
cargo update -p log --precise 0.4.18
cargo update -p serde_json --precise 1.0.99
cargo update -p serde --precise 1.0.156
cargo update -p quote --precise 1.0.30
cargo update -p proc-macro2 --precise 1.0.63
fi

# Integration test.
Expand Down
2 changes: 1 addition & 1 deletion integration_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ edition = "2018"

[dependencies]
bitcoincore-rpc = { path = "../client" }
bitcoin = { version = "0.31.0", features = ["serde", "rand"]}
bitcoin = { version = "0.32.0-rc1", features = ["serde", "rand"]}
lazy_static = "1.4.0"
log = "0.4"
20 changes: 11 additions & 9 deletions integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use bitcoin::hashes::hex::FromHex;
use bitcoin::hashes::Hash;
use bitcoin::{secp256k1, ScriptBuf, sighash};
use bitcoin::{
transaction, Address, Amount, Network, OutPoint, PrivateKey, Sequence, SignedAmount,
transaction, Address, Amount, CompressedPublicKey, Network, OutPoint, PrivateKey, Sequence, SignedAmount,
Transaction, TxIn, TxOut, Txid, Witness,
};
use bitcoincore_rpc::bitcoincore_rpc_json::{
Expand Down Expand Up @@ -267,7 +267,8 @@ fn test_get_raw_change_address(cl: &Client) {
fn test_dump_private_key(cl: &Client) {
let addr = cl.get_new_address(None, Some(json::AddressType::Bech32)).unwrap().assume_checked();
let sk = cl.dump_private_key(&addr).unwrap();
assert_eq!(addr, Address::p2wpkh(&sk.public_key(&SECP), *NET).unwrap());
let pk = CompressedPublicKey::from_private_key(&SECP, &sk).unwrap();
assert_eq!(addr, Address::p2wpkh(&pk, *NET));
}

fn test_generate(cl: &Client) {
Expand Down Expand Up @@ -570,11 +571,12 @@ fn test_get_block_filter(cl: &Client) {

fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) {
let sk = PrivateKey {
network: Network::Regtest,
network: Network::Regtest.into(),
inner: secp256k1::SecretKey::new(&mut secp256k1::rand::thread_rng()),
compressed: true,
};
let addr = Address::p2wpkh(&sk.public_key(&SECP), Network::Regtest).unwrap();
let pk = CompressedPublicKey::from_private_key(&SECP, &sk).unwrap();
let addr = Address::p2wpkh(&pk, Network::Regtest);

let options = json::ListUnspentQueryOptions {
minimum_amount: Some(btc(2)),
Expand Down Expand Up @@ -693,7 +695,7 @@ fn test_decode_raw_transaction(cl: &Client) {

let decoded_transaction = cl.decode_raw_transaction(hex, None).unwrap();

assert_eq!(tx.txid(), decoded_transaction.txid);
assert_eq!(tx.compute_txid(), decoded_transaction.txid);
assert_eq!(500_000, decoded_transaction.locktime);

assert_eq!(decoded_transaction.vin[0].txid.unwrap(), unspent.txid);
Expand Down Expand Up @@ -983,7 +985,7 @@ fn test_list_received_by_address(cl: &Client) {

fn test_import_public_key(cl: &Client) {
let sk = PrivateKey {
network: Network::Regtest,
network: Network::Regtest.into(),
inner: secp256k1::SecretKey::new(&mut secp256k1::rand::thread_rng()),
compressed: true,
};
Expand All @@ -994,7 +996,7 @@ fn test_import_public_key(cl: &Client) {

fn test_import_priv_key(cl: &Client) {
let sk = PrivateKey {
network: Network::Regtest,
network: Network::Regtest.into(),
inner: secp256k1::SecretKey::new(&mut secp256k1::rand::thread_rng()),
compressed: true,
};
Expand All @@ -1005,7 +1007,7 @@ fn test_import_priv_key(cl: &Client) {

fn test_import_address(cl: &Client) {
let sk = PrivateKey {
network: Network::Regtest,
network: Network::Regtest.into(),
inner: secp256k1::SecretKey::new(&mut secp256k1::rand::thread_rng()),
compressed: true,
};
Expand All @@ -1017,7 +1019,7 @@ fn test_import_address(cl: &Client) {

fn test_import_address_script(cl: &Client) {
let sk = PrivateKey {
network: Network::Regtest,
network: Network::Regtest.into(),
inner: secp256k1::SecretKey::new(&mut secp256k1::rand::thread_rng()),
compressed: true,
};
Expand Down
7 changes: 4 additions & 3 deletions json/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bitcoincore-rpc-json"
version = "0.18.0"
version = "0.19.0"
authors = [
"Steven Roose <[email protected]>",
"Jean Pierre Dudey <[email protected]>",
Expand All @@ -12,7 +12,8 @@ repository = "https://github.com/rust-bitcoin/rust-bitcoincore-rpc/"
description = "JSON-enabled type structs for bitcoincore-rpc crate."
keywords = [ "crypto", "bitcoin", "bitcoin-core", "rpc" ]
readme = "README.md"
edition = "2018"
edition = "2021"
rust-version = "1.56.1"

[lib]
name = "bitcoincore_rpc_json"
Expand All @@ -22,4 +23,4 @@ path = "src/lib.rs"
serde = { version = "1", features = [ "derive" ] }
serde_json = "1"

bitcoin = { version = "0.31.0", features = ["serde", "rand-std"]}
bitcoin = { version = "0.32.0-rc1", features = ["serde", "rand-std"]}