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

This commit is contained in:
Christian Grothoff 2020-01-19 20:57:32 +01:00
parent 6f3c682722
commit 4fac247bc7
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
9 changed files with 54 additions and 97 deletions

View File

@ -5258,28 +5258,14 @@ run (void *cls,
return;
}
{
char *rounding_str;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
TALER_config_get_amount (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))
{
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;
}

View File

@ -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,
TALER_config_get_amount (cfg,
"auditor",
"TINY_AMOUNT",
&tinys))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"auditor",
"TINY_AMOUNT");
global_ret = 1;
return;
}
if (GNUNET_OK !=
TALER_string_to_amount (tinys,
&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))
{

View File

@ -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,
if ( (GNUNET_OK !=
TALER_config_get_amount (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))
&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,
if ( (GNUNET_OK !=
TALER_config_get_amount (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))
&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 */

View File

@ -603,28 +603,16 @@ exchange_serve_process_config ()
}
{
char *rounding_str;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
if ( (GNUNET_OK !=
TALER_config_get_amount (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))
&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;
}
}

View File

@ -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

View File

@ -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

View File

@ -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/"

View File

@ -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/"

View File

@ -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]