diff options
author | Javier Sepulveda <javier.sepulveda@uv.es> | 2023-09-15 11:29:29 +0200 |
---|---|---|
committer | Javier Sepulveda <javier.sepulveda@uv.es> | 2023-09-15 11:29:29 +0200 |
commit | 275d1ea9b3358efa76fe1588e9a60e72522dc874 (patch) | |
tree | 31cee8e27043bee03dbaa3ee703b8eaee35c841f | |
parent | b62a0185ac93b0febab39f784d17e3e81d5f38d7 (diff) | |
download | deployment-275d1ea9b3358efa76fe1588e9a60e72522dc874.tar.gz deployment-275d1ea9b3358efa76fe1588e9a60e72522dc874.tar.bz2 deployment-275d1ea9b3358efa76fe1588e9a60e72522dc874.zip |
fund-rewards.sh script added to the --new folder: utils
-rwxr-xr-x | sandcastle/utils/fund-rewards.sh | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/sandcastle/utils/fund-rewards.sh b/sandcastle/utils/fund-rewards.sh new file mode 100755 index 0000000..cf09723 --- /dev/null +++ b/sandcastle/utils/fund-rewards.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +# This file is in the public domain. + +set -eu + +# Maybe add these to base Dockerfile as ENV? + +export LD_LIBRARY_PATH=/usr/local/lib +export GNUNET_FORCE_LOG=";;;;WARNING" + +# Configuration variables - Please change to your needs + +DOMAIN="demo.taler.net" + +# Program variables - No need to be changed by the user. + +MERCHANT_URL="https://backend.${DOMAIN}/" +MERCHANT_APIKEY=$(taler-config -c /config/deployment.conf -s taler-deployment -o merchant-apikey) +BANK_ACCESS_URL="https://bank.${DOMAIN}/demobanks/default/access-api/" +WIRE_METHOD="iban" +AMOUNT="100" # Amount to add, on each new reserve (tiptopup option) +BANK_ACCOUNT="survey-at-sandbox" +BANK_PASSWORD="secret-at-sandbox" +#BANK_PASSWORD=$(taler-config -c /config/deployment.conf -s taler-deployment -o db-password) +EXCHANGE_URL=$(taler-config -c /config/deployment.conf -s taler-deployment -o default-exchange) +EXCHANGE_URL="https://exchange.${DOMAIN}/" +# shellcheck disable=SC2034 +CURRENCY=$(taler-config -c /config/deployment.conf -s taler-deployment -o currency) + +# Obtain current reserves in json format +# Just one single call to the taler-harness program to avoid inconsistencies + +JSON=$(taler-harness deployment tip-status \ + --merchant-url "$MERCHANT_URL" \ + --merchant-apikey "$MERCHANT_APIKEY") + +# 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') +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)) + +# Decide whether add a new reserve, or leave it as is. + +if [ "$TOTAL_RESERVE_AMOUNT" -lt 100 ]; then + # Add new reserve amount of 100 units + taler-harness deployment tip-topup \ + --merchant-url "$MERCHANT_URL" \ + --merchant-apikey="$MERCHANT_APIKEY" \ + --bank-access-url "$BANK_ACCESS_URL" \ + --wire-method="$WIRE_METHOD" \ + --amount=KUDOS:"$AMOUNT" \ + --bank-account="$BANK_ACCOUNT" \ + --bank-password="$BANK_PASSWORD" \ + --exchange-url "$EXCHANGE_URL" +fi + +# If the json variable contains more than 100 records, wipe its content + +TOTAL_JSON_RECORDS=$(echo "$JSON" | jq '.[] | length') + +if [ "$TOTAL_JSON_RECORDS" -gt 100 ]; then + taler-harness deployment tip-cleanup --merchant-url "$BACKEND_URL" +fi + |