diff --git a/Cargo.toml b/Cargo.toml index 59fa0432a..0fea6f9eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ arraydeque = "0.5.1" arrayref = "0.3.6" base64 = "0.21.3" bincode = "1.3.1" -bitcoin = { version = "0.30.1", features = [ "serde" ] } +bitcoin = { version = "0.31", features = [ "serde" ] } clap = "2.33.3" crossbeam-channel = "0.5.0" dirs = "5.0.1" @@ -58,7 +58,7 @@ electrum-client = { version = "0.8", optional = true } [dev-dependencies] -bitcoind = { version = "0.32.0", features = [ "25_0" ] } +bitcoind = { version = "0.34", features = [ "25_0" ] } elementsd = { version = "0.8.0", features = [ "22_1_1" ] } electrumd = { version = "0.1.0", features = [ "4_1_5" ] } ureq = { version = "2.9", default-features = false, features = [ "json" ] } diff --git a/src/bin/tx-fingerprint-stats.rs b/src/bin/tx-fingerprint-stats.rs index da5318547..8e4c35e30 100644 --- a/src/bin/tx-fingerprint-stats.rs +++ b/src/bin/tx-fingerprint-stats.rs @@ -70,7 +70,7 @@ fn main() { continue; } // skip coinbase txs - if tx.is_coin_base() { + if tx.is_coinbase() { continue; } @@ -90,12 +90,26 @@ fn main() { .collect(), ); - let total_out: u64 = tx.output.iter().map(|out| out.value).sum(); - let small_out = tx.output.iter().map(|out| out.value).min().unwrap(); - let large_out = tx.output.iter().map(|out| out.value).max().unwrap(); - - let total_in: u64 = prevouts.values().map(|out| out.value).sum(); - let smallest_in = prevouts.values().map(|out| out.value).min().unwrap(); + let total_out: u64 = tx.output.iter().map(|out| out.value.to_sat()).sum(); + let small_out = tx + .output + .iter() + .map(|out| out.value.to_sat()) + .min() + .unwrap(); + let large_out = tx + .output + .iter() + .map(|out| out.value.to_sat()) + .max() + .unwrap(); + + let total_in: u64 = prevouts.values().map(|out| out.value.to_sat()).sum(); + let smallest_in = prevouts + .values() + .map(|out| out.value.to_sat()) + .min() + .unwrap(); let fee = total_in - total_out; diff --git a/src/chain.rs b/src/chain.rs index 9876580f5..57015543a 100644 --- a/src/chain.rs +++ b/src/chain.rs @@ -15,7 +15,7 @@ pub use { }; use bitcoin::blockdata::constants::genesis_block; -pub use bitcoin::network::constants::Network as BNetwork; +pub use bitcoin::network::Network as BNetwork; #[cfg(not(feature = "liquid"))] pub type Value = u64; diff --git a/src/new_index/fetch.rs b/src/new_index/fetch.rs index 20d0bfde0..a2e1ba4cb 100644 --- a/src/new_index/fetch.rs +++ b/src/new_index/fetch.rs @@ -88,7 +88,7 @@ fn bitcoind_fetcher( .zip(entries) .map(|(block, entry)| BlockEntry { entry: entry.clone(), // TODO: remove this clone() - size: block.size() as u32, + size: block.total_size() as u32, block, }) .collect(); diff --git a/src/new_index/mempool.rs b/src/new_index/mempool.rs index 7d722d4e0..a6228c211 100644 --- a/src/new_index/mempool.rs +++ b/src/new_index/mempool.rs @@ -362,7 +362,10 @@ impl Mempool { fee: feeinfo.fee, vsize: feeinfo.vsize, #[cfg(not(feature = "liquid"))] - value: prevouts.values().map(|prevout| prevout.value).sum(), + value: prevouts + .values() + .map(|prevout| prevout.value.to_sat()) + .sum(), }); self.feeinfo.insert(txid, feeinfo); @@ -377,7 +380,7 @@ impl Mempool { vin: input_index as u16, prev_txid: full_hash(&txi.previous_output.txid[..]), prev_vout: txi.previous_output.vout as u16, - value: prevout.value, + value: prevout.value.to_sat(), }), ) }); @@ -396,7 +399,7 @@ impl Mempool { TxHistoryInfo::Funding(FundingInfo { txid: txid_bytes, vout: index as u16, - value: txo.value, + value: txo.value.to_sat(), }), ) }); diff --git a/src/new_index/schema.rs b/src/new_index/schema.rs index f5afd1fb3..403ecf2db 100644 --- a/src/new_index/schema.rs +++ b/src/new_index/schema.rs @@ -1104,7 +1104,7 @@ fn index_transaction( TxHistoryInfo::Funding(FundingInfo { txid, vout: txo_index as u16, - value: txo.value, + value: txo.value.to_sat(), }), ); rows.push(history.into_row()); @@ -1132,7 +1132,7 @@ fn index_transaction( vin: txi_index as u16, prev_txid: full_hash(&txi.previous_output.txid[..]), prev_vout: txi.previous_output.vout as u16, - value: prev_txo.value, + value: prev_txo.value.to_sat(), }), ); rows.push(history.into_row()); diff --git a/src/rest.rs b/src/rest.rs index c5ac02d8d..4af0beea1 100644 --- a/src/rest.rs +++ b/src/rest.rs @@ -14,8 +14,8 @@ use crate::util::{ #[cfg(not(feature = "liquid"))] use bitcoin::consensus::encode; -use bitcoin::hashes::Error as HashError; -use hex::{DisplayHex, FromHex, HexToBytesError}; +use bitcoin::hashes::FromSliceError as HashError; +use hex::{DisplayHex, FromHex}; use hyper::service::{make_service_fn, service_fn}; use hyper::{Body, Method, Response, Server, StatusCode}; use hyperlocal::UnixServerExt; @@ -159,11 +159,11 @@ impl TransactionValue { TransactionValue { txid: tx.txid(), - version: tx.version as u32, + version: tx.version.0 as u32, locktime: tx.lock_time.to_consensus_u32(), vin: vins, vout: vouts, - size: tx.size() as u32, + size: tx.total_size() as u32, weight: weight as u64, fee, status: Some(TransactionStatus::from(blockid)), @@ -310,11 +310,11 @@ impl TxOutValue { "p2pkh" } else if script.is_p2sh() { "p2sh" - } else if script.is_v0_p2wpkh() { + } else if script.is_p2wpkh() { "v0_p2wpkh" - } else if script.is_v0_p2wsh() { + } else if script.is_p2wsh() { "v0_p2wsh" - } else if script.is_v1_p2tr() { + } else if script.is_p2tr() { "v1_p2tr" } else if script.is_provably_unspendable() { "provably_unspendable" @@ -330,7 +330,7 @@ impl TxOutValue { scriptpubkey_asm: script_asm, scriptpubkey_address: script_addr, scriptpubkey_type: script_type.to_string(), - value, + value: value.to_sat(), #[cfg(feature = "liquid")] valuecommitment: txout.value.commitment(), #[cfg(feature = "liquid")] @@ -1251,14 +1251,14 @@ impl From for HttpError { HttpError::from("Invalid hash string".to_string()) } } -impl From for HttpError { - fn from(_e: HexToBytesError) -> Self { +impl From for HttpError { + fn from(_e: hex::HexToBytesError) -> Self { //HttpError::from(e.description().to_string()) HttpError::from("Invalid hex string".to_string()) } } -impl From for HttpError { - fn from(_e: bitcoin::hashes::hex::Error) -> Self { +impl From for HttpError { + fn from(_e: hex::HexToArrayError) -> Self { //HttpError::from(e.description().to_string()) HttpError::from("Invalid hex string".to_string()) } @@ -1295,6 +1295,13 @@ impl From for HttpError { HttpError::from(e.to_string()) } } + +impl From for HttpError { + fn from(e: address::ParseError) -> Self { + HttpError::from(e.to_string()) + } +} + #[cfg(feature = "liquid")] impl From for HttpError { fn from(e: address::AddressError) -> Self { diff --git a/src/util/fees.rs b/src/util/fees.rs index 164b9c133..9cbe6c1d7 100644 --- a/src/util/fees.rs +++ b/src/util/fees.rs @@ -29,12 +29,15 @@ impl TxFeeInfo { #[cfg(not(feature = "liquid"))] pub fn get_tx_fee(tx: &Transaction, prevouts: &HashMap, _network: Network) -> u64 { - if tx.is_coin_base() { + if tx.is_coinbase() { return 0; } - let total_in: u64 = prevouts.values().map(|prevout| prevout.value).sum(); - let total_out: u64 = tx.output.iter().map(|vout| vout.value).sum(); + let total_in: u64 = prevouts + .values() + .map(|prevout| prevout.value.to_sat()) + .sum(); + let total_out: u64 = tx.output.iter().map(|vout| vout.value.to_sat()).sum(); total_in - total_out } diff --git a/src/util/script.rs b/src/util/script.rs index f7a2a65f3..f1834f12c 100644 --- a/src/util/script.rs +++ b/src/util/script.rs @@ -54,8 +54,8 @@ pub fn get_innerscripts(txin: &TxIn, prevout: &TxOut) -> InnerScripts { }; // Wrapped witnessScript for P2WSH or P2SH-P2WSH spends - let witness_script = if prevout.script_pubkey.is_v0_p2wsh() - || redeem_script.as_ref().map_or(false, |s| s.is_v0_p2wsh()) + let witness_script = if prevout.script_pubkey.is_p2wsh() + || redeem_script.as_ref().map_or(false, |s| s.is_p2wsh()) { let witness = &txin.witness; #[cfg(feature = "liquid")]