blob: 6f76a394242d700437bec926327c806e39b4beaa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#!/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)]')
# 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] | 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))
else
# Otherwise set variable to zero
TOTAL_RESERVE_AMOUNT=0
fi
# 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
|