-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitcoin-dash
134 lines (105 loc) · 4.94 KB
/
bitcoin-dash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
source ~/Rxs/colors
source /home/pi/.bitcoin/BTC_value #hacky thing defines $BTC0 to get wallet balance to flash when new incoming BTC arrives
#Network
#bytes up/down
bytes_rcv=$(echo "scale=4; $(bitcoin-cli getnettotals| jq .totalbytesrecv)/1000000000" | bc)
bytes_snt=$(echo "scale=4; $(bitcoin-cli getnettotals| jq .totalbytessent)/1000000000" | bc)
peers=$(bitcoin-cli getnetworkinfo | jq .connections)
outbound=$(bitcoin-cli getnetworkinfo | jq .connections_out)
inbound=$(bitcoin-cli getnetworkinfo | jq .connections_in)
#server up time
seconds=$(bitcoin-cli uptime)
#Wallet
if [ "$(bitcoin-cli getbalance)" \> "$BTC0" ]
then wallet=1
else wallet=0
fi
BTC_diff=$(echo "$(bitcoin-cli getbalance)-$BTC0" | bc)
#BTC and $US info
BTC0=$(bitcoin-cli getbalance)
BTC1=$(curl -s http://api.coindesk.com/v1/bpi/currentprice/usd.json | jq -r .bpi.USD.rate | cut -d \. -f1)
BTC2=$(curl -s http://api.coindesk.com/v1/bpi/currentprice/usd.json | jq .bpi.USD.rate_float)
BTC_US=$(echo "scale=2; ($BTC0*$BTC2)/1" | bc | sed -r ':L;s=\b([0-9]+)([0-9]{3})\b=\1,\2=g;t L' | cut -d \. -f1)
#miner fees and fees per tx
feerate=$(curl -s "https://mempool.space/api/v1/fees/recommended" | jq .hourFee) # fee in satoshis/byte
miner_fee_US=$(echo "scale=2; ($feerate*144*.00000001*$BTC2)/1" | bc) # 144 is average transaction size in bytes
miner_fee_BTC=$(echo "$feerate*144*.00000001" | bc) # 144 is average transaction size in bytes
#Blockchain
#get last 3 blocks
block0=$(bitcoin-cli getblockcount)
block1=$(expr $block0 - 1)
block2=$(expr $block0 - 2)
#format last 3 blocks with thousands separator
block0_fmt=$(echo $block0 | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta')
block1_fmt=$(echo $block1 | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta')
block2_fmt=$(echo $block2 | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta')
#get timestamps for last 3 blocks
now=$(date +'%s')
block0_time=$(bitcoin-cli getblock $(bitcoin-cli getblockhash $block0) | jq .time)
block1_time=$(bitcoin-cli getblock $(bitcoin-cli getblockhash $block1) | jq .time)
block2_time=$(bitcoin-cli getblock $(bitcoin-cli getblockhash $block2) | jq .time)
#block__time=$(bitcoin-cli getblock $(bitcoin-cli getblockhash 0) | jq .time)
block__time=1231006505
#elapsed time calculation for last 3 blocks
block0_age=$(echo "($now-$block0_time)/60" | bc)
block1_age=$(echo "($now-$block1_time)/60" | bc)
block2_age=$(echo "($now-$block2_time)/60" | bc)
block__age=$(echo "($now-$block__time)" | bc) #genesis block
genesis_block2=$(printf '%dyr:%dmo:%dd \n' $(($block__age/31556926)) $(($block__age%31556926/2629743)) $(($block__age%2629743/86400))) #$(($block__age%86400/3600)) $(($block__age%3600/60)))
genesis_block=$(printf '%dyr:%dd:%dh:%dm \n' $(($block__age/31556926)) $(($block__age%31556926/86400)) $(($block__age%86400/3600)) $(($block__age%3600/60)))
#number of tx in memory pool
mem_pool=$(bitcoin-cli getmempoolinfo | jq .size | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta')
#Output
output=$(
#echo -e "\e[1m\e[32mBitcoin Stats\e[0m"
echo -e $bold$(bitcoind -version | grep version)" "$(date -I)$off
echo
echo 1 BTC = "$"$BTC1
#echo
echo -e "\e[32mWallet\e[0m"
if [ $wallet = 1 ]
then
echo -e "\e[5m\e[42mBTC:\e[0m $BTC0 +$BTC_diff"
ssh [email protected] 'mpg123 -q - ' < /home/pi/.bitcoin/cash.mp3
else echo BTC: $BTC0
fi
echo "US$: "$BTC_US
echo -e $green"Recommended Miner Fees"$off
echo Satoshis/vByte: $feerate
echo "BTC(\$US)/tx: "$miner_fee_BTC"($"$miner_fee_US")"
echo
echo -e "\e[32mBlockchain\e[0m"
echo Block: $block0_fmt Age: $block0_age minutes
echo Block: $block1_fmt Age: $block1_age minutes
echo Block: $block2_fmt Age: $block2_age minutes
echo "Block: 0 Age: "$genesis_block2
echo Mempool: $mem_pool
#echo $block__age seconds elapsed since block 0
echo
echo -e "\e[32mNetwork\e[0m"
echo GBs recv: $bytes_rcv
echo GBs sent: $bytes_snt
echo Inbound Connections: $inbound
echo Outbound Connections: $outbound
echo
echo -e "\e[32mServer UpTime\e[0m"
printf '%dmo:%dd:%dh:%dm:%ds \n' $(($seconds/2629743)) $(($seconds%2629743/86400)) $(($seconds%86400/3600)) $(($seconds%3600/60)) $(($seconds%60))
echo
#show available space on / and blockchain size on data partition
echo -e "\e[32mStorage\e[0m"
df -h --output='target','size','used','avail','pcent'| grep -w Mounted
df -h --output='target','size','used','avail','pcent'| grep -w /
df -h --output='target','size','used','avail','pcent'| grep -w /mnt/crypto
) ###this bracket ends $output variable#####
echo "$output"
echo BTC0=$BTC0 > /home/pi/.bitcoin/BTC_value
#write out some variables for troubleshooting in case bitcoind shuts down
date > node_down_log
echo Block: $block0_fmt Age: $block0_age minutes >> node_down_log
echo Mempool: $mem_pool >> node_down_log
echo >> node_down_log
echo Total Connections: $peers >> node_down_log
printf 'Server UpTime: %dd:%dh:%dm:%ds \n' $(($seconds/86400)) $(($seconds%86400/3600)) $(($seconds%3600/60)) $(($seconds%60)) >> node_down_log
echo >> node_down_log
free -m >> node_down_log