Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 115 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ electrum-discovery = ["electrum-client"]
arrayref = "0.3.6"
base64 = "0.13.0"
bincode-do-not-use-directly = { version = "1.3.1", package = "bincode" }
bitcoin = { version = "0.28", features = [ "use-serde" ] }
bitcoin = { version = "0.32", features = [ "serde" ] }
bounded-vec-deque = "0.1.1"
clap = "2.33.3"
crossbeam-channel = "0.5.0"
Expand Down
3 changes: 2 additions & 1 deletion src/bin/electrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extern crate log;

extern crate electrs;

use bitcoin::p2p::Magic;
use error_chain::ChainedError;
use std::process;
use std::sync::{Arc, RwLock};
Expand Down Expand Up @@ -50,7 +51,7 @@ fn run_server(config: Arc<Config>) -> Result<()> {
config.daemon_rpc_addr,
config.cookie_getter(),
config.network_type,
config.magic,
config.magic.map(|m| Magic::from_bytes(m.to_be_bytes())),
signal.clone(),
&metrics,
)?);
Expand Down
37 changes: 26 additions & 11 deletions src/bin/tx-fingerprint-stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ fn main() {
use std::collections::HashSet;
use std::sync::Arc;

use bitcoin::blockdata::script::Script;
use bitcoin::consensus::encode::deserialize;
use bitcoin::p2p::Magic;
use bitcoin::ScriptBuf;
use electrs::{
chain::Transaction,
config::Config,
Expand All @@ -35,7 +36,7 @@ fn main() {
config.daemon_rpc_addr,
config.cookie_getter(),
config.network_type,
config.magic,
config.magic.map(|m| Magic::from_bytes(m.to_be_bytes())),
signal,
&metrics,
)
Expand All @@ -62,7 +63,7 @@ fn main() {
}

let tx: Transaction = deserialize(value).expect("failed to parse Transaction");
let txid = tx.txid();
let txid = tx.compute_txid();

iter.next();

Expand All @@ -71,7 +72,7 @@ fn main() {
continue;
}
// skip coinbase txs
if tx.is_coin_base() {
if tx.is_coinbase() {
continue;
}

Expand All @@ -91,12 +92,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 All @@ -119,7 +134,7 @@ fn main() {

// test for sending back to one of the spent spks
let has_reuse = {
let prev_spks: HashSet<Script> = prevouts
let prev_spks: HashSet<ScriptBuf> = prevouts
.values()
.map(|out| out.script_pubkey.clone())
.collect();
Expand Down
19 changes: 9 additions & 10 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use std::str::FromStr;

#[cfg(not(feature = "liquid"))] // use regular Bitcoin data structures
pub use bitcoin::{
address,
block::Header as BlockHeader,
blockdata::{opcodes, script, witness::Witness},
consensus::deserialize,
hashes,
util::address,
Block, BlockHash, BlockHeader, OutPoint, Script, Transaction, TxIn, TxOut, Txid,
hashes, Block, BlockHash, Opcode, OutPoint, Script, Transaction, TxIn, TxOut, Txid,
};

#[cfg(feature = "liquid")]
Expand All @@ -20,7 +20,8 @@ pub use {
};

use bitcoin::blockdata::constants::genesis_block;
pub use bitcoin::network::constants::Network as BNetwork;
use bitcoin::p2p::Magic;
pub use bitcoin::Network as BNetwork;

#[cfg(not(feature = "liquid"))]
pub type Value = u64;
Expand Down Expand Up @@ -59,15 +60,11 @@ pub const LIQUID_TESTNET_PARAMS: address::AddressParams = address::AddressParams

/// Magic for testnet4, 0x1c163f28 (from BIP94) with flipped endianness.
#[cfg(not(feature = "liquid"))]
const TESTNET4_MAGIC: u32 = 0x283f161c;

impl Network {
#[cfg(not(feature = "liquid"))]
pub fn magic(self) -> u32 {
match self {
Self::Testnet4 => TESTNET4_MAGIC,
_ => BNetwork::from(self).magic(),
}
pub fn magic(self) -> Magic {
BNetwork::from(self).magic()
}

#[cfg(feature = "liquid")]
Expand Down Expand Up @@ -234,8 +231,10 @@ impl From<BNetwork> for Network {
match network {
BNetwork::Bitcoin => Network::Bitcoin,
BNetwork::Testnet => Network::Testnet,
BNetwork::Testnet4 => Network::Testnet4,
BNetwork::Regtest => Network::Regtest,
BNetwork::Signet => Network::Signet,
_ => panic!("unknown network"),
}
}
}
Loading