merchant

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

commit a5588bc383115bce1aeadf5ecb6eb3387b05a027
parent 3e17cd9c65f071514cce08726f1d191bef90b083
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed, 22 Jul 2026 03:19:18 +0200

merchantdb: match table names

Diffstat:
Msrc/backend/taler-merchant-depositcheck.c | 8++++----
Msrc/backend/taler-merchant-exchangekeyupdate.c | 8++++----
Msrc/backend/taler-merchant-httpd_delete-private-otp-devices-DEVICE_ID.c | 8++++----
Msrc/backend/taler-merchant-httpd_get-private-incoming-ID.c | 4++--
Msrc/backend/taler-merchant-httpd_get-private-otp-devices-DEVICE_ID.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_get-private-statistics-amount-SLUG.c | 8++++----
Msrc/backend/taler-merchant-httpd_get-private-statistics-counter-SLUG.c | 8++++----
Msrc/backend/taler-merchant-httpd_get-private-statistics-report-transactions.c | 8++++----
Msrc/backend/taler-merchant-httpd_helper.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_patch-private-otp-devices-DEVICE_ID.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_post-orders-ORDER_ID-paid.c | 14+++++++-------
Msrc/backend/taler-merchant-httpd_post-orders-ORDER_ID-pay.c | 36++++++++++++++++++------------------
Msrc/backend/taler-merchant-httpd_post-private-orders.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_post-private-otp-devices.c | 20++++++++++----------
Msrc/backend/taler-merchant-httpd_post-private-templates.c | 10+++++-----
Msrc/backend/taler-merchant-reconciliation.c | 64++++++++++++++++++++++++++++++++--------------------------------
Msrc/backend/taler-merchant-report-generator.c | 4++--
Msrc/backend/taler-merchant-wirewatch.c | 10+++++-----
Dsrc/backenddb/delete_otp.c | 48------------------------------------------------
Asrc/backenddb/delete_otp_device.c | 48++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_donau_instance_by_url.c | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_exchange_wire_fee.c | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/backenddb/get_order_charity.c | 83-------------------------------------------------------------------------------
Dsrc/backenddb/get_otp.c | 69---------------------------------------------------------------------
Asrc/backenddb/get_otp_device.c | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_otp_device_serial.c | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/backenddb/get_otp_serial.c | 56--------------------------------------------------------
Dsrc/backenddb/get_wire_fee.c | 79-------------------------------------------------------------------------------
Asrc/backenddb/insert_exchange_signing_key.c | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/backenddb/insert_exchange_signkey.c | 63---------------------------------------------------------------
Asrc/backenddb/insert_exchange_wire_fee.c | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/backenddb/insert_order_blinded_sigs.c | 57---------------------------------------------------------
Asrc/backenddb/insert_order_token_blinded_sig.c | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/backenddb/insert_otp.c | 68--------------------------------------------------------------------
Asrc/backenddb/insert_otp_device.c | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/backenddb/insert_spent_token.c | 85-------------------------------------------------------------------------------
Asrc/backenddb/insert_used_token.c | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/backenddb/insert_spent_token.sql -> src/backenddb/insert_used_token.sql | 0
Dsrc/backenddb/insert_wire_fee.c | 72------------------------------------------------------------------------
Dsrc/backenddb/iterate_accounts_by_exchange.c | 142-------------------------------------------------------------------------------
Dsrc/backenddb/iterate_all_webhooks.c | 165-------------------------------------------------------------------------------
Asrc/backenddb/iterate_exchange_accounts.c | 142+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_open_expected_transfers.c | 151++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/backenddb/iterate_open_transfers.sql -> src/backenddb/iterate_open_expected_transfers.sql | 0
Dsrc/backenddb/iterate_open_transfers.c | 151------------------------------------------------------------------------------
Dsrc/backenddb/iterate_order_blinded_sigs.c | 127-------------------------------------------------------------------------------
Asrc/backenddb/iterate_order_token_blinded_sigs.c | 127+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_pending_reports.c | 174+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/backenddb/iterate_reports_pending.sql -> src/backenddb/iterate_pending_reports.sql | 0
Asrc/backenddb/iterate_pending_webhooks_above_serial_id.c | 165+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/backenddb/iterate_reports_pending.c | 174-------------------------------------------------------------------------------
Dsrc/backenddb/iterate_spent_tokens_by_order.c | 158-------------------------------------------------------------------------------
Asrc/backenddb/iterate_statistic_bucket_amounts.c | 221+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_statistic_bucket_amounts_by_range.c | 163+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_statistic_bucket_counters.c | 159+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_statistic_bucket_counters_by_range.c | 185+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_statistic_interval_amounts.c | 239+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/backenddb/iterate_statistics_amount_by_interval.sql -> src/backenddb/iterate_statistic_interval_amounts.sql | 0
Asrc/backenddb/iterate_statistic_interval_counters.c | 210+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/backenddb/iterate_statistics_counter_by_interval.sql -> src/backenddb/iterate_statistic_interval_counters.sql | 0
Dsrc/backenddb/iterate_statistics_amount_by_bucket.c | 221-------------------------------------------------------------------------------
Dsrc/backenddb/iterate_statistics_amount_by_bucket_range.c | 163-------------------------------------------------------------------------------
Dsrc/backenddb/iterate_statistics_amount_by_interval.c | 239-------------------------------------------------------------------------------
Dsrc/backenddb/iterate_statistics_counter_by_bucket.c | 159-------------------------------------------------------------------------------
Dsrc/backenddb/iterate_statistics_counter_by_bucket_range.c | 185-------------------------------------------------------------------------------
Dsrc/backenddb/iterate_statistics_counter_by_interval.c | 210-------------------------------------------------------------------------------
Asrc/backenddb/iterate_transfer_summaries.c | 149+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/backenddb/iterate_transfer_summary.c | 149-------------------------------------------------------------------------------
Asrc/backenddb/iterate_used_tokens_by_order.c | 158+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/backenddb/meson.build | 58+++++++++++++++++++++++++++++-----------------------------
Msrc/backenddb/sql-schema/meson.build | 10+++++-----
Msrc/backenddb/test_merchantdb.c | 104++++++++++++++++++++++++++++++++++++++++----------------------------------------
Asrc/backenddb/update_account_last_bank_serial.c | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/backenddb/update_contract_session.c | 78------------------------------------------------------------------------------
Asrc/backenddb/update_contract_terms_session.c | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/backenddb/update_deposit_confirmation_status.c | 63---------------------------------------------------------------
Asrc/backenddb/update_deposit_settlement_status.c | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/update_expected_transfer_status.c | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/backenddb/update_otp.c | 59-----------------------------------------------------------
Asrc/backenddb/update_otp_device.c | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/update_to_expected_transfer_finalized.c | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/backenddb/update_to_transfer_finalized.c | 76----------------------------------------------------------------------------
Dsrc/backenddb/update_transfer_status.c | 67-------------------------------------------------------------------
Dsrc/backenddb/update_wirewatch_progress.c | 51---------------------------------------------------
Msrc/include/merchant-database/all.h | 58+++++++++++++++++++++++++++++-----------------------------
Dsrc/include/merchant-database/delete_otp.h | 44--------------------------------------------
Asrc/include/merchant-database/delete_otp_device.h | 44++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_donau_instance_by_url.h | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_exchange_wire_fee.h | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/merchant-database/get_order_charity.h | 63---------------------------------------------------------------
Dsrc/include/merchant-database/get_otp.h | 46----------------------------------------------
Asrc/include/merchant-database/get_otp_device.h | 46++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_otp_device_serial.h | 44++++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/merchant-database/get_otp_serial.h | 44--------------------------------------------
Dsrc/include/merchant-database/get_wire_fee.h | 54------------------------------------------------------
Asrc/include/merchant-database/insert_exchange_signing_key.h | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/merchant-database/insert_exchange_signkey.h | 52----------------------------------------------------
Asrc/include/merchant-database/insert_exchange_wire_fee.h | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/merchant-database/insert_order_blinded_sigs.h | 47-----------------------------------------------
Asrc/include/merchant-database/insert_order_token_blinded_sig.h | 48++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/merchant-database/insert_otp.h | 46----------------------------------------------
Asrc/include/merchant-database/insert_otp_device.h | 46++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/merchant-database/insert_spent_token.h | 47-----------------------------------------------
Asrc/include/merchant-database/insert_used_token.h | 47+++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/merchant-database/insert_wire_fee.h | 52----------------------------------------------------
Dsrc/include/merchant-database/iterate_accounts_by_exchange.h | 65-----------------------------------------------------------------
Dsrc/include/merchant-database/iterate_all_webhooks.h | 73-------------------------------------------------------------------------
Asrc/include/merchant-database/iterate_exchange_accounts.h | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_open_expected_transfers.h | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/merchant-database/iterate_open_transfers.h | 71-----------------------------------------------------------------------
Dsrc/include/merchant-database/iterate_order_blinded_sigs.h | 61-------------------------------------------------------------
Asrc/include/merchant-database/iterate_order_token_blinded_sigs.h | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_pending_reports.h | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_pending_webhooks_above_serial_id.h | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/merchant-database/iterate_reports_pending.h | 79-------------------------------------------------------------------------------
Dsrc/include/merchant-database/iterate_spent_tokens_by_order.h | 67-------------------------------------------------------------------
Asrc/include/merchant-database/iterate_statistic_bucket_amounts.h | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_statistic_bucket_amounts_by_range.h | 94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_statistic_bucket_counters.h | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_statistic_bucket_counters_by_range.h | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_statistic_interval_amounts.h | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_statistic_interval_counters.h | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/merchant-database/iterate_statistics_amount_by_bucket.h | 68--------------------------------------------------------------------
Dsrc/include/merchant-database/iterate_statistics_amount_by_bucket_range.h | 94-------------------------------------------------------------------------------
Dsrc/include/merchant-database/iterate_statistics_amount_by_interval.h | 65-----------------------------------------------------------------
Dsrc/include/merchant-database/iterate_statistics_counter_by_bucket.h | 67-------------------------------------------------------------------
Dsrc/include/merchant-database/iterate_statistics_counter_by_bucket_range.h | 71-----------------------------------------------------------------------
Dsrc/include/merchant-database/iterate_statistics_counter_by_interval.h | 82-------------------------------------------------------------------------------
Asrc/include/merchant-database/iterate_transfer_summaries.h | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/merchant-database/iterate_transfer_summary.h | 62--------------------------------------------------------------
Asrc/include/merchant-database/iterate_used_tokens_by_order.h | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/update_account_last_bank_serial.h | 46++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/merchant-database/update_contract_session.h | 50--------------------------------------------------
Asrc/include/merchant-database/update_contract_terms_session.h | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/merchant-database/update_deposit_confirmation_status.h | 53-----------------------------------------------------
Asrc/include/merchant-database/update_deposit_settlement_status.h | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/update_expected_transfer_status.h | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/merchant-database/update_otp.h | 48------------------------------------------------
Asrc/include/merchant-database/update_otp_device.h | 48++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/update_to_expected_transfer_finalized.h | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/merchant-database/update_to_transfer_finalized.h | 54------------------------------------------------------
Dsrc/include/merchant-database/update_transfer_status.h | 53-----------------------------------------------------
Dsrc/include/merchant-database/update_wirewatch_progress.h | 46----------------------------------------------
143 files changed, 5288 insertions(+), 5281 deletions(-)

