Skip to content

Commit

Permalink
Upgrade bitcoin dependency to version 0.31.0-rc2
Browse files Browse the repository at this point in the history
Upgrade to the rc2 release for upcoming bitcoin v0.31.0 by doing:

- Remove dependency on `bitcoin_private`, use hex stuff from
`bitcoin::hex` (re-export of `hex-conservative`).
- Do type renames.
- Add a couple of type annotations when parsing `Address`.
  • Loading branch information
tcharding committed Oct 27, 2023
1 parent 1a901f4 commit 96300ce
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 27 deletions.
1 change: 0 additions & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ jsonrpc = "0.14.0"
# Used for deserialization of JSON.
serde = "1"
serde_json = "1"
bitcoin-private = "0.1.0"
2 changes: 1 addition & 1 deletion client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::path::PathBuf;
use std::{fmt, result};

use crate::{bitcoin, deserialize_hex};
use bitcoin_private::hex::exts::DisplayHex;
use bitcoin::hex::DisplayHex;
use jsonrpc;
use serde;
use serde_json;
Expand Down
6 changes: 3 additions & 3 deletions client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use serde_json;
#[derive(Debug)]
pub enum Error {
JsonRpc(jsonrpc::error::Error),
Hex(hex::Error),
Hex(hex::HexToBytesError),
Json(serde_json::error::Error),
BitcoinSerialization(bitcoin::consensus::encode::Error),
Secp256k1(secp256k1::Error),
Expand All @@ -39,8 +39,8 @@ impl From<jsonrpc::error::Error> for Error {
}
}

