diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f1b7ec3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +# see https://editorconfig.org for more options, and setup instructions for yours editor + +[*] +indent_style = space +indent_size = 4 + diff --git a/Cargo.lock b/Cargo.lock index 80be001..b587886 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -98,6 +98,11 @@ name = "bech32" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "bech32" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "bincode" version = "1.1.3" @@ -105,7 +110,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -148,12 +153,25 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitcoin-bech32 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "bitcoin_hashes 0.3.2 (git+https://github.com/rust-bitcoin/bitcoin_hashes?rev=803b5fb48b9c949cbfbb548a7032e8d9b3213c97)", + "bitcoin_hashes 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)", "secp256k1 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "bitcoin" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bech32 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bitcoin_hashes 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "secp256k1 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -167,10 +185,19 @@ dependencies = [ [[package]] name = "bitcoin_hashes" version = "0.3.2" -source = "git+https://github.com/rust-bitcoin/bitcoin_hashes?rev=803b5fb48b9c949cbfbb548a7032e8d9b3213c97#803b5fb48b9c949cbfbb548a7032e8d9b3213c97" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "bitcoin_hashes" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -387,9 +414,7 @@ dependencies = [ "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "bincode 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "bitcoin 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", - "bitcoin-bech32 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "bitcoin_hashes 0.3.2 (git+https://github.com/rust-bitcoin/bitcoin_hashes?rev=803b5fb48b9c949cbfbb548a7032e8d9b3213c97)", + "bitcoin 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", "chan 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", "chan-signal 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -412,8 +437,7 @@ dependencies = [ "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "rocksdb 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", - "secp256k1 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "stderrlog 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -431,9 +455,9 @@ source = "git+https://github.com/elementsproject/rust-elements?rev=ae548a4748508 dependencies = [ "bech32 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitcoin 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", - "bitcoin_hashes 0.3.2 (git+https://github.com/rust-bitcoin/bitcoin_hashes?rev=803b5fb48b9c949cbfbb548a7032e8d9b3213c97)", + "bitcoin_hashes 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "secp256k1 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1224,8 +1248,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.90" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "serde_derive" @@ -1244,7 +1271,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1686,13 +1713,16 @@ dependencies = [ "checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6" "checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" "checksum bech32 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "58946044516aa9dc922182e0d6e9d124a31aafe6b421614654eb27cf90cec09c" +"checksum bech32 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9e0089c35ab7c6f2bc55ab23f769913f0ac65b1023e7e74638a1f43128dd5df2" "checksum bincode 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "959c8e54c1ad412ffeeb95f05a9cade02d2d40a7b3c2f852d3353148f4beff35" "checksum bindgen 0.47.3 (registry+https://github.com/rust-lang/crates.io-index)" = "df683a55b54b41d5ea8ebfaebb5aa7e6b84e3f3006a78f010dadc9ca88469260" "checksum bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9bf6104718e80d7b26a68fdbacff3481cfc05df670821affc7e9cbc1884400c" "checksum bit-vec 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "02b4ff8b16e6076c3e14220b39fbc1fabb6737522281a388998046859400895f" "checksum bitcoin 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)" = "381b74ae6480c4da21dccdf6fdf7400250710fc891af8d82376cb5c03e5f6f1d" +"checksum bitcoin 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a07466bc4cdfb06734571b562a9506e5302a82218a00e6454a9a0850c3518f7c" "checksum bitcoin-bech32 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4e67e8ccfc663811145e6cabdb9a2a6978877f72b048516e83eb95622e9b2554" -"checksum bitcoin_hashes 0.3.2 (git+https://github.com/rust-bitcoin/bitcoin_hashes?rev=803b5fb48b9c949cbfbb548a7032e8d9b3213c97)" = "" +"checksum bitcoin_hashes 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2b7a2e9773ee7ae7f2560f0426c938f57902dcb9e39321b0cbd608f47ed579a4" +"checksum bitcoin_hashes 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "db6b697833d852acea530c9e815e6adc724267856b6506bc500362a068a39c7b" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400" "checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" @@ -1813,7 +1843,7 @@ dependencies = [ "checksum secp256k1 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfaccd3a23619349e0878d9a241f34b1982343cdf67367058cd7d078d326b63e" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)" = "aa5f7c20820475babd2c077c3ab5f8c77a31c15e16ea38687b4c02d3e48680f4" +"checksum serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)" = "7fe5626ac617da2f2d9c48af5515a21d5a480dbd151e01bb1c355e26a3e68113" "checksum serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)" = "58fc82bec244f168b23d1963b45c8bf5726e9a15a9d146a067f9081aeed2de79" "checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" diff --git a/Cargo.toml b/Cargo.toml index 9942e6c..f89b21f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,6 @@ arraydeque = "0.4" arrayref = "0.3" base64 = "0.10" bincode = "1.0" -bitcoin-bech32 = "0.9.0" chan = "0.1" chan-signal = "0.3" clap = "2.31" @@ -42,7 +41,6 @@ prometheus = "0.5" rayon = "1.0" rocksdb = "0.12.1" rust-crypto = "0.2" -secp256k1 = "0.12" serde = "1.0" serde_derive = "1.0" serde_json = "1.0" @@ -53,15 +51,9 @@ tiny_http = "0.6" url = "1.0" [dependencies.bitcoin] -version = "0.18" -features = ["serde"] +version = "0.19.1" +features = ["use-serde"] -[dependencies.bitcoin_hashes] -version = "0.3" -features = ["serde"] - -[patch.crates-io] -bitcoin_hashes = { git = "https://github.com/rust-bitcoin/bitcoin_hashes", rev = "803b5fb48b9c949cbfbb548a7032e8d9b3213c97" } [dependencies.elements] optional = true git = "https://github.com/elementsproject/rust-elements" diff --git a/src/app.rs b/src/app.rs index 05e7da9..76e837b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,4 +1,4 @@ -use bitcoin_hashes::sha256d::Hash as Sha256dHash; +use bitcoin::hashes::sha256d::Hash as Sha256dHash; use std::sync::{Arc, Mutex}; use crate::{daemon, index, signal::Waiter, store}; diff --git a/src/chain.rs b/src/chain.rs index 4804e77..8453238 100644 --- a/src/chain.rs +++ b/src/chain.rs @@ -11,8 +11,7 @@ pub use elements::{confidential, Address, Block, BlockHeader, OutPoint, Transact use bitcoin::blockdata::constants::genesis_block; use bitcoin::network::constants::Network as BNetwork; use bitcoin::util::hash::BitcoinHash; -use bitcoin_bech32::constants::Network as B32Network; -use bitcoin_hashes::sha256d::Hash as Sha256dHash; +use bitcoin::hashes::sha256d::Hash as Sha256dHash; #[cfg(not(feature = "liquid"))] pub type Value = u64; @@ -111,20 +110,6 @@ impl From<&Network> for BNetwork { } } -impl From<&Network> for B32Network { - fn from(network: &Network) -> Self { - match network { - Network::Bitcoin => B32Network::Bitcoin, - Network::Testnet => B32Network::Testnet, - Network::Regtest => B32Network::Regtest, - #[cfg(feature = "liquid")] - Network::Liquid => B32Network::Bitcoin, // @FIXME - #[cfg(feature = "liquid")] - Network::LiquidRegtest => B32Network::Regtest, // @FIXME - } - } -} - impl From<&BNetwork> for Network { fn from(network: &BNetwork) -> Self { match network { diff --git a/src/config.rs b/src/config.rs index 733719b..c833319 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,7 +8,7 @@ use std::sync::Arc; use stderrlog; #[cfg(feature = "liquid")] -use bitcoin_hashes::hex::ToHex; +use bitcoin::hashes::hex::ToHex; use crate::chain::Network; use crate::daemon::CookieGetter; diff --git a/src/daemon.rs b/src/daemon.rs index 46c039d..72007a7 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -1,8 +1,8 @@ use base64; use bitcoin::consensus::encode::{deserialize, serialize}; use bitcoin::util::hash::BitcoinHash; -use bitcoin_hashes::hex::{FromHex, ToHex}; -use bitcoin_hashes::sha256d::Hash as Sha256dHash; +use bitcoin::hashes::hex::{FromHex, ToHex}; +use bitcoin::hashes::sha256d::Hash as Sha256dHash; use glob; use hex; use serde_json::{from_str, from_value, Value}; diff --git a/src/electrum.rs b/src/electrum.rs index 602fb2a..6dfd826 100644 --- a/src/electrum.rs +++ b/src/electrum.rs @@ -1,6 +1,6 @@ use bitcoin::consensus::encode::serialize; -use bitcoin_hashes::hex::{FromHex, ToHex}; -use bitcoin_hashes::sha256d::Hash as Sha256dHash; +use bitcoin::hashes::hex::{FromHex, ToHex}; +use bitcoin::hashes::sha256d::Hash as Sha256dHash; use crypto::digest::Digest; use crypto::sha2::Sha256; use error_chain::ChainedError; diff --git a/src/elements/asset.rs b/src/elements/asset.rs index 9969239..09639c9 100644 --- a/src/elements/asset.rs +++ b/src/elements/asset.rs @@ -1,7 +1,7 @@ use std::collections::{HashMap, HashSet}; use bitcoin::consensus::encode::{deserialize, serialize}; -use bitcoin_hashes::{hex::FromHex, sha256, sha256d, Hash}; +use bitcoin::hashes::{hex::FromHex, sha256, sha256d, Hash}; use elements::confidential::{Asset, Value}; use elements::{AssetIssuance, OutPoint, Transaction, TxIn}; diff --git a/src/elements/assetid.rs b/src/elements/assetid.rs index d3ab092..b20bfb9 100644 --- a/src/elements/assetid.rs +++ b/src/elements/assetid.rs @@ -1,7 +1,7 @@ // Copeid from https://github.com/ElementsProject/rust-elements/pull/19 pending merge use bitcoin::consensus::Encodable; -use bitcoin_hashes::{hex, sha256, sha256d, Error, Hash, HashEngine}; +use bitcoin::hashes::{hex, sha256, sha256d, Error, Hash, HashEngine}; use elements::OutPoint; /// The zero hash. @@ -107,7 +107,7 @@ impl ::std::fmt::LowerHex for AssetId { #[cfg(feature = "serde")] impl ::serde::Serialize for AssetId { fn serialize(&self, s: S) -> Result { - use bitcoin_hashes::hex::ToHex; + use bitcoin::hashes::hex::ToHex; if s.is_human_readable() { s.serialize_str(&self.to_hex()) } else { @@ -119,8 +119,8 @@ impl ::serde::Serialize for AssetId { #[cfg(feature = "serde")] impl<'de> ::serde::Deserialize<'de> for AssetId { fn deserialize>(d: D) -> Result { - use bitcoin_hashes::hex::FromHex; - use bitcoin_hashes::sha256; + use bitcoin::hashes::hex::FromHex; + use bitcoin::hashes::sha256; if d.is_human_readable() { struct HexVisitor; diff --git a/src/elements/mod.rs b/src/elements/mod.rs index e74f9f1..74defed 100644 --- a/src/elements/mod.rs +++ b/src/elements/mod.rs @@ -1,7 +1,7 @@ use bitcoin::blockdata::script::Instruction::PushBytes; use bitcoin::consensus::encode::serialize; use bitcoin::Script; -use bitcoin_hashes::hex::ToHex; +use bitcoin::hashes::hex::ToHex; use elements::confidential::Value; use elements::{Proof, TxIn}; use hex; diff --git a/src/lib.rs b/src/lib.rs index 100f9ac..c758ed9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,8 +3,6 @@ extern crate base64; extern crate bincode; extern crate bitcoin; -extern crate bitcoin_bech32; -extern crate bitcoin_hashes; extern crate chan_signal; extern crate crypto; extern crate dirs; @@ -20,7 +18,6 @@ extern crate page_size; extern crate prometheus; extern crate rayon; extern crate rocksdb; -extern crate secp256k1; extern crate serde; extern crate stderrlog; extern crate sysconf; diff --git a/src/new_index/fetch.rs b/src/new_index/fetch.rs index d8d86fa..a291a23 100644 --- a/src/new_index/fetch.rs +++ b/src/new_index/fetch.rs @@ -2,7 +2,7 @@ use crate::chain::Block; use bitcoin::consensus::encode::{deserialize, serialize, Decodable}; use bitcoin::util::hash::BitcoinHash; -use bitcoin_hashes::sha256d::Hash as Sha256dHash; +use bitcoin::hashes::sha256d::Hash as Sha256dHash; use rayon::prelude::*; use std::collections::HashMap; diff --git a/src/new_index/mempool.rs b/src/new_index/mempool.rs index 1df91ab..1d1b913 100644 --- a/src/new_index/mempool.rs +++ b/src/new_index/mempool.rs @@ -1,6 +1,6 @@ use arraydeque::{ArrayDeque, Wrapping}; use bitcoin::consensus::encode::serialize; -use bitcoin_hashes::sha256d::Hash as Sha256dHash; +use bitcoin::hashes::sha256d::Hash as Sha256dHash; use itertools::Itertools; use std::collections::{BTreeSet, HashMap, HashSet}; diff --git a/src/new_index/query.rs b/src/new_index/query.rs index 468906a..1862acc 100644 --- a/src/new_index/query.rs +++ b/src/new_index/query.rs @@ -1,4 +1,4 @@ -use bitcoin_hashes::sha256d::Hash as Sha256dHash; +use bitcoin::hashes::sha256d::Hash as Sha256dHash; use rayon::prelude::*; use std::collections::{BTreeSet, HashMap}; diff --git a/src/new_index/schema.rs b/src/new_index/schema.rs index d94d207..111477b 100644 --- a/src/new_index/schema.rs +++ b/src/new_index/schema.rs @@ -1,7 +1,7 @@ use bincode; use bitcoin::blockdata::script::Script; use bitcoin::consensus::encode::{deserialize, serialize}; -use bitcoin_hashes::sha256d::Hash as Sha256dHash; +use bitcoin::hashes::sha256d::Hash as Sha256dHash; use crypto::digest::Digest; use crypto::sha2::Sha256; use itertools::Itertools; diff --git a/src/rest.rs b/src/rest.rs index 8edd77c..d2858c9 100644 --- a/src/rest.rs +++ b/src/rest.rs @@ -9,8 +9,8 @@ use crate::util::{ use bitcoin::consensus::encode::{self, serialize}; use bitcoin::{BitcoinHash, Script}; -use bitcoin_hashes::hex::{FromHex, ToHex}; -use bitcoin_hashes::{sha256d::Hash as Sha256dHash, Error as HashError}; +use bitcoin::hashes::hex::{FromHex, ToHex}; +use bitcoin::hashes::{sha256d::Hash as Sha256dHash, Error as HashError}; use futures::sync::oneshot; use hex::{self, FromHexError}; use hyper::rt::{self, Future, Stream}; @@ -1106,6 +1106,18 @@ impl From for HttpError { HttpError::from("Invalid hex string".to_string()) } } +impl From for HttpError { + fn from(_e: bitcoin::hashes::hex::Error) -> Self { + //HttpError::from(e.description().to_string()) + HttpError::from("Invalid hex string".to_string()) + } +} +impl From for HttpError { + fn from(_e: bitcoin::util::address::Error) -> Self { + //HttpError::from(e.description().to_string()) + HttpError::from("Invalid Bitcoin address".to_string()) + } +} impl From for HttpError { fn from(e: errors::Error) -> Self { warn!("errors::Error: {:?}", e); diff --git a/src/util/block.rs b/src/util/block.rs index 81d0005..43840ad 100644 --- a/src/util/block.rs +++ b/src/util/block.rs @@ -4,7 +4,7 @@ use crate::new_index::BlockEntry; use bitcoin::consensus::encode::serialize; use bitcoin::util::hash::BitcoinHash; -use bitcoin_hashes::sha256d::Hash as Sha256dHash; +use bitcoin::hashes::sha256d::Hash as Sha256dHash; use std::collections::HashMap; use std::fmt; diff --git a/src/util/merkle.rs b/src/util/merkle.rs index 2b8faf2..53dc7bb 100644 --- a/src/util/merkle.rs +++ b/src/util/merkle.rs @@ -1,4 +1,4 @@ -use bitcoin_hashes::{sha256d::Hash as Sha256dHash, Hash}; +use bitcoin::hashes::{sha256d::Hash as Sha256dHash, Hash}; use crate::errors::*; use crate::new_index::ChainQuery; diff --git a/src/util/mod.rs b/src/util/mod.rs index cadb70f..8aeeba4 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -15,7 +15,7 @@ use std::sync::mpsc::{channel, sync_channel, Receiver, Sender, SyncSender}; use std::thread; use crate::chain::BlockHeader; -use bitcoin_hashes::sha256d::Hash as Sha256dHash; +use bitcoin::hashes::sha256d::Hash as Sha256dHash; pub type Bytes = Vec; pub type HeaderMap = HashMap; diff --git a/src/util/script.rs b/src/util/script.rs index 6045182..3542c14 100644 --- a/src/util/script.rs +++ b/src/util/script.rs @@ -1,9 +1,4 @@ use bitcoin::blockdata::script::{Instruction::PushBytes, Script}; -use bitcoin::network::constants::Network as BNetwork; -use bitcoin::util::address; -use bitcoin_bech32::constants::Network as B32Network; -use bitcoin_bech32::{self, u5}; -use bitcoin_hashes::{hash160::Hash as Hash160, Hash}; #[cfg(feature = "liquid")] use elements::address as elements_address; @@ -28,36 +23,7 @@ pub fn script_to_address(script: &Script, network: &Network) -> Option { _ => (), }; - let payload = if script.is_p2pkh() { - address::Payload::PubkeyHash(Hash160::from_slice(&script[3..23]).ok()?) - } else if script.is_p2sh() { - address::Payload::ScriptHash(Hash160::from_slice(&script[2..22]).ok()?) - } else if script.is_v0_p2wpkh() || script.is_v0_p2wsh() { - let program = if script.is_v0_p2wpkh() { - script[2..22].to_vec() - } else { - script[2..34].to_vec() - }; - - address::Payload::WitnessProgram( - bitcoin_bech32::WitnessProgram::new( - u5::try_from_u8(0).expect("0<32"), - program, - B32Network::from(network), - ) - .unwrap(), - ) - } else { - return None; - }; - - Some( - address::Address { - payload, - network: BNetwork::from(network), - } - .to_string(), - ) + bitcoin::Address::from_script(script, network.into()).map(|s| s.to_string()) } pub fn get_script_asm(script: &Script) -> String { diff --git a/src/util/transaction.rs b/src/util/transaction.rs index 63d88e7..b8853f5 100644 --- a/src/util/transaction.rs +++ b/src/util/transaction.rs @@ -1,6 +1,6 @@ #[cfg(feature = "liquid")] -use bitcoin_hashes::hex::FromHex; -use bitcoin_hashes::sha256d::Hash as Sha256dHash; +use bitcoin::hashes::hex::FromHex; +use bitcoin::hashes::sha256d::Hash as Sha256dHash; use crate::chain::{TxIn, TxOut}; use crate::util::BlockId;