Skip to content

Commit 71d0af8

Browse files
committed
Upgrade bitcoin dependency to version 0.31.0
Upgrade to the recent bitcoin v0.31.0 release 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`.
1 parent 45db68c commit 71d0af8

File tree

8 files changed

+24
-27
lines changed

8 files changed

+24
-27
lines changed

client/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,3 @@ jsonrpc = "0.14.0"
2727
# Used for deserialization of JSON.
2828
serde = "1"
2929
serde_json = "1"
30-
bitcoin-private = "0.1.0"

client/src/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::path::PathBuf;
1515
use std::{fmt, result};
1616

1717
use crate::{bitcoin, deserialize_hex};
18-
use bitcoin_private::hex::exts::DisplayHex;
18+
use bitcoin::hex::DisplayHex;
1919
use jsonrpc;
2020
use serde;
2121
use serde_json;

client/src/error.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use serde_json;
2020
#[derive(Debug)]
2121
pub enum Error {
2222
JsonRpc(jsonrpc::error::Error),
23-
Hex(hex::Error),
23+
Hex(hex::HexToBytesError),
2424
Json(serde_json::error::Error),
2525
BitcoinSerialization(bitcoin::consensus::encode::Error),
2626
Secp256k1(secp256k1::Error),
@@ -39,8 +39,8 @@ impl From<jsonrpc::error::Error> for Error {
3939
}
4040
}
4141

42-
impl From<hex::Error> for Error {
43-
fn from(e: hex::Error) -> Error {
42+
impl From<hex::HexToBytesError> for Error {
43+
fn from(e: hex::HexToBytesError) -> Error {
4444
Error::Hex(e)
4545
}
4646
}

client/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub extern crate bitcoincore_rpc_json;
2828
pub use crate::json::bitcoin;
2929
pub use bitcoincore_rpc_json as json;
3030
use json::bitcoin::consensus::{Decodable, ReadExt};
31-
use json::bitcoin::hashes::hex::HexIterator;
31+
use json::bitcoin::hex::HexToBytesIter;
3232

3333
mod client;
3434
mod error;
@@ -39,7 +39,7 @@ pub use crate::error::Error;
3939
pub use crate::queryable::*;
4040

4141
fn deserialize_hex<T: Decodable>(hex: &str) -> Result<T> {
42-
let mut reader = HexIterator::new(&hex)?;
42+
let mut reader = HexToBytesIter::new(&hex)?;
4343
let object = Decodable::consensus_decode(&mut reader)?;
4444
if reader.read_u8().is_ok() {
4545
Err(Error::BitcoinSerialization(bitcoin::consensus::encode::Error::ParseFailed(

integration_test/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ edition = "2018"
66

77
[dependencies]
88
bitcoincore-rpc = { path = "../client" }
9-
bitcoin = { version = "0.30.0", features = ["serde", "rand"]}
9+
bitcoin = { version = "0.31.0-rc2", features = ["serde", "rand"]}
1010
lazy_static = "1.4.0"
1111
log = "0.4"

integration_test/src/main.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::collections::HashMap;
1717
use std::str::FromStr;
1818

1919
use bitcoin::absolute::LockTime;
20-
use bitcoin::address::NetworkChecked;
20+
use bitcoin::address::{NetworkChecked, NetworkUnchecked};
2121
use bitcoincore_rpc::json;
2222
use bitcoincore_rpc::jsonrpc::error::Error as JsonRpcError;
2323
use bitcoincore_rpc::{Auth, Client, Error, RpcApi};
@@ -28,8 +28,8 @@ use bitcoin::hashes::hex::FromHex;
2828
use bitcoin::hashes::Hash;
2929
use bitcoin::{secp256k1, sighash, ScriptBuf};
3030
use bitcoin::{
31-
Address, Amount, Network, OutPoint, PrivateKey, Sequence, SignedAmount, Transaction, TxIn,
32-
TxOut, Txid, Witness,
31+
transaction, Address, Amount, Network, OutPoint, PrivateKey, Sequence, SignedAmount,
32+
Transaction, TxIn, TxOut, Txid, Witness,
3333
};
3434
use bitcoincore_rpc::bitcoincore_rpc_json::{
3535
GetBlockTemplateModes, GetBlockTemplateRules, ScanTxOutRequest,
@@ -603,7 +603,7 @@ fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) {
603603
let unspent = unspent.into_iter().nth(0).unwrap();
604604

605605
let tx = Transaction {
606-
version: 1,
606+
version: transaction::Version::ONE,
607607
lock_time: LockTime::ZERO,
608608
input: vec![TxIn {
609609
previous_output: OutPoint {
@@ -615,7 +615,7 @@ fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) {
615615
witness: Witness::new(),
616616
}],
617617
output: vec![TxOut {
618-
value: (unspent.amount - *FEE).to_sat(),
618+
value: (unspent.amount - *FEE),
619619
script_pubkey: addr.script_pubkey(),
620620
}],
621621
};
@@ -632,7 +632,7 @@ fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) {
632632
let txid = cl.send_raw_transaction(&res.transaction().unwrap()).unwrap();
633633

634634
let tx = Transaction {
635-
version: 1,
635+
version: transaction::Version::ONE,
636636
lock_time: LockTime::ZERO,
637637
input: vec![TxIn {
638638
previous_output: OutPoint {
@@ -644,7 +644,7 @@ fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) {
644644
witness: Witness::new(),
645645
}],
646646
output: vec![TxOut {
647-
value: (unspent.amount - *FEE - *FEE).to_sat(),
647+
value: (unspent.amount - *FEE - *FEE),
648648
script_pubkey: RANDOM_ADDRESS.script_pubkey(),
649649
}],
650650
};
@@ -1415,12 +1415,13 @@ fn test_add_multisig_address(cl: &Client) {
14151415
.is_ok());
14161416
}
14171417

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

@@ -1431,8 +1432,8 @@ fn test_derive_addresses(cl: &Client) {
14311432
assert_eq!(
14321433
cl.derive_addresses(descriptor, Some([0, 1])).unwrap(),
14331434
vec![
1434-
"bcrt1q5n5tjkpva8v5s0uadu2y5f0g7pn4h5eqaq2ux2".parse().unwrap(),
1435-
"bcrt1qcgl303ht03ja2e0hudpwk7ypcxk5t478wspzlt".parse().unwrap(),
1435+
"bcrt1q5n5tjkpva8v5s0uadu2y5f0g7pn4h5eqaq2ux2".parse::<Address<NetworkUnchecked>>().unwrap(),
1436+
"bcrt1qcgl303ht03ja2e0hudpwk7ypcxk5t478wspzlt".parse::<Address<NetworkUnchecked>>().unwrap(),
14361437
]
14371438
);
14381439
assert!(cl.derive_addresses(descriptor, None).is_err()); // Range must be specified for a ranged descriptor

json/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ path = "src/lib.rs"
2222
serde = { version = "1", features = [ "derive" ] }
2323
serde_json = "1"
2424

25-
bitcoin = { version = "0.30.0", features = ["serde", "rand-std"]}
26-
bitcoin-private = "0.1.0"
25+
bitcoin = { version = "0.31.0", features = ["serde", "rand-std"]}

json/src/lib.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ use std::fmt;
4343
///
4444
/// The module is compatible with the serde attribute.
4545
pub mod serde_hex {
46-
use bitcoin::hashes::hex::FromHex;
47-
use bitcoin_private::hex::exts::DisplayHex;
46+
use bitcoin::hex::{DisplayHex, FromHex};
4847
use serde::de::Error;
4948
use serde::{Deserializer, Serializer};
5049

@@ -58,8 +57,7 @@ pub mod serde_hex {
5857
}
5958

6059
pub mod opt {
61-
use bitcoin::hashes::hex::FromHex;
62-
use bitcoin_private::hex::exts::DisplayHex;
60+
use bitcoin::hex::{DisplayHex, FromHex};
6361
use serde::de::Error;
6462
use serde::{Deserializer, Serializer};
6563

@@ -176,7 +174,7 @@ pub struct GetWalletInfoResult {
176174
#[serde(rename = "paytxfee", with = "bitcoin::amount::serde::as_btc")]
177175
pub pay_tx_fee: Amount,
178176
#[serde(rename = "hdseedid")]
179-
pub hd_seed_id: Option<bitcoin::hash_types::XpubIdentifier>,
177+
pub hd_seed_id: Option<bitcoin::bip32::XKeyIdentifier>,
180178
pub private_keys_enabled: bool,
181179
pub avoid_reuse: Option<bool>,
182180
pub scanning: Option<ScanningDetails>,
@@ -946,7 +944,7 @@ pub struct GetAddressInfoResultEmbedded {
946944
#[serde(rename = "hdkeypath")]
947945
pub hd_key_path: Option<bip32::DerivationPath>,
948946
#[serde(rename = "hdseedid")]
949-
pub hd_seed_id: Option<bitcoin::hash_types::XpubIdentifier>,
947+
pub hd_seed_id: Option<bitcoin::bip32::XKeyIdentifier>,
950948
#[serde(default)]
951949
pub labels: Vec<GetAddressInfoResultLabel>,
952950
}
@@ -1000,7 +998,7 @@ pub struct GetAddressInfoResult {
1000998
#[serde(rename = "hdkeypath")]
1001999
pub hd_key_path: Option<bip32::DerivationPath>,
10021000
#[serde(rename = "hdseedid")]
1003-
pub hd_seed_id: Option<bitcoin::hash_types::XpubIdentifier>,
1001+
pub hd_seed_id: Option<bitcoin::bip32::XKeyIdentifier>,
10041002
pub labels: Vec<GetAddressInfoResultLabel>,
10051003
/// Deprecated in v0.20.0. See `labels` field instead.
10061004
#[deprecated(note = "since Core v0.20.0")]

0 commit comments

Comments
 (0)