impl From<hex::Error> for Error {
fn from(e: hex::Error) -> Error {
impl From<hex::HexToBytesError> for Error {
fn from(e: hex::HexToBytesError) -> Error {
Error::Hex(e)
}
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ 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::hashes::hex::HexIterator;
use json::bitcoin::hex::HexToBytesIter;

mod client;
mod error;
Expand All @@ -39,7 +39,7 @@ pub use crate::error::Error;
pub use crate::queryable::*;

fn deserialize_hex<T: Decodable>(hex: &str) -> Result<T> {
let mut reader = HexIterator::new(&hex)?;
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(
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.30.0", features = ["serde", "rand"]}
bitcoin = { version = "0.31.0-rc2", features = ["serde", "rand"]}
lazy_static = "1.4.0"
log = "0.4"
21 changes: 11 additions & 10 deletions integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::collections::HashMap;
use std::str::FromStr;

use bitcoin::absolute::LockTime;
use bitcoin::address::NetworkChecked;
use bitcoin::address::{NetworkChecked, NetworkUnchecked};
use bitcoincore_rpc::json;
use bitcoincore_rpc::jsonrpc::error::Error as JsonRpcError;
use bitcoincore_rpc::{Auth, Client, Error, RpcApi};
Expand All @@ -28,8 +28,8 @@ use bitcoin::hashes::hex::FromHex;
use bitcoin::hashes::Hash;
use bitcoin::{secp256k1, sighash, ScriptBuf};
use bitcoin::{
Address, Amount, Network, OutPoint, PrivateKey, Sequence, SignedAmount, Transaction, TxIn,
TxOut, Txid, Witness,
transaction, Address, Amount, Network, OutPoint, PrivateKey, Sequence, SignedAmount,
Transaction, TxIn, TxOut, Txid, Witness,
};
use bitcoincore_rpc::bitcoincore_rpc_json::{
GetBlockTemplateModes, GetBlockTemplateRules, ScanTxOutRequest,
Expand Down Expand Up @@ -603,7 +603,7 @@ fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) {
let unspent = unspent.into_iter().nth(0).unwrap();

let tx = Transaction {
version: 1,
version: transaction::Version::ONE,
lock_time: LockTime::ZERO,
input: vec![TxIn {
previous_output: OutPoint {
Expand All @@ -615,7 +615,7 @@ fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) {
witness: Witness::new(),
}],
output: vec![TxOut {
value: (unspent.amount - *FEE).to_sat(),
value: (unspent.amount - *FEE),
script_pubkey: addr.script_pubkey(),
}],
};
Expand All @@ -632,7 +632,7 @@ fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) {
let txid = cl.send_raw_transaction(&res.transaction().unwrap()).unwrap();

let tx = Transaction {
version: 1,
version: transaction::Version::ONE,
lock_time: LockTime::ZERO,
input: vec![TxIn {
previous_output: OutPoint {
Expand All @@ -644,7 +644,7 @@ fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) {
witness: Witness::new(),
}],
output: vec![TxOut {
value: (unspent.amount - *FEE - *FEE).to_sat(),
value: (unspent.amount - *FEE - *FEE),
script_pubkey: RANDOM_ADDRESS.script_pubkey(),
}],
};
Expand Down Expand Up @@ -1415,12 +1415,13 @@ fn test_add_multisig_address(cl: &Client) {
.is_ok());
}

#[rustfmt::skip]
fn test_derive_addresses(cl: &Client) {
let descriptor =
r"pkh(02e96fe52ef0e22d2f131dd425ce1893073a3c6ad20e8cac36726393dfb4856a4c)#62k9sn4x";
assert_eq!(
cl.derive_addresses(descriptor, None).unwrap(),
vec!["mrkwtj5xpYQjHeJe5wsweNjVeTKkvR5fCr".parse().unwrap()]
vec!["mrkwtj5xpYQjHeJe5wsweNjVeTKkvR5fCr".parse::<Address<NetworkUnchecked>>().unwrap()]
);
assert!(cl.derive_addresses(descriptor, Some([0, 1])).is_err()); // Range should not be specified for an unranged descriptor

Expand All @@ -1431,8 +1432,8 @@ fn test_derive_addresses(cl: &Client) {
assert_eq!(
cl.derive_addresses(descriptor, Some([0, 1])).unwrap(),
vec![
"bcrt1q5n5tjkpva8v5s0uadu2y5f0g7pn4h5eqaq2ux2".parse().unwrap(),
"bcrt1qcgl303ht03ja2e0hudpwk7ypcxk5t478wspzlt".parse().unwrap(),
"bcrt1q5n5tjkpva8v5s0uadu2y5f0g7pn4h5eqaq2ux2".parse::<Address<NetworkUnchecked>>().unwrap(),
"bcrt1qcgl303ht03ja2e0hudpwk7ypcxk5t478wspzlt".parse::<Address<NetworkUnchecked>>().unwrap(),
]
);
assert!(cl.derive_addresses(descriptor, None).is_err()); // Range must be specified for a ranged descriptor
Expand Down
3 changes: 1 addition & 2 deletions json/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ path = "src/lib.rs"
serde = { version = "1", features = [ "derive" ] }
serde_json = "1"

bitcoin = { version = "0.30.0", features = ["serde", "rand-std"]}
bitcoin-private = "0.1.0"
bitcoin = { version = "0.31.0-rc2", features = ["serde", "rand-std"]}
12 changes: 5 additions & 7 deletions json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ use std::fmt;
///
/// The module is compatible with the serde attribute.
pub mod serde_hex {
use bitcoin::hashes::hex::FromHex;
use bitcoin_private::hex::exts::DisplayHex;
use bitcoin::hex::{DisplayHex, FromHex};
use serde::de::Error;
use serde::{Deserializer, Serializer};

Expand All @@ -58,8 +57,7 @@ pub mod serde_hex {
}

pub mod opt {
use bitcoin::hashes::hex::FromHex;
use bitcoin_private::hex::exts::DisplayHex;
use bitcoin::hex::{DisplayHex, FromHex};
use serde::de::Error;
use serde::{Deserializer, Serializer};

Expand Down Expand Up @@ -176,7 +174,7 @@ pub struct GetWalletInfoResult {
#[serde(rename = "paytxfee", with = "bitcoin::amount::serde::as_btc")]
pub pay_tx_fee: Amount,
#[serde(rename = "hdseedid")]
pub hd_seed_id: Option<bitcoin::hash_types::XpubIdentifier>,
pub hd_seed_id: Option<bitcoin::bip32::XKeyIdentifier>,
pub private_keys_enabled: bool,
pub avoid_reuse: Option<bool>,
pub scanning: Option<ScanningDetails>,
Expand Down Expand Up @@ -946,7 +944,7 @@ pub struct GetAddressInfoResultEmbedded {
#[serde(rename = "hdkeypath")]
pub hd_key_path: Option<bip32::DerivationPath>,
#[serde(rename = "hdseedid")]
pub hd_seed_id: Option<bitcoin::hash_types::XpubIdentifier>,
pub hd_seed_id: Option<bitcoin::bip32::XKeyIdentifier>,
#[serde(default)]
pub labels: Vec<GetAddressInfoResultLabel>,
}
Expand Down Expand Up @@ -1000,7 +998,7 @@ pub struct GetAddressInfoResult {
#[serde(rename = "hdkeypath")]
pub hd_key_path: Option<bip32::DerivationPath>,
#[serde(rename = "hdseedid")]
pub hd_seed_id: Option<bitcoin::hash_types::XpubIdentifier>,
pub hd_seed_id: Option<bitcoin::bip32::XKeyIdentifier>,
pub labels: Vec<GetAddressInfoResultLabel>,
/// Deprecated in v0.20.0. See `labels` field instead.
#[deprecated(note = "since Core v0.20.0")]
Expand Down

0 comments on commit 96300ce

Please sign in to comment.