merchant

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

commit 99d671b4f2c1f543c7016892038c170f4dc5674e
parent bfc2668f58bef4735320bbc21219f8357674f8ab
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed, 22 Jul 2026 03:13:24 +0200

merchantdb: start DB rename fest

Diffstat:
Mdebian/control | 2+-
Msrc/backend/taler-merchant-httpd.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_delete-private-orders-ORDER_ID.c | 24++++++++++++------------
Msrc/backend/taler-merchant-httpd_delete-private-tokens-SERIAL.c | 8++++----
Msrc/backend/taler-merchant-httpd_get-orders-ORDER_ID.c | 4++--
Msrc/backend/taler-merchant-httpd_get-private-orders-ORDER_ID.c | 24++++++++++++------------
Msrc/backend/taler-merchant-httpd_get-private-orders.c | 24++++++++++++------------
Msrc/backend/taler-merchant-httpd_get-private-statistics-report-transactions.c | 8++++----
Msrc/backend/taler-merchant-httpd_get-products-IMAGE_HASH-image.c | 2+-
Msrc/backend/taler-merchant-httpd_post-orders-ORDER_ID-pay.c | 4++--
Msrc/backend/taler-merchant-webhook.c | 6+++---
Msrc/backenddb/delete_login_token.c | 23-----------------------
Asrc/backenddb/delete_login_token_by_serial.c | 47+++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/backenddb/lookup_contract_terms2.c | 90-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_contract_terms3.c | 102-------------------------------------------------------------------------------
Asrc/backenddb/lookup_contract_terms_pos.c | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/lookup_contract_terms_status.c | 102+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/backenddb/lookup_instances.c | 6+++---
Msrc/backenddb/lookup_pending_webhooks.c | 6+++---
Dsrc/backenddb/lookup_product_image.c | 58----------------------------------------------------------
Asrc/backenddb/lookup_product_image_by_hash.c | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/backenddb/lookup_statistics_amount_by_bucket2.c | 163-------------------------------------------------------------------------------
Asrc/backenddb/lookup_statistics_amount_by_bucket_range.c | 163+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/backenddb/lookup_statistics_counter_by_bucket2.c | 185-------------------------------------------------------------------------------
Asrc/backenddb/lookup_statistics_counter_by_bucket_range.c | 185+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/backenddb/meson.build | 11++++++-----
Msrc/backenddb/test_merchantdb.c | 46+++++++++++++++++++++++-----------------------
Msrc/include/merchant-database/all.h | 25++++++++++++++++++-------
Msrc/include/merchant-database/delete_login_token.h | 15---------------
Asrc/include/merchant-database/delete_login_token_by_serial.h | 46++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/merchant-database/lookup_contract_terms2.h | 55-------------------------------------------------------
Dsrc/include/merchant-database/lookup_contract_terms3.h | 59-----------------------------------------------------------
Asrc/include/merchant-database/lookup_contract_terms_pos.h | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/lookup_contract_terms_status.h | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/include/merchant-database/lookup_instances.h | 2+-
Msrc/include/merchant-database/lookup_pending_webhooks.h | 31++++++-------------------------
Dsrc/include/merchant-database/lookup_product_image.h | 34----------------------------------
Asrc/include/merchant-database/lookup_product_image_by_hash.h | 34++++++++++++++++++++++++++++++++++
Dsrc/include/merchant-database/lookup_statistics_amount_by_bucket2.h | 92-------------------------------------------------------------------------------
Asrc/include/merchant-database/lookup_statistics_amount_by_bucket_range.h | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/merchant-database/lookup_statistics_counter_by_bucket2.h | 71-----------------------------------------------------------------------
Asrc/include/merchant-database/lookup_statistics_counter_by_bucket_range.h | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
42 files changed, 1123 insertions(+), 1072 deletions(-)

