merchant

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

do_insert_fountain.c (3851B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2026 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/do_insert_fountain.c
     18  * @brief Implementation of the do_insert_fountain function for Postgres
     19  * @author Bohdan Potuzhnyi
     20  */
     21 #include "platform.h"
     22 #include <taler/taler_pq_lib.h>
     23 #include "merchant-database/do_insert_fountain.h"
     24 #include "helper.h"
     25 
     26 
     27 enum GNUNET_DB_QueryStatus
     28 TALER_MERCHANTDB_do_insert_fountain (
     29   struct TALER_MERCHANTDB_PostgresContext *pg,
     30   const char *instance_id,
     31   const char *fountain_id,
     32   const struct GNUNET_HashCode *h_fountain_secret,
     33   const char *description,
     34   struct GNUNET_TIME_Relative poll_freq,
     35   unsigned int grants_len,
     36   const struct TALER_MERCHANTDB_FountainGrant grants[static grants_len],
     37   char **unknown_slug,
     38   bool *conflict)
     39 {
     40   const char *slugs[GNUNET_NZL (grants_len)];
     41   uint64_t limits[GNUNET_NZL (grants_len)];
     42   uint64_t stashes[GNUNET_NZL (grants_len)];
     43   uint64_t windows[GNUNET_NZL (grants_len)];
     44   struct GNUNET_PQ_QueryParam params[] = {
     45     GNUNET_PQ_query_param_string (fountain_id),
     46     GNUNET_PQ_query_param_auto_from_type (h_fountain_secret),
     47     GNUNET_PQ_query_param_string (description),
     48     GNUNET_PQ_query_param_relative_time (&poll_freq),
     49     GNUNET_PQ_query_param_array_ptrs_string (grants_len,
     50                                              slugs,
     51                                              pg->conn),
     52     GNUNET_PQ_query_param_array_uint64 (grants_len,
     53                                         limits,
     54                                         pg->conn),
     55     GNUNET_PQ_query_param_array_uint64 (grants_len,
     56                                         stashes,
     57                                         pg->conn),
     58     GNUNET_PQ_query_param_array_uint64 (grants_len,
     59                                         windows,
     60                                         pg->conn),
     61     GNUNET_PQ_query_param_end
     62   };
     63   struct GNUNET_PQ_ResultSpec rs[] = {
     64     GNUNET_PQ_result_spec_allow_null (
     65       GNUNET_PQ_result_spec_string ("out_unknown_slug",
     66                                     unknown_slug),
     67       NULL),
     68     GNUNET_PQ_result_spec_bool ("out_conflict",
     69                                 conflict),
     70     GNUNET_PQ_result_spec_end
     71   };
     72   enum GNUNET_DB_QueryStatus qs;
     73 
     74   *unknown_slug = NULL;
     75   *conflict = false;
     76   for (unsigned int i = 0; i < grants_len; i++)
     77   {
     78     slugs[i] = grants[i].token_family_slug;
     79     limits[i] = grants[i].tokens_per_period_limit;
     80     stashes[i] = grants[i].tokens_per_period_stash;
     81     windows[i] = grants[i].key_window_size;
     82   }
     83   GNUNET_assert (NULL != pg->current_merchant_id);
     84   GNUNET_assert (0 == strcmp (instance_id,
     85                               pg->current_merchant_id));
     86   TMH_PQ_prepare_anon (pg,
     87                        "SELECT"
     88                        "  out_unknown_slug"
     89                        " ,out_conflict"
     90                        "  FROM merchant_do_insert_fountain"
     91                        " ($1, $2, $3, $4, $5, $6, $7, $8);");
     92   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     93                                                  "",
     94                                                  params,
     95                                                  rs);
     96   GNUNET_PQ_cleanup_query_params_closures (params);
     97   return qs;
     98 }