merchant

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

select_order_blinded_sigs.c (3721B)


      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_pq_lib.h>
     23 #include "merchant-database/select_order_blinded_sigs.h"
     24 #include "helper.h"
     25 
     26 /**
     27  * @brief Context for the callback to handle the result of the blinded sigs selection.
     28  */
     29 struct SelectBlindedSigsContext
     30 {
     31   /**
     32    * @brief Callback to be called with the result of the blinded sigs selection.
     33    */
     34   void *cb_cls;
     35 
     36   /**
     37    * @brief Callback to be called with the result of the blinded sigs selection.
     38    */
     39   TALER_MERCHANTDB_BlindedSigCallback cb;
     40 
     41   /**
     42    * @brief Result status of the query.
     43    */
     44   enum GNUNET_DB_QueryStatus qs;
     45 };
     46 
     47 
     48 /**
     49  * @brief Callback to handle the result of the blinded sigs selection.
     50  *
     51  * @param cls the closure containing the callback and its context
     52  * @param result the result of the query
     53  * @param num_results number of results in the result set
     54  */
     55 static void
     56 restore_sig_cb (void *cls,
     57                 PGresult *result,
     58                 unsigned int num_results)
     59 {
     60   struct SelectBlindedSigsContext *ctx = cls;
     61 
     62   for (unsigned int i = 0; i < num_results; i++)
     63   {
     64     struct GNUNET_HashCode h_issue;
     65     struct GNUNET_CRYPTO_BlindedSignature *sig;
     66     struct GNUNET_PQ_ResultSpec rs[] = {
     67       GNUNET_PQ_result_spec_auto_from_type ("token_hash",
     68                                             &h_issue),
     69       GNUNET_PQ_result_spec_blinded_sig ("token_blinded_signature",
     70                                          &sig),
     71       GNUNET_PQ_result_spec_end
     72     };
     73 
     74     if (GNUNET_OK !=
     75         GNUNET_PQ_extract_result (result,
     76                                   rs,
     77                                   i))
     78     {
     79       ctx->qs = GNUNET_DB_STATUS_HARD_ERROR;
     80       return;
     81     }
     82     ctx->cb (ctx->cb_cls,
     83              &h_issue,
     84              sig);
     85     GNUNET_PQ_cleanup_result (rs);
     86   }
     87 }
     88 
     89 
     90 enum GNUNET_DB_QueryStatus
     91 TALER_MERCHANTDB_select_order_blinded_sigs (
     92   struct TALER_MERCHANTDB_PostgresContext *pg,
     93   const char *order_id,
     94   TALER_MERCHANTDB_BlindedSigCallback cb,
     95   void *cb_cls)
     96 {
     97   struct SelectBlindedSigsContext ctx = {
     98     .cb = cb,
     99     .cb_cls = cb_cls,
    100     .qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
    101   };
    102   struct GNUNET_PQ_QueryParam params[] = {
    103     GNUNET_PQ_query_param_string (order_id),
    104     GNUNET_PQ_query_param_end
    105   };
    106 
    107   GNUNET_assert (NULL != pg->current_merchant_id);
    108   check_connection (pg);
    109   TMH_PQ_prepare_anon (pg,
    110                        "SELECT"
    111                        "  motbs.token_blinded_signature"
    112                        " ,motbs.token_hash"
    113                        " FROM merchant_order_token_blinded_sigs AS motbs"
    114                        " JOIN merchant_contract_terms AS mct USING (order_serial)"
    115                        " WHERE mct.order_id = $1"
    116                        " ORDER BY motbs.token_index ASC");
    117   return GNUNET_PQ_eval_prepared_multi_select (
    118     pg->conn,
    119     "",
    120     params,
    121     &restore_sig_cb,
    122     &ctx);
    123 }