summaryrefslogtreecommitdiff
path: root/src/exchange
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-05-22 16:18:09 +0200
committerChristian Grothoff <christian@grothoff.org>2022-05-22 16:18:09 +0200
commit4a5d71cca2297cfd98b5dd907df2fc355d0da297 (patch)
treecfa1a24613b09d5bc6e36bad41479bb4551761df /src/exchange
parent96fb11bed0def1bfb3666b732dd32be253f46c01 (diff)
downloadexchange-4a5d71cca2297cfd98b5dd907df2fc355d0da297.tar.gz
exchange-4a5d71cca2297cfd98b5dd907df2fc355d0da297.tar.bz2
exchange-4a5d71cca2297cfd98b5dd907df2fc355d0da297.zip
-implement reserve history DB logic
Diffstat (limited to 'src/exchange')
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_history.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/exchange/taler-exchange-httpd_reserves_history.c b/src/exchange/taler-exchange-httpd_reserves_history.c
index 96902d01c..4766dadc8 100644
--- a/src/exchange/taler-exchange-httpd_reserves_history.c
+++ b/src/exchange/taler-exchange-httpd_reserves_history.c
@@ -96,6 +96,8 @@ reply_reserve_history_success (struct MHD_Connection *connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_JSON_ALLOCATION_FAILURE,
NULL);
+ /* FIXME: should set explicit cache control headers
+ for this response to enable caching! */
return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_OK,
@@ -129,7 +131,45 @@ reserve_history_transaction (void *cls,
struct ReserveHistoryContext *rsc = cls;
enum GNUNET_DB_QueryStatus qs;
- // FIXME: first deduct rsc->gf->fees.history from reserve balance (and persist the signature justifying this)
+ if (! TALER_amount_is_zero (&rsc->gf->fees.history))
+ {
+ bool balance_ok = false;
+ bool idempotent = true;
+
+ qs = TEH_plugin->insert_history_request (TEH_plugin->cls,
+ rsc->reserve_pub,
+ &rsc->reserve_sig,
+ rsc->timestamp,
+ &rsc->gf->fees.history,
+ &balance_ok,
+ &idempotent);
+ if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+ {
+ GNUNET_break (0);
+ *mhd_ret
+ = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "get_reserve_history");
+ }
+ if (qs <= 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return qs;
+ }
+ if (! balance_ok)
+ {
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_EXCHANGE_WITHDRAW_HISTORY_ERROR_INSUFFICIENT_FUNDS,
+ NULL);
+ }
+ if (idempotent)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Idempotent /reserves/history request observed. Is caching working?\n");
+ }
+ }
qs = TEH_plugin->get_reserve_history (TEH_plugin->cls,
rsc->reserve_pub,
&rsc->balance,