exchange

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

commit 4fac247bc7187cd611daad87563396c06a8295e4
parent 6f3c6827221fae6da47a113af4172e8f269bd38c
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 19 Jan 2020 20:57:32 +0100

use TALER_config_get_amount() consistently, require currency rounding option to exist instead of defaulting

Diffstat:
Msrc/auditor/taler-auditor.c | 24+++++-------------------
Msrc/auditor/taler-wire-auditor.c | 19+++----------------
Msrc/exchange-tools/taler-exchange-keyup.c | 74+++++++++++++++++++++++++++++++++-----------------------------------------
Msrc/exchange/taler-exchange-aggregator.c | 28++++++++--------------------
Msrc/testing/test-taler-exchange-aggregator-postgres.conf | 1+
Msrc/testing/test-taler-exchange-wirewatch-postgres.conf | 2+-
Msrc/testing/test_auditor_api.conf | 1+
Msrc/testing/test_exchange_api.conf | 1+
Msrc/testing/test_exchange_api_twisted.conf | 1+
9 files changed, 54 insertions(+), 97 deletions(-)

diff --git a/src/auditor/taler-auditor.c b/src/auditor/taler-auditor.c @@ -5258,28 +5258,14 @@ run (void *cls, return; } { - char *rounding_str; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (cfg, - "taler", - "CURRENCY_ROUND_UNIT", - &rounding_str)) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "No [taler]/CURRENCY_ROUND_UNIT specified, defaulting to '0.01'.\n"); - GNUNET_assert (GNUNET_OK == - TALER_amount_get_zero (currency, - &currency_round_unit)); - currency_round_unit.fraction = TALER_AMOUNT_FRAC_BASE / 100; - } - else if (GNUNET_OK != - TALER_string_to_amount (rounding_str, - &currency_round_unit)) + TALER_config_get_amount (cfg, + "taler", + "CURRENCY_ROUND_UNIT", + &currency_round_unit)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Invalid amount `%s' specified in `TALER' under `CURRENCY_ROUND_UNIT'\n", - rounding_str); - GNUNET_free (rounding_str); + "Invalid or missing amount in `TALER' under `CURRENCY_ROUND_UNIT'\n"); global_ret = 1; return; } diff --git a/src/auditor/taler-wire-auditor.c b/src/auditor/taler-wire-auditor.c @@ -2103,7 +2103,6 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c) { static const struct TALER_MasterPublicKeyP zeromp; - char *tinys; (void) cls; (void) args; @@ -2113,22 +2112,11 @@ run (void *cls, start_time = GNUNET_TIME_absolute_get (); cfg = c; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (cfg, - "auditor", - "TINY_AMOUNT", - &tinys)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + TALER_config_get_amount (cfg, "auditor", - "TINY_AMOUNT"); - global_ret = 1; - return; - } - if (GNUNET_OK != - TALER_string_to_amount (tinys, - &tiny_amount)) + "TINY_AMOUNT", + &tiny_amount)) { - GNUNET_free (tinys); GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "auditor", "TINY_AMOUNT", @@ -2136,7 +2124,6 @@ run (void *cls, global_ret = 1; return; } - GNUNET_free (tinys); if (0 == GNUNET_memcmp (&zeromp, &master_pub)) { diff --git a/src/exchange-tools/taler-exchange-keyup.c b/src/exchange-tools/taler-exchange-keyup.c @@ -164,6 +164,11 @@ struct CoinTypeParams /** + * The configured currency. + */ +static char *currency; + +/** * Filename of the master private key. */ static char *masterkeyfile; @@ -987,7 +992,6 @@ create_wire_fee_for_method (void *cls, { struct TALER_EXCHANGEDB_AggregateFees *af; char *opt; - char *amounts; GNUNET_snprintf (yearstr, sizeof (yearstr), @@ -1002,68 +1006,44 @@ create_wire_fee_for_method (void *cls, GNUNET_asprintf (&opt, "wire-fee-%u", year); - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (kcfg, - section, - opt, - &amounts)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - section, - opt); - *ret = GNUNET_SYSERR; - GNUNET_free (opt); - break; - } - if (GNUNET_OK != - TALER_string_to_amount (amounts, - &af->wire_fee)) + if ( (GNUNET_OK != + TALER_config_get_amount (kcfg, + section, + opt, + &af->wire_fee)) || + (0 != strcasecmp (currency, + af->wire_fee.currency)) ) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Invalid amount `%s' specified in `%s' under `%s'\n", - amounts, + "Invalid or missing amount in `%s' under `%s'\n", wiremethod, opt); *ret = GNUNET_SYSERR; - GNUNET_free (amounts); GNUNET_free (opt); break; } - GNUNET_free (amounts); GNUNET_free (opt); /* handle closing fee */ GNUNET_asprintf (&opt, "closing-fee-%u", year); - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (kcfg, - section, - opt, - &amounts)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - section, - opt); - *ret = GNUNET_SYSERR; - GNUNET_free (opt); - break; - } - if (GNUNET_OK != - TALER_string_to_amount (amounts, - &af->closing_fee)) + if ( (GNUNET_OK != + TALER_config_get_amount (kcfg, + section, + opt, + &af->closing_fee)) || + (0 != strcasecmp (currency, + af->wire_fee.currency)) ) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Invalid amount `%s' specified in `%s' under `%s'\n", - amounts, + "Invalid or missing amount in `%s' under `%s'\n", wiremethod, opt); *ret = GNUNET_SYSERR; - GNUNET_free (amounts); GNUNET_free (opt); break; } - GNUNET_free (amounts); GNUNET_free (opt); sign_af (af, @@ -1193,6 +1173,18 @@ run (void *cls, (void) cfgfile; kcfg = cfg; + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, + "taler", + "CURRENCY", + &currency)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "taler", + "CURRENCY"); + global_ret = 1; + return; + } if (now.abs_value_us != now_tmp.abs_value_us) { /* The user gave "--now", use it */ diff --git a/src/exchange/taler-exchange-aggregator.c b/src/exchange/taler-exchange-aggregator.c @@ -603,28 +603,16 @@ exchange_serve_process_config () } { - char *rounding_str; - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (cfg, - "taler", - "CURRENCY_ROUND_UNIT", - &rounding_str)) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "No [taler]/CURRENCY_ROUND_UNIT specified, defaulting to '0.01'.\n"); - GNUNET_assert (GNUNET_OK == - TALER_amount_get_zero (exchange_currency_string, - &currency_round_unit)); - currency_round_unit.fraction = TALER_AMOUNT_FRAC_BASE / 100; - } - else if (GNUNET_OK != - TALER_string_to_amount (rounding_str, - &currency_round_unit)) + if ( (GNUNET_OK != + TALER_config_get_amount (cfg, + "taler", + "CURRENCY_ROUND_UNIT", + &currency_round_unit)) || + ( (0 != currency_round_unit.fraction) && + (0 != currency_round_unit.value) ) ) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Invalid amount `%s' specified in `TALER' under `CURRENCY_ROUND_UNIT'\n", - rounding_str); - GNUNET_free (rounding_str); + "Invalid value specified in `TALER' under `CURRENCY_ROUND_UNIT'\n"); return GNUNET_SYSERR; } } diff --git a/src/testing/test-taler-exchange-aggregator-postgres.conf b/src/testing/test-taler-exchange-aggregator-postgres.conf @@ -5,6 +5,7 @@ TALER_TEST_HOME = test_taler_exchange_httpd_home/ [taler] # Currency supported by the exchange (can only be one) CURRENCY = EUR +CURRENCY_ROUND_UNIT = EUR:0.01 [exchange] # The DB plugin to use diff --git a/src/testing/test-taler-exchange-wirewatch-postgres.conf b/src/testing/test-taler-exchange-wirewatch-postgres.conf @@ -5,6 +5,7 @@ TALER_TEST_HOME = test_taler_exchange_httpd_home/ [taler] # Currency supported by the exchange (can only be one) CURRENCY = EUR +CURRENCY_ROUND_UNIT = EUR:0.01 [exchange] # The DB plugin to use @@ -101,4 +102,3 @@ fee_deposit = EUR:0.00 fee_refresh = EUR:0.01 fee_refund = EUR:0.01 rsa_keysize = 1024 - diff --git a/src/testing/test_auditor_api.conf b/src/testing/test_auditor_api.conf @@ -8,6 +8,7 @@ TALER_TEST_HOME = test_exchange_api_home/ [taler] # Currency supported by the exchange (can only be one) CURRENCY = EUR +CURRENCY_ROUND_UNIT = EUR:0.01 [auditor] BASE_URL = "http://localhost:8083/" diff --git a/src/testing/test_exchange_api.conf b/src/testing/test_exchange_api.conf @@ -9,6 +9,7 @@ TALER_TEST_HOME = test_exchange_api_home/ [taler] # Currency supported by the exchange (can only be one) CURRENCY = EUR +CURRENCY_ROUND_UNIT = EUR:0.01 [auditor] BASE_URL = "http://localhost:8083/" diff --git a/src/testing/test_exchange_api_twisted.conf b/src/testing/test_exchange_api_twisted.conf @@ -9,6 +9,7 @@ TALER_TEST_HOME = test_exchange_api_home/ [taler] # Currency supported by the exchange (can only be one) CURRENCY = EUR +CURRENCY_ROUND_UNIT = EUR:0.01 [exchange]