Skip to content

Commit

Permalink
Bump bitcoin to 0.32
Browse files Browse the repository at this point in the history
  • Loading branch information
yaziciahmet committed Aug 13, 2024
1 parent 5527a8d commit c27037a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions client/examples/test_against_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ async fn main_result() -> Result<(), Error> {

let bitcoin_block: bitcoin::Block = rpc.get_by_id(&best_block_hash).await?;
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()).await?;
println!("tx by `get`: {}", bitcoin_tx.txid());
let bitcoin_tx: bitcoin::Transaction = rpc.get_by_id(&bitcoin_block.txdata[0].compute_txid()).await?;
println!("tx by `get`: {}", bitcoin_tx.compute_txid());

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ pub extern crate jsonrpc_async;

pub extern crate bitcoincore_rpc_json;
pub use crate::json::bitcoin;
use bitcoincore_rpc_json::bitcoin::io::Cursor;
pub use bitcoincore_rpc_json as json;
use json::bitcoin::consensus::{Decodable, ReadExt};
use json::bitcoin::hex::HexToBytesIter;

mod client;
mod error;
Expand All @@ -39,7 +39,7 @@ pub use crate::error::Error;
pub use crate::queryable::*;

fn deserialize_hex<T: Decodable>(hex: &str) -> Result<T> {
let mut reader = HexToBytesIter::new(&hex)?;
let mut reader = Cursor::new(hex.as_bytes());
let object = Decodable::consensus_decode(&mut reader)?;
if reader.read_u8().is_ok() {
Err(Error::BitcoinSerialization(bitcoin::consensus::encode::Error::ParseFailed(
Expand Down
2 changes: 1 addition & 1 deletion integration_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"

[dependencies]
bitcoincore-rpc = { path = "../client" }
bitcoin = { version = "0.31.2", features = ["serde", "rand"]}
bitcoin = { version = "0.32.2", features = ["serde", "rand", "rand-std"]}
lazy_static = "1.4.0"
log = "0.4"
tokio = { version = "1", features = ["full"] }
21 changes: 12 additions & 9 deletions integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::json::BlockStatsFields as BsFields;
use bitcoin::consensus::encode::{deserialize, serialize_hex};
use bitcoin::hashes::hex::FromHex;
use bitcoin::hashes::Hash;
use bitcoin::{secp256k1, sighash, ScriptBuf};
use bitcoin::{secp256k1, sighash, CompressedPublicKey, NetworkKind, ScriptBuf};
use bitcoin::{
transaction, Address, Amount, Network, OutPoint, PrivateKey, Sequence, SignedAmount,
Transaction, TxIn, TxOut, Txid, Witness,
Expand Down Expand Up @@ -281,7 +281,8 @@ async fn test_dump_private_key(cl: &Client) {
let addr =
cl.get_new_address(None, Some(json::AddressType::Bech32)).await.unwrap().assume_checked();
let sk = cl.dump_private_key(&addr).await.unwrap();
assert_eq!(addr, Address::p2wpkh(&sk.public_key(&SECP), *NET).unwrap());
let pub_key = CompressedPublicKey::from_private_key(&SECP, &sk).unwrap();
assert_eq!(addr, Address::p2wpkh(&pub_key, *NET));
}

async fn test_generate(cl: &Client) {
Expand Down Expand Up @@ -633,11 +634,13 @@ async fn test_get_block_filter(cl: &Client) {

async fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) {
let sk = PrivateKey {
network: Network::Regtest,
network: NetworkKind::Test,
inner: secp256k1::SecretKey::new(&mut secp256k1::rand::thread_rng()),
compressed: true,
};
let addr = Address::p2wpkh(&sk.public_key(&SECP), Network::Regtest).unwrap();

let pub_key = CompressedPublicKey::from_private_key(&SECP, &sk).unwrap();
let addr = Address::p2wpkh(&pub_key, Network::Regtest);

let options = json::ListUnspentQueryOptions {
minimum_amount: Some(btc(2)),
Expand Down Expand Up @@ -768,7 +771,7 @@ async fn test_decode_raw_transaction(cl: &Client) {

let decoded_transaction = cl.decode_raw_transaction(hex, None).await.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);
Expand Down Expand Up @@ -1070,7 +1073,7 @@ async fn test_list_received_by_address(cl: &Client) {

async fn test_import_public_key(cl: &Client) {
let sk = PrivateKey {
network: Network::Regtest,
network: NetworkKind::Test,
inner: secp256k1::SecretKey::new(&mut secp256k1::rand::thread_rng()),
compressed: true,
};
Expand All @@ -1081,7 +1084,7 @@ async fn test_import_public_key(cl: &Client) {

async fn test_import_priv_key(cl: &Client) {
let sk = PrivateKey {
network: Network::Regtest,
network: NetworkKind::Test,
inner: secp256k1::SecretKey::new(&mut secp256k1::rand::thread_rng()),
compressed: true,
};
Expand All @@ -1092,7 +1095,7 @@ async fn test_import_priv_key(cl: &Client) {

async fn test_import_address(cl: &Client) {
let sk = PrivateKey {
network: Network::Regtest,
network: NetworkKind::Test,
inner: secp256k1::SecretKey::new(&mut secp256k1::rand::thread_rng()),
compressed: true,
};
Expand All @@ -1104,7 +1107,7 @@ async fn test_import_address(cl: &Client) {

async fn test_import_address_script(cl: &Client) {
let sk = PrivateKey {
network: Network::Regtest,
network: NetworkKind::Test,
inner: secp256k1::SecretKey::new(&mut secp256k1::rand::thread_rng()),
compressed: true,
};
Expand Down
2 changes: 1 addition & 1 deletion json/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ path = "src/lib.rs"
serde = { version = "1", features = [ "derive" ] }
serde_json = "1"

bitcoin = { version = "0.31.2", features = ["serde", "rand-std"]}
bitcoin = { version = "0.32.2", features = ["serde"]}
2 changes: 1 addition & 1 deletion json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use bitcoin::consensus::encode;
use bitcoin::hashes::hex::FromHex;
use bitcoin::hashes::sha256;
use bitcoin::{
bip158, bip32, Address, Amount, CompactTarget, Network, PrivateKey, PublicKey, Script,
bip158, bip32, Address, Amount, Network, PrivateKey, PublicKey, Script,
ScriptBuf, SignedAmount, Transaction,
};
use serde::de::Error as SerdeError;
Expand Down

0 comments on commit c27037a

Please sign in to comment.