|
#!/bin/bash |
|
|
|
# update electrumx banner to report bitcoin memory pool, fees, height and time since last block |
|
# activate with cron job similar to this |
|
#*/2 * * * * ~/bin/update-electrumx-banner |
|
|
|
# specify your bitcoin-cli location |
|
BITCOIN_CLI=/usr/local/bin/bitcoin-cli |
|
|
|
# specify your bitcoin data directory |
|
#BITCOIN_DATADIR=/home/bitcoin/.bitcoin |
|
|
|
# specify the location of your electrumx banner file |
|
# note: uses %{BANNER}.template as the template (top portion) of each banner update |
|
BANNER=/home/electrumx/.electrumx/banner |
|
|
|
# save initial banner as template for creation of new banners |
|
if [ ! -f ${BANNER}.template ]; then |
|
cp ${BANNER} ${BANNER}.template |
|
fi |
|
|
|
# create new banner from template |
|
cp ${BANNER}.template ${BANNER}.new |
|
|
|
# mempool |
|
#MEMPOOL=`${BITCOIN_CLI} -datadir=${BITCOIN_DATADIR} getmempoolinfo | grep size | grep -o '[0-9\.]*'` |
|
MEMPOOL=`${BITCOIN_CLI} getmempoolinfo | grep size | grep -o '[0-9\.]*'` |
|
|
|
# report last block and current height from electrumx journal |
|
TFILE=/home/electrumx/.electrumx/tmp/btcfees-$$ |
|
journalctl --since "6 hours ago" -u electrumx -o short-iso --utc | grep Prefetcher:new | tail -n 1 > ${TFILE} |
|
if [ `wc -c < ${TFILE}` -gt 10 ]; then |
|
block_height=`< ${TFILE} awk '{print $7}'` |
|
block_time=`< ${TFILE} awk '{print $1}'` |
|
block_utime=`date -ud $block_time +'%s'` |
|
now_utime=`date +'%s'` |
|
minutes_ago=`echo ${now_utime} ${block_utime} | awk '{print int(($1-$2)/6)/10}'` |
|
fi |
|
rm ${TFILE} |
|
|
|
# Header info |
|
echo "_______________________________________________________________________________________________" >> ${BANNER}.new |
|
echo "___" >> ${BANNER}.new |
|
printf "___ $(date +%d.%m.%Y' '%H:%M) / Last Block: ${block_height} (${minutes_ago} mins ago) / Mem Pool: ${MEMPOOL} /\n" >> ${BANNER}.new |
|
echo "____________________________________________________________________________________________" >> ${BANNER}.new |
|
echo "___" >> ${BANNER}.new |
|
|
|
# get exchange rate and average fee per satoshi |
|
if ${BITCOIN_CLI} --version | grep -q ABC; then |
|
USDPERBTC=`curl -m 10 -L -s 'https://apiv2.bitcoinaverage.com/indices/global/ticker/BCHUSD' | python3 -c 'import sys, json; j=json.load(sys.stdin); print(j["last"])'` |
|
EURPERBTC=`curl -m 10 -L -s 'https://apiv2.bitcoinaverage.com/indices/global/ticker/BCHEUR' | python3 -c 'import sys, json; j=json.load(sys.stdin); print(j["last"])'` |
|
CHFPERBTC=`curl -m 10 -L -s 'https://apiv2.bitcoinaverage.com/indices/global/ticker/BCHCHF' | python3 -c 'import sys, json; j=json.load(sys.stdin); print(j["last"])'` |
|
TICKER=BCH |
|
BYTESPERTX=226 |
|
else |
|
USDPERBTC=`curl -m 10 -L -s 'https://apiv2.bitcoinaverage.com/indices/global/ticker/BTCUSD' | python3 -c 'import sys, json; j=json.load(sys.stdin); print(j["last"])'` |
|
EURPERBTC=`curl -m 10 -L -s 'https://apiv2.bitcoinaverage.com/indices/global/ticker/BTCEUR' | python3 -c 'import sys, json; j=json.load(sys.stdin); print(j["last"])'` |
|
CHFPERBTC=`curl -m 10 -L -s 'https://apiv2.bitcoinaverage.com/indices/global/ticker/BTCCHF' | python3 -c 'import sys, json; j=json.load(sys.stdin); print(j["last"])'` |
|
TICKER=BTC |
|
BYTESPERTX=168 |
|
fi |
|
USDPERSAT=`echo ${USDPERBTC} | awk '{print $1/100000000}'` |
|
|
|
echo "___ ${USDPERBTC} USD/${TICKER} / ${EURPERBTC} EUR/${TICKER} / ${CHFPERBTC} CHF/${TICKER} / " >> ${BANNER}.new |
|
echo "_________________________________________________________________________________________" >> ${BANNER}.new |
|
echo "___" >> ${BANNER}.new |
|
|
|
# report fees for various block times |
|
for BLOCKS in 2 6 12 24 144 504 1008 |
|
do |
|
# SATPERBYTE=`${BITCOIN_CLI} -datadir=${BITCOIN_DATADIR} estimatesmartfee ${BLOCKS} | grep feerate | grep -o '[0-9\.\-]*' | awk '{print $1*100000+0.5}'` |
|
SATPERBYTE=`${BITCOIN_CLI} estimatesmartfee ${BLOCKS} | grep feerate | grep -o '[0-9\.\-]*' | awk '{print $1*100000+0.5}'` |
|
if [ `echo ${SATPERBYTE} | awk '{print int($1)}'` -lt 1 ]; then |
|
break; |
|
fi |
|
echo ${BLOCKS} ${SATPERBYTE} ${BYTESPERTX} ${USDPERSAT} | awk '{printf "___ Fee to confirm within %d blocks (%s hours) = %d sat/B ($%0.2f)\n", $1, int($1/0.06)/100, $2, $2*$3*$4, 1 }' >> ${BANNER}.new |
|
done |
|
echo "________________________________________________________________________________" >> ${BANNER}.new |
|
|
|
|
|
# save backup of original banner on first run (just in case...) |
|
if [ ! -f ${BANNER}.backup ]; then |
|
cp ${BANNER} ${BANNER}.backup |
|
fi |
|
|
|
# replace banner with newly generated version |
|
mv ${BANNER}.new ${BANNER} |