diff --git a/Cargo.toml b/Cargo.toml index df0a30c2..9caf95fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,3 +5,21 @@ members = [ "client", "integration_test", ] + +[patch.crates-io.base58check] +path = "/home/tobin/build/github.com/tcharding/rust-bitcoin/release/base58" + +[patch.crates-io.bitcoin] +path = "/home/tobin/build/github.com/tcharding/rust-bitcoin/release/bitcoin" + +[patch.crates-io.bitcoin_hashes] +path = "/home/tobin/build/github.com/tcharding/rust-bitcoin/release/hashes" + +[patch.crates-io.bitcoin-internals] +path = "/home/tobin/build/github.com/tcharding/rust-bitcoin/release/internals" + +[patch.crates-io.bitcoin-io] +path = "/home/tobin/build/github.com/tcharding/rust-bitcoin/release/io" + +[patch.crates-io.bitcoin-units] +path = "/home/tobin/build/github.com/tcharding/rust-bitcoin/release/units" diff --git a/client/examples/test_against_node.rs b/client/examples/test_against_node.rs index e658e781..bf698adb 100644 --- a/client/examples/test_against_node.rs +++ b/client/examples/test_against_node.rs @@ -37,8 +37,8 @@ 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 faea7490..859a535b 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/src/main.rs b/integration_test/src/main.rs index 7c439619..51176bc5 100644 --- a/integration_test/src/main.rs +++ b/integration_test/src/main.rs @@ -28,7 +28,7 @@ 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, Address, Amount, CompressedPublicKey, Network, OutPoint, PrivateKey, Sequence, SignedAmount, Transaction, TxIn, TxOut, Txid, Witness, }; use bitcoincore_rpc::bitcoincore_rpc_json::{ @@ -267,7 +267,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) { @@ -570,11 +571,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)), @@ -693,7 +695,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); @@ -983,7 +985,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, }; @@ -994,7 +996,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, }; @@ -1005,7 +1007,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, }; @@ -1017,7 +1019,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, };