merchant

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

pg_update_money_pot.c (3372B)


      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_update_money_pot.c
     18  * @brief Implementation of the update_money_pot function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "taler/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_update_money_pot.h"
     26 #include "pg_helper.h"
     27 
     28 
     29 enum GNUNET_DB_QueryStatus
     30 TMH_PG_update_money_pot (
     31   void *cls,
     32   const char *instance_id,
     33   uint64_t money_pot_id,
     34   const char *name,
     35   const char *description,
     36   size_t opt_len,
     37   const struct TALER_Amount *old_pot_totals,
     38   size_t npt_len,
     39   const struct TALER_Amount *new_pot_totals,
     40   bool *conflict_total,
     41   bool *conflict_name)
     42 {
     43   struct PostgresClosure *pg = cls;
     44   struct GNUNET_PQ_QueryParam params[] = {
     45     GNUNET_PQ_query_param_string (instance_id),
     46     GNUNET_PQ_query_param_uint64 (&money_pot_id),
     47     GNUNET_PQ_query_param_string (name),
     48     GNUNET_PQ_query_param_string (description),
     49     (NULL == old_pot_totals)
     50     ? GNUNET_PQ_query_param_null ()
     51     : TALER_PQ_query_param_array_amount_with_currency (opt_len,
     52                                                        old_pot_totals,
     53                                                        pg->conn),
     54     (NULL == new_pot_totals)
     55     ? GNUNET_PQ_query_param_null ()
     56     : TALER_PQ_query_param_array_amount_with_currency (npt_len,
     57                                                        new_pot_totals,
     58                                                        pg->conn),
     59     GNUNET_PQ_query_param_end
     60   };
     61   bool not_found;
     62   struct GNUNET_PQ_ResultSpec rs[] = {
     63     GNUNET_PQ_result_spec_bool ("conflict_total",
     64                                 conflict_total),
     65     GNUNET_PQ_result_spec_bool ("conflict_name",
     66                                 conflict_name),
     67     GNUNET_PQ_result_spec_bool ("not_found",
     68                                 &not_found),
     69     GNUNET_PQ_result_spec_end
     70   };
     71   enum GNUNET_DB_QueryStatus qs;
     72 
     73   check_connection (pg);
     74   PREPARE (pg,
     75            "update_money_pot",
     76            "SELECT"
     77            " out_conflict_name AS conflict_name"
     78            ",out_conflict_total AS conflict_total"
     79            ",out_not_found AS not_found"
     80            " FROM merchant_do_update_money_pot"
     81            "($1,$2,$3,$4,$5,$6);");
     82   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     83                                                  "update_money_pot",
     84                                                  params,
     85                                                  rs);
     86   GNUNET_PQ_cleanup_query_params_closures (params);
     87   if (qs <= 0)
     88     return qs;
     89   if (not_found)
     90     return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
     91   return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
     92 }