merchant

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

commit 4f3756b826bedc1dfeca19bd2671af66630fb7f6
parent d3cc24a0c4ef238279d46ccb004eb04f87e9a56a
Author: Christian Grothoff <christian@grothoff.org>
Date:   Mon, 29 Dec 2025 06:24:44 +0100

add check_money_pots DB API

Diffstat:
Msrc/backend/taler-merchant-report-generator.c | 2+-
Msrc/backenddb/Makefile.am | 1+
Asrc/backenddb/pg_check_money_pots.c | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/pg_check_money_pots.h | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/backenddb/plugin_merchantdb_postgres.c | 3+++
Msrc/include/taler_merchantdb_plugin.h | 31+++++++++++++++++++++++++++----
6 files changed, 152 insertions(+), 5 deletions(-)

diff --git a/src/backend/taler-merchant-report-generator.c b/src/backend/taler-merchant-report-generator.c @@ -28,7 +28,7 @@ #include <taler/taler_dbevents.h> #include <taler/taler_error_codes.h> #include "taler_merchantdb_plugin.h" -#include "taler/taler_merchantdb_lib.h" +#include "taler_merchantdb_lib.h" #include "taler_merchant_service.h" #include <curl/curl.h> diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am @@ -163,6 +163,7 @@ libtaler_plugin_merchantdb_postgres_la_SOURCES = \ pg_insert_money_pot.h pg_insert_money_pot.c \ pg_delete_money_pot.h pg_delete_money_pot.c \ pg_update_money_pot.h pg_update_money_pot.c \ + pg_check_money_pots.h pg_check_money_pots.c \ pg_select_money_pots.h pg_select_money_pots.c \ pg_select_money_pot.h pg_select_money_pot.c \ pg_lock_product.h pg_lock_product.c \ diff --git a/src/backenddb/pg_check_money_pots.c b/src/backenddb/pg_check_money_pots.c @@ -0,0 +1,69 @@ +/* + This file is part of TALER + Copyright (C) 2025 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file backenddb/pg_check_money_pots.c + * @brief Implementation of the check_money_pots function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "pg_check_money_pots.h" +#include "pg_helper.h" + + +enum GNUNET_DB_QueryStatus +TMH_PG_check_money_pots (void *cls, + const char *instance_id, + unsigned int pots_len, + uint64_t pots[static pots_len], + uint64_t *pot_missing) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (instance_id), + GNUNET_PQ_query_param_array_uint64 (pots_len, + pots, + pg->conn), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("out_missing", + pot_missing), + GNUNET_PQ_result_spec_end + }; + + check_connection (pg); + PREPARE (pg, + "check_money_pots", + "SELECT n AS out_missing" + " FROM UNNEST($2::INT8[]) AS n" + " WHERE NOT EXISTS (" + " SELECT 1" + " FROM merchant_money_pots mmp" + " JOIN merchant_instances mi" + " USING (merchant_serial)" + " WHERE mmp.money_pot_serial=n" + " AND mi.merchant_id=$1" + " )" + " LIMIT 1;"); + return GNUNET_PQ_eval_prepared_singleton_select ( + pg->conn, + "check_money_pots", + params, + rs); +} diff --git a/src/backenddb/pg_check_money_pots.h b/src/backenddb/pg_check_money_pots.h @@ -0,0 +1,51 @@ +/* + This file is part of TALER + Copyright (C) 2025 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file backenddb/pg_check_money_pots.h + * @brief implementation of the check_money_pots function for Postgres + * @author Christian Grothoff + */ +#ifndef PG_CHECK_MONEY_POTS_H +#define PG_CHECK_MONEY_POTS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "taler_merchantdb_plugin.h" + + +/** + * Check that all of the money pots given exist at the instance, + * returning one that does *not* exist (for generating an error) + * if the check fails. + * + * @param cls closure + * @param instance_id instance to lookup token families for + * @param pots_len length of the @a pots array + * @param pots money pot identifiers to check if they exist + * @param[out] pot_missing set to ID of pot not known at the instance + * @return transaction status, + * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS means that all pots exist + * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT indicates that + * @a pot_missing was initialized to a missing pot + */ +enum GNUNET_DB_QueryStatus +TMH_PG_check_money_pots (void *cls, + const char *instance_id, + unsigned int pots_len, + uint64_t pots[static pots_len], + uint64_t *pot_missing); + +#endif diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c @@ -74,6 +74,7 @@ #include "pg_insert_money_pot.h" #include "pg_delete_money_pot.h" #include "pg_update_money_pot.h" +#include "pg_check_money_pots.h" #include "pg_select_money_pots.h" #include "pg_select_money_pot.h" #include "pg_update_wirewatch_progress.h" @@ -719,6 +720,8 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) = &TMH_PG_delete_money_pot; plugin->update_money_pot = &TMH_PG_update_money_pot; + plugin->check_money_pots + = &TMH_PG_check_money_pots; plugin->select_money_pots = &TMH_PG_select_money_pots; plugin->select_money_pot diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h @@ -4944,7 +4944,7 @@ struct TALER_MERCHANTDB_Plugin * Lookup all of the money pots the given instance has configured. * * @param cls closure - * @param instance_id instance to lookup token families for + * @param instance_id instance to lookup money pots for * @param limit number of entries to return, negative for descending in execution time, * positive for ascending in execution time * @param offset number of the money pot we want to offset from @@ -4960,11 +4960,34 @@ struct TALER_MERCHANTDB_Plugin TALER_MERCHANTDB_MoneyPotsCallback cb, void *cb_cls); + + /** + * Check that all of the money pots given exist at the instance, + * returning one that does *not* exist (for generating an error) + * if the check fails. + * + * @param cls closure + * @param instance_id instance to lookup token families for + * @param pots_len length of the @a pots array + * @param pots money pot identifiers to check if they exist + * @param[out] pot_missing set to ID of pot not known at the instance + * @return transaction status, + * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS means that all pots exist + * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT indicates that + * @a pot_missing was initialized to a missing pot + */ + enum GNUNET_DB_QueryStatus + (*check_money_pots)(void *cls, + const char *instance_id, + unsigned int pots_len, + uint64_t pots[static pots_len], + uint64_t *pot_missing); + /** * Lookup details about a particular money pot. * * @param cls closure - * @param instance_id instance to lookup token family for + * @param instance_id instance to lookup money pot for * @param money_pot_id serial number of the pot to lookup * @param [out] name set to name of the pot, * must be freed by caller @@ -4988,7 +5011,7 @@ struct TALER_MERCHANTDB_Plugin * Delete information about a money pot. * * @param cls closure - * @param instance_id instance to delete token family of + * @param instance_id instance to delete money pot of * @param money_pot_id serial number of the pot to delete * @return database result code */ @@ -5001,7 +5024,7 @@ struct TALER_MERCHANTDB_Plugin * Update details about a particular money pot. * * @param cls closure - * @param instance_id instance to update token family for + * @param instance_id instance to update money pot for * @param money_pot_id serial number of the pot to delete * @param name set to name of the pot * @param description set to description of the pot