diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-01-15 15:17:02 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-01-15 15:17:25 +0100 |
commit | da5b3ba8aeb9d47e4f99cd22847c9b539ff8ee2b (patch) | |
tree | 6e67e1d08fd941144f464dfe55b8835db65687e6 /src/auditor | |
parent | b37fff0d5b08926169633ce8822de7ac616ae169 (diff) |
round amounts based on config, do unit test for rounding
Diffstat (limited to 'src/auditor')
-rw-r--r-- | src/auditor/taler-auditor.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/auditor/taler-auditor.c b/src/auditor/taler-auditor.c index d4fb84d16..d2bc34046 100644 --- a/src/auditor/taler-auditor.c +++ b/src/auditor/taler-auditor.c @@ -86,6 +86,11 @@ static struct TALER_EXCHANGEDB_Plugin *edb; static char *currency; /** + * How many fractional digits does the currency use? + */ +static uint8_t currency_rounding_fractional_digits; + +/** * Our configuration. */ static const struct GNUNET_CONFIGURATION_Handle *cfg; @@ -2895,7 +2900,8 @@ check_wire_out_cb } /* Round down to amount supported by wire method */ - GNUNET_break (TALER_amount_round (&final_amount)); + GNUNET_break (TALER_amount_round_down (&final_amount, + currency_rounding_fractional_digits)); /* Calculate the exchange's gain as the fees plus rounding differences! */ if (GNUNET_OK != @@ -5204,6 +5210,30 @@ run (void *cls, global_ret = 1; return; } + { + unsigned long long num; + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_number (cfg, + "taler", + "CURRENCY_ROUNDING_FRACTIONAL_DIGITS", + &num)) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "No [taler]/CURRENCY_ROUNDING_FRACTIONAL_DIGITS specified, defaulting to 2 digits.\n"); + currency_rounding_fractional_digits = 2; + } + else if (num > TALER_AMOUNT_FRAC_LEN) + { + global_ret = 1; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Value of CURRENCY_ROUNDING_FRACTIONAL_DIGITS too big.\n"); + return; + } + else + { + currency_rounding_fractional_digits = (uint8_t) num; + } + } if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, "exchangedb", |