anastasis-db_mark_challenge_sent.c (3551B)
1 /* 2 This file is part of Anastasis 3 Copyright (C) 2020-2022 Anastasis SARL 4 5 Anastasis is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Affero General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. 12 13 You should have received a copy of the GNU Affero General Public License along with 14 Anastasis; see the file COPYING.GPL. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file stasis/anastasis-db_mark_challenge_sent.c 18 * @brief Anastasis database: mark challenge sent 19 * @author Christian Grothoff 20 */ 21 #include "platform.h" 22 #include "anastasis-db_pg.h" 23 #include "anastasis/anastasis-database/mark_challenge_sent.h" 24 #include "anastasis/anastasis-database/transaction.h" 25 #include "anastasis/anastasis-database/preflight.h" 26 #include <taler/taler_pq_lib.h> 27 28 29 /** 30 * Remember in the database that we successfully sent a challenge. 31 * 32 * @param payment_secret payment secret which the user must provide with every upload 33 * @param truth_uuid the identifier for the challenge 34 * @param code the challenge that was sent 35 */ 36 enum GNUNET_DB_QueryStatus 37 ANASTASIS_DB_mark_challenge_sent ( 38 const struct ANASTASIS_PaymentSecretP *payment_secret, 39 const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid, 40 uint64_t code) 41 { 42 enum GNUNET_DB_QueryStatus qs; 43 44 PREPARE ("challengecode_mark_sent", 45 "UPDATE anastasis_challengecode" 46 " SET retransmission_date=$3" 47 " WHERE truth_uuid=$1" 48 " AND code=$2" 49 " AND creation_date IN" 50 " (SELECT creation_date" 51 " FROM anastasis_challengecode" 52 " WHERE truth_uuid=$1" 53 " AND code=$2" 54 " ORDER BY creation_date DESC" 55 " LIMIT 1);"); 56 PREPARE ("challengepayment_dec_counter", 57 "UPDATE anastasis_challenge_payment" 58 " SET counter=counter - 1" 59 " WHERE truth_uuid=$1" 60 " AND payment_identifier=$2" 61 " AND counter > 0;"); 62 { 63 struct GNUNET_TIME_Timestamp now; 64 struct GNUNET_PQ_QueryParam params[] = { 65 GNUNET_PQ_query_param_auto_from_type (truth_uuid), 66 GNUNET_PQ_query_param_uint64 (&code), 67 GNUNET_PQ_query_param_timestamp (&now), 68 GNUNET_PQ_query_param_end 69 }; 70 71 now = GNUNET_TIME_timestamp_get (); 72 qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, 73 "challengecode_mark_sent", 74 params); 75 if (qs <= 0) 76 return qs; 77 } 78 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 79 "Marking challenge %llu as issued\n", 80 (unsigned long long) code); 81 { 82 struct GNUNET_PQ_QueryParam params[] = { 83 GNUNET_PQ_query_param_auto_from_type (truth_uuid), 84 GNUNET_PQ_query_param_auto_from_type (payment_secret), 85 GNUNET_PQ_query_param_end 86 }; 87 88 qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, 89 "challengepayment_dec_counter", 90 params); 91 if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) 92 return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; /* probably was free */ 93 return qs; 94 } 95 } 96 97 98 /* end of anastasis-db_mark_challenge_sent.c */