From 559aa39c6d5659292af5e0769e20f97ab4d8392e Mon Sep 17 00:00:00 2001 From: Abu Shifrah <35174370+muaawiyahtucker@users.noreply.github.com> Date: Sat, 5 Jul 2025 09:07:22 +0300 Subject: [PATCH] Corrected rounding error and used mapfile to better handle the results from array --- src/04_2_i_txfee-calc.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/04_2_i_txfee-calc.sh b/src/04_2_i_txfee-calc.sh index 64a884a..4fea0c3 100644 --- a/src/04_2_i_txfee-calc.sh +++ b/src/04_2_i_txfee-calc.sh @@ -1,14 +1,14 @@ #!/bin/bash -if [ -z $1 ]; +if [ -z "$1" ]; then echo "You must include the raw transaction hex as an argument."; exit; fi -usedtxid=($(bitcoin-cli decoderawtransaction $1 | jq -r '.vin | .[] | .txid')) -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) }'