Last active
November 13, 2020 09:46
-
-
Save pwm/5500be87b7a298e280c1080c5373a53b to your computer and use it in GitHub Desktop.
lnd_pool_check
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
#!/usr/bin/env bash | |
set -euo pipefail | |
function getBatchInfo() { | |
batch=$(sudo su - pool -c "pool auction s ${1:-""}") | |
batch_id=$(echo "$batch" | jq -r '.batch_id') | |
prev_batch_id=$(echo "$batch" | jq -r '.prev_batch_id') | |
batch_tx_id=$(echo "$batch" | jq -r '.batch_tx_id') | |
asks=$(echo "$batch" | jq -r '[.matched_orders[].ask.rate_fixed] | max') | |
bids=$(echo "$batch" | jq -r '[.matched_orders[].bid.rate_fixed] | min') | |
block=$(bitcoin-cli getrawtransaction "$batch_tx_id" true) | |
blockhash=$(echo "$block" | jq -r '.blockhash') | |
confirmations=$(echo "$block" | jq -r '.confirmations') | |
blocktime=$(echo "$block" | jq -r '.blocktime') | |
humantime="null" | |
if [ "$blocktime" != "null" ]; then | |
humantime=$(echo "$blocktime" | xargs -I % date -d @%) | |
fi | |
json=$(cat <<EOF | |
{ | |
"batch_id": "$batch_id", | |
"prev_batch_id": "$prev_batch_id", | |
"batch_tx_id": "$batch_tx_id", | |
"blockhash": "$blockhash", | |
"confirmations": "$confirmations", | |
"blocktime": "$blocktime", | |
"humantime": "$humantime", | |
"max_ask": $asks, | |
"min_bid": $bids | |
} | |
EOF | |
) | |
echo "$json" | |
} | |
#### | |
cycles=${1:-3} | |
batch_id="" | |
c=1 | |
while [ $c -le "$cycles" ]; do | |
c=$((c+1)) | |
out=$(getBatchInfo "$batch_id") | |
batch_id=$(echo "$out" | jq -r '.prev_batch_id') | |
echo "$out" | jq . | |
if [ "$batch_id" == "null" ]; then | |
break | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment