Skip to content

Commit

Permalink
Depend on bitcoin v0.32.0-rc1
Browse files Browse the repository at this point in the history
Test the latest bitcoin release candidate. Includes bumping the version
numbers so we can use this branch to test crates further up the stack.
  • Loading branch information
tcharding committed Apr 9, 2024
1 parent e7a438b commit e068140
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 43 deletions.
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"
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 <steven@stevenroose.org>",
"Jean Pierre Dudey <jeandudey@hotmail.com>",
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
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
4 changes: 2 additions & 2 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 <steven@stevenroose.org>",
"Jean Pierre Dudey <jeandudey@hotmail.com>",
Expand All @@ -23,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"]}

0 comments on commit e068140

Please sign in to comment.