Skip to content

Commit 9bcd3d0

Browse files
committed
cotrib: add a helper script to show miner of a bkock
1 parent 2adfcd2 commit 9bcd3d0

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

contrib/showminer.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#! /bin/bash
2+
3+
read -r -d '' help << EOM
4+
$0 - helper script for displaying miner of a mined block.
5+
6+
Options:
7+
8+
-h Display this message.
9+
10+
--height Specify blockheight.
11+
--hash Specify blockhash.
12+
EOM
13+
14+
while getopts ":h-:" optchar; do
15+
case "${optchar}" in
16+
-)
17+
case "${OPTARG}" in
18+
hash)
19+
blockhash="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
20+
;;
21+
height)
22+
blockheight="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
23+
blockhash=$(lbcctl getblockhash ${blockheight})
24+
;;
25+
*) echo "Unknown long option --${OPTARG}" >&2; exit -2 ;;
26+
esac
27+
;;
28+
h) printf "${help}\n\n"; exit 2;;
29+
*) echo "Unknown option -${OPTARG}" >&2; exit -2;;
30+
esac
31+
done
32+
33+
34+
block=$(lbcctl getblock $blockhash)
35+
blockheight=$(lbcctl getblock $blockhash | jq -r .height)
36+
37+
coinbase_txid=$(echo ${block} | jq -r '.tx[0]')
38+
coinbase_raw=$(lbcctl getrawtransaction ${coinbase_txid} 1)
39+
coinbase=$(echo ${coinbase_raw} | jq '.vin[0].coinbase')
40+
miner=$(echo ${coinbase} | grep -o '2f.*2f' | xxd -r -p | strings)
41+
42+
echo ${blockheight}: ${blockhash}: ${miner}

0 commit comments

Comments
 (0)