summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsandcastle/utils/fund-rewards.sh9
1 files changed, 8 insertions, 1 deletions
diff --git a/sandcastle/utils/fund-rewards.sh b/sandcastle/utils/fund-rewards.sh
index cf09723..d53bd99 100755
--- a/sandcastle/utils/fund-rewards.sh
+++ b/sandcastle/utils/fund-rewards.sh
@@ -38,9 +38,16 @@ JSON=$(taler-harness deployment tip-status \
# Calculate remaining funds
ACTIVE_FUNDS=$(echo "$JSON" | jq '[.reserves[] | select(.active)]')
-TOTAL_EXCHANGE_INITIAL_AMOUNT=$(echo "$ACTIVE_FUNDS" | jq --arg cur "$CURRENCY" '[.[].exchange_initial_amount | sub($cur + ":"; "") | tonumber] | add')
+
+# If there is ANY active reserve, then do the substraction
+if [[ $ACTIVE_FUNDS != "[]" ]]; then
+TOTAL_EXCHANGE_INITIAL_AMOUNT=$(echo "$ACTIVE_FUNDS" | jq --arg cur "$CURRENCY" '[.[].exchange_initial_amount | sub($cur + ":"; "") | tonumber] |>
TOTAL_PICKUP_AMOUNT=$(echo "$ACTIVE_FUNDS" | jq --arg cur "$CURRENCY" '[.[].pickup_amount | sub($cur + ":"; "") | tonumber] | add')
TOTAL_RESERVE_AMOUNT=$((TOTAL_EXCHANGE_INITIAL_AMOUNT - TOTAL_PICKUP_AMOUNT))
+else
+# Otherwise set variable to zero
+TOTAL_RESERVE_AMOUNT=0
+fi
# Decide whether add a new reserve, or leave it as is.