diff --git a/Cargo.lock b/Cargo.lock index 7fef399bf..4c2ce8b81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -55,15 +55,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "autocfg" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dde43e75fd43e8a1bf86103336bc699aa8d17ad1be60c76c0bdfd4828e19b78" -dependencies = [ - "autocfg 1.1.0", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -106,6 +97,12 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf9ff0bbfd639f15c74af777d81383cf53efb7c93613f6cab67c6c11e05bbf8b" +[[package]] +name = "bech32" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" + [[package]] name = "bincode" version = "1.3.3" @@ -140,7 +137,7 @@ version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a41df6ad9642c5c15ae312dd3d074de38fd3eb7cc87ad4ce10f90292a83fe4d" dependencies = [ - "bech32", + "bech32 0.8.1", "bitcoin_hashes 0.10.0", "secp256k1 0.20.3", "serde", @@ -148,16 +145,24 @@ dependencies = [ [[package]] name = "bitcoin" -version = "0.28.0" +version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42b2a9a8e3c7544f5ce2b475f2f56580a3102b37e0ee001558ad4faedcf56cf4" +checksum = "4e99ff7289b20a7385f66a0feda78af2fc119d28fb56aea8886a9cd0a4abdd75" dependencies = [ - "bech32", - "bitcoin_hashes 0.10.0", - "secp256k1 0.22.1", + "bech32 0.9.1", + "bitcoin-private", + "bitcoin_hashes 0.12.0", + "hex_lit", + "secp256k1 0.27.0", "serde", ] +[[package]] +name = "bitcoin-private" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73290177011694f38ec25e165d0387ab7ea749a4b81cd4c80dae5988229f7a57" + [[package]] name = "bitcoin_hashes" version = "0.7.6" @@ -173,6 +178,16 @@ dependencies = [ "serde", ] +[[package]] +name = "bitcoin_hashes" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d7066118b13d4b20b23645932dfb3a81ce7e29f95726c2036fa33cd7b092501" +dependencies = [ + "bitcoin-private", + "serde", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -266,15 +281,6 @@ dependencies = [ "vec_map", ] -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags", -] - [[package]] name = "crossbeam-channel" version = "0.5.4" @@ -302,7 +308,7 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c" dependencies = [ - "autocfg 1.1.0", + "autocfg", "cfg-if", "crossbeam-utils", "lazy_static", @@ -354,7 +360,7 @@ dependencies = [ "arrayref", "base64 0.13.0", "bincode", - "bitcoin 0.28.0", + "bitcoin 0.30.1", "clap", "crossbeam-channel", "dirs", @@ -362,7 +368,7 @@ dependencies = [ "elements", "error-chain", "glob", - "hex", + "hex-conservative", "hyper", "hyperlocal", "itertools", @@ -407,12 +413,11 @@ dependencies = [ [[package]] name = "elements" -version = "0.19.1" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61c5ef61d480567b862631efcc22f704eeed7291dbf929ae008a8d5b7f5c4527" +checksum = "686e85412860d3ac25988e55da4d65541714f1318bf10fd81711e08cbfdcf5b4" dependencies = [ - "bitcoin 0.28.0", - "bitcoin_hashes 0.10.0", + "bitcoin 0.30.1", "secp256k1-zkp", "serde", "serde_json", @@ -571,6 +576,18 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hex-conservative" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ed443af458ccb6d81c1e7e661545f94d3176752fb1df2f543b902a1e0f51e2" + +[[package]] +name = "hex_lit" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd" + [[package]] name = "http" version = "0.2.6" @@ -750,7 +767,7 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" dependencies = [ - "autocfg 1.1.0", + "autocfg", "scopeguard", ] @@ -781,7 +798,7 @@ version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -847,7 +864,7 @@ version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" dependencies = [ - "autocfg 1.1.0", + "autocfg", "num-traits", ] @@ -857,7 +874,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -973,6 +990,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + [[package]] name = "proc-macro2" version = "1.0.37" @@ -1037,31 +1060,23 @@ dependencies = [ [[package]] name = "rand" -version = "0.6.5" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "autocfg 0.1.8", "libc", "rand_chacha", - "rand_core 0.4.2", - "rand_hc", - "rand_isaac", - "rand_jitter", - "rand_os", - "rand_pcg", - "rand_xorshift", - "winapi 0.3.9", + "rand_core 0.6.4", ] [[package]] name = "rand_chacha" -version = "0.1.1" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ - "autocfg 0.1.8", - "rand_core 0.3.1", + "ppv-lite86", + "rand_core 0.6.4", ] [[package]] @@ -1080,65 +1095,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" [[package]] -name = "rand_hc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi 0.3.9", -] - -[[package]] -name = "rand_os" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.4.2", - "rdrand", - "winapi 0.3.9", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg 0.1.8", - "rand_core 0.4.2", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.1" +name = "rand_core" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "rand_core 0.3.1", + "getrandom", ] [[package]] @@ -1147,7 +1109,7 @@ version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd249e82c21598a9a426a4e00dd7adc1d640b22445ec8545feef801d1a74c221" dependencies = [ - "autocfg 1.1.0", + "autocfg", "crossbeam-deque", "either", "rayon-core", @@ -1331,13 +1293,13 @@ dependencies = [ [[package]] name = "secp256k1" -version = "0.22.1" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26947345339603ae8395f68e2f3d85a6b0a8ddfe6315818e80b8504415099db0" +checksum = "25996b82292a7a57ed3508f052cfff8640d38d32018784acd714758b43da9c8f" dependencies = [ - "bitcoin_hashes 0.10.0", - "rand 0.6.5", - "secp256k1-sys 0.5.0", + "bitcoin_hashes 0.12.0", + "rand 0.8.5", + "secp256k1-sys 0.8.1", "serde", ] @@ -1352,33 +1314,34 @@ dependencies = [ [[package]] name = "secp256k1-sys" -version = "0.5.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07b5b9d7322572e1f3aeed208668ce87789b3645dbb73082c5ce99a004103a35" +checksum = "70a129b9e9efbfb223753b9163c4ab3b13cff7fd9c7f010fbac25ab4099fa07e" dependencies = [ "cc", ] [[package]] name = "secp256k1-zkp" -version = "0.6.0" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c724fda6aae465ed9a39320202bc6164e0adb3cdf9bc16d5af4be7eebaba75e5" +checksum = "026efcdacb95ee6aae5cc19144dc1549973eac36a4972700c28493de1ee5d69f" dependencies = [ - "rand 0.6.5", - "secp256k1 0.22.1", + "bitcoin-private", + "rand 0.8.5", + "secp256k1 0.27.0", "secp256k1-zkp-sys", "serde", ] [[package]] name = "secp256k1-zkp-sys" -version = "0.6.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6f880412a627e79d3ce17355150ea1e0e76570efb7f0f70df51504cbe2582e3" +checksum = "d03ab1ca75a18e1899e8d9b8d28b5998ae1ddcb42fec5956769718543293c723" dependencies = [ "cc", - "secp256k1-sys 0.5.0", + "secp256k1-sys 0.8.1", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 7b8ec562c..7c4d2da86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,14 +22,14 @@ arraydeque = "0.4" arrayref = "0.3.6" base64 = "0.13.0" bincode = "1.3.1" -bitcoin = { version = "0.28", features = [ "use-serde" ] } +bitcoin = { version = "0.30.1", features = [ "serde" ] } clap = "2.33.3" crossbeam-channel = "0.5.0" dirs = "4.0.0" -elements = { version = "0.19.1", features = [ "serde-feature" ], optional = true } +elements = { version = "0.23.0", features = [ "serde" ], optional = true } error-chain = "0.12.4" glob = "0.3" -hex = "0.4.2" +hex = { package = "hex-conservative", version = "0.1.1" } itertools = "0.10" lazy_static = "1.3.0" libc = "0.2.81" diff --git a/contrib/check-api-stablity.sh b/contrib/check-api-stablity.sh new file mode 100644 index 000000000..23e77b083 --- /dev/null +++ b/contrib/check-api-stablity.sh @@ -0,0 +1,93 @@ +#!/bin/bash + +set -eo pipefail +shopt -s expand_aliases + +# A simple script for checking HTTP API stability by comparing the responses +# between two running electrs instances connected to a regtest node backend. + +: ${NODE_DIR?missing NODE_DIR} # for bitcoind/elementds +: ${ELECTRS1_URL?missing ELECTRS1_URL} +: ${ELECTRS2_URL?missing ELECTRS2_URL} +# Set ELEMENTS_CHAIN for Elements-based chains (e.g. to 'elementsregtest') + +alias cli="$([[ -z $ELEMENTS_CHAIN ]] && echo bitcoin-cli -regtest || echo elements-cli -chain=$ELEMENTS_CHAIN) -datadir=$NODE_DIR" + +check() { + echo "Checking GET $1 ..." + local res1=$(curl -f -s "$ELECTRS1_URL$1" || echo "Request to ELECTRS1 failed") + local res2=$(curl -f -s "$ELECTRS2_URL$1" || echo "Request to ELECTRS2 failed") + { if [[ "$res1" = "{"* || "$res1" = "["* ]]; then + # Use `jq` for canonicalized ordering and to display a diff of beautified JSON + local sort_arr='walk(if type == "array" then sort else . end)' + diff -u1 <(jq --sort-keys "$sort_arr" <<< $res1) <(jq --sort-keys "$sort_arr" <<< $res2) + else + diff -u1 <(echo "$res1") <(echo "$res2") + fi } && echo OK || echo No match +} + +sync() { pkill -USR1 electrs; sleep 1; } + +# Ensure both electrs instances are connected to the same node backend +check /blocks/tip/hash + +# Send an unconfirmed transaction +address=$(cli getnewaddress) +txid=$(cli sendtoaddress $address 1.234) +sync +check /address/$address +check /address/$address/txs +check /address/$address/utxo +check /tx/$txid +check /mempool +check /mempool/recent + +# Mine a block confirming the transaction +blockhash=$(cli -generate 1 | jq -r .blocks[0]) +sync +check /block/$blockhash +check /block/$blockhash/txs +check /blocks +check /address/$address +check /address/$address/txs +check /address/$address/utxo +check /tx/$txid + +# Elements-only tests +if [[ -n $ELEMENTS_CHAIN ]]; then + # Test non-confidential transaction + uc_address=$(cli getaddressinfo $address | jq -r .unconfidential) + uc_txid=$(cli sendtoaddress $uc_address 5.678) + sync + check /address/$uc_address + check /tx/$uc_txid + + # Test asset issuance (blinded w/o contract hash & unblinded w/ contract hash) + asset1=$(cli issueasset 10 20 true) + asset2=$(cli issueasset 30 40 false 3333333333333333333333333333333333333333333333333333333333333333) + sync + check_asset() { + check /asset/$(jq -r .asset <<< $1) + check /tx/$(jq -r .txid <<< $1) # issuance tx + } + check_asset "$asset1" + check_asset "$asset2" + cli -generate 1 > /dev/null + sync + check_asset "$asset1" + check_asset "$asset2" + + # Test transactions transferring an issued asset (confidential & non-confidential) + asset1_id=$(jq -r .asset <<< $asset1) + asset2_id=$(jq -r .asset <<< $asset2) + i_txid=$(cli -named sendtoaddress address=$address amount=0.987 assetlabel=$asset1_id) + i_uc_txid=$(cli -named sendtoaddress address=$uc_address amount=0.654 assetlabel=$asset2_id) + sync + check /tx/$i_txid + check /tx/$i_uc_txid + check /address/$uc_address + check /address/$uc_address/utxo + + # Test issuance with no reissuance tokens + check_asset "$(cli issueasset 10 0 false && sync)" +fi \ No newline at end of file diff --git a/src/bin/popular-scripts.rs b/src/bin/popular-scripts.rs index 3c75e3e35..0f0976449 100644 --- a/src/bin/popular-scripts.rs +++ b/src/bin/popular-scripts.rs @@ -5,6 +5,7 @@ use electrs::{ config::Config, new_index::{Store, TxHistoryKey}, }; +use hex::DisplayHex; fn main() { let config = Config::from_args(); @@ -30,7 +31,11 @@ fn main() { if curr_scripthash != entry.hash { if total_entries > 100 { - println!("{} {}", hex::encode(&curr_scripthash), total_entries); + println!( + "{} {}", + curr_scripthash.to_lower_hex_string(), + total_entries + ); } curr_scripthash = entry.hash; @@ -45,7 +50,7 @@ fn main() { if total_entries >= 4000 { println!( "scripthash,{},{}", - hex::encode(&curr_scripthash), + curr_scripthash.to_lower_hex_string(), total_entries ); } diff --git a/src/bin/tx-fingerprint-stats.rs b/src/bin/tx-fingerprint-stats.rs index f3ccf45e0..da5318547 100644 --- a/src/bin/tx-fingerprint-stats.rs +++ b/src/bin/tx-fingerprint-stats.rs @@ -9,7 +9,7 @@ fn main() { use std::collections::HashSet; use std::sync::Arc; - use bitcoin::blockdata::script::Script; + use bitcoin::blockdata::script::ScriptBuf; use bitcoin::consensus::encode::deserialize; use electrs::{ chain::Transaction, @@ -118,7 +118,7 @@ fn main() { // test for sending back to one of the spent spks let has_reuse = { - let prev_spks: HashSet