-
Notifications
You must be signed in to change notification settings - Fork 4
/
geld.sh
84 lines (72 loc) · 2.32 KB
/
geld.sh
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
#!/usr/bin env bash
set -e -u -o pipefail
ord_fingerprint="0063036f7264"
# default values
rpcuser="bitcoinrpc"
rpcpassword="password"
rpchost="localhost"
rpcport="8332"
startblock=1
chain="main"
while getopts ":u:p:h:P:s:c:" opt; do
case $opt in
u)
rpcuser=$OPTARG
;;
p)
rpcpassword=$OPTARG
;;
h)
rpchost=$OPTARG
;;
P)
rpcport=$OPTARG
;;
s)
startblock=$OPTARG
;;
c)
chain=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
if [ -f "lastblock.txt" ]; then
lastblock=$(cat lastblock.txt)
else
lastblock=$startblock
fi
while true; do
blockheight=$(bitcoin-cli -chain=$chain -rpcuser=$rpcuser -rpcpassword=$rpcpassword -rpcport=$rpcport -rpcconnect=$rpchost getblockcount)
for ((i=$lastblock; i<$blockheight; i++)); do
blockhash=$(bitcoin-cli -chain=$chain -rpcuser=$rpcuser -rpcpassword=$rpcpassword -rpcport=$rpcport -rpcconnect=$rpchost getblockhash $i)
block=$(bitcoin-cli -chain=$chain -rpcuser=$rpcuser -rpcpassword=$rpcpassword -rpcport=$rpcport -rpcconnect=$rpchost getblock $blockhash)
transactions=$(echo $block | jq -r '.tx[]')
for transaction in $transactions; do
# skip the coinbase
if [ $transaction == $(echo $block | jq -r '.tx[0]') ]; then
continue
fi
tx=$(bitcoin-cli -chain=$chain -rpcuser=$rpcuser -rpcpassword=$rpcpassword -rpcport=$rpcport -rpcconnect=$rpchost getrawtransaction $transaction 1)
if [ $(echo $tx | jq -r '.vin[].txinwitness | length') -eq 0 ]; then
continue
fi
vins=$(echo $tx | jq -r '.vin[]')
echo $tx | jq -c '.vin[]' | while read -r vins; do
txwitness=$(echo $vins | jq -r '.txinwitness[]')
if [ ${#txwitness} -ge 2 ] && [[ $txwitness == *"$ord_fingerprint"* ]]; then
echo "Shitcoining detected at block height $i! They lied to the code and must be punished! DEUS VULT!"
echo "Block hash: $blockhash"
bitcoin-cli -chain=$chain -rpcuser=$rpcuser -rpcpassword=$rpcpassword -rpcport=$rpcport -rpcconnect=$rpchost invalidateblock $blockhash
break
fi
done
done
echo "done processing block $i"
echo $i > lastblock.txt
done
echo "bitcoin never sleeps, but I do. sleeping for 60 seconds"
sleep 60
done