Browse Source

Use bc for more accurate arithmetic

master
Luke Childs 6 years ago
parent
commit
eb48d22737
  1. 14
      consolidateutxos.sh

14
consolidateutxos.sh

@ -1,10 +1,6 @@
#!/bin/bash
cd "${BASH_SOURCE%/*}" || exit
calc() {
awk "BEGIN { print "$*" }"
}
coin="KMD"
address="RPxsaGNqTKzPnbm5q7QXwu7b6EZWuLxJG3"
cli=$(./listclis.sh ${coin})
@ -16,20 +12,20 @@ echo "[${coin}] Checking mining UTXOs - ${date}"
mining_rewards=$(${cli} listunspent | jq -r 'map(select(.spendable == true and .amount != 0.0001))')
no_of_mining_utxos=$(echo $mining_rewards | jq -r 'length')
total_mining_rewards=$(echo $mining_rewards | jq -r '[ .[].amount ] | add')
total_mining_rewards=$(echo $mining_rewards | jq -r '.[].amount' | paste -sd+ - | bc)
old_igunan_utxos=$(${cli} listunspent | jq -r "map(select(.spendable == true and .amount == 0.0001 and .confirmations > ${iguana_age_threshold}))")
no_of_iguana_utxos=$(echo $old_igunan_utxos | jq -r 'length')
total_iguana_utxos=$(echo $old_igunan_utxos | jq -r '[ .[].amount ] | add')
total_iguana_utxos=$(echo $old_igunan_utxos | jq -r '.[].amount' | paste -sd+ - | bc)
echo "[${coin}] ${no_of_mining_utxos} mining UTXOs totalling ${total_mining_rewards} ${coin}"
echo "[${coin}] ${no_of_iguana_utxos} iguana UTXOs older than ${iguana_age_threshold} confs totalling ${total_iguana_utxos} ${coin}"
no_of_utxos=$(calc $no_of_mining_utxos+$no_of_iguana_utxos)
amount_of_utxos=$(calc $total_mining_rewards+$total_iguana_utxos)
no_of_utxos=$(echo "$no_of_mining_utxos+$no_of_iguana_utxos" | bc)
amount_of_utxos=$(echo "$total_mining_rewards+$total_iguana_utxos" | bc)
if [[ $no_of_utxos -gt 1 ]]; then
output_amount=$(calc $amount_of_utxos-$txfee)
output_amount=$(echo "$amount_of_utxos-$txfee" | bc)
transaction_inputs=$(jq -r --argjson mining_rewards "$mining_rewards" --argjson old_igunan_utxos "$old_igunan_utxos" -n '$mining_rewards + $old_igunan_utxos | [.[] | {txid, vout}]')
transaction_outputs="{\"$address\":$output_amount}"

Loading…
Cancel
Save