-
-
Notifications
You must be signed in to change notification settings - Fork 826
Expand file tree
/
Copy path04_2_i_txfee-calc.sh
More file actions
14 lines (12 loc) · 772 Bytes
/
04_2_i_txfee-calc.sh
File metadata and controls
14 lines (12 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash
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) }' </dev/null)
echo $(printf '%.8f-%.8f' $btcin $btcout_f) | /usr/bin/bc