Skip to content

Commit 7b66711

Browse files
committed
Upgrade bitcoin dependency
Upgrade to the upcoming bitcoin beta release. This is a local branch with a few PRs merged as described in rust-bitcoin/rust-bitcoin#5742
1 parent 2607a0b commit 7b66711

109 files changed

Lines changed: 1160 additions & 878 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

client/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ rustdoc-args = ["--cfg", "docsrs"]
2121
client-sync = ["jsonrpc"]
2222

2323
[dependencies]
24-
bitcoin = { version = "0.32.0", default-features = false, features = ["std", "serde"] }
24+
# Branch `corepc`. hex stuff plus RC stuff (#5704, #5657, and #5710)
25+
bitcoin = { version = "0.33.0-beta", path = "../../rust-bitcoin/bitcoin", default-features = false, features = ["std", "serde"] }
2526
log = "0.4"
2627
serde = { version = "1.0.103", default-features = false, features = [ "derive", "alloc" ] }
2728
serde_json = { version = "1.0.117" }

client/src/client_sync/error.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ use bitcoin::hex;
88
#[derive(Debug)]
99
pub enum Error {
1010
JsonRpc(jsonrpc::error::Error),
11-
HexToArray(hex::HexToArrayError),
12-
HexToBytes(hex::HexToBytesError),
11+
// TODO: Consider renaming these two variants now the inner type changed.
12+
HexToArray(hex::DecodeFixedLengthBytesError),
13+
HexToBytes(hex::DecodeVariableLengthBytesError),
1314
Json(serde_json::error::Error),
1415
BitcoinSerialization(bitcoin::consensus::encode::FromHexError),
1516
Io(io::Error),
@@ -28,12 +29,12 @@ impl From<jsonrpc::error::Error> for Error {
2829
fn from(e: jsonrpc::error::Error) -> Error { Error::JsonRpc(e) }
2930
}
3031

31-
impl From<hex::HexToArrayError> for Error {
32-
fn from(e: hex::HexToArrayError) -> Self { Self::HexToArray(e) }
32+
impl From<hex::DecodeFixedLengthBytesError> for Error {
33+
fn from(e: hex::DecodeFixedLengthBytesError) -> Self { Self::HexToArray(e) }
3334
}
3435

35-
impl From<hex::HexToBytesError> for Error {
36-
fn from(e: hex::HexToBytesError) -> Self { Self::HexToBytes(e) }
36+
impl From<hex::DecodeVariableLengthBytesError> for Error {
37+
fn from(e: hex::DecodeVariableLengthBytesError) -> Self { Self::HexToBytes(e) }
3738
}
3839

3940
impl From<serde_json::error::Error> for Error {

integration_test/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ v17 = ["v18_and_below"]
6161
TODO = [] # This is a dirty hack while writing the tests.
6262

6363
[dependencies]
64-
bitcoin = { version = "0.32.0", default-features = false, features = ["std", "serde"] }
64+
# Branch `corepc`. hex stuff plus RC stuff (#5704, #5657, and #5710)
65+
bitcoin = { version = "0.33.0-beta", path = "../../rust-bitcoin/bitcoin", default-features = false, features = ["std", "serde"] }
66+
hex-unstable = { package = "hex-conservative", version = "0.3.0", default-features = false, features = ["alloc"] }
6567
env_logger = "0.9.0"
6668
node = { package = "corepc-node", version = "0.11.0", path = "../node", default-features = false }
6769
rand = "0.8.5"

integration_test/src/lib.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
use std::path::PathBuf;
44

55
use bitcoin::bip32::{Fingerprint, Xpriv, Xpub};
6-
use bitcoin::secp256k1::{Secp256k1, XOnlyPublicKey};
7-
use bitcoin::Network;
6+
use bitcoin::{Network, XOnlyPublicKey};
87
use node::{Conf, P2P};
98
use rand::distributions::Alphanumeric;
109
use rand::Rng;
@@ -86,7 +85,7 @@ impl NodeExt for Node {
8685
}
8786

8887
fn create_mempool_transaction(&self) -> (bitcoin::Address, bitcoin::Txid) {
89-
const MILLION_SATS: bitcoin::Amount = bitcoin::Amount::from_sat(1000000);
88+
const MILLION_SATS: bitcoin::Amount = bitcoin::Amount::from_sat_u32(1000000);
9089

9190
let address = self.client.new_address().expect("failed to get new address");
9291

@@ -105,7 +104,8 @@ impl NodeExt for Node {
105104

106105
let best_block_hash = self.client.best_block_hash().expect("best_block_hash");
107106
let best_block = self.client.get_block(best_block_hash).expect("best_block");
108-
let tx = best_block.txdata[1].clone();
107+
108+
let tx = best_block.assume_checked(None).transactions()[1].clone();
109109

110110
(address, tx)
111111
}
@@ -162,14 +162,13 @@ pub struct TestKeys {
162162

163163
/// Returns deterministic test keys derived from a zero seed.
164164
pub fn test_keys() -> TestKeys {
165-
let secp = Secp256k1::new();
166165
let seed = [0u8; 32];
167-
let xprv = Xpriv::new_master(Network::Regtest, &seed).unwrap();
168-
let xpub = Xpub::from_priv(&secp, &xprv);
166+
let xprv = Xpriv::new_master(Network::Regtest, &seed);
167+
let xpub = Xpub::from_xpriv(&xprv);
169168
TestKeys {
170169
xprv,
171170
xpub,
172171
fingerprint: xpub.fingerprint(),
173-
x_only_public_key: xprv.private_key.x_only_public_key(&secp).0,
172+
x_only_public_key: xprv.private_key.x_only_public_key().0.into(),
174173
}
175174
}

integration_test/tests/blockchain.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#![allow(non_snake_case)] // Test names intentionally use double underscore.
66

77
use bitcoin::consensus::encode;
8+
#[allow(unused_imports)] // Because of feature gated tests.
9+
use bitcoin::ext::*;
810
use bitcoin::hex;
911
use integration_test::{Node, NodeExt as _, Wallet};
1012
use node::vtype::*; // All the version specific types.
@@ -39,7 +41,8 @@ fn blockchain__get_best_block_hash__modelled() {
3941
let node = Node::with_wallet(Wallet::None, &[]);
4042

4143
let json: GetBestBlockHash = node.client.get_best_block_hash().expect("getbestblockhash");
42-
let model: Result<mtype::GetBestBlockHash, hex::HexToArrayError> = json.into_model();
44+
let model: Result<mtype::GetBestBlockHash, hex::DecodeFixedLengthBytesError> =
45+
json.into_model();
4346
model.unwrap();
4447
}
4548

@@ -79,8 +82,8 @@ fn blockchain__get_block__modelled() {
7982
.find(|entry| entry.transaction.transaction.compute_txid() == mined_txid)
8083
.expect("mined transaction should be present in verbosity=2 results");
8184
assert!(mined_entry.fee.is_some());
82-
assert!(!mined_entry.transaction.transaction.input.is_empty());
83-
assert!(!mined_entry.transaction.transaction.output.is_empty());
85+
assert!(!mined_entry.transaction.transaction.inputs.is_empty());
86+
assert!(!mined_entry.transaction.transaction.outputs.is_empty());
8487

8588
let json: GetBlockVerboseThree =
8689
node.client.get_block_verbose_three(block_hash).expect("getblock verbose=3");
@@ -140,7 +143,6 @@ fn blockchain__get_block_filter__modelled() {
140143
#[test]
141144
#[cfg(not(feature = "v22_and_below"))]
142145
fn blockchain__get_block_from_peer() {
143-
use bitcoin::hashes::Hash;
144146
let (node1, _node2, _node3) = integration_test::three_node_network();
145147

146148
let now = std::time::SystemTime::now()
@@ -152,8 +154,8 @@ fn blockchain__get_block_from_peer() {
152154
let mut header = bitcoin::block::Header {
153155
version: bitcoin::block::Version::from_consensus(0x20000000),
154156
prev_blockhash: node1.client.best_block_hash().expect("best_block_hash failed"),
155-
merkle_root: bitcoin::TxMerkleNode::all_zeros(),
156-
time: now,
157+
merkle_root: bitcoin::TxMerkleNode::from_byte_array([0_u8; 32]),
158+
time: bitcoin::BlockTime::from_u32(now),
157159
bits: bitcoin::CompactTarget::from_consensus(0x207fffff),
158160
nonce: 0,
159161
};
@@ -173,7 +175,7 @@ fn blockchain__get_block_hash__modelled() {
173175
let node = Node::with_wallet(Wallet::None, &[]);
174176

175177
let json: GetBlockHash = node.client.get_block_hash(0).expect("getblockhash");
176-
let model: Result<mtype::GetBlockHash, hex::HexToArrayError> = json.into_model();
178+
let model: Result<mtype::GetBlockHash, hex::DecodeFixedLengthBytesError> = json.into_model();
177179
model.unwrap();
178180
}
179181

@@ -349,7 +351,8 @@ fn blockchain__get_mempool_ancestors__modelled() {
349351

350352
let json: GetMempoolAncestors =
351353
node.client.get_mempool_ancestors(child_txid).expect("getmempoolancestors");
352-
let model: Result<mtype::GetMempoolAncestors, hex::HexToArrayError> = json.into_model();
354+
let model: Result<mtype::GetMempoolAncestors, hex::DecodeFixedLengthBytesError> =
355+
json.into_model();
353356
let ancestors = model.unwrap();
354357

355358
assert!(ancestors.0.contains(&parent_txid));
@@ -379,7 +382,8 @@ fn blockchain__get_mempool_descendants__modelled() {
379382

380383
let json: GetMempoolDescendants =
381384
node.client.get_mempool_descendants(parent_txid).expect("getmempooldescendants");
382-
let model: Result<mtype::GetMempoolDescendants, hex::HexToArrayError> = json.into_model();
385+
let model: Result<mtype::GetMempoolDescendants, hex::DecodeFixedLengthBytesError> =
386+
json.into_model();
383387
let descendants = model.unwrap();
384388

385389
assert!(descendants.0.contains(&child_txid));
@@ -436,7 +440,8 @@ fn blockchain__get_raw_mempool__modelled() {
436440

437441
// verbose = false + mempool_sequence = false
438442
let json: GetRawMempool = node.client.get_raw_mempool().expect("getrawmempool");
439-
let model: Result<mtype::GetRawMempool, hex::HexToArrayError> = json.clone().into_model();
443+
let model: Result<mtype::GetRawMempool, hex::DecodeFixedLengthBytesError> =
444+
json.clone().into_model();
440445
let mempool = model.unwrap();
441446
// Sanity check.
442447
assert_eq!(mempool.0.len(), 1);
@@ -454,7 +459,8 @@ fn blockchain__get_raw_mempool__modelled() {
454459
// verbose = false + mempool_sequence = true
455460
let json: GetRawMempoolSequence =
456461
node.client.get_raw_mempool_sequence().expect("getrawmempool sequence");
457-
let model: Result<mtype::GetRawMempoolSequence, hex::HexToArrayError> = json.into_model();
462+
let model: Result<mtype::GetRawMempoolSequence, hex::DecodeFixedLengthBytesError> =
463+
json.into_model();
458464
let mempool = model.unwrap();
459465
// Sanity check.
460466
assert_eq!(mempool.txids.len(), 1);
@@ -646,7 +652,8 @@ fn blockchain__verify_tx_out_proof__modelled() {
646652
let proof = node.client.get_tx_out_proof(&[txid]).expect("gettxoutproof");
647653

648654
let json: VerifyTxOutProof = node.client.verify_tx_out_proof(&proof).expect("verifytxoutproof");
649-
let model: Result<mtype::VerifyTxOutProof, hex::HexToArrayError> = json.into_model();
655+
let model: Result<mtype::VerifyTxOutProof, hex::DecodeFixedLengthBytesError> =
656+
json.into_model();
650657
let txids = model.unwrap();
651658

652659
// sanity check
@@ -713,7 +720,7 @@ fn blockchain__wait_for_new_block__modelled() {
713720
fn create_child_spending_parent(node: &Node, parent_txid: bitcoin::Txid) -> bitcoin::Txid {
714721
let inputs = vec![Input { txid: parent_txid, vout: 0, sequence: None }];
715722
let spend_address = node.client.new_address().expect("newaddress");
716-
let outputs = vec![Output::new(spend_address, bitcoin::Amount::from_sat(100_000))];
723+
let outputs = vec![Output::new(spend_address, bitcoin::Amount::from_sat_u32(100_000))];
717724

718725
let raw: CreateRawTransaction =
719726
node.client.create_raw_transaction(&inputs, &outputs).expect("createrawtransaction");

integration_test/tests/generating.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn generating__generate_block__modelled() {
1616
node.fund_wallet();
1717
let mining_addr = node.client.new_address().expect("failed to get new address");
1818
let dest_addr = node.client.new_address().expect("failed to get new address");
19-
let amount = bitcoin::Amount::from_sat(1_000_000);
19+
let amount = bitcoin::Amount::from_sat_u32(1_000_000);
2020
let txid = node
2121
.client
2222
.send_to_address_rbf(&dest_addr, amount)
@@ -33,7 +33,8 @@ fn generating__generate_block__modelled() {
3333
.client
3434
.generate_block(&mining_addr.to_string(), &transactions)
3535
.expect("generateblock");
36-
let model: Result<mtype::GenerateBlock, hex::HexToArrayError> = json.into_model();
36+
let model: Result<mtype::GenerateBlock, hex::DecodeFixedLengthBytesError> =
37+
json.into_model();
3738
model.unwrap();
3839
}
3940

@@ -57,7 +58,7 @@ fn generating__generate__modelled() {
5758

5859
let json: Generate = node.client.generate(NBLOCKS).expect("generate");
5960

60-
let model: Result<mtype::Generate, hex::HexToArrayError> = json.into_model();
61+
let model: Result<mtype::Generate, hex::DecodeFixedLengthBytesError> = json.into_model();
6162
model.unwrap();
6263
}
6364

@@ -71,7 +72,8 @@ fn generating__generate_to_address__modelled() {
7172
let json: GenerateToAddress =
7273
node.client.generate_to_address(NBLOCKS, &address).expect("generatetoaddress");
7374

74-
let model: Result<mtype::GenerateToAddress, hex::HexToArrayError> = json.into_model();
75+
let model: Result<mtype::GenerateToAddress, hex::DecodeFixedLengthBytesError> =
76+
json.into_model();
7577
model.unwrap();
7678
}
7779

@@ -86,7 +88,8 @@ fn generating__generate_to_descriptor__modelled() {
8688

8789
let json: GenerateToDescriptor =
8890
node.client.generate_to_descriptor(NBLOCKS, &descriptor).expect("generatetodescriptor");
89-
let model: Result<mtype::GenerateToDescriptor, hex::HexToArrayError> = json.into_model();
91+
let model: Result<mtype::GenerateToDescriptor, hex::DecodeFixedLengthBytesError> =
92+
json.into_model();
9093
model.unwrap();
9194
}
9295

@@ -113,7 +116,8 @@ fn generating__invalidate_block() {
113116
node.client.invalidate_block(new_best_block).expect("invalidateblock");
114117

115118
let json: GetBestBlockHash = node.client.get_best_block_hash().expect("getbestblockhash");
116-
let model: Result<mtype::GetBestBlockHash, hex::HexToArrayError> = json.into_model();
119+
let model: Result<mtype::GetBestBlockHash, hex::DecodeFixedLengthBytesError> =
120+
json.into_model();
117121
let best_block = model.unwrap();
118122

119123
assert_eq!(old_best_block, best_block.0);

integration_test/tests/hidden.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
#[cfg(not(feature = "v28_and_below"))]
88
use std::collections::HashMap;
99

10-
#[cfg(not(feature = "v28_and_below"))]
11-
use bitcoin::hashes::Hash;
12-
#[cfg(not(feature = "v28_and_below"))]
13-
use bitcoin::hex::DisplayHex;
10+
#[allow(unused_imports)] // Because of feature gated tests.
11+
use bitcoin::ext::*;
1412
#[cfg(not(feature = "v28_and_below"))]
1513
use bitcoin::{
16-
absolute, consensus, transaction, Amount, OutPoint, ScriptBuf, Sequence, Transaction, TxIn,
14+
absolute, consensus, transaction, Amount, OutPoint, ScriptSigBuf, Sequence, Transaction, TxIn,
1715
TxOut, Txid, Witness,
1816
};
17+
#[cfg(not(feature = "v28_and_below"))]
18+
use hex_unstable::DisplayHex;
1919
use integration_test::{Node, NodeExt as _, Wallet};
2020
use node::mtype;
2121
use node::vtype::*; // All the version specific types.
@@ -110,17 +110,14 @@ fn hidden__get_orphan_txs__modelled() {
110110
.map(|i| Transaction {
111111
version: transaction::Version::ONE,
112112
lock_time: absolute::LockTime::ZERO,
113-
input: vec![TxIn {
114-
previous_output: OutPoint {
115-
txid: Txid::from_raw_hash(Txid::from_byte_array([i; 32]).into()),
116-
vout: 0,
117-
},
118-
script_sig: ScriptBuf::new(),
113+
inputs: vec![TxIn {
114+
previous_output: OutPoint { txid: Txid::from_byte_array([i; 32]), vout: 0 },
115+
script_sig: ScriptSigBuf::new(),
119116
sequence: Sequence::MAX,
120117
witness: Witness::new(),
121118
}],
122-
output: vec![TxOut {
123-
value: Amount::from_sat(100_000),
119+
outputs: vec![TxOut {
120+
amount: Amount::from_sat_u32(100_000),
124121
script_pubkey: address.script_pubkey(),
125122
}],
126123
})

0 commit comments

Comments
 (0)