Skip to content

Commit

Permalink
Update rust-bitcoin to v0.31
Browse files Browse the repository at this point in the history
  • Loading branch information
shesek committed Feb 13, 2024
1 parent aabc363 commit 9cc3afc
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" ] }
Expand Down
28 changes: 21 additions & 7 deletions src/bin/tx-fingerprint-stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn main() {
continue;
}
// skip coinbase txs
if tx.is_coin_base() {
if tx.is_coinbase() {
continue;
}

Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/new_index/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 6 additions & 3 deletions src/new_index/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(),
}),
)
});
Expand All @@ -396,7 +399,7 @@ impl Mempool {
TxHistoryInfo::Funding(FundingInfo {
txid: txid_bytes,
vout: index as u16,
value: txo.value,
value: txo.value.to_sat(),
}),
)
});
Expand Down
4 changes: 2 additions & 2 deletions src/new_index/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
31 changes: 19 additions & 12 deletions src/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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"
Expand All @@ -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")]
Expand Down Expand Up @@ -1251,14 +1251,14 @@ impl From<HashError> for HttpError {
HttpError::from("Invalid hash string".to_string())
}
}
impl From<HexToBytesError> for HttpError {
fn from(_e: HexToBytesError) -> Self {
impl From<hex::HexToBytesError> for HttpError {
fn from(_e: hex::HexToBytesError) -> Self {
//HttpError::from(e.description().to_string())
HttpError::from("Invalid hex string".to_string())
}
}
impl From<bitcoin::hashes::hex::Error> for HttpError {
fn from(_e: bitcoin::hashes::hex::Error) -> Self {
impl From<hex::HexToArrayError> for HttpError {
fn from(_e: hex::HexToArrayError) -> Self {
//HttpError::from(e.description().to_string())
HttpError::from("Invalid hex string".to_string())
}
Expand Down Expand Up @@ -1295,6 +1295,13 @@ impl From<std::string::FromUtf8Error> for HttpError {
HttpError::from(e.to_string())
}
}

impl From<address::ParseError> for HttpError {
fn from(e: address::ParseError) -> Self {
HttpError::from(e.to_string())
}
}

#[cfg(feature = "liquid")]
impl From<address::AddressError> for HttpError {
fn from(e: address::AddressError) -> Self {
Expand Down
9 changes: 6 additions & 3 deletions src/util/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ impl TxFeeInfo {

#[cfg(not(feature = "liquid"))]
pub fn get_tx_fee(tx: &Transaction, prevouts: &HashMap<u32, &TxOut>, _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
}

Expand Down
4 changes: 2 additions & 2 deletions src/util/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit 9cc3afc

Please sign in to comment.