diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index d10df2d..fbf523a 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -56,8 +56,6 @@ jobs: run: | cargo update -p reqwest --precise "0.12.4" cargo update -p minreq --precise "2.13.2" - cargo update -p zstd-sys --precise "2.0.8+zstd.1.5.5" - cargo update -p time --precise "0.3.20" cargo update -p home --precise "0.5.5" cargo update -p url --precise "2.5.0" cargo update -p tokio --precise "1.38.1" @@ -71,7 +69,6 @@ jobs: cargo update -p parking_lot_core --precise "0.9.10" cargo update -p lock_api --precise "0.4.12" - cargo update -p base64ct --precise "1.6.0" # dev-dependency cargo update -p bzip2-sys --precise "0.1.12+1.0.8" # dev-dependency - name: Build run: cargo build --features ${{ matrix.features }} --no-default-features diff --git a/Cargo.toml b/Cargo.toml index f1e85b9..33a4e52 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ tokio = { version = "1", features = ["time"], optional = true } [dev-dependencies] serde_json = "1.0" tokio = { version = "1.20.1", features = ["full"] } -electrsd = { version = "0.28.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_25_0"] } +electrsd = { version = "0.33.0", features = ["legacy", "esplora_a33e97e1", "corepc-node_28_0"] } lazy_static = "1.4.0" [features] diff --git a/README.md b/README.md index 581cb9d..6617859 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,6 @@ To build with the MSRV you will need to pin dependencies as follows: ```shell cargo update -p reqwest --precise "0.12.4" cargo update -p minreq --precise "2.13.2" -cargo update -p zstd-sys --precise "2.0.8+zstd.1.5.5" -cargo update -p time --precise "0.3.20" cargo update -p home --precise "0.5.5" cargo update -p url --precise "2.5.0" cargo update -p tokio --precise "1.38.1" diff --git a/src/lib.rs b/src/lib.rs index ce00211..d8091b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -264,32 +264,29 @@ impl_error!(bitcoin::hex::HexToBytesError, HexToBytes, Error); #[cfg(test)] mod test { use super::*; - use electrsd::{bitcoind, bitcoind::BitcoinD, ElectrsD}; + use electrsd::{corepc_node, ElectrsD}; use lazy_static::lazy_static; use std::env; use tokio::sync::Mutex; #[cfg(all(feature = "blocking", feature = "async"))] use { - bitcoin::hashes::Hash, - bitcoin::Amount, - electrsd::{ - bitcoind::bitcoincore_rpc::json::AddressType, bitcoind::bitcoincore_rpc::RpcApi, - electrum_client::ElectrumApi, - }, + bitcoin::{hashes::Hash, Amount}, + corepc_node::AddressType, + electrsd::electrum_client::ElectrumApi, std::time::Duration, tokio::sync::OnceCell, }; lazy_static! { - static ref BITCOIND: BitcoinD = { + static ref BITCOIND: corepc_node::Node = { let bitcoind_exe = env::var("BITCOIND_EXE") .ok() - .or_else(|| bitcoind::downloaded_exe_path().ok()) + .or_else(|| corepc_node::downloaded_exe_path().ok()) .expect( "you need to provide an env var BITCOIND_EXE or specify a bitcoind version feature", ); - let conf = bitcoind::Conf::default(); - BitcoinD::with_conf(bitcoind_exe, &conf).unwrap() + let conf = corepc_node::Conf::default(); + corepc_node::Node::with_conf(bitcoind_exe, &conf).unwrap() }; static ref ELECTRSD: ElectrsD = { let electrs_exe = env::var("ELECTRS_EXE") @@ -348,7 +345,7 @@ mod test { #[cfg(all(feature = "blocking", feature = "async"))] fn generate_blocks_and_wait(num: usize) { - let cur_height = BITCOIND.client.get_block_count().unwrap(); + let cur_height = BITCOIND.client.get_block_count().unwrap().0; generate_blocks(num); wait_for_block(cur_height as usize + num); } @@ -357,13 +354,9 @@ mod test { fn generate_blocks(num: usize) { let address = BITCOIND .client - .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap() - .assume_checked(); - let _block_hashes = BITCOIND - .client - .generate_to_address(num as u64, &address) + .new_address_with_type(AddressType::Legacy) .unwrap(); + let _block_hashes = BITCOIND.client.generate_to_address(num, &address).unwrap(); } #[cfg(all(feature = "blocking", feature = "async"))] @@ -454,21 +447,13 @@ mod test { let address = BITCOIND .client - .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap() - .assume_checked(); + .new_address_with_type(AddressType::Legacy) + .unwrap(); let txid = BITCOIND .client - .send_to_address( - &address, - Amount::from_sat(1000), - None, - None, - None, - None, - None, - None, - ) + .send_to_address(&address, Amount::from_sat(1000)) + .unwrap() + .txid() .unwrap(); let _miner = MINER.lock().await; generate_blocks_and_wait(1); @@ -485,21 +470,13 @@ mod test { let address = BITCOIND .client - .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap() - .assume_checked(); + .new_address_with_type(AddressType::Legacy) + .unwrap(); let txid = BITCOIND .client - .send_to_address( - &address, - Amount::from_sat(1000), - None, - None, - None, - None, - None, - None, - ) + .send_to_address(&address, Amount::from_sat(1000)) + .unwrap() + .txid() .unwrap(); let _miner = MINER.lock().await; generate_blocks_and_wait(1); @@ -516,21 +493,13 @@ mod test { let address = BITCOIND .client - .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap() - .assume_checked(); + .new_address_with_type(AddressType::Legacy) + .unwrap(); let txid = BITCOIND .client - .send_to_address( - &address, - Amount::from_sat(1000), - None, - None, - None, - None, - None, - None, - ) + .send_to_address(&address, Amount::from_sat(1000)) + .unwrap() + .txid() .unwrap(); let _miner = MINER.lock().await; generate_blocks_and_wait(1); @@ -558,27 +527,31 @@ mod test { let address = BITCOIND .client - .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap() - .assume_checked(); + .new_address_with_type(AddressType::Legacy) + .unwrap(); let txid = BITCOIND .client - .send_to_address( - &address, - Amount::from_sat(1000), - None, - None, - None, - None, - None, - None, - ) + .send_to_address(&address, Amount::from_sat(1000)) + .unwrap() + .txid() .unwrap(); let _miner = MINER.lock().await; generate_blocks_and_wait(1); - let tx_res = BITCOIND.client.get_transaction(&txid, None).unwrap(); - let tx_exp = tx_res.transaction().expect("must decode"); + let tx_res = BITCOIND + .client + .get_transaction(txid) + .unwrap() + .into_model() + .unwrap(); + let tx_exp: Transaction = tx_res.tx; + let tx_block_height = BITCOIND + .client + .get_block_header_verbose(&tx_res.block_hash.unwrap()) + .unwrap() + .into_model() + .unwrap() + .height; let tx_info = blocking_client .get_tx_info(&txid) @@ -596,9 +569,12 @@ mod test { assert_eq!(tx_info.weight(), tx_exp.weight()); assert_eq!(tx_info.fee(), tx_res.fee.unwrap().unsigned_abs()); assert!(tx_info.status.confirmed); - assert_eq!(tx_info.status.block_height, tx_res.info.blockheight); - assert_eq!(tx_info.status.block_hash, tx_res.info.blockhash); - assert_eq!(tx_info.status.block_time, tx_res.info.blocktime); + assert_eq!(tx_info.status.block_height, Some(tx_block_height)); + assert_eq!(tx_info.status.block_hash, tx_res.block_hash); + assert_eq!( + tx_info.status.block_time, + tx_res.block_time.map(|bt| bt as u64) + ); let txid = Txid::hash(b"not exist"); assert_eq!(blocking_client.get_tx_info(&txid).unwrap(), None); @@ -610,7 +586,12 @@ mod test { async fn test_get_header_by_hash() { let (blocking_client, async_client) = setup_clients().await; - let block_hash = BITCOIND.client.get_block_hash(23).unwrap(); + let block_hash = BITCOIND + .client + .get_block_hash(23) + .unwrap() + .block_hash() + .unwrap(); let block_header = blocking_client.get_header_by_hash(&block_hash).unwrap(); let block_header_async = async_client.get_header_by_hash(&block_hash).await.unwrap(); @@ -622,8 +603,18 @@ mod test { async fn test_get_block_status() { let (blocking_client, async_client) = setup_clients().await; - let block_hash = BITCOIND.client.get_block_hash(21).unwrap(); - let next_block_hash = BITCOIND.client.get_block_hash(22).unwrap(); + let block_hash = BITCOIND + .client + .get_block_hash(21) + .unwrap() + .block_hash() + .unwrap(); + let next_block_hash = BITCOIND + .client + .get_block_hash(22) + .unwrap() + .block_hash() + .unwrap(); let expected = BlockStatus { in_best_chain: true, @@ -667,9 +658,14 @@ mod test { async fn test_get_block_by_hash() { let (blocking_client, async_client) = setup_clients().await; - let block_hash = BITCOIND.client.get_block_hash(21).unwrap(); + let block_hash = BITCOIND + .client + .get_block_hash(21) + .unwrap() + .block_hash() + .unwrap(); - let expected = Some(BITCOIND.client.get_block(&block_hash).unwrap()); + let expected = Some(BITCOIND.client.get_block(block_hash).unwrap()); let block = blocking_client.get_block_by_hash(&block_hash).unwrap(); let block_async = async_client.get_block_by_hash(&block_hash).await.unwrap(); @@ -684,21 +680,13 @@ mod test { let address = BITCOIND .client - .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap() - .assume_checked(); + .new_address_with_type(AddressType::Legacy) + .unwrap(); let txid = BITCOIND .client - .send_to_address( - &address, - Amount::from_sat(1000), - None, - None, - None, - None, - None, - None, - ) + .send_to_address(&address, Amount::from_sat(1000)) + .unwrap() + .txid() .unwrap(); let _miner = MINER.lock().await; generate_blocks_and_wait(1); @@ -707,9 +695,15 @@ mod test { let async_res = async_client.broadcast(tx.as_ref().unwrap()).await; let blocking_res = blocking_client.broadcast(tx.as_ref().unwrap()); assert!(async_res.is_err()); - assert_eq!(async_res.unwrap_err().to_string(),"HttpResponse { status: 400, message: \"sendrawtransaction RPC error: {\\\"code\\\":-27,\\\"message\\\":\\\"Transaction already in block chain\\\"}\" }"); + assert!(matches!( + async_res.unwrap_err(), + Error::HttpResponse { status: 400, message } if message.contains("-27") + )); assert!(blocking_res.is_err()); - assert_eq!(blocking_res.unwrap_err().to_string(),"HttpResponse { status: 400, message: \"sendrawtransaction RPC error: {\\\"code\\\":-27,\\\"message\\\":\\\"Transaction already in block chain\\\"}\" }"); + assert!(matches!( + blocking_res.unwrap_err(), + Error::HttpResponse { status: 400, message } if message.contains("-27") + )); } #[cfg(all(feature = "blocking", feature = "async"))] @@ -735,21 +729,13 @@ mod test { let address = BITCOIND .client - .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap() - .assume_checked(); + .new_address_with_type(AddressType::Legacy) + .unwrap(); let txid = BITCOIND .client - .send_to_address( - &address, - Amount::from_sat(1000), - None, - None, - None, - None, - None, - None, - ) + .send_to_address(&address, Amount::from_sat(1000)) + .unwrap() + .txid() .unwrap(); let _miner = MINER.lock().await; generate_blocks_and_wait(1); @@ -767,21 +753,13 @@ mod test { let address = BITCOIND .client - .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap() - .assume_checked(); + .new_address_with_type(AddressType::Legacy) + .unwrap(); let txid = BITCOIND .client - .send_to_address( - &address, - Amount::from_sat(1000), - None, - None, - None, - None, - None, - None, - ) + .send_to_address(&address, Amount::from_sat(1000)) + .unwrap() + .txid() .unwrap(); let _miner = MINER.lock().await; generate_blocks_and_wait(1); @@ -808,21 +786,13 @@ mod test { let address = BITCOIND .client - .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap() - .assume_checked(); + .new_address_with_type(AddressType::Legacy) + .unwrap(); let txid = BITCOIND .client - .send_to_address( - &address, - Amount::from_sat(1000), - None, - None, - None, - None, - None, - None, - ) + .send_to_address(&address, Amount::from_sat(1000)) + .unwrap() + .txid() .unwrap(); let _miner = MINER.lock().await; generate_blocks_and_wait(1); @@ -864,7 +834,12 @@ mod test { async fn test_get_block_hash() { let (blocking_client, async_client) = setup_clients().await; - let block_hash = BITCOIND.client.get_block_hash(21).unwrap(); + let block_hash = BITCOIND + .client + .get_block_hash(21) + .unwrap() + .block_hash() + .unwrap(); let block_hash_blocking = blocking_client.get_block_hash(21).unwrap(); let block_hash_async = async_client.get_block_hash(21).await.unwrap(); @@ -877,7 +852,12 @@ mod test { async fn test_get_txid_at_block_index() { let (blocking_client, async_client) = setup_clients().await; - let block_hash = BITCOIND.client.get_block_hash(23).unwrap(); + let block_hash = BITCOIND + .client + .get_block_hash(23) + .unwrap() + .block_hash() + .unwrap(); let txid_at_block_index = blocking_client .get_txid_at_block_index(&block_hash, 0) @@ -907,31 +887,24 @@ mod test { let address = BITCOIND .client - .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap() - .assume_checked(); + .new_address_with_type(AddressType::Legacy) + .unwrap(); let txid = BITCOIND .client - .send_to_address( - &address, - Amount::from_sat(1000), - None, - None, - None, - None, - None, - None, - ) + .send_to_address(&address, Amount::from_sat(1000)) + .unwrap() + .txid() .unwrap(); let _miner = MINER.lock().await; generate_blocks_and_wait(1); let expected_tx = BITCOIND .client - .get_transaction(&txid, None) + .get_transaction(txid) .unwrap() - .transaction() - .unwrap(); + .into_model() + .unwrap() + .tx; let script = &expected_tx.output[0].script_pubkey; let scripthash_txs_txids: Vec = blocking_client .scripthash_txs(script, None) @@ -953,7 +926,7 @@ mod test { #[tokio::test] async fn test_get_blocks() { let (blocking_client, async_client) = setup_clients().await; - let start_height = BITCOIND.client.get_block_count().unwrap(); + let start_height = BITCOIND.client.get_block_count().unwrap().0; let blocks1 = blocking_client.get_blocks(None).unwrap(); let blocks_async1 = async_client.get_blocks(None).await.unwrap(); assert_eq!(blocks1[0].time.height, start_height as u32); @@ -990,21 +963,13 @@ mod test { let address = BITCOIND .client - .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap() - .assume_checked(); + .new_address_with_type(AddressType::Legacy) + .unwrap(); let txid = BITCOIND .client - .send_to_address( - &address, - Amount::from_sat(1000), - None, - None, - None, - None, - None, - None, - ) + .send_to_address(&address, Amount::from_sat(1000)) + .unwrap() + .txid() .unwrap(); let _miner = MINER.lock().await; generate_blocks_and_wait(1); @@ -1021,22 +986,14 @@ mod test { let address = BITCOIND .client - .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap() - .assume_checked(); + .new_address_with_type(AddressType::Legacy) + .unwrap(); let _txid = BITCOIND .client - .send_to_address( - &address, - Amount::from_sat(1000), - None, - None, - None, - None, - None, - None, - ) + .send_to_address(&address, Amount::from_sat(1000)) + .unwrap() + .txid() .unwrap(); let address_stats_blocking = blocking_client.get_address_stats(&address).unwrap(); @@ -1061,22 +1018,14 @@ mod test { let address = BITCOIND .client - .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap() - .assume_checked(); + .new_address_with_type(AddressType::Legacy) + .unwrap(); let txid = BITCOIND .client - .send_to_address( - &address, - Amount::from_sat(1000), - None, - None, - None, - None, - None, - None, - ) + .send_to_address(&address, Amount::from_sat(1000)) + .unwrap() + .txid() .unwrap(); let _miner = MINER.lock().await;