From 4fac247bc7187cd611daad87563396c06a8295e4 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 19 Jan 2020 20:57:32 +0100 Subject: [PATCH] use TALER_config_get_amount() consistently, require currency rounding option to exist instead of defaulting --- src/auditor/taler-auditor.c | 24 ++---- src/auditor/taler-wire-auditor.c | 19 +---- src/exchange-tools/taler-exchange-keyup.c | 74 +++++++++---------- src/exchange/taler-exchange-aggregator.c | 28 ++----- ...st-taler-exchange-aggregator-postgres.conf | 1 + ...est-taler-exchange-wirewatch-postgres.conf | 2 +- src/testing/test_auditor_api.conf | 1 + src/testing/test_exchange_api.conf | 1 + src/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 index 6752b34ab..d2bd8de6d 100644 --- 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, - ¤cy_round_unit)); - currency_round_unit.fraction = TALER_AMOUNT_FRAC_BASE / 100; - } - else if (GNUNET_OK != - TALER_string_to_amount (rounding_str, - ¤cy_round_unit)) + TALER_config_get_amount (cfg, + "taler", + "CURRENCY_ROUND_UNIT", + ¤cy_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 index 73f1f9db9..6821aedb2 100644 --- 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 index 71ccace91..a235d46fe 100644 --- a/src/exchange-tools/taler-exchange-keyup.c +++ b/src/exchange-tools/taler-exchange-keyup.c @@ -163,6 +163,11 @@ struct CoinTypeParams }; +/** + * The configured currency. + */ +static char *currency; + /** * Filename of the master private key. */ @@ -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", + ¤cy)) + { + 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 index e9474d89f..0718fdda5 100644 --- 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, - ¤cy_round_unit)); - currency_round_unit.fraction = TALER_AMOUNT_FRAC_BASE / 100; - } - else if (GNUNET_OK != - TALER_string_to_amount (rounding_str, - ¤cy_round_unit)) + if ( (GNUNET_OK != + TALER_config_get_amount (cfg, + "taler", + "CURRENCY_ROUND_UNIT", + ¤cy_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 index 0f8ed70d9..f7da395d4 100644 --- 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 index 168e7eda3..61029e3f2 100644 --- 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 index da84149b0..b448b12a5 100644 --- 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 index 6af202e30..7454934a8 100644 --- 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 index 2cda46e5a..8abe13273 100644 --- 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]