do_update_fountain.c (3937B)
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_update_fountain.c 18 * @brief Implementation of the do_update_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_update_fountain.h" 24 #include "helper.h" 25 26 27 enum GNUNET_DB_QueryStatus 28 TALER_MERCHANTDB_do_update_fountain ( 29 struct TALER_MERCHANTDB_PostgresContext *pg, 30 const char *instance_id, 31 const char *fountain_id, 32 const char *description, 33 const struct GNUNET_TIME_Relative *poll_freq, 34 bool replace_grants, 35 unsigned int grants_len, 36 const struct TALER_MERCHANTDB_FountainGrant *grants, 37 bool *not_found, 38 char **unknown_slug) 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 (NULL == description) 47 ? GNUNET_PQ_query_param_null () 48 : GNUNET_PQ_query_param_string (description), 49 (NULL == poll_freq) 50 ? GNUNET_PQ_query_param_null () 51 : GNUNET_PQ_query_param_relative_time (poll_freq), 52 GNUNET_PQ_query_param_bool (replace_grants), 53 GNUNET_PQ_query_param_array_ptrs_string (grants_len, 54 slugs, 55 pg->conn), 56 GNUNET_PQ_query_param_array_uint64 (grants_len, 57 limits, 58 pg->conn), 59 GNUNET_PQ_query_param_array_uint64 (grants_len, 60 stashes, 61 pg->conn), 62 GNUNET_PQ_query_param_array_uint64 (grants_len, 63 windows, 64 pg->conn), 65 GNUNET_PQ_query_param_end 66 }; 67 struct GNUNET_PQ_ResultSpec rs[] = { 68 GNUNET_PQ_result_spec_bool ("out_not_found", 69 not_found), 70 GNUNET_PQ_result_spec_allow_null ( 71 GNUNET_PQ_result_spec_string ("out_unknown_slug", 72 unknown_slug), 73 NULL), 74 GNUNET_PQ_result_spec_end 75 }; 76 enum GNUNET_DB_QueryStatus qs; 77 78 *not_found = false; 79 *unknown_slug = NULL; 80 for (unsigned int i = 0; i < grants_len; i++) 81 { 82 slugs[i] = grants[i].token_family_slug; 83 limits[i] = grants[i].tokens_per_period_limit; 84 stashes[i] = grants[i].tokens_per_period_stash; 85 windows[i] = grants[i].key_window_size; 86 } 87 GNUNET_assert (NULL != pg->current_merchant_id); 88 GNUNET_assert (0 == strcmp (instance_id, 89 pg->current_merchant_id)); 90 TMH_PQ_prepare_anon (pg, 91 "SELECT" 92 " out_not_found" 93 " ,out_unknown_slug" 94 " FROM merchant_do_update_fountain" 95 " ($1, $2, $3, $4, $5, $6, $7, $8);"); 96 qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 97 "", 98 params, 99 rs); 100 GNUNET_PQ_cleanup_query_params_closures (params); 101 return qs; 102 }