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 | |
parent | 04c32eafb9194727876469c92b7cbedc008c51ec (diff) | |
download | exchange-d04769b729a6a7153c76d56ab3764efe2ca28667.tar.xz |
handle case where purse expiration refunded the coin's deposited amount
-rw-r--r-- | src/exchange/taler-exchange-httpd_responses.c | 52 | ||||
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 5 | ||||
-rw-r--r-- | src/include/taler_exchangedb_plugin.h | 5 | ||||
-rw-r--r-- | src/lib/exchange_api_common.c | 20 |
4 files changed, 32 insertions, 50 deletions
diff --git a/src/exchange/taler-exchange-httpd_responses.c b/src/exchange/taler-exchange-httpd_responses.c index 450a9bab4..11cc0b930 100644 --- a/src/exchange/taler-exchange-httpd_responses.c +++ b/src/exchange/taler-exchange-httpd_responses.c @@ -411,6 +411,8 @@ TEH_RESPONSE_compile_transaction_history ( : pd->exchange_base_url), GNUNET_JSON_pack_data_auto ("purse_pub", &pd->purse_pub), + GNUNET_JSON_pack_bool ("refunded", + pd->refunded), GNUNET_JSON_pack_data_auto ("coin_sig", &pd->coin_sig)))) { @@ -420,56 +422,6 @@ TEH_RESPONSE_compile_transaction_history ( } break; } - -#if FIXME_PURSE_REFUND - case TALER_EXCHANGEDB_TT_PURSE_REFUND: - { - struct TALER_EXCHANGEDB_PurseRefundListEntry *pr - = pos->details.purse_refund; - struct TALER_ExchangePublicKeyP epub; - struct TALER_ExchangeSignatureP esig; - - if (TALER_EC_NONE != - TALER_exchange_online_purse_refund_sign ( - &TEH_keys_exchange_sign_, - &pr->amount, - &pr->refund_fee, - &pr->purse_share_fee, - &pr->purse_pub, - coin_pub, - &epub, - &esig)) - { - GNUNET_break (0); - json_decref (history); - return NULL; - } - if (0 != - json_array_append_new ( - history, - GNUNET_JSON_PACK ( - GNUNET_JSON_pack_string ("type", - "PURSE-REFUND"), - TALER_JSON_pack_amount ("amount", - &pd->amount), - TALER_JSON_pack_amount ("refund_fee", - &pd->refund_fee), - TALER_JSON_pack_amount ("purse_share_fee", - &pd->purse_share_fee), - GNUNET_JSON_pack_data_auto ("purse_pub", - &pd->purse_pub), - GNUNET_JSON_pack_data_auto ("exchange_sig", - &esig), - GNUNET_JSON_pack_data_auto ("exchange_pub", - &epub)))) - { - GNUNET_break (0); - json_decref (history); - return NULL; - } - break; - } -#endif } } return history; diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 83f99f46f..2d99311af 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -1269,9 +1269,12 @@ prepare_statements (struct PostgresClosure *pg) ",purse_pub" ",coin_sig" ",purse_deposit_serial_id" + ",pr.refunded" " FROM purse_deposits pd" " LEFT JOIN partners" " USING (partner_serial_id)" + " JOIN purse_requests pr" + " USING (purse_pub)" " JOIN known_coins kc" " ON (pd.coin_pub = kc.coin_pub)" " JOIN denominations denoms" @@ -8314,6 +8317,8 @@ add_coin_purse_deposit (void *cls, NULL), GNUNET_PQ_result_spec_auto_from_type ("coin_sig", &deposit->coin_sig), + GNUNET_PQ_result_spec_bool ("refunded", + &deposit->refunded), GNUNET_PQ_result_spec_end }; diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index 0bc53e1eb..707ce311f 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h @@ -1679,6 +1679,11 @@ struct TALER_EXCHANGEDB_PurseDepositListEntry */ struct TALER_CoinSpendSignatureP coin_sig; + /** + * Set to true if the coin was refunded. + */ + bool refunded; + }; /** 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; } |