diff --git a/debian/control b/debian/control @@ -6,7 +6,7 @@ Build-Depends: meson, ninja-build, debhelper-compat (= 12), - libgnunet-dev (>=0.27.0), + libgnunet-dev (>=0.28.0~dev5), libtalerexchange-dev (>=1.5.0), libpq-dev (>=15.0), libdonau-dev (>=1.5.0), diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c @@ -1011,11 +1011,11 @@ load_instances (void *cls, &mi->h_instance, mi); } - qs = TALER_MERCHANTDB_lookup_instance (TMH_db, - id, - false, - &add_instance_cb, - NULL); + qs = TALER_MERCHANTDB_lookup_instances_by_id (TMH_db, + id, + false, + &add_instance_cb, + NULL); } if (0 > qs) { diff --git a/src/backend/taler-merchant-httpd_delete-private-orders-ORDER_ID.c b/src/backend/taler-merchant-httpd_delete-private-orders-ORDER_ID.c @@ -24,7 +24,7 @@ #include <taler/taler_json_lib.h> #include "merchant-database/delete_contract_terms.h" #include "merchant-database/delete_order.h" -#include "merchant-database/lookup_contract_terms3.h" +#include "merchant-database/lookup_contract_terms_status.h" #include "merchant-database/lookup_order.h" @@ -90,17 +90,17 @@ TMH_private_delete_orders_ID (const struct TMH_RequestHandler *rh, NULL); if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) { - qs = TALER_MERCHANTDB_lookup_contract_terms3 (TMH_db, - mi->settings.id, - hc->infix, - NULL, - NULL, - &order_serial, - &paid, - &wired, - &matches, - NULL, - &choice_index); + qs = TALER_MERCHANTDB_lookup_contract_terms_status (TMH_db, + mi->settings.id, + hc->infix, + NULL, + NULL, + &order_serial, + &paid, + &wired, + &matches, + NULL, + &choice_index); } if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) return TALER_MHD_reply_with_error (connection, diff --git a/src/backend/taler-merchant-httpd_delete-private-tokens-SERIAL.c b/src/backend/taler-merchant-httpd_delete-private-tokens-SERIAL.c @@ -26,7 +26,7 @@ #include "taler-merchant-httpd_delete-private-tokens-SERIAL.h" #include "taler-merchant-httpd_helper.h" #include <taler/taler_json_lib.h> -#include "merchant-database/delete_login_token.h" +#include "merchant-database/delete_login_token_by_serial.h" enum MHD_Result @@ -55,9 +55,9 @@ TMH_private_delete_instances_ID_token_SERIAL ( } - qs = TALER_MERCHANTDB_delete_login_token_serial (TMH_db, - mi->settings.id, - serial); + qs = TALER_MERCHANTDB_delete_login_token_by_serial (TMH_db, + mi->settings.id, + serial); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/backend/taler-merchant-httpd_get-orders-ORDER_ID.c b/src/backend/taler-merchant-httpd_get-orders-ORDER_ID.c @@ -35,7 +35,7 @@ #include "taler/taler_error_codes.h" #include "taler/taler_util.h" #include "taler/taler_merchant_util.h" -#include "merchant-database/lookup_contract_terms3.h" +#include "merchant-database/lookup_contract_terms_status.h" #include "merchant-database/lookup_order.h" #include "merchant-database/lookup_order_by_fulfillment.h" #include "merchant-database/lookup_order_status.h" @@ -648,7 +648,7 @@ phase_lookup_terms (struct GetOrderData *god) bool paid; bool wired; bool session_matches; - qs = TALER_MERCHANTDB_lookup_contract_terms3 ( + qs = TALER_MERCHANTDB_lookup_contract_terms_status ( TMH_db, god->hc->instance->settings.id, god->order_id, diff --git a/src/backend/taler-merchant-httpd_get-private-orders-ORDER_ID.c b/src/backend/taler-merchant-httpd_get-private-orders-ORDER_ID.c @@ -32,7 +32,7 @@ #include "taler-merchant-httpd_helper.h" #include "taler-merchant-httpd_get-private-orders.h" #include "taler-merchant-httpd_get-private-orders-ORDER_ID.h" -#include "merchant-database/lookup_contract_terms3.h" +#include "merchant-database/lookup_contract_terms_status.h" #include "merchant-database/lookup_deposits_by_order.h" #include "merchant-database/lookup_order.h" #include "merchant-database/lookup_order_by_fulfillment.h" @@ -696,17 +696,17 @@ phase_fetch_contract (struct GetOrderRequestContext *gorc) gorc->order_only = false; } TALER_MERCHANTDB_preflight (TMH_db); - qs = TALER_MERCHANTDB_lookup_contract_terms3 (TMH_db, - hc->instance->settings.id, - hc->infix, - gorc->session_id, - &gorc->contract_terms_json, - &gorc->order_serial, - &gorc->paid, - &gorc->wired, - &gorc->paid_session_matches, - &gorc->claim_token, - &gorc->choice_index); + qs = TALER_MERCHANTDB_lookup_contract_terms_status (TMH_db, + hc->instance->settings.id, + hc->infix, + gorc->session_id, + &gorc->contract_terms_json, + &gorc->order_serial, + &gorc->paid, + &gorc->wired, + &gorc->paid_session_matches, + &gorc->claim_token, + &gorc->choice_index); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "lookup_contract_terms (%s) returned %d\n", hc->infix, diff --git a/src/backend/taler-merchant-httpd_get-private-orders.c b/src/backend/taler-merchant-httpd_get-private-orders.c @@ -25,7 +25,7 @@ #include <taler/taler_merchant_util.h> #include <taler/taler_json_lib.h> #include <taler/taler_dbevents.h> -#include "merchant-database/lookup_contract_terms3.h" +#include "merchant-database/lookup_contract_terms_status.h" #include "merchant-database/lookup_order.h" #include "merchant-database/set_instance.h" #include "merchant-database/lookup_order_status_by_serial.h" @@ -534,17 +534,17 @@ add_order (void *cls, uint64_t os; bool session_matches; - qs = TALER_MERCHANTDB_lookup_contract_terms3 (TMH_db, - po->instance_id, - order_id, - NULL, - &terms, - &os, - &paid, - &wired, - &session_matches, - NULL, - &choice_index); + qs = TALER_MERCHANTDB_lookup_contract_terms_status (TMH_db, + po->instance_id, + order_id, + NULL, + &terms, + &os, + &paid, + &wired, + &session_matches, + NULL, + &choice_index); if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) { GNUNET_break (os == order_serial); diff --git a/src/backend/taler-merchant-httpd_get-private-statistics-report-transactions.c b/src/backend/taler-merchant-httpd_get-private-statistics-report-transactions.c @@ -24,8 +24,8 @@ #include <taler/taler_json_lib.h> #include <taler/taler_mhd_lib.h> #include "taler/taler_merchant_util.h" -#include "merchant-database/lookup_statistics_amount_by_bucket2.h" -#include "merchant-database/lookup_statistics_counter_by_bucket2.h" +#include "merchant-database/lookup_statistics_amount_by_bucket_range.h" +#include "merchant-database/lookup_statistics_counter_by_bucket_range.h" /** @@ -311,7 +311,7 @@ make_transaction_volume_report (struct ResponseContext *rctx, rctx->data_groups = json_array (); GNUNET_assert (NULL != rctx->data_groups); - qs = TALER_MERCHANTDB_lookup_statistics_amount_by_bucket2 ( + qs = TALER_MERCHANTDB_lookup_statistics_amount_by_bucket_range ( TMH_db, rctx->hc->instance->settings.id, bucket_name, @@ -464,7 +464,7 @@ make_transaction_count_report (struct ResponseContext *rctx, rctx->data_groups = json_array (); GNUNET_assert (NULL != rctx->data_groups); - qs = TALER_MERCHANTDB_lookup_statistics_counter_by_bucket2 ( + qs = TALER_MERCHANTDB_lookup_statistics_counter_by_bucket_range ( TMH_db, rctx->hc->instance->settings.id, prefix, /* prefix to match against bucket name */ diff --git a/src/backend/taler-merchant-httpd_get-products-IMAGE_HASH-image.c b/src/backend/taler-merchant-httpd_get-products-IMAGE_HASH-image.c @@ -22,7 +22,7 @@ #include "taler-merchant-httpd_get-products-IMAGE_HASH-image.h" #include "taler-merchant-httpd_helper.h" #include <taler/taler_error_codes.h> -#include "merchant-database/lookup_product_image.h" +#include "merchant-database/lookup_product_image_by_hash.h" enum MHD_Result diff --git a/src/backend/taler-merchant-httpd_post-orders-ORDER_ID-pay.c b/src/backend/taler-merchant-httpd_post-orders-ORDER_ID-pay.c @@ -58,7 +58,7 @@ struct ExchangeGroup; #include "merchant-database/insert_issued_token.h" #include "merchant-database/insert_order_blinded_sigs.h" #include "merchant-database/insert_spent_token.h" -#include "merchant-database/lookup_contract_terms2.h" +#include "merchant-database/lookup_contract_terms_pos.h" #include "merchant-database/lookup_deposits.h" #include "merchant-database/lookup_deposits_by_order.h" #include "merchant-database/lookup_order_charity.h" @@ -4512,7 +4512,7 @@ phase_check_contract (struct PayContext *pc) TALER_MERCHANT_contract_free (pc->check_contract.contract_terms); pc->check_contract.contract_terms = NULL; } - qs = TALER_MERCHANTDB_lookup_contract_terms2 ( + qs = TALER_MERCHANTDB_lookup_contract_terms_pos ( TMH_db, pc->hc->instance->settings.id, pc->order_id, diff --git a/src/backend/taler-merchant-webhook.c b/src/backend/taler-merchant-webhook.c @@ -498,9 +498,9 @@ select_work (void *cls) GNUNET_SCHEDULER_shutdown (); return; } - qs = TALER_MERCHANTDB_lookup_future_webhook (pg, - &future_webhook_cb, - NULL); + qs = TALER_MERCHANTDB_lookup_pending_webhooks_next (pg, + &future_webhook_cb, + NULL); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/backenddb/delete_login_token.c b/src/backenddb/delete_login_token.c @@ -25,29 +25,6 @@ enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_delete_login_token_serial ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *id, - uint64_t serial) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&serial), - GNUNET_PQ_query_param_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (id, - pg->current_merchant_id)); - TMH_PQ_prepare_anon (pg, - "DELETE FROM merchant_login_tokens" - " WHERE serial=$1"); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "", - params); -} - - -enum GNUNET_DB_QueryStatus TALER_MERCHANTDB_delete_login_token ( struct TALER_MERCHANTDB_PostgresContext *pg, const char *id, diff --git a/src/backenddb/delete_login_token_by_serial.c b/src/backenddb/delete_login_token_by_serial.c @@ -0,0 +1,47 @@ +/* + This file is part of TALER + Copyright (C) 2023, 2026 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 src/backenddb/delete_login_token_by_serial.c + * @brief Implementation of the delete_login_token_by_serial function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/delete_login_token_by_serial.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_delete_login_token_by_serial ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *id, + uint64_t serial) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&serial), + GNUNET_PQ_query_param_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (id, + pg->current_merchant_id)); + TMH_PQ_prepare_anon (pg, + "DELETE FROM merchant_login_tokens" + " WHERE serial=$1"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "", + params); +} diff --git a/src/backenddb/lookup_contract_terms2.c b/src/backenddb/lookup_contract_terms2.c @@ -1,90 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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 src/backenddb/lookup_contract_terms2.c - * @brief Implementation of the lookup_contract_terms2 function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_contract_terms2.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_contract_terms2 ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *order_id, - json_t **contract_terms, - uint64_t *order_serial, - bool *paid, - struct TALER_ClaimTokenP *claim_token, - char **pos_key, - enum TALER_MerchantConfirmationAlgorithm *pos_algorithm) -{ - enum GNUNET_DB_QueryStatus qs; - struct TALER_ClaimTokenP ct; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (order_id), - GNUNET_PQ_query_param_end - }; - uint32_t pos32 = TALER_MCA_NONE; - struct GNUNET_PQ_ResultSpec rs[] = { - /* contract_terms must be first! */ - TALER_PQ_result_spec_json ("contract_terms", - contract_terms), - GNUNET_PQ_result_spec_uint64 ("order_serial", - order_serial), - GNUNET_PQ_result_spec_bool ("paid", - paid), - GNUNET_PQ_result_spec_auto_from_type ("claim_token", - &ct), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("pos_key", - pos_key), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_uint32 ("pos_algorithm", - &pos32), - NULL), - GNUNET_PQ_result_spec_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance_id, - pg->current_merchant_id)); - TMH_PQ_prepare_anon (pg, - "SELECT" - " contract_terms::TEXT" - ",order_serial" - ",claim_token" - ",paid" - ",pos_key" - ",pos_algorithm" - " FROM merchant_contract_terms" - " WHERE order_id=$1"); - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - (NULL != contract_terms) - ? rs - : &rs[1]); - *pos_algorithm = (enum TALER_MerchantConfirmationAlgorithm) pos32; - if (NULL != claim_token) - *claim_token = ct; - return qs; -} diff --git a/src/backenddb/lookup_contract_terms3.c b/src/backenddb/lookup_contract_terms3.c @@ -1,102 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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 src/backenddb/lookup_contract_terms3.c - * @brief Implementation of the lookup_contract_terms3 function for Postgres - * @author Iván Ávalos - * @author Christian Grothoff - */ -#include "platform.h" -#include <sys/types.h> -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_contract_terms3.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_contract_terms3 ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *order_id, - const char *session_id, - json_t **contract_terms, - uint64_t *order_serial, - bool *paid, - bool *wired, - bool *session_matches, - struct TALER_ClaimTokenP *claim_token, - int16_t *choice_index) -{ - enum GNUNET_DB_QueryStatus qs; - struct TALER_ClaimTokenP ct; - uint16_t ci = 0; - bool choice_index_null = false; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (order_id), - NULL == session_id - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_string (session_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - /* contract_terms must be first! */ - TALER_PQ_result_spec_json ("contract_terms", - contract_terms), - GNUNET_PQ_result_spec_uint64 ("order_serial", - order_serial), - GNUNET_PQ_result_spec_bool ("paid", - paid), - GNUNET_PQ_result_spec_bool ("wired", - wired), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_bool ("session_matches", - session_matches), - NULL), - GNUNET_PQ_result_spec_auto_from_type ("claim_token", - &ct), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_uint16 ("choice_index", - &ci), - &choice_index_null), - GNUNET_PQ_result_spec_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance_id, - pg->current_merchant_id)); - *session_matches = false; - TMH_PQ_prepare_anon (pg, - "SELECT" - " contract_terms::TEXT" - ",order_serial" - ",claim_token" - ",paid" - ",wired" - ",(session_id=$2) AS session_matches" - ",choice_index" - " FROM merchant_contract_terms" - " WHERE order_id=$1"); - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - (NULL != contract_terms) - ? rs - : &rs[1]); - if (NULL != claim_token) - *claim_token = ct; - *choice_index = (choice_index_null) ? -1 : (int16_t) ci; - return qs; -} diff --git a/src/backenddb/lookup_contract_terms_pos.c b/src/backenddb/lookup_contract_terms_pos.c @@ -0,0 +1,90 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/backenddb/lookup_contract_terms_pos.c + * @brief Implementation of the lookup_contract_terms_pos function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/lookup_contract_terms_pos.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_lookup_contract_terms_pos ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *order_id, + json_t **contract_terms, + uint64_t *order_serial, + bool *paid, + struct TALER_ClaimTokenP *claim_token, + char **pos_key, + enum TALER_MerchantConfirmationAlgorithm *pos_algorithm) +{ + enum GNUNET_DB_QueryStatus qs; + struct TALER_ClaimTokenP ct; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (order_id), + GNUNET_PQ_query_param_end + }; + uint32_t pos32 = TALER_MCA_NONE; + struct GNUNET_PQ_ResultSpec rs[] = { + /* contract_terms must be first! */ + TALER_PQ_result_spec_json ("contract_terms", + contract_terms), + GNUNET_PQ_result_spec_uint64 ("order_serial", + order_serial), + GNUNET_PQ_result_spec_bool ("paid", + paid), + GNUNET_PQ_result_spec_auto_from_type ("claim_token", + &ct), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("pos_key", + pos_key), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_uint32 ("pos_algorithm", + &pos32), + NULL), + GNUNET_PQ_result_spec_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (instance_id, + pg->current_merchant_id)); + TMH_PQ_prepare_anon (pg, + "SELECT" + " contract_terms::TEXT" + ",order_serial" + ",claim_token" + ",paid" + ",pos_key" + ",pos_algorithm" + " FROM merchant_contract_terms" + " WHERE order_id=$1"); + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + (NULL != contract_terms) + ? rs + : &rs[1]); + *pos_algorithm = (enum TALER_MerchantConfirmationAlgorithm) pos32; + if (NULL != claim_token) + *claim_token = ct; + return qs; +} diff --git a/src/backenddb/lookup_contract_terms_status.c b/src/backenddb/lookup_contract_terms_status.c @@ -0,0 +1,102 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/backenddb/lookup_contract_terms_status.c + * @brief Implementation of the lookup_contract_terms_status function for Postgres + * @author Iván Ávalos + * @author Christian Grothoff + */ +#include "platform.h" +#include <sys/types.h> +#include <taler/taler_pq_lib.h> +#include "merchant-database/lookup_contract_terms_status.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_lookup_contract_terms_status ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *order_id, + const char *session_id, + json_t **contract_terms, + uint64_t *order_serial, + bool *paid, + bool *wired, + bool *session_matches, + struct TALER_ClaimTokenP *claim_token, + int16_t *choice_index) +{ + enum GNUNET_DB_QueryStatus qs; + struct TALER_ClaimTokenP ct; + uint16_t ci = 0; + bool choice_index_null = false; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (order_id), + NULL == session_id + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (session_id), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + /* contract_terms must be first! */ + TALER_PQ_result_spec_json ("contract_terms", + contract_terms), + GNUNET_PQ_result_spec_uint64 ("order_serial", + order_serial), + GNUNET_PQ_result_spec_bool ("paid", + paid), + GNUNET_PQ_result_spec_bool ("wired", + wired), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_bool ("session_matches", + session_matches), + NULL), + GNUNET_PQ_result_spec_auto_from_type ("claim_token", + &ct), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_uint16 ("choice_index", + &ci), + &choice_index_null), + GNUNET_PQ_result_spec_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (instance_id, + pg->current_merchant_id)); + *session_matches = false; + TMH_PQ_prepare_anon (pg, + "SELECT" + " contract_terms::TEXT" + ",order_serial" + ",claim_token" + ",paid" + ",wired" + ",(session_id=$2) AS session_matches" + ",choice_index" + " FROM merchant_contract_terms" + " WHERE order_id=$1"); + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + (NULL != contract_terms) + ? rs + : &rs[1]); + if (NULL != claim_token) + *claim_token = ct; + *choice_index = (choice_index_null) ? -1 : (int16_t) ci; + return qs; +} diff --git a/src/backenddb/lookup_instances.c b/src/backenddb/lookup_instances.c @@ -227,7 +227,7 @@ TALER_MERCHANTDB_lookup_instances ( enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_instance ( +TALER_MERCHANTDB_lookup_instances_by_id ( struct TALER_MERCHANTDB_PostgresContext *pg, const char *id, bool active_only, @@ -247,7 +247,7 @@ TALER_MERCHANTDB_lookup_instance ( enum GNUNET_DB_QueryStatus qs; PREPARE (pg, - "lookup_instance", + "lookup_instances_by_id", "SELECT" " merchant_serial" " ,merchant_pub" @@ -273,7 +273,7 @@ TALER_MERCHANTDB_lookup_instance ( " WHERE (merchant_id = $2)" " AND (NOT $1 OR merchant_priv IS NOT NULL)"); qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "lookup_instance", + "lookup_instances_by_id", params, &lookup_instances_cb, &lic); diff --git a/src/backenddb/lookup_pending_webhooks.c b/src/backenddb/lookup_pending_webhooks.c @@ -159,7 +159,7 @@ TALER_MERCHANTDB_lookup_pending_webhooks ( enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_future_webhook ( +TALER_MERCHANTDB_lookup_pending_webhooks_next ( struct TALER_MERCHANTDB_PostgresContext *pg, TALER_MERCHANTDB_PendingWebhooksCallback cb, void *cb_cls) @@ -175,7 +175,7 @@ TALER_MERCHANTDB_lookup_future_webhook ( enum GNUNET_DB_QueryStatus qs; PREPARE (pg, - "lookup_future_webhook", + "lookup_pending_webhooks_next", "SELECT" " webhook_pending_serial" " ,next_attempt" @@ -188,7 +188,7 @@ TALER_MERCHANTDB_lookup_future_webhook ( " ORDER BY next_attempt ASC" " LIMIT 1"); qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "lookup_future_webhook", + "lookup_pending_webhooks_next", params_null, &lookup_pending_webhooks_cb, &pwlc); diff --git a/src/backenddb/lookup_product_image.c b/src/backenddb/lookup_product_image.c @@ -1,58 +0,0 @@ -/* - 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 src/backenddb/lookup_product_image.c - * @brief Implementation of the lookup_product_image_by_hash function for Postgres - * @author Bohdan Potuzhnyi - */ -#include "merchantdb_lib.h" -#include "merchant-database/lookup_product_image.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_product_image_by_hash ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *image_hash, - char **image) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (image_hash), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("image", - image), - GNUNET_PQ_result_spec_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance_id, - pg->current_merchant_id)); - TMH_PQ_prepare_anon ( - pg, - "SELECT" - " mi.image" - " FROM merchant_inventory mi" - " WHERE mi.image_hash=$1"); - *image = NULL; - return GNUNET_PQ_eval_prepared_singleton_select ( - pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/lookup_product_image_by_hash.c b/src/backenddb/lookup_product_image_by_hash.c @@ -0,0 +1,58 @@ +/* + 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 src/backenddb/lookup_product_image_by_hash.c + * @brief Implementation of the lookup_product_image_by_hash function for Postgres + * @author Bohdan Potuzhnyi + */ +#include "merchantdb_lib.h" +#include "merchant-database/lookup_product_image_by_hash.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_lookup_product_image_by_hash ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *image_hash, + char **image) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (image_hash), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("image", + image), + GNUNET_PQ_result_spec_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (instance_id, + pg->current_merchant_id)); + TMH_PQ_prepare_anon ( + pg, + "SELECT" + " mi.image" + " FROM merchant_inventory mi" + " WHERE mi.image_hash=$1"); + *image = NULL; + return GNUNET_PQ_eval_prepared_singleton_select ( + pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/lookup_statistics_amount_by_bucket2.c b/src/backenddb/lookup_statistics_amount_by_bucket2.c @@ -1,163 +0,0 @@ -/* - 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 src/backenddb/lookup_statistics_amount_by_bucket2.c - * @brief Implementation of the lookup_statistics_amount_by_bucket2 function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_statistics_amount_by_bucket2.h" -#include "helper.h" - - -/** - * Context used for TALER_MERCHANTDB_lookup_statistics_amount_by_bucket2(). - */ -struct LookupAmountStatisticsContext2 -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_AmountByBucketStatisticsCallback2 cb; - - /** - * Closure for @a cb. - */ - void *cb_cls; - - /** - * Did database result extraction fail? - */ - bool extract_failed; - - /** - * Postgres context for array lookups - */ - struct TALER_MERCHANTDB_PostgresContext *pg; -}; - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results about token families. - * - * @param[in,out] cls of type `struct LookupAmountStatisticsContext2 *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_statistics_amount_by_bucket_cb2 (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupAmountStatisticsContext2 *tflc = cls; - struct TALER_MERCHANTDB_PostgresContext *pg = tflc->pg; - - for (unsigned int i = 0; i < num_results; i++) - { - struct TALER_Amount *amounts; - size_t num_amounts; - uint64_t bucket_start_epoch; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("bucket_start", - &bucket_start_epoch), - TALER_PQ_result_spec_array_amount_with_currency (pg->conn, - "merchant", - "cumulative_amounts", - &num_amounts, - &amounts), - GNUNET_PQ_result_spec_end - }; - struct GNUNET_TIME_Timestamp bucket_start; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - tflc->extract_failed = true; - return; - } - - bucket_start = GNUNET_TIME_timestamp_from_s (bucket_start_epoch); - tflc->cb (tflc->cb_cls, - bucket_start, - num_amounts, - amounts); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_statistics_amount_by_bucket2 ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *slug, - const char *granularity, - uint64_t counter, - TALER_MERCHANTDB_AmountByBucketStatisticsCallback2 cb, - void *cb_cls) -{ - struct LookupAmountStatisticsContext2 context = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the lookup_statistics_amount_by_bucket_cb2 */ - .extract_failed = false, - .pg = pg, - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (slug), - GNUNET_PQ_query_param_string (granularity), - GNUNET_PQ_query_param_uint64 (&counter), - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance_id, - pg->current_merchant_id)); - TMH_PQ_prepare_anon (pg, - "SELECT" - " msba.bucket_start" - ",ARRAY_AGG (" - " ROW(msba.cumulative_value::INT8, msba.cumulative_frac::INT4, msba.curr)::merchant.taler_amount_currency" - " ) AS cumulative_amounts" - " FROM merchant_statistic_bucket_meta msbm" - " JOIN merchant_statistic_bucket_amount msba" - " USING (bmeta_serial_id)" - " WHERE msbm.slug=$1" - " AND msba.bucket_range=$2::TEXT::merchant.statistic_range" - " AND msbm.stype='amount'" - " GROUP BY msba.bucket_start" - " ORDER BY msba.bucket_start DESC" - " LIMIT $3;"); - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_statistics_amount_by_bucket_cb2, - &context); - /* If there was an error inside the cb, return a hard error. */ - if (context.extract_failed) - { - GNUNET_break (0); - return GNUNET_DB_STATUS_HARD_ERROR; - } - return qs; -} diff --git a/src/backenddb/lookup_statistics_amount_by_bucket_range.c b/src/backenddb/lookup_statistics_amount_by_bucket_range.c @@ -0,0 +1,163 @@ +/* + 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 src/backenddb/lookup_statistics_amount_by_bucket_range.c + * @brief Implementation of the lookup_statistics_amount_by_bucket_range function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/lookup_statistics_amount_by_bucket_range.h" +#include "helper.h" + + +/** + * Context used for TALER_MERCHANTDB_lookup_statistics_amount_by_bucket_range(). + */ +struct LookupAmountStatisticsContext2 +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_AmountByBucketRangeStatisticsCallback cb; + + /** + * Closure for @a cb. + */ + void *cb_cls; + + /** + * Did database result extraction fail? + */ + bool extract_failed; + + /** + * Postgres context for array lookups + */ + struct TALER_MERCHANTDB_PostgresContext *pg; +}; + + +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results about token families. + * + * @param[in,out] cls of type `struct LookupAmountStatisticsContext2 *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_statistics_amount_by_bucket_cb2 (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupAmountStatisticsContext2 *tflc = cls; + struct TALER_MERCHANTDB_PostgresContext *pg = tflc->pg; + + for (unsigned int i = 0; i < num_results; i++) + { + struct TALER_Amount *amounts; + size_t num_amounts; + uint64_t bucket_start_epoch; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("bucket_start", + &bucket_start_epoch), + TALER_PQ_result_spec_array_amount_with_currency (pg->conn, + "merchant", + "cumulative_amounts", + &num_amounts, + &amounts), + GNUNET_PQ_result_spec_end + }; + struct GNUNET_TIME_Timestamp bucket_start; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + tflc->extract_failed = true; + return; + } + + bucket_start = GNUNET_TIME_timestamp_from_s (bucket_start_epoch); + tflc->cb (tflc->cb_cls, + bucket_start, + num_amounts, + amounts); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_lookup_statistics_amount_by_bucket_range ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *slug, + const char *granularity, + uint64_t counter, + TALER_MERCHANTDB_AmountByBucketRangeStatisticsCallback cb, + void *cb_cls) +{ + struct LookupAmountStatisticsContext2 context = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the lookup_statistics_amount_by_bucket_cb2 */ + .extract_failed = false, + .pg = pg, + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (slug), + GNUNET_PQ_query_param_string (granularity), + GNUNET_PQ_query_param_uint64 (&counter), + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (instance_id, + pg->current_merchant_id)); + TMH_PQ_prepare_anon (pg, + "SELECT" + " msba.bucket_start" + ",ARRAY_AGG (" + " ROW(msba.cumulative_value::INT8, msba.cumulative_frac::INT4, msba.curr)::merchant.taler_amount_currency" + " ) AS cumulative_amounts" + " FROM merchant_statistic_bucket_meta msbm" + " JOIN merchant_statistic_bucket_amount msba" + " USING (bmeta_serial_id)" + " WHERE msbm.slug=$1" + " AND msba.bucket_range=$2::TEXT::merchant.statistic_range" + " AND msbm.stype='amount'" + " GROUP BY msba.bucket_start" + " ORDER BY msba.bucket_start DESC" + " LIMIT $3;"); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &lookup_statistics_amount_by_bucket_cb2, + &context); + /* If there was an error inside the cb, return a hard error. */ + if (context.extract_failed) + { + GNUNET_break (0); + return GNUNET_DB_STATUS_HARD_ERROR; + } + return qs; +} diff --git a/src/backenddb/lookup_statistics_counter_by_bucket2.c b/src/backenddb/lookup_statistics_counter_by_bucket2.c @@ -1,185 +0,0 @@ -/* - 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 src/backenddb/lookup_statistics_counter_by_bucket2.c - * @brief Implementation of the lookup_statistics_counter_by_bucket2 function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_statistics_counter_by_bucket2.h" -#include "helper.h" - -/** - * Context used for TALER_MERCHANTDB_lookup_statistics_counter_by_bucket2(). - */ -struct LookupCounterStatisticsContext2 -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_CounterByBucketStatisticsCallback2 cb; - - /** - * Closure for @a cb. - */ - void *cb_cls; - - /** - * Did database result extraction fail? - */ - bool extract_failed; - - /** - * Postgres context for array lookups - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - -}; - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results about token families. - * - * @param[in,out] cls of type `struct LookupCounterStatisticsContext2 *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_statistics_counter_by_bucket_cb2 (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupCounterStatisticsContext2 *tflc = cls; - struct TALER_MERCHANTDB_PostgresContext *pg = tflc->pg; - - for (unsigned int i = 0; i < num_results; i++) - { - size_t num_slugs; - char *slugs; - size_t num_counters; - uint64_t *counters; - uint64_t bucket_start_epoch; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("bucket_start", - &bucket_start_epoch), - GNUNET_PQ_result_spec_array_uint64 (pg->conn, - "counters", - &num_counters, - &counters), - GNUNET_PQ_result_spec_array_string (pg->conn, - "slugs", - &num_slugs, - &slugs), - GNUNET_PQ_result_spec_end - }; - struct GNUNET_TIME_Timestamp bucket_start; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - tflc->extract_failed = true; - return; - } - if (num_slugs != num_counters) - { - GNUNET_break (0); - tflc->extract_failed = true; - GNUNET_PQ_cleanup_result (rs); - return; - } - { - const char *slugptrs[num_slugs]; - const char *pos = slugs; - - for (size_t j = 0; j<num_slugs; j++) - { - slugptrs[j] = pos; - pos += strlen (pos) + 1; - } - - bucket_start = GNUNET_TIME_timestamp_from_s (bucket_start_epoch); - tflc->cb (tflc->cb_cls, - bucket_start, - num_slugs, - slugptrs, - counters); - } - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_statistics_counter_by_bucket2 ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *prefix, - const char *granularity, - uint64_t counter, - TALER_MERCHANTDB_CounterByBucketStatisticsCallback2 cb, - void *cb_cls) -{ - struct LookupCounterStatisticsContext2 context = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the lookup_statistics_counter_by_bucket_cb2 */ - .extract_failed = false, - .pg = pg - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (prefix), - GNUNET_PQ_query_param_string (granularity), - GNUNET_PQ_query_param_uint64 (&counter), - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance_id, - pg->current_merchant_id)); - TMH_PQ_prepare_anon (pg, - "SELECT" - " msbc.bucket_start" - ",ARRAY_AGG(msbm.slug) AS slugs" - ",ARRAY_AGG(msbc.cumulative_number) AS counters" - " FROM merchant_statistic_bucket_counter msbc" - " JOIN merchant_statistic_bucket_meta msbm" - " USING (bmeta_serial_id)" - " WHERE msbm.slug LIKE $1" - " AND msbc.bucket_range=$2::TEXT::merchant.statistic_range" - " AND msbm.stype = 'number'" - " GROUP BY msbc.bucket_start" - " ORDER BY msbc.bucket_start DESC" - " LIMIT $3"); - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_statistics_counter_by_bucket_cb2, - &context); - /* If there was an error inside the cb, return a hard error. */ - if (context.extract_failed) - { - GNUNET_break (0); - return GNUNET_DB_STATUS_HARD_ERROR; - } - return qs; -} diff --git a/src/backenddb/lookup_statistics_counter_by_bucket_range.c b/src/backenddb/lookup_statistics_counter_by_bucket_range.c @@ -0,0 +1,185 @@ +/* + 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 src/backenddb/lookup_statistics_counter_by_bucket_range.c + * @brief Implementation of the lookup_statistics_counter_by_bucket_range function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/lookup_statistics_counter_by_bucket_range.h" +#include "helper.h" + +/** + * Context used for TALER_MERCHANTDB_lookup_statistics_counter_by_bucket_range(). + */ +struct LookupCounterStatisticsContext2 +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_CounterByBucketRangeStatisticsCallback cb; + + /** + * Closure for @a cb. + */ + void *cb_cls; + + /** + * Did database result extraction fail? + */ + bool extract_failed; + + /** + * Postgres context for array lookups + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + +}; + + +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results about token families. + * + * @param[in,out] cls of type `struct LookupCounterStatisticsContext2 *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_statistics_counter_by_bucket_cb2 (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupCounterStatisticsContext2 *tflc = cls; + struct TALER_MERCHANTDB_PostgresContext *pg = tflc->pg; + + for (unsigned int i = 0; i < num_results; i++) + { + size_t num_slugs; + char *slugs; + size_t num_counters; + uint64_t *counters; + uint64_t bucket_start_epoch; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("bucket_start", + &bucket_start_epoch), + GNUNET_PQ_result_spec_array_uint64 (pg->conn, + "counters", + &num_counters, + &counters), + GNUNET_PQ_result_spec_array_string (pg->conn, + "slugs", + &num_slugs, + &slugs), + GNUNET_PQ_result_spec_end + }; + struct GNUNET_TIME_Timestamp bucket_start; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + tflc->extract_failed = true; + return; + } + if (num_slugs != num_counters) + { + GNUNET_break (0); + tflc->extract_failed = true; + GNUNET_PQ_cleanup_result (rs); + return; + } + { + const char *slugptrs[num_slugs]; + const char *pos = slugs; + + for (size_t j = 0; j<num_slugs; j++) + { + slugptrs[j] = pos; + pos += strlen (pos) + 1; + } + + bucket_start = GNUNET_TIME_timestamp_from_s (bucket_start_epoch); + tflc->cb (tflc->cb_cls, + bucket_start, + num_slugs, + slugptrs, + counters); + } + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_lookup_statistics_counter_by_bucket_range ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *prefix, + const char *granularity, + uint64_t counter, + TALER_MERCHANTDB_CounterByBucketRangeStatisticsCallback cb, + void *cb_cls) +{ + struct LookupCounterStatisticsContext2 context = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the lookup_statistics_counter_by_bucket_cb2 */ + .extract_failed = false, + .pg = pg + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (prefix), + GNUNET_PQ_query_param_string (granularity), + GNUNET_PQ_query_param_uint64 (&counter), + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (instance_id, + pg->current_merchant_id)); + TMH_PQ_prepare_anon (pg, + "SELECT" + " msbc.bucket_start" + ",ARRAY_AGG(msbm.slug) AS slugs" + ",ARRAY_AGG(msbc.cumulative_number) AS counters" + " FROM merchant_statistic_bucket_counter msbc" + " JOIN merchant_statistic_bucket_meta msbm" + " USING (bmeta_serial_id)" + " WHERE msbm.slug LIKE $1" + " AND msbc.bucket_range=$2::TEXT::merchant.statistic_range" + " AND msbm.stype = 'number'" + " GROUP BY msbc.bucket_start" + " ORDER BY msbc.bucket_start DESC" + " LIMIT $3"); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &lookup_statistics_counter_by_bucket_cb2, + &context); + /* If there was an error inside the cb, return a hard error. */ + if (context.extract_failed) + { + GNUNET_break (0); + return GNUNET_DB_STATUS_HARD_ERROR; + } + return qs; +} diff --git a/src/backenddb/meson.build b/src/backenddb/meson.build @@ -26,6 +26,7 @@ libtalermerchantdb = library( 'delete_exchange_accounts.c', 'delete_instance_private_key.c', 'delete_login_token.c', + 'delete_login_token_by_serial.c', 'delete_order.c', 'delete_otp.c', 'delete_pending_webhook.c', @@ -105,8 +106,8 @@ libtalermerchantdb = library( 'lookup_categories.c', 'lookup_categories_by_ids.c', 'lookup_contract_terms.c', - 'lookup_contract_terms2.c', - 'lookup_contract_terms3.c', + 'lookup_contract_terms_pos.c', + 'lookup_contract_terms_status.c', 'lookup_deposits.c', 'lookup_deposits_by_contract_and_coin.c', 'lookup_deposits_by_order.c', @@ -126,14 +127,14 @@ libtalermerchantdb = library( 'lookup_pending_deposits.c', 'lookup_pending_webhooks.c', 'lookup_product.c', - 'lookup_product_image.c', + 'lookup_product_image_by_hash.c', 'lookup_products.c', 'lookup_refund_proof.c', 'lookup_refunds.c', 'lookup_refunds_detailed.c', 'lookup_spent_tokens_by_order.c', - 'lookup_statistics_amount_by_bucket2.c', - 'lookup_statistics_counter_by_bucket2.c', + 'lookup_statistics_amount_by_bucket_range.c', + 'lookup_statistics_counter_by_bucket_range.c', 'lookup_template.c', 'lookup_templates.c', 'lookup_token_families.c', diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c @@ -58,7 +58,7 @@ #include "merchant-database/lock_product.h" #include "merchant-database/lookup_account.h" #include "merchant-database/lookup_contract_terms.h" -#include "merchant-database/lookup_contract_terms3.h" +#include "merchant-database/lookup_contract_terms_status.h" #include "merchant-database/lookup_deposits.h" #include "merchant-database/lookup_deposits_by_contract_and_coin.h" #include "merchant-database/lookup_deposits_by_order.h" @@ -2260,17 +2260,17 @@ test_lookup_payment_status (const char *instance_id, TEST_SET_INSTANCE (instance_id, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT); TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == - TALER_MERCHANTDB_lookup_contract_terms3 (pg, - instance_id, - order_id, - session_id, - NULL, - &os, - &paid, - &wired, - &matches, - NULL, - &choice_index), + TALER_MERCHANTDB_lookup_contract_terms_status (pg, + instance_id, + order_id, + session_id, + NULL, + &os, + &paid, + &wired, + &matches, + NULL, + &choice_index), "Lookup payment status failed\n"); if ( (NULL != session_id) && (! matches) ) { @@ -7062,7 +7062,7 @@ struct LookupPendingWebhookSerial_Closure /** * Function called after calling @e test_lookup_all_webhook, - * test_lookup_future_webhook and test_lookup_pending_webhook + * test_lookup_pending_webhooks_next and test_lookup_pending_webhook * * @param cls a pointer to the lookup closure. * @param webhook_serial reference to the configured webhook template. @@ -7163,7 +7163,7 @@ struct TestLookupPendingWebhooks_Closure /** * Function called after calling @e test_lookup_all_webhook, - * test_lookup_future_webhook and test_lookup_pending_webhook + * test_lookup_pending_webhooks_next and test_lookup_pending_webhook * * @param cls a pointer to the lookup closure. * @param webhook_serial reference to the configured webhook template. @@ -7257,9 +7257,9 @@ test_lookup_pending_webhooks (const struct InstanceData *instance, * @return 0 when successful, 1 otherwise. */ static int -test_lookup_future_webhook (const struct InstanceData *instance, - unsigned int pwebhooks_length, - const struct PendingWebhookData *pwebhooks) +test_lookup_pending_webhooks_next (const struct InstanceData *instance, + unsigned int pwebhooks_length, + const struct PendingWebhookData *pwebhooks) { unsigned int results_matching[pwebhooks_length]; struct TestLookupPendingWebhooks_Closure cls = { @@ -7270,9 +7270,9 @@ test_lookup_future_webhook (const struct InstanceData *instance, }; memset (results_matching, 0, sizeof (results_matching)); - if (0 > TALER_MERCHANTDB_lookup_future_webhook (pg, - &lookup_pending_webhooks_cb, - &cls)) + if (0 > TALER_MERCHANTDB_lookup_pending_webhooks_next (pg, + &lookup_pending_webhooks_cb, + &cls)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup future webhook failed\n"); @@ -7486,9 +7486,9 @@ run_test_pending_webhooks (struct TestPendingWebhooks_Closure *cls) TEST_RET_ON_FAIL (test_update_pending_webhook (&cls->instance, &cls->pwebhooks[0], GNUNET_DB_STATUS_SUCCESS_ONE_RESULT)); - TEST_RET_ON_FAIL (test_lookup_future_webhook (&cls->instance, - 1, - &cls->pwebhooks[1])); + TEST_RET_ON_FAIL (test_lookup_pending_webhooks_next (&cls->instance, + 1, + &cls->pwebhooks[1])); TEST_RET_ON_FAIL (test_update_pending_webhook (&cls->instance, &cls->pwebhooks[1], GNUNET_DB_STATUS_SUCCESS_NO_RESULTS)); diff --git a/src/include/merchant-database/all.h b/src/include/merchant-database/all.h @@ -1,8 +1,9 @@ -/* Umbrella header including all merchant-database declarations */ +/* Umbrella header including all merchant-database declarations. + Generated list; contrib/check-db-naming.py verifies it stays complete. */ #ifndef MERCHANT_DATABASE_ALL_H #define MERCHANT_DATABASE_ALL_H -#include "merchant-database/helper.h" +#include "merchantdb_lib.h" #include "merchant-database/account_kyc_get_outdated.h" #include "merchant-database/account_kyc_get_status.h" #include "merchant-database/account_kyc_set_failed.h" @@ -13,12 +14,14 @@ #include "merchant-database/check_report.h" #include "merchant-database/check_transfer_exists.h" #include "merchant-database/create_mfa_challenge.h" +#include "merchant-database/create_tables.h" #include "merchant-database/delete_category.h" #include "merchant-database/delete_contract_terms.h" #include "merchant-database/delete_donau_instance.h" #include "merchant-database/delete_exchange_accounts.h" #include "merchant-database/delete_instance_private_key.h" #include "merchant-database/delete_login_token.h" +#include "merchant-database/delete_login_token_by_serial.h" #include "merchant-database/delete_money_pot.h" #include "merchant-database/delete_order.h" #include "merchant-database/delete_otp.h" @@ -32,6 +35,9 @@ #include "merchant-database/delete_transfer.h" #include "merchant-database/delete_unit.h" #include "merchant-database/delete_webhook.h" +#include "merchant-database/drop_tables.h" +#include "merchant-database/event_listen.h" +#include "merchant-database/event_notify.h" #include "merchant-database/expire_locks.h" #include "merchant-database/finalize_transfer_status.h" #include "merchant-database/gc.h" @@ -76,11 +82,12 @@ #include "merchant-database/lock_product.h" #include "merchant-database/lookup_account.h" #include "merchant-database/lookup_all_products.h" +#include "merchant-database/lookup_all_webhooks.h" #include "merchant-database/lookup_categories.h" #include "merchant-database/lookup_categories_by_ids.h" #include "merchant-database/lookup_contract_terms.h" -#include "merchant-database/lookup_contract_terms2.h" -#include "merchant-database/lookup_contract_terms3.h" +#include "merchant-database/lookup_contract_terms_pos.h" +#include "merchant-database/lookup_contract_terms_status.h" #include "merchant-database/lookup_custom_units_by_names.h" #include "merchant-database/lookup_deposits.h" #include "merchant-database/lookup_deposits_by_contract_and_coin.h" @@ -105,7 +112,7 @@ #include "merchant-database/lookup_pending_deposits.h" #include "merchant-database/lookup_pending_webhooks.h" #include "merchant-database/lookup_product.h" -#include "merchant-database/lookup_product_image.h" +#include "merchant-database/lookup_product_image_by_hash.h" #include "merchant-database/lookup_products.h" #include "merchant-database/lookup_reconciliation_details.h" #include "merchant-database/lookup_refund_proof.h" @@ -114,10 +121,10 @@ #include "merchant-database/lookup_reports_pending.h" #include "merchant-database/lookup_spent_tokens_by_order.h" #include "merchant-database/lookup_statistics_amount_by_bucket.h" -#include "merchant-database/lookup_statistics_amount_by_bucket2.h" +#include "merchant-database/lookup_statistics_amount_by_bucket_range.h" #include "merchant-database/lookup_statistics_amount_by_interval.h" #include "merchant-database/lookup_statistics_counter_by_bucket.h" -#include "merchant-database/lookup_statistics_counter_by_bucket2.h" +#include "merchant-database/lookup_statistics_counter_by_bucket_range.h" #include "merchant-database/lookup_statistics_counter_by_interval.h" #include "merchant-database/lookup_template.h" #include "merchant-database/lookup_templates.h" @@ -137,12 +144,14 @@ #include "merchant-database/lookup_wire_fee.h" #include "merchant-database/mark_contract_paid.h" #include "merchant-database/mark_order_wired.h" +#include "merchant-database/preflight.h" #include "merchant-database/purge_instance.h" #include "merchant-database/refund_coin.h" #include "merchant-database/select_account.h" #include "merchant-database/select_account_by_uri.h" #include "merchant-database/select_accounts.h" #include "merchant-database/select_accounts_by_exchange.h" +#include "merchant-database/select_accounts_by_instance.h" #include "merchant-database/select_all_donau_instances.h" #include "merchant-database/select_category.h" #include "merchant-database/select_category_by_name.h" @@ -163,7 +172,9 @@ #include "merchant-database/select_reports.h" #include "merchant-database/select_unit.h" #include "merchant-database/select_wirewatch_accounts.h" +#include "merchant-database/set_instance.h" #include "merchant-database/solve_mfa_challenge.h" +#include "merchant-database/start.h" #include "merchant-database/store_wire_fee_by_exchange.h" #include "merchant-database/unlock_inventory.h" #include "merchant-database/update_account.h" diff --git a/src/include/merchant-database/delete_login_token.h b/src/include/merchant-database/delete_login_token.h @@ -28,21 +28,6 @@ struct TALER_MERCHANTDB_PostgresContext; /** - * Delete login token from database by serial. - * - * @param pg database context - * @param id identifier of the instance - * @param serial serial of the token - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_delete_login_token_serial ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *id, - uint64_t serial); - - -/** * Delete login token from database. * * @param pg database context diff --git a/src/include/merchant-database/delete_login_token_by_serial.h b/src/include/merchant-database/delete_login_token_by_serial.h @@ -0,0 +1,46 @@ +/* + This file is part of TALER + Copyright (C) 2023 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 src/include/merchant-database/delete_login_token_by_serial.h + * @brief implementation of the delete_login_token_by_serial function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_DELETE_LOGIN_TOKEN_BY_SERIAL_H +#define MERCHANT_DATABASE_DELETE_LOGIN_TOKEN_BY_SERIAL_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; + +/** + * Delete login token from database by serial. + * + * @param pg database context + * @param id identifier of the instance + * @param serial serial of the token + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_delete_login_token_by_serial ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *id, + uint64_t serial); + + +#endif diff --git a/src/include/merchant-database/lookup_contract_terms2.h b/src/include/merchant-database/lookup_contract_terms2.h @@ -1,55 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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 src/include/merchant-database/lookup_contract_terms2.h - * @brief implementation of the lookup_contract_terms2 function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_CONTRACT_TERMS2_H -#define MERCHANT_DATABASE_LOOKUP_CONTRACT_TERMS2_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Retrieve contract terms given its @a order_id - * - * @param pg database context - * @param instance_id instance's identifier - * @param order_id order_id used to lookup. - * @param[out] contract_terms where to store the result, NULL to only check for existence - * @param[out] order_serial set to the order's serial number - * @param[out] paid set to true if the order is fully paid - * @param[out] claim_token set to the claim token, NULL to only check for existence - * @param[out] pos_key encoded key for payment verification - * @param[out] pos_algorithm algorithm to compute the payment verification - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_contract_terms2 (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *order_id, - json_t **contract_terms, - uint64_t *order_serial, - bool *paid, - struct TALER_ClaimTokenP *claim_token, - char **pos_key, - enum TALER_MerchantConfirmationAlgorithm *pos_algorithm); - -#endif diff --git a/src/include/merchant-database/lookup_contract_terms3.h b/src/include/merchant-database/lookup_contract_terms3.h @@ -1,59 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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 src/include/merchant-database/lookup_contract_terms3.h - * @brief implementation of the lookup_contract_terms3 function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_CONTRACT_TERMS3_H -#define MERCHANT_DATABASE_LOOKUP_CONTRACT_TERMS3_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Retrieve contract terms given its @a order_id - * - * @param pg database context - * @param instance_id instance's identifier - * @param order_id order_id used to lookup. - * @param session_id session_id to compare, can be NULL - * @param[out] contract_terms where to store the result, NULL to only check for existence - * @param[out] order_serial set to the order's serial number - * @param[out] paid set to true if the order is fully paid - * @param[out] wired set to true if the exchange wired the funds - * @param[out] session_matches set to true if @a session_id matches session stored for this contract - * @param[out] claim_token set to token to use for access control - * @param[out] choice_index set to the choice index, -1 if not set - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_contract_terms3 (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *order_id, - const char *session_id, - json_t **contract_terms, - uint64_t *order_serial, - bool *paid, - bool *wired, - bool *session_matches, - struct TALER_ClaimTokenP *claim_token, - int16_t *choice_index); - -#endif diff --git a/src/include/merchant-database/lookup_contract_terms_pos.h b/src/include/merchant-database/lookup_contract_terms_pos.h @@ -0,0 +1,56 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/include/merchant-database/lookup_contract_terms_pos.h + * @brief implementation of the lookup_contract_terms_pos function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_LOOKUP_CONTRACT_TERMS_POS_H +#define MERCHANT_DATABASE_LOOKUP_CONTRACT_TERMS_POS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Retrieve contract terms given its @a order_id + * + * @param pg database context + * @param instance_id instance's identifier + * @param order_id order_id used to lookup. + * @param[out] contract_terms where to store the result, NULL to only check for existence + * @param[out] order_serial set to the order's serial number + * @param[out] paid set to true if the order is fully paid + * @param[out] claim_token set to the claim token, NULL to only check for existence + * @param[out] pos_key encoded key for payment verification + * @param[out] pos_algorithm algorithm to compute the payment verification + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_lookup_contract_terms_pos ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *order_id, + json_t **contract_terms, + uint64_t *order_serial, + bool *paid, + struct TALER_ClaimTokenP *claim_token, + char **pos_key, + enum TALER_MerchantConfirmationAlgorithm *pos_algorithm); + +#endif diff --git a/src/include/merchant-database/lookup_contract_terms_status.h b/src/include/merchant-database/lookup_contract_terms_status.h @@ -0,0 +1,60 @@ +/* + This file is part of TALER + Copyright (C) 2022 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 src/include/merchant-database/lookup_contract_terms_status.h + * @brief implementation of the lookup_contract_terms_status function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_LOOKUP_CONTRACT_TERMS_STATUS_H +#define MERCHANT_DATABASE_LOOKUP_CONTRACT_TERMS_STATUS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Retrieve contract terms given its @a order_id + * + * @param pg database context + * @param instance_id instance's identifier + * @param order_id order_id used to lookup. + * @param session_id session_id to compare, can be NULL + * @param[out] contract_terms where to store the result, NULL to only check for existence + * @param[out] order_serial set to the order's serial number + * @param[out] paid set to true if the order is fully paid + * @param[out] wired set to true if the exchange wired the funds + * @param[out] session_matches set to true if @a session_id matches session stored for this contract + * @param[out] claim_token set to token to use for access control + * @param[out] choice_index set to the choice index, -1 if not set + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_lookup_contract_terms_status ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *order_id, + const char *session_id, + json_t **contract_terms, + uint64_t *order_serial, + bool *paid, + bool *wired, + bool *session_matches, + struct TALER_ClaimTokenP *claim_token, + int16_t *choice_index); + +#endif diff --git a/src/include/merchant-database/lookup_instances.h b/src/include/merchant-database/lookup_instances.h @@ -68,7 +68,7 @@ TALER_MERCHANTDB_lookup_instances ( * @param cb_cls closure for @a cb */ enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_instance ( +TALER_MERCHANTDB_lookup_instances_by_id ( struct TALER_MERCHANTDB_PostgresContext *pg, const char *id, bool active_only, diff --git a/src/include/merchant-database/lookup_pending_webhooks.h b/src/include/merchant-database/lookup_pending_webhooks.h @@ -70,8 +70,8 @@ TALER_MERCHANTDB_lookup_pending_webhooks (struct TALER_MERCHANTDB_PostgresContex /** - * Lookup future webhook in the pending webhook that need to be send. - * With that we can know how long the system can 'sleep'. + * Lookup the next webhook in the pending webhooks that needs to be + * sent. With that we can know how long the system can 'sleep'. * * @param pg database context * @param cb pending webhook callback @@ -79,29 +79,10 @@ TALER_MERCHANTDB_lookup_pending_webhooks (struct TALER_MERCHANTDB_PostgresContex */ // ORDER BY next_attempt ASC LIMIT 1 enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_future_webhook (struct TALER_MERCHANTDB_PostgresContext *pg, - TALER_MERCHANTDB_PendingWebhooksCallback cb, - void *cb_cls); +TALER_MERCHANTDB_lookup_pending_webhooks_next ( + struct TALER_MERCHANTDB_PostgresContext *pg, + TALER_MERCHANTDB_PendingWebhooksCallback cb, + void *cb_cls); -/** - * Lookup all the webhooks in the pending webhook. - * Use by the administrator - * - * @param pg database context - * @param instance_id to lookup webhooks for this instance particularly - * @param min_row to see the list of the pending webhook that it is started with this minimum row. - * @param max_results to see the list of the pending webhook that it is end with this max results. - * @param cb pending webhook callback - * @param cb_cls callback closure - */ -// WHERE webhook_pending_serial > min_row ORDER BY webhook_pending_serial ASC LIMIT max_results -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_all_webhooks (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t min_row, - uint32_t max_results, - TALER_MERCHANTDB_PendingWebhooksCallback cb, - void *cb_cls); - #endif diff --git a/src/include/merchant-database/lookup_product_image.h b/src/include/merchant-database/lookup_product_image.h @@ -1,34 +0,0 @@ -/* - 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 src/include/merchant-database/lookup_product_image.h - * @brief declaration of lookup_product_image_by_hash for Postgres - * @author Bohdan Potuzhnyi - */ -#ifndef MERCHANT_DATABASE_LOOKUP_PRODUCT_IMAGE_H -#define MERCHANT_DATABASE_LOOKUP_PRODUCT_IMAGE_H - -#include "merchantdb_lib.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_product_image_by_hash ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *image_hash, - char **image); - -#endif diff --git a/src/include/merchant-database/lookup_product_image_by_hash.h b/src/include/merchant-database/lookup_product_image_by_hash.h @@ -0,0 +1,34 @@ +/* + 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 src/include/merchant-database/lookup_product_image_by_hash.h + * @brief declaration of lookup_product_image_by_hash for Postgres + * @author Bohdan Potuzhnyi + */ +#ifndef MERCHANT_DATABASE_LOOKUP_PRODUCT_IMAGE_BY_HASH_H +#define MERCHANT_DATABASE_LOOKUP_PRODUCT_IMAGE_BY_HASH_H + +#include "merchantdb_lib.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_lookup_product_image_by_hash ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *image_hash, + char **image); + +#endif diff --git a/src/include/merchant-database/lookup_statistics_amount_by_bucket2.h b/src/include/merchant-database/lookup_statistics_amount_by_bucket2.h @@ -1,92 +0,0 @@ -/* - 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 src/include/merchant-database/lookup_statistics_amount_by_bucket2.h - * @brief implementation of the lookup_statistics_amount_by_bucket2 function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_STATISTICS_AMOUNT_BY_BUCKET2_H -#define MERCHANT_DATABASE_LOOKUP_STATISTICS_AMOUNT_BY_BUCKET2_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/* Callback typedefs */ -/** - * Returns amount-valued statistics by bucket. - * Called by `lookup_statistics_amount_by_bucket`. - * - * @param cls closure - * @param description description of the statistic - * @param bucket_start start time of the bucket - * @param bucket_end end time of the bucket - * @param bucket_range range of the bucket - * @param cumulative_amounts_len the length of @a cumulative_amounts - * @param cumulative_amounts the cumulative amounts array - */ -typedef void -(*TALER_MERCHANTDB_AmountByBucketStatisticsCallback)( - void *cls, - const char *description, - struct GNUNET_TIME_Timestamp bucket_start, - struct GNUNET_TIME_Timestamp bucket_end, - const char *bucket_range, - unsigned int cumulative_amounts_len, - const struct TALER_Amount cumulative_amounts[static cumulative_amounts_len]); - -/** - * Returns amount-valued statistics by bucket. - * Called by `lookup_statistics_amount_by_bucket2`. - * - * @param cls closure - * @param bucket_start start time of the bucket - * @param cumulative_amounts_len the length of @a cumulative_amounts - * @param cumulative_amounts the cumulative amounts array - */ -typedef void -(*TALER_MERCHANTDB_AmountByBucketStatisticsCallback2)( - void *cls, - struct GNUNET_TIME_Timestamp bucket_start, - unsigned int cumulative_amounts_len, - const struct TALER_Amount cumulative_amounts[static cumulative_amounts_len]); - -/** - * Lookup amount statistics for instance and slug by bucket, - * restricting to a fixed number of buckets at a given granularity. - * - * @param pg database context - * @param instance_id instance to lookup statistics for - * @param slug instance to lookup statistics for - * @param granularity limit to buckets of this size - * @param counter requested number of buckets - * @param cb function to call on all token families found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_statistics_amount_by_bucket2 (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *slug, - const char *granularity, - uint64_t counter, - TALER_MERCHANTDB_AmountByBucketStatisticsCallback2 - cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_statistics_amount_by_bucket_range.h b/src/include/merchant-database/lookup_statistics_amount_by_bucket_range.h @@ -0,0 +1,93 @@ +/* + 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 src/include/merchant-database/lookup_statistics_amount_by_bucket_range.h + * @brief implementation of the lookup_statistics_amount_by_bucket_range function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_LOOKUP_STATISTICS_AMOUNT_BY_BUCKET_RANGE_H +#define MERCHANT_DATABASE_LOOKUP_STATISTICS_AMOUNT_BY_BUCKET_RANGE_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/* Callback typedefs */ +/** + * Returns amount-valued statistics by bucket. + * Called by `lookup_statistics_amount_by_bucket`. + * + * @param cls closure + * @param description description of the statistic + * @param bucket_start start time of the bucket + * @param bucket_end end time of the bucket + * @param bucket_range range of the bucket + * @param cumulative_amounts_len the length of @a cumulative_amounts + * @param cumulative_amounts the cumulative amounts array + */ +typedef void +(*TALER_MERCHANTDB_AmountByBucketStatisticsCallback)( + void *cls, + const char *description, + struct GNUNET_TIME_Timestamp bucket_start, + struct GNUNET_TIME_Timestamp bucket_end, + const char *bucket_range, + unsigned int cumulative_amounts_len, + const struct TALER_Amount cumulative_amounts[static cumulative_amounts_len]); + +/** + * Returns amount-valued statistics by bucket. + * Called by `lookup_statistics_amount_by_bucket2`. + * + * @param cls closure + * @param bucket_start start time of the bucket + * @param cumulative_amounts_len the length of @a cumulative_amounts + * @param cumulative_amounts the cumulative amounts array + */ +typedef void +(*TALER_MERCHANTDB_AmountByBucketRangeStatisticsCallback)( + void *cls, + struct GNUNET_TIME_Timestamp bucket_start, + unsigned int cumulative_amounts_len, + const struct TALER_Amount cumulative_amounts[static cumulative_amounts_len]); + +/** + * Lookup amount statistics for instance and slug by bucket, + * restricting to a fixed number of buckets at a given granularity. + * + * @param pg database context + * @param instance_id instance to lookup statistics for + * @param slug instance to lookup statistics for + * @param granularity limit to buckets of this size + * @param counter requested number of buckets + * @param cb function to call on all token families found + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_lookup_statistics_amount_by_bucket_range (struct TALER_MERCHANTDB_PostgresContext * + pg, + const char *instance_id, + const char *slug, + const char *granularity, + uint64_t counter, + TALER_MERCHANTDB_AmountByBucketRangeStatisticsCallback + cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/lookup_statistics_counter_by_bucket2.h b/src/include/merchant-database/lookup_statistics_counter_by_bucket2.h @@ -1,71 +0,0 @@ -/* - 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 src/include/merchant-database/lookup_statistics_counter_by_bucket2.h - * @brief implementation of the lookup_statistics_counter_by_bucket2 function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_STATISTICS_COUNTER_BY_BUCKET2_H -#define MERCHANT_DATABASE_LOOKUP_STATISTICS_COUNTER_BY_BUCKET2_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Function returning integer-valued statistics for a bucket. - * Called by `lookup_statistics_counter_by_bucket2`. - * - * @param cls closure - * @param bucket_start start time of the bucket - * @param counters_len the length of @a cumulative_amounts - * @param descriptions description for the counter in the bucket - * @param counters the counters in the bucket - */ -typedef void -(*TALER_MERCHANTDB_CounterByBucketStatisticsCallback2)( - void *cls, - struct GNUNET_TIME_Timestamp bucket_start, - unsigned int counters_len, - const char *descriptions[static counters_len], - uint64_t counters[static counters_len]); - - -/** - * Lookup counter statistics for instance and slug-prefix by bucket. - * - * @param pg database context - * @param instance_id instance to lookup statistics for - * @param prefix slug prefix to lookup statistics under - * @param granularity limit to buckets of this size - * @param counter requested number of buckets - * @param cb function to call on all token families found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_statistics_counter_by_bucket2 ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *prefix, - const char *granularity, - uint64_t counter, - TALER_MERCHANTDB_CounterByBucketStatisticsCallback2 cb, - void *cb_cls); - - -#endif diff --git a/src/include/merchant-database/lookup_statistics_counter_by_bucket_range.h b/src/include/merchant-database/lookup_statistics_counter_by_bucket_range.h @@ -0,0 +1,71 @@ +/* + 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 src/include/merchant-database/lookup_statistics_counter_by_bucket_range.h + * @brief implementation of the lookup_statistics_counter_by_bucket_range function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_LOOKUP_STATISTICS_COUNTER_BY_BUCKET_RANGE_H +#define MERCHANT_DATABASE_LOOKUP_STATISTICS_COUNTER_BY_BUCKET_RANGE_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Function returning integer-valued statistics for a bucket. + * Called by `lookup_statistics_counter_by_bucket2`. + * + * @param cls closure + * @param bucket_start start time of the bucket + * @param counters_len the length of @a cumulative_amounts + * @param descriptions description for the counter in the bucket + * @param counters the counters in the bucket + */ +typedef void +(*TALER_MERCHANTDB_CounterByBucketRangeStatisticsCallback)( + void *cls, + struct GNUNET_TIME_Timestamp bucket_start, + unsigned int counters_len, + const char *descriptions[static counters_len], + uint64_t counters[static counters_len]); + + +/** + * Lookup counter statistics for instance and slug-prefix by bucket. + * + * @param pg database context + * @param instance_id instance to lookup statistics for + * @param prefix slug prefix to lookup statistics under + * @param granularity limit to buckets of this size + * @param counter requested number of buckets + * @param cb function to call on all token families found + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_lookup_statistics_counter_by_bucket_range ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *prefix, + const char *granularity, + uint64_t counter, + TALER_MERCHANTDB_CounterByBucketRangeStatisticsCallback cb, + void *cb_cls); + + +#endif