From 3a3446a4d48b15b59c86426b94737b016c9e615d Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 30 Apr 2024 07:46:45 +1000 Subject: [PATCH] Depend on bitcoin v0.32.0 Depend on the latest release of `rust-bitcoin`. --- Cargo-minimal.lock | 88 +++++++++++++++++++++++----- Cargo-recent.lock | 88 +++++++++++++++++++++++----- client/examples/test_against_node.rs | 5 +- client/src/client.rs | 13 ++-- client/src/error.rs | 6 +- client/src/lib.rs | 14 ----- client/src/queryable.rs | 6 +- integration_test/Cargo.toml | 2 +- integration_test/src/main.rs | 22 +++---- json/Cargo.toml | 3 +- 10 files changed, 177 insertions(+), 70 deletions(-) diff --git a/Cargo-minimal.lock b/Cargo-minimal.lock index ee88a8ee..762f15b9 100644 --- a/Cargo-minimal.lock +++ b/Cargo-minimal.lock @@ -2,12 +2,28 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "autocfg" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +[[package]] +name = "base58ck" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f" +dependencies = [ + "bitcoin-internals 0.3.0", + "bitcoin_hashes 0.14.0", +] + [[package]] name = "base64" version = "0.13.1" @@ -16,20 +32,23 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "bech32" -version = "0.10.0-beta" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98f7eed2b2781a6f0b5c903471d48e15f56fb4e1165df8a9a2337fd1a59d45ea" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" [[package]] name = "bitcoin" -version = "0.31.2" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c85783c2fe40083ea54a33aa2f0ba58831d90fcd190f5bdc47e74e84d2a96ae" +checksum = "7170e7750a20974246f17ece04311b4205a6155f1db564c5b224af817663c3ea" dependencies = [ + "base58ck", "bech32", - "bitcoin-internals", - "bitcoin_hashes", - "hex-conservative", + "bitcoin-internals 0.3.0", + "bitcoin-io", + "bitcoin-units", + "bitcoin_hashes 0.14.0", + "hex-conservative 0.2.0", "hex_lit", "secp256k1", "serde", @@ -40,7 +59,29 @@ name = "bitcoin-internals" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9425c3bf7089c983facbae04de54513cce73b41c7f9ff8c845b54e7bc64ebbfb" + +[[package]] +name = "bitcoin-internals" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2" +dependencies = [ + "serde", +] + +[[package]] +name = "bitcoin-io" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "340e09e8399c7bd8912f495af6aa58bea0c9214773417ffaa8f6460f93aaee56" + +[[package]] +name = "bitcoin-units" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb54da0b28892f3c52203a7191534033e051b6f4b52bc15480681b57b7e036f5" dependencies = [ + "bitcoin-internals 0.3.0", "serde", ] @@ -50,8 +91,18 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1930a4dabfebb8d7d9992db18ebe3ae2876f0a305fab206fd168df931ede293b" dependencies = [ - "bitcoin-internals", - "hex-conservative", + "bitcoin-internals 0.2.0", + "hex-conservative 0.1.1", +] + +[[package]] +name = "bitcoin_hashes" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" +dependencies = [ + "bitcoin-io", + "hex-conservative 0.2.0", "serde", ] @@ -136,6 +187,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30ed443af458ccb6d81c1e7e661545f94d3176752fb1df2f543b902a1e0f51e2" +[[package]] +name = "hex-conservative" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1aa273bf451e37ed35ced41c71a5e2a4e29064afb104158f2514bcd71c2c986" +dependencies = [ + "arrayvec", +] + [[package]] name = "hex_lit" version = "0.1.1" @@ -298,11 +358,11 @@ checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" [[package]] name = "secp256k1" -version = "0.28.2" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24b59d129cdadea20aea4fb2352fa053712e5d713eee47d700cd4b2bc002f10" +checksum = "0e0cc0f1cf93f4969faf3ea1c7d8a9faed25918d96affa959720823dfe86d4f3" dependencies = [ - "bitcoin_hashes", + "bitcoin_hashes 0.13.0", "rand", "secp256k1-sys", "serde", @@ -310,9 +370,9 @@ dependencies = [ [[package]] name = "secp256k1-sys" -version = "0.9.2" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d1746aae42c19d583c3c1a8c646bfad910498e2051c551a7f2e3c0c9fbb7eb" +checksum = "1433bd67156263443f14d603720b082dd3121779323fce20cba2aa07b874bc1b" dependencies = [ "cc", ] diff --git a/Cargo-recent.lock b/Cargo-recent.lock index ee88a8ee..762f15b9 100644 --- a/Cargo-recent.lock +++ b/Cargo-recent.lock @@ -2,12 +2,28 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "autocfg" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +[[package]] +name = "base58ck" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f" +dependencies = [ + "bitcoin-internals 0.3.0", + "bitcoin_hashes 0.14.0", +] + [[package]] name = "base64" version = "0.13.1" @@ -16,20 +32,23 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "bech32" -version = "0.10.0-beta" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98f7eed2b2781a6f0b5c903471d48e15f56fb4e1165df8a9a2337fd1a59d45ea" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" [[package]] name = "bitcoin" -version = "0.31.2" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c85783c2fe40083ea54a33aa2f0ba58831d90fcd190f5bdc47e74e84d2a96ae" +checksum = "7170e7750a20974246f17ece04311b4205a6155f1db564c5b224af817663c3ea" dependencies = [ + "base58ck", "bech32", - "bitcoin-internals", - "bitcoin_hashes", - "hex-conservative", + "bitcoin-internals 0.3.0", + "bitcoin-io", + "bitcoin-units", + "bitcoin_hashes 0.14.0", + "hex-conservative 0.2.0", "hex_lit", "secp256k1", "serde", @@ -40,7 +59,29 @@ name = "bitcoin-internals" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9425c3bf7089c983facbae04de54513cce73b41c7f9ff8c845b54e7bc64ebbfb" + +[[package]] +name = "bitcoin-internals" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2" +dependencies = [ + "serde", +] + +[[package]] +name = "bitcoin-io" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "340e09e8399c7bd8912f495af6aa58bea0c9214773417ffaa8f6460f93aaee56" + +[[package]] +name = "bitcoin-units" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb54da0b28892f3c52203a7191534033e051b6f4b52bc15480681b57b7e036f5" dependencies = [ + "bitcoin-internals 0.3.0", "serde", ] @@ -50,8 +91,18 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1930a4dabfebb8d7d9992db18ebe3ae2876f0a305fab206fd168df931ede293b" dependencies = [ - "bitcoin-internals", - "hex-conservative", + "bitcoin-internals 0.2.0", + "hex-conservative 0.1.1", +] + +[[package]] +name = "bitcoin_hashes" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" +dependencies = [ + "bitcoin-io", + "hex-conservative 0.2.0", "serde", ] @@ -136,6 +187,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30ed443af458ccb6d81c1e7e661545f94d3176752fb1df2f543b902a1e0f51e2" +[[package]] +name = "hex-conservative" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1aa273bf451e37ed35ced41c71a5e2a4e29064afb104158f2514bcd71c2c986" +dependencies = [ + "arrayvec", +] + [[package]] name = "hex_lit" version = "0.1.1" @@ -298,11 +358,11 @@ checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" [[package]] name = "secp256k1" -version = "0.28.2" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24b59d129cdadea20aea4fb2352fa053712e5d713eee47d700cd4b2bc002f10" +checksum = "0e0cc0f1cf93f4969faf3ea1c7d8a9faed25918d96affa959720823dfe86d4f3" dependencies = [ - "bitcoin_hashes", + "bitcoin_hashes 0.13.0", "rand", "secp256k1-sys", "serde", @@ -310,9 +370,9 @@ dependencies = [ [[package]] name = "secp256k1-sys" -version = "0.9.2" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d1746aae42c19d583c3c1a8c646bfad910498e2051c551a7f2e3c0c9fbb7eb" +checksum = "1433bd67156263443f14d603720b082dd3121779323fce20cba2aa07b874bc1b" dependencies = [ "cc", ] diff --git a/client/examples/test_against_node.rs b/client/examples/test_against_node.rs index e658e781..1a68196f 100644 --- a/client/examples/test_against_node.rs +++ b/client/examples/test_against_node.rs @@ -37,8 +37,9 @@ 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(()) } diff --git a/client/src/client.rs b/client/src/client.rs index 206668a0..c97a0174 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -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; @@ -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) } } @@ -333,7 +334,7 @@ pub trait RpcApi: Sized { fn get_block(&self, hash: &bitcoin::BlockHash) -> Result { 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 { @@ -347,7 +348,7 @@ pub trait RpcApi: Sized { fn get_block_header(&self, hash: &bitcoin::BlockHash) -> Result { let hex: String = self.call("getblockheader", &[into_json(hash)?, false.into()])?; - deserialize_hex(&hex) + Ok(encode::deserialize_hex(&hex)?) } fn get_block_header_info( @@ -491,7 +492,7 @@ pub trait RpcApi: Sized { ) -> Result { 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( @@ -788,7 +789,7 @@ pub trait RpcApi: Sized { replaceable: Option, ) -> Result { let hex: String = self.create_raw_transaction_hex(utxos, outs, locktime, replaceable)?; - deserialize_hex(&hex) + Ok(encode::deserialize_hex(&hex)?) } fn decode_raw_transaction( diff --git a/client/src/error.rs b/client/src/error.rs index 3a6b6961..02a04d52 100644 --- a/client/src/error.rs +++ b/client/src/error.rs @@ -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), @@ -51,8 +51,8 @@ impl From for Error { } } -impl From for Error { - fn from(e: bitcoin::consensus::encode::Error) -> Error { +impl From for Error { + fn from(e: bitcoin::consensus::encode::FromHexError) -> Error { Error::BitcoinSerialization(e) } } diff --git a/client/src/lib.rs b/client/src/lib.rs index c3c7b420..abcffe0d 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -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; @@ -37,15 +35,3 @@ mod queryable; pub use crate::client::*; pub use crate::error::Error; pub use crate::queryable::*; - -fn deserialize_hex(hex: &str) -> Result { - 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) - } -} diff --git a/client/src/queryable.rs b/client/src/queryable.rs index 696a37d2..6052f7e8 100644 --- a/client/src/queryable.rs +++ b/client/src/queryable.rs @@ -28,8 +28,7 @@ impl Queryable for bitcoin::block::Block { fn query(rpc: &C, id: &Self::Id) -> Result { let rpc_name = "getblock"; let hex: String = rpc.call(rpc_name, &[serde_json::to_value(id)?, 0.into()])?; - let bytes: Vec = bitcoin::hashes::hex::FromHex::from_hex(&hex)?; - Ok(bitcoin::consensus::encode::deserialize(&bytes)?) + Ok(bitcoin::consensus::encode::deserialize_hex(&hex)?) } } @@ -39,8 +38,7 @@ impl Queryable for bitcoin::transaction::Transaction { fn query(rpc: &C, id: &Self::Id) -> Result { let rpc_name = "getrawtransaction"; let hex: String = rpc.call(rpc_name, &[serde_json::to_value(id)?])?; - let bytes: Vec = bitcoin::hashes::hex::FromHex::from_hex(&hex)?; - Ok(bitcoin::consensus::encode::deserialize(&bytes)?) + Ok(bitcoin::consensus::encode::deserialize_hex(&hex)?) } } diff --git a/integration_test/Cargo.toml b/integration_test/Cargo.toml index d7ba0c08..7cec049e 100644 --- a/integration_test/Cargo.toml +++ b/integration_test/Cargo.toml @@ -6,6 +6,6 @@ edition = "2018" [dependencies] bitcoincore-rpc = { path = "../client" } -bitcoin = { version = "0.31.0", features = ["serde", "rand"]} +bitcoin = { version = "0.32.0", features = ["serde", "rand"] } lazy_static = "1.4.0" log = "0.4" diff --git a/integration_test/src/main.rs b/integration_test/src/main.rs index c1d42cf1..c3236bb9 100644 --- a/integration_test/src/main.rs +++ b/integration_test/src/main.rs @@ -28,8 +28,8 @@ 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, TxIn, TxOut, Txid, Witness, + transaction, Address, Amount, CompressedPublicKey, Network, OutPoint, PrivateKey, Sequence, + SignedAmount, Transaction, TxIn, TxOut, Txid, Witness, }; use bitcoincore_rpc::bitcoincore_rpc_json::{ GetBlockTemplateModes, GetBlockTemplateRules, GetZmqNotificationsResult, ScanTxOutRequest, @@ -268,7 +268,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) { @@ -571,11 +572,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)), @@ -694,7 +696,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); @@ -984,7 +986,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, }; @@ -995,7 +997,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, }; @@ -1006,7 +1008,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, }; @@ -1018,7 +1020,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, }; diff --git a/json/Cargo.toml b/json/Cargo.toml index 0bb6b4d6..0150c632 100644 --- a/json/Cargo.toml +++ b/json/Cargo.toml @@ -23,5 +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", features = ["serde", "rand-std"] }