Skip to content

Commit

Permalink
fix awk usage
Browse files Browse the repository at this point in the history
- The issue was that awk was performing the comparison with limited precision, which could lead to incorrect results with very small differences.
- This modification passes the $SYNCED value to awk as a variable, which avoids potential issues with shell variable expansion inside the awk command. It should correctly handle the floating-point comparison.
  • Loading branch information
bap2pecs committed Oct 19, 2024
1 parent 3f7397b commit 6f6ba4f
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ SYNCED=$(docker exec bitcoindsim /bin/sh -c "
-rpcuser=rpcuser \
-rpcpassword=rpcpass \
getblockchaininfo" | jq -r '.verificationprogress')
if (( $(awk 'BEGIN {print ($SYNCED < 0.999)}') )); then
if (( $(awk -v synced="$SYNCED" 'BEGIN {print (synced < 0.999)}') )); then
echo "Error: Bitcoin node is not fully synced. Expected at least 99.9%, got ${SYNCED}"
exit 1
fi
Expand Down Expand Up @@ -82,7 +82,7 @@ BALANCE_BTC=$(docker exec bitcoindsim /bin/sh -c "
-rpcpassword=rpcpass \
-rpcwallet=btcstaker \
listunspent" | jq -r '[.[] | .amount] | add')
if (( $(awk 'BEGIN {print ($BALANCE_BTC < 0.01)}') )); then
if (( $(awk -v balance="$BALANCE_BTC" 'BEGIN {print (balance < 0.01)}') )); then
echo "Warning: BTCStaker balance is less than 0.01 BTC. You may need to fund this address for ${BITCOIN_NETWORK}."
else
echo "BTCStaker balance is sufficient: ${BALANCE_BTC} BTC"
Expand Down

0 comments on commit 6f6ba4f

Please sign in to comment.