diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-06-04 14:04:27 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-06-04 14:04:27 +0200 |
commit | d04769b729a6a7153c76d56ab3764efe2ca28667 (patch) | |
tree | 749ca9bbde4b751cca184cb0385d306ba8a2d380 /src/lib | |
parent | 04c32eafb9194727876469c92b7cbedc008c51ec (diff) | |
download | exchange-d04769b729a6a7153c76d56ab3764efe2ca28667.tar.xz |
handle case where purse expiration refunded the coin's deposited amount
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/exchange_api_common.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/exchange_api_common.c b/src/lib/exchange_api_common.c index 78dea63e4..d60327831 100644 --- a/src/lib/exchange_api_common.c +++ b/src/lib/exchange_api_common.c @@ -1185,6 +1185,7 @@ help_purse_deposit (struct CoinHistoryParseContext *pc, struct TALER_PurseContractPublicKeyP purse_pub; struct TALER_CoinSpendSignatureP coin_sig; const char *exchange_base_url; + bool refunded; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_fixed_auto ("purse_pub", &purse_pub), @@ -1192,6 +1193,8 @@ help_purse_deposit (struct CoinHistoryParseContext *pc, &coin_sig), GNUNET_JSON_spec_string ("exchange_base_url", &exchange_base_url), + GNUNET_JSON_spec_bool ("refunded", + &refunded), GNUNET_JSON_spec_end () }; @@ -1214,6 +1217,23 @@ help_purse_deposit (struct CoinHistoryParseContext *pc, GNUNET_break_op (0); return GNUNET_SYSERR; } + if (refunded) + { + /* We add the amount to refunds here, the original + deposit will be added to the balance later because + we still return GNUNET_YES, thus effectively + cancelling out this operation with respect to + the final balance. */ + if (0 > + TALER_amount_add (&pc->rtotal, + &pc->rtotal, + amount)) + { + /* overflow in refund history? inconceivable! Bad exchange! */ + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + } return GNUNET_YES; } |