pg_select_order_blinded_sigs.c (3678B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2025 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER 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 General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file backenddb/pg_select_order_blinded_sigs.c 18 * @brief Implementation of the select blinded sigs by order_id function for Postgres 19 * @author Bohdan Potuzhnyi 20 */ 21 #include "platform.h" 22 #include <taler/taler_error_codes.h> 23 #include <taler/taler_dbevents.h> 24 #include <taler/taler_pq_lib.h> 25 #include "pg_select_order_blinded_sigs.h" 26 #include "pg_helper.h" 27 28 /** 29 * @brief Context for the callback to handle the result of the blinded sigs selection. 30 */ 31 struct SelectBlindedSigsContext 32 { 33 /** 34 * @brief Callback to be called with the result of the blinded sigs selection. 35 */ 36 void *cb_cls; 37 38 /** 39 * @brief Callback to be called with the result of the blinded sigs selection. 40 */ 41 TALER_MERCHANTDB_BlindedSigCallback cb; 42 43 /** 44 * @brief Result status of the query. 45 */ 46 enum GNUNET_DB_QueryStatus qs; 47 }; 48 49 50 /** 51 * @brief Callback to handle the result of the blinded sigs selection. 52 * 53 * @param cls the closure containing the callback and its context 54 * @param result the result of the query 55 * @param num_results number of results in the result set 56 */ 57 static void 58 restore_sig_cb (void *cls, 59 PGresult *result, 60 unsigned int num_results) 61 { 62 struct SelectBlindedSigsContext *ctx = cls; 63 64 for (unsigned int i = 0; i < num_results; i++) 65 { 66 struct GNUNET_HashCode h_issue; 67 struct GNUNET_CRYPTO_BlindedSignature *sig; 68 struct GNUNET_PQ_ResultSpec rs[] = { 69 GNUNET_PQ_result_spec_auto_from_type ("token_hash", 70 &h_issue), 71 GNUNET_PQ_result_spec_blinded_sig ("token_blinded_signature", 72 &sig), 73 GNUNET_PQ_result_spec_end 74 }; 75 76 if (GNUNET_OK != 77 GNUNET_PQ_extract_result (result, 78 rs, 79 i)) 80 { 81 ctx->qs = GNUNET_DB_STATUS_HARD_ERROR; 82 return; 83 } 84 ctx->cb (ctx->cb_cls, 85 &h_issue, 86 sig); 87 GNUNET_PQ_cleanup_result (rs); 88 } 89 } 90 91 92 enum GNUNET_DB_QueryStatus 93 TMH_PG_select_order_blinded_sigs ( 94 void *cls, 95 const char *order_id, 96 TALER_MERCHANTDB_BlindedSigCallback cb, 97 void *cb_cls) 98 { 99 struct PostgresClosure *pg = cls; 100 struct SelectBlindedSigsContext ctx = { 101 .cb = cb, 102 .cb_cls = cb_cls, 103 .qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS 104 }; 105 106 struct GNUNET_PQ_QueryParam params[] = { 107 GNUNET_PQ_query_param_string (order_id), 108 GNUNET_PQ_query_param_end 109 }; 110 111 check_connection (pg); 112 PREPARE (pg, 113 "select_blinded_sigs", 114 "SELECT" 115 " motbs.token_blinded_signature" 116 " ,motbs.token_hash" 117 " FROM merchant_order_token_blinded_sigs AS motbs" 118 " JOIN merchant_contract_terms AS mct USING (order_serial)" 119 " WHERE mct.order_id = $1" 120 " ORDER BY motbs.token_index ASC"); 121 return GNUNET_PQ_eval_prepared_multi_select ( 122 pg->conn, 123 "select_blinded_sigs", 124 params, 125 &restore_sig_cb, 126 &ctx); 127 }