diff --git a/src/backend/taler-merchant-depositcheck.c b/src/backend/taler-merchant-depositcheck.c @@ -36,7 +36,7 @@ struct ExchangeInteraction; #include "merchant-database/insert_kyc_failure.h" #include "merchant-database/set_instance.h" #include "merchant-database/insert_deposit_to_transfer.h" -#include "merchant-database/update_deposit_confirmation_status.h" +#include "merchant-database/update_deposit_settlement_status.h" #include "merchant-database/start.h" /** @@ -493,7 +493,7 @@ deposit_get_cb ( GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Bumping wire transfer deadline in DB to %s as that is when we will retry\n", GNUNET_TIME_absolute2s (future_retry)); - qs = TALER_MERCHANTDB_update_deposit_confirmation_status ( + qs = TALER_MERCHANTDB_update_deposit_settlement_status ( pg, w->deposit_serial, true, /* need to try again in the future! */ @@ -519,7 +519,7 @@ deposit_get_cb ( GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Bumping wire transfer deadline in DB to %s as that is when we will retry\n", GNUNET_TIME_absolute2s (future_retry)); - qs = TALER_MERCHANTDB_update_deposit_confirmation_status ( + qs = TALER_MERCHANTDB_update_deposit_settlement_status ( pg, w->deposit_serial, true /* need to try again in the future */, @@ -569,7 +569,7 @@ deposit_get_cb ( retry_needed = true; break; } - qs = TALER_MERCHANTDB_update_deposit_confirmation_status ( + qs = TALER_MERCHANTDB_update_deposit_settlement_status ( pg, w->deposit_serial, retry_needed, diff --git a/src/backend/taler-merchant-exchangekeyupdate.c b/src/backend/taler-merchant-exchangekeyupdate.c @@ -33,14 +33,14 @@ struct Exchange; #include "merchantdb_lib.h" #include "merchant-database/delete_exchange_accounts.h" #include "merchant-database/insert_exchange_keys.h" -#include "merchant-database/insert_exchange_signkey.h" +#include "merchant-database/insert_exchange_signing_key.h" #include "merchant-database/start.h" #include "merchant-database/preflight.h" #include "merchant-database/event_notify.h" #include "merchant-database/event_listen.h" #include "merchant-database/insert_exchange_account.h" #include "merchant-database/get_exchange_keys.h" -#include "merchant-database/insert_wire_fee.h" +#include "merchant-database/insert_exchange_wire_fee.h" /** * Maximum frequency for the exchange interaction. @@ -345,7 +345,7 @@ insert_keys_data (const struct TALER_EXCHANGE_Keys *keys, const struct TALER_EXCHANGE_SigningPublicKey *sign_key = &keys->sign_keys[i]; - qs = TALER_MERCHANTDB_insert_exchange_signkey ( + qs = TALER_MERCHANTDB_insert_exchange_signing_key ( pg, &keys->master_pub, &sign_key->key, @@ -450,7 +450,7 @@ insert_keys_data (const struct TALER_EXCHANGE_Keys *keys, GNUNET_CRYPTO_hash (wire_method, strlen (wire_method) + 1, &h_wire_method); - qs = TALER_MERCHANTDB_insert_wire_fee ( + qs = TALER_MERCHANTDB_insert_exchange_wire_fee ( pg, &keys->master_pub, &h_wire_method, diff --git a/src/backend/taler-merchant-httpd_delete-private-otp-devices-DEVICE_ID.c b/src/backend/taler-merchant-httpd_delete-private-otp-devices-DEVICE_ID.c @@ -21,7 +21,7 @@ #include "platform.h" #include "taler-merchant-httpd_delete-private-otp-devices-DEVICE_ID.h" #include <taler/taler_json_lib.h> -#include "merchant-database/delete_otp.h" +#include "merchant-database/delete_otp_device.h" /** @@ -43,9 +43,9 @@ TMH_private_delete_otp_devices_ID (const struct TMH_RequestHandler *rh, (void) rh; GNUNET_assert (NULL != mi); GNUNET_assert (NULL != hc->infix); - qs = TALER_MERCHANTDB_delete_otp (TMH_db, - mi->settings.id, - hc->infix); + qs = TALER_MERCHANTDB_delete_otp_device (TMH_db, + mi->settings.id, + hc->infix); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/backend/taler-merchant-httpd_get-private-incoming-ID.c b/src/backend/taler-merchant-httpd_get-private-incoming-ID.c @@ -24,7 +24,7 @@ #include "taler-merchant-httpd_get-private-incoming-ID.h" #include "merchant-database/get_expected_transfer.h" #include "merchant-database/iterate_reconciliation_details.h" -#include "merchant-database/get_wire_fee.h" +#include "merchant-database/get_exchange_wire_fee.h" #include "merchant-database/preflight.h" @@ -139,7 +139,7 @@ TMH_private_get_incoming_ID (const struct TMH_RequestHandler *rh, struct TALER_WireFeeSet fees; method = TALER_payto_get_method (payto_uri.full_payto); - qs = TALER_MERCHANTDB_get_wire_fee ( + qs = TALER_MERCHANTDB_get_exchange_wire_fee ( TMH_db, &master_pub, method, diff --git a/src/backend/taler-merchant-httpd_get-private-otp-devices-DEVICE_ID.c b/src/backend/taler-merchant-httpd_get-private-otp-devices-DEVICE_ID.c @@ -21,7 +21,7 @@ #include "platform.h" #include "taler-merchant-httpd_get-private-otp-devices-DEVICE_ID.h" #include <taler/taler_json_lib.h> -#include "merchant-database/get_otp.h" +#include "merchant-database/get_otp_device.h" /** @@ -56,10 +56,10 @@ TMH_private_get_otp_devices_ID (const struct TMH_RequestHandler *rh, &price); my_time = GNUNET_TIME_timestamp_from_s (faketime_s); GNUNET_assert (NULL != mi); - qs = TALER_MERCHANTDB_get_otp (TMH_db, - mi->settings.id, - hc->infix, - &tp); + qs = TALER_MERCHANTDB_get_otp_device (TMH_db, + mi->settings.id, + hc->infix, + &tp); if (0 > qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-private-statistics-amount-SLUG.c b/src/backend/taler-merchant-httpd_get-private-statistics-amount-SLUG.c @@ -22,8 +22,8 @@ #include "taler-merchant-httpd_get-private-statistics-amount-SLUG.h" #include <gnunet/gnunet_json_lib.h> #include <taler/taler_json_lib.h> -#include "merchant-database/iterate_statistics_amount_by_bucket.h" -#include "merchant-database/iterate_statistics_amount_by_interval.h" +#include "merchant-database/iterate_statistic_bucket_amounts.h" +#include "merchant-database/iterate_statistic_interval_amounts.h" /** @@ -209,7 +209,7 @@ TMH_private_get_statistics_amount_SLUG (const struct TMH_RequestHandler *rh, { enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_iterate_statistics_amount_by_bucket ( + qs = TALER_MERCHANTDB_iterate_statistic_bucket_amounts ( TMH_db, mi->settings.id, hc->infix, @@ -230,7 +230,7 @@ TMH_private_get_statistics_amount_SLUG (const struct TMH_RequestHandler *rh, { enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_iterate_statistics_amount_by_interval ( + qs = TALER_MERCHANTDB_iterate_statistic_interval_amounts ( TMH_db, mi->settings.id, hc->infix, diff --git a/src/backend/taler-merchant-httpd_get-private-statistics-counter-SLUG.c b/src/backend/taler-merchant-httpd_get-private-statistics-counter-SLUG.c @@ -22,8 +22,8 @@ #include "taler-merchant-httpd_get-private-statistics-counter-SLUG.h" #include <gnunet/gnunet_json_lib.h> #include <taler/taler_json_lib.h> -#include "merchant-database/iterate_statistics_counter_by_bucket.h" -#include "merchant-database/iterate_statistics_counter_by_interval.h" +#include "merchant-database/iterate_statistic_bucket_counters.h" +#include "merchant-database/iterate_statistic_interval_counters.h" /** @@ -182,7 +182,7 @@ TMH_private_get_statistics_counter_SLUG (const struct TMH_RequestHandler *rh, { enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_iterate_statistics_counter_by_bucket ( + qs = TALER_MERCHANTDB_iterate_statistic_bucket_counters ( TMH_db, mi->settings.id, hc->infix, @@ -203,7 +203,7 @@ TMH_private_get_statistics_counter_SLUG (const struct TMH_RequestHandler *rh, { enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_iterate_statistics_counter_by_interval ( + qs = TALER_MERCHANTDB_iterate_statistic_interval_counters ( TMH_db, mi->settings.id, hc->infix, 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/iterate_statistics_amount_by_bucket_range.h" -#include "merchant-database/iterate_statistics_counter_by_bucket_range.h" +#include "merchant-database/iterate_statistic_bucket_amounts_by_range.h" +#include "merchant-database/iterate_statistic_bucket_counters_by_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_iterate_statistics_amount_by_bucket_range ( + qs = TALER_MERCHANTDB_iterate_statistic_bucket_amounts_by_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_iterate_statistics_counter_by_bucket_range ( + qs = TALER_MERCHANTDB_iterate_statistic_bucket_counters_by_range ( TMH_db, rctx->hc->instance->settings.id, prefix, /* prefix to match against bucket name */ diff --git a/src/backend/taler-merchant-httpd_helper.c b/src/backend/taler-merchant-httpd_helper.c @@ -27,7 +27,7 @@ #include <taler/taler_dbevents.h> #include "merchant-database/insert_pending_webhook.h" #include "merchant-database/iterate_webhooks_by_event.h" -#include "merchant-database/iterate_accounts_by_exchange.h" +#include "merchant-database/iterate_exchange_accounts.h" #include "merchant-database/get_login_token.h" #include "merchant-database/get_unit.h" #include "merchant-database/event_notify.h" @@ -1122,10 +1122,10 @@ TMH_exchange_accounts_by_method ( enum GNUNET_DB_QueryStatus qs; GNUNET_assert (NULL != emc.accounts); - qs = TALER_MERCHANTDB_iterate_accounts_by_exchange (TMH_db, - master_pub, - &add_matching_account, - &emc); + qs = TALER_MERCHANTDB_iterate_exchange_accounts (TMH_db, + master_pub, + &add_matching_account, + &emc); if (qs < 0) { json_decref (emc.accounts); diff --git a/src/backend/taler-merchant-httpd_patch-private-otp-devices-DEVICE_ID.c b/src/backend/taler-merchant-httpd_patch-private-otp-devices-DEVICE_ID.c @@ -26,7 +26,7 @@ #include "taler-merchant-httpd_patch-private-otp-devices-DEVICE_ID.h" #include "taler-merchant-httpd_helper.h" #include <taler/taler_json_lib.h> -#include "merchant-database/update_otp.h" +#include "merchant-database/update_otp_device.h" enum MHD_Result @@ -69,10 +69,10 @@ TMH_private_patch_otp_devices_ID (const struct TMH_RequestHandler *rh, : MHD_NO; } - qs = TALER_MERCHANTDB_update_otp (TMH_db, - mi->settings.id, - device_id, - &tp); + qs = TALER_MERCHANTDB_update_otp_device (TMH_db, + mi->settings.id, + device_id, + &tp); { enum MHD_Result ret = MHD_NO; diff --git a/src/backend/taler-merchant-httpd_post-orders-ORDER_ID-paid.c b/src/backend/taler-merchant-httpd_post-orders-ORDER_ID-paid.c @@ -29,7 +29,7 @@ #include <taler/taler_exchange_service.h> #include "taler-merchant-httpd_helper.h" #include "taler-merchant-httpd_post-orders-ORDER_ID-paid.h" -#include "merchant-database/update_contract_session.h" +#include "merchant-database/update_contract_terms_session.h" #include "merchant-database/event_notify.h" #include "merchant-database/preflight.h" @@ -117,12 +117,12 @@ TMH_post_orders_ID_paid (const struct TMH_RequestHandler *rh, TALER_MERCHANTDB_preflight (TMH_db); - qs = TALER_MERCHANTDB_update_contract_session (TMH_db, - hc->instance->settings.id, - &hct, - session_id, - &fulfillment_url, - &refunded); + qs = TALER_MERCHANTDB_update_contract_terms_session (TMH_db, + hc->instance->settings.id, + &hct, + session_id, + &fulfillment_url, + &refunded); switch (qs) { case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: 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 @@ -56,18 +56,18 @@ struct ExchangeGroup; #include "merchant-database/insert_deposit.h" #include "merchant-database/insert_deposit_confirmation.h" #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/insert_order_token_blinded_sig.h" +#include "merchant-database/insert_used_token.h" #include "merchant-database/get_contract_terms_pos.h" #include "merchant-database/iterate_deposits.h" #include "merchant-database/iterate_deposits_by_order.h" -#include "merchant-database/get_order_charity.h" +#include "merchant-database/get_donau_instance_by_url.h" #include "merchant-database/iterate_refunds.h" #include "merchant-database/set_instance.h" -#include "merchant-database/iterate_spent_tokens_by_order.h" +#include "merchant-database/iterate_used_tokens_by_order.h" #include "merchant-database/get_token_family_key.h" #include "merchant-database/update_to_contract_terms_paid.h" -#include "merchant-database/iterate_order_blinded_sigs.h" +#include "merchant-database/iterate_order_token_blinded_sigs.h" #include "merchant-database/start.h" #include "merchant-database/preflight.h" #include "merchant-database/event_notify.h" @@ -2116,7 +2116,7 @@ phase_final_output_token_processing (struct PayContext *pc) { if (NULL == pc->output_tokens[i].sig.signature) continue; /* must have been optional and not provided by wallet */ - qs = TALER_MERCHANTDB_insert_order_blinded_sigs ( + qs = TALER_MERCHANTDB_insert_order_token_blinded_sig ( TMH_db, pc->order_id, i, @@ -3010,12 +3010,12 @@ phase_execute_pay_transaction (struct PayContext *pc) /* Insert used token into database, the unique constraint will case an error if this token was used before. */ - qs = TALER_MERCHANTDB_insert_spent_token (TMH_db, - &pc->check_contract.h_contract_terms, - &tuc->h_issue, - &tuc->pub, - &tuc->sig, - &tuc->unblinded_sig); + qs = TALER_MERCHANTDB_insert_used_token (TMH_db, + &pc->check_contract.h_contract_terms, + &tuc->h_issue, + &tuc->pub, + &tuc->sig, + &tuc->unblinded_sig); switch (qs) { @@ -4383,10 +4383,10 @@ phase_contract_paid (struct PayContext *pc) enum GNUNET_DB_QueryStatus qs; /* FIXME-Optimization: Maybe use h_contract instead of order_serial here? */ - qs = TALER_MERCHANTDB_iterate_spent_tokens_by_order (TMH_db, - pc->check_contract.order_serial, - &input_tokens_paid_check, - pc); + qs = TALER_MERCHANTDB_iterate_used_tokens_by_order (TMH_db, + pc->check_contract.order_serial, + &input_tokens_paid_check, + pc); if (qs < 0) { @@ -4415,7 +4415,7 @@ phase_contract_paid (struct PayContext *pc) enum GNUNET_DB_QueryStatus qs; pc->output_index_gen = 0; - qs = TALER_MERCHANTDB_iterate_order_blinded_sigs ( + qs = TALER_MERCHANTDB_iterate_order_token_blinded_sigs ( TMH_db, pc->order_id, &append_output_token_sig, @@ -4882,7 +4882,7 @@ phase_parse_wallet_data (struct PayContext *pc) { enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_get_order_charity ( + qs = TALER_MERCHANTDB_get_donau_instance_by_url ( TMH_db, pc->hc->instance->settings.id, donau_url_tmp, diff --git a/src/backend/taler-merchant-httpd_post-private-orders.c b/src/backend/taler-merchant-httpd_post-private-orders.c @@ -62,7 +62,7 @@ #include "merchant-database/get_token_family_key.h" #include "merchant-database/iterate_token_family_keys.h" #include "merchant-database/iterate_donau_instances_filtered.h" -#include "merchant-database/get_otp.h" +#include "merchant-database/get_otp_device.h" #include "merchant-database/delete_inventory_lock.h" @@ -4063,10 +4063,10 @@ phase_parse_request (struct OrderContext *oc) memset (&td, 0, sizeof (td)); - qs = TALER_MERCHANTDB_get_otp (TMH_db, - oc->hc->instance->settings.id, - otp_id, - &td); + qs = TALER_MERCHANTDB_get_otp_device (TMH_db, + oc->hc->instance->settings.id, + otp_id, + &td); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/backend/taler-merchant-httpd_post-private-otp-devices.c b/src/backend/taler-merchant-httpd_post-private-otp-devices.c @@ -26,8 +26,8 @@ #include "taler-merchant-httpd_post-private-otp-devices.h" #include "taler-merchant-httpd_helper.h" #include <taler/taler_json_lib.h> -#include "merchant-database/insert_otp.h" -#include "merchant-database/get_otp.h" +#include "merchant-database/insert_otp_device.h" +#include "merchant-database/get_otp_device.h" #include "merchant-database/start.h" @@ -115,10 +115,10 @@ TMH_private_post_otp_devices (const struct TMH_RequestHandler *rh, TALER_EC_GENERIC_DB_START_FAILED, NULL); } - qs = TALER_MERCHANTDB_get_otp (TMH_db, - mi->settings.id, - device_id, - &etp); + qs = TALER_MERCHANTDB_get_otp_device (TMH_db, + mi->settings.id, + device_id, + &etp); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: @@ -160,10 +160,10 @@ TMH_private_post_otp_devices (const struct TMH_RequestHandler *rh, } } /* end switch (qs) */ - qs = TALER_MERCHANTDB_insert_otp (TMH_db, - mi->settings.id, - device_id, - &tp); + qs = TALER_MERCHANTDB_insert_otp_device (TMH_db, + mi->settings.id, + device_id, + &tp); if (GNUNET_DB_STATUS_HARD_ERROR == qs) { TALER_MERCHANTDB_rollback (TMH_db); diff --git a/src/backend/taler-merchant-httpd_post-private-templates.c b/src/backend/taler-merchant-httpd_post-private-templates.c @@ -28,7 +28,7 @@ #include <taler/taler_json_lib.h> #include "merchant-database/insert_template.h" #include "merchant-database/get_template.h" -#include "merchant-database/get_otp_serial.h" +#include "merchant-database/get_otp_device_serial.h" /** @@ -148,10 +148,10 @@ TMH_private_post_templates (const struct TMH_RequestHandler *rh, if (NULL != tp.otp_id) { - qs = TALER_MERCHANTDB_get_otp_serial (TMH_db, - mi->settings.id, - tp.otp_id, - &otp_serial); + qs = TALER_MERCHANTDB_get_otp_device_serial (TMH_db, + mi->settings.id, + tp.otp_id, + &otp_serial); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/backend/taler-merchant-reconciliation.c b/src/backend/taler-merchant-reconciliation.c @@ -30,14 +30,14 @@ struct Inquiry; #include "taler/taler_merchant_bank_lib.h" #include "merchantdb_lib.h" #include "merchantdb_lib.h" -#include "merchant-database/update_to_transfer_finalized.h" +#include "merchant-database/update_to_expected_transfer_finalized.h" #include "merchant-database/insert_transfer_details.h" #include "merchant-database/iterate_deposits_by_contract_and_coin.h" -#include "merchant-database/get_wire_fee.h" +#include "merchant-database/get_exchange_wire_fee.h" #include "merchant-database/get_exchange_keys.h" -#include "merchant-database/iterate_open_transfers.h" +#include "merchant-database/iterate_open_expected_transfers.h" #include "merchant-database/set_instance.h" -#include "merchant-database/update_transfer_status.h" +#include "merchant-database/update_expected_transfer_status.h" #include "merchant-database/event_listen.h" #include "merchant-database/preflight.h" @@ -313,14 +313,14 @@ update_transaction_status (const struct Inquiry *w, GNUNET_SCHEDULER_shutdown (); return; } - qs = TALER_MERCHANTDB_update_transfer_status (pg, - w->exchange->exchange_url, - &w->wtid, - next_attempt, - http_status, - ec, - last_hint, - needs_retry); + qs = TALER_MERCHANTDB_update_expected_transfer_status (pg, + w->exchange->exchange_url, + &w->wtid, + next_attempt, + http_status, + ec, + last_hint, + needs_retry); GNUNET_break (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == TALER_MERCHANTDB_set_instance ( pg, @@ -566,14 +566,14 @@ check_wire_fee (struct Inquiry *w, return GNUNET_NO; } wire_method = TALER_payto_get_method (w->payto_uri.full_payto); - qs = TALER_MERCHANTDB_get_wire_fee (pg, - &keys->master_pub, - wire_method, - execution_time, - &fees, - &start_date, - &end_date, - &master_sig); + qs = TALER_MERCHANTDB_get_exchange_wire_fee (pg, + &keys->master_pub, + wire_method, + execution_time, + &fees, + &start_date, + &end_date, + &master_sig); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: @@ -965,14 +965,14 @@ wire_transfer_cb (struct Inquiry *w, { enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_update_to_transfer_finalized (pg, - w->exchange->exchange_url, - &w->wtid, - &td->h_details, - &td->total_amount, - &td->wire_fee, - &td->exchange_pub, - &td->exchange_sig); + qs = TALER_MERCHANTDB_update_to_expected_transfer_finalized (pg, + w->exchange->exchange_url, + &w->wtid, + &td->h_details, + &td->total_amount, + &td->wire_fee, + &td->exchange_pub, + &td->exchange_sig); if (qs < 0) { GNUNET_break (0); @@ -1132,10 +1132,10 @@ find_work (void *cls) return; } at_limit = false; - qs = TALER_MERCHANTDB_iterate_open_transfers (pg, - limit, - &start_inquiry, - NULL); + qs = TALER_MERCHANTDB_iterate_open_expected_transfers (pg, + limit, + &start_inquiry, + NULL); if (qs < 0) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, diff --git a/src/backend/taler-merchant-report-generator.c b/src/backend/taler-merchant-report-generator.c @@ -33,7 +33,7 @@ #include <microhttpd.h> #include <curl/curl.h> #include "merchant-database/delete_report.h" -#include "merchant-database/iterate_reports_pending.h" +#include "merchant-database/iterate_pending_reports.h" #include "merchant-database/update_report_status.h" #include "merchant-database/set_instance.h" #include "merchant-database/event_listen.h" @@ -729,7 +729,7 @@ check_pending_reports (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Checking for pending reports...\n"); next = GNUNET_TIME_UNIT_FOREVER_ABS; - qs = TALER_MERCHANTDB_iterate_reports_pending (pg, + qs = TALER_MERCHANTDB_iterate_pending_reports (pg, &process_pending_report, &next); if (qs < 0) diff --git a/src/backend/taler-merchant-wirewatch.c b/src/backend/taler-merchant-wirewatch.c @@ -31,7 +31,7 @@ #include "merchant-database/insert_transfer.h" #include "merchant-database/set_instance.h" #include "merchant-database/iterate_wirewatch_accounts.h" -#include "merchant-database/update_wirewatch_progress.h" +#include "merchant-database/update_account_last_bank_serial.h" #include "merchant-database/event_listen.h" @@ -201,10 +201,10 @@ save (struct Watch *w) return; } - qs = TALER_MERCHANTDB_update_wirewatch_progress (pg, - w->instance_id, - w->payto_uri, - w->start_row); + qs = TALER_MERCHANTDB_update_account_last_bank_serial (pg, + w->instance_id, + w->payto_uri, + w->start_row); GNUNET_break (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == TALER_MERCHANTDB_set_instance (pg, NULL)); diff --git a/src/backenddb/delete_otp.c b/src/backenddb/delete_otp.c @@ -1,48 +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/delete_otp.c - * @brief Implementation of the delete_otp function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/delete_otp.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_delete_otp ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *otp_id) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (otp_id), - GNUNET_PQ_query_param_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance_id, - pg->current_merchant_id)); - TMH_PQ_prepare_anon (pg, - "DELETE" - " FROM merchant_otp_devices" - " WHERE otp_id=$1"); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "", - params); -} diff --git a/src/backenddb/delete_otp_device.c b/src/backenddb/delete_otp_device.c @@ -0,0 +1,48 @@ +/* + 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/delete_otp_device.c + * @brief Implementation of the delete_otp_device function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/delete_otp_device.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_delete_otp_device ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *otp_id) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (otp_id), + GNUNET_PQ_query_param_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (instance_id, + pg->current_merchant_id)); + TMH_PQ_prepare_anon (pg, + "DELETE" + " FROM merchant_otp_devices" + " WHERE otp_id=$1"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "", + params); +} diff --git a/src/backenddb/get_donau_instance_by_url.c b/src/backenddb/get_donau_instance_by_url.c @@ -0,0 +1,83 @@ +/* + 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/get_donau_instance_by_url.c + * @brief Implementation for retrieving Donau charity_id and corresponding private key + * by Donau URL. + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#include "platform.h" +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "merchantdb_lib.h" +#include "donau/donau_service.h" +#include "merchant-database/get_donau_instance_by_url.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_donau_instance_by_url ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *donau_url, + uint64_t *charity_id, + struct TALER_Amount *charity_max_per_year, + struct TALER_Amount *charity_receipts_to_date, + json_t **donau_keys_json, + uint64_t *donau_instance_serial) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (donau_url), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("charity_id", + charity_id), + TALER_PQ_result_spec_json ("keys_json", + donau_keys_json), + TALER_PQ_result_spec_amount_with_currency ("charity_max_per_year", + charity_max_per_year), + TALER_PQ_result_spec_amount_with_currency ("charity_receipts_to_date", + charity_receipts_to_date), + GNUNET_PQ_result_spec_uint64 ("donau_instances_serial", + donau_instance_serial), + 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" + " di.donau_instances_serial" + " ,di.charity_id" + " ,dk.keys_json::TEXT" + " ,di.charity_max_per_year" + " ,di.charity_receipts_to_date" + " FROM merchant_donau_instances di" + " JOIN merchant.merchant_donau_keys dk" + " ON dk.donau_url = di.donau_url" + " WHERE di.donau_url = $1;"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/get_exchange_wire_fee.c b/src/backenddb/get_exchange_wire_fee.c @@ -0,0 +1,79 @@ +/* + 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/backenddb/get_exchange_wire_fee.c + * @brief Implementation of the get_exchange_wire_fee function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_exchange_wire_fee.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_exchange_wire_fee ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const struct TALER_MasterPublicKeyP *master_pub, + const char *wire_method, + struct GNUNET_TIME_Timestamp contract_date, + struct TALER_WireFeeSet *fees, + struct GNUNET_TIME_Timestamp *start_date, + struct GNUNET_TIME_Timestamp *end_date, + struct TALER_MasterSignatureP *master_sig) +{ + struct GNUNET_HashCode h_wire_method; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (master_pub), + GNUNET_PQ_query_param_auto_from_type (&h_wire_method), + GNUNET_PQ_query_param_timestamp (&contract_date), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + TALER_PQ_result_spec_amount_with_currency ("wire_fee", + &fees->wire), + TALER_PQ_result_spec_amount_with_currency ("closing_fee", + &fees->closing), + GNUNET_PQ_result_spec_timestamp ("start_date", + start_date), + GNUNET_PQ_result_spec_timestamp ("end_date", + end_date), + GNUNET_PQ_result_spec_auto_from_type ("master_sig", + master_sig), + GNUNET_PQ_result_spec_end + }; + + GNUNET_CRYPTO_hash (wire_method, + strlen (wire_method) + 1, + &h_wire_method); + PREPARE (pg, + "lookup_wire_fee", + "SELECT" + " wire_fee" + ",closing_fee" + ",start_date" + ",end_date" + ",master_sig" + " FROM merchant.merchant_exchange_wire_fees" + " WHERE master_pub=$1" + " AND h_wire_method=$2" + " AND start_date <= $3" + " AND end_date > $3"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "lookup_wire_fee", + params, + rs); +} diff --git a/src/backenddb/get_order_charity.c b/src/backenddb/get_order_charity.c @@ -1,83 +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/get_order_charity.c - * @brief Implementation for retrieving Donau charity_id and corresponding private key - * by Donau URL. - * @author Bohdan Potuzhnyi - * @author Vlada Svirsh - */ -#include "platform.h" -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "merchantdb_lib.h" -#include "donau/donau_service.h" -#include "merchant-database/get_order_charity.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_get_order_charity ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *donau_url, - uint64_t *charity_id, - struct TALER_Amount *charity_max_per_year, - struct TALER_Amount *charity_receipts_to_date, - json_t **donau_keys_json, - uint64_t *donau_instance_serial) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (donau_url), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("charity_id", - charity_id), - TALER_PQ_result_spec_json ("keys_json", - donau_keys_json), - TALER_PQ_result_spec_amount_with_currency ("charity_max_per_year", - charity_max_per_year), - TALER_PQ_result_spec_amount_with_currency ("charity_receipts_to_date", - charity_receipts_to_date), - GNUNET_PQ_result_spec_uint64 ("donau_instances_serial", - donau_instance_serial), - 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" - " di.donau_instances_serial" - " ,di.charity_id" - " ,dk.keys_json::TEXT" - " ,di.charity_max_per_year" - " ,di.charity_receipts_to_date" - " FROM merchant_donau_instances di" - " JOIN merchant.merchant_donau_keys dk" - " ON dk.donau_url = di.donau_url" - " WHERE di.donau_url = $1;"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/get_otp.c b/src/backenddb/get_otp.c @@ -1,69 +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/get_otp.c - * @brief Implementation of the get_otp function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/get_otp.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_get_otp ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *otp_id, - struct TALER_MERCHANTDB_OtpDeviceDetails *td) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (otp_id), - GNUNET_PQ_query_param_end - }; - uint32_t pos32 = TALER_MCA_NONE; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("otp_description", - &td->otp_description), - GNUNET_PQ_result_spec_uint64 ("otp_ctr", - &td->otp_ctr), - GNUNET_PQ_result_spec_string ("otp_key", - &td->otp_key), - GNUNET_PQ_result_spec_uint32 ("otp_algorithm", - &pos32), - GNUNET_PQ_result_spec_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" - " otp_description" - ",otp_ctr" - ",otp_key" - ",otp_algorithm" - " FROM merchant_otp_devices" - " WHERE otp_id=$1"); - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); - td->otp_algorithm = (enum TALER_MerchantConfirmationAlgorithm) pos32; - return qs; -} diff --git a/src/backenddb/get_otp_device.c b/src/backenddb/get_otp_device.c @@ -0,0 +1,69 @@ +/* + 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/get_otp_device.c + * @brief Implementation of the get_otp_device function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_otp_device.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_otp_device ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *otp_id, + struct TALER_MERCHANTDB_OtpDeviceDetails *td) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (otp_id), + GNUNET_PQ_query_param_end + }; + uint32_t pos32 = TALER_MCA_NONE; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("otp_description", + &td->otp_description), + GNUNET_PQ_result_spec_uint64 ("otp_ctr", + &td->otp_ctr), + GNUNET_PQ_result_spec_string ("otp_key", + &td->otp_key), + GNUNET_PQ_result_spec_uint32 ("otp_algorithm", + &pos32), + GNUNET_PQ_result_spec_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" + " otp_description" + ",otp_ctr" + ",otp_key" + ",otp_algorithm" + " FROM merchant_otp_devices" + " WHERE otp_id=$1"); + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); + td->otp_algorithm = (enum TALER_MerchantConfirmationAlgorithm) pos32; + return qs; +} diff --git a/src/backenddb/get_otp_device_serial.c b/src/backenddb/get_otp_device_serial.c @@ -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/backenddb/get_otp_device_serial.c + * @brief Implementation of the get_otp_device_serial function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_otp_device_serial.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_otp_device_serial ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *otp_id, + uint64_t *serial) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (otp_id), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("otp_serial", + serial), + 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" + " otp_serial" + " FROM merchant_otp_devices" + " WHERE otp_id=$1"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/get_otp_serial.c b/src/backenddb/get_otp_serial.c @@ -1,56 +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/get_otp_serial.c - * @brief Implementation of the get_otp_serial function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/get_otp_serial.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_get_otp_serial ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *otp_id, - uint64_t *serial) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (otp_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("otp_serial", - serial), - 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" - " otp_serial" - " FROM merchant_otp_devices" - " WHERE otp_id=$1"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/get_wire_fee.c b/src/backenddb/get_wire_fee.c @@ -1,79 +0,0 @@ -/* - 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/backenddb/get_wire_fee.c - * @brief Implementation of the get_wire_fee function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/get_wire_fee.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_get_wire_fee ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const struct TALER_MasterPublicKeyP *master_pub, - const char *wire_method, - struct GNUNET_TIME_Timestamp contract_date, - struct TALER_WireFeeSet *fees, - struct GNUNET_TIME_Timestamp *start_date, - struct GNUNET_TIME_Timestamp *end_date, - struct TALER_MasterSignatureP *master_sig) -{ - struct GNUNET_HashCode h_wire_method; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (master_pub), - GNUNET_PQ_query_param_auto_from_type (&h_wire_method), - GNUNET_PQ_query_param_timestamp (&contract_date), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_amount_with_currency ("wire_fee", - &fees->wire), - TALER_PQ_result_spec_amount_with_currency ("closing_fee", - &fees->closing), - GNUNET_PQ_result_spec_timestamp ("start_date", - start_date), - GNUNET_PQ_result_spec_timestamp ("end_date", - end_date), - GNUNET_PQ_result_spec_auto_from_type ("master_sig", - master_sig), - GNUNET_PQ_result_spec_end - }; - - GNUNET_CRYPTO_hash (wire_method, - strlen (wire_method) + 1, - &h_wire_method); - PREPARE (pg, - "lookup_wire_fee", - "SELECT" - " wire_fee" - ",closing_fee" - ",start_date" - ",end_date" - ",master_sig" - " FROM merchant.merchant_exchange_wire_fees" - " WHERE master_pub=$1" - " AND h_wire_method=$2" - " AND start_date <= $3" - " AND end_date > $3"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "lookup_wire_fee", - params, - rs); -} diff --git a/src/backenddb/insert_exchange_signing_key.c b/src/backenddb/insert_exchange_signing_key.c @@ -0,0 +1,63 @@ +/* + 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/insert_exchange_signing_key.c + * @brief Implementation of the insert_exchange_signing_key function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/insert_exchange_signing_key.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_insert_exchange_signing_key ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const struct TALER_MasterPublicKeyP *master_pub, + const struct TALER_ExchangePublicKeyP *exchange_pub, + struct GNUNET_TIME_Timestamp start_date, + struct GNUNET_TIME_Timestamp expire_date, + struct GNUNET_TIME_Timestamp end_date, + const struct TALER_MasterSignatureP *master_sig) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (master_pub), + GNUNET_PQ_query_param_auto_from_type (exchange_pub), + GNUNET_PQ_query_param_timestamp (&start_date), + GNUNET_PQ_query_param_timestamp (&expire_date), + GNUNET_PQ_query_param_timestamp (&end_date), + GNUNET_PQ_query_param_auto_from_type (master_sig), + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "insert_exchange_signkey", + "INSERT INTO merchant.merchant_exchange_signing_keys" + "(master_pub" + ",exchange_pub" + ",start_date" + ",expire_date" + ",end_date" + ",master_sig)" + "VALUES" + "($1, $2, $3, $4, $5, $6)" + " ON CONFLICT DO NOTHING;"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_exchange_signkey", + params); + +} diff --git a/src/backenddb/insert_exchange_signkey.c b/src/backenddb/insert_exchange_signkey.c @@ -1,63 +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/insert_exchange_signkey.c - * @brief Implementation of the insert_exchange_signkey function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/insert_exchange_signkey.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_insert_exchange_signkey ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const struct TALER_MasterPublicKeyP *master_pub, - const struct TALER_ExchangePublicKeyP *exchange_pub, - struct GNUNET_TIME_Timestamp start_date, - struct GNUNET_TIME_Timestamp expire_date, - struct GNUNET_TIME_Timestamp end_date, - const struct TALER_MasterSignatureP *master_sig) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (master_pub), - GNUNET_PQ_query_param_auto_from_type (exchange_pub), - GNUNET_PQ_query_param_timestamp (&start_date), - GNUNET_PQ_query_param_timestamp (&expire_date), - GNUNET_PQ_query_param_timestamp (&end_date), - GNUNET_PQ_query_param_auto_from_type (master_sig), - GNUNET_PQ_query_param_end - }; - - PREPARE (pg, - "insert_exchange_signkey", - "INSERT INTO merchant.merchant_exchange_signing_keys" - "(master_pub" - ",exchange_pub" - ",start_date" - ",expire_date" - ",end_date" - ",master_sig)" - "VALUES" - "($1, $2, $3, $4, $5, $6)" - " ON CONFLICT DO NOTHING;"); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_exchange_signkey", - params); - -} diff --git a/src/backenddb/insert_exchange_wire_fee.c b/src/backenddb/insert_exchange_wire_fee.c @@ -0,0 +1,72 @@ +/* + 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/insert_exchange_wire_fee.c + * @brief Implementation of the insert_exchange_wire_fee function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/insert_exchange_wire_fee.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_insert_exchange_wire_fee ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const struct TALER_MasterPublicKeyP *master_pub, + const struct GNUNET_HashCode *h_wire_method, + const struct TALER_WireFeeSet *fees, + struct GNUNET_TIME_Timestamp start_date, + struct GNUNET_TIME_Timestamp end_date, + const struct TALER_MasterSignatureP *master_sig) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (master_pub), + GNUNET_PQ_query_param_auto_from_type (h_wire_method), + TALER_PQ_query_param_amount_with_currency (pg->conn, + &fees->wire), + TALER_PQ_query_param_amount_with_currency (pg->conn, + &fees->closing), + GNUNET_PQ_query_param_timestamp (&start_date), + GNUNET_PQ_query_param_timestamp (&end_date), + GNUNET_PQ_query_param_auto_from_type (master_sig), + GNUNET_PQ_query_param_end + }; + + /* no preflight check here, run in its own transaction by the caller */ + PREPARE (pg, + "insert_wire_fee", + "INSERT INTO merchant.merchant_exchange_wire_fees" + "(master_pub" + ",h_wire_method" + ",wire_fee" + ",closing_fee" + ",start_date" + ",end_date" + ",master_sig)" + " VALUES " + "($1, $2, $3, $4, $5, $6, $7)" + " ON CONFLICT DO NOTHING"); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Storing wire fee for %s starting at %s of %s\n", + TALER_B2S (master_pub), + GNUNET_TIME_timestamp2s (start_date), + TALER_amount2s (&fees->wire)); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_wire_fee", + params); +} diff --git a/src/backenddb/insert_order_blinded_sigs.c b/src/backenddb/insert_order_blinded_sigs.c @@ -1,57 +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/insert_order_blinded_sigs.c - * @brief implementation of insert_order_blinded_sigs() for Postgres - * @author Bohdan Potuzhnyi - */ -#include "platform.h" -#include "merchant-database/insert_order_blinded_sigs.h" -#include "helper.h" - - -/* FIXME-Optimize: this smells like it should support the use of arrays... */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_insert_order_blinded_sigs ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *order_id, - uint32_t i, - const struct GNUNET_HashCode *hash, - const struct GNUNET_CRYPTO_BlindedSignature *blind_sig) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (order_id), - GNUNET_PQ_query_param_uint32 (&i), - GNUNET_PQ_query_param_auto_from_type (hash), - GNUNET_PQ_query_param_blinded_sig (blind_sig), - GNUNET_PQ_query_param_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - TMH_PQ_prepare_anon (pg, - "INSERT INTO merchant_order_token_blinded_sigs" - " (order_serial" - " ,token_index" - " ,token_hash" - " ,token_blinded_signature" - ")" - " SELECT order_serial, $2, $3, $4" - " FROM merchant_contract_terms" - " WHERE order_id = $1"); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "", - params); -} diff --git a/src/backenddb/insert_order_token_blinded_sig.c b/src/backenddb/insert_order_token_blinded_sig.c @@ -0,0 +1,57 @@ +/* + 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/insert_order_token_blinded_sig.c + * @brief implementation of insert_order_blinded_sigs() for Postgres + * @author Bohdan Potuzhnyi + */ +#include "platform.h" +#include "merchant-database/insert_order_token_blinded_sig.h" +#include "helper.h" + + +/* FIXME-Optimize: this smells like it should support the use of arrays... */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_insert_order_token_blinded_sig ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *order_id, + uint32_t i, + const struct GNUNET_HashCode *hash, + const struct GNUNET_CRYPTO_BlindedSignature *blind_sig) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (order_id), + GNUNET_PQ_query_param_uint32 (&i), + GNUNET_PQ_query_param_auto_from_type (hash), + GNUNET_PQ_query_param_blinded_sig (blind_sig), + GNUNET_PQ_query_param_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + TMH_PQ_prepare_anon (pg, + "INSERT INTO merchant_order_token_blinded_sigs" + " (order_serial" + " ,token_index" + " ,token_hash" + " ,token_blinded_signature" + ")" + " SELECT order_serial, $2, $3, $4" + " FROM merchant_contract_terms" + " WHERE order_id = $1"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "", + params); +} diff --git a/src/backenddb/insert_otp.c b/src/backenddb/insert_otp.c @@ -1,68 +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/insert_otp.c - * @brief Implementation of the insert_otp function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/insert_otp.h" -#include "helper.h" - - -/** - * Insert details about a particular OTP device. - * - * @param pg database context - * @param instance_id instance to insert OTP device for - * @param otp_id otp identifier of OTP device to insert - * @param td the OTP device details to insert - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_insert_otp ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *otp_id, - const struct TALER_MERCHANTDB_OtpDeviceDetails *td) -{ - uint32_t pos32 = (uint32_t) td->otp_algorithm; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (otp_id), - GNUNET_PQ_query_param_string (td->otp_description), - GNUNET_PQ_query_param_string (td->otp_key), - GNUNET_PQ_query_param_uint32 (&pos32), - GNUNET_PQ_query_param_uint64 (&td->otp_ctr), - GNUNET_PQ_query_param_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance_id, - pg->current_merchant_id)); - TMH_PQ_prepare_anon (pg, - "INSERT INTO merchant_otp_devices" - "(otp_id" - ",otp_description" - ",otp_key" - ",otp_algorithm" - ",otp_ctr" - ")" - " VALUES ($1, $2, $3, $4, $5)"); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "", - params); -} diff --git a/src/backenddb/insert_otp_device.c b/src/backenddb/insert_otp_device.c @@ -0,0 +1,68 @@ +/* + 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/insert_otp_device.c + * @brief Implementation of the insert_otp_device function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/insert_otp_device.h" +#include "helper.h" + + +/** + * Insert details about a particular OTP device. + * + * @param pg database context + * @param instance_id instance to insert OTP device for + * @param otp_id otp identifier of OTP device to insert + * @param td the OTP device details to insert + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_insert_otp_device ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *otp_id, + const struct TALER_MERCHANTDB_OtpDeviceDetails *td) +{ + uint32_t pos32 = (uint32_t) td->otp_algorithm; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (otp_id), + GNUNET_PQ_query_param_string (td->otp_description), + GNUNET_PQ_query_param_string (td->otp_key), + GNUNET_PQ_query_param_uint32 (&pos32), + GNUNET_PQ_query_param_uint64 (&td->otp_ctr), + GNUNET_PQ_query_param_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (instance_id, + pg->current_merchant_id)); + TMH_PQ_prepare_anon (pg, + "INSERT INTO merchant_otp_devices" + "(otp_id" + ",otp_description" + ",otp_key" + ",otp_algorithm" + ",otp_ctr" + ")" + " VALUES ($1, $2, $3, $4, $5)"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "", + params); +} diff --git a/src/backenddb/insert_spent_token.c b/src/backenddb/insert_spent_token.c @@ -1,85 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2024 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/insert_spent_token.c - * @brief Implementation of the insert_spent_token function for Postgres - * @author Christian Blättler - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/insert_spent_token.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_insert_spent_token ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const struct TALER_PrivateContractHashP *h_contract_terms, - const struct TALER_TokenIssuePublicKeyHashP *h_issue_pub, - const struct TALER_TokenUsePublicKeyP *use_pub, - const struct TALER_TokenUseSignatureP *use_sig, - const struct TALER_TokenIssueSignature *issue_sig) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (h_contract_terms), - GNUNET_PQ_query_param_auto_from_type (h_issue_pub), - GNUNET_PQ_query_param_auto_from_type (use_pub), - GNUNET_PQ_query_param_auto_from_type (use_sig), - GNUNET_PQ_query_param_unblinded_sig (issue_sig->signature), - GNUNET_PQ_query_param_end - }; - bool no_fam; - bool conflict; /* used to signal double-spending */ - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_bool ("out_no_family", - &no_fam), - GNUNET_PQ_result_spec_bool ("out_conflict", - &conflict), - GNUNET_PQ_result_spec_end - }; - enum GNUNET_DB_QueryStatus qs; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Storing token spent with key %s\n", - GNUNET_h2s (&h_issue_pub->hash)); - TMH_PQ_prepare_anon (pg, - "SELECT" - " out_no_family" - " ,out_conflict" - " FROM merchant_do_insert_spent_token" - "($1, $2, $3, $4, $5);"); - qs = GNUNET_PQ_eval_prepared_singleton_select ( - pg->conn, - "", - params, - rs); - if (qs < 0) - return qs; - // FIXME: return specific errors to caller - if (no_fam) - { - GNUNET_break (0); - return GNUNET_DB_STATUS_HARD_ERROR; - } - if (conflict) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Client attempted to double-spend token\n"); - return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; - } - return qs; -} diff --git a/src/backenddb/insert_used_token.c b/src/backenddb/insert_used_token.c @@ -0,0 +1,85 @@ +/* + This file is part of TALER + Copyright (C) 2024 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/insert_used_token.c + * @brief Implementation of the insert_used_token function for Postgres + * @author Christian Blättler + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/insert_used_token.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_insert_used_token ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const struct TALER_PrivateContractHashP *h_contract_terms, + const struct TALER_TokenIssuePublicKeyHashP *h_issue_pub, + const struct TALER_TokenUsePublicKeyP *use_pub, + const struct TALER_TokenUseSignatureP *use_sig, + const struct TALER_TokenIssueSignature *issue_sig) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (h_contract_terms), + GNUNET_PQ_query_param_auto_from_type (h_issue_pub), + GNUNET_PQ_query_param_auto_from_type (use_pub), + GNUNET_PQ_query_param_auto_from_type (use_sig), + GNUNET_PQ_query_param_unblinded_sig (issue_sig->signature), + GNUNET_PQ_query_param_end + }; + bool no_fam; + bool conflict; /* used to signal double-spending */ + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_bool ("out_no_family", + &no_fam), + GNUNET_PQ_result_spec_bool ("out_conflict", + &conflict), + GNUNET_PQ_result_spec_end + }; + enum GNUNET_DB_QueryStatus qs; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Storing token spent with key %s\n", + GNUNET_h2s (&h_issue_pub->hash)); + TMH_PQ_prepare_anon (pg, + "SELECT" + " out_no_family" + " ,out_conflict" + " FROM merchant_do_insert_spent_token" + "($1, $2, $3, $4, $5);"); + qs = GNUNET_PQ_eval_prepared_singleton_select ( + pg->conn, + "", + params, + rs); + if (qs < 0) + return qs; + // FIXME: return specific errors to caller + if (no_fam) + { + GNUNET_break (0); + return GNUNET_DB_STATUS_HARD_ERROR; + } + if (conflict) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Client attempted to double-spend token\n"); + return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; + } + return qs; +} diff --git a/src/backenddb/insert_spent_token.sql b/src/backenddb/insert_used_token.sql diff --git a/src/backenddb/insert_wire_fee.c b/src/backenddb/insert_wire_fee.c @@ -1,72 +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/insert_wire_fee.c - * @brief Implementation of the insert_wire_fee function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/insert_wire_fee.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_insert_wire_fee ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const struct TALER_MasterPublicKeyP *master_pub, - const struct GNUNET_HashCode *h_wire_method, - const struct TALER_WireFeeSet *fees, - struct GNUNET_TIME_Timestamp start_date, - struct GNUNET_TIME_Timestamp end_date, - const struct TALER_MasterSignatureP *master_sig) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (master_pub), - GNUNET_PQ_query_param_auto_from_type (h_wire_method), - TALER_PQ_query_param_amount_with_currency (pg->conn, - &fees->wire), - TALER_PQ_query_param_amount_with_currency (pg->conn, - &fees->closing), - GNUNET_PQ_query_param_timestamp (&start_date), - GNUNET_PQ_query_param_timestamp (&end_date), - GNUNET_PQ_query_param_auto_from_type (master_sig), - GNUNET_PQ_query_param_end - }; - - /* no preflight check here, run in its own transaction by the caller */ - PREPARE (pg, - "insert_wire_fee", - "INSERT INTO merchant.merchant_exchange_wire_fees" - "(master_pub" - ",h_wire_method" - ",wire_fee" - ",closing_fee" - ",start_date" - ",end_date" - ",master_sig)" - " VALUES " - "($1, $2, $3, $4, $5, $6, $7)" - " ON CONFLICT DO NOTHING"); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Storing wire fee for %s starting at %s of %s\n", - TALER_B2S (master_pub), - GNUNET_TIME_timestamp2s (start_date), - TALER_amount2s (&fees->wire)); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_wire_fee", - params); -} diff --git a/src/backenddb/iterate_accounts_by_exchange.c b/src/backenddb/iterate_accounts_by_exchange.c @@ -1,142 +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/iterate_accounts_by_exchange.c - * @brief Implementation of the iterate_accounts_by_exchange function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/iterate_accounts_by_exchange.h" -#include "helper.h" - - -/** - * Closure for #parse_accounts. - */ -struct SelectAccountContext -{ - /** - * Function to call on each result. - */ - TALER_MERCHANTDB_ExchangeAccountCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; - - /** - * Set to true on failure. - */ - bool failed; -}; - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results about accounts. - * - * @param cls of type `struct SelectAccountContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -parse_accounts (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct SelectAccountContext *ctx = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - struct TALER_FullPayto payto_uri; - char *conversion_url = NULL; - json_t *debit_restrictions; - json_t *credit_restrictions; - struct TALER_MasterSignatureP master_sig; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("master_sig", - &master_sig), - GNUNET_PQ_result_spec_string ("payto_uri", - &payto_uri.full_payto), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("conversion_url", - &conversion_url), - NULL), - TALER_PQ_result_spec_json ("debit_restrictions", - &debit_restrictions), - TALER_PQ_result_spec_json ("credit_restrictions", - &credit_restrictions), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - ctx->failed = true; - return; - } - ctx->cb (ctx->cb_cls, - payto_uri, - conversion_url, - debit_restrictions, - credit_restrictions, - &master_sig); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_accounts_by_exchange ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const struct TALER_MasterPublicKeyP *master_pub, - TALER_MERCHANTDB_ExchangeAccountCallback cb, - void *cb_cls) -{ - struct SelectAccountContext ctx = { - .cb = cb, - .cb_cls = cb_cls - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (master_pub), - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "select_exchange_accounts", - "SELECT" - " payto_uri" - ",conversion_url" - ",debit_restrictions::TEXT" - ",credit_restrictions::TEXT" - ",master_sig" - " FROM merchant_exchange_accounts" - " WHERE master_pub=$1;"); - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "select_exchange_accounts", - params, - &parse_accounts, - &ctx); - if (ctx.failed) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/backenddb/iterate_all_webhooks.c b/src/backenddb/iterate_all_webhooks.c @@ -1,165 +0,0 @@ -/* - 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/backenddb/iterate_all_webhooks.c - * @brief Implementation of the iterate_all_webhooks function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/iterate_all_webhooks.h" -#include "helper.h" - -/** - * Context used for lookup_all_webhooks_cb(). - */ -struct LookupAllWebhookContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_AllWebhooksCallback cb; - - /** - * Closure for @a cb. - */ - void *cb_cls; - - /** - * Did database result extraction fail? - */ - bool extract_failed; -}; - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results about webhook. - * - * @param[in,out] cls of type `struct LookupAllWebhookContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_all_webhooks_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupAllWebhookContext *pwlc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - uint64_t webhook_pending_serial; - struct GNUNET_TIME_Absolute next_attempt; - uint32_t retries; - char *url; - char *http_method; - char *header = NULL; - char *body = NULL; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("out_webhook_pending_serial", - &webhook_pending_serial), - GNUNET_PQ_result_spec_absolute_time ("out_next_attempt", - &next_attempt), - GNUNET_PQ_result_spec_uint32 ("out_retries", - &retries), - GNUNET_PQ_result_spec_string ("out_url", - &url), - GNUNET_PQ_result_spec_string ("out_http_method", - &http_method), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("out_header", - &header), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("out_body", - &body), - NULL), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - pwlc->extract_failed = true; - return; - } - pwlc->cb (pwlc->cb_cls, - webhook_pending_serial, - next_attempt, - retries, - url, - http_method, - header, - body); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_all_webhooks ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t min_row, - uint32_t max_results, - TALER_MERCHANTDB_AllWebhooksCallback cb, - void *cb_cls) -{ - struct LookupAllWebhookContext pwlc = { - .cb = cb, - .cb_cls = cb_cls, - .extract_failed = false, - }; - uint64_t max_results64 = max_results; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&pg->current_merchant_serial), - GNUNET_PQ_query_param_uint64 (&min_row), - GNUNET_PQ_query_param_uint64 (&max_results64), - 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)); - PREPARE (pg, - "lookup_all_webhooks", - " SELECT" - " webhook_pending_serial AS out_webhook_pending_serial" - " ,next_attempt AS out_next_attempt" - " ,retries AS out_retries" - " ,url AS out_url" - " ,http_method AS out_http_method" - " ,header AS out_header" - " ,body AS out_body" - " FROM merchant.merchant_pending_webhooks" - " WHERE merchant_serial = $1" - " AND webhook_pending_serial > $2" - " ORDER BY webhook_pending_serial ASC" - " LIMIT $3"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "lookup_all_webhooks", - params, - &lookup_all_webhooks_cb, - &pwlc); - if (pwlc.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/backenddb/iterate_exchange_accounts.c b/src/backenddb/iterate_exchange_accounts.c @@ -0,0 +1,142 @@ +/* + 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/iterate_exchange_accounts.c + * @brief Implementation of the iterate_exchange_accounts function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_exchange_accounts.h" +#include "helper.h" + + +/** + * Closure for #parse_accounts. + */ +struct SelectAccountContext +{ + /** + * Function to call on each result. + */ + TALER_MERCHANTDB_ExchangeAccountCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Set to true on failure. + */ + bool failed; +}; + +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results about accounts. + * + * @param cls of type `struct SelectAccountContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +parse_accounts (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct SelectAccountContext *ctx = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + struct TALER_FullPayto payto_uri; + char *conversion_url = NULL; + json_t *debit_restrictions; + json_t *credit_restrictions; + struct TALER_MasterSignatureP master_sig; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("master_sig", + &master_sig), + GNUNET_PQ_result_spec_string ("payto_uri", + &payto_uri.full_payto), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("conversion_url", + &conversion_url), + NULL), + TALER_PQ_result_spec_json ("debit_restrictions", + &debit_restrictions), + TALER_PQ_result_spec_json ("credit_restrictions", + &credit_restrictions), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ctx->failed = true; + return; + } + ctx->cb (ctx->cb_cls, + payto_uri, + conversion_url, + debit_restrictions, + credit_restrictions, + &master_sig); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_exchange_accounts ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const struct TALER_MasterPublicKeyP *master_pub, + TALER_MERCHANTDB_ExchangeAccountCallback cb, + void *cb_cls) +{ + struct SelectAccountContext ctx = { + .cb = cb, + .cb_cls = cb_cls + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (master_pub), + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (pg, + "select_exchange_accounts", + "SELECT" + " payto_uri" + ",conversion_url" + ",debit_restrictions::TEXT" + ",credit_restrictions::TEXT" + ",master_sig" + " FROM merchant_exchange_accounts" + " WHERE master_pub=$1;"); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "select_exchange_accounts", + params, + &parse_accounts, + &ctx); + if (ctx.failed) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/backenddb/iterate_open_expected_transfers.c b/src/backenddb/iterate_open_expected_transfers.c @@ -0,0 +1,151 @@ +/* + This file is part of TALER + Copyright (C) 2022, 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/iterate_open_expected_transfers.c + * @brief Implementation of the iterate_open_expected_transfers function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_open_expected_transfers.h" +#include "helper.h" + + +/** + * Context used for open_transfers_cb(). + */ +struct SelectOpenTransfersContext +{ + /** + * Postgres context. + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_OpenTransferCallback cb; + + /** + * Closure for @a cb. + */ + void *cb_cls; + + /** + * Internal result. + */ + enum GNUNET_DB_QueryStatus qs; +}; + + +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results about rewards. + * + * @param[in,out] cls of type `struct SelectOpenTransfersContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +open_transfers_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct SelectOpenTransfersContext *plc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + uint64_t rowid; + char *instance_id; + char *exchange_url; + struct TALER_FullPayto payto_uri; + struct TALER_WireTransferIdentifierRawP wtid; + struct GNUNET_TIME_Absolute retry_time; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("out_expected_credit_serial", + &rowid), + GNUNET_PQ_result_spec_string ("out_instance_id", + &instance_id), + GNUNET_PQ_result_spec_string ("out_exchange_url", + &exchange_url), + GNUNET_PQ_result_spec_string ("out_payto_uri", + &payto_uri.full_payto), + GNUNET_PQ_result_spec_auto_from_type ("out_wtid", + &wtid), + GNUNET_PQ_result_spec_absolute_time ("out_retry_time", + &retry_time), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + plc->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + plc->cb (plc->cb_cls, + rowid, + instance_id, + exchange_url, + payto_uri, + &wtid, + retry_time); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_open_expected_transfers ( + struct TALER_MERCHANTDB_PostgresContext *pg, + uint64_t limit, + TALER_MERCHANTDB_OpenTransferCallback cb, + void *cb_cls) +{ + struct SelectOpenTransfersContext plc = { + .pg = pg, + .cb = cb, + .cb_cls = cb_cls + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&limit), + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (pg, + "select_open_transfers", + "SELECT" + " out_expected_credit_serial" + " ,out_instance_id" + " ,out_exchange_url" + " ,out_payto_uri" + " ,out_wtid" + " ,out_retry_time" + " FROM merchant.select_open_transfers($1)"); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "select_open_transfers", + params, + &open_transfers_cb, + &plc); + if (0 != plc.qs) + return plc.qs; + return qs; +} diff --git a/src/backenddb/iterate_open_transfers.sql b/src/backenddb/iterate_open_expected_transfers.sql diff --git a/src/backenddb/iterate_open_transfers.c b/src/backenddb/iterate_open_transfers.c @@ -1,151 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022, 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/iterate_open_transfers.c - * @brief Implementation of the iterate_open_transfers function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/iterate_open_transfers.h" -#include "helper.h" - - -/** - * Context used for open_transfers_cb(). - */ -struct SelectOpenTransfersContext -{ - /** - * Postgres context. - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_OpenTransferCallback cb; - - /** - * Closure for @a cb. - */ - void *cb_cls; - - /** - * Internal result. - */ - enum GNUNET_DB_QueryStatus qs; -}; - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results about rewards. - * - * @param[in,out] cls of type `struct SelectOpenTransfersContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -open_transfers_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct SelectOpenTransfersContext *plc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - uint64_t rowid; - char *instance_id; - char *exchange_url; - struct TALER_FullPayto payto_uri; - struct TALER_WireTransferIdentifierRawP wtid; - struct GNUNET_TIME_Absolute retry_time; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("out_expected_credit_serial", - &rowid), - GNUNET_PQ_result_spec_string ("out_instance_id", - &instance_id), - GNUNET_PQ_result_spec_string ("out_exchange_url", - &exchange_url), - GNUNET_PQ_result_spec_string ("out_payto_uri", - &payto_uri.full_payto), - GNUNET_PQ_result_spec_auto_from_type ("out_wtid", - &wtid), - GNUNET_PQ_result_spec_absolute_time ("out_retry_time", - &retry_time), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - plc->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - plc->cb (plc->cb_cls, - rowid, - instance_id, - exchange_url, - payto_uri, - &wtid, - retry_time); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_open_transfers ( - struct TALER_MERCHANTDB_PostgresContext *pg, - uint64_t limit, - TALER_MERCHANTDB_OpenTransferCallback cb, - void *cb_cls) -{ - struct SelectOpenTransfersContext plc = { - .pg = pg, - .cb = cb, - .cb_cls = cb_cls - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&limit), - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "select_open_transfers", - "SELECT" - " out_expected_credit_serial" - " ,out_instance_id" - " ,out_exchange_url" - " ,out_payto_uri" - " ,out_wtid" - " ,out_retry_time" - " FROM merchant.select_open_transfers($1)"); - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "select_open_transfers", - params, - &open_transfers_cb, - &plc); - if (0 != plc.qs) - return plc.qs; - return qs; -} diff --git a/src/backenddb/iterate_order_blinded_sigs.c b/src/backenddb/iterate_order_blinded_sigs.c @@ -1,127 +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/iterate_order_blinded_sigs.c - * @brief Implementation of the select blinded sigs by order_id function for Postgres - * @author Bohdan Potuzhnyi - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/iterate_order_blinded_sigs.h" -#include "helper.h" - -/** - * @brief Context for the callback to handle the result of the blinded sigs selection. - */ -struct SelectBlindedSigsContext -{ - /** - * @brief Callback to be called with the result of the blinded sigs selection. - */ - void *cb_cls; - - /** - * @brief Callback to be called with the result of the blinded sigs selection. - */ - TALER_MERCHANTDB_BlindedSigCallback cb; - - /** - * @brief Result status of the query. - */ - enum GNUNET_DB_QueryStatus qs; -}; - - -/** - * @brief Callback to handle the result of the blinded sigs selection. - * - * @param cls the closure containing the callback and its context - * @param result the result of the query - * @param num_results number of results in the result set - */ -static void -restore_sig_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct SelectBlindedSigsContext *ctx = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - struct GNUNET_HashCode h_issue; - struct GNUNET_CRYPTO_BlindedSignature *sig; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("token_hash", - &h_issue), - GNUNET_PQ_result_spec_blinded_sig ("token_blinded_signature", - &sig), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - ctx->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - ctx->cb (ctx->cb_cls, - &h_issue, - sig); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_order_blinded_sigs ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *order_id, - TALER_MERCHANTDB_BlindedSigCallback cb, - void *cb_cls) -{ - struct SelectBlindedSigsContext ctx = { - .cb = cb, - .cb_cls = cb_cls, - .qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (order_id), - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - GNUNET_assert (NULL != pg->current_merchant_id); - TMH_PQ_prepare_anon (pg, - "SELECT" - " motbs.token_blinded_signature" - " ,motbs.token_hash" - " FROM merchant_order_token_blinded_sigs AS motbs" - " JOIN merchant_contract_terms AS mct USING (order_serial)" - " WHERE mct.order_id = $1" - " ORDER BY motbs.token_index ASC"); - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &restore_sig_cb, - &ctx); - /* propagate an extraction failure recorded by the row callback */ - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != ctx.qs) - return ctx.qs; - return qs; -} diff --git a/src/backenddb/iterate_order_token_blinded_sigs.c b/src/backenddb/iterate_order_token_blinded_sigs.c @@ -0,0 +1,127 @@ +/* + 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/iterate_order_token_blinded_sigs.c + * @brief Implementation of the select blinded sigs by order_id function for Postgres + * @author Bohdan Potuzhnyi + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_order_token_blinded_sigs.h" +#include "helper.h" + +/** + * @brief Context for the callback to handle the result of the blinded sigs selection. + */ +struct SelectBlindedSigsContext +{ + /** + * @brief Callback to be called with the result of the blinded sigs selection. + */ + void *cb_cls; + + /** + * @brief Callback to be called with the result of the blinded sigs selection. + */ + TALER_MERCHANTDB_BlindedSigCallback cb; + + /** + * @brief Result status of the query. + */ + enum GNUNET_DB_QueryStatus qs; +}; + + +/** + * @brief Callback to handle the result of the blinded sigs selection. + * + * @param cls the closure containing the callback and its context + * @param result the result of the query + * @param num_results number of results in the result set + */ +static void +restore_sig_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct SelectBlindedSigsContext *ctx = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + struct GNUNET_HashCode h_issue; + struct GNUNET_CRYPTO_BlindedSignature *sig; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("token_hash", + &h_issue), + GNUNET_PQ_result_spec_blinded_sig ("token_blinded_signature", + &sig), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + ctx->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + ctx->cb (ctx->cb_cls, + &h_issue, + sig); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_order_token_blinded_sigs ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *order_id, + TALER_MERCHANTDB_BlindedSigCallback cb, + void *cb_cls) +{ + struct SelectBlindedSigsContext ctx = { + .cb = cb, + .cb_cls = cb_cls, + .qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (order_id), + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + GNUNET_assert (NULL != pg->current_merchant_id); + TMH_PQ_prepare_anon (pg, + "SELECT" + " motbs.token_blinded_signature" + " ,motbs.token_hash" + " FROM merchant_order_token_blinded_sigs AS motbs" + " JOIN merchant_contract_terms AS mct USING (order_serial)" + " WHERE mct.order_id = $1" + " ORDER BY motbs.token_index ASC"); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &restore_sig_cb, + &ctx); + /* propagate an extraction failure recorded by the row callback */ + if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != ctx.qs) + return ctx.qs; + return qs; +} diff --git a/src/backenddb/iterate_pending_reports.c b/src/backenddb/iterate_pending_reports.c @@ -0,0 +1,174 @@ +/* + 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/iterate_pending_reports.c + * @brief Implementation of the iterate_pending_reports function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_pending_reports.h" +#include "helper.h" + + +/** + * Context used for TALER_MERCHANTDB_iterate_pending_reports(). + */ +struct SelectReportsContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_ReportsPendingCallback cb; + + /** + * Closure for @a cb. + */ + void *cb_cls; + + /** + * Did database result extraction fail? + */ + bool extract_failed; +}; + + +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results about reports. + * + * @param[in,out] cls of type `struct SelectReportsContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +select_pending_reports_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct SelectReportsContext *plc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + char *instance_id; + uint64_t report_serial; + char *report_program_section; + char *report_description; + char *mime_type; + struct TALER_MERCHANT_ReportToken report_token; + char *target_address; + struct GNUNET_TIME_Relative frequency; + struct GNUNET_TIME_Relative frequency_shift; + struct GNUNET_TIME_Absolute next_transmission; + bool one_shot; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("out_merchant_id", + &instance_id), + GNUNET_PQ_result_spec_uint64 ("out_report_serial", + &report_serial), + GNUNET_PQ_result_spec_string ("out_report_program_section", + &report_program_section), + GNUNET_PQ_result_spec_string ("out_report_description", + &report_description), + GNUNET_PQ_result_spec_string ("out_mime_type", + &mime_type), + GNUNET_PQ_result_spec_auto_from_type ("out_report_token", + &report_token), + GNUNET_PQ_result_spec_string ("out_target_address", + &target_address), + GNUNET_PQ_result_spec_relative_time ("out_frequency", + &frequency), + GNUNET_PQ_result_spec_relative_time ("out_frequency_shift", + &frequency_shift), + GNUNET_PQ_result_spec_absolute_time ("out_next_transmission", + &next_transmission), + GNUNET_PQ_result_spec_bool ("out_one_shot_hidden", + &one_shot), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + plc->extract_failed = true; + return; + } + plc->cb (plc->cb_cls, + instance_id, + report_serial, + report_program_section, + report_description, + mime_type, + &report_token, + target_address, + frequency, + frequency_shift, + next_transmission, + one_shot); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_pending_reports ( + struct TALER_MERCHANTDB_PostgresContext *pg, + TALER_MERCHANTDB_ReportsPendingCallback cb, + void *cb_cls) +{ + struct SelectReportsContext plc = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the lookup_reports_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (pg, + "lookup_reports_pending", + "SELECT" + " out_merchant_id" + " ,out_report_serial" + " ,out_report_program_section" + " ,out_report_description" + " ,out_mime_type" + " ,out_report_token" + " ,out_target_address" + " ,out_frequency" + " ,out_frequency_shift" + " ,out_next_transmission" + " ,out_one_shot_hidden" + " FROM merchant.lookup_reports_pending()"); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "lookup_reports_pending", + params, + &select_pending_reports_cb, + &plc); + /* If there was an error inside select_pending_reports_cb, return a hard error. */ + if (plc.extract_failed) + { + GNUNET_break (0); + return GNUNET_DB_STATUS_HARD_ERROR; + } + return qs; +} diff --git a/src/backenddb/iterate_reports_pending.sql b/src/backenddb/iterate_pending_reports.sql diff --git a/src/backenddb/iterate_pending_webhooks_above_serial_id.c b/src/backenddb/iterate_pending_webhooks_above_serial_id.c @@ -0,0 +1,165 @@ +/* + 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/backenddb/iterate_pending_webhooks_above_serial_id.c + * @brief Implementation of the iterate_pending_webhooks_above_serial_id function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_pending_webhooks_above_serial_id.h" +#include "helper.h" + +/** + * Context used for lookup_all_webhooks_cb(). + */ +struct LookupAllWebhookContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_AllWebhooksCallback cb; + + /** + * Closure for @a cb. + */ + void *cb_cls; + + /** + * Did database result extraction fail? + */ + bool extract_failed; +}; + + +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results about webhook. + * + * @param[in,out] cls of type `struct LookupAllWebhookContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_all_webhooks_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupAllWebhookContext *pwlc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + uint64_t webhook_pending_serial; + struct GNUNET_TIME_Absolute next_attempt; + uint32_t retries; + char *url; + char *http_method; + char *header = NULL; + char *body = NULL; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("out_webhook_pending_serial", + &webhook_pending_serial), + GNUNET_PQ_result_spec_absolute_time ("out_next_attempt", + &next_attempt), + GNUNET_PQ_result_spec_uint32 ("out_retries", + &retries), + GNUNET_PQ_result_spec_string ("out_url", + &url), + GNUNET_PQ_result_spec_string ("out_http_method", + &http_method), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("out_header", + &header), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("out_body", + &body), + NULL), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + pwlc->extract_failed = true; + return; + } + pwlc->cb (pwlc->cb_cls, + webhook_pending_serial, + next_attempt, + retries, + url, + http_method, + header, + body); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_pending_webhooks_above_serial_id ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + uint64_t min_row, + uint32_t max_results, + TALER_MERCHANTDB_AllWebhooksCallback cb, + void *cb_cls) +{ + struct LookupAllWebhookContext pwlc = { + .cb = cb, + .cb_cls = cb_cls, + .extract_failed = false, + }; + uint64_t max_results64 = max_results; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&pg->current_merchant_serial), + GNUNET_PQ_query_param_uint64 (&min_row), + GNUNET_PQ_query_param_uint64 (&max_results64), + 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)); + PREPARE (pg, + "lookup_all_webhooks", + " SELECT" + " webhook_pending_serial AS out_webhook_pending_serial" + " ,next_attempt AS out_next_attempt" + " ,retries AS out_retries" + " ,url AS out_url" + " ,http_method AS out_http_method" + " ,header AS out_header" + " ,body AS out_body" + " FROM merchant.merchant_pending_webhooks" + " WHERE merchant_serial = $1" + " AND webhook_pending_serial > $2" + " ORDER BY webhook_pending_serial ASC" + " LIMIT $3"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "lookup_all_webhooks", + params, + &lookup_all_webhooks_cb, + &pwlc); + if (pwlc.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/backenddb/iterate_reports_pending.c b/src/backenddb/iterate_reports_pending.c @@ -1,174 +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/iterate_reports_pending.c - * @brief Implementation of the iterate_reports_pending function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/iterate_reports_pending.h" -#include "helper.h" - - -/** - * Context used for TALER_MERCHANTDB_iterate_reports_pending(). - */ -struct SelectReportsContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_ReportsPendingCallback cb; - - /** - * Closure for @a cb. - */ - void *cb_cls; - - /** - * Did database result extraction fail? - */ - bool extract_failed; -}; - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results about reports. - * - * @param[in,out] cls of type `struct SelectReportsContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -select_pending_reports_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct SelectReportsContext *plc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - char *instance_id; - uint64_t report_serial; - char *report_program_section; - char *report_description; - char *mime_type; - struct TALER_MERCHANT_ReportToken report_token; - char *target_address; - struct GNUNET_TIME_Relative frequency; - struct GNUNET_TIME_Relative frequency_shift; - struct GNUNET_TIME_Absolute next_transmission; - bool one_shot; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("out_merchant_id", - &instance_id), - GNUNET_PQ_result_spec_uint64 ("out_report_serial", - &report_serial), - GNUNET_PQ_result_spec_string ("out_report_program_section", - &report_program_section), - GNUNET_PQ_result_spec_string ("out_report_description", - &report_description), - GNUNET_PQ_result_spec_string ("out_mime_type", - &mime_type), - GNUNET_PQ_result_spec_auto_from_type ("out_report_token", - &report_token), - GNUNET_PQ_result_spec_string ("out_target_address", - &target_address), - GNUNET_PQ_result_spec_relative_time ("out_frequency", - &frequency), - GNUNET_PQ_result_spec_relative_time ("out_frequency_shift", - &frequency_shift), - GNUNET_PQ_result_spec_absolute_time ("out_next_transmission", - &next_transmission), - GNUNET_PQ_result_spec_bool ("out_one_shot_hidden", - &one_shot), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - plc->extract_failed = true; - return; - } - plc->cb (plc->cb_cls, - instance_id, - report_serial, - report_program_section, - report_description, - mime_type, - &report_token, - target_address, - frequency, - frequency_shift, - next_transmission, - one_shot); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_reports_pending ( - struct TALER_MERCHANTDB_PostgresContext *pg, - TALER_MERCHANTDB_ReportsPendingCallback cb, - void *cb_cls) -{ - struct SelectReportsContext plc = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the lookup_reports_cb */ - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "lookup_reports_pending", - "SELECT" - " out_merchant_id" - " ,out_report_serial" - " ,out_report_program_section" - " ,out_report_description" - " ,out_mime_type" - " ,out_report_token" - " ,out_target_address" - " ,out_frequency" - " ,out_frequency_shift" - " ,out_next_transmission" - " ,out_one_shot_hidden" - " FROM merchant.lookup_reports_pending()"); - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "lookup_reports_pending", - params, - &select_pending_reports_cb, - &plc); - /* If there was an error inside select_pending_reports_cb, return a hard error. */ - if (plc.extract_failed) - { - GNUNET_break (0); - return GNUNET_DB_STATUS_HARD_ERROR; - } - return qs; -} diff --git a/src/backenddb/iterate_spent_tokens_by_order.c b/src/backenddb/iterate_spent_tokens_by_order.c @@ -1,158 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2024 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/iterate_spent_tokens_by_order.c - * @brief Implementation of the iterate_spent_tokens_by_order function for Postgres - * @author Christian Blättler - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/iterate_spent_tokens_by_order.h" -#include "helper.h" -#include "merchantdb_lib.h" - -/** - * Closure for lookup_spent_tokens_by_order_cb(). - */ -struct LookupSpentTokensByOrderContext -{ - - /** - * Plugin context. - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - - /** - * Function to call with all results. - */ - TALER_MERCHANTDB_UsedTokensCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; - - /** - * Set to the query result. - */ - enum GNUNET_DB_QueryStatus qs; -}; - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls of type `struct LookupSpentTokensByOrderContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_spent_tokens_by_order_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupSpentTokensByOrderContext *ctx = cls; - - for (unsigned int i = 0; i<num_results; i++) - { - uint64_t spent_token_serial; - struct TALER_PrivateContractHashP h_contract_terms; - struct TALER_TokenIssuePublicKeyHashP h_issue_pub; - struct TALER_TokenUsePublicKeyP use_pub; - struct TALER_TokenUseSignatureP use_sig; - struct TALER_TokenIssueSignature issue_sig; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("spent_token_serial", - &spent_token_serial), - GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", - &h_contract_terms), - GNUNET_PQ_result_spec_auto_from_type ("h_pub", - &h_issue_pub), - GNUNET_PQ_result_spec_auto_from_type ("token_pub", - &use_pub), - GNUNET_PQ_result_spec_auto_from_type ("token_sig", - &use_sig), - GNUNET_PQ_result_spec_unblinded_sig ("blind_sig", - &issue_sig.signature), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - ctx->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - ctx->cb (ctx->cb_cls, - spent_token_serial, - &h_contract_terms, - &h_issue_pub, - &use_pub, - &use_sig, - &issue_sig); - GNUNET_PQ_cleanup_result (rs); - } - ctx->qs = num_results; -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_spent_tokens_by_order ( - struct TALER_MERCHANTDB_PostgresContext *pg, - uint64_t order_serial, - TALER_MERCHANTDB_UsedTokensCallback cb, - void *cb_cls) -{ - struct LookupSpentTokensByOrderContext ctx = { - .pg = pg, - .cb = cb, - .cb_cls = cb_cls - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&order_serial), - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - GNUNET_assert (NULL != pg->current_merchant_id); - TMH_PQ_prepare_anon (pg, - "SELECT" - " spent_token_serial" - ",h_contract_terms" - ",h_pub" - ",token_pub" - ",token_sig" - ",blind_sig" - " FROM merchant_used_tokens" - " JOIN merchant_contract_terms" - " USING (h_contract_terms)" - " JOIN merchant_token_family_keys" - " USING (token_family_key_serial)" - " WHERE order_serial=$1"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "", - params, - &lookup_spent_tokens_by_order_cb, - &ctx); - - if (qs < 0) - return qs; - return ctx.qs; -} diff --git a/src/backenddb/iterate_statistic_bucket_amounts.c b/src/backenddb/iterate_statistic_bucket_amounts.c @@ -0,0 +1,221 @@ +/* + 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/iterate_statistic_bucket_amounts.c + * @brief Implementation of the iterate_statistic_bucket_amounts function for Postgres + * @author Martin Schanzenbach + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_statistic_bucket_amounts.h" +#include "helper.h" +#include "merchantdb_lib.h" + + +/** + * Context used for TALER_MERCHANTDB_iterate_statistic_bucket_amounts(). + */ +struct LookupAmountStatisticsContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_AmountByBucketStatisticsCallback 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 LookupAmountStatisticsContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_statistics_amount_by_bucket_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupAmountStatisticsContext *tflc = cls; + struct TALER_Amount *amounts = NULL; + char *resp_range = NULL; + char *resp_desc = NULL; + uint64_t cur_bucket_start_epoch; + uint64_t cur_bucket_end_epoch; + uint64_t bmeta_id_current; + unsigned int amounts_len = 0; + + for (unsigned int i = 0; i < num_results; i++) + { + struct TALER_Amount cumulative_amount; + char *description; + char *bucket_range; + uint64_t bmeta_id; + uint64_t bucket_start_epoch; + uint64_t bucket_end_epoch; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("bmeta_serial_id", + &bmeta_id), + GNUNET_PQ_result_spec_string ("description", + &description), + GNUNET_PQ_result_spec_uint64 ("bucket_start", + &bucket_start_epoch), + GNUNET_PQ_result_spec_uint64 ("bucket_end", + &bucket_end_epoch), + GNUNET_PQ_result_spec_string ("bucket_range", + &bucket_range), + TALER_PQ_result_spec_amount_with_currency ("cumulative_amount", + &cumulative_amount), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + tflc->extract_failed = true; + return; + } + /* Call callback if the bucket changed */ + if ( (NULL != resp_desc) && + ( (bmeta_id != bmeta_id_current) || + (bucket_start_epoch != cur_bucket_start_epoch) || + (0 != strcasecmp (resp_range, + bucket_range)) ) ) + { + struct GNUNET_TIME_Timestamp bucket_start; + struct GNUNET_TIME_Timestamp bucket_end; + + bucket_start = GNUNET_TIME_timestamp_from_s (cur_bucket_start_epoch); + bucket_end = GNUNET_TIME_timestamp_from_s (cur_bucket_end_epoch); + tflc->cb (tflc->cb_cls, + resp_desc, + bucket_start, + bucket_end, + resp_range, + amounts_len, + amounts); + GNUNET_free (resp_range); + GNUNET_free (resp_desc); + GNUNET_array_grow (amounts, + amounts_len, + 0); + } + if (NULL == resp_desc) + { + cur_bucket_end_epoch = bucket_end_epoch; + cur_bucket_start_epoch = bucket_start_epoch; + resp_range = GNUNET_strdup (bucket_range); + resp_desc = GNUNET_strdup (description); + bmeta_id_current = bmeta_id; + } + GNUNET_array_append (amounts, + amounts_len, + cumulative_amount); + GNUNET_PQ_cleanup_result (rs); + } + if (0 != amounts_len) + { + struct GNUNET_TIME_Timestamp bucket_start; + struct GNUNET_TIME_Timestamp bucket_end; + + bucket_start = GNUNET_TIME_timestamp_from_s (cur_bucket_start_epoch); + bucket_end = GNUNET_TIME_timestamp_from_s (cur_bucket_end_epoch); + tflc->cb (tflc->cb_cls, + resp_desc, + bucket_start, + bucket_end, + resp_range, + amounts_len, + amounts); + GNUNET_array_grow (amounts, + amounts_len, + 0); + GNUNET_free (resp_range); + GNUNET_free (resp_desc); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_statistic_bucket_amounts ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *slug, + TALER_MERCHANTDB_AmountByBucketStatisticsCallback cb, + void *cb_cls) +{ + struct LookupAmountStatisticsContext context = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the lookup_statistics_amount_by_bucket_cb */ + .extract_failed = false, + .pg = pg, + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (slug), + 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" + " bmeta_serial_id" + ",description" + ",bucket_start" + ",bucket_range::TEXT" + ",merchant_statistics_bucket_end(bucket_start, bucket_range) AS bucket_end" + ",(cumulative_value,cumulative_frac,curr)::merchant.taler_amount_currency AS cumulative_amount" + " FROM merchant_statistic_bucket_amount" + " JOIN merchant_statistic_bucket_meta" + " USING (bmeta_serial_id)" + " WHERE merchant_statistic_bucket_meta.slug=$1" + " AND merchant_statistic_bucket_meta.stype='amount'"); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &lookup_statistics_amount_by_bucket_cb, + &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/iterate_statistic_bucket_amounts_by_range.c b/src/backenddb/iterate_statistic_bucket_amounts_by_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/iterate_statistic_bucket_amounts_by_range.c + * @brief Implementation of the iterate_statistic_bucket_amounts_by_range function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_statistic_bucket_amounts_by_range.h" +#include "helper.h" + + +/** + * Context used for TALER_MERCHANTDB_iterate_statistic_bucket_amounts_by_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_iterate_statistic_bucket_amounts_by_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/iterate_statistic_bucket_counters.c b/src/backenddb/iterate_statistic_bucket_counters.c @@ -0,0 +1,159 @@ +/* + 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/iterate_statistic_bucket_counters.c + * @brief Implementation of the iterate_statistic_bucket_counters function for Postgres + * @author Martin Schanzenbach + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_statistic_bucket_counters.h" +#include "helper.h" +#include "merchantdb_lib.h" + + +/** + * Context used for TALER_MERCHANTDB_iterate_statistic_bucket_counters(). + */ +struct LookupCounterStatisticsContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_CounterByBucketStatisticsCallback cb; + + /** + * Closure for @a cb. + */ + void *cb_cls; + + /** + * Did database result extraction fail? + */ + bool extract_failed; +}; + + +/** + * 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 LookupCounterStatisticsContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_statistics_counter_by_bucket_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupCounterStatisticsContext *tflc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + char *description; + char *bucket_range; + uint64_t cumulative_number; + uint64_t bucket_start_epoch; + uint64_t bucket_end_epoch; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("description", + &description), + GNUNET_PQ_result_spec_uint64 ("bucket_start", + &bucket_start_epoch), + GNUNET_PQ_result_spec_uint64 ("bucket_end", + &bucket_end_epoch), + GNUNET_PQ_result_spec_string ("bucket_range", + &bucket_range), + GNUNET_PQ_result_spec_uint64 ("cumulative_number", + &cumulative_number), + GNUNET_PQ_result_spec_end + }; + struct GNUNET_TIME_Timestamp bucket_start; + struct GNUNET_TIME_Timestamp bucket_end; + + 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); + bucket_end = GNUNET_TIME_timestamp_from_s (bucket_end_epoch); + tflc->cb (tflc->cb_cls, + description, + bucket_start, + bucket_end, + bucket_range, + cumulative_number); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_statistic_bucket_counters ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *slug, + TALER_MERCHANTDB_CounterByBucketStatisticsCallback cb, + void *cb_cls) +{ + struct LookupCounterStatisticsContext context = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the lookup_statistics_counter_by_bucket_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (slug), + 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" + " description" + ",bucket_start" + ",bucket_range::TEXT" + ",merchant_statistics_bucket_end(bucket_start, bucket_range) AS bucket_end" + ",cumulative_number" + " FROM merchant_statistic_bucket_counter" + " JOIN merchant_statistic_bucket_meta" + " USING (bmeta_serial_id)" + " WHERE merchant_statistic_bucket_meta.slug=$1" + " AND merchant_statistic_bucket_meta.stype = 'number'"); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &lookup_statistics_counter_by_bucket_cb, + &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/iterate_statistic_bucket_counters_by_range.c b/src/backenddb/iterate_statistic_bucket_counters_by_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/iterate_statistic_bucket_counters_by_range.c + * @brief Implementation of the iterate_statistic_bucket_counters_by_range function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_statistic_bucket_counters_by_range.h" +#include "helper.h" + +/** + * Context used for TALER_MERCHANTDB_iterate_statistic_bucket_counters_by_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_iterate_statistic_bucket_counters_by_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/iterate_statistic_interval_amounts.c b/src/backenddb/iterate_statistic_interval_amounts.c @@ -0,0 +1,239 @@ +/* + 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/iterate_statistic_interval_amounts.c + * @brief Implementation of the iterate_statistic_interval_amounts function for Postgres + * @author Martin Schanzenbach + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_statistic_interval_amounts.h" +#include "helper.h" +#include "merchantdb_lib.h" + + +/** + * Context used for TALER_MERCHANTDB_iterate_statistic_interval_amounts(). + */ +struct LookupAmountStatisticsContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_AmountByIntervalStatisticsCallback cb; + + /** + * Closure for @a cb. + */ + void *cb_cls; + + /** + * Did database result extraction fail? + */ + bool extract_failed; + + /** + * Description of statistic + */ + char*description; +}; + +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results about statistics. + * + * @param[in,out] cls of type `struct LookupTokenFamiliesContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_statistics_amount_by_interval_desc_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupAmountStatisticsContext *tflc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + char *description; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("description", + &description), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + tflc->extract_failed = true; + return; + } + + tflc->description = GNUNET_strdup (description); + + GNUNET_PQ_cleanup_result (rs); + } +} + + +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results about statistics. + * + * @param[in,out] cls of type `struct LookupTokenFamiliesContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_statistics_amount_by_interval_cb ( + void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupAmountStatisticsContext *tflc = cls; + struct TALER_Amount *amounts = NULL; + uint64_t cur_interval_start_ago = UINT64_MAX; + unsigned int amounts_len = 0; + + for (unsigned int i = 0; i < num_results; i++) + { + struct TALER_Amount cumulative_amount; + uint64_t interval_start_ago; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("range", + &interval_start_ago), + TALER_PQ_result_spec_amount_with_currency ("rvalue", + &cumulative_amount), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + tflc->extract_failed = true; + return; + } + + /* Call callback if the bucket changed */ + if ( (interval_start_ago != cur_interval_start_ago) && + (i > 0) ) + { + struct GNUNET_TIME_Timestamp interval_start; + + interval_start = GNUNET_TIME_timestamp_get (); + interval_start.abs_time.abs_value_us -= cur_interval_start_ago * 1000 * 1000; + tflc->cb (tflc->cb_cls, + tflc->description, + interval_start, + amounts_len, + amounts); + GNUNET_array_grow (amounts, + amounts_len, + 0); + } + cur_interval_start_ago = interval_start_ago; + GNUNET_array_append (amounts, + amounts_len, + cumulative_amount); + GNUNET_PQ_cleanup_result (rs); + } + if (0 != amounts_len) + { + struct GNUNET_TIME_Timestamp interval_start; + + interval_start = GNUNET_TIME_timestamp_get (); + interval_start.abs_time.abs_value_us -= cur_interval_start_ago * 1000 * 1000; + tflc->cb (tflc->cb_cls, + tflc->description, + interval_start, + amounts_len, + amounts); + GNUNET_array_grow (amounts, + amounts_len, + 0); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_statistic_interval_amounts ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *slug, + TALER_MERCHANTDB_AmountByIntervalStatisticsCallback cb, + void *cb_cls) +{ + struct LookupAmountStatisticsContext context = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the lookup_statistics_amount_by_interval_cb */ + .extract_failed = false, + .description = NULL + }; + struct GNUNET_PQ_QueryParam descParams[] = { + GNUNET_PQ_query_param_string (slug), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (slug), + 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 description" + " FROM merchant_statistic_interval_meta" + " WHERE slug=$1 LIMIT 1"); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + descParams, + &lookup_statistics_amount_by_interval_desc_cb, + &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; + } + TMH_PQ_prepare_anon (pg, + "SELECT *" + " FROM merchant_statistic_interval_amount_get($1)"); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &lookup_statistics_amount_by_interval_cb, + &context); + if (NULL != context.description) + GNUNET_free (context.description); + /* 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/iterate_statistics_amount_by_interval.sql b/src/backenddb/iterate_statistic_interval_amounts.sql diff --git a/src/backenddb/iterate_statistic_interval_counters.c b/src/backenddb/iterate_statistic_interval_counters.c @@ -0,0 +1,210 @@ +/* + 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/iterate_statistic_interval_counters.c + * @brief Implementation of the iterate_statistic_interval_counters function for Postgres + * @author Martin Schanzenbach + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_statistic_interval_counters.h" +#include "helper.h" +#include "merchantdb_lib.h" + + +/** + * Context used for TALER_MERCHANTDB_iterate_statistic_interval_counters(). + */ +struct LookupCounterStatisticsContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_CounterByIntervalStatisticsCallback cb; + + /** + * Closure for @a cb. + */ + void *cb_cls; + + /** + * Did database result extraction fail? + */ + bool extract_failed; + + /** + * Description of statistic + */ + char*description; +}; + +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results about statistics. + * + * @param[in,out] cls of type `struct LookupTokenFamiliesContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_statistics_counter_by_interval_desc_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupCounterStatisticsContext *tflc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + char *description; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("description", + &description), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + tflc->extract_failed = true; + return; + } + + tflc->description = GNUNET_strdup (description); + + GNUNET_PQ_cleanup_result (rs); + } +} + + +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results about statistics. + * + * @param[in,out] cls of type `struct LookupTokenFamiliesContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_statistics_counter_by_interval_cb ( + void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupCounterStatisticsContext *tflc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + uint64_t cumulative_number; + uint64_t interval_start_ago; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("range", + &interval_start_ago), + GNUNET_PQ_result_spec_uint64 ("rvalue", + &cumulative_number), + GNUNET_PQ_result_spec_end + }; + struct GNUNET_TIME_Timestamp interval_start; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + tflc->extract_failed = true; + return; + } + + interval_start = GNUNET_TIME_timestamp_get (); + interval_start.abs_time.abs_value_us -= interval_start_ago * 1000 * 1000; + tflc->cb (tflc->cb_cls, + tflc->description, + interval_start, + cumulative_number); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_statistic_interval_counters ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *slug, + TALER_MERCHANTDB_CounterByIntervalStatisticsCallback cb, + void *cb_cls) +{ + struct LookupCounterStatisticsContext context = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the lookup_statistics_counter_by_interval_cb */ + .extract_failed = false, + .description = NULL + }; + struct GNUNET_PQ_QueryParam descParams[] = { + GNUNET_PQ_query_param_string (slug), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (slug), + 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 description" + " FROM merchant_statistic_interval_meta" + " WHERE slug=$1" + " LIMIT 1"); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + descParams, + &lookup_statistics_counter_by_interval_desc_cb, + &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; + } + TMH_PQ_prepare_anon (pg, + "SELECT" + " range" + " ,rvalue" + " FROM merchant_statistic_interval_number_get($1)"); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &lookup_statistics_counter_by_interval_cb, + &context); + if (NULL != context.description) + GNUNET_free (context.description); + /* 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/iterate_statistics_counter_by_interval.sql b/src/backenddb/iterate_statistic_interval_counters.sql diff --git a/src/backenddb/iterate_statistics_amount_by_bucket.c b/src/backenddb/iterate_statistics_amount_by_bucket.c @@ -1,221 +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/iterate_statistics_amount_by_bucket.c - * @brief Implementation of the iterate_statistics_amount_by_bucket function for Postgres - * @author Martin Schanzenbach - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/iterate_statistics_amount_by_bucket.h" -#include "helper.h" -#include "merchantdb_lib.h" - - -/** - * Context used for TALER_MERCHANTDB_iterate_statistics_amount_by_bucket(). - */ -struct LookupAmountStatisticsContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_AmountByBucketStatisticsCallback 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 LookupAmountStatisticsContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_statistics_amount_by_bucket_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupAmountStatisticsContext *tflc = cls; - struct TALER_Amount *amounts = NULL; - char *resp_range = NULL; - char *resp_desc = NULL; - uint64_t cur_bucket_start_epoch; - uint64_t cur_bucket_end_epoch; - uint64_t bmeta_id_current; - unsigned int amounts_len = 0; - - for (unsigned int i = 0; i < num_results; i++) - { - struct TALER_Amount cumulative_amount; - char *description; - char *bucket_range; - uint64_t bmeta_id; - uint64_t bucket_start_epoch; - uint64_t bucket_end_epoch; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("bmeta_serial_id", - &bmeta_id), - GNUNET_PQ_result_spec_string ("description", - &description), - GNUNET_PQ_result_spec_uint64 ("bucket_start", - &bucket_start_epoch), - GNUNET_PQ_result_spec_uint64 ("bucket_end", - &bucket_end_epoch), - GNUNET_PQ_result_spec_string ("bucket_range", - &bucket_range), - TALER_PQ_result_spec_amount_with_currency ("cumulative_amount", - &cumulative_amount), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - tflc->extract_failed = true; - return; - } - /* Call callback if the bucket changed */ - if ( (NULL != resp_desc) && - ( (bmeta_id != bmeta_id_current) || - (bucket_start_epoch != cur_bucket_start_epoch) || - (0 != strcasecmp (resp_range, - bucket_range)) ) ) - { - struct GNUNET_TIME_Timestamp bucket_start; - struct GNUNET_TIME_Timestamp bucket_end; - - bucket_start = GNUNET_TIME_timestamp_from_s (cur_bucket_start_epoch); - bucket_end = GNUNET_TIME_timestamp_from_s (cur_bucket_end_epoch); - tflc->cb (tflc->cb_cls, - resp_desc, - bucket_start, - bucket_end, - resp_range, - amounts_len, - amounts); - GNUNET_free (resp_range); - GNUNET_free (resp_desc); - GNUNET_array_grow (amounts, - amounts_len, - 0); - } - if (NULL == resp_desc) - { - cur_bucket_end_epoch = bucket_end_epoch; - cur_bucket_start_epoch = bucket_start_epoch; - resp_range = GNUNET_strdup (bucket_range); - resp_desc = GNUNET_strdup (description); - bmeta_id_current = bmeta_id; - } - GNUNET_array_append (amounts, - amounts_len, - cumulative_amount); - GNUNET_PQ_cleanup_result (rs); - } - if (0 != amounts_len) - { - struct GNUNET_TIME_Timestamp bucket_start; - struct GNUNET_TIME_Timestamp bucket_end; - - bucket_start = GNUNET_TIME_timestamp_from_s (cur_bucket_start_epoch); - bucket_end = GNUNET_TIME_timestamp_from_s (cur_bucket_end_epoch); - tflc->cb (tflc->cb_cls, - resp_desc, - bucket_start, - bucket_end, - resp_range, - amounts_len, - amounts); - GNUNET_array_grow (amounts, - amounts_len, - 0); - GNUNET_free (resp_range); - GNUNET_free (resp_desc); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_statistics_amount_by_bucket ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *slug, - TALER_MERCHANTDB_AmountByBucketStatisticsCallback cb, - void *cb_cls) -{ - struct LookupAmountStatisticsContext context = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the lookup_statistics_amount_by_bucket_cb */ - .extract_failed = false, - .pg = pg, - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (slug), - 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" - " bmeta_serial_id" - ",description" - ",bucket_start" - ",bucket_range::TEXT" - ",merchant_statistics_bucket_end(bucket_start, bucket_range) AS bucket_end" - ",(cumulative_value,cumulative_frac,curr)::merchant.taler_amount_currency AS cumulative_amount" - " FROM merchant_statistic_bucket_amount" - " JOIN merchant_statistic_bucket_meta" - " USING (bmeta_serial_id)" - " WHERE merchant_statistic_bucket_meta.slug=$1" - " AND merchant_statistic_bucket_meta.stype='amount'"); - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_statistics_amount_by_bucket_cb, - &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/iterate_statistics_amount_by_bucket_range.c b/src/backenddb/iterate_statistics_amount_by_bucket_range.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/iterate_statistics_amount_by_bucket_range.c - * @brief Implementation of the iterate_statistics_amount_by_bucket_range function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/iterate_statistics_amount_by_bucket_range.h" -#include "helper.h" - - -/** - * Context used for TALER_MERCHANTDB_iterate_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_iterate_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/iterate_statistics_amount_by_interval.c b/src/backenddb/iterate_statistics_amount_by_interval.c @@ -1,239 +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/iterate_statistics_amount_by_interval.c - * @brief Implementation of the iterate_statistics_amount_by_interval function for Postgres - * @author Martin Schanzenbach - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/iterate_statistics_amount_by_interval.h" -#include "helper.h" -#include "merchantdb_lib.h" - - -/** - * Context used for TALER_MERCHANTDB_iterate_statistics_amount_by_interval(). - */ -struct LookupAmountStatisticsContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_AmountByIntervalStatisticsCallback cb; - - /** - * Closure for @a cb. - */ - void *cb_cls; - - /** - * Did database result extraction fail? - */ - bool extract_failed; - - /** - * Description of statistic - */ - char*description; -}; - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results about statistics. - * - * @param[in,out] cls of type `struct LookupTokenFamiliesContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_statistics_amount_by_interval_desc_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupAmountStatisticsContext *tflc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - char *description; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("description", - &description), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - tflc->extract_failed = true; - return; - } - - tflc->description = GNUNET_strdup (description); - - GNUNET_PQ_cleanup_result (rs); - } -} - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results about statistics. - * - * @param[in,out] cls of type `struct LookupTokenFamiliesContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_statistics_amount_by_interval_cb ( - void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupAmountStatisticsContext *tflc = cls; - struct TALER_Amount *amounts = NULL; - uint64_t cur_interval_start_ago = UINT64_MAX; - unsigned int amounts_len = 0; - - for (unsigned int i = 0; i < num_results; i++) - { - struct TALER_Amount cumulative_amount; - uint64_t interval_start_ago; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("range", - &interval_start_ago), - TALER_PQ_result_spec_amount_with_currency ("rvalue", - &cumulative_amount), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - tflc->extract_failed = true; - return; - } - - /* Call callback if the bucket changed */ - if ( (interval_start_ago != cur_interval_start_ago) && - (i > 0) ) - { - struct GNUNET_TIME_Timestamp interval_start; - - interval_start = GNUNET_TIME_timestamp_get (); - interval_start.abs_time.abs_value_us -= cur_interval_start_ago * 1000 * 1000; - tflc->cb (tflc->cb_cls, - tflc->description, - interval_start, - amounts_len, - amounts); - GNUNET_array_grow (amounts, - amounts_len, - 0); - } - cur_interval_start_ago = interval_start_ago; - GNUNET_array_append (amounts, - amounts_len, - cumulative_amount); - GNUNET_PQ_cleanup_result (rs); - } - if (0 != amounts_len) - { - struct GNUNET_TIME_Timestamp interval_start; - - interval_start = GNUNET_TIME_timestamp_get (); - interval_start.abs_time.abs_value_us -= cur_interval_start_ago * 1000 * 1000; - tflc->cb (tflc->cb_cls, - tflc->description, - interval_start, - amounts_len, - amounts); - GNUNET_array_grow (amounts, - amounts_len, - 0); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_statistics_amount_by_interval ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *slug, - TALER_MERCHANTDB_AmountByIntervalStatisticsCallback cb, - void *cb_cls) -{ - struct LookupAmountStatisticsContext context = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the lookup_statistics_amount_by_interval_cb */ - .extract_failed = false, - .description = NULL - }; - struct GNUNET_PQ_QueryParam descParams[] = { - GNUNET_PQ_query_param_string (slug), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (slug), - 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 description" - " FROM merchant_statistic_interval_meta" - " WHERE slug=$1 LIMIT 1"); - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - descParams, - &lookup_statistics_amount_by_interval_desc_cb, - &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; - } - TMH_PQ_prepare_anon (pg, - "SELECT *" - " FROM merchant_statistic_interval_amount_get($1)"); - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_statistics_amount_by_interval_cb, - &context); - if (NULL != context.description) - GNUNET_free (context.description); - /* 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/iterate_statistics_counter_by_bucket.c b/src/backenddb/iterate_statistics_counter_by_bucket.c @@ -1,159 +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/iterate_statistics_counter_by_bucket.c - * @brief Implementation of the iterate_statistics_counter_by_bucket function for Postgres - * @author Martin Schanzenbach - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/iterate_statistics_counter_by_bucket.h" -#include "helper.h" -#include "merchantdb_lib.h" - - -/** - * Context used for TALER_MERCHANTDB_iterate_statistics_counter_by_bucket(). - */ -struct LookupCounterStatisticsContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_CounterByBucketStatisticsCallback cb; - - /** - * Closure for @a cb. - */ - void *cb_cls; - - /** - * Did database result extraction fail? - */ - bool extract_failed; -}; - - -/** - * 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 LookupCounterStatisticsContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_statistics_counter_by_bucket_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupCounterStatisticsContext *tflc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - char *description; - char *bucket_range; - uint64_t cumulative_number; - uint64_t bucket_start_epoch; - uint64_t bucket_end_epoch; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("description", - &description), - GNUNET_PQ_result_spec_uint64 ("bucket_start", - &bucket_start_epoch), - GNUNET_PQ_result_spec_uint64 ("bucket_end", - &bucket_end_epoch), - GNUNET_PQ_result_spec_string ("bucket_range", - &bucket_range), - GNUNET_PQ_result_spec_uint64 ("cumulative_number", - &cumulative_number), - GNUNET_PQ_result_spec_end - }; - struct GNUNET_TIME_Timestamp bucket_start; - struct GNUNET_TIME_Timestamp bucket_end; - - 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); - bucket_end = GNUNET_TIME_timestamp_from_s (bucket_end_epoch); - tflc->cb (tflc->cb_cls, - description, - bucket_start, - bucket_end, - bucket_range, - cumulative_number); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_statistics_counter_by_bucket ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *slug, - TALER_MERCHANTDB_CounterByBucketStatisticsCallback cb, - void *cb_cls) -{ - struct LookupCounterStatisticsContext context = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the lookup_statistics_counter_by_bucket_cb */ - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (slug), - 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" - " description" - ",bucket_start" - ",bucket_range::TEXT" - ",merchant_statistics_bucket_end(bucket_start, bucket_range) AS bucket_end" - ",cumulative_number" - " FROM merchant_statistic_bucket_counter" - " JOIN merchant_statistic_bucket_meta" - " USING (bmeta_serial_id)" - " WHERE merchant_statistic_bucket_meta.slug=$1" - " AND merchant_statistic_bucket_meta.stype = 'number'"); - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_statistics_counter_by_bucket_cb, - &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/iterate_statistics_counter_by_bucket_range.c b/src/backenddb/iterate_statistics_counter_by_bucket_range.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/iterate_statistics_counter_by_bucket_range.c - * @brief Implementation of the iterate_statistics_counter_by_bucket_range function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/iterate_statistics_counter_by_bucket_range.h" -#include "helper.h" - -/** - * Context used for TALER_MERCHANTDB_iterate_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_iterate_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/iterate_statistics_counter_by_interval.c b/src/backenddb/iterate_statistics_counter_by_interval.c @@ -1,210 +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/iterate_statistics_counter_by_interval.c - * @brief Implementation of the iterate_statistics_counter_by_interval function for Postgres - * @author Martin Schanzenbach - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/iterate_statistics_counter_by_interval.h" -#include "helper.h" -#include "merchantdb_lib.h" - - -/** - * Context used for TALER_MERCHANTDB_iterate_statistics_counter_by_interval(). - */ -struct LookupCounterStatisticsContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_CounterByIntervalStatisticsCallback cb; - - /** - * Closure for @a cb. - */ - void *cb_cls; - - /** - * Did database result extraction fail? - */ - bool extract_failed; - - /** - * Description of statistic - */ - char*description; -}; - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results about statistics. - * - * @param[in,out] cls of type `struct LookupTokenFamiliesContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_statistics_counter_by_interval_desc_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupCounterStatisticsContext *tflc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - char *description; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("description", - &description), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - tflc->extract_failed = true; - return; - } - - tflc->description = GNUNET_strdup (description); - - GNUNET_PQ_cleanup_result (rs); - } -} - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results about statistics. - * - * @param[in,out] cls of type `struct LookupTokenFamiliesContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_statistics_counter_by_interval_cb ( - void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupCounterStatisticsContext *tflc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - uint64_t cumulative_number; - uint64_t interval_start_ago; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("range", - &interval_start_ago), - GNUNET_PQ_result_spec_uint64 ("rvalue", - &cumulative_number), - GNUNET_PQ_result_spec_end - }; - struct GNUNET_TIME_Timestamp interval_start; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - tflc->extract_failed = true; - return; - } - - interval_start = GNUNET_TIME_timestamp_get (); - interval_start.abs_time.abs_value_us -= interval_start_ago * 1000 * 1000; - tflc->cb (tflc->cb_cls, - tflc->description, - interval_start, - cumulative_number); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_statistics_counter_by_interval ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *slug, - TALER_MERCHANTDB_CounterByIntervalStatisticsCallback cb, - void *cb_cls) -{ - struct LookupCounterStatisticsContext context = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the lookup_statistics_counter_by_interval_cb */ - .extract_failed = false, - .description = NULL - }; - struct GNUNET_PQ_QueryParam descParams[] = { - GNUNET_PQ_query_param_string (slug), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (slug), - 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 description" - " FROM merchant_statistic_interval_meta" - " WHERE slug=$1" - " LIMIT 1"); - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - descParams, - &lookup_statistics_counter_by_interval_desc_cb, - &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; - } - TMH_PQ_prepare_anon (pg, - "SELECT" - " range" - " ,rvalue" - " FROM merchant_statistic_interval_number_get($1)"); - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_statistics_counter_by_interval_cb, - &context); - if (NULL != context.description) - GNUNET_free (context.description); - /* 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/iterate_transfer_summaries.c b/src/backenddb/iterate_transfer_summaries.c @@ -0,0 +1,149 @@ +/* + This file is part of TALER + Copyright (C) 2023, 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/iterate_transfer_summaries.c + * @brief Implementation of the iterate_transfer_summaries function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_transfer_summaries.h" +#include "helper.h" + +/** + * Closure for #lookup_transfer_summary_cb(). + */ +struct LookupTransferSummaryContext +{ + /** + * Function to call for each order that was aggregated. + */ + TALER_MERCHANTDB_TransferSummaryCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Plugin context. + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + + /** + * Transaction result. + */ + enum GNUNET_DB_QueryStatus qs; +}; + + +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results. + * + * @param cls of type `struct LookupTransferSummaryContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_transfer_summary_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupTransferSummaryContext *ltdc = cls; + + for (unsigned int i = 0; i<num_results; i++) + { + char *order_id; + struct TALER_Amount deposit_value; + struct TALER_Amount deposit_fee; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("order_id", + &order_id), + TALER_PQ_result_spec_amount_with_currency ("exchange_deposit_value", + &deposit_value), + TALER_PQ_result_spec_amount_with_currency ("exchange_deposit_fee", + &deposit_fee), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ltdc->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + ltdc->cb (ltdc->cb_cls, + order_id, + &deposit_value, + &deposit_fee); + GNUNET_PQ_cleanup_result (rs); + } + ltdc->qs = num_results; +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_transfer_summaries ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *exchange_url, + const struct TALER_WireTransferIdentifierRawP *wtid, + TALER_MERCHANTDB_TransferSummaryCallback cb, + void *cb_cls) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (exchange_url), + GNUNET_PQ_query_param_auto_from_type (wtid), + GNUNET_PQ_query_param_end + }; + struct LookupTransferSummaryContext ltdc = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg + }; + enum GNUNET_DB_QueryStatus qs; + + GNUNET_assert (NULL != pg->current_merchant_id); + TMH_PQ_prepare_anon (pg, + "SELECT" + " mct.order_id" + ",mtc.exchange_deposit_value" + ",mtc.exchange_deposit_fee" + " FROM merchant_expected_transfers met" + " JOIN merchant_expected_transfer_to_coin mtc" + " USING (expected_credit_serial)" + " JOIN merchant_deposits dep" + " USING (deposit_serial)" + " JOIN merchant_deposit_confirmations mcon" + " USING (deposit_confirmation_serial)" + " JOIN merchant_contract_terms mct" + " USING (order_serial)" + " WHERE met.wtid=$2" + " AND met.exchange_url=$1"); + + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &lookup_transfer_summary_cb, + &ltdc); + if (0 >= qs) + return qs; + return ltdc.qs; +} diff --git a/src/backenddb/iterate_transfer_summary.c b/src/backenddb/iterate_transfer_summary.c @@ -1,149 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2023, 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/iterate_transfer_summary.c - * @brief Implementation of the iterate_transfer_summary function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/iterate_transfer_summary.h" -#include "helper.h" - -/** - * Closure for #lookup_transfer_summary_cb(). - */ -struct LookupTransferSummaryContext -{ - /** - * Function to call for each order that was aggregated. - */ - TALER_MERCHANTDB_TransferSummaryCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; - - /** - * Plugin context. - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - - /** - * Transaction result. - */ - enum GNUNET_DB_QueryStatus qs; -}; - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls of type `struct LookupTransferSummaryContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_transfer_summary_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupTransferSummaryContext *ltdc = cls; - - for (unsigned int i = 0; i<num_results; i++) - { - char *order_id; - struct TALER_Amount deposit_value; - struct TALER_Amount deposit_fee; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("order_id", - &order_id), - TALER_PQ_result_spec_amount_with_currency ("exchange_deposit_value", - &deposit_value), - TALER_PQ_result_spec_amount_with_currency ("exchange_deposit_fee", - &deposit_fee), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - ltdc->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - ltdc->cb (ltdc->cb_cls, - order_id, - &deposit_value, - &deposit_fee); - GNUNET_PQ_cleanup_result (rs); - } - ltdc->qs = num_results; -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_transfer_summary ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *exchange_url, - const struct TALER_WireTransferIdentifierRawP *wtid, - TALER_MERCHANTDB_TransferSummaryCallback cb, - void *cb_cls) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (exchange_url), - GNUNET_PQ_query_param_auto_from_type (wtid), - GNUNET_PQ_query_param_end - }; - struct LookupTransferSummaryContext ltdc = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - enum GNUNET_DB_QueryStatus qs; - - GNUNET_assert (NULL != pg->current_merchant_id); - TMH_PQ_prepare_anon (pg, - "SELECT" - " mct.order_id" - ",mtc.exchange_deposit_value" - ",mtc.exchange_deposit_fee" - " FROM merchant_expected_transfers met" - " JOIN merchant_expected_transfer_to_coin mtc" - " USING (expected_credit_serial)" - " JOIN merchant_deposits dep" - " USING (deposit_serial)" - " JOIN merchant_deposit_confirmations mcon" - " USING (deposit_confirmation_serial)" - " JOIN merchant_contract_terms mct" - " USING (order_serial)" - " WHERE met.wtid=$2" - " AND met.exchange_url=$1"); - - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_transfer_summary_cb, - &ltdc); - if (0 >= qs) - return qs; - return ltdc.qs; -} diff --git a/src/backenddb/iterate_used_tokens_by_order.c b/src/backenddb/iterate_used_tokens_by_order.c @@ -0,0 +1,158 @@ +/* + This file is part of TALER + Copyright (C) 2024 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/iterate_used_tokens_by_order.c + * @brief Implementation of the iterate_used_tokens_by_order function for Postgres + * @author Christian Blättler + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_used_tokens_by_order.h" +#include "helper.h" +#include "merchantdb_lib.h" + +/** + * Closure for lookup_spent_tokens_by_order_cb(). + */ +struct LookupSpentTokensByOrderContext +{ + + /** + * Plugin context. + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + + /** + * Function to call with all results. + */ + TALER_MERCHANTDB_UsedTokensCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Set to the query result. + */ + enum GNUNET_DB_QueryStatus qs; +}; + + +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results. + * + * @param cls of type `struct LookupSpentTokensByOrderContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_spent_tokens_by_order_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupSpentTokensByOrderContext *ctx = cls; + + for (unsigned int i = 0; i<num_results; i++) + { + uint64_t spent_token_serial; + struct TALER_PrivateContractHashP h_contract_terms; + struct TALER_TokenIssuePublicKeyHashP h_issue_pub; + struct TALER_TokenUsePublicKeyP use_pub; + struct TALER_TokenUseSignatureP use_sig; + struct TALER_TokenIssueSignature issue_sig; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("spent_token_serial", + &spent_token_serial), + GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", + &h_contract_terms), + GNUNET_PQ_result_spec_auto_from_type ("h_pub", + &h_issue_pub), + GNUNET_PQ_result_spec_auto_from_type ("token_pub", + &use_pub), + GNUNET_PQ_result_spec_auto_from_type ("token_sig", + &use_sig), + GNUNET_PQ_result_spec_unblinded_sig ("blind_sig", + &issue_sig.signature), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ctx->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + ctx->cb (ctx->cb_cls, + spent_token_serial, + &h_contract_terms, + &h_issue_pub, + &use_pub, + &use_sig, + &issue_sig); + GNUNET_PQ_cleanup_result (rs); + } + ctx->qs = num_results; +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_used_tokens_by_order ( + struct TALER_MERCHANTDB_PostgresContext *pg, + uint64_t order_serial, + TALER_MERCHANTDB_UsedTokensCallback cb, + void *cb_cls) +{ + struct LookupSpentTokensByOrderContext ctx = { + .pg = pg, + .cb = cb, + .cb_cls = cb_cls + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&order_serial), + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + GNUNET_assert (NULL != pg->current_merchant_id); + TMH_PQ_prepare_anon (pg, + "SELECT" + " spent_token_serial" + ",h_contract_terms" + ",h_pub" + ",token_pub" + ",token_sig" + ",blind_sig" + " FROM merchant_used_tokens" + " JOIN merchant_contract_terms" + " USING (h_contract_terms)" + " JOIN merchant_token_family_keys" + " USING (token_family_key_serial)" + " WHERE order_serial=$1"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "", + params, + &lookup_spent_tokens_by_order_cb, + &ctx); + + if (qs < 0) + return qs; + return ctx.qs; +} diff --git a/src/backenddb/meson.build b/src/backenddb/meson.build @@ -28,7 +28,7 @@ libtalermerchantdb = library( 'delete_login_token.c', 'delete_login_token_by_serial.c', 'delete_order.c', - 'delete_otp.c', + 'delete_otp_device.c', 'delete_pending_webhook.c', 'delete_product.c', 'delete_template.c', @@ -52,17 +52,17 @@ libtalermerchantdb = library( 'insert_deposit_to_transfer.c', 'insert_exchange_account.c', 'insert_exchange_keys.c', - 'insert_exchange_signkey.c', + 'insert_exchange_signing_key.c', 'insert_instance.c', 'insert_issued_token.c', 'insert_login_token.c', 'insert_order.c', 'insert_order_lock.c', - 'insert_otp.c', + 'insert_otp_device.c', 'insert_pending_webhook.c', 'insert_product.c', 'insert_refund_proof.c', - 'insert_spent_token.c', + 'insert_used_token.c', 'insert_template.c', 'insert_tos_accepted_early.c', 'update_unit.c', @@ -84,7 +84,7 @@ libtalermerchantdb = library( 'update_report.c', 'get_report_by_token.c', 'iterate_reports.c', - 'iterate_reports_pending.c', + 'iterate_pending_reports.c', 'update_report_status.c', 'get_report.c', 'insert_product_group.c', @@ -132,9 +132,9 @@ libtalermerchantdb = library( 'get_refund_proof.c', 'iterate_refunds.c', 'iterate_refunds_detailed.c', - 'iterate_spent_tokens_by_order.c', - 'iterate_statistics_amount_by_bucket_range.c', - 'iterate_statistics_counter_by_bucket_range.c', + 'iterate_used_tokens_by_order.c', + 'iterate_statistic_bucket_amounts_by_range.c', + 'iterate_statistic_bucket_counters_by_range.c', 'get_template.c', 'iterate_templates.c', 'iterate_token_families.c', @@ -143,57 +143,57 @@ libtalermerchantdb = library( 'iterate_token_family_keys.c', 'iterate_transfer_details.c', 'iterate_transfer_details_by_order.c', - 'iterate_transfer_summary.c', + 'iterate_transfer_summaries.c', 'iterate_transfers.c', 'get_webhook.c', 'iterate_webhooks_by_event.c', - 'iterate_all_webhooks.c', + 'iterate_pending_webhooks_above_serial_id.c', 'iterate_webhooks.c', - 'get_wire_fee.c', + 'get_exchange_wire_fee.c', 'update_to_contract_terms_paid.c', 'update_to_contract_terms_wired.c', - 'iterate_order_blinded_sigs.c', + 'iterate_order_token_blinded_sigs.c', 'delete_instance.c', 'insert_refund_by_coin.c', 'get_account.c', 'get_account_by_uri.c', 'iterate_accounts.c', 'iterate_accounts_by_instance.c', - 'iterate_accounts_by_exchange.c', + 'iterate_exchange_accounts.c', 'get_category.c', 'get_category_by_name.c', 'get_exchange_keys.c', 'iterate_exchanges.c', 'get_login_token.c', - 'iterate_open_transfers.c', - 'get_otp.c', - 'get_otp_serial.c', + 'iterate_open_expected_transfers.c', + 'get_otp_device.c', + 'get_otp_device_serial.c', 'iterate_wirewatch_accounts.c', - 'insert_wire_fee.c', + 'insert_exchange_wire_fee.c', 'delete_inventory_lock.c', 'update_account.c', 'update_category.c', - 'update_contract_session.c', + 'update_contract_terms_session.c', 'update_contract_terms.c', - 'update_deposit_confirmation_status.c', + 'update_deposit_settlement_status.c', 'update_donau_instance_receipts_amount.c', 'update_instance.c', 'update_instance_auth.c', - 'update_otp.c', + 'update_otp_device.c', 'update_pending_webhook.c', 'update_product.c', 'update_template.c', 'update_token_family.c', - 'update_transfer_status.c', - 'update_to_transfer_finalized.c', + 'update_expected_transfer_status.c', + 'update_to_expected_transfer_finalized.c', 'delete_donau_instance.c', - 'insert_order_blinded_sigs.c', + 'insert_order_token_blinded_sig.c', 'update_webhook.c', - 'update_wirewatch_progress.c', - 'iterate_statistics_counter_by_bucket.c', - 'iterate_statistics_counter_by_interval.c', - 'iterate_statistics_amount_by_bucket.c', - 'iterate_statistics_amount_by_interval.c', + 'update_account_last_bank_serial.c', + 'iterate_statistic_bucket_counters.c', + 'iterate_statistic_interval_counters.c', + 'iterate_statistic_bucket_amounts.c', + 'iterate_statistic_interval_amounts.c', 'insert_donau_instance.c', 'get_exists_donau_instance.c', 'iterate_donau_instances.c', @@ -201,7 +201,7 @@ libtalermerchantdb = library( 'iterate_donau_instances_filtered.c', 'get_donau_instance_by_serial.c', 'get_donau_keys.c', - 'get_order_charity.c', + 'get_donau_instance_by_url.c', 'get_tos_accepted_early.c', 'insert_donau_keys.c', 'update_donau_instance.c', diff --git a/src/backenddb/sql-schema/meson.build b/src/backenddb/sql-schema/meson.build @@ -12,11 +12,11 @@ sql_global_procedures = [ '../pg_fixup_instance_schema.sql', '../iterate_outdated_kyc_statuses.sql', '../iterate_wirewatch_accounts.sql', - '../iterate_open_transfers.sql', + '../iterate_open_expected_transfers.sql', '../iterate_all_donau_instances.sql', '../do_solve_mfa_challenge.sql', '../iterate_pending_deposits.sql', - '../iterate_reports_pending.sql', + '../iterate_pending_reports.sql', '../pg_select_accounts.sql', '../pg_create_instance_schema.sql', '../pg_create_instance_trigger.sql', @@ -39,12 +39,12 @@ sql_instance_procedures = [ '../delete_unit.sql', '../insert_unit.sql', '../update_unit.sql', - '../iterate_statistics_amount_by_interval.sql', - '../iterate_statistics_counter_by_interval.sql', + '../iterate_statistic_interval_amounts.sql', + '../iterate_statistic_interval_counters.sql', '../insert_deposit_to_transfer.sql', '../insert_product.sql', '../insert_issued_token.sql', - '../insert_spent_token.sql', + '../insert_used_token.sql', '../insert_transfer_details.sql', '../update_product.sql', '../insert_kyc_status.sql', diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c @@ -43,11 +43,11 @@ #include "merchant-database/insert_deposit.h" #include "merchant-database/insert_deposit_confirmation.h" #include "merchant-database/insert_deposit_to_transfer.h" -#include "merchant-database/insert_exchange_signkey.h" +#include "merchant-database/insert_exchange_signing_key.h" #include "merchant-database/insert_instance.h" #include "merchant-database/insert_order.h" #include "merchant-database/insert_order_lock.h" -#include "merchant-database/insert_otp.h" +#include "merchant-database/insert_otp_device.h" #include "merchant-database/insert_pending_webhook.h" #include "merchant-database/insert_product.h" #include "merchant-database/insert_refund_proof.h" @@ -67,7 +67,7 @@ #include "merchant-database/get_order_by_fulfillment.h" #include "merchant-database/get_order_status.h" #include "merchant-database/iterate_orders.h" -#include "merchant-database/iterate_all_webhooks.h" +#include "merchant-database/iterate_pending_webhooks_above_serial_id.h" #include "merchant-database/iterate_pending_webhooks.h" #include "merchant-database/get_product.h" #include "merchant-database/iterate_products.h" @@ -78,17 +78,17 @@ #include "merchant-database/iterate_templates.h" #include "merchant-database/iterate_transfer_details.h" #include "merchant-database/iterate_transfer_details_by_order.h" -#include "merchant-database/iterate_transfer_summary.h" +#include "merchant-database/iterate_transfer_summaries.h" #include "merchant-database/iterate_transfers.h" #include "merchant-database/get_webhook.h" #include "merchant-database/iterate_webhooks_by_event.h" #include "merchant-database/iterate_webhooks.h" -#include "merchant-database/get_wire_fee.h" +#include "merchant-database/get_exchange_wire_fee.h" #include "merchant-database/update_to_contract_terms_paid.h" #include "merchant-database/update_to_contract_terms_wired.h" #include "merchant-database/insert_refund_by_coin.h" #include "merchant-database/set_instance.h" -#include "merchant-database/insert_wire_fee.h" +#include "merchant-database/insert_exchange_wire_fee.h" #include "merchant-database/delete_inventory_lock.h" #include "merchant-database/update_contract_terms.h" #include "merchant-database/update_instance.h" @@ -2891,14 +2891,14 @@ test_insert_exchange_signkey (const struct ExchangeSignkeyData *signkey, enum GNUNET_DB_QueryStatus expected_result) { TEST_COND_RET_ON_FAIL (expected_result == - TALER_MERCHANTDB_insert_exchange_signkey (pg, - &signkey->master_pub, - &signkey->exchange_pub - , - signkey->start_date, - signkey->expire_date, - signkey->end_date, - &signkey->master_sig), + TALER_MERCHANTDB_insert_exchange_signing_key (pg, + &signkey->master_pub, + &signkey->exchange_pub + , + signkey->start_date, + signkey->expire_date, + signkey->end_date, + &signkey->master_sig), "Insert exchange signkey failed\n"); return 0; } @@ -3873,11 +3873,11 @@ test_lookup_transfer_summary ( .deposit_fee = expected_deposit_fee, .result = 0 }; - if (1 != TALER_MERCHANTDB_iterate_transfer_summary (pg, - exchange_url, - wtid, - &lookup_transfer_summary_cb, - &cmp)) + if (1 != TALER_MERCHANTDB_iterate_transfer_summaries (pg, + exchange_url, + wtid, + &lookup_transfer_summary_cb, + &cmp)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup transfer summary failed\n"); @@ -4165,7 +4165,7 @@ test_insert_wire_fee (const struct ExchangeSignkeyData *signkey, enum GNUNET_DB_QueryStatus expected_result) { TEST_COND_RET_ON_FAIL (expected_result == - TALER_MERCHANTDB_insert_wire_fee ( + TALER_MERCHANTDB_insert_exchange_wire_fee ( pg, &signkey->master_pub, &wire_fee->h_wire_method, @@ -4193,14 +4193,14 @@ test_lookup_wire_fee (const struct ExchangeSignkeyData *signkey, struct GNUNET_TIME_Timestamp start_date; struct GNUNET_TIME_Timestamp end_date; struct TALER_MasterSignatureP master_sig; - if (1 != TALER_MERCHANTDB_get_wire_fee (pg, - &signkey->master_pub, - wire_fee_data->wire_method, - GNUNET_TIME_timestamp_get (), - &fees, - &start_date, - &end_date, - &master_sig)) + if (1 != TALER_MERCHANTDB_get_exchange_wire_fee (pg, + &signkey->master_pub, + wire_fee_data->wire_method, + GNUNET_TIME_timestamp_get (), + &fees, + &start_date, + &end_date, + &master_sig)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup wire fee failed\n"); @@ -4597,14 +4597,14 @@ run_test_transfers (struct TestTransfers_Closure *cls) /* Test lookup wire fee fails when it isn't in the db */ TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == - TALER_MERCHANTDB_get_wire_fee (pg, - &cls->signkey.master_pub, - cls->wire_fee[0].wire_method, - GNUNET_TIME_timestamp_get (), - &fees, - NULL, - NULL, - NULL), + TALER_MERCHANTDB_get_exchange_wire_fee (pg, + &cls->signkey.master_pub, + cls->wire_fee[0].wire_method, + GNUNET_TIME_timestamp_get (), + &fees, + NULL, + NULL, + NULL), "Lookup wire fee failed\n"); /* Test store wire fee by exchange */ TEST_RET_ON_FAIL (test_insert_wire_fee (&cls->signkey, @@ -6344,10 +6344,10 @@ run_test_templates (struct TestTemplates_Closure *cls) .otp_ctr = 42 }; GNUNET_assert (0 <= - TALER_MERCHANTDB_insert_otp (pg, - cls->instance.instance.id, - "otp_id", - &td)); + TALER_MERCHANTDB_insert_otp_device (pg, + cls->instance.instance.id, + "otp_id", + &td)); } GNUNET_assert (0 == json_array_append_new ( @@ -7122,12 +7122,12 @@ get_pending_serial (const struct InstanceData *instance, TALER_MERCHANTDB_set_instance (pg, instance->instance.id)); GNUNET_assert (0 < - TALER_MERCHANTDB_iterate_all_webhooks (pg, - instance->instance.id, - 0, - INT_MAX, - &get_pending_serial_cb, - &lpw)); + TALER_MERCHANTDB_iterate_pending_webhooks_above_serial_id (pg, + instance->instance.id, + 0, + INT_MAX, + &get_pending_serial_cb, + &lpw)); GNUNET_assert (0 != lpw.webhook_pending_serial); return lpw.webhook_pending_serial; @@ -7324,12 +7324,12 @@ test_lookup_all_webhooks (const struct InstanceData *instance, 0, sizeof (results_matching)); TEST_SET_INSTANCE (instance->instance.id, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT); - if (0 > TALER_MERCHANTDB_iterate_all_webhooks (pg, - instance->instance.id, - min_row, - max_results, - &lookup_pending_webhooks_cb, - &cls)) + if (0 > TALER_MERCHANTDB_iterate_pending_webhooks_above_serial_id (pg, + instance->instance.id, + min_row, + max_results, + &lookup_pending_webhooks_cb, + &cls)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup all webhooks failed\n"); diff --git a/src/backenddb/update_account_last_bank_serial.c b/src/backenddb/update_account_last_bank_serial.c @@ -0,0 +1,51 @@ +/* + 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/update_account_last_bank_serial.c + * @brief Implementation of the update_account_last_bank_serial function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/update_account_last_bank_serial.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_update_account_last_bank_serial ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance, + struct TALER_FullPayto payto_uri, + uint64_t last_serial) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (payto_uri.full_payto), + GNUNET_PQ_query_param_uint64 (&last_serial), + GNUNET_PQ_query_param_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (instance, + pg->current_merchant_id)); + TMH_PQ_prepare_anon (pg, + "UPDATE merchant_accounts" + " SET last_bank_serial=$2" + " WHERE REGEXP_REPLACE(payto_uri,'\\?.*','')" + " =REGEXP_REPLACE(CAST ($1 AS TEXT),'\\?.*','')"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "", + params); +} diff --git a/src/backenddb/update_contract_session.c b/src/backenddb/update_contract_session.c @@ -1,78 +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/update_contract_session.c - * @brief Implementation of the update_contract_session function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/update_contract_session.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_update_contract_session ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const struct TALER_PrivateContractHashP *h_contract_terms, - const char *session_id, - char **fulfillment_url, - bool *refunded) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (h_contract_terms), - GNUNET_PQ_query_param_string (session_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("fulfillment_url", - fulfillment_url), - NULL), - GNUNET_PQ_result_spec_bool ("refunded", - refunded), - GNUNET_PQ_result_spec_end - }; - - /* Session ID must always be given by the caller. */ - GNUNET_assert (NULL != session_id); - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance_id, - pg->current_merchant_id)); - - /* no preflight check here, run in transaction by caller! */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Updating session for h_contract_terms '%s' of `%s' to `%s'\n", - GNUNET_h2s (&h_contract_terms->hash), - instance_id, - session_id); - TMH_PQ_prepare_anon (pg, - "UPDATE merchant_contract_terms mct SET" - " session_id=$2" - " WHERE h_contract_terms=$1" - " RETURNING" - " contract_terms->>'fulfillment_url' AS fulfillment_url" - " ,EXISTS (SELECT 1" - " FROM merchant_refunds mr" - " WHERE order_serial=mct.order_serial" - " ) AS refunded"); - *fulfillment_url = NULL; - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/update_contract_terms_session.c b/src/backenddb/update_contract_terms_session.c @@ -0,0 +1,78 @@ +/* + 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/update_contract_terms_session.c + * @brief Implementation of the update_contract_terms_session function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/update_contract_terms_session.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_update_contract_terms_session ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const struct TALER_PrivateContractHashP *h_contract_terms, + const char *session_id, + char **fulfillment_url, + bool *refunded) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (h_contract_terms), + GNUNET_PQ_query_param_string (session_id), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("fulfillment_url", + fulfillment_url), + NULL), + GNUNET_PQ_result_spec_bool ("refunded", + refunded), + GNUNET_PQ_result_spec_end + }; + + /* Session ID must always be given by the caller. */ + GNUNET_assert (NULL != session_id); + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (instance_id, + pg->current_merchant_id)); + + /* no preflight check here, run in transaction by caller! */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Updating session for h_contract_terms '%s' of `%s' to `%s'\n", + GNUNET_h2s (&h_contract_terms->hash), + instance_id, + session_id); + TMH_PQ_prepare_anon (pg, + "UPDATE merchant_contract_terms mct SET" + " session_id=$2" + " WHERE h_contract_terms=$1" + " RETURNING" + " contract_terms->>'fulfillment_url' AS fulfillment_url" + " ,EXISTS (SELECT 1" + " FROM merchant_refunds mr" + " WHERE order_serial=mct.order_serial" + " ) AS refunded"); + *fulfillment_url = NULL; + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/update_deposit_confirmation_status.c b/src/backenddb/update_deposit_confirmation_status.c @@ -1,63 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2024 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/update_deposit_confirmation_status.c - * @brief Implementation of the update_deposit_confirmation_status function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/update_deposit_confirmation_status.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_update_deposit_confirmation_status ( - struct TALER_MERCHANTDB_PostgresContext *pg, - uint64_t deposit_serial, - bool retry_needed, - struct GNUNET_TIME_Timestamp retry_time, - uint32_t last_http_status, - enum TALER_ErrorCode last_ec, - const char *last_detail) -{ - uint32_t ec32 = (uint32_t) last_ec; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&deposit_serial), - GNUNET_PQ_query_param_bool (retry_needed), - GNUNET_PQ_query_param_timestamp (&retry_time), - GNUNET_PQ_query_param_uint32 (&last_http_status), - GNUNET_PQ_query_param_uint32 (&ec32), - NULL == last_detail - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_string (last_detail), - GNUNET_PQ_query_param_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - TMH_PQ_prepare_anon (pg, - "UPDATE merchant_deposits SET" - " settlement_retry_needed=$2" - ",settlement_retry_time=$3" - ",settlement_last_http_status=$4" - ",settlement_last_ec=$5" - ",settlement_last_detail=$6" - " WHERE deposit_serial=$1;"); - return GNUNET_PQ_eval_prepared_non_select ( - pg->conn, - "", - params); -} diff --git a/src/backenddb/update_deposit_settlement_status.c b/src/backenddb/update_deposit_settlement_status.c @@ -0,0 +1,63 @@ +/* + This file is part of TALER + Copyright (C) 2024 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/update_deposit_settlement_status.c + * @brief Implementation of the update_deposit_settlement_status function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/update_deposit_settlement_status.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_update_deposit_settlement_status ( + struct TALER_MERCHANTDB_PostgresContext *pg, + uint64_t deposit_serial, + bool retry_needed, + struct GNUNET_TIME_Timestamp retry_time, + uint32_t last_http_status, + enum TALER_ErrorCode last_ec, + const char *last_detail) +{ + uint32_t ec32 = (uint32_t) last_ec; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&deposit_serial), + GNUNET_PQ_query_param_bool (retry_needed), + GNUNET_PQ_query_param_timestamp (&retry_time), + GNUNET_PQ_query_param_uint32 (&last_http_status), + GNUNET_PQ_query_param_uint32 (&ec32), + NULL == last_detail + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (last_detail), + GNUNET_PQ_query_param_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + TMH_PQ_prepare_anon (pg, + "UPDATE merchant_deposits SET" + " settlement_retry_needed=$2" + ",settlement_retry_time=$3" + ",settlement_last_http_status=$4" + ",settlement_last_ec=$5" + ",settlement_last_detail=$6" + " WHERE deposit_serial=$1;"); + return GNUNET_PQ_eval_prepared_non_select ( + pg->conn, + "", + params); +} diff --git a/src/backenddb/update_expected_transfer_status.c b/src/backenddb/update_expected_transfer_status.c @@ -0,0 +1,67 @@ +/* + This file is part of TALER + Copyright (C) 2022, 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/update_expected_transfer_status.c + * @brief Implementation of the update_expected_transfer_status function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/update_expected_transfer_status.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_update_expected_transfer_status ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *exchange_url, + const struct TALER_WireTransferIdentifierRawP *wtid, + struct GNUNET_TIME_Absolute next_attempt, + unsigned int http_status, + enum TALER_ErrorCode ec, + const char *detail, + bool needs_retry) +{ + uint32_t hs32 = (uint32_t) http_status; + uint32_t ec32 = (uint32_t) ec; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (wtid), + GNUNET_PQ_query_param_string (exchange_url), + GNUNET_PQ_query_param_uint32 (&hs32), + GNUNET_PQ_query_param_uint32 (&ec32), + NULL == detail + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (detail), + GNUNET_PQ_query_param_bool (needs_retry), + GNUNET_PQ_query_param_absolute_time (&next_attempt), + GNUNET_PQ_query_param_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + TMH_PQ_prepare_anon (pg, + "UPDATE merchant_expected_transfers SET" + " last_http_status=$3" + ",last_ec=$4" + ",last_detail=$5" + ",retry_needed=$6" + ",retry_time=$7" + " WHERE wtid=$1" + " AND exchange_url=$2"); + return GNUNET_PQ_eval_prepared_non_select ( + pg->conn, + "", + params); +} diff --git a/src/backenddb/update_otp.c b/src/backenddb/update_otp.c @@ -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/backenddb/update_otp.c - * @brief Implementation of the update_otp function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/update_otp.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_update_otp ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *otp_id, - const struct TALER_MERCHANTDB_OtpDeviceDetails *td) -{ - uint32_t pos32 = (uint32_t) td->otp_algorithm; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (otp_id), - GNUNET_PQ_query_param_string (td->otp_description), - GNUNET_PQ_query_param_uint32 (&pos32), - GNUNET_PQ_query_param_uint64 (&td->otp_ctr), - (NULL == td->otp_key) - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_string (td->otp_key), - GNUNET_PQ_query_param_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance_id, - pg->current_merchant_id)); - TMH_PQ_prepare_anon (pg, - "UPDATE merchant_otp_devices SET" - " otp_description=$2" - ",otp_algorithm=$3" - ",otp_ctr=$4" - ",otp_key=COALESCE($5,otp_key)" - " WHERE otp_id=$1"); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "", - params); -} diff --git a/src/backenddb/update_otp_device.c b/src/backenddb/update_otp_device.c @@ -0,0 +1,59 @@ +/* + 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/update_otp_device.c + * @brief Implementation of the update_otp_device function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/update_otp_device.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_update_otp_device ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *otp_id, + const struct TALER_MERCHANTDB_OtpDeviceDetails *td) +{ + uint32_t pos32 = (uint32_t) td->otp_algorithm; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (otp_id), + GNUNET_PQ_query_param_string (td->otp_description), + GNUNET_PQ_query_param_uint32 (&pos32), + GNUNET_PQ_query_param_uint64 (&td->otp_ctr), + (NULL == td->otp_key) + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (td->otp_key), + GNUNET_PQ_query_param_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (instance_id, + pg->current_merchant_id)); + TMH_PQ_prepare_anon (pg, + "UPDATE merchant_otp_devices SET" + " otp_description=$2" + ",otp_algorithm=$3" + ",otp_ctr=$4" + ",otp_key=COALESCE($5,otp_key)" + " WHERE otp_id=$1"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "", + params); +} diff --git a/src/backenddb/update_to_expected_transfer_finalized.c b/src/backenddb/update_to_expected_transfer_finalized.c @@ -0,0 +1,76 @@ +/* + 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/update_to_expected_transfer_finalized.c + * @brief Implementation of the update_to_expected_transfer_finalized function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/update_to_expected_transfer_finalized.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_update_to_expected_transfer_finalized ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *exchange_url, + const struct TALER_WireTransferIdentifierRawP *wtid, + const struct GNUNET_HashCode *h_details, + const struct TALER_Amount *total_amount, + const struct TALER_Amount *wire_fee, + const struct TALER_ExchangePublicKeyP *exchange_pub, + const struct TALER_ExchangeSignatureP *exchange_sig) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (wtid), + GNUNET_PQ_query_param_string (exchange_url), + TALER_PQ_query_param_amount_with_currency (pg->conn, + total_amount), + TALER_PQ_query_param_amount_with_currency (pg->conn, + wire_fee), + GNUNET_PQ_query_param_auto_from_type (h_details), + GNUNET_PQ_query_param_auto_from_type (exchange_pub), + GNUNET_PQ_query_param_auto_from_type (exchange_sig), + GNUNET_PQ_query_param_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + TMH_PQ_prepare_anon (pg, + "WITH subquery AS (" + " SELECT signkey_serial" + " FROM merchant.merchant_exchange_signing_keys" + " WHERE exchange_pub=$6" + ")" + "UPDATE merchant_expected_transfers SET" + " last_http_status=200" + ",last_ec=0" + ",last_detail=NULL" + ",retry_needed=FALSE" + ",retry_time=0" + ",expected_credit_amount=$3" + ",wire_fee=$4" + ",h_details=$5" + ",signkey_serial=subquery.signkey_serial" + ",exchange_sig=$7" + " FROM subquery" + " WHERE wtid=$1" + " AND exchange_url=$2"); + return GNUNET_PQ_eval_prepared_non_select ( + pg->conn, + "", + params); +} diff --git a/src/backenddb/update_to_transfer_finalized.c b/src/backenddb/update_to_transfer_finalized.c @@ -1,76 +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/update_to_transfer_finalized.c - * @brief Implementation of the update_to_transfer_finalized function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/update_to_transfer_finalized.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_update_to_transfer_finalized ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *exchange_url, - const struct TALER_WireTransferIdentifierRawP *wtid, - const struct GNUNET_HashCode *h_details, - const struct TALER_Amount *total_amount, - const struct TALER_Amount *wire_fee, - const struct TALER_ExchangePublicKeyP *exchange_pub, - const struct TALER_ExchangeSignatureP *exchange_sig) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (wtid), - GNUNET_PQ_query_param_string (exchange_url), - TALER_PQ_query_param_amount_with_currency (pg->conn, - total_amount), - TALER_PQ_query_param_amount_with_currency (pg->conn, - wire_fee), - GNUNET_PQ_query_param_auto_from_type (h_details), - GNUNET_PQ_query_param_auto_from_type (exchange_pub), - GNUNET_PQ_query_param_auto_from_type (exchange_sig), - GNUNET_PQ_query_param_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - TMH_PQ_prepare_anon (pg, - "WITH subquery AS (" - " SELECT signkey_serial" - " FROM merchant.merchant_exchange_signing_keys" - " WHERE exchange_pub=$6" - ")" - "UPDATE merchant_expected_transfers SET" - " last_http_status=200" - ",last_ec=0" - ",last_detail=NULL" - ",retry_needed=FALSE" - ",retry_time=0" - ",expected_credit_amount=$3" - ",wire_fee=$4" - ",h_details=$5" - ",signkey_serial=subquery.signkey_serial" - ",exchange_sig=$7" - " FROM subquery" - " WHERE wtid=$1" - " AND exchange_url=$2"); - return GNUNET_PQ_eval_prepared_non_select ( - pg->conn, - "", - params); -} diff --git a/src/backenddb/update_transfer_status.c b/src/backenddb/update_transfer_status.c @@ -1,67 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022, 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/update_transfer_status.c - * @brief Implementation of the update_transfer_status function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/update_transfer_status.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_update_transfer_status ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *exchange_url, - const struct TALER_WireTransferIdentifierRawP *wtid, - struct GNUNET_TIME_Absolute next_attempt, - unsigned int http_status, - enum TALER_ErrorCode ec, - const char *detail, - bool needs_retry) -{ - uint32_t hs32 = (uint32_t) http_status; - uint32_t ec32 = (uint32_t) ec; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (wtid), - GNUNET_PQ_query_param_string (exchange_url), - GNUNET_PQ_query_param_uint32 (&hs32), - GNUNET_PQ_query_param_uint32 (&ec32), - NULL == detail - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_string (detail), - GNUNET_PQ_query_param_bool (needs_retry), - GNUNET_PQ_query_param_absolute_time (&next_attempt), - GNUNET_PQ_query_param_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - TMH_PQ_prepare_anon (pg, - "UPDATE merchant_expected_transfers SET" - " last_http_status=$3" - ",last_ec=$4" - ",last_detail=$5" - ",retry_needed=$6" - ",retry_time=$7" - " WHERE wtid=$1" - " AND exchange_url=$2"); - return GNUNET_PQ_eval_prepared_non_select ( - pg->conn, - "", - params); -} diff --git a/src/backenddb/update_wirewatch_progress.c b/src/backenddb/update_wirewatch_progress.c @@ -1,51 +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/update_wirewatch_progress.c - * @brief Implementation of the update_wirewatch_progress function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/update_wirewatch_progress.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_update_wirewatch_progress ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance, - struct TALER_FullPayto payto_uri, - uint64_t last_serial) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (payto_uri.full_payto), - GNUNET_PQ_query_param_uint64 (&last_serial), - GNUNET_PQ_query_param_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance, - pg->current_merchant_id)); - TMH_PQ_prepare_anon (pg, - "UPDATE merchant_accounts" - " SET last_bank_serial=$2" - " WHERE REGEXP_REPLACE(payto_uri,'\\?.*','')" - " =REGEXP_REPLACE(CAST ($1 AS TEXT),'\\?.*','')"); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "", - params); -} diff --git a/src/include/merchant-database/all.h b/src/include/merchant-database/all.h @@ -24,7 +24,7 @@ #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" +#include "merchant-database/delete_otp_device.h" #include "merchant-database/delete_pending_webhook.h" #include "merchant-database/delete_product.h" #include "merchant-database/delete_product_group.h" @@ -39,7 +39,7 @@ #include "merchant-database/event_listen.h" #include "merchant-database/event_notify.h" #include "merchant-database/do_expire_locks.h" -#include "merchant-database/update_to_transfer_finalized.h" +#include "merchant-database/update_to_expected_transfer_finalized.h" #include "merchant-database/gc.h" #include "merchant-database/get_kyc_limits.h" #include "merchant-database/get_kyc_status.h" @@ -55,21 +55,21 @@ #include "merchant-database/insert_donau_instance.h" #include "merchant-database/insert_exchange_account.h" #include "merchant-database/insert_exchange_keys.h" -#include "merchant-database/insert_exchange_signkey.h" +#include "merchant-database/insert_exchange_signing_key.h" #include "merchant-database/insert_instance.h" #include "merchant-database/insert_issued_token.h" #include "merchant-database/insert_login_token.h" #include "merchant-database/insert_money_pot.h" #include "merchant-database/insert_order.h" -#include "merchant-database/insert_order_blinded_sigs.h" +#include "merchant-database/insert_order_token_blinded_sig.h" #include "merchant-database/insert_order_lock.h" -#include "merchant-database/insert_otp.h" +#include "merchant-database/insert_otp_device.h" #include "merchant-database/insert_pending_webhook.h" #include "merchant-database/insert_product.h" #include "merchant-database/insert_product_group.h" #include "merchant-database/insert_refund_proof.h" #include "merchant-database/insert_report.h" -#include "merchant-database/insert_spent_token.h" +#include "merchant-database/insert_used_token.h" #include "merchant-database/insert_template.h" #include "merchant-database/insert_token_family.h" #include "merchant-database/insert_token_family_key.h" @@ -82,7 +82,7 @@ #include "merchant-database/insert_inventory_lock.h" #include "merchant-database/get_account_serial.h" #include "merchant-database/iterate_all_products.h" -#include "merchant-database/iterate_all_webhooks.h" +#include "merchant-database/iterate_pending_webhooks_above_serial_id.h" #include "merchant-database/iterate_categories.h" #include "merchant-database/iterate_categories_by_ids.h" #include "merchant-database/get_contract_terms.h" @@ -103,7 +103,7 @@ #include "merchant-database/get_mfa_challenge.h" #include "merchant-database/get_order.h" #include "merchant-database/get_order_by_fulfillment.h" -#include "merchant-database/get_order_charity.h" +#include "merchant-database/get_donau_instance_by_url.h" #include "merchant-database/get_order_status.h" #include "merchant-database/get_order_status_by_serial.h" #include "merchant-database/get_order_summary.h" @@ -118,14 +118,14 @@ #include "merchant-database/get_refund_proof.h" #include "merchant-database/iterate_refunds.h" #include "merchant-database/iterate_refunds_detailed.h" -#include "merchant-database/iterate_reports_pending.h" -#include "merchant-database/iterate_spent_tokens_by_order.h" -#include "merchant-database/iterate_statistics_amount_by_bucket.h" -#include "merchant-database/iterate_statistics_amount_by_bucket_range.h" -#include "merchant-database/iterate_statistics_amount_by_interval.h" -#include "merchant-database/iterate_statistics_counter_by_bucket.h" -#include "merchant-database/iterate_statistics_counter_by_bucket_range.h" -#include "merchant-database/iterate_statistics_counter_by_interval.h" +#include "merchant-database/iterate_pending_reports.h" +#include "merchant-database/iterate_used_tokens_by_order.h" +#include "merchant-database/iterate_statistic_bucket_amounts.h" +#include "merchant-database/iterate_statistic_bucket_amounts_by_range.h" +#include "merchant-database/iterate_statistic_interval_amounts.h" +#include "merchant-database/iterate_statistic_bucket_counters.h" +#include "merchant-database/iterate_statistic_bucket_counters_by_range.h" +#include "merchant-database/iterate_statistic_interval_counters.h" #include "merchant-database/get_template.h" #include "merchant-database/iterate_templates.h" #include "merchant-database/iterate_token_families.h" @@ -135,13 +135,13 @@ #include "merchant-database/get_tos_accepted_early.h" #include "merchant-database/iterate_transfer_details.h" #include "merchant-database/iterate_transfer_details_by_order.h" -#include "merchant-database/iterate_transfer_summary.h" +#include "merchant-database/iterate_transfer_summaries.h" #include "merchant-database/iterate_transfers.h" #include "merchant-database/iterate_units.h" #include "merchant-database/get_webhook.h" #include "merchant-database/iterate_webhooks_by_event.h" #include "merchant-database/iterate_webhooks.h" -#include "merchant-database/get_wire_fee.h" +#include "merchant-database/get_exchange_wire_fee.h" #include "merchant-database/update_to_contract_terms_paid.h" #include "merchant-database/update_to_contract_terms_wired.h" #include "merchant-database/preflight.h" @@ -150,7 +150,7 @@ #include "merchant-database/get_account.h" #include "merchant-database/get_account_by_uri.h" #include "merchant-database/iterate_accounts.h" -#include "merchant-database/iterate_accounts_by_exchange.h" +#include "merchant-database/iterate_exchange_accounts.h" #include "merchant-database/iterate_accounts_by_instance.h" #include "merchant-database/iterate_all_donau_instances.h" #include "merchant-database/get_category.h" @@ -163,10 +163,10 @@ #include "merchant-database/get_login_token.h" #include "merchant-database/get_money_pot.h" #include "merchant-database/iterate_money_pots.h" -#include "merchant-database/iterate_open_transfers.h" -#include "merchant-database/iterate_order_blinded_sigs.h" -#include "merchant-database/get_otp.h" -#include "merchant-database/get_otp_serial.h" +#include "merchant-database/iterate_open_expected_transfers.h" +#include "merchant-database/iterate_order_token_blinded_sigs.h" +#include "merchant-database/get_otp_device.h" +#include "merchant-database/get_otp_device_serial.h" #include "merchant-database/iterate_product_groups.h" #include "merchant-database/get_report.h" #include "merchant-database/iterate_reports.h" @@ -175,20 +175,20 @@ #include "merchant-database/set_instance.h" #include "merchant-database/do_solve_mfa_challenge.h" #include "merchant-database/start.h" -#include "merchant-database/insert_wire_fee.h" +#include "merchant-database/insert_exchange_wire_fee.h" #include "merchant-database/delete_inventory_lock.h" #include "merchant-database/update_account.h" #include "merchant-database/update_category.h" -#include "merchant-database/update_contract_session.h" +#include "merchant-database/update_contract_terms_session.h" #include "merchant-database/update_contract_terms.h" -#include "merchant-database/update_deposit_confirmation_status.h" +#include "merchant-database/update_deposit_settlement_status.h" #include "merchant-database/update_donau_instance.h" #include "merchant-database/update_donau_instance_receipts_amount.h" #include "merchant-database/update_instance.h" #include "merchant-database/update_instance_auth.h" #include "merchant-database/update_mfa_challenge.h" #include "merchant-database/update_money_pot.h" -#include "merchant-database/update_otp.h" +#include "merchant-database/update_otp_device.h" #include "merchant-database/update_pending_webhook.h" #include "merchant-database/update_product.h" #include "merchant-database/update_product_group.h" @@ -196,10 +196,10 @@ #include "merchant-database/update_report_status.h" #include "merchant-database/update_template.h" #include "merchant-database/update_token_family.h" -#include "merchant-database/update_transfer_status.h" +#include "merchant-database/update_expected_transfer_status.h" #include "merchant-database/update_unit.h" #include "merchant-database/update_webhook.h" -#include "merchant-database/update_wirewatch_progress.h" +#include "merchant-database/update_account_last_bank_serial.h" #include "merchant-database/insert_donau_keys.h" #endif diff --git a/src/include/merchant-database/delete_otp.h b/src/include/merchant-database/delete_otp.h @@ -1,44 +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/delete_otp.h - * @brief implementation of the delete_otp function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_DELETE_OTP_H -#define MERCHANT_DATABASE_DELETE_OTP_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Delete information about an OTP device. - * - * @param pg database context - * @param instance_id instance to delete OTP device of - * @param otp_id otp device to delete - * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS - * if template unknown. - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_delete_otp (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *otp_id); - -#endif diff --git a/src/include/merchant-database/delete_otp_device.h b/src/include/merchant-database/delete_otp_device.h @@ -0,0 +1,44 @@ +/* + 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/delete_otp_device.h + * @brief implementation of the delete_otp_device function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_DELETE_OTP_DEVICE_H +#define MERCHANT_DATABASE_DELETE_OTP_DEVICE_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Delete information about an OTP device. + * + * @param pg database context + * @param instance_id instance to delete OTP device of + * @param otp_id otp device to delete + * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS + * if template unknown. + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_delete_otp_device (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *otp_id); + +#endif diff --git a/src/include/merchant-database/get_donau_instance_by_url.h b/src/include/merchant-database/get_donau_instance_by_url.h @@ -0,0 +1,63 @@ +/* + 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/get_donau_instance_by_url.h + * @brief Header for retrieving Donau charity_id and corresponding private key + * by Donau URL. + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ + +#ifndef MERCHANT_DATABASE_GET_DONAU_INSTANCE_BY_URL_H +#define MERCHANT_DATABASE_GET_DONAU_INSTANCE_BY_URL_H + +#include "platform.h" +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "donau/donau_service.h" +#include "merchantdb_lib.h" + + +/** + * Retrieve the charity’s ID and private key for a given Donau URL. + * + * @param pg database context + * @param instance_id the instance ID of the merchant + * @param donau_url base URL of the Donau instance + * @param[out] charity_id set to the `charity_id` from `merchant_donau_instances` + * @param[out] charity_max_per_year set to the maximum amount that can be donated + * per year to this charity + * @param[out] charity_receipts_to_date set to the total amount of receipts + * issued to date + * @param[out] donau_keys_json set to the JSON object containing the Donau keys + * @param[out] donau_instance_serial set to the serial number of the Donau instance in DB + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_donau_instance_by_url ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *donau_url, + uint64_t *charity_id, + struct TALER_Amount *charity_max_per_year, + struct TALER_Amount *charity_receipts_to_date, + json_t **donau_keys_json, + uint64_t *donau_instance_serial); + +#endif /* MERCHANT_DATABASE_GET_DONAU_INSTANCE_BY_URL_H */ diff --git a/src/include/merchant-database/get_exchange_wire_fee.h b/src/include/merchant-database/get_exchange_wire_fee.h @@ -0,0 +1,54 @@ +/* + 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/get_exchange_wire_fee.h + * @brief implementation of the get_exchange_wire_fee function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_GET_EXCHANGE_WIRE_FEE_H +#define MERCHANT_DATABASE_GET_EXCHANGE_WIRE_FEE_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Obtain information about wire fees charged by an exchange, + * including signature (so we have proof). + * + * @param pg database context + * @param master_pub public key of the exchange + * @param wire_method the wire method + * @param contract_date date of the contract to use for the lookup + * @param[out] fees wire fees charged + * @param[out] start_date start of fee being used + * @param[out] end_date end of fee being used + * @param[out] master_sig signature of exchange over fee structure + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_exchange_wire_fee (struct TALER_MERCHANTDB_PostgresContext *pg, + const struct TALER_MasterPublicKeyP *master_pub, + const char *wire_method, + struct GNUNET_TIME_Timestamp contract_date, + struct TALER_WireFeeSet *fees, + struct GNUNET_TIME_Timestamp *start_date, + struct GNUNET_TIME_Timestamp *end_date, + struct TALER_MasterSignatureP *master_sig); + +#endif diff --git a/src/include/merchant-database/get_order_charity.h b/src/include/merchant-database/get_order_charity.h @@ -1,63 +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/get_order_charity.h - * @brief Header for retrieving Donau charity_id and corresponding private key - * by Donau URL. - * @author Bohdan Potuzhnyi - * @author Vlada Svirsh - */ - -#ifndef MERCHANT_DATABASE_GET_ORDER_CHARITY_H -#define MERCHANT_DATABASE_GET_ORDER_CHARITY_H - -#include "platform.h" -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "donau/donau_service.h" -#include "merchantdb_lib.h" - - -/** - * Retrieve the charity’s ID and private key for a given Donau URL. - * - * @param pg database context - * @param instance_id the instance ID of the merchant - * @param donau_url base URL of the Donau instance - * @param[out] charity_id set to the `charity_id` from `merchant_donau_instances` - * @param[out] charity_max_per_year set to the maximum amount that can be donated - * per year to this charity - * @param[out] charity_receipts_to_date set to the total amount of receipts - * issued to date - * @param[out] donau_keys_json set to the JSON object containing the Donau keys - * @param[out] donau_instance_serial set to the serial number of the Donau instance in DB - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_get_order_charity ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *donau_url, - uint64_t *charity_id, - struct TALER_Amount *charity_max_per_year, - struct TALER_Amount *charity_receipts_to_date, - json_t **donau_keys_json, - uint64_t *donau_instance_serial); - -#endif /* MERCHANT_DATABASE_GET_ORDER_CHARITY_H */ diff --git a/src/include/merchant-database/get_otp.h b/src/include/merchant-database/get_otp.h @@ -1,46 +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/get_otp.h - * @brief implementation of the get_otp function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_GET_OTP_H -#define MERCHANT_DATABASE_GET_OTP_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Lookup details about an OTP device. - * - * @param pg database context - * @param instance_id instance to lookup template for - * @param otp_id OTP device to lookup - * @param[out] td set to the OTP device details on success, can be NULL - * (in that case we only want to check if the template exists) - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_get_otp (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *otp_id, - struct TALER_MERCHANTDB_OtpDeviceDetails *td); - -#endif diff --git a/src/include/merchant-database/get_otp_device.h b/src/include/merchant-database/get_otp_device.h @@ -0,0 +1,46 @@ +/* + 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/get_otp_device.h + * @brief implementation of the get_otp_device function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_GET_OTP_DEVICE_H +#define MERCHANT_DATABASE_GET_OTP_DEVICE_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Lookup details about an OTP device. + * + * @param pg database context + * @param instance_id instance to lookup template for + * @param otp_id OTP device to lookup + * @param[out] td set to the OTP device details on success, can be NULL + * (in that case we only want to check if the template exists) + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_otp_device (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *otp_id, + struct TALER_MERCHANTDB_OtpDeviceDetails *td); + +#endif diff --git a/src/include/merchant-database/get_otp_device_serial.h b/src/include/merchant-database/get_otp_device_serial.h @@ -0,0 +1,44 @@ +/* + 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/get_otp_device_serial.h + * @brief implementation of the get_otp_device_serial function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_GET_OTP_DEVICE_SERIAL_H +#define MERCHANT_DATABASE_GET_OTP_DEVICE_SERIAL_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Lookup serial number of an OTP device. + * + * @param pg database context + * @param instance_id instance to lookup template for + * @param otp_id OTP device to lookup + * @param[out] serial set to the OTP device serial number * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_otp_device_serial (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *otp_id, + uint64_t *serial); + +#endif diff --git a/src/include/merchant-database/get_otp_serial.h b/src/include/merchant-database/get_otp_serial.h @@ -1,44 +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/get_otp_serial.h - * @brief implementation of the get_otp_serial function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_GET_OTP_SERIAL_H -#define MERCHANT_DATABASE_GET_OTP_SERIAL_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Lookup serial number of an OTP device. - * - * @param pg database context - * @param instance_id instance to lookup template for - * @param otp_id OTP device to lookup - * @param[out] serial set to the OTP device serial number * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_get_otp_serial (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *otp_id, - uint64_t *serial); - -#endif diff --git a/src/include/merchant-database/get_wire_fee.h b/src/include/merchant-database/get_wire_fee.h @@ -1,54 +0,0 @@ -/* - 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/get_wire_fee.h - * @brief implementation of the get_wire_fee function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_GET_WIRE_FEE_H -#define MERCHANT_DATABASE_GET_WIRE_FEE_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Obtain information about wire fees charged by an exchange, - * including signature (so we have proof). - * - * @param pg database context - * @param master_pub public key of the exchange - * @param wire_method the wire method - * @param contract_date date of the contract to use for the lookup - * @param[out] fees wire fees charged - * @param[out] start_date start of fee being used - * @param[out] end_date end of fee being used - * @param[out] master_sig signature of exchange over fee structure - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_get_wire_fee (struct TALER_MERCHANTDB_PostgresContext *pg, - const struct TALER_MasterPublicKeyP *master_pub, - const char *wire_method, - struct GNUNET_TIME_Timestamp contract_date, - struct TALER_WireFeeSet *fees, - struct GNUNET_TIME_Timestamp *start_date, - struct GNUNET_TIME_Timestamp *end_date, - struct TALER_MasterSignatureP *master_sig); - -#endif diff --git a/src/include/merchant-database/insert_exchange_signing_key.h b/src/include/merchant-database/insert_exchange_signing_key.h @@ -0,0 +1,52 @@ +/* + 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/insert_exchange_signing_key.h + * @brief implementation of the insert_exchange_signing_key function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_INSERT_EXCHANGE_SIGNING_KEY_H +#define MERCHANT_DATABASE_INSERT_EXCHANGE_SIGNING_KEY_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Insert an exchange signing key into our database. + * + * @param pg database context + * @param master_pub exchange master public key used for @a master_sig + * @param exchange_pub exchange signing key to insert + * @param start_date when does the signing key become valid + * @param expire_date when does the signing key stop being used + * @param end_date when does the signing key become void as proof + * @param master_sig signature of @a master_pub over the @a exchange_pub and the dates + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_insert_exchange_signing_key (struct TALER_MERCHANTDB_PostgresContext *pg, + const struct TALER_MasterPublicKeyP *master_pub, + const struct + TALER_ExchangePublicKeyP *exchange_pub, + struct GNUNET_TIME_Timestamp start_date, + struct GNUNET_TIME_Timestamp expire_date, + struct GNUNET_TIME_Timestamp end_date, + const struct + TALER_MasterSignatureP *master_sig); + +#endif diff --git a/src/include/merchant-database/insert_exchange_signkey.h b/src/include/merchant-database/insert_exchange_signkey.h @@ -1,52 +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/insert_exchange_signkey.h - * @brief implementation of the insert_exchange_signkey function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_INSERT_EXCHANGE_SIGNKEY_H -#define MERCHANT_DATABASE_INSERT_EXCHANGE_SIGNKEY_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Insert an exchange signing key into our database. - * - * @param pg database context - * @param master_pub exchange master public key used for @a master_sig - * @param exchange_pub exchange signing key to insert - * @param start_date when does the signing key become valid - * @param expire_date when does the signing key stop being used - * @param end_date when does the signing key become void as proof - * @param master_sig signature of @a master_pub over the @a exchange_pub and the dates - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_insert_exchange_signkey (struct TALER_MERCHANTDB_PostgresContext *pg, - const struct TALER_MasterPublicKeyP *master_pub, - const struct - TALER_ExchangePublicKeyP *exchange_pub, - struct GNUNET_TIME_Timestamp start_date, - struct GNUNET_TIME_Timestamp expire_date, - struct GNUNET_TIME_Timestamp end_date, - const struct - TALER_MasterSignatureP *master_sig); - -#endif diff --git a/src/include/merchant-database/insert_exchange_wire_fee.h b/src/include/merchant-database/insert_exchange_wire_fee.h @@ -0,0 +1,52 @@ +/* + 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/insert_exchange_wire_fee.h + * @brief implementation of the postgres_store_wire_fee_by_exchange function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_INSERT_EXCHANGE_WIRE_FEE_H +#define MERCHANT_DATABASE_INSERT_EXCHANGE_WIRE_FEE_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Store information about wire fees charged by an exchange, + * including signature (so we have proof). + * + * @param pg database context + * @param master_pub public key of the exchange + * @param h_wire_method hash of wire method + * @param fees the fee charged + * @param start_date start of fee being used + * @param end_date end of fee being used + * @param master_sig signature of exchange over fee structure + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_insert_exchange_wire_fee (struct TALER_MERCHANTDB_PostgresContext *pg, + const struct TALER_MasterPublicKeyP *master_pub, + const struct GNUNET_HashCode *h_wire_method, + const struct TALER_WireFeeSet *fees, + struct GNUNET_TIME_Timestamp start_date, + struct GNUNET_TIME_Timestamp end_date, + const struct TALER_MasterSignatureP *master_sig); + +#endif diff --git a/src/include/merchant-database/insert_order_blinded_sigs.h b/src/include/merchant-database/insert_order_blinded_sigs.h @@ -1,47 +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/insert_order_blinded_sigs.h - * @brief Implementation of the insert blinded sigs by order_id function for Postgres - * @author Bohdan Potuzhnyi - */ -#ifndef MERCHANT_DATABASE_INSERT_ORDER_BLINDED_SIGS_H -#define MERCHANT_DATABASE_INSERT_ORDER_BLINDED_SIGS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Store (or update) the Donau *blinded* signature JSON for an order. - * - * @param pg database context - * @param order_id business-level order identifier - * @param i index of the @a blinded_sig in the output token array - * @param hash hash of the @a blinded_sig - * @param blind_sig blinded signature for the token outputs - * @return GNUNET_DB status code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_insert_order_blinded_sigs (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *order_id, - uint32_t i, - const struct GNUNET_HashCode *hash, - const struct GNUNET_CRYPTO_BlindedSignature *blind_sig); - -#endif diff --git a/src/include/merchant-database/insert_order_token_blinded_sig.h b/src/include/merchant-database/insert_order_token_blinded_sig.h @@ -0,0 +1,48 @@ +/* + 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/insert_order_token_blinded_sig.h + * @brief Implementation of the insert blinded sigs by order_id function for Postgres + * @author Bohdan Potuzhnyi + */ +#ifndef MERCHANT_DATABASE_INSERT_ORDER_TOKEN_BLINDED_SIG_H +#define MERCHANT_DATABASE_INSERT_ORDER_TOKEN_BLINDED_SIG_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Store (or update) the Donau *blinded* signature JSON for an order. + * + * @param pg database context + * @param order_id business-level order identifier + * @param i index of the @a blinded_sig in the output token array + * @param hash hash of the @a blinded_sig + * @param blind_sig blinded signature for the token outputs + * @return GNUNET_DB status code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_insert_order_token_blinded_sig (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *order_id, + uint32_t i, + const struct GNUNET_HashCode *hash, + const struct GNUNET_CRYPTO_BlindedSignature * + blind_sig); + +#endif diff --git a/src/include/merchant-database/insert_otp.h b/src/include/merchant-database/insert_otp.h @@ -1,46 +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/insert_otp.h - * @brief implementation of the insert_otp function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_INSERT_OTP_H -#define MERCHANT_DATABASE_INSERT_OTP_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Insert details about a particular OTP device. - * - * @param pg database context - * @param instance_id instance to insert OTP device for - * @param otp_id otp identifier of OTP device to insert - * @param td the OTP device details to insert - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_insert_otp (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *otp_id, - const struct TALER_MERCHANTDB_OtpDeviceDetails *td); - - -#endif diff --git a/src/include/merchant-database/insert_otp_device.h b/src/include/merchant-database/insert_otp_device.h @@ -0,0 +1,46 @@ +/* + 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/insert_otp_device.h + * @brief implementation of the insert_otp_device function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_INSERT_OTP_DEVICE_H +#define MERCHANT_DATABASE_INSERT_OTP_DEVICE_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Insert details about a particular OTP device. + * + * @param pg database context + * @param instance_id instance to insert OTP device for + * @param otp_id otp identifier of OTP device to insert + * @param td the OTP device details to insert + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_insert_otp_device (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *otp_id, + const struct TALER_MERCHANTDB_OtpDeviceDetails *td); + + +#endif diff --git a/src/include/merchant-database/insert_spent_token.h b/src/include/merchant-database/insert_spent_token.h @@ -1,47 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2024 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/insert_spent_token.h - * @brief implementation of the insert_spent_token function for Postgres - * @author Christian Blättler - */ -#ifndef MERCHANT_DATABASE_INSERT_SPENT_TOKEN_H -#define MERCHANT_DATABASE_INSERT_SPENT_TOKEN_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * @param pg database context - * @param h_contract_terms hash of the contract the token was used for - * @param h_issue_pub hash of the token issue public key - * @param use_pub token use public key - * @param use_sig token use signature - * @param issue_sig token issue signature - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_insert_spent_token (struct TALER_MERCHANTDB_PostgresContext *pg, - const struct TALER_PrivateContractHashP *h_contract_terms, - const struct TALER_TokenIssuePublicKeyHashP *h_issue_pub, - const struct TALER_TokenUsePublicKeyP *use_pub, - const struct TALER_TokenUseSignatureP *use_sig, - const struct TALER_TokenIssueSignature *issue_sig); - -#endif diff --git a/src/include/merchant-database/insert_used_token.h b/src/include/merchant-database/insert_used_token.h @@ -0,0 +1,47 @@ +/* + This file is part of TALER + Copyright (C) 2024 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/insert_used_token.h + * @brief implementation of the insert_used_token function for Postgres + * @author Christian Blättler + */ +#ifndef MERCHANT_DATABASE_INSERT_USED_TOKEN_H +#define MERCHANT_DATABASE_INSERT_USED_TOKEN_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * @param pg database context + * @param h_contract_terms hash of the contract the token was used for + * @param h_issue_pub hash of the token issue public key + * @param use_pub token use public key + * @param use_sig token use signature + * @param issue_sig token issue signature + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_insert_used_token (struct TALER_MERCHANTDB_PostgresContext *pg, + const struct TALER_PrivateContractHashP *h_contract_terms, + const struct TALER_TokenIssuePublicKeyHashP *h_issue_pub, + const struct TALER_TokenUsePublicKeyP *use_pub, + const struct TALER_TokenUseSignatureP *use_sig, + const struct TALER_TokenIssueSignature *issue_sig); + +#endif diff --git a/src/include/merchant-database/insert_wire_fee.h b/src/include/merchant-database/insert_wire_fee.h @@ -1,52 +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/insert_wire_fee.h - * @brief implementation of the postgres_store_wire_fee_by_exchange function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_INSERT_WIRE_FEE_H -#define MERCHANT_DATABASE_INSERT_WIRE_FEE_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Store information about wire fees charged by an exchange, - * including signature (so we have proof). - * - * @param pg database context - * @param master_pub public key of the exchange - * @param h_wire_method hash of wire method - * @param fees the fee charged - * @param start_date start of fee being used - * @param end_date end of fee being used - * @param master_sig signature of exchange over fee structure - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_insert_wire_fee (struct TALER_MERCHANTDB_PostgresContext *pg, - const struct TALER_MasterPublicKeyP *master_pub, - const struct GNUNET_HashCode *h_wire_method, - const struct TALER_WireFeeSet *fees, - struct GNUNET_TIME_Timestamp start_date, - struct GNUNET_TIME_Timestamp end_date, - const struct TALER_MasterSignatureP *master_sig); - -#endif diff --git a/src/include/merchant-database/iterate_accounts_by_exchange.h b/src/include/merchant-database/iterate_accounts_by_exchange.h @@ -1,65 +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/iterate_accounts_by_exchange.h - * @brief implementation of the iterate_accounts_by_exchange function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_ITERATE_ACCOUNTS_BY_EXCHANGE_H -#define MERCHANT_DATABASE_ITERATE_ACCOUNTS_BY_EXCHANGE_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * If the given account is feasible, add it to the array - * of accounts we return. - * - * @param cls closure - * @param payto_uri URI of the account - * @param conversion_url URL of a conversion service - * @param debit_restrictions restrictions for debits from account - * @param credit_restrictions restrictions for credits to account - * @param master_sig signature affirming the account - */ -typedef void -(*TALER_MERCHANTDB_ExchangeAccountCallback) ( - void *cls, - struct TALER_FullPayto payto_uri, - const char *conversion_url, - const json_t *debit_restrictions, - const json_t *credit_restrictions, - const struct TALER_MasterSignatureP *master_sig); - -/** - * Return information about wire accounts of an exchange. - * - * @param pg database context - * @param master_pub public key of the exchange - * @param cb function to call on each account - * @param cb_cls closure for @a cb - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_accounts_by_exchange ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const struct TALER_MasterPublicKeyP *master_pub, - TALER_MERCHANTDB_ExchangeAccountCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/iterate_all_webhooks.h b/src/include/merchant-database/iterate_all_webhooks.h @@ -1,73 +0,0 @@ -/* - 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/iterate_all_webhooks.h - * @brief implementation of the iterate_all_webhooks function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_ITERATE_ALL_WEBHOOKS_H -#define MERCHANT_DATABASE_ITERATE_ALL_WEBHOOKS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Typically called by `lookup_all_webhooks`. - * - * @param cls a `json_t *` JSON array to build - * @param webhook_serial reference to the configured webhook template. - * @param next_attempt is the time we should make the next request to the webhook. - * @param retries how often have we tried this request to the webhook. - * @param url to make request to - * @param http_method use for the webhook - * @param header of the webhook - * @param body of the webhook - */ -typedef void -(*TALER_MERCHANTDB_AllWebhooksCallback)( - void *cls, - uint64_t webhook_serial, - struct GNUNET_TIME_Absolute - next_attempt, - uint32_t retries, - const char *url, - const char *http_method, - const char *header, - const char *body); - - -/** - * Lookup all the webhooks in the ALL 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 ALL webhook that it is started with this minimum row. - * @param max_results to see the list of the ALL webhook that it is end with this max results. - * @param cb ALL webhook callback - * @param cb_cls callback closure - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_all_webhooks (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t min_row, - uint32_t max_results, - TALER_MERCHANTDB_AllWebhooksCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/iterate_exchange_accounts.h b/src/include/merchant-database/iterate_exchange_accounts.h @@ -0,0 +1,65 @@ +/* + 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/iterate_exchange_accounts.h + * @brief implementation of the iterate_exchange_accounts function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_EXCHANGE_ACCOUNTS_H +#define MERCHANT_DATABASE_ITERATE_EXCHANGE_ACCOUNTS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * If the given account is feasible, add it to the array + * of accounts we return. + * + * @param cls closure + * @param payto_uri URI of the account + * @param conversion_url URL of a conversion service + * @param debit_restrictions restrictions for debits from account + * @param credit_restrictions restrictions for credits to account + * @param master_sig signature affirming the account + */ +typedef void +(*TALER_MERCHANTDB_ExchangeAccountCallback) ( + void *cls, + struct TALER_FullPayto payto_uri, + const char *conversion_url, + const json_t *debit_restrictions, + const json_t *credit_restrictions, + const struct TALER_MasterSignatureP *master_sig); + +/** + * Return information about wire accounts of an exchange. + * + * @param pg database context + * @param master_pub public key of the exchange + * @param cb function to call on each account + * @param cb_cls closure for @a cb + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_exchange_accounts ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const struct TALER_MasterPublicKeyP *master_pub, + TALER_MERCHANTDB_ExchangeAccountCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_open_expected_transfers.h b/src/include/merchant-database/iterate_open_expected_transfers.h @@ -0,0 +1,71 @@ +/* + 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/iterate_open_expected_transfers.h + * @brief implementation of the iterate_open_expected_transfers function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_OPEN_EXPECTED_TRANSFERS_H +#define MERCHANT_DATABASE_ITERATE_OPEN_EXPECTED_TRANSFERS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/* Callback typedefs */ +/** + * Function called with information about wire transfers + * that taler-merchant-exchange still needs to process. + * + * @param cls closure + * @param rowid row of the transfer in the merchant database + * @param instance_id instance that received the transfer + * @param exchange_url URL of the exchange that is making the deposit + * @param payto_uri account of the merchant that received the transfer + * @param wtid wire transfer subject identifying the aggregation + * @param next_attempt when should we next try to interact with the exchange + */ +typedef void +(*TALER_MERCHANTDB_OpenTransferCallback)( + void *cls, + uint64_t rowid, + const char *instance_id, + const char *exchange_url, + struct TALER_FullPayto payto_uri, + const struct TALER_WireTransferIdentifierRawP *wtid, + struct GNUNET_TIME_Absolute next_attempt); + +/** + * Retrieve wire transfer details of wire details + * that taler-merchant-exchange still needs to + * investigate. + * + * @param pg database context + * @param limit maximum number of results to return + * @param cb function called with the wire transfer data + * @param cb_cls closure for @a cb + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_open_expected_transfers (struct TALER_MERCHANTDB_PostgresContext *pg, + uint64_t limit, + TALER_MERCHANTDB_OpenTransferCallback cb, + void *cb_cls); + + +#endif diff --git a/src/include/merchant-database/iterate_open_transfers.h b/src/include/merchant-database/iterate_open_transfers.h @@ -1,71 +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/iterate_open_transfers.h - * @brief implementation of the iterate_open_transfers function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_ITERATE_OPEN_TRANSFERS_H -#define MERCHANT_DATABASE_ITERATE_OPEN_TRANSFERS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/* Callback typedefs */ -/** - * Function called with information about wire transfers - * that taler-merchant-exchange still needs to process. - * - * @param cls closure - * @param rowid row of the transfer in the merchant database - * @param instance_id instance that received the transfer - * @param exchange_url URL of the exchange that is making the deposit - * @param payto_uri account of the merchant that received the transfer - * @param wtid wire transfer subject identifying the aggregation - * @param next_attempt when should we next try to interact with the exchange - */ -typedef void -(*TALER_MERCHANTDB_OpenTransferCallback)( - void *cls, - uint64_t rowid, - const char *instance_id, - const char *exchange_url, - struct TALER_FullPayto payto_uri, - const struct TALER_WireTransferIdentifierRawP *wtid, - struct GNUNET_TIME_Absolute next_attempt); - -/** - * Retrieve wire transfer details of wire details - * that taler-merchant-exchange still needs to - * investigate. - * - * @param pg database context - * @param limit maximum number of results to return - * @param cb function called with the wire transfer data - * @param cb_cls closure for @a cb - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_open_transfers (struct TALER_MERCHANTDB_PostgresContext *pg, - uint64_t limit, - TALER_MERCHANTDB_OpenTransferCallback cb, - void *cb_cls); - - -#endif diff --git a/src/include/merchant-database/iterate_order_blinded_sigs.h b/src/include/merchant-database/iterate_order_blinded_sigs.h @@ -1,61 +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/iterate_order_blinded_sigs.h - * @brief Implementation of the select blinded sigs by order_id function for Postgres - * @author Bohdan Potuzhnyi - */ -#ifndef MERCHANT_DATABASE_ITERATE_ORDER_BLINDED_SIGS_H -#define MERCHANT_DATABASE_ITERATE_ORDER_BLINDED_SIGS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/* Callback typedefs */ -/** - * Typically called by `select_order_blinded_sigs` - * - * @param cls closure - * @param hash hash of the token - * @param blinded_sig blinded signature for the token - */ -typedef void -(*TALER_MERCHANTDB_BlindedSigCallback)( - void *cls, - struct GNUNET_HashCode *hash, - struct GNUNET_CRYPTO_BlindedSignature *blinded_sig); - -/** - * Look up the Donau *blinded‐signature* blob we already stored for an - * order (identified by its human-readable `order_id`) and hand it back - * to the caller. - * - * @param pg database context - * @param order_id business-level order identifier - * @param cb callback to be called with the blinded signature and hash - * @param cb_cls callback closure - * @return GNUNET_DB status code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_order_blinded_sigs (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *order_id, - TALER_MERCHANTDB_BlindedSigCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/iterate_order_token_blinded_sigs.h b/src/include/merchant-database/iterate_order_token_blinded_sigs.h @@ -0,0 +1,61 @@ +/* + 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/iterate_order_token_blinded_sigs.h + * @brief Implementation of the select blinded sigs by order_id function for Postgres + * @author Bohdan Potuzhnyi + */ +#ifndef MERCHANT_DATABASE_ITERATE_ORDER_TOKEN_BLINDED_SIGS_H +#define MERCHANT_DATABASE_ITERATE_ORDER_TOKEN_BLINDED_SIGS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/* Callback typedefs */ +/** + * Typically called by `select_order_blinded_sigs` + * + * @param cls closure + * @param hash hash of the token + * @param blinded_sig blinded signature for the token + */ +typedef void +(*TALER_MERCHANTDB_BlindedSigCallback)( + void *cls, + struct GNUNET_HashCode *hash, + struct GNUNET_CRYPTO_BlindedSignature *blinded_sig); + +/** + * Look up the Donau *blinded‐signature* blob we already stored for an + * order (identified by its human-readable `order_id`) and hand it back + * to the caller. + * + * @param pg database context + * @param order_id business-level order identifier + * @param cb callback to be called with the blinded signature and hash + * @param cb_cls callback closure + * @return GNUNET_DB status code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_order_token_blinded_sigs (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *order_id, + TALER_MERCHANTDB_BlindedSigCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_pending_reports.h b/src/include/merchant-database/iterate_pending_reports.h @@ -0,0 +1,79 @@ +/* + 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/iterate_pending_reports.h + * @brief implementation of the iterate_pending_reports function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_PENDING_REPORTS_H +#define MERCHANT_DATABASE_ITERATE_PENDING_REPORTS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "taler/taler_merchant_util.h" +#include "merchantdb_lib.h" + + +/** + * Typically called by `lookup_reports_pending`. + * + * @param cls closure + * @param instance_id name of the instance + * @param report_id serial number of the report + * @param report_program_section configuration section of program + * for report generation + * @param report_description text describing the report + * @param mime_type mime type to request + * @param report_token token to authorize access to the data source + * @param target_address where to send report data + * @param frequency report frequency + * @param frequency_shift how much to shift the report time from a + * multiple of the report @a frequency + * @param next_transmission when is the next transmission of this report + * due + * @param one_shot true if the report should be removed from the + * list after generation instead of being repeated + */ +typedef void +(*TALER_MERCHANTDB_ReportsPendingCallback)( + void *cls, + const char *instance_id, + uint64_t report_id, + const char *report_program_section, + const char *report_description, + const char *mime_type, + const struct TALER_MERCHANT_ReportToken *report_token, + const char *target_address, + struct GNUNET_TIME_Relative frequency, + struct GNUNET_TIME_Relative frequency_shift, + struct GNUNET_TIME_Absolute next_transmission, + bool one_shot); + +/** + * Lookup all of the reports pending for the given backend. + * + * @param pg database context + * @param cb function to call on all reports found + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_pending_reports ( + struct TALER_MERCHANTDB_PostgresContext *pg, + TALER_MERCHANTDB_ReportsPendingCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_pending_webhooks_above_serial_id.h b/src/include/merchant-database/iterate_pending_webhooks_above_serial_id.h @@ -0,0 +1,74 @@ +/* + 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/iterate_pending_webhooks_above_serial_id.h + * @brief implementation of the iterate_pending_webhooks_above_serial_id function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_ITERATE_PENDING_WEBHOOKS_ABOVE_SERIAL_ID_H +#define MERCHANT_DATABASE_ITERATE_PENDING_WEBHOOKS_ABOVE_SERIAL_ID_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Typically called by `lookup_all_webhooks`. + * + * @param cls a `json_t *` JSON array to build + * @param webhook_serial reference to the configured webhook template. + * @param next_attempt is the time we should make the next request to the webhook. + * @param retries how often have we tried this request to the webhook. + * @param url to make request to + * @param http_method use for the webhook + * @param header of the webhook + * @param body of the webhook + */ +typedef void +(*TALER_MERCHANTDB_AllWebhooksCallback)( + void *cls, + uint64_t webhook_serial, + struct GNUNET_TIME_Absolute + next_attempt, + uint32_t retries, + const char *url, + const char *http_method, + const char *header, + const char *body); + + +/** + * Lookup all the webhooks in the ALL 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 ALL webhook that it is started with this minimum row. + * @param max_results to see the list of the ALL webhook that it is end with this max results. + * @param cb ALL webhook callback + * @param cb_cls callback closure + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_pending_webhooks_above_serial_id (struct TALER_MERCHANTDB_PostgresContext * + pg, + const char *instance_id, + uint64_t min_row, + uint32_t max_results, + TALER_MERCHANTDB_AllWebhooksCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_reports_pending.h b/src/include/merchant-database/iterate_reports_pending.h @@ -1,79 +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/iterate_reports_pending.h - * @brief implementation of the iterate_reports_pending function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_ITERATE_REPORTS_PENDING_H -#define MERCHANT_DATABASE_ITERATE_REPORTS_PENDING_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "taler/taler_merchant_util.h" -#include "merchantdb_lib.h" - - -/** - * Typically called by `lookup_reports_pending`. - * - * @param cls closure - * @param instance_id name of the instance - * @param report_id serial number of the report - * @param report_program_section configuration section of program - * for report generation - * @param report_description text describing the report - * @param mime_type mime type to request - * @param report_token token to authorize access to the data source - * @param target_address where to send report data - * @param frequency report frequency - * @param frequency_shift how much to shift the report time from a - * multiple of the report @a frequency - * @param next_transmission when is the next transmission of this report - * due - * @param one_shot true if the report should be removed from the - * list after generation instead of being repeated - */ -typedef void -(*TALER_MERCHANTDB_ReportsPendingCallback)( - void *cls, - const char *instance_id, - uint64_t report_id, - const char *report_program_section, - const char *report_description, - const char *mime_type, - const struct TALER_MERCHANT_ReportToken *report_token, - const char *target_address, - struct GNUNET_TIME_Relative frequency, - struct GNUNET_TIME_Relative frequency_shift, - struct GNUNET_TIME_Absolute next_transmission, - bool one_shot); - -/** - * Lookup all of the reports pending for the given backend. - * - * @param pg database context - * @param cb function to call on all reports found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_reports_pending ( - struct TALER_MERCHANTDB_PostgresContext *pg, - TALER_MERCHANTDB_ReportsPendingCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/iterate_spent_tokens_by_order.h b/src/include/merchant-database/iterate_spent_tokens_by_order.h @@ -1,67 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2024 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/iterate_spent_tokens_by_order.h - * @brief implementation of the iterate_spent_tokens_by_order function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_ITERATE_SPENT_TOKENS_BY_ORDER_H -#define MERCHANT_DATABASE_ITERATE_SPENT_TOKENS_BY_ORDER_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Function called with information about a token that was used. - * - * @param cls closure - * @param spent_token_serial which used token is this about - * @param h_contract_terms hash of the contract terms this token was used on - * @param h_issue_pub hash of the token issue public key - * @param use_pub token use public key - * @param use_sig token use signature - * @param issue_sig unblinded token issue signature - */ -typedef void -(*TALER_MERCHANTDB_UsedTokensCallback)( - void *cls, - uint64_t spent_token_serial, - const struct TALER_PrivateContractHashP *h_contract_terms, - const struct TALER_TokenIssuePublicKeyHashP *h_issue_pub, - const struct TALER_TokenUsePublicKeyP *use_pub, - const struct TALER_TokenUseSignatureP *use_sig, - const struct TALER_TokenIssueSignature *issue_sig); - -/** - * Retrieve details about tokens that were used for an order. - * - * @param pg database context - * @param order_serial identifies the order - * @param cb function to call for each used token - * @param cb_cls closure for @a cb - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_spent_tokens_by_order ( - struct TALER_MERCHANTDB_PostgresContext *pg, - uint64_t order_serial, - TALER_MERCHANTDB_UsedTokensCallback cb, - void *cb_cls); - - -#endif diff --git a/src/include/merchant-database/iterate_statistic_bucket_amounts.h b/src/include/merchant-database/iterate_statistic_bucket_amounts.h @@ -0,0 +1,68 @@ +/* + 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/iterate_statistic_bucket_amounts.h + * @brief implementation of the iterate_statistic_bucket_amounts function for Postgres + * @author Martin Schanzenbach + */ +#ifndef MERCHANT_DATABASE_ITERATE_STATISTIC_BUCKET_AMOUNTS_H +#define MERCHANT_DATABASE_ITERATE_STATISTIC_BUCKET_AMOUNTS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + +/** + * 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]); + +/** + * Lookup statistics where the values are amounts. + * + * @param pg database context + * @param instance_id instance to lookup statistics for + * @param slug slug to lookup statistics for + * @param cb function to call on all statistics found + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_statistic_bucket_amounts ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *slug, + TALER_MERCHANTDB_AmountByBucketStatisticsCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_statistic_bucket_amounts_by_range.h b/src/include/merchant-database/iterate_statistic_bucket_amounts_by_range.h @@ -0,0 +1,94 @@ +/* + 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/iterate_statistic_bucket_amounts_by_range.h + * @brief implementation of the iterate_statistic_bucket_amounts_by_range function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_STATISTIC_BUCKET_AMOUNTS_BY_RANGE_H +#define MERCHANT_DATABASE_ITERATE_STATISTIC_BUCKET_AMOUNTS_BY_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_iterate_statistic_bucket_amounts_by_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/iterate_statistic_bucket_counters.h b/src/include/merchant-database/iterate_statistic_bucket_counters.h @@ -0,0 +1,67 @@ +/* + 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/iterate_statistic_bucket_counters.h + * @brief implementation of the iterate_statistic_bucket_counters function for Postgres + * @author Martin Schanzenbach + */ +#ifndef MERCHANT_DATABASE_ITERATE_STATISTIC_BUCKET_COUNTERS_H +#define MERCHANT_DATABASE_ITERATE_STATISTIC_BUCKET_COUNTERS_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_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_counter counter value + */ +typedef void +(*TALER_MERCHANTDB_CounterByBucketStatisticsCallback)( + void *cls, + const char *description, + struct GNUNET_TIME_Timestamp bucket_start, + struct GNUNET_TIME_Timestamp bucket_end, + const char *bucket_range, + uint64_t cumulative_counter); + +/** + * Lookup statistics where the values are counters. + * + * @param pg database context + * @param instance_id instance to lookup statistics for + * @param slug slug to lookup statistics for + * @param cb function to call on all statistics found + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_statistic_bucket_counters ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *slug, + TALER_MERCHANTDB_CounterByBucketStatisticsCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_statistic_bucket_counters_by_range.h b/src/include/merchant-database/iterate_statistic_bucket_counters_by_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/iterate_statistic_bucket_counters_by_range.h + * @brief implementation of the iterate_statistic_bucket_counters_by_range function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_STATISTIC_BUCKET_COUNTERS_BY_RANGE_H +#define MERCHANT_DATABASE_ITERATE_STATISTIC_BUCKET_COUNTERS_BY_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_iterate_statistic_bucket_counters_by_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 diff --git a/src/include/merchant-database/iterate_statistic_interval_amounts.h b/src/include/merchant-database/iterate_statistic_interval_amounts.h @@ -0,0 +1,65 @@ +/* + 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/iterate_statistic_interval_amounts.h + * @brief implementation of the iterate_statistic_interval_amounts function for Postgres + * @author Martin Schanzenbach + */ +#ifndef MERCHANT_DATABASE_ITERATE_STATISTIC_INTERVAL_AMOUNTS_H +#define MERCHANT_DATABASE_ITERATE_STATISTIC_INTERVAL_AMOUNTS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Returns amount-valued statistics over a particular time interval. + * Called by `lookup_statistics_amount_by_interval`. + * + * @param cls closure + * @param description description of the statistic + * @param interval_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_AmountByIntervalStatisticsCallback)( + void *cls, + const char *description, + struct GNUNET_TIME_Timestamp interval_start, + unsigned int cumulative_amounts_len, + const struct TALER_Amount cumulative_amounts[static cumulative_amounts_len]); + +/** + * Lookup statistics where the values are amounts. + * + * @param pg database context + * @param instance_id instance to lookup statistics for + * @param slug slug to lookup statistics for + * @param cb function to call on all statistics found + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_statistic_interval_amounts ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *slug, + TALER_MERCHANTDB_AmountByIntervalStatisticsCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_statistic_interval_counters.h b/src/include/merchant-database/iterate_statistic_interval_counters.h @@ -0,0 +1,82 @@ +/* + 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/iterate_statistic_interval_counters.h + * @brief implementation of the iterate_statistic_interval_counters function for Postgres + * @author Martin Schanzenbach + */ +#ifndef MERCHANT_DATABASE_ITERATE_STATISTIC_INTERVAL_COUNTERS_H +#define MERCHANT_DATABASE_ITERATE_STATISTIC_INTERVAL_COUNTERS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Details about a statistic with counter. + */ +struct TALER_MERCHANTDB_StatisticsCounterByIntervalDetails +{ + /** + * Start time of the interval. + * The interval always ends at the response generation time. + */ + struct GNUNET_TIME_Timestamp start_time; + + /** + * Sum of all counters falling under the given + * SLUG within this timeframe + */ + uint64_t cumulative_counter; +}; + + +/** + * Function returning integer-valued statistics for a time interval. + * Called by `lookup_statistics_counter_by_interval`. + * + * @param cls closure + * @param description description of the statistic + * @param interval_start start time of the interval + * @param cumulative_counter counter value + */ +typedef void +(*TALER_MERCHANTDB_CounterByIntervalStatisticsCallback)( + void *cls, + const char *description, + struct GNUNET_TIME_Timestamp interval_start, + uint64_t cumulative_counter); + +/** + * Lookup statistics where the values are counters. + * + * @param pg database context + * @param instance_id instance to lookup statistics for + * @param slug slug to lookup statistics for + * @param cb function to call on all statistics found + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_statistic_interval_counters ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *slug, + TALER_MERCHANTDB_CounterByIntervalStatisticsCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_statistics_amount_by_bucket.h b/src/include/merchant-database/iterate_statistics_amount_by_bucket.h @@ -1,68 +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/iterate_statistics_amount_by_bucket.h - * @brief implementation of the iterate_statistics_amount_by_bucket function for Postgres - * @author Martin Schanzenbach - */ -#ifndef MERCHANT_DATABASE_ITERATE_STATISTICS_AMOUNT_BY_BUCKET_H -#define MERCHANT_DATABASE_ITERATE_STATISTICS_AMOUNT_BY_BUCKET_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - -/** - * 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]); - -/** - * Lookup statistics where the values are amounts. - * - * @param pg database context - * @param instance_id instance to lookup statistics for - * @param slug slug to lookup statistics for - * @param cb function to call on all statistics found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_statistics_amount_by_bucket ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *slug, - TALER_MERCHANTDB_AmountByBucketStatisticsCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/iterate_statistics_amount_by_bucket_range.h b/src/include/merchant-database/iterate_statistics_amount_by_bucket_range.h @@ -1,94 +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/iterate_statistics_amount_by_bucket_range.h - * @brief implementation of the iterate_statistics_amount_by_bucket_range function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_ITERATE_STATISTICS_AMOUNT_BY_BUCKET_RANGE_H -#define MERCHANT_DATABASE_ITERATE_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_iterate_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/iterate_statistics_amount_by_interval.h b/src/include/merchant-database/iterate_statistics_amount_by_interval.h @@ -1,65 +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/iterate_statistics_amount_by_interval.h - * @brief implementation of the iterate_statistics_amount_by_interval function for Postgres - * @author Martin Schanzenbach - */ -#ifndef MERCHANT_DATABASE_ITERATE_STATISTICS_AMOUNT_BY_INTERVAL_H -#define MERCHANT_DATABASE_ITERATE_STATISTICS_AMOUNT_BY_INTERVAL_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Returns amount-valued statistics over a particular time interval. - * Called by `lookup_statistics_amount_by_interval`. - * - * @param cls closure - * @param description description of the statistic - * @param interval_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_AmountByIntervalStatisticsCallback)( - void *cls, - const char *description, - struct GNUNET_TIME_Timestamp interval_start, - unsigned int cumulative_amounts_len, - const struct TALER_Amount cumulative_amounts[static cumulative_amounts_len]); - -/** - * Lookup statistics where the values are amounts. - * - * @param pg database context - * @param instance_id instance to lookup statistics for - * @param slug slug to lookup statistics for - * @param cb function to call on all statistics found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_statistics_amount_by_interval ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *slug, - TALER_MERCHANTDB_AmountByIntervalStatisticsCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/iterate_statistics_counter_by_bucket.h b/src/include/merchant-database/iterate_statistics_counter_by_bucket.h @@ -1,67 +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/iterate_statistics_counter_by_bucket.h - * @brief implementation of the iterate_statistics_counter_by_bucket function for Postgres - * @author Martin Schanzenbach - */ -#ifndef MERCHANT_DATABASE_ITERATE_STATISTICS_COUNTER_BY_BUCKET_H -#define MERCHANT_DATABASE_ITERATE_STATISTICS_COUNTER_BY_BUCKET_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_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_counter counter value - */ -typedef void -(*TALER_MERCHANTDB_CounterByBucketStatisticsCallback)( - void *cls, - const char *description, - struct GNUNET_TIME_Timestamp bucket_start, - struct GNUNET_TIME_Timestamp bucket_end, - const char *bucket_range, - uint64_t cumulative_counter); - -/** - * Lookup statistics where the values are counters. - * - * @param pg database context - * @param instance_id instance to lookup statistics for - * @param slug slug to lookup statistics for - * @param cb function to call on all statistics found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_statistics_counter_by_bucket ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *slug, - TALER_MERCHANTDB_CounterByBucketStatisticsCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/iterate_statistics_counter_by_bucket_range.h b/src/include/merchant-database/iterate_statistics_counter_by_bucket_range.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/iterate_statistics_counter_by_bucket_range.h - * @brief implementation of the iterate_statistics_counter_by_bucket_range function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_ITERATE_STATISTICS_COUNTER_BY_BUCKET_RANGE_H -#define MERCHANT_DATABASE_ITERATE_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_iterate_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 diff --git a/src/include/merchant-database/iterate_statistics_counter_by_interval.h b/src/include/merchant-database/iterate_statistics_counter_by_interval.h @@ -1,82 +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/iterate_statistics_counter_by_interval.h - * @brief implementation of the lookup_statistics_by_interval function for Postgres - * @author Martin Schanzenbach - */ -#ifndef MERCHANT_DATABASE_ITERATE_STATISTICS_COUNTER_BY_INTERVAL_H -#define MERCHANT_DATABASE_ITERATE_STATISTICS_COUNTER_BY_INTERVAL_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Details about a statistic with counter. - */ -struct TALER_MERCHANTDB_StatisticsCounterByIntervalDetails -{ - /** - * Start time of the interval. - * The interval always ends at the response generation time. - */ - struct GNUNET_TIME_Timestamp start_time; - - /** - * Sum of all counters falling under the given - * SLUG within this timeframe - */ - uint64_t cumulative_counter; -}; - - -/** - * Function returning integer-valued statistics for a time interval. - * Called by `lookup_statistics_counter_by_interval`. - * - * @param cls closure - * @param description description of the statistic - * @param interval_start start time of the interval - * @param cumulative_counter counter value - */ -typedef void -(*TALER_MERCHANTDB_CounterByIntervalStatisticsCallback)( - void *cls, - const char *description, - struct GNUNET_TIME_Timestamp interval_start, - uint64_t cumulative_counter); - -/** - * Lookup statistics where the values are counters. - * - * @param pg database context - * @param instance_id instance to lookup statistics for - * @param slug slug to lookup statistics for - * @param cb function to call on all statistics found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_statistics_counter_by_interval ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *slug, - TALER_MERCHANTDB_CounterByIntervalStatisticsCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/iterate_transfer_summaries.h b/src/include/merchant-database/iterate_transfer_summaries.h @@ -0,0 +1,62 @@ +/* + 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/iterate_transfer_summaries.h + * @brief implementation of the iterate_transfer_summaries function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_ITERATE_TRANSFER_SUMMARIES_H +#define MERCHANT_DATABASE_ITERATE_TRANSFER_SUMMARIES_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Function called with information about a wire transfer identifier. + * + * @param cls closure + * @param order_id the order to which the deposits belong + * @param deposit_value the amount deposited under @a order_id + * @param deposit_fee the fee charged for @a deposit_value + */ +typedef void +(*TALER_MERCHANTDB_TransferSummaryCallback)( + void *cls, + const char *order_id, + const struct TALER_Amount *deposit_value, + const struct TALER_Amount *deposit_fee); + +/** + * Lookup transfer summary. + * + * @param pg database context + * @param exchange_url the exchange that made the transfer + * @param wtid wire transfer subject + * @param cb function to call with detailed transfer data + * @param cb_cls closure for @a cb + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_transfer_summaries ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *exchange_url, + const struct TALER_WireTransferIdentifierRawP *wtid, + TALER_MERCHANTDB_TransferSummaryCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_transfer_summary.h b/src/include/merchant-database/iterate_transfer_summary.h @@ -1,62 +0,0 @@ -/* - 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/iterate_transfer_summary.h - * @brief implementation of the iterate_transfer_summary function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_ITERATE_TRANSFER_SUMMARY_H -#define MERCHANT_DATABASE_ITERATE_TRANSFER_SUMMARY_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Function called with information about a wire transfer identifier. - * - * @param cls closure - * @param order_id the order to which the deposits belong - * @param deposit_value the amount deposited under @a order_id - * @param deposit_fee the fee charged for @a deposit_value - */ -typedef void -(*TALER_MERCHANTDB_TransferSummaryCallback)( - void *cls, - const char *order_id, - const struct TALER_Amount *deposit_value, - const struct TALER_Amount *deposit_fee); - -/** - * Lookup transfer summary. - * - * @param pg database context - * @param exchange_url the exchange that made the transfer - * @param wtid wire transfer subject - * @param cb function to call with detailed transfer data - * @param cb_cls closure for @a cb - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_iterate_transfer_summary ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *exchange_url, - const struct TALER_WireTransferIdentifierRawP *wtid, - TALER_MERCHANTDB_TransferSummaryCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/iterate_used_tokens_by_order.h b/src/include/merchant-database/iterate_used_tokens_by_order.h @@ -0,0 +1,67 @@ +/* + This file is part of TALER + Copyright (C) 2024 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/iterate_used_tokens_by_order.h + * @brief implementation of the iterate_used_tokens_by_order function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_USED_TOKENS_BY_ORDER_H +#define MERCHANT_DATABASE_ITERATE_USED_TOKENS_BY_ORDER_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Function called with information about a token that was used. + * + * @param cls closure + * @param spent_token_serial which used token is this about + * @param h_contract_terms hash of the contract terms this token was used on + * @param h_issue_pub hash of the token issue public key + * @param use_pub token use public key + * @param use_sig token use signature + * @param issue_sig unblinded token issue signature + */ +typedef void +(*TALER_MERCHANTDB_UsedTokensCallback)( + void *cls, + uint64_t spent_token_serial, + const struct TALER_PrivateContractHashP *h_contract_terms, + const struct TALER_TokenIssuePublicKeyHashP *h_issue_pub, + const struct TALER_TokenUsePublicKeyP *use_pub, + const struct TALER_TokenUseSignatureP *use_sig, + const struct TALER_TokenIssueSignature *issue_sig); + +/** + * Retrieve details about tokens that were used for an order. + * + * @param pg database context + * @param order_serial identifies the order + * @param cb function to call for each used token + * @param cb_cls closure for @a cb + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_used_tokens_by_order ( + struct TALER_MERCHANTDB_PostgresContext *pg, + uint64_t order_serial, + TALER_MERCHANTDB_UsedTokensCallback cb, + void *cb_cls); + + +#endif diff --git a/src/include/merchant-database/update_account_last_bank_serial.h b/src/include/merchant-database/update_account_last_bank_serial.h @@ -0,0 +1,46 @@ +/* + 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/update_account_last_bank_serial.h + * @brief implementation of the update_account_last_bank_serial function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_UPDATE_ACCOUNT_LAST_BANK_SERIAL_H +#define MERCHANT_DATABASE_UPDATE_ACCOUNT_LAST_BANK_SERIAL_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Update information about progress made by taler-merchant-wirewatch. + * + * @param pg database context + * @param instance name of the instance to record progress for + * @param payto_uri bank account URI to record progress for + * @param last_serial latest serial of a transaction that was processed + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_update_account_last_bank_serial (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance, + struct TALER_FullPayto payto_uri, + uint64_t last_serial); + + +#endif diff --git a/src/include/merchant-database/update_contract_session.h b/src/include/merchant-database/update_contract_session.h @@ -1,50 +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/update_contract_session.h - * @brief implementation of the update_contract_session function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_UPDATE_CONTRACT_SESSION_H -#define MERCHANT_DATABASE_UPDATE_CONTRACT_SESSION_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Update session associated with a contract and return - * the fulfillment URL and the refund status. - * - * @param pg database context - * @param instance_id instance to mark contract as paid for - * @param h_contract_terms hash of the contract that is now paid - * @param session_id the session that paid the contract - * @param[out] fulfillment_url set to the fulfillment URL (possibly NULL) - * @param[out] refunded set to true if the order was refunded - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_update_contract_session (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const struct TALER_PrivateContractHashP *h_contract_terms, - const char *session_id, - char **fulfillment_url, - bool *refunded); - -#endif diff --git a/src/include/merchant-database/update_contract_terms_session.h b/src/include/merchant-database/update_contract_terms_session.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 src/include/merchant-database/update_contract_terms_session.h + * @brief implementation of the update_contract_terms_session function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_UPDATE_CONTRACT_TERMS_SESSION_H +#define MERCHANT_DATABASE_UPDATE_CONTRACT_TERMS_SESSION_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Update session associated with a contract and return + * the fulfillment URL and the refund status. + * + * @param pg database context + * @param instance_id instance to mark contract as paid for + * @param h_contract_terms hash of the contract that is now paid + * @param session_id the session that paid the contract + * @param[out] fulfillment_url set to the fulfillment URL (possibly NULL) + * @param[out] refunded set to true if the order was refunded + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_update_contract_terms_session (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const struct TALER_PrivateContractHashP * + h_contract_terms, + const char *session_id, + char **fulfillment_url, + bool *refunded); + +#endif diff --git a/src/include/merchant-database/update_deposit_confirmation_status.h b/src/include/merchant-database/update_deposit_confirmation_status.h @@ -1,53 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2024 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/update_deposit_confirmation_status.h - * @brief implementation of the update_deposit_confirmation_status function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_UPDATE_DEPOSIT_CONFIRMATION_STATUS_H -#define MERCHANT_DATABASE_UPDATE_DEPOSIT_CONFIRMATION_STATUS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Update the deposit confirmation status associated with - * the given @a deposit_serial. - * - * @param pg database context - * @param deposit_serial deposit to update status for - * @param retry_needed true if the HTTP request should be retried - * @param retry_time when should we ask the exchange again - * @param last_http_status HTTP status code of the last reply - * @param last_ec Taler error code of the last reply - * @param last_hint hint from error message to record, possibly NULL - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_update_deposit_confirmation_status (struct TALER_MERCHANTDB_PostgresContext *pg, - uint64_t deposit_serial, - bool retry_needed, - struct GNUNET_TIME_Timestamp retry_time, - uint32_t last_http_status, - enum TALER_ErrorCode last_ec, - const char *last_hint); - - -#endif diff --git a/src/include/merchant-database/update_deposit_settlement_status.h b/src/include/merchant-database/update_deposit_settlement_status.h @@ -0,0 +1,53 @@ +/* + This file is part of TALER + Copyright (C) 2024 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/update_deposit_settlement_status.h + * @brief implementation of the update_deposit_settlement_status function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_UPDATE_DEPOSIT_SETTLEMENT_STATUS_H +#define MERCHANT_DATABASE_UPDATE_DEPOSIT_SETTLEMENT_STATUS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Update the deposit confirmation status associated with + * the given @a deposit_serial. + * + * @param pg database context + * @param deposit_serial deposit to update status for + * @param retry_needed true if the HTTP request should be retried + * @param retry_time when should we ask the exchange again + * @param last_http_status HTTP status code of the last reply + * @param last_ec Taler error code of the last reply + * @param last_hint hint from error message to record, possibly NULL + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_update_deposit_settlement_status (struct TALER_MERCHANTDB_PostgresContext *pg, + uint64_t deposit_serial, + bool retry_needed, + struct GNUNET_TIME_Timestamp retry_time, + uint32_t last_http_status, + enum TALER_ErrorCode last_ec, + const char *last_hint); + + +#endif diff --git a/src/include/merchant-database/update_expected_transfer_status.h b/src/include/merchant-database/update_expected_transfer_status.h @@ -0,0 +1,54 @@ +/* + 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/update_expected_transfer_status.h + * @brief implementation of the update_expected_transfer_status function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_UPDATE_EXPECTED_TRANSFER_STATUS_H +#define MERCHANT_DATABASE_UPDATE_EXPECTED_TRANSFER_STATUS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Update transfer status. + * + * @param pg database context + * @param exchange_url the exchange that made the transfer + * @param wtid wire transfer subject + * @param next_attempt when should we try again (if ever) + * @param http_status last HTTP status code from the server, 0 for timeout + * @param ec current error state of checking the transfer + * @param hint last hint from the server, possibly NULL + * @param needs_retry true if we should retry the request + * @return database transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_update_expected_transfer_status (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *exchange_url, + const struct TALER_WireTransferIdentifierRawP * + wtid, + struct GNUNET_TIME_Absolute next_attempt, + unsigned int http_status, + enum TALER_ErrorCode ec, + const char *hint, + bool needs_retry); + +#endif diff --git a/src/include/merchant-database/update_otp.h b/src/include/merchant-database/update_otp.h @@ -1,48 +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/update_otp.h - * @brief implementation of the update_otp function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_UPDATE_OTP_H -#define MERCHANT_DATABASE_UPDATE_OTP_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Update details about a particular OTP device. - * - * @param pg database context - * @param instance_id instance to update OTP device for - * @param otp_id OTP device to update - * @param td update to the OTP device details on success, can be NULL - * (in that case we only want to check if the template exists) - * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the template - * does not yet exist. - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_update_otp (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *otp_id, - const struct TALER_MERCHANTDB_OtpDeviceDetails *td); - - -#endif diff --git a/src/include/merchant-database/update_otp_device.h b/src/include/merchant-database/update_otp_device.h @@ -0,0 +1,48 @@ +/* + 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/update_otp_device.h + * @brief implementation of the update_otp_device function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_UPDATE_OTP_DEVICE_H +#define MERCHANT_DATABASE_UPDATE_OTP_DEVICE_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Update details about a particular OTP device. + * + * @param pg database context + * @param instance_id instance to update OTP device for + * @param otp_id OTP device to update + * @param td update to the OTP device details on success, can be NULL + * (in that case we only want to check if the template exists) + * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the template + * does not yet exist. + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_update_otp_device (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *otp_id, + const struct TALER_MERCHANTDB_OtpDeviceDetails *td); + + +#endif diff --git a/src/include/merchant-database/update_to_expected_transfer_finalized.h b/src/include/merchant-database/update_to_expected_transfer_finalized.h @@ -0,0 +1,57 @@ +/* + 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/update_to_expected_transfer_finalized.h + * @brief implementation of the update_to_expected_transfer_finalized function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_UPDATE_TO_EXPECTED_TRANSFER_FINALIZED_H +#define MERCHANT_DATABASE_UPDATE_TO_EXPECTED_TRANSFER_FINALIZED_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Finalize transfer status. + * + * @param pg database context + * @param exchange_url the exchange that made the transfer + * @param wtid wire transfer subject + * @param h_details hash over all of the aggregated deposits + * @param total_amount total amount exchange claimed to have transferred + * @param wire_fee wire fee charged by the exchange + * @param exchange_pub key used to make @e exchange_sig + * @param exchange_sig signature of the exchange over reconciliation data + * @return database transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_update_to_expected_transfer_finalized (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *exchange_url, + const struct + TALER_WireTransferIdentifierRawP *wtid, + const struct GNUNET_HashCode *h_details, + const struct TALER_Amount *total_amount, + const struct TALER_Amount *wire_fee, + const struct TALER_ExchangePublicKeyP * + exchange_pub, + const struct TALER_ExchangeSignatureP * + exchange_sig); + + +#endif diff --git a/src/include/merchant-database/update_to_transfer_finalized.h b/src/include/merchant-database/update_to_transfer_finalized.h @@ -1,54 +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/update_to_transfer_finalized.h - * @brief implementation of the update_to_transfer_finalized function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_UPDATE_TO_TRANSFER_FINALIZED_H -#define MERCHANT_DATABASE_UPDATE_TO_TRANSFER_FINALIZED_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Finalize transfer status. - * - * @param pg database context - * @param exchange_url the exchange that made the transfer - * @param wtid wire transfer subject - * @param h_details hash over all of the aggregated deposits - * @param total_amount total amount exchange claimed to have transferred - * @param wire_fee wire fee charged by the exchange - * @param exchange_pub key used to make @e exchange_sig - * @param exchange_sig signature of the exchange over reconciliation data - * @return database transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_update_to_transfer_finalized (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *exchange_url, - const struct TALER_WireTransferIdentifierRawP *wtid, - const struct GNUNET_HashCode *h_details, - const struct TALER_Amount *total_amount, - const struct TALER_Amount *wire_fee, - const struct TALER_ExchangePublicKeyP *exchange_pub, - const struct TALER_ExchangeSignatureP *exchange_sig); - - -#endif diff --git a/src/include/merchant-database/update_transfer_status.h b/src/include/merchant-database/update_transfer_status.h @@ -1,53 +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/update_transfer_status.h - * @brief implementation of the update_transfer_status function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_UPDATE_TRANSFER_STATUS_H -#define MERCHANT_DATABASE_UPDATE_TRANSFER_STATUS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Update transfer status. - * - * @param pg database context - * @param exchange_url the exchange that made the transfer - * @param wtid wire transfer subject - * @param next_attempt when should we try again (if ever) - * @param http_status last HTTP status code from the server, 0 for timeout - * @param ec current error state of checking the transfer - * @param hint last hint from the server, possibly NULL - * @param needs_retry true if we should retry the request - * @return database transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_update_transfer_status (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *exchange_url, - const struct TALER_WireTransferIdentifierRawP *wtid, - struct GNUNET_TIME_Absolute next_attempt, - unsigned int http_status, - enum TALER_ErrorCode ec, - const char *hint, - bool needs_retry); - -#endif diff --git a/src/include/merchant-database/update_wirewatch_progress.h b/src/include/merchant-database/update_wirewatch_progress.h @@ -1,46 +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/update_wirewatch_progress.h - * @brief implementation of the update_wirewatch_progress function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_UPDATE_WIREWATCH_PROGRESS_H -#define MERCHANT_DATABASE_UPDATE_WIREWATCH_PROGRESS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Update information about progress made by taler-merchant-wirewatch. - * - * @param pg database context - * @param instance name of the instance to record progress for - * @param payto_uri bank account URI to record progress for - * @param last_serial latest serial of a transaction that was processed - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_update_wirewatch_progress (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance, - struct TALER_FullPayto payto_uri, - uint64_t last_serial); - - -#endif