mirror of
https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line.git
synced 2025-06-07 07:56:31 +00:00
Create 4_2_i_txfee-calc.sh
This commit is contained in:
parent
7a9855b7a8
commit
206929d3dd
13
src/4_2_i_txfee-calc.sh
Normal file
13
src/4_2_i_txfee-calc.sh
Normal file
@ -0,0 +1,13 @@
|
||||
#!/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}')
|
||||
echo "$btcin-$btcout"| /usr/bin/bc
|
Loading…
x
Reference in New Issue
Block a user