commit b31b93eda7e62079894c9d65758068fe3d6a8c32
parent 331d587cb8e88df66381309b44a1403d7f928f9e
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date: Tue, 19 Mar 2024 21:08:29 +0100
[donau] some changes on issue receipt
Diffstat:
3 files changed, 31 insertions(+), 50 deletions(-)
diff --git a/src/donau/donau-httpd_batch-issue.h b/src/donau/donau-httpd_batch-issue.h
@@ -36,6 +36,6 @@ MHD_RESULT
DH_handler_issue_receipts_post (
struct DH_RequestContext *rc,
const json_t *root,
- const char *const args[]);
+ const char *const args[1]);
#endif
diff --git a/src/donau/donau-httpd_issue-receipts.h b/src/donau/donau-httpd_issue-receipts.h
@@ -1,41 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2024 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Affero General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file donau-httpd_batch-issue.h
- * @brief Handle /batch-issue requests
- * @author Lukas Matyja
- */
-#ifndef DONAU_HTTPD_ISSUE_RECEIPTS_H
-#define DONAU_HTTPD_ISSUE_RECEIPTS_H
-
-#include <microhttpd.h>
-#include "donau-httpd.h"
-
-
-/**
- * Handle a POST "/batch-issue" request.
- *
- * @param connection the MHD connection to handle
- * @param root uploaded JSON data
- * @return MHD result code
- */
-MHD_RESULT
-DH_handler_issue_receipts_post (
- struct DH_RequestContext *rc,
- const json_t *root,
- const char *const args[]);
-
-#endif
diff --git a/src/donau/donau-httpd_post-batch-issue.c b/src/donau/donau-httpd_post-batch-issue.c
@@ -204,13 +204,13 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc,
}
// Get charity pub
- struct DONAUDB_CharityMetaData meta;
- enum GNUNET_DB_QueryStatus qs;
+ struct DONAUDB_CharityMetaData charity_meta;
+ enum GNUNET_DB_QueryStatus qs_charity;
- qs = DH_plugin->lookup_charity (DH_plugin->cls,
+ qs_charity = DH_plugin->lookup_charity (DH_plugin->cls,
(uint64_t) charity_id,
- &meta);
- switch (qs)
+ &charity_meta);
+ switch (qs_charity)
{
case GNUNET_DB_STATUS_HARD_ERROR:
case GNUNET_DB_STATUS_SOFT_ERROR:
@@ -233,7 +233,7 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc,
/* verify charity signature */
if (GNUNET_OK !=
DONAU_charity_budi_key_pair_verify(num_bkp, &irc.bkp,
- &meta.charity_pub,
+ &charity_meta.charity_pub,
&irc.charity_sig))
{
GNUNET_break_op (0);
@@ -245,13 +245,35 @@ DH_handler_issue_receipts_post (struct DH_RequestContext *rc,
}
/* request already made? -> idempotent */
+ enum GNUNET_DB_QueryStatus qs_check_receipts;
+ struct DONAUDB_IssuedReceiptsMetaData check_receipts_meta;
+ struct DONAU_BudiKeyPairsHashP bkp_hash;
+ GNUNET_CRYPTO_hash (irc.bkp,
+ sizeof (irc.bkp[0]) * num_bkp,
+ &bkp_hash.hash);
-
+ qs_check_receipts = DH_plugin->lookup_issued_receipts (DH_plugin->cls,
+ bkp_hash,
+ &check_receipts_meta);
+ switch (qs_check_receipts)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ NULL);
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ break; // it's the first request from the charity, we can proceed
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ // A request was already made. We do not change the annual limit
+ break;
+ }
/* check annual limit and change it -> Rollback if we could not save the request*/
/* save Request (charity signature, charity id, amount, hash over bkps) and make it idempotent*/
/* sign budis and send the signatures back */
-
// {
// MHD_RESULT mhd_ret;
//