exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

taler-exchange-helper-measure-test-form (5558B)


      1 #!/bin/bash
      2 #
      3 #  This file is part of TALER
      4 #  Copyright (C) 2014-2024 Taler Systems SA
      5 #
      6 #  TALER is free software; you can redistribute it and/or modify it under the
      7 #  terms of the GNU General Public License as published by the Free Software
      8 #  Foundation; either version 3, or (at your option) any later version.
      9 #
     10 #  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     11 #  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     12 #  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     13 #
     14 #  You should have received a copy of the GNU General Public License along with
     15 #  TALER; see the file COPYING.  If not, If not, see <http://www.gnu.org/license>
     16 #
     17 
     18 # Hard error reporting on.
     19 set -eu
     20 
     21 
     22 # Exit, with error message (hard failure)
     23 function exit_fail() {
     24     echo " FAIL: " "$@" >&2
     25     EXIT_STATUS=1
     26     exit "$EXIT_STATUS"
     27 }
     28 
     29 CONF="$HOME/.config/taler-exchange.conf"
     30 VERBOSE=0
     31 
     32 while getopts 'ac:hirvV' OPTION;
     33 do
     34     case "$OPTION" in
     35         a)
     36             # This AML program expects as inputs a full_name
     37             # and a date of birth.
     38             echo "FULL_NAME"
     39             echo "DATE_OF_BIRTH"
     40             exit 0
     41             ;;
     42         c)
     43             # shellcheck disable=SC2034
     44             CONF="$OPTARG"
     45             ;;
     46         h)
     47             echo "This is a KYC measure program that checks the output of a simple FORM submission, and if it passed, increases all limits to EUR:1000. (and does not impose any other limits)"
     48             echo 'Supported options:'
     49             echo '  -a           -- show required attributes'
     50             # shellcheck disable=SC2016
     51             echo '  -c $CONF     -- set configuration'
     52             echo '  -h           -- print this help'
     53             echo '  -i           -- show required inputs'
     54             echo '  -r           -- show required context'
     55             echo '  -v           -- show version'
     56             echo '  -V           -- be verbose'
     57             exit 0
     58             ;;
     59         i)
     60             # Attributes are required.
     61             echo "attributes"
     62             exit 0
     63             ;;
     64         r)
     65             # No context is required.
     66             exit 0
     67             ;;
     68         v)
     69             echo "$0 v0.0.0"
     70             exit 0
     71             ;;
     72         V)
     73             VERBOSE=1
     74             ;;
     75         ?)
     76         exit_fail "Unrecognized command line option"
     77         ;;
     78     esac
     79 done
     80 
     81 if [ 1 = "$VERBOSE" ]
     82 then
     83     echo "Running $0" 1>&2
     84 fi
     85 
     86 # First, check everything we expect is in stdin.
     87 A=$(jq -r .attributes)
     88 
     89 # Get form ID
     90 FORM_ID=$(echo "$A" | jq -r '.FORM_ID')
     91 
     92 # The 'form' here should be the 'test' form
     93 if [ "$FORM_ID" != "test" ]
     94 then
     95     exit_fail "Invalid form ID"
     96 fi
     97 
     98 
     99 J=$(echo "$A" | jq -r 'def get($k):
    100              if has($k)
    101                then .[$k]
    102                else error("attribute missing")
    103            end;
    104            {"FULL_NAME":get("FULL_NAME"),
    105             "DATE_OF_BIRTH":get("DATE_OF_BIRTH")}')
    106 
    107 # Here we could use those values...
    108 echo "$J" >> /dev/null
    109 
    110 # See https://docs.taler.net/taler-exchange-manual.html#tsref-type-AmlProgramInput
    111 # for the full JSON with possible inputs.
    112 
    113 # New rules apply for 30 days.
    114 EXPIRATION=$((3600 * 30 + $(date +%s)))
    115 
    116 # Read currency from the config
    117 CURRENCY=$(taler-exchange-config -c "$CONF" -s exchange -o currency)
    118 
    119 # Finally, output the new rules.
    120 # See https://docs.taler.net/taler-exchange-manual.html#tsref-type-AmlOutcome
    121 # for the required output format.
    122 
    123 jq -n \
    124     --argjson expiration "$EXPIRATION" \
    125     --arg currency "$CURRENCY" \
    126     '{ "to_investigate": false,
    127        "new_rules" : {
    128          "custom_measures" : {},
    129          "expiration_time" : { "t_s": $expiration },
    130          "rules" : [
    131          {
    132            "operation_type": "WITHDRAW",
    133            "threshold" : "\($currency):1000",
    134            "timeframe" : { "d_us" : 3600000000 },
    135            "measures" : [ "verboten" ],
    136            "display_priority" : 1,
    137            "exposed" : true,
    138            "is_and_combinator" : true
    139          },
    140          {
    141            "operation_type": "DEPOSIT",
    142            "threshold" : "\($currency):1000",
    143            "timeframe" : { "d_us" : 3600000000 },
    144            "measures" : [ "verboten" ],
    145            "display_priority" : 1,
    146            "exposed" : true,
    147            "is_and_combinator" : true
    148          },
    149          {
    150            "operation_type": "AGGREGATE",
    151            "threshold" : "\($currency):1000",
    152            "timeframe" : { "d_us" : 3600000000 },
    153            "measures" : [ "verboten" ],
    154            "display_priority" : 1,
    155            "exposed" : true,
    156            "is_and_combinator" : true
    157          },
    158          {
    159            "operation_type": "MERGE",
    160            "threshold" : "\($currency):1000",
    161            "timeframe" : { "d_us" : 3600000000 },
    162            "measures" : [ "verboten" ],
    163            "display_priority" : 1,
    164            "exposed" : true,
    165            "is_and_combinator" : true
    166          },
    167          {
    168            "operation_type": "BALANCE",
    169            "threshold" : "\($currency):1000",
    170            "timeframe" : { "d_us" : 3600000000 },
    171            "measures" : [ "verboten" ],
    172            "display_priority" : 1,
    173            "exposed" : true,
    174            "is_and_combinator" : true
    175          },
    176          {
    177            "operation_type": "CLOSE",
    178            "threshold" : "\($currency):1000",
    179            "timeframe" : { "d_us" : 3600000000 },
    180            "measures" : [ "verboten" ],
    181            "display_priority" : 1,
    182            "exposed" : true,
    183            "is_and_combinator" : true
    184          }
    185          ]
    186        }
    187      }' < /dev/null
    188 
    189 exit 0