Last active
July 11, 2020 07:37
-
-
Save tumf/70882949e523d297e6a5a1e93d10276c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# UTXO checker for Bitcoin mainnet | |
api=https://blockstream.info/api | |
function usage() | |
{ | |
cat <<-EOF | |
usage: $(basename $0) tx_id index | |
EOF | |
} | |
commands='jq curl' | |
for c in $commands; do | |
hash $c || { echo "install $c"; exit 255; } | |
done | |
tx=$1 | |
index=$2 | |
[ -n "$tx" ] || { usage; exit 255; } | |
[ -n "$index" ] || { usage; exit 255; } | |
result=$(curl -s "${api}/tx/$tx/outspends" | jq ".[${index}].spent") | |
[ "$result" = "null" ] && { echo 'invalid'; exit 255; } | |
value=$(curl -s "${api}/tx/$tx" | jq ".vout[${index}].value") | |
[ "$result" = "false" ] && { echo "$value unspent"; exit 0; } | |
[ "$result" = "true" ] && { echo "$value spent"; exit 1; } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment