Title: [BASH] Script to get and process transactions by hash (bitcoin-cli wrapper) Post by: naufragus on October 01, 2020, 01:46:52 AM Hello guys!
It has been some months my working on some bash scripts. These scripts warp arounf bitcoin-cli rpc calls to parse block and transaction data. Just give it the trasaction hash or block hash/height As i wrote some wrappers for blockchain.com APIs, I wanted to get more or less the same information. I used functions from grondilu's bitcoin-bash-tools.. Before trying the scripts, one needs have bitcoin-cli, openssl, jq and bash (v4 or above) installed. Also, that is a very good idea to have bitcoin-cli set with txindex=1 (otherwise you will need supply the block hash for the transactions and some addresses will not be coded to base58 from their hex). The scripts are at https://github.com/mountaineerbr/scripts There are two scripts, one for getting block information and transaction hashes in that block, and another to get transaction information by transaction hash. For example: Get info of a transaction by its hash id: Code: $ bitcoin.tx.sh a8bb9571a0667d63eaaaa36f9de87675f0d430e13c916248ded1d13093a77561 The output: Code: -------- One can parse all transactions from a block (ex: height 400000) using my two scripts, such as: Code: $ bitcoin.blk.sh -ii 400000 | bitcoin.tx.sh I have been checking some blockchair parses that try to parse binary blockchain data, which don't output as much useful information (at least for me, a regular user) of a transaction as my script do. The transaction script (bitcoin.tx.sh) is slow because depending on the transaction vins and vouts it needs query previous transactions, too. This script can take from a fraction of a second for a simple transaction up to a few seconds to parse a transaction with various in and out vectors. Transaction from block 400000 and 668385 took approximately 12 minutes and 18 minutes to parse, respectively with my script (intel i7). The script (bitcoin.blk.sh) for parsing block data can also decode transaction hex of coinbase. Decode coinbase from block height 668385: Code: $ bitcoin.blk.sh -y 668385 And the bitcoin.hx.sh will help you guys encoding and decoding public and private keys (legacy addresses only), as well as decoding hex strings that you may get from the blockchain. The scripts contain a help page, print with -h : https://github.com/mountaineerbr/scripts Cheers, |