2
\$\begingroup\$

I wrote a little bash script that displays the transaction info in json:

#!/usr/bin/env bash
set -e
set -o errexit

function process_block() {
  date --rfc-3339=ns
  bhash=${1:-$(bitcoin-cli getbestblockhash)}
  block=$(bitcoin-cli getblock $bhash)
  pbhash=$(echo "$block" | jq -r .previousblockhash)
  height=$(echo "$block" | jq -r .height)
  echo "height: $height"
  nTx=$(echo "$block" | jq -r .nTx)
  echo "$nTx transactions"
  Tx=$(echo "$block" | jq -r .tx[])
  IFS=$'\n'
  for txhash in $Tx; do
    txjson=$(bitcoin-cli getrawtransaction $txhash 1 $bhash)
    addresses=$(echo "$txjson" | jq -r '.vout[].scriptPubKey | select(.type == "pubkeyhash") | .addresses | .[]')
    for a in $addresses; do
      if [[ $a == ${2} ]]; then
        echo "$txjson"
      fi
    done
  done
  process_block $pbhash ${2}
}

process_block "" ${1}

Can be used as:

./btc.sh 1...

I ran bitcoind in pruned mode to get a blockchain. I downloaded the latest snapshot like this:

aria2c http://utxosets.blob.core.windows.net/public/$(curl https://raw.githubusercontent.com/btcpayserver/btcpayserver-docker/master/contrib/FastSync/utxo-sets | grep -F mainnet | tail -n 1 | grep -Po utxo.*)

The only problem is that it is really slow. It takes about a minute to process about 1k transactions. Any advice how the things could be speed up?

\$\endgroup\$
  • \$\begingroup\$ I am currently rebuilding the whole blockchain with -txindex option. But I don't know how many days/weeks it can take. \$\endgroup\$ – reardenlife Aug 31 '19 at 20:43
  • \$\begingroup\$ Wait a second. Actually I was rebuilding with -reindex option and -txindex is incompatible with prune mode. I interrupted the process to check it out, then resumed it and it is started from the beginning of the blockchain basically ruining 3 days of servers's work. I guess I have to wait till the end without any interruption with -reindex option to see if it will help.. \$\endgroup\$ – reardenlife Sep 2 '19 at 16:40
  • \$\begingroup\$ Nah. It is unlikely it will help anyhow w/o txindex. I should probably find other ways how to speed up my explorer. \$\endgroup\$ – reardenlife Sep 2 '19 at 16:49
  • \$\begingroup\$ Alright. We got getblock with verbosity = 2 here. :) github.com/bitcoin/bitcoin/issues/12651#issuecomment-527418478 \$\endgroup\$ – reardenlife Sep 3 '19 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.