Skip to content
Draft
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

Cargo.lock
**/target

# The Claude config directory
.claude
3 changes: 2 additions & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ rustdoc-args = ["--cfg", "docsrs"]
client-sync = ["jsonrpc"]

[dependencies]
bitcoin = { version = "0.32.0", default-features = false, features = ["std", "serde"] }
# Branch `corepc`. hex stuff plus RC stuff (#5704, #5657, and #5710)
bitcoin = { version = "0.33.0-beta", path = "../../rust-bitcoin/bitcoin", default-features = false, features = ["std", "serde"] }
log = "0.4"
serde = { version = "1.0.103", default-features = false, features = [ "derive", "alloc" ] }
serde_json = { version = "1.0.117" }
Expand Down
13 changes: 7 additions & 6 deletions client/src/client_sync/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use bitcoin::hex;
#[derive(Debug)]
pub enum Error {
JsonRpc(jsonrpc::error::Error),
HexToArray(hex::HexToArrayError),
HexToBytes(hex::HexToBytesError),
// TODO: Consider renaming these two variants now the inner type changed.
HexToArray(hex::DecodeFixedLengthBytesError),
HexToBytes(hex::DecodeVariableLengthBytesError),
Json(serde_json::error::Error),
BitcoinSerialization(bitcoin::consensus::encode::FromHexError),
Io(io::Error),
Expand All @@ -28,12 +29,12 @@ impl From<jsonrpc::error::Error> for Error {
fn from(e: jsonrpc::error::Error) -> Error { Error::JsonRpc(e) }
}

impl From<hex::HexToArrayError> for Error {
fn from(e: hex::HexToArrayError) -> Self { Self::HexToArray(e) }
impl From<hex::DecodeFixedLengthBytesError> for Error {
fn from(e: hex::DecodeFixedLengthBytesError) -> Self { Self::HexToArray(e) }
}

impl From<hex::HexToBytesError> for Error {
fn from(e: hex::HexToBytesError) -> Self { Self::HexToBytes(e) }
impl From<hex::DecodeVariableLengthBytesError> for Error {
fn from(e: hex::DecodeVariableLengthBytesError) -> Self { Self::HexToBytes(e) }
}

impl From<serde_json::error::Error> for Error {
Expand Down
4 changes: 3 additions & 1 deletion integration_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ v17 = ["v18_and_below"]
TODO = [] # This is a dirty hack while writing the tests.

[dependencies]
bitcoin = { version = "0.32.0", default-features = false, features = ["std", "serde"] }
# Branch `corepc`. hex stuff plus RC stuff (#5704, #5657, and #5710)
bitcoin = { version = "0.33.0-beta", path = "../../rust-bitcoin/bitcoin", default-features = false, features = ["std", "serde"] }
hex-unstable = { package = "hex-conservative", version = "0.3.0", default-features = false, features = ["alloc"] }
env_logger = "0.9.0"
node = { package = "corepc-node", version = "0.11.0", path = "../node", default-features = false }
rand = "0.8.5"
Expand Down
15 changes: 7 additions & 8 deletions integration_test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use std::path::PathBuf;

use bitcoin::bip32::{Fingerprint, Xpriv, Xpub};
use bitcoin::secp256k1::{Secp256k1, XOnlyPublicKey};
use bitcoin::Network;
use bitcoin::{Network, XOnlyPublicKey};
use node::{Conf, P2P};
use rand::distributions::Alphanumeric;
use rand::Rng;
Expand Down Expand Up @@ -86,7 +85,7 @@ impl NodeExt for Node {
}

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

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

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

let best_block_hash = self.client.best_block_hash().expect("best_block_hash");
let best_block = self.client.get_block(best_block_hash).expect("best_block");
let tx = best_block.txdata[1].clone();

let tx = best_block.assume_checked(None).transactions()[1].clone();

(address, tx)
}
Expand Down Expand Up @@ -162,14 +162,13 @@ pub struct TestKeys {

/// Returns deterministic test keys derived from a zero seed.
pub fn test_keys() -> TestKeys {
let secp = Secp256k1::new();
let seed = [0u8; 32];
let xprv = Xpriv::new_master(Network::Regtest, &seed).unwrap();
let xpub = Xpub::from_priv(&secp, &xprv);
let xprv = Xpriv::new_master(Network::Regtest, &seed);
let xpub = Xpub::from_xpriv(&xprv);
TestKeys {
xprv,
xpub,
fingerprint: xpub.fingerprint(),
x_only_public_key: xprv.private_key.x_only_public_key(&secp).0,
x_only_public_key: xprv.private_key.x_only_public_key().0.into(),
}
}
33 changes: 20 additions & 13 deletions integration_test/tests/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#![allow(non_snake_case)] // Test names intentionally use double underscore.

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

let json: GetBestBlockHash = node.client.get_best_block_hash().expect("getbestblockhash");
let model: Result<mtype::GetBestBlockHash, hex::HexToArrayError> = json.into_model();
let model: Result<mtype::GetBestBlockHash, hex::DecodeFixedLengthBytesError> =
json.into_model();
model.unwrap();
}

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

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

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

let json: GetBlockHash = node.client.get_block_hash(0).expect("getblockhash");
let model: Result<mtype::GetBlockHash, hex::HexToArrayError> = json.into_model();
let model: Result<mtype::GetBlockHash, hex::DecodeFixedLengthBytesError> = json.into_model();
model.unwrap();
}

Expand Down Expand Up @@ -349,7 +351,8 @@ fn blockchain__get_mempool_ancestors__modelled() {

let json: GetMempoolAncestors =
node.client.get_mempool_ancestors(child_txid).expect("getmempoolancestors");
let model: Result<mtype::GetMempoolAncestors, hex::HexToArrayError> = json.into_model();
let model: Result<mtype::GetMempoolAncestors, hex::DecodeFixedLengthBytesError> =
json.into_model();
let ancestors = model.unwrap();

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

let json: GetMempoolDescendants =
node.client.get_mempool_descendants(parent_txid).expect("getmempooldescendants");
let model: Result<mtype::GetMempoolDescendants, hex::HexToArrayError> = json.into_model();
let model: Result<mtype::GetMempoolDescendants, hex::DecodeFixedLengthBytesError> =
json.into_model();
let descendants = model.unwrap();

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

// verbose = false + mempool_sequence = false
let json: GetRawMempool = node.client.get_raw_mempool().expect("getrawmempool");
let model: Result<mtype::GetRawMempool, hex::HexToArrayError> = json.clone().into_model();
let model: Result<mtype::GetRawMempool, hex::DecodeFixedLengthBytesError> =
json.clone().into_model();
let mempool = model.unwrap();
// Sanity check.
assert_eq!(mempool.0.len(), 1);
Expand All @@ -454,7 +459,8 @@ fn blockchain__get_raw_mempool__modelled() {
// verbose = false + mempool_sequence = true
let json: GetRawMempoolSequence =
node.client.get_raw_mempool_sequence().expect("getrawmempool sequence");
let model: Result<mtype::GetRawMempoolSequence, hex::HexToArrayError> = json.into_model();
let model: Result<mtype::GetRawMempoolSequence, hex::DecodeFixedLengthBytesError> =
json.into_model();
let mempool = model.unwrap();
// Sanity check.
assert_eq!(mempool.txids.len(), 1);
Expand Down Expand Up @@ -646,7 +652,8 @@ fn blockchain__verify_tx_out_proof__modelled() {
let proof = node.client.get_tx_out_proof(&[txid]).expect("gettxoutproof");

let json: VerifyTxOutProof = node.client.verify_tx_out_proof(&proof).expect("verifytxoutproof");
let model: Result<mtype::VerifyTxOutProof, hex::HexToArrayError> = json.into_model();
let model: Result<mtype::VerifyTxOutProof, hex::DecodeFixedLengthBytesError> =
json.into_model();
let txids = model.unwrap();

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

let raw: CreateRawTransaction =
node.client.create_raw_transaction(&inputs, &outputs).expect("createrawtransaction");
Expand Down
16 changes: 10 additions & 6 deletions integration_test/tests/generating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn generating__generate_block__modelled() {
node.fund_wallet();
let mining_addr = node.client.new_address().expect("failed to get new address");
let dest_addr = node.client.new_address().expect("failed to get new address");
let amount = bitcoin::Amount::from_sat(1_000_000);
let amount = bitcoin::Amount::from_sat_u32(1_000_000);
let txid = node
.client
.send_to_address_rbf(&dest_addr, amount)
Expand All @@ -33,7 +33,8 @@ fn generating__generate_block__modelled() {
.client
.generate_block(&mining_addr.to_string(), &transactions)
.expect("generateblock");
let model: Result<mtype::GenerateBlock, hex::HexToArrayError> = json.into_model();
let model: Result<mtype::GenerateBlock, hex::DecodeFixedLengthBytesError> =
json.into_model();
model.unwrap();
}

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

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

let model: Result<mtype::Generate, hex::HexToArrayError> = json.into_model();
let model: Result<mtype::Generate, hex::DecodeFixedLengthBytesError> = json.into_model();
model.unwrap();
}

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

let model: Result<mtype::GenerateToAddress, hex::HexToArrayError> = json.into_model();
let model: Result<mtype::GenerateToAddress, hex::DecodeFixedLengthBytesError> =
json.into_model();
model.unwrap();
}

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

let json: GenerateToDescriptor =
node.client.generate_to_descriptor(NBLOCKS, &descriptor).expect("generatetodescriptor");
let model: Result<mtype::GenerateToDescriptor, hex::HexToArrayError> = json.into_model();
let model: Result<mtype::GenerateToDescriptor, hex::DecodeFixedLengthBytesError> =
json.into_model();
model.unwrap();
}

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

let json: GetBestBlockHash = node.client.get_best_block_hash().expect("getbestblockhash");
let model: Result<mtype::GetBestBlockHash, hex::HexToArrayError> = json.into_model();
let model: Result<mtype::GetBestBlockHash, hex::DecodeFixedLengthBytesError> =
json.into_model();
let best_block = model.unwrap();

assert_eq!(old_best_block, best_block.0);
Expand Down
23 changes: 10 additions & 13 deletions integration_test/tests/hidden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
#[cfg(not(feature = "v28_and_below"))]
use std::collections::HashMap;

#[cfg(not(feature = "v28_and_below"))]
use bitcoin::hashes::Hash;
#[cfg(not(feature = "v28_and_below"))]
use bitcoin::hex::DisplayHex;
#[allow(unused_imports)] // Because of feature gated tests.
use bitcoin::ext::*;
#[cfg(not(feature = "v28_and_below"))]
use bitcoin::{
absolute, consensus, transaction, Amount, OutPoint, ScriptBuf, Sequence, Transaction, TxIn,
absolute, consensus, transaction, Amount, OutPoint, ScriptSigBuf, Sequence, Transaction, TxIn,
TxOut, Txid, Witness,
};
#[cfg(not(feature = "v28_and_below"))]
use hex_unstable::DisplayHex;
use integration_test::{Node, NodeExt as _, Wallet};
use node::mtype;
use node::vtype::*; // All the version specific types.
Expand Down Expand Up @@ -110,17 +110,14 @@ fn hidden__get_orphan_txs__modelled() {
.map(|i| Transaction {
version: transaction::Version::ONE,
lock_time: absolute::LockTime::ZERO,
input: vec![TxIn {
previous_output: OutPoint {
txid: Txid::from_raw_hash(Txid::from_byte_array([i; 32]).into()),
vout: 0,
},
script_sig: ScriptBuf::new(),
inputs: vec![TxIn {
previous_output: OutPoint { txid: Txid::from_byte_array([i; 32]), vout: 0 },
script_sig: ScriptSigBuf::new(),
sequence: Sequence::MAX,
witness: Witness::new(),
}],
output: vec![TxOut {
value: Amount::from_sat(100_000),
outputs: vec![TxOut {
amount: Amount::from_sat_u32(100_000),
script_pubkey: address.script_pubkey(),
}],
})
Expand Down
Loading
Loading