From 7378b5a081a0d839c3bd63f6ddd359bca50be695 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 17 Jan 2020 18:59:15 +0100 Subject: amount rounding a la Christian --- src/auditor/taler-auditor.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'src/auditor') diff --git a/src/auditor/taler-auditor.c b/src/auditor/taler-auditor.c index 8b2c2c37e..f3bb0e2b7 100644 --- a/src/auditor/taler-auditor.c +++ b/src/auditor/taler-auditor.c @@ -88,7 +88,7 @@ static char *currency; /** * How many fractional digits does the currency use? */ -static uint8_t currency_rounding_fractional_digits; +static struct TALER_Amount currency_round_unit; /** * Our configuration. @@ -2894,7 +2894,7 @@ check_wire_out_cb /* Round down to amount supported by wire method */ GNUNET_break (TALER_amount_round_down (&final_amount, - currency_rounding_fractional_digits)); + ¤cy_round_unit)); /* Calculate the exchange's gain as the fees plus rounding differences! */ if (GNUNET_OK != @@ -5205,28 +5205,29 @@ run (void *cls, return; } { - unsigned long long num; + char *rounding_str; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (cfg, + GNUNET_CONFIGURATION_get_value_string (cfg, "taler", - "CURRENCY_ROUNDING_FRACTIONAL_DIGITS", - &num)) + "CURRENCY_ROUND_UNIT", + &rounding_str)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "No [taler]/CURRENCY_ROUNDING_FRACTIONAL_DIGITS specified, defaulting to 2 digits.\n"); - currency_rounding_fractional_digits = 2; + "No [taler]/CURRENCY_ROUND_UNIT specified, defaulting to '0.01'.\n"); + TALER_amount_get_zero (currency, ¤cy_round_unit); + currency_round_unit.fraction = TALER_AMOUNT_FRAC_BASE / 100; } - else if (num > TALER_AMOUNT_FRAC_LEN) + else if (GNUNET_OK != + TALER_string_to_amount (rounding_str, + ¤cy_round_unit)) { - global_ret = 1; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Value of CURRENCY_ROUNDING_FRACTIONAL_DIGITS too big.\n"); + "Invalid amount `%s' specified in `TALER' under `CURRENCY_ROUND_UNIT'\n", + rounding_str); + GNUNET_free (rounding_str); + global_ret = 1; return; } - else - { - currency_rounding_fractional_digits = (uint8_t) num; - } } if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, -- cgit v1.2.3