merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

select_order_blinded_sigs.c (3822B)


      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 src/backenddb/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 "merchant-database/select_order_blinded_sigs.h"
     26 #include "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 TALER_MERCHANTDB_select_order_blinded_sigs (struct TALER_MERCHANTDB_PostgresContext *pg,
     94                                             const char *order_id,
     95                                             TALER_MERCHANTDB_BlindedSigCallback cb,
     96                                             void *cb_cls)
     97 {
     98   struct SelectBlindedSigsContext ctx = {
     99     .cb = cb,
    100     .cb_cls = cb_cls,
    101     .qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
    102   };
    103 
    104   struct GNUNET_PQ_QueryParam params[] = {
    105     GNUNET_PQ_query_param_string (order_id),
    106     GNUNET_PQ_query_param_end
    107   };
    108 
    109   check_connection (pg);
    110   PREPARE (pg,
    111            "select_blinded_sigs",
    112            "SELECT"
    113            "  motbs.token_blinded_signature"
    114            " ,motbs.token_hash"
    115            " FROM merchant_order_token_blinded_sigs AS motbs"
    116            " JOIN merchant_contract_terms AS mct USING (order_serial)"
    117            " WHERE mct.order_id = $1"
    118            " ORDER BY motbs.token_index ASC");
    119   return GNUNET_PQ_eval_prepared_multi_select (
    120     pg->conn,
    121     "select_blinded_sigs",
    122     params,
    123     &restore_sig_cb,
    124     &ctx);
    125 }