From 2118d06300bd3af93943b62004a6b0e53405ce79 Mon Sep 17 00:00:00 2001 From: Cryp Toon Date: Mon, 25 Mar 2024 21:03:14 +0100 Subject: [PATCH] Fix bc error with scientific numbers in txfee_calc --- 04_2__Interlude_Using_JQ.md | 2 +- src/04_2_i_txfee-calc.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/04_2__Interlude_Using_JQ.md b/04_2__Interlude_Using_JQ.md index b516fe2..698beef 100644 --- a/04_2__Interlude_Using_JQ.md +++ b/04_2__Interlude_Using_JQ.md @@ -372,7 +372,7 @@ $ usedtxid=($(bitcoin-cli decoderawtransaction $rawtxhex | jq -r '.vin | .[] | . $ usedvout=($(bitcoin-cli decoderawtransaction $rawtxhex | jq -r '.vin | .[] | .vout')) $ btcin=$(for ((i=0; i<${#usedtxid[*]}; i++)); do txid=${usedtxid[i]}; vout=${usedvout[i]}; bitcoin-cli listunspent | jq -r '.[] | select (.txid | contains("'${txid}'")) | select(.vout | contains('$vout')) | .amount'; done | awk '{s+=$1} END {print s}') $ btcout=$(bitcoin-cli decoderawtransaction $rawtxhex | jq -r '.vout [] | .value' | awk '{s+=$1} END {print s}') -$ echo "$btcin-$btcout"| /usr/bin/bc +$ echo $(printf '%.8f-%.8f' $btcin $btcout_f) | /usr/bin/bc .255 ``` And that's also a good example of why you double-check your fees: we'd intended to send a transaction fee of 5,000 satoshis, but sent 255,000 satoshis instead. Whoops! diff --git a/src/04_2_i_txfee-calc.sh b/src/04_2_i_txfee-calc.sh index 64a884a..0e94a05 100644 --- a/src/04_2_i_txfee-calc.sh +++ b/src/04_2_i_txfee-calc.sh @@ -11,4 +11,4 @@ usedvout=($(bitcoin-cli decoderawtransaction $1 | jq -r '.vin | .[] | .vout')) btcin=$(for ((i=0; i<${#usedtxid[*]}; i++)); do txid=${usedtxid[i]}; vout=${usedvout[i]}; bitcoin-cli listunspent | jq -r '.[] | select (.txid | contains("'${txid}'")) | select(.vout | contains('$vout')) | .amount'; done | awk '{s+=$1} END {print s}') btcout=$(bitcoin-cli decoderawtransaction $1 | jq -r '.vout [] | .value' | awk '{s+=$1} END {print s}') btcout_f=$(awk -v btcout="$btcout" 'BEGIN { printf("%f\n", btcout